X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fyang-jmx-generator%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyangjmxgenerator%2FModuleMXBeanEntryTest.java;h=50f38e3978a790528205fb58452c4956a646e659;hp=9ea34ca2b8ed990c56c6c14988733e09d88e3995;hb=3f09df41971e718e2c68d59cea21443c1ed6f502;hpb=306f95ccf8d699e2eed111f193b2fc388fa03e70 diff --git a/opendaylight/config/yang-jmx-generator/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/ModuleMXBeanEntryTest.java b/opendaylight/config/yang-jmx-generator/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/ModuleMXBeanEntryTest.java index 9ea34ca2b8..50f38e3978 100644 --- a/opendaylight/config/yang-jmx-generator/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/ModuleMXBeanEntryTest.java +++ b/opendaylight/config/yang-jmx-generator/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/ModuleMXBeanEntryTest.java @@ -7,8 +7,32 @@ */ package org.opendaylight.controller.config.yangjmxgenerator; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.isA; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; import com.google.common.collect.Sets; +import java.net.URI; +import java.net.URISyntaxException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.regex.Matcher; +import javax.management.openmbean.ArrayType; +import javax.management.openmbean.CompositeType; +import javax.management.openmbean.SimpleType; import org.junit.Before; import org.junit.Test; import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc; @@ -26,39 +50,7 @@ import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode; import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath; -import javax.management.openmbean.ArrayType; -import javax.management.openmbean.CompositeType; -import javax.management.openmbean.SimpleType; -import java.net.URI; -import java.net.URISyntaxException; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.regex.Matcher; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; - public class ModuleMXBeanEntryTest extends AbstractYangTest { - public static final String EVENTBUS_MXB_NAME = "eventbus"; - public static final String ASYNC_EVENTBUS_MXB_NAME = "async-eventbus"; - public static final String THREADFACTORY_NAMING_MXB_NAME = "threadfactory-naming"; - public static final String THREADPOOL_DYNAMIC_MXB_NAME = "threadpool-dynamic"; - public static final String THREADPOOL_REGISTRY_IMPL_NAME = "threadpool-registry-impl"; - - public static final String BGP_LISTENER_IMPL_MXB_NAME = "bgp-listener-impl"; public static final String PACKAGE_NAME = "pack2"; @@ -82,23 +74,15 @@ public class ModuleMXBeanEntryTest extends AbstractYangTest { protected Map modulesToSIEs; - protected Map loadThreadsJava() { - Map namesToMBEs = ModuleMXBeanEntry - .create(threadsJavaModule, modulesToSIEs, context, new TypeProviderWrapper(new TypeProviderImpl - (context)), PACKAGE_NAME); - assertNotNull(namesToMBEs); - Set expectedMXBeanNames = Sets.newHashSet(EVENTBUS_MXB_NAME, - ASYNC_EVENTBUS_MXB_NAME, THREADFACTORY_NAMING_MXB_NAME, - THREADPOOL_DYNAMIC_MXB_NAME, THREADPOOL_REGISTRY_IMPL_NAME); - assertThat(namesToMBEs.keySet(), is(expectedMXBeanNames)); - return namesToMBEs; - } @Before public void setUp() { - Map identitiesToSIs = new HashMap<>(); - modulesToSIEs = ServiceInterfaceEntry.create(threadsModule, - "packages.sis",identitiesToSIs); + modulesToSIEs = loadThreadsServiceInterfaceEntries("packages.sis"); + } + + + protected Map loadThreadsJava() { + return loadThreadsJava(modulesToSIEs, PACKAGE_NAME); } @Test @@ -110,9 +94,12 @@ public class ModuleMXBeanEntryTest extends AbstractYangTest { PACKAGE_NAME,identitiesToSIs)); Map namesToMBEs = ModuleMXBeanEntry .create(jmxImplModule, modulesToSIEs, context, new TypeProviderWrapper(new TypeProviderImpl(context)) - , PACKAGE_NAME); + , PACKAGE_NAME); Map attributes = namesToMBEs.get("impl-netconf") .getAttributes(); + + assertCorrectAttributesSize(namesToMBEs, attributes); + // DependencyAttribute threadFactoryAttribute = (DependencyAttribute) attributes .get("thread-factory"); @@ -126,22 +113,44 @@ public class ModuleMXBeanEntryTest extends AbstractYangTest { is("threadFactory")); assertThat(threadFactoryAttribute.getUpperCaseCammelCase(), is("ThreadFactory")); - assertThat(threadFactoryAttribute.getOpenType(), is(SimpleType.class)); + assertThat(threadFactoryAttribute.getOpenType(), isA(SimpleType.class)); assertNull(threadFactoryAttribute.getNullableDefault()); assertNull(threadFactoryAttribute.getNullableDescription()); assertThat(threadFactoryAttribute.getType().getName(), is("ObjectName")); } + private void assertCorrectAttributesSize(final Map namesToMBEs, final Map attributes) { + assertEquals(14, attributes.size()); + assertEquals(1, namesToMBEs.get("impl-netconf").getRuntimeBeans().size()); + assertEquals(2, namesToMBEs.get("impl-netconf").getRuntimeBeans().iterator().next().getAttributes().size()); + + assertEquals(4, namesToMBEs.get("impl").getAttributes().size()); + assertEquals(1, namesToMBEs.get("impl").getRuntimeBeans().size()); + assertEquals(1, namesToMBEs.get("impl").getRuntimeBeans().iterator().next().getAttributes().size()); + } + protected RuntimeBeanEntry findFirstByYangName( - Collection runtimeBeans, String yangName) { + final Collection runtimeBeans, final String yangName) { for (RuntimeBeanEntry rb : runtimeBeans) { - if (yangName.equals(rb.getYangName())) + if (yangName.equals(rb.getYangName())) { return rb; + } } throw new IllegalArgumentException("Yang name not found:" + yangName + " in " + runtimeBeans); } + protected RuntimeBeanEntry findFirstByNamePrefix(final Collection runtimeBeans, final String namePrefix) { + for (RuntimeBeanEntry rb : runtimeBeans) { + if (namePrefix.equals(rb.getJavaNamePrefix())) { + return rb; + } + } + + throw new IllegalArgumentException("Name prefix not found:" + namePrefix + + " in " + runtimeBeans); + } + @Test public void testGetWhenConditionMatcher() { assertMatches("config", @@ -152,10 +161,10 @@ public class ModuleMXBeanEntryTest extends AbstractYangTest { "/config:modules/config:module/config:type=\"threadpool-dynamic\""); } - private void assertMatches(String prefix, String input) { + private void assertMatches(final String prefix, final String input) { RevisionAwareXPath whenConstraint = mock(RevisionAwareXPath.class); doReturn(input).when(whenConstraint).toString(); - Matcher output = ModuleMXBeanEntry.getWhenConditionMatcher(prefix, + Matcher output = ModuleMXBeanEntryBuilder.getWhenConditionMatcher(prefix, whenConstraint); assertTrue(output.matches()); assertEquals("threadpool-dynamic", output.group(1)); @@ -183,7 +192,7 @@ public class ModuleMXBeanEntryTest extends AbstractYangTest { is((Type) Types.typeForClass(Long.class))); } // check dependency on thread factory - QName threadfactoryQName = new QName(THREADS_NAMESPACE, + QName threadfactoryQName = QName.create(THREADS_NAMESPACE, THREADS_REVISION_DATE, "threadfactory"); ServiceInterfaceEntry threadFactorySIEntry = modulesToSIEs .get(threadfactoryQName); @@ -194,7 +203,7 @@ public class ModuleMXBeanEntryTest extends AbstractYangTest { DataSchemaNode mockedDataSchemaNode = mock(DataSchemaNode.class); doReturn(Collections.emptyList()).when(mockedDataSchemaNode) - .getUnknownSchemaNodes(); + .getUnknownSchemaNodes(); doReturn(threadfactoryQName).when(mockedDataSchemaNode).getQName(); AttributeIfc expectedDependencyAttribute = new DependencyAttribute( mockedDataSchemaNode, threadFactorySIEntry, @@ -202,7 +211,7 @@ public class ModuleMXBeanEntryTest extends AbstractYangTest { assertThat(actualThreadFactory, is(expectedDependencyAttribute)); assertThat( dynamicThreadPool - .getFullyQualifiedName("DynamicThreadPoolModuleMXBean"), + .getFullyQualifiedName("DynamicThreadPoolModuleMXBean"), is(PACKAGE_NAME + ".DynamicThreadPoolModuleMXBean")); assertThat(dynamicThreadPool.getNullableDescription(), is("threadpool-dynamic description")); @@ -249,8 +258,8 @@ public class ModuleMXBeanEntryTest extends AbstractYangTest { assertThat(threadRB.getRpcs().size(), is(2)); } { - RuntimeBeanEntry streamRB = findFirstByYangName(runtimeBeans, - "stream"); + RuntimeBeanEntry streamRB = findFirstByNamePrefix(runtimeBeans, + "ThreadStream"); assertNotNull(streamRB); assertFalse(streamRB.getKeyYangName().isPresent()); assertFalse(streamRB.getKeyJavaName().isPresent()); @@ -263,7 +272,7 @@ public class ModuleMXBeanEntryTest extends AbstractYangTest { assertThat(toAttr.getAttributeYangName(), is("peer")); assertThat(toAttr.getLowerCaseCammelCase(), is("peer")); assertThat(toAttr.getUpperCaseCammelCase(), is("Peer")); - assertThat(toAttr.getOpenType(), is(CompositeType.class)); + assertThat(toAttr.getOpenType(), isA(CompositeType.class)); Set propsExpected = new HashSet(2); propsExpected.add("port"); propsExpected.add("core-size"); @@ -298,7 +307,7 @@ public class ModuleMXBeanEntryTest extends AbstractYangTest { is("innerStreamList")); assertThat(innerStream.getUpperCaseCammelCase(), is("InnerStreamList")); - assertThat(innerStream.getOpenType(), is(ArrayType.class)); + assertThat(innerStream.getOpenType(), isA(ArrayType.class)); }