Search in sources :

Example 1 with ModuleMXBeanEntry

use of org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry in project controller by opendaylight.

the class ModuleMXBeanEntryTemplatesTest method mockMbe.

public static ModuleMXBeanEntry mockMbe(final String packageName) {
    final ModuleMXBeanEntry mbe = mock(ModuleMXBeanEntry.class);
    final Map<String, AttributeIfc> a = Maps.newHashMap();
    final JavaAttribute attr = mockJavaAttr();
    a.put("attr1", attr);
    doReturn(a).when(mbe).getAttributes();
    doReturn(packageName).when(mbe).getPackageName();
    doReturn(Collections.emptyMap()).when(mbe).getProvidedServices();
    doReturn("yang-module").when(mbe).getYangModuleName();
    doReturn("local").when(mbe).getYangModuleLocalname();
    doReturn("AbstractType").when(mbe).getAbstractFactoryName();
    doReturn("Module").when(mbe).getStubModuleName();
    doReturn("fullA").when(mbe).getFullyQualifiedName(anyString());
    doReturn("uniq").when(mbe).getGloballyUniqueName();
    return mbe;
}
Also used : ModuleMXBeanEntry(org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry) AttributeIfc(org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc) Matchers.anyString(org.mockito.Matchers.anyString) JavaAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute)

Example 2 with ModuleMXBeanEntry

use of org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry in project controller by opendaylight.

the class ConcreteModuleGeneratedObjectFactoryTest method test.

@Test
public void test() throws Exception {
    FullyQualifiedName fqn = new FullyQualifiedName("foo.bar", "Baz");
    FullyQualifiedName abstractFQN = new FullyQualifiedName("foo.bar", "AbstractBaz");
    String nullableDescription = null;
    ModuleMXBeanEntry moduleMXBeanEntry = mockModuleMXBeanEntry(fqn, abstractFQN, nullableDescription);
    Optional<String> copyright = Optional.absent();
    Optional<String> header = Optional.absent();
    GeneratedObject go = new ConcreteModuleGeneratedObjectFactory().toGeneratedObject(moduleMXBeanEntry, copyright, header);
    Entry<FullyQualifiedName, File> entry = go.persist(generatorOutputPath).get();
    File dstFile = entry.getValue();
    Node c = parse(dstFile);
    assertEquals(fqn.getPackageName(), ((ASTCompilationUnit) c).getPackageDeclaration().getPackageNameImage());
    assertEquals(fqn.getTypeName(), c.getFirstDescendantOfType(ASTClassOrInterfaceDeclaration.class).getImage());
    assertHasMethodNamed(c, "customValidation");
    assertHasMethodNamed(c, "createInstance");
}
Also used : ConcreteModuleGeneratedObjectFactory(org.opendaylight.controller.config.yangjmxgenerator.plugin.gofactory.ConcreteModuleGeneratedObjectFactory) ASTCompilationUnit(net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit) ModuleMXBeanEntry(org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry) Node(net.sourceforge.pmd.lang.ast.Node) FullyQualifiedName(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName) GeneratedObject(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObject) File(java.io.File) AbstractGeneratedObjectTest(org.opendaylight.controller.config.yangjmxgenerator.plugin.module.AbstractGeneratedObjectTest) Test(org.junit.Test)

Example 3 with ModuleMXBeanEntry

use of org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry in project controller by opendaylight.

the class ConcreteModuleGeneratedObjectFactoryTest method mockModuleMXBeanEntry.

static ModuleMXBeanEntry mockModuleMXBeanEntry(FullyQualifiedName fqn, FullyQualifiedName abstractFQN, String nullableDescription) {
    ModuleMXBeanEntry mock = mock(ModuleMXBeanEntry.class);
    assertEquals(fqn.getPackageName(), abstractFQN.getPackageName());
    doReturn(fqn.getPackageName()).when(mock).getPackageName();
    doReturn(fqn.getTypeName()).when(mock).getStubModuleName();
    doReturn(nullableDescription).when(mock).getNullableDescription();
    doReturn(abstractFQN.getTypeName()).when(mock).getAbstractModuleName();
    return mock;
}
Also used : ModuleMXBeanEntry(org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry)

Example 4 with ModuleMXBeanEntry

use of org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry in project controller by opendaylight.

the class ConfigSubsystemFacade method transformMbeToModuleConfigs.

public Map<String, /* Namespace from yang file */
Map<String, /* Name of module entry from yang file */
ModuleConfig>> transformMbeToModuleConfigs(final BeanReader reader, final Map<String, /* Namespace from yang file */
Map<String, /* Name of module entry from yang file */
ModuleMXBeanEntry>> mbeanentries) {
    Map<String, Map<String, ModuleConfig>> namespaceToModuleNameToModuleConfig = new HashMap<>();
    for (Map.Entry<String, Map<String, ModuleMXBeanEntry>> namespaceToModuleToMbe : mbeanentries.entrySet()) {
        for (Map.Entry<String, ModuleMXBeanEntry> moduleNameToMbe : namespaceToModuleToMbe.getValue().entrySet()) {
            String moduleName = moduleNameToMbe.getKey();
            ModuleMXBeanEntry moduleMXBeanEntry = moduleNameToMbe.getValue();
            ModuleConfig moduleConfig = new ModuleConfig(moduleName, new InstanceConfig(reader, moduleMXBeanEntry.getAttributes(), moduleMXBeanEntry.getNullableDummyContainerName()));
            Map<String, ModuleConfig> moduleNameToModuleConfig = namespaceToModuleNameToModuleConfig.computeIfAbsent(namespaceToModuleToMbe.getKey(), k -> new HashMap<>());
            moduleNameToModuleConfig.put(moduleName, moduleConfig);
        }
    }
    return namespaceToModuleNameToModuleConfig;
}
Also used : InstanceConfig(org.opendaylight.controller.config.facade.xml.mapping.config.InstanceConfig) HashMap(java.util.HashMap) ModuleMXBeanEntry(org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry) ModuleConfig(org.opendaylight.controller.config.facade.xml.mapping.config.ModuleConfig) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with ModuleMXBeanEntry

use of org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry in project controller by opendaylight.

the class ConfigSubsystemFacade method createModuleRuntimes.

private Map<String, Map<String, ModuleRuntime>> createModuleRuntimes(final ConfigRegistryClient client, final Map<String, Map<String, ModuleMXBeanEntry>> mbeanentries) {
    Map<String, Map<String, ModuleRuntime>> retVal = new HashMap<>();
    for (Map.Entry<String, Map<String, ModuleMXBeanEntry>> namespaceToModuleEntry : mbeanentries.entrySet()) {
        Map<String, ModuleRuntime> innerMap = new HashMap<>();
        Map<String, ModuleMXBeanEntry> entriesFromNamespace = namespaceToModuleEntry.getValue();
        for (Map.Entry<String, ModuleMXBeanEntry> moduleToMXEntry : entriesFromNamespace.entrySet()) {
            ModuleMXBeanEntry mbe = moduleToMXEntry.getValue();
            Map<RuntimeBeanEntry, InstanceConfig> cache = new HashMap<>();
            RuntimeBeanEntry root = null;
            for (RuntimeBeanEntry rbe : mbe.getRuntimeBeans()) {
                cache.put(rbe, new InstanceConfig(client, rbe.getYangPropertiesToTypesMap(), mbe.getNullableDummyContainerName()));
                if (rbe.isRoot()) {
                    root = rbe;
                }
            }
            if (root == null) {
                continue;
            }
            InstanceRuntime rootInstanceRuntime = createInstanceRuntime(root, cache);
            ModuleRuntime moduleRuntime = new ModuleRuntime(rootInstanceRuntime);
            innerMap.put(moduleToMXEntry.getKey(), moduleRuntime);
        }
        retVal.put(namespaceToModuleEntry.getKey(), innerMap);
    }
    return retVal;
}
Also used : InstanceRuntime(org.opendaylight.controller.config.facade.xml.runtime.InstanceRuntime) HashMap(java.util.HashMap) RuntimeBeanEntry(org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry) InstanceConfig(org.opendaylight.controller.config.facade.xml.mapping.config.InstanceConfig) ModuleMXBeanEntry(org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry) ModuleRuntime(org.opendaylight.controller.config.facade.xml.runtime.ModuleRuntime) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ModuleMXBeanEntry (org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry)10 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 Map (java.util.Map)3 RuntimeBeanEntry (org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry)3 File (java.io.File)2 InstanceConfig (org.opendaylight.controller.config.facade.xml.mapping.config.InstanceConfig)2 ServiceInterfaceEntry (org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntry)2 AttributeIfc (org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc)2 JavaAttribute (org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute)2 AbstractGeneratedObjectTest (org.opendaylight.controller.config.yangjmxgenerator.plugin.module.AbstractGeneratedObjectTest)2 QName (org.opendaylight.yangtools.yang.common.QName)2 IOException (java.io.IOException)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 Node (net.sourceforge.pmd.lang.ast.Node)1 ASTCompilationUnit (net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit)1 Matchers.anyString (org.mockito.Matchers.anyString)1 ModuleConfig (org.opendaylight.controller.config.facade.xml.mapping.config.ModuleConfig)1 ModuleRpcs (org.opendaylight.controller.config.facade.xml.rpc.ModuleRpcs)1