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=d7fb213bea4fe4f3daa36f10ee01b8ee086f72c7;hp=fab273c60093b529931e5f0ce4f02f9198327ff7;hb=20a32e6459fd1e27e7669bf1ebc7742b96787b94;hpb=e2df8aa67238c153f1038eb45f7799442861985b 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 fab273c600..d7fb213bea 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 @@ -8,6 +8,7 @@ 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; @@ -18,24 +19,18 @@ 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; @@ -45,10 +40,11 @@ import org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribu import org.opendaylight.controller.config.yangjmxgenerator.attribute.ListDependenciesAttribute; import org.opendaylight.controller.config.yangjmxgenerator.attribute.TOAttribute; import org.opendaylight.controller.config.yangjmxgenerator.attribute.TypedAttribute; -import org.opendaylight.yangtools.binding.generator.util.Types; -import org.opendaylight.yangtools.sal.binding.model.api.Type; -import org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl; +import org.opendaylight.mdsal.binding.model.api.Type; +import org.opendaylight.mdsal.binding.model.util.Types; +import org.opendaylight.mdsal.binding.yang.types.TypeProviderImpl; import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.common.Revision; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode; import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath; @@ -58,20 +54,13 @@ public class ModuleMXBeanEntryTest extends AbstractYangTest { public static final String PACKAGE_NAME = "pack2"; protected static final URI THREADS_NAMESPACE; - protected static final Date THREADS_REVISION_DATE; + protected static final Revision THREADS_REVISION_DATE = Revision.of("2013-04-09"); static { try { - THREADS_NAMESPACE = new URI(ConfigConstants.CONFIG_NAMESPACE - + ":threads"); - } catch (URISyntaxException e) { - throw new Error(e); - } - SimpleDateFormat revisionFormat = new SimpleDateFormat("yyyy-MM-dd"); - try { - THREADS_REVISION_DATE = revisionFormat.parse("2013-04-09"); - } catch (ParseException e) { - throw new Error(e); + THREADS_NAMESPACE = new URI(ConfigConstants.CONFIG_NAMESPACE + ":threads"); + } catch (final URISyntaxException e) { + throw new ExceptionInInitializerError(e); } } @@ -80,31 +69,31 @@ public class ModuleMXBeanEntryTest extends AbstractYangTest { @Before public void setUp() { - modulesToSIEs = loadThreadsServiceInterfaceEntries("packages.sis"); + this.modulesToSIEs = loadThreadsServiceInterfaceEntries("packages.sis"); } protected Map loadThreadsJava() { - return loadThreadsJava(modulesToSIEs, PACKAGE_NAME); + return loadThreadsJava(this.modulesToSIEs, PACKAGE_NAME); } @Test public void test_jmxImplModule() { - Map identitiesToSIs = new HashMap<>(); - Map modulesToSIEs = ServiceInterfaceEntry - .create(threadsModule, PACKAGE_NAME,identitiesToSIs); - modulesToSIEs.putAll(ServiceInterfaceEntry.create(jmxModule, + final Map identitiesToSIs = new HashMap<>(); + final Map modulesToSIEs = ServiceInterfaceEntry + .create(this.threadsModule, PACKAGE_NAME,identitiesToSIs); + modulesToSIEs.putAll(ServiceInterfaceEntry.create(this.jmxModule, PACKAGE_NAME,identitiesToSIs)); - Map namesToMBEs = ModuleMXBeanEntry - .create(jmxImplModule, modulesToSIEs, context, new TypeProviderWrapper(new TypeProviderImpl(context)) + final Map namesToMBEs = ModuleMXBeanEntry + .create(this.jmxImplModule, modulesToSIEs, this.context, new TypeProviderWrapper(new TypeProviderImpl(this.context)) , PACKAGE_NAME); - Map attributes = namesToMBEs.get("impl-netconf") + final Map attributes = namesToMBEs.get("impl-netconf") .getAttributes(); assertCorrectAttributesSize(namesToMBEs, attributes); // - DependencyAttribute threadFactoryAttribute = (DependencyAttribute) attributes + final DependencyAttribute threadFactoryAttribute = (DependencyAttribute) attributes .get("thread-factory"); assertNotNull(threadFactoryAttribute); assertFalse(threadFactoryAttribute.getDependency().isMandatory()); @@ -116,7 +105,7 @@ 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")); @@ -134,7 +123,7 @@ public class ModuleMXBeanEntryTest extends AbstractYangTest { protected RuntimeBeanEntry findFirstByYangName( final Collection runtimeBeans, final String yangName) { - for (RuntimeBeanEntry rb : runtimeBeans) { + for (final RuntimeBeanEntry rb : runtimeBeans) { if (yangName.equals(rb.getYangName())) { return rb; } @@ -143,6 +132,17 @@ public class ModuleMXBeanEntryTest extends AbstractYangTest { + " in " + runtimeBeans); } + protected RuntimeBeanEntry findFirstByNamePrefix(final Collection runtimeBeans, final String namePrefix) { + for (final 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", @@ -154,9 +154,9 @@ public class ModuleMXBeanEntryTest extends AbstractYangTest { } private void assertMatches(final String prefix, final String input) { - RevisionAwareXPath whenConstraint = mock(RevisionAwareXPath.class); + final RevisionAwareXPath whenConstraint = mock(RevisionAwareXPath.class); doReturn(input).when(whenConstraint).toString(); - Matcher output = ModuleMXBeanEntryBuilder.getWhenConditionMatcher(prefix, + final Matcher output = ModuleMXBeanEntryBuilder.getWhenConditionMatcher(prefix, whenConstraint); assertTrue(output.matches()); assertEquals("threadpool-dynamic", output.group(1)); @@ -164,40 +164,40 @@ public class ModuleMXBeanEntryTest extends AbstractYangTest { @Test public void testThreadsJava() { - Map namesToMBEs = loadThreadsJava(); + final Map namesToMBEs = loadThreadsJava(); { // check threadpool-dynamic - ModuleMXBeanEntry dynamicThreadPool = namesToMBEs + final ModuleMXBeanEntry dynamicThreadPool = namesToMBEs .get(THREADPOOL_DYNAMIC_MXB_NAME); - Map attributes = dynamicThreadPool + final Map attributes = dynamicThreadPool .getAttributes(); // core-size, keepalive, maximum-size // threadfactory - Set longAttribs = Sets.newHashSet("core-size", + final Set longAttribs = Sets.newHashSet("core-size", "maximum-size"); - for (String longAttrib : longAttribs) { + for (final String longAttrib : longAttribs) { - TypedAttribute attribute = (TypedAttribute) attributes + final TypedAttribute attribute = (TypedAttribute) attributes .get(longAttrib); assertThat("Failed to check " + longAttrib, attribute.getType(), is((Type) Types.typeForClass(Long.class))); } // check dependency on thread factory - QName threadfactoryQName = QName.create(THREADS_NAMESPACE, + final QName threadfactoryQName = QName.create(THREADS_NAMESPACE, THREADS_REVISION_DATE, "threadfactory"); - ServiceInterfaceEntry threadFactorySIEntry = modulesToSIEs + final ServiceInterfaceEntry threadFactorySIEntry = this.modulesToSIEs .get(threadfactoryQName); assertNotNull(threadFactorySIEntry); - boolean expectedMandatory = true; - TypedAttribute actualThreadFactory = (TypedAttribute) attributes + final boolean expectedMandatory = true; + final TypedAttribute actualThreadFactory = (TypedAttribute) attributes .get("threadfactory"); - DataSchemaNode mockedDataSchemaNode = mock(DataSchemaNode.class); + final DataSchemaNode mockedDataSchemaNode = mock(DataSchemaNode.class); doReturn(Collections.emptyList()).when(mockedDataSchemaNode) .getUnknownSchemaNodes(); doReturn(threadfactoryQName).when(mockedDataSchemaNode).getQName(); - AttributeIfc expectedDependencyAttribute = new DependencyAttribute( + final AttributeIfc expectedDependencyAttribute = new DependencyAttribute( mockedDataSchemaNode, threadFactorySIEntry, expectedMandatory, "threadfactory description"); assertThat(actualThreadFactory, is(expectedDependencyAttribute)); @@ -213,14 +213,14 @@ public class ModuleMXBeanEntryTest extends AbstractYangTest { is(THREADPOOL_DYNAMIC_MXB_NAME)); // check root runtime bean - Collection runtimeBeans = dynamicThreadPool + final Collection runtimeBeans = dynamicThreadPool .getRuntimeBeans(); assertThat(runtimeBeans.size(), is(1)); - RuntimeBeanEntry rootRB = findFirstByYangName(runtimeBeans, + final RuntimeBeanEntry rootRB = findFirstByYangName(runtimeBeans, THREADPOOL_DYNAMIC_MXB_NAME); assertThat(rootRB.isRoot(), is(true)); assertThat(rootRB.getAttributes().size(), is(1)); - JavaAttribute attribute = (JavaAttribute) rootRB.getAttributes() + final JavaAttribute attribute = (JavaAttribute) rootRB.getAttributes() .iterator().next(); assertThat(attribute.getAttributeYangName(), is("created-sessions")); assertThat(rootRB.getYangName(), is(THREADPOOL_DYNAMIC_MXB_NAME)); @@ -228,20 +228,20 @@ public class ModuleMXBeanEntryTest extends AbstractYangTest { is(Long.class.getName())); } {// check threadfactory-naming - ModuleMXBeanEntry threadFactoryNaming = namesToMBEs + final ModuleMXBeanEntry threadFactoryNaming = namesToMBEs .get(THREADFACTORY_NAMING_MXB_NAME); - Collection runtimeBeans = threadFactoryNaming + final Collection runtimeBeans = threadFactoryNaming .getRuntimeBeans(); assertThat(runtimeBeans.size(), is(4)); { - RuntimeBeanEntry threadRB = findFirstByYangName(runtimeBeans, + final RuntimeBeanEntry threadRB = findFirstByYangName(runtimeBeans, "thread"); assertNotNull(threadRB); assertFalse(threadRB.isRoot()); assertEquals("name", threadRB.getKeyYangName().get()); assertEquals("Name", threadRB.getKeyJavaName().get()); assertThat(threadRB.getAttributes().size(), is(1)); - AttributeIfc threadNameAttr = threadRB.getAttributes() + final AttributeIfc threadNameAttr = threadRB.getAttributes() .iterator().next(); assertThat(threadNameAttr.getAttributeYangName(), is("name")); assertTrue(threadNameAttr instanceof JavaAttribute); @@ -250,47 +250,47 @@ public class ModuleMXBeanEntryTest extends AbstractYangTest { assertThat(threadRB.getRpcs().size(), is(2)); } { - RuntimeBeanEntry streamRB = findFirstByYangName(runtimeBeans, - "stream"); + final RuntimeBeanEntry streamRB = findFirstByNamePrefix(runtimeBeans, + "ThreadStream"); assertNotNull(streamRB); assertFalse(streamRB.getKeyYangName().isPresent()); assertFalse(streamRB.getKeyJavaName().isPresent()); - Map attributeMap = streamRB + final Map attributeMap = streamRB .getYangPropertiesToTypesMap(); assertEquals(4, attributeMap.size()); - TOAttribute toAttr = (TOAttribute) attributeMap.get("peer"); + final TOAttribute toAttr = (TOAttribute) attributeMap.get("peer"); assertNotNull(toAttr); assertThat(toAttr.getAttributeYangName(), is("peer")); assertThat(toAttr.getLowerCaseCammelCase(), is("peer")); assertThat(toAttr.getUpperCaseCammelCase(), is("Peer")); - assertThat(toAttr.getOpenType(), is(CompositeType.class)); - Set propsExpected = new HashSet(2); + assertThat(toAttr.getOpenType(), isA(CompositeType.class)); + Set propsExpected = new HashSet<>(2); propsExpected.add("port"); propsExpected.add("core-size"); assertThat(toAttr.getYangPropertiesToTypesMap().keySet(), is(propsExpected)); - propsExpected = new HashSet(2); + propsExpected = new HashSet<>(2); propsExpected.add("Port"); propsExpected.add("CoreSize"); assertThat( toAttr.getCapitalizedPropertiesToTypesMap().keySet(), is(propsExpected)); - propsExpected = new HashSet(2); + propsExpected = new HashSet<>(2); propsExpected.add("port"); propsExpected.add("coreSize"); assertThat(toAttr.getJmxPropertiesToTypesMap().keySet(), is(propsExpected)); - JavaAttribute timestampAttr = (JavaAttribute) attributeMap + final JavaAttribute timestampAttr = (JavaAttribute) attributeMap .get("timestamp"); assertNotNull(timestampAttr); - JavaAttribute stateAttr = (JavaAttribute) attributeMap + final JavaAttribute stateAttr = (JavaAttribute) attributeMap .get("state"); assertNotNull(stateAttr); - ListAttribute innerStream = (ListAttribute) attributeMap + final ListAttribute innerStream = (ListAttribute) attributeMap .get("inner-stream-list"); assertNotNull(innerStream); assertThat(innerStream.getAttributeYangName(), @@ -299,19 +299,19 @@ public class ModuleMXBeanEntryTest extends AbstractYangTest { is("innerStreamList")); assertThat(innerStream.getUpperCaseCammelCase(), is("InnerStreamList")); - assertThat(innerStream.getOpenType(), is(ArrayType.class)); + assertThat(innerStream.getOpenType(), isA(ArrayType.class)); } } { // test multiple dependencies - ModuleMXBeanEntry threadPoolRegistry = namesToMBEs.get(THREADPOOL_REGISTRY_IMPL_NAME); - Map attributes = threadPoolRegistry.getAttributes(); + final ModuleMXBeanEntry threadPoolRegistry = namesToMBEs.get(THREADPOOL_REGISTRY_IMPL_NAME); + final Map attributes = threadPoolRegistry.getAttributes(); assertEquals(1, attributes.size()); - AttributeIfc threadpoolsAttr = attributes.get("threadpools"); + final AttributeIfc threadpoolsAttr = attributes.get("threadpools"); assertNotNull(threadpoolsAttr); assertTrue(threadpoolsAttr instanceof ListDependenciesAttribute); - ListDependenciesAttribute threadpools = (ListDependenciesAttribute) threadpoolsAttr; + final ListDependenciesAttribute threadpools = (ListDependenciesAttribute) threadpoolsAttr; } }