Search in sources :

Example 6 with JavaAttribute

use of org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute in project controller by opendaylight.

the class ModuleMXBeanEntryTemplatesTest method mockJavaAttr.

public static JavaAttribute mockJavaAttr() {
    final JavaAttribute attr = mock(JavaAttribute.class);
    final Type typeA = mock(Type.class);
    doReturn("package").when(typeA).getName();
    doReturn("type").when(typeA).getPackageName();
    doReturn("package.type").when(typeA).getFullyQualifiedName();
    doReturn(typeA).when(attr).getType();
    doReturn("Type").when(attr).getUpperCaseCammelCase();
    doReturn("new Default()").when(attr).getNullableDefault();
    return attr;
}
Also used : Type(org.opendaylight.mdsal.binding.model.api.Type) JavaAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute)

Example 7 with JavaAttribute

use of org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute in project controller by opendaylight.

the class ModuleMXBeanEntryTest method testThreadsJava.

@Test
public void testThreadsJava() {
    final Map<String, ModuleMXBeanEntry> /* identity local name */
    namesToMBEs = loadThreadsJava();
    {
        // check threadpool-dynamic
        final ModuleMXBeanEntry dynamicThreadPool = namesToMBEs.get(THREADPOOL_DYNAMIC_MXB_NAME);
        final Map<String, AttributeIfc> attributes = dynamicThreadPool.getAttributes();
        // core-size, keepalive, maximum-size
        // threadfactory
        final Set<String> longAttribs = Sets.newHashSet("core-size", "maximum-size");
        for (final String longAttrib : longAttribs) {
            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
        final QName threadfactoryQName = QName.create(THREADS_NAMESPACE, THREADS_REVISION_DATE, "threadfactory");
        final ServiceInterfaceEntry threadFactorySIEntry = this.modulesToSIEs.get(threadfactoryQName);
        assertNotNull(threadFactorySIEntry);
        final boolean expectedMandatory = true;
        final TypedAttribute actualThreadFactory = (TypedAttribute) attributes.get("threadfactory");
        final DataSchemaNode mockedDataSchemaNode = mock(DataSchemaNode.class);
        doReturn(Collections.emptyList()).when(mockedDataSchemaNode).getUnknownSchemaNodes();
        doReturn(threadfactoryQName).when(mockedDataSchemaNode).getQName();
        final AttributeIfc expectedDependencyAttribute = new DependencyAttribute(mockedDataSchemaNode, threadFactorySIEntry, expectedMandatory, "threadfactory description");
        assertThat(actualThreadFactory, is(expectedDependencyAttribute));
        assertThat(dynamicThreadPool.getFullyQualifiedName("DynamicThreadPoolModuleMXBean"), is(PACKAGE_NAME + ".DynamicThreadPoolModuleMXBean"));
        assertThat(dynamicThreadPool.getNullableDescription(), is("threadpool-dynamic description"));
        assertThat(dynamicThreadPool.getYangModuleName(), is("config-threads-java"));
        assertThat(dynamicThreadPool.getYangModuleLocalname(), is(THREADPOOL_DYNAMIC_MXB_NAME));
        // check root runtime bean
        final Collection<RuntimeBeanEntry> runtimeBeans = dynamicThreadPool.getRuntimeBeans();
        assertThat(runtimeBeans.size(), is(1));
        final RuntimeBeanEntry rootRB = findFirstByYangName(runtimeBeans, THREADPOOL_DYNAMIC_MXB_NAME);
        assertThat(rootRB.isRoot(), is(true));
        assertThat(rootRB.getAttributes().size(), is(1));
        final JavaAttribute attribute = (JavaAttribute) rootRB.getAttributes().iterator().next();
        assertThat(attribute.getAttributeYangName(), is("created-sessions"));
        assertThat(rootRB.getYangName(), is(THREADPOOL_DYNAMIC_MXB_NAME));
        assertThat(attribute.getType().getFullyQualifiedName(), is(Long.class.getName()));
    }
    {
        // check threadfactory-naming
        final ModuleMXBeanEntry threadFactoryNaming = namesToMBEs.get(THREADFACTORY_NAMING_MXB_NAME);
        final Collection<RuntimeBeanEntry> runtimeBeans = threadFactoryNaming.getRuntimeBeans();
        assertThat(runtimeBeans.size(), is(4));
        {
            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));
            final AttributeIfc threadNameAttr = threadRB.getAttributes().iterator().next();
            assertThat(threadNameAttr.getAttributeYangName(), is("name"));
            assertTrue(threadNameAttr instanceof JavaAttribute);
            assertThat(((JavaAttribute) threadNameAttr).getType().getFullyQualifiedName(), is(String.class.getName()));
            assertThat(threadRB.getRpcs().size(), is(2));
        }
        {
            final RuntimeBeanEntry streamRB = findFirstByNamePrefix(runtimeBeans, "ThreadStream");
            assertNotNull(streamRB);
            assertFalse(streamRB.getKeyYangName().isPresent());
            assertFalse(streamRB.getKeyJavaName().isPresent());
            final Map<String, AttributeIfc> attributeMap = streamRB.getYangPropertiesToTypesMap();
            assertEquals(4, attributeMap.size());
            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(), isA(CompositeType.class));
            Set<String> propsExpected = new HashSet<>(2);
            propsExpected.add("port");
            propsExpected.add("core-size");
            assertThat(toAttr.getYangPropertiesToTypesMap().keySet(), is(propsExpected));
            propsExpected = new HashSet<>(2);
            propsExpected.add("Port");
            propsExpected.add("CoreSize");
            assertThat(toAttr.getCapitalizedPropertiesToTypesMap().keySet(), is(propsExpected));
            propsExpected = new HashSet<>(2);
            propsExpected.add("port");
            propsExpected.add("coreSize");
            assertThat(toAttr.getJmxPropertiesToTypesMap().keySet(), is(propsExpected));
            final JavaAttribute timestampAttr = (JavaAttribute) attributeMap.get("timestamp");
            assertNotNull(timestampAttr);
            final JavaAttribute stateAttr = (JavaAttribute) attributeMap.get("state");
            assertNotNull(stateAttr);
            final ListAttribute innerStream = (ListAttribute) attributeMap.get("inner-stream-list");
            assertNotNull(innerStream);
            assertThat(innerStream.getAttributeYangName(), is("inner-stream-list"));
            assertThat(innerStream.getLowerCaseCammelCase(), is("innerStreamList"));
            assertThat(innerStream.getUpperCaseCammelCase(), is("InnerStreamList"));
            assertThat(innerStream.getOpenType(), isA(ArrayType.class));
        }
    }
    {
        // test multiple dependencies
        final ModuleMXBeanEntry threadPoolRegistry = namesToMBEs.get(THREADPOOL_REGISTRY_IMPL_NAME);
        final Map<String, AttributeIfc> attributes = threadPoolRegistry.getAttributes();
        assertEquals(1, attributes.size());
        final AttributeIfc threadpoolsAttr = attributes.get("threadpools");
        assertNotNull(threadpoolsAttr);
        assertTrue(threadpoolsAttr instanceof ListDependenciesAttribute);
        final ListDependenciesAttribute threadpools = (ListDependenciesAttribute) threadpoolsAttr;
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) TypedAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.TypedAttribute) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) QName(org.opendaylight.yangtools.yang.common.QName) ListDependenciesAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.ListDependenciesAttribute) TOAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.TOAttribute) ArrayType(javax.management.openmbean.ArrayType) DependencyAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.DependencyAttribute) AttributeIfc(org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) JavaAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute) ListAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute) CompositeType(javax.management.openmbean.CompositeType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with JavaAttribute

use of org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute in project controller by opendaylight.

the class RuntimeBeanEntryTest method runtimeBeanRPCTest.

@Test
public void runtimeBeanRPCTest() {
    // create service interfaces
    final Map<QName, ServiceInterfaceEntry> modulesToSIEs = ServiceInterfaceEntry.create(this.threadsModule, "packages.sis", identitiesToSIs);
    assertNotNull(modulesToSIEs);
    // create MXBeans map
    final Map<String, ModuleMXBeanEntry> namesToMBEs = ModuleMXBeanEntry.create(this.threadsJavaModule, modulesToSIEs, this.context, new TypeProviderWrapper(new TypeProviderImpl(this.context)), PACKAGE_NAME);
    assertFalse(namesToMBEs.isEmpty());
    // get threadfactory-naming bean
    final ModuleMXBeanEntry threadfactoryNamingMXBean = namesToMBEs.get(THREADFACTORY_NAMING_MXB_NAME);
    assertNotNull(threadfactoryNamingMXBean);
    // get runtime beans
    final Collection<RuntimeBeanEntry> runtimeBeanEntries = threadfactoryNamingMXBean.getRuntimeBeans();
    assertFalse(runtimeBeanEntries.isEmpty());
    // get root runtime bean
    final RuntimeBeanEntry threadfactoryRuntimeBeanEntry = getRuntimeBeanEntryByJavaName(runtimeBeanEntries, "NamingThreadFactoryRuntimeMXBean");
    assertNotNull(threadfactoryRuntimeBeanEntry);
    assertTrue(threadfactoryRuntimeBeanEntry.isRoot());
    // get thread runtime bean
    final RuntimeBeanEntry runtimeBeanEntry = getRuntimeBeanEntryByJavaName(runtimeBeanEntries, THREAD_RUNTIME_BEAN_JAVA_NAME);
    assertNotNull(runtimeBeanEntry);
    // test thread runtime bean properties
    assertEquals(THREAD_RUNTIME_BEAN_JAVA_PREFIX, runtimeBeanEntry.getJavaNamePrefix());
    assertEquals(PACKAGE_NAME, runtimeBeanEntry.getPackageName());
    assertEquals(PACKAGE_NAME + "." + THREAD_RUNTIME_BEAN_JAVA_NAME, runtimeBeanEntry.getFullyQualifiedName(runtimeBeanEntry.getJavaNameOfRuntimeMXBean()));
    assertEquals(THREAD_RUNTIME_BEAN_YANG_NAME, runtimeBeanEntry.getYangName());
    // get thread runtime bean rpcs
    final List<RuntimeBeanEntry.Rpc> rpcs = new ArrayList<>(runtimeBeanEntry.getRpcs());
    assertEquals(2, rpcs.size());
    // get sleep rpc and test it
    final RuntimeBeanEntry.Rpc rpc = getRpcByName(rpcs, SLEEP_RPC_NAME);
    assertNotNull(rpc);
    assertEquals(SLEEP_RPC_NAME, rpc.getYangName());
    assertTrue(((JavaAttribute) rpc.getReturnType()).getType().getFullyQualifiedName().endsWith(SLEEP_RPC_OUTPUT));
    // get sleep rpc input attribute and test it
    final List<JavaAttribute> attributes = rpc.getParameters();
    assertEquals(1, attributes.size());
    final JavaAttribute attribute = attributes.get(0);
    assertEquals(SLEEP_RPC_INPUT_NAME, attribute.getAttributeYangName());
    assertEquals(SLEEP_RPC_INPUT_TYPE, attribute.getType().getName());
    assertEquals(SLEEP_RPC_INPUT_NAME, attribute.getLowerCaseCammelCase());
    assertEquals("Millis", attribute.getUpperCaseCammelCase());
    assertNull(attribute.getNullableDefault());
    assertNull(attribute.getNullableDescription());
    assertTrue(attribute.getOpenType() instanceof SimpleType);
}
Also used : QName(org.opendaylight.yangtools.yang.common.QName) ArrayList(java.util.ArrayList) SimpleType(javax.management.openmbean.SimpleType) TypeProviderImpl(org.opendaylight.mdsal.binding.yang.types.TypeProviderImpl) JavaAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute) Test(org.junit.Test)

Aggregations

JavaAttribute (org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute)8 AttributeIfc (org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc)6 ListAttribute (org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 TOAttribute (org.opendaylight.controller.config.yangjmxgenerator.attribute.TOAttribute)3 QName (org.opendaylight.yangtools.yang.common.QName)3 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 SimpleType (javax.management.openmbean.SimpleType)2 ModuleMXBeanEntry (org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry)2 Rpc (org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry.Rpc)2 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)2 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 ArrayType (javax.management.openmbean.ArrayType)1 CompositeType (javax.management.openmbean.CompositeType)1 Matchers.anyString (org.mockito.Matchers.anyString)1