Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<properties>
<shadeBase>org.weakref.jmx.\$internal</shadeBase>
<dep.plugin.njord.version>0.8.7</dep.plugin.njord.version>
<dep.junit.version>6.0.1</dep.junit.version>
</properties>

<distributionManagement>
Expand All @@ -47,12 +48,6 @@
</distributionManagement>

<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.2.1</version>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change

<scope>test</scope>
</dependency>

<dependency>
<groupId>com.google.inject</groupId>
Expand All @@ -73,7 +68,37 @@
<version>3.0.0</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${dep.junit.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${dep.junit.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${dep.junit.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.27.6</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<pluginManagement>
<plugins>
Expand Down
115 changes: 60 additions & 55 deletions src/test/java/org/weakref/jmx/AbstractMbeanTest.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package org.weakref.jmx;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import javax.management.AttributeNotFoundException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanParameterInfo;

import java.lang.reflect.Method;
import java.util.List;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
import static org.assertj.core.api.Assertions.assertThat;

@TestInstance(PER_CLASS)
public abstract class AbstractMbeanTest<T>
{
protected List<T> objects;
Expand All @@ -36,7 +36,8 @@ protected abstract void setAttribute(T t, String attributeName, Object value)
protected abstract Object invoke(T t, Object value, String operationName)
throws Exception;

@Test(dataProvider = "fixtures")
@ParameterizedTest
@MethodSource("getFixtures")
public void testGetterAttributeInfo(String attribute, boolean isIs, Object[] values, Class<?> clazz)
throws Exception
{
Expand All @@ -48,15 +49,16 @@ public void testGetterAttributeInfo(String attribute, boolean isIs, Object[] val

MBeanInfo info = getMBeanInfo(t);
MBeanAttributeInfo attributeInfo = getAttributeInfo(info, attributeName);
assertNotNull(attributeInfo, "AttributeInfo for " + attributeName);
assertEquals(attributeInfo.getName(), attributeName, "Attribute Name for " + attributeName);
assertEquals(attributeInfo.getType(), setter.getParameterTypes()[0].getName(), "Attribute type for " + attributeName);
assertEquals(attributeInfo.isIs(), isIs, "Attribute isIs for " + attributeName);
assertTrue(attributeInfo.isReadable(), "Attribute Readable for " + attributeName);
assertThat(attributeInfo).describedAs("AttributeInfo for " + attributeName).isNotNull();
assertThat(attributeInfo.getName()).describedAs("Attribute Name for " + attributeName).isEqualTo(attributeName);
assertThat(attributeInfo.getType()).describedAs("Attribute type for " + attributeName).isEqualTo(setter.getParameterTypes()[0].getName());
assertThat(attributeInfo.isIs()).describedAs("Attribute isIs for " + attributeName).isEqualTo(isIs);
assertThat(attributeInfo.isReadable()).describedAs("Attribute Readable for " + attributeName).isTrue();
}
}

@Test(dataProvider = "fixtures")
@ParameterizedTest
@MethodSource("getFixtures")
public void testSetterAttributeInfo(String attribute, boolean isIs, Object[] values, Class<?> clazz)
throws Exception
{
Expand All @@ -69,10 +71,10 @@ public void testSetterAttributeInfo(String attribute, boolean isIs, Object[] val

MBeanInfo info = getMBeanInfo(t);
MBeanAttributeInfo attributeInfo = getAttributeInfo(info, attributeName);
assertNotNull(attributeInfo, "AttributeInfo for " + attributeName);
assertEquals(attributeInfo.getName(), attributeName, "Attribute Name for " + attributeName);
assertEquals(attributeInfo.getType(), getter.getReturnType().getName(), "Attribute Type for " + attributeName);
assertTrue(attributeInfo.isWritable(), "Attribute Writable for " + attributeName);
assertThat(attributeInfo).describedAs("AttributeInfo for " + attributeName).isNotNull();
assertThat(attributeInfo.getName()).describedAs("Attribute Name for " + attributeName).isEqualTo(attributeName);
assertThat(attributeInfo.getType()).describedAs("Attribute Type for " + attributeName).isEqualTo(getter.getReturnType().getName());
assertThat(attributeInfo.isWritable()).describedAs("Attribute Writable for " + attributeName).isTrue();
}
}

Expand All @@ -85,7 +87,7 @@ public void testNotManagedAttributeInfo()
MBeanInfo info = getMBeanInfo(t);
String attributeName = toFeatureName("NotManaged", t);
MBeanAttributeInfo attributeInfo = getAttributeInfo(info, attributeName);
assertNull(attributeInfo, "AttributeInfo for " + attributeName);
assertThat(attributeInfo).describedAs("AttributeInfo for " + attributeName).isNull();
}
}

Expand All @@ -98,11 +100,11 @@ public void testReadOnlyAttributeInfo()

String attributeName = toFeatureName("ReadOnly", t);
MBeanAttributeInfo attributeInfo = getAttributeInfo(info, attributeName);
assertNotNull(attributeInfo, "AttributeInfo for " + attributeName);
assertEquals(attributeInfo.getName(), attributeName, "Attribute Name for " + attributeName);
assertEquals(attributeInfo.getType(), "int", "Attribute Type for " + attributeName);
assertTrue(attributeInfo.isReadable(), "Attribute Readable for " + attributeName);
assertFalse(attributeInfo.isWritable(), "Attribute Writable for " + attributeName);
assertThat(attributeInfo).describedAs("AttributeInfo for " + attributeName).isNotNull();
assertThat(attributeInfo.getName()).describedAs("Attribute Name for " + attributeName).isEqualTo(attributeName);
assertThat(attributeInfo.getType()).describedAs("Attribute Type for " + attributeName).isEqualTo("int");
assertThat(attributeInfo.isReadable()).describedAs("Attribute Readable for " + attributeName).isTrue();
assertThat(attributeInfo.isWritable()).describedAs("Attribute Writable for " + attributeName).isFalse();
}
}

Expand All @@ -114,11 +116,11 @@ public void testWriteOnlyAttributeInfo()
MBeanInfo info = getMBeanInfo(t);
String attributeName = toFeatureName("WriteOnly", t);
MBeanAttributeInfo attributeInfo = getAttributeInfo(info, attributeName);
assertNotNull(attributeInfo, "AttributeInfo for " + attributeName);
assertEquals(attributeInfo.getName(), attributeName, "Attribute Name for " + attributeName);
assertEquals(attributeInfo.getType(), "int", "Attribute Type for " + attributeName);
assertFalse(attributeInfo.isReadable(), "Attribute Readable for " + attributeName);
assertTrue(attributeInfo.isWritable(), "Attribute Writable for " + attributeName);
assertThat(attributeInfo).describedAs("AttributeInfo for " + attributeName).isNotNull();
assertThat(attributeInfo.getName()).describedAs("Attribute Name for " + attributeName).isEqualTo(attributeName);
assertThat(attributeInfo.getType()).describedAs("Attribute Type for " + attributeName).isEqualTo("int");
assertThat(attributeInfo.isReadable()).describedAs("Attribute Readable for " + attributeName).isFalse();
assertThat(attributeInfo.isWritable()).describedAs("Attribute Writable for " + attributeName).isTrue();
}
}

Expand All @@ -132,7 +134,8 @@ private static MBeanAttributeInfo getAttributeInfo(MBeanInfo info, String attrib
return null;
}

@Test(dataProvider = "fixtures")
@ParameterizedTest
@MethodSource("getFixtures")
public void testOperationInfo(String attribute, boolean isIs, Object[] values, Class<?> clazz)
throws Exception
{
Expand All @@ -147,18 +150,19 @@ public void testOperationInfo(String attribute, boolean isIs, Object[] values, C
}
}

assertNotNull(operationInfo, "OperationInfo for " + operationName);
assertEquals(operationInfo.getName(), operationName, "Operation Name for " + operationName);
assertEquals(operationInfo.getImpact(), MBeanOperationInfo.UNKNOWN, "Operation Impact for " + operationName);
assertEquals(operationInfo.getReturnType(), Object.class.getName(), "Operation Return Type for " + operationName);
assertEquals(operationInfo.getSignature().length, 1, "Operation Parameter Length for " + operationName);
assertThat(operationInfo).describedAs("OperationInfo for " + operationName).isNotNull();
assertThat(operationInfo.getName()).describedAs("Operation Name for " + operationName).isEqualTo(operationName);
assertThat(operationInfo.getImpact()).describedAs("Operation Impact for " + operationName).isEqualTo(MBeanOperationInfo.UNKNOWN);
assertThat(operationInfo.getReturnType()).describedAs("Operation Return Type for " + operationName).isEqualTo(Object.class.getName());
assertThat(operationInfo.getSignature().length).describedAs("Operation Parameter Length for " + operationName).isEqualTo(1);
MBeanParameterInfo parameterInfo = operationInfo.getSignature()[0];
assertEquals(parameterInfo.getName(), "value", "Operation Parameter[0] Name for " + operationName);
assertEquals(parameterInfo.getType(), Object.class.getName(), "Operation Parameter[0] Type for " + operationName);
assertThat(parameterInfo.getName()).describedAs("Operation Parameter[0] Name for " + operationName).isEqualTo("value");
assertThat(parameterInfo.getType()).describedAs("Operation Parameter[0] Type for " + operationName).isEqualTo(Object.class.getName());
}
}

@Test(dataProvider = "fixtures")
@ParameterizedTest
@MethodSource("getFixtures")
public void testGet(String attribute, boolean isIs, Object[] values, Class<?> clazz)
throws Exception
{
Expand All @@ -171,12 +175,13 @@ public void testGet(String attribute, boolean isIs, Object[] values, Class<?> cl
for (Object value : values) {
setter.invoke(simpleObject, value);

assertEquals(getAttribute(t, attributeName), value);
assertThat(getAttribute(t, attributeName)).isEqualTo(value);
}
}
}

@Test(dataProvider = "fixtures")
@ParameterizedTest
@MethodSource("getFixtures")
public void testSet(String attribute, boolean isIs, Object[] values, Class<?> clazz)
throws Exception
{
Expand All @@ -190,7 +195,7 @@ public void testSet(String attribute, boolean isIs, Object[] values, Class<?> cl
for (Object value : values) {
setAttribute(t, attributeName, value);

assertEquals(getter.invoke(simpleObject), value);
assertThat(getter.invoke(simpleObject)).isEqualTo(value);
}
}
}
Expand All @@ -205,13 +210,13 @@ public void testSetFailsOnNotManaged()
simpleObject.setNotManaged(1);
try {
setAttribute(t, "NotManaged", 2);
fail("Should not allow setting unmanaged attribute");
throw new AssertionError("Should not allow setting unmanaged attribute");
}
catch (AttributeNotFoundException e) {
// ignore
}

assertEquals(simpleObject.getNotManaged(), 1);
assertThat(simpleObject.getNotManaged()).isEqualTo(1);
}
}

Expand All @@ -223,7 +228,7 @@ public void testGetFailsOnNotManaged()
for (T t : objects) {
try {
getAttribute(t, "NotManaged");
fail("Should not allow getting unmanaged attribute");
throw new AssertionError("Should not allow getting unmanaged attribute");
}
catch (AttributeNotFoundException e) {
// ignore
Expand All @@ -238,7 +243,7 @@ public void testGetFailsOnWriteOnly()
for (T t : objects) {
try {
getAttribute(t, "WriteOnly");
fail("Should not allow getting write-only attribute");
throw new AssertionError("Should not allow getting write-only attribute");
}
catch (AttributeNotFoundException e) {
// ignore
Expand All @@ -255,13 +260,13 @@ public void testSetFailsOnReadOnly()
simpleObject.setReadOnly(1);
try {
setAttribute(t, "ReadOnly", 2);
fail("Should not allow setting read-only attribute");
throw new AssertionError("Should not allow setting read-only attribute");
}
catch (AttributeNotFoundException e) {
// ignore
}

assertEquals(simpleObject.getReadOnly(), 1);
assertThat(simpleObject.getReadOnly()).isEqualTo(1);
}
}

Expand All @@ -274,31 +279,31 @@ public void testDescription()
for (MBeanAttributeInfo info : getMBeanInfo(t).getAttributes()) {
String attributeName = toFeatureName("DescribedInt", t);
if (info.getName().equals(attributeName)) {
assertEquals("epic description", info.getDescription());
assertThat(info.getDescription()).isEqualTo("epic description");
described = true;
}
else {
assertEquals("", info.getDescription());
assertThat(info.getDescription()).isEqualTo("");
}
}
assertTrue(described);
assertThat(described).isTrue();
}
}

@Test(dataProvider = "fixtures")
@ParameterizedTest
@MethodSource("getFixtures")
public void testOperation(String attribute, boolean isIs, Object[] values, Class<?> clazz)
throws Exception
{
for (T t : objects) {
for (Object value : values) {
String operationName = toFeatureName("echo", t);
assertEquals(invoke(t, value, operationName), value);
assertThat(invoke(t, value, operationName)).isEqualTo(value);
}
}
}

@DataProvider(name = "fixtures")
Object[][] getFixtures()
static Object[][] getFixtures()
{
return new Object[][] {

Expand Down
22 changes: 10 additions & 12 deletions src/test/java/org/weakref/jmx/TestExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

package org.weakref.jmx;

import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.weakref.jmx.testing.TestingMBeanServer;

import javax.management.AttributeNotFoundException;
Expand All @@ -32,8 +33,7 @@
import java.util.ArrayList;
import java.util.Map;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.weakref.jmx.Util.getUniqueObjectName;

public class TestExporter extends AbstractMbeanTest<TestExporter.NamedObject>
Expand Down Expand Up @@ -93,7 +93,7 @@ protected Object invoke(NamedObject namedObject, Object value, String operationN
new String[] { Object.class.getName() });
}

@BeforeMethod
@BeforeEach
void setup()
{
server = new TestingMBeanServer();
Expand All @@ -119,14 +119,14 @@ void testManagedClasses()
for(NamedObject namedObject : objects) {
String name = namedObject.objectName.getCanonicalName();

assertTrue(managedClasses.containsKey(name));
assertThat(managedClasses.containsKey(name)).isTrue();

ManagedClass managedClass = managedClasses.get(name);
assertEquals(namedObject.object, managedClass.getTarget());
assertThat(managedClass.getTarget()).isEqualTo(namedObject.object);

if(namedObject.object instanceof NestedObject || namedObject.object instanceof FlattenObject) {
assertEquals(managedClass.getChildren().size(), 1);
assertEquals(managedClass.getChildren().get("SimpleObject").getTargetClass(), SimpleObject.class);
assertThat(managedClass.getChildren().size()).isEqualTo(1);
assertThat(managedClass.getChildren().get("SimpleObject").getTargetClass()).isEqualTo(SimpleObject.class);
}
}
}
Expand All @@ -143,8 +143,6 @@ void testDuplicateKey()
catch(JmxException e) {
// do nothing
}
assertEquals(exporter.getExportedObjects().size(), 1);
assertThat(exporter.getExportedObjects().size()).isEqualTo(1);
}
}


Loading
Loading