Search in sources :

Example 11 with ModuleFactory

use of org.opendaylight.controller.config.spi.ModuleFactory in project controller by opendaylight.

the class JMXGeneratorTest method generateMBEsTest.

@Test
public void generateMBEsTest() throws Exception {
    // default value for module factory file is true
    map.put(JMXGenerator.MODULE_FACTORY_FILE_BOOLEAN, "randomValue");
    jmxGenerator.setAdditionalConfig(map);
    Collection<File> files = jmxGenerator.generateSources(context, outputBaseDir, Collections.singleton(threadsJavaModule), m -> Optional.empty());
    assertEquals(expectedModuleFileNames, toFileNames(files));
    for (File file : files) {
        final String name = file.getName();
        if (!name.endsWith("java")) {
            continue;
        }
        MbeASTVisitor visitor = new MbeASTVisitor(EXPECTED_PACKAGE_PREFIX + ".threads.java", name);
        verifyFile(file, visitor);
        switch(name) {
            case "AbstractDynamicThreadPoolModule.java":
                assertAbstractDynamicThreadPoolModule(visitor);
                break;
            case "AsyncEventBusModuleMXBean.java":
                assertEquals("Incorrenct number of generated methods", 4, visitor.methods.size());
                break;
            case "AbstractNamingThreadFactoryModuleFactory.java":
                assertAbstractNamingThreadFactoryModuleFactory(visitor);
                break;
            case "AsyncEventBusModule.java":
                assertContains(visitor.extnds, EXPECTED_PACKAGE_PREFIX + ".threads.java.AbstractAsyncEventBusModule");
                visitor.assertFields(0);
                assertEquals("Incorrenct number of generated methods", 2, visitor.methods.size());
                visitor.assertConstructors(2);
                visitor.assertMethodDescriptions(0);
                visitor.assertMethodJavadocs(0);
                break;
            case "EventBusModuleFactory.java":
                assertContains(visitor.extnds, EXPECTED_PACKAGE_PREFIX + ".threads.java.AbstractEventBusModuleFactory");
                visitor.assertFields(0);
                assertEquals("Incorrenct number of generated methods", 0, visitor.methods.size());
                visitor.assertConstructors(0);
                visitor.assertMethodDescriptions(0);
                visitor.assertMethodJavadocs(0);
                break;
        }
    }
    verifyXmlFiles(Collections2.filter(files, input -> input.getName().endsWith("xml")));
    // verify ModuleFactory file
    File moduleFactoryFile = JMXGenerator.concatFolders(generatedResourcesDir, "META-INF", "services", ModuleFactory.class.getName());
    assertTrue(moduleFactoryFile.exists());
    Set<String> lines = ImmutableSet.copyOf(Files.readLines(moduleFactoryFile, StandardCharsets.UTF_8));
    Set<String> expectedLines = ImmutableSet.of(EXPECTED_PACKAGE_PREFIX + ".threads.java.EventBusModuleFactory", EXPECTED_PACKAGE_PREFIX + ".threads.java.AsyncEventBusModuleFactory", EXPECTED_PACKAGE_PREFIX + ".threads.java.DynamicThreadPoolModuleFactory", EXPECTED_PACKAGE_PREFIX + ".threads.java.NamingThreadFactoryModuleFactory", EXPECTED_PACKAGE_PREFIX + ".threads.java.ThreadPoolRegistryImplModuleFactory");
    assertEquals(expectedLines, lines);
}
Also used : ConfigConstants(org.opendaylight.controller.config.yangjmxgenerator.ConfigConstants) DynamicMBeanWithInstance(org.opendaylight.controller.config.api.DynamicMBeanWithInstance) HashMap(java.util.HashMap) ModuleFactory(org.opendaylight.controller.config.spi.ModuleFactory) Collections2(com.google.common.collect.Collections2) AbstractModule(org.opendaylight.controller.config.spi.AbstractModule) DependencyResolverFactory(org.opendaylight.controller.config.api.DependencyResolverFactory) ArrayList(java.util.ArrayList) Assert.assertThat(org.junit.Assert.assertThat) EXPECTED_PACKAGE_PREFIX(org.opendaylight.controller.config.yangjmxgenerator.PackageTranslatorTest.EXPECTED_PACKAGE_PREFIX) ErrorHandler(org.xml.sax.ErrorHandler) ParseException(com.github.javaparser.ParseException) Files(com.google.common.io.Files) MavenProject(org.apache.maven.project.MavenProject) Assert.fail(org.junit.Assert.fail) ServiceInterfaceEntryTest(org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntryTest) CompilationUnit(com.github.javaparser.ast.CompilationUnit) Mockito.doReturn(org.mockito.Mockito.doReturn) Before(org.junit.Before) InputSource(org.xml.sax.InputSource) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ImmutableSet(com.google.common.collect.ImmutableSet) Module(org.opendaylight.controller.config.spi.Module) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) IOException(java.io.IOException) Test(org.junit.Test) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) BundleContext(org.osgi.framework.BundleContext) List(java.util.List) SAXParseException(org.xml.sax.SAXParseException) DependencyResolver(org.opendaylight.controller.config.api.DependencyResolver) Assert.assertFalse(org.junit.Assert.assertFalse) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXException(org.xml.sax.SAXException) Optional(java.util.Optional) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) JavaParser(com.github.javaparser.JavaParser) ModuleFactory(org.opendaylight.controller.config.spi.ModuleFactory) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File) ServiceInterfaceEntryTest(org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntryTest) Test(org.junit.Test)

Example 12 with ModuleFactory

use of org.opendaylight.controller.config.spi.ModuleFactory in project controller by opendaylight.

the class DependencyResolverManagerTest method mockGetInstance.

private static void mockGetInstance(final DependencyResolverManager tested, final ModuleIdentifier moduleIdentifier) {
    ModuleFactory moduleFactory = mock(ModuleFactory.class);
    ModuleInternalInfo maybeOldInternalInfo = null;
    TransactionModuleJMXRegistration transactionModuleJMXRegistration = null;
    boolean isDefaultBean = false;
    tested.put(moduleIdentifier, mockedModule(), moduleFactory, maybeOldInternalInfo, transactionModuleJMXRegistration, isDefaultBean, mock(BundleContext.class));
}
Also used : ModuleFactory(org.opendaylight.controller.config.spi.ModuleFactory) TransactionModuleJMXRegistration(org.opendaylight.controller.config.manager.impl.jmx.TransactionModuleJMXRegistrator.TransactionModuleJMXRegistration) ModuleInternalInfo(org.opendaylight.controller.config.manager.impl.ModuleInternalInfo) BundleContext(org.osgi.framework.BundleContext)

Example 13 with ModuleFactory

use of org.opendaylight.controller.config.spi.ModuleFactory in project controller by opendaylight.

the class BundleContextBackedModuleFactoriesResolverTest method getMockFactory.

private static ModuleFactory getMockFactory(final String name) {
    ModuleFactory mock = mock(ModuleFactory.class);
    doReturn(name).when(mock).toString();
    doReturn(name).when(mock).getImplementationName();
    return mock;
}
Also used : ModuleFactory(org.opendaylight.controller.config.spi.ModuleFactory)

Aggregations

ModuleFactory (org.opendaylight.controller.config.spi.ModuleFactory)13 BundleContext (org.osgi.framework.BundleContext)8 DependencyResolver (org.opendaylight.controller.config.api.DependencyResolver)4 ModuleIdentifier (org.opendaylight.controller.config.api.ModuleIdentifier)4 AbstractModule (org.opendaylight.controller.config.spi.AbstractModule)4 Module (org.opendaylight.controller.config.spi.Module)4 HashMap (java.util.HashMap)3 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)3 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 InstanceNotFoundException (javax.management.InstanceNotFoundException)2 ObjectName (javax.management.ObjectName)2 Test (org.junit.Test)2 ConfigRegistryImpl (org.opendaylight.controller.config.manager.impl.ConfigRegistryImpl)2 JavaParser (com.github.javaparser.JavaParser)1 ParseException (com.github.javaparser.ParseException)1 CompilationUnit (com.github.javaparser.ast.CompilationUnit)1