X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fyang-jmx-generator-plugin%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyangjmxgenerator%2Fplugin%2FModuleMXBeanEntryPluginTest.java;fp=opendaylight%2Fconfig%2Fyang-jmx-generator-plugin%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyangjmxgenerator%2Fplugin%2FModuleMXBeanEntryPluginTest.java;h=b457216480b0ce062ddc5084a9e3c084e42aa11d;hp=0000000000000000000000000000000000000000;hb=9fb64948564e252018f9b1e13e7cea2c92f991aa;hpb=1742b3894614be478c333a1043ced8ef1bc5dc84 diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ModuleMXBeanEntryPluginTest.java b/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ModuleMXBeanEntryPluginTest.java new file mode 100644 index 0000000000..b457216480 --- /dev/null +++ b/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ModuleMXBeanEntryPluginTest.java @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.config.yangjmxgenerator.plugin; + +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.assertThat; + +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry; +import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntryTest; +import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry; +import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc; +import org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute; +import org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute; +import org.opendaylight.controller.config.yangjmxgenerator.attribute.TOAttribute; +import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.FtlTemplate; +import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.GeneralClassTemplate; +import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.GeneralInterfaceTemplate; +import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.TemplateFactory; +import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Method; + +public class ModuleMXBeanEntryPluginTest extends ModuleMXBeanEntryTest { + + @Test + public void testThreadsJavaPlugin() { + Map namesToMBEs = loadThreadsJava(); + {// check threadfactory-naming + ModuleMXBeanEntry threadFactoryNaming = namesToMBEs + .get(THREADFACTORY_NAMING_MXB_NAME); + Collection runtimeBeans = threadFactoryNaming + .getRuntimeBeans(); + assertThat(runtimeBeans.size(), is(4)); + // first one should be root + { + RuntimeBeanEntry rootRB = findFirstByYangName(runtimeBeans, + THREADFACTORY_NAMING_MXB_NAME); + assertThat(rootRB.isRoot(), is(true)); + assertThat(rootRB.getAttributes().size(), is(1)); + JavaAttribute attribute = (JavaAttribute) rootRB + .getAttributes().iterator().next(); + assertThat(attribute.getAttributeYangName(), + is("created-sessions")); + assertThat(rootRB.getYangName(), + is(THREADFACTORY_NAMING_MXB_NAME)); + Map ftlMap = TemplateFactory + .getTOAndMXInterfaceFtlFiles(rootRB); + assertThat(ftlMap.size(), is(1)); + GeneralInterfaceTemplate rootGeneratorInterface = (GeneralInterfaceTemplate) ftlMap + .get("NamingThreadFactoryRuntimeMXBean.java"); + assertNotNull(rootGeneratorInterface); + assertThat(rootGeneratorInterface.getPackageName(), + is(PACKAGE_NAME)); + assertThat(rootGeneratorInterface.getFullyQualifiedName(), + is(PACKAGE_NAME + ".NamingThreadFactoryRuntimeMXBean")); + assertThat( + rootGeneratorInterface.getTypeDeclaration() + .getExtended(), + is(Arrays + .asList("org.opendaylight.controller.config.api.runtime.RuntimeBean"))); + + assertThat(rootGeneratorInterface.getMethods().size(), is(1)); + Method getCreatedSessions = findFirstMethodByName( + rootGeneratorInterface.getMethods(), + "getCreatedSessions"); + assertThat(getCreatedSessions.getName(), + is("getCreatedSessions")); + assertThat(getCreatedSessions.getParameters().isEmpty(), + is(true)); + assertThat(getCreatedSessions.getReturnType(), + is(Long.class.getName())); + } + } + { + ModuleMXBeanEntry threadFactoryNaming = namesToMBEs + .get(THREADFACTORY_NAMING_MXB_NAME); + Collection runtimeBeans = threadFactoryNaming + .getRuntimeBeans(); + assertThat(runtimeBeans.size(), is(4)); + + { + RuntimeBeanEntry streamRB = findFirstByYangName(runtimeBeans, + "stream"); + assertNotNull(streamRB); + assertFalse(streamRB.getKeyYangName().isPresent()); + assertFalse(streamRB.getKeyJavaName().isPresent()); + Map attributeMap = streamRB + .getYangPropertiesToTypesMap(); + assertEquals(4, attributeMap.size()); + TOAttribute toAttr = (TOAttribute) attributeMap.get("peer"); + assertNotNull(toAttr); + JavaAttribute timestampAttr = (JavaAttribute) attributeMap + .get("timestamp"); + assertNotNull(timestampAttr); + JavaAttribute stateAttr = (JavaAttribute) attributeMap + .get("state"); + assertNotNull(stateAttr); + ListAttribute innerStreamList = (ListAttribute) attributeMap + .get("inner-stream-list"); + assertNotNull(innerStreamList); + + Map ftlMap = TemplateFactory + .getTOAndMXInterfaceFtlFiles(streamRB); + assertThat(ftlMap.size(), is(3)); + GeneralInterfaceTemplate streamGeneralInterface = (GeneralInterfaceTemplate) ftlMap + .get("ThreadStreamRuntimeMXBean.java"); + assertThat(streamGeneralInterface.getMethods().size(), is(4)); + Method getPeer = findFirstMethodByName( + streamGeneralInterface.getMethods(), "getPeer"); + assertNotNull(getPeer); + assertThat(getPeer.getReturnType(), is(PACKAGE_NAME + ".Peer")); + + // test TO + GeneralClassTemplate peerTO = (GeneralClassTemplate) ftlMap + .get("pack2.Peer"); + assertThat(peerTO.getPackageName(), is(PACKAGE_NAME)); + assertThat(peerTO.getTypeDeclaration().getExtended().isEmpty(), + is(true)); + assertThat(peerTO.getFullyQualifiedName(), is(PACKAGE_NAME + + ".Peer")); + assertThat(peerTO.getMethods().size(), is(4)); + Method getPort = findFirstMethodByName(peerTO.getMethods(), + "getPort"); + assertNotNull(getPort); + Method setPort = findFirstMethodByName(peerTO.getMethods(), + "setPort"); + assertNotNull(setPort); + Method getCoreSize = findFirstMethodByName(peerTO.getMethods(), + "getCoreSize"); + Method setCoreSize = findFirstMethodByName(peerTO.getMethods(), + "setCoreSize"); + assertNotNull(setCoreSize); + assertNotNull(getCoreSize); + + } + } + } + + private Method findFirstMethodByName(List methods, + String name) { + for (Method ms : methods) { + if (name.equals(ms.getName())) { + return ms; + } + } + throw new IllegalArgumentException("Method with given name not found"); + } +}