X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-maven-plugin-it%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang2sources%2Fplugin%2Fit%2FYangToSourcesPluginTestIT.java;h=c27c926132f623714ef8b304762f9fab9f30f4b9;hb=ae14ac018999945d45c1f7568b32bb725808a254;hp=e2d889e78e58c5090c24151096279294621a7b70;hpb=458b176c7fbcbfa3f0911b5fe4657813d3071819;p=yangtools.git diff --git a/yang/yang-maven-plugin-it/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/it/YangToSourcesPluginTestIT.java b/yang/yang-maven-plugin-it/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/it/YangToSourcesPluginTestIT.java index e2d889e78e..c27c926132 100644 --- a/yang/yang-maven-plugin-it/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/it/YangToSourcesPluginTestIT.java +++ b/yang/yang-maven-plugin-it/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/it/YangToSourcesPluginTestIT.java @@ -12,16 +12,17 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; import com.google.common.base.Joiner; - +import com.google.common.io.Resources; import java.io.File; -import java.io.FileInputStream; +import java.io.IOException; import java.io.InputStream; import java.net.URISyntaxException; import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Arrays; -import java.util.List; +import java.util.Optional; import java.util.Properties; - import org.apache.maven.it.VerificationException; import org.apache.maven.it.Verifier; import org.junit.Test; @@ -32,110 +33,101 @@ public class YangToSourcesPluginTestIT { @Test public void testYangRootNotExist() throws Exception { - Verifier v = setUp("test-parent/YangRootNotExist/", false); - v.verifyTextInLog("[WARNING] yang-to-sources: YANG source directory"); + setUp("test-parent/YangRootNotExist/", false) + .verifyTextInLog("[WARNING] yang-to-sources: YANG source directory"); } @Test - public void testCorrect() throws Exception { - Verifier v = setUp("test-parent/Correct/", false); - verifyCorrectLog(v); + public void testCorrect() throws VerificationException, URISyntaxException, IOException { + verifyCorrectLog(setUp("test-parent/Correct/", false)); } @Test public void testAdditionalConfiguration() throws Exception { - Verifier v = setUp("test-parent/AdditionalConfig/", false); - v.verifyTextInLog("[DEBUG] yang-to-sources: Additional configuration picked up for : org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl: {nm1=abcd=a.b.c.d, nm2=abcd2=a.b.c.d.2}"); - v.verifyTextInLog("[DEBUG] yang-to-sources: Additional configuration picked up for : org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl: {c1=config}"); - v.verifyTextInLog(File.separator - + "files marked as resources: META-INF/yang"); - v.verifyTextInLog( - Joiner.on(File.separator).join( - Arrays.asList("target", "generated-sources", "spi")) - - + " marked as resources for generator: org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl"); + Verifier vrf = setUp("test-parent/AdditionalConfig/", false); + vrf.verifyTextInLog("[DEBUG] yang-to-sources: Additional configuration picked up for : " + + "org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl: " + + "{nm1=abcd=a.b.c.d, nm2=abcd2=a.b.c.d.2}"); + vrf.verifyTextInLog("[DEBUG] yang-to-sources: Additional configuration picked up for : " + + "org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl: {c1=config}"); + vrf.verifyTextInLog("[DEBUG] yang-to-sources: YANG files marked as resources:"); + vrf.verifyTextInLog(Joiner.on(File.separator).join(Arrays.asList("target", "generated-sources", "spi")) + + " marked as resources for generator: org.opendaylight.yangtools.yang2sources.spi." + + "CodeGeneratorTestImpl"); } @Test public void testMissingYangInDep() throws Exception { try { setUp("test-parent/MissingYangInDep/", false); + fail("Verification exception should have been thrown"); } catch (VerificationException e) { - assertVerificationException( - e, - "org.opendaylight.yangtools.yang.parser.util.YangValidationException: Not existing module imported:unknownDep:2013-02-27 by:private:2013-02-27"); + assertVerificationException(e, + "SchemaResolutionException{unsatisfiedImports={RevisionSourceIdentifier" + + " [name=private@2013-02-27]=[ModuleImportImpl" + + " [name=unknownDep, revision=2013-02-27, semanticVersion=0.0.0]]}"); return; } - - fail("Verification exception should have been thrown"); } - @Test - public void testNamingConflict() throws Exception { - Verifier v = setUp("test-parent/NamingConflict/", false); - v.verifyErrorFreeLog(); - String baseDir = v.getBasedir(); - String fileName = v.getLogFileName(); - List lines = v.loadFile(baseDir, fileName, false); - for (String s : lines) { - if (s.contains("conflict")) { - System.err.println(s); - } - } - v.verifyTextInLog("[WARNING] Naming conflict for type 'org.opendaylight.yang.gen.v1.urn.yang.test.rev140303.NetworkTopologyRef': file with same name already exists and will not be generated."); - } - - static void verifyCorrectLog(final Verifier v) throws VerificationException { - v.verifyErrorFreeLog(); - v.verifyTextInLog("[INFO] yang-to-sources: YANG files parsed from"); - v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl"); - v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl: null"); + static void verifyCorrectLog(final Verifier vrf) throws VerificationException { + vrf.verifyErrorFreeLog(); + vrf.verifyTextInLog("[INFO] yang-to-sources: Project model files parsed: "); + vrf.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from " + + "org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl"); + vrf.verifyTextInLog("[INFO] yang-to-sources: Sources generated by " + + "org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl: null"); } @Test public void testNoGenerators() throws Exception { - Verifier v = setUp("test-parent/NoGenerators/", false); - v.verifyErrorFreeLog(); - v.verifyTextInLog("[WARNING] yang-to-sources: No code generators provided"); + Verifier vrf = setUp("test-parent/NoGenerators/", false); + vrf.verifyErrorFreeLog(); + vrf.verifyTextInLog("[WARNING] yang-to-sources: No code generators provided"); } @Test public void testInvalidVersion() throws Exception { - Verifier v = setUp("test-parent/InvalidVersion/", false); - v.verifyErrorFreeLog(); - v.verifyTextInLog("[WARNING] yang-to-sources: Dependency resolution conflict:"); + Verifier vrf = setUp("test-parent/InvalidVersion/", false); + vrf.verifyErrorFreeLog(); + vrf.verifyTextInLog("[WARNING] yang-to-sources: Dependency resolution conflict:"); } @Test public void testUnknownGenerator() throws Exception { - Verifier v = setUp("test-parent/UnknownGenerator/", true); - v.verifyTextInLog("[ERROR] yang-to-sources: Unable to generate sources with unknown generator"); - v.verifyTextInLog("java.lang.ClassNotFoundException: unknown"); - v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl"); - v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl: null"); - v.verifyTextInLog("[ERROR] yang-to-sources: One or more code generators failed, including failed list(generatorClass=exception) {unknown=java.lang.ClassNotFoundException}"); + Verifier vrf = setUp("test-parent/UnknownGenerator/", true); + vrf.verifyTextInLog("[ERROR] yang-to-sources: Unable to generate sources with unknown generator"); + vrf.verifyTextInLog("java.lang.ClassNotFoundException: unknown"); + vrf.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from " + + "org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl"); + vrf.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.yangtools.yang2sources.spi." + + "CodeGeneratorTestImpl: null"); + vrf.verifyTextInLog("[ERROR] yang-to-sources: One or more code generators failed, including failed list" + + "(generatorClass=exception) {unknown=java.lang.ClassNotFoundException}"); } @Test public void testNoYangFiles() throws Exception { - Verifier v = setUp("test-parent/NoYangFiles/", false); - v.verifyTextInLog("[INFO] yang-to-sources: No input files found"); + setUp("test-parent/NoYangFiles/", false).verifyTextInLog("[INFO] yang-to-sources: No input files found"); } - static void assertVerificationException(final VerificationException e, - final String string) { - assertThat(e.getMessage(), containsString(string)); + static void assertVerificationException(final VerificationException ex, final String string) { + assertThat(ex.getMessage(), containsString(string)); } static Verifier setUp(final String project, final boolean ignoreF) - throws VerificationException, URISyntaxException { - final URL path = YangToSourcesPluginTestIT.class.getResource("/" - + project + "pom.xml"); - File parent = new File(path.toURI()); - Verifier verifier = new Verifier(parent.getParent()); + throws VerificationException, URISyntaxException, IOException { + final URL path = YangToSourcesPluginTestIT.class.getResource("/" + project + "pom.xml"); + final Verifier verifier = new Verifier(new File(path.toURI()).getParent()); if (ignoreF) { verifier.addCliOption("-fn"); } + + final Optional maybeSettings = getEffectiveSettingsXML(); + if (maybeSettings.isPresent()) { + verifier.addCliOption("-gs"); + verifier.addCliOption(maybeSettings.get()); + } verifier.setMavenDebug(true); verifier.executeGoal("generate-sources"); return verifier; @@ -143,42 +135,50 @@ public class YangToSourcesPluginTestIT { @Test public void testNoOutputDir() throws Exception { - Verifier v = YangToSourcesPluginTestIT.setUp("test-parent/NoOutputDir/", false); - verifyCorrectLog(v); + verifyCorrectLog(YangToSourcesPluginTestIT.setUp("test-parent/NoOutputDir/", false)); } @Test public void testFindResourceOnCp() throws Exception { - Verifier v1 = new Verifier(new File(getClass().getResource( - "/test-parent/GenerateTest1/pom.xml").toURI()).getParent()); + Verifier v1 = setUp("test-parent/GenerateTest1/", false); v1.executeGoal("clean"); v1.executeGoal("package"); - Properties sp = new Properties(); - try (InputStream is = new FileInputStream(v1.getBasedir() + "/it-project.properties")) { - sp.load(is); - } - String buildDir = sp.getProperty("target.dir"); - - v1.assertFilePresent(buildDir + "/classes/META-INF/yang/testfile1.yang"); - v1.assertFilePresent(buildDir + "/classes/META-INF/yang/testfile2.yang"); - v1.assertFilePresent(buildDir + "/classes/META-INF/yang/testfile3.yang"); + String buildDir = getMavenBuildDirectory(v1); + v1.assertFilePresent(buildDir + "/classes/META-INF/yang/types1@2013-02-27.yang"); + v1.assertFilePresent(buildDir + "/classes/META-INF/yang/types2@2013-02-27.yang"); + v1.assertFilePresent(buildDir + "/classes/META-INF/yang/types3@2013-02-27.yang"); - Verifier v2 = new Verifier(new File(getClass().getResource( - "/test-parent/GenerateTest2/pom.xml").toURI()).getParent()); + Verifier v2 = setUp("test-parent/GenerateTest2/", false); v2.executeGoal("clean"); v2.executeGoal("package"); - sp = new Properties(); - try (InputStream is = new FileInputStream(v2.getBasedir() + "/it-project.properties")) { + buildDir = getMavenBuildDirectory(v2); + v2.assertFilePresent(buildDir + "/classes/META-INF/yang/private@2013-02-27.yang"); + v2.assertFileNotPresent(buildDir + "/classes/META-INF/yang/types1@2013-02-27.yang"); + v2.assertFileNotPresent(buildDir + "/classes/META-INF/yang/types2@2013-02-27.yang"); + v2.assertFileNotPresent(buildDir + "/classes/META-INF/yang/types3@2013-02-27.yang"); + } + + private static String getMavenBuildDirectory(final Verifier verifier) throws IOException { + final Properties sp = new Properties(); + final Path path = new File(verifier.getBasedir() + "/it-project.properties").toPath(); + try (InputStream is = Files.newInputStream(path)) { sp.load(is); } - buildDir = sp.getProperty("target.dir"); - - v2.assertFilePresent(buildDir + "/classes/META-INF/yang/private.yang"); - v2.assertFileNotPresent(buildDir + "/classes/META-INF/yang/testfile1.yang"); - v2.assertFileNotPresent(buildDir + "/classes/META-INF/yang/testfile2.yang"); - v2.assertFileNotPresent(buildDir + "/classes/META-INF/yang/testfile3.yang"); + return sp.getProperty("target.dir"); } + private static Optional getEffectiveSettingsXML() throws URISyntaxException, VerificationException, + IOException { + final URL path = Resources.getResource(YangToSourcesPluginTestIT.class, "/test-parent/pom.xml"); + final File buildDir = new File(path.toURI()).getParentFile().getParentFile().getParentFile(); + final File effectiveSettingsXML = new File(buildDir, "effective-settings.xml"); + if (effectiveSettingsXML.exists()) { + return Optional.of(effectiveSettingsXML.getAbsolutePath()); + } + + fail(effectiveSettingsXML.getAbsolutePath()); + return Optional.empty(); + } }