Search in sources :

Example 1 with Method

use of org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Method in project controller by opendaylight.

the class GenericGeneratedObjectFactory method toGeneratedObject.

public GeneratedObject toGeneratedObject(FtlTemplate template, Optional<String> copyright) {
    JavaFileInputBuilder b = new JavaFileInputBuilder();
    b.setHeader(template.getHeaderString());
    b.setFqn(new FullyQualifiedName(template.getPackageName(), template.getTypeDeclaration().getName()));
    b.setClassJavaDoc(template.getMaybeJavadoc());
    for (Annotation annotation : template.getAnnotations()) {
        b.addClassAnnotation(annotation);
    }
    // type declaration
    for (String extended : template.getTypeDeclaration().getExtended()) {
        b.addExtendsFQN(FullyQualifiedName.fromString(extended));
    }
    for (String implemented : template.getTypeDeclaration().getImplemented()) {
        b.addImplementsFQN(FullyQualifiedName.fromString(implemented));
    }
    b.setCopyright(copyright);
    b.setTypeName(template.getTypeDeclaration().toTypeName());
    // fields
    for (Field field : template.getFields()) {
        b.addToBody(field.toString());
    }
    // constructors
    for (Constructor constructor : template.getConstructors()) {
        b.addToBody(constructor.toString());
    }
    // methods
    for (Method method : template.getMethods()) {
        b.addToBody(method.toString());
    }
    return new GeneratedObjectBuilder(b.build()).toGeneratedObject();
}
Also used : Field(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field) Constructor(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Constructor) GeneratedObjectBuilder(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObjectBuilder) FullyQualifiedName(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName) Method(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Method) Annotation(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Annotation) JavaFileInputBuilder(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.JavaFileInputBuilder)

Example 2 with Method

use of org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Method in project controller by opendaylight.

the class ModuleMXBeanEntryPluginTest method testThreadsJavaPlugin.

@Test
public void testThreadsJavaPlugin() {
    Map<String, ModuleMXBeanEntry> /* identity local name */
    namesToMBEs = loadThreadsJava();
    {
        // check threadfactory-naming
        ModuleMXBeanEntry threadFactoryNaming = namesToMBEs.get(THREADFACTORY_NAMING_MXB_NAME);
        Collection<RuntimeBeanEntry> 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<String, FtlTemplate> 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<RuntimeBeanEntry> runtimeBeans = threadFactoryNaming.getRuntimeBeans();
        assertThat(runtimeBeans.size(), is(4));
        {
            RuntimeBeanEntry streamRB = findFirstByNamePrefix(runtimeBeans, "ThreadStream");
            assertNotNull(streamRB);
            assertFalse(streamRB.getKeyYangName().isPresent());
            assertFalse(streamRB.getKeyJavaName().isPresent());
            Map<String, AttributeIfc> 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<String, FtlTemplate> 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(5 + 2));
            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);
        }
    }
}
Also used : GeneralInterfaceTemplate(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.GeneralInterfaceTemplate) RuntimeBeanEntry(org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry) GeneralClassTemplate(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.GeneralClassTemplate) Method(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Method) TOAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.TOAttribute) ModuleMXBeanEntry(org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry) Collection(java.util.Collection) AttributeIfc(org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc) FtlTemplate(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.FtlTemplate) JavaAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute) ListAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute) Test(org.junit.Test) ModuleMXBeanEntryTest(org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntryTest)

Aggregations

Method (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Method)2 Collection (java.util.Collection)1 Test (org.junit.Test)1 ModuleMXBeanEntry (org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry)1 ModuleMXBeanEntryTest (org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntryTest)1 RuntimeBeanEntry (org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry)1 AttributeIfc (org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc)1 JavaAttribute (org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute)1 ListAttribute (org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute)1 TOAttribute (org.opendaylight.controller.config.yangjmxgenerator.attribute.TOAttribute)1 FtlTemplate (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.FtlTemplate)1 GeneralClassTemplate (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.GeneralClassTemplate)1 GeneralInterfaceTemplate (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.GeneralInterfaceTemplate)1 Annotation (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Annotation)1 Constructor (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Constructor)1 Field (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field)1 FullyQualifiedName (org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName)1 GeneratedObjectBuilder (org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObjectBuilder)1 JavaFileInputBuilder (org.opendaylight.controller.config.yangjmxgenerator.plugin.java.JavaFileInputBuilder)1