Search in sources :

Example 1 with EXPECTED_PACKAGE_PREFIX

use of org.opendaylight.controller.config.yangjmxgenerator.PackageTranslatorTest.EXPECTED_PACKAGE_PREFIX 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)

Aggregations

JavaParser (com.github.javaparser.JavaParser)1 ParseException (com.github.javaparser.ParseException)1 CompilationUnit (com.github.javaparser.ast.CompilationUnit)1 Collections2 (com.google.common.collect.Collections2)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Files (com.google.common.io.Files)1 File (java.io.File)1 IOException (java.io.IOException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 MavenProject (org.apache.maven.project.MavenProject)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1