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=5015100ca26817fe33e1cf6a79a2be7b58d504e6;hb=refs%2Fheads%2Fstable%2Fberyllium;hp=feb051e820b84e5b9f7a96ca0de4664c4693eca1;hpb=9f3c936d2eb7f933d15b78a4211ed3afcec3c927;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 feb051e820..5015100ca2 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 @@ -7,78 +7,78 @@ */ package org.opendaylight.yangtools.yang2sources.plugin.it; +import static org.hamcrest.CoreMatchers.containsString; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; -import static org.junit.matchers.JUnitMatchers.containsString; - +import com.google.common.base.Joiner; 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.util.Arrays; +import java.util.List; import java.util.Properties; - import org.apache.maven.it.VerificationException; import org.apache.maven.it.Verifier; import org.junit.BeforeClass; import org.junit.Test; public class YangToSourcesPluginTestIT { - private static final String SRC_PROPERTIES = "target/it-project.properties"; - private static final String VERSION_PROP = "it-project.version"; - private static Properties props; + private static String GLOBAL_SETTINGS_OVERRIDE; + private static String USER_SETTINGS_OVERRIDE; + + @BeforeClass + public static void setupClass() { + // OpenDaylight Jenkins does not have settings at the default path, pick file locations from environment + GLOBAL_SETTINGS_OVERRIDE = System.getenv("GLOBAL_SETTINGS_FILE"); + USER_SETTINGS_OVERRIDE = System.getenv("SETTINGS_FILE"); + } // TODO Test yang files in transitive dependencies @Test - public void testYangRootNotExist() { - try { - setUp("YangRootNotExist/", false); - } catch (VerificationException e) { - assertVerificationException(e, - "[ERROR] yang-to-sources: Unable to parse yang files from "); - assertVerificationException( - e, - "Caused by: org.apache.maven.plugin.MojoExecutionException: yang-to-sources: Unable to parse yang files from "); - return; - } - - fail("Verification exception should have been thrown"); + public void testYangRootNotExist() throws Exception { + Verifier v = setUp("test-parent/YangRootNotExist/", false); + v.verifyTextInLog("[WARNING] yang-to-sources: YANG source directory"); } @Test - public void testCorrect() throws VerificationException { - Verifier v = setUp("Correct/", false); + public void testCorrect() throws Exception { + Verifier v = setUp("test-parent/Correct/", false); verifyCorrectLog(v); } @Test - public void testAdditionalConfiguration() throws VerificationException { - Verifier v = setUp("AdditionalConfig/", false); + 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("target" - + File.separator - + "generated-resources marked as resources for generator: org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl"); + v.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 VerificationException { + public void testMissingYangInDep() throws Exception { try { - setUp("MissingYangInDep/", false); + setUp("test-parent/MissingYangInDep/", false); } 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"); + "org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException: Imported module " + + "[ModuleIdentifierImpl{name='unknownDep', namespace=null, revision=2013-02-27}"); return; } fail("Verification exception should have been thrown"); } - static void verifyCorrectLog(Verifier v) throws VerificationException { + 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"); @@ -86,15 +86,22 @@ public class YangToSourcesPluginTestIT { } @Test - public void testNoGenerators() throws VerificationException { - Verifier v = setUp("NoGenerators/", false); + public void testNoGenerators() throws Exception { + Verifier v = setUp("test-parent/NoGenerators/", false); v.verifyErrorFreeLog(); v.verifyTextInLog("[WARNING] yang-to-sources: No code generators provided"); } @Test - public void testUnknownGenerator() throws VerificationException { - Verifier v = setUp("UnknownGenerator/", true); + public void testInvalidVersion() throws Exception { + Verifier v = setUp("test-parent/InvalidVersion/", false); + v.verifyErrorFreeLog(); + v.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"); @@ -103,64 +110,74 @@ public class YangToSourcesPluginTestIT { } @Test - public void testNoYangFiles() throws VerificationException { - Verifier v = setUp("NoYangFiles/", false); + public void testNoYangFiles() throws Exception { + Verifier v = setUp("test-parent/NoYangFiles/", false); v.verifyTextInLog("[INFO] yang-to-sources: No input files found"); } - static void assertVerificationException(VerificationException e, - String string) { + static void assertVerificationException(final VerificationException e, + final String string) { assertThat(e.getMessage(), containsString(string)); } - @BeforeClass - public static void generateProps() throws IOException { - final Properties sp = new Properties(); - try (InputStream is = new FileInputStream(new File(SRC_PROPERTIES))) { - sp.load(is); - } - - props = new Properties(System.getProperties()); - props.put(VERSION_PROP, sp.getProperty(VERSION_PROP)); - } - - static Verifier setUp(String project, boolean ignoreF) - throws VerificationException { + 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.getPath()); + File parent = new File(path.toURI()); Verifier verifier = new Verifier(parent.getParent()); - if (ignoreF) + if (ignoreF) { verifier.addCliOption("-fn"); + } + if (GLOBAL_SETTINGS_OVERRIDE != null) { + verifier.addCliOption("-gs"); + verifier.addCliOption(GLOBAL_SETTINGS_OVERRIDE); + } + if (USER_SETTINGS_OVERRIDE != null) { + verifier.addCliOption("-s"); + verifier.addCliOption(USER_SETTINGS_OVERRIDE); + } verifier.setMavenDebug(true); - verifier.setSystemProperties(props); verifier.executeGoal("generate-sources"); return verifier; } @Test - public void testNoOutputDir() throws VerificationException { - Verifier v = YangToSourcesPluginTestIT.setUp("NoOutputDir/", false); + public void testNoOutputDir() throws Exception { + Verifier v = YangToSourcesPluginTestIT.setUp("test-parent/NoOutputDir/", false); verifyCorrectLog(v); } @Test - public void testFindResourceOnCp() throws VerificationException { - Verifier v1 = new Verifier(new File(getClass().getResource( - "/GenerateTest1/pom.xml").getPath()).getParent()); - v1.setSystemProperties(props); + public void testFindResourceOnCp() throws Exception { + Verifier v1 = setUp("test-parent/GenerateTest1/", false); v1.executeGoal("clean"); v1.executeGoal("package"); - v1.assertFilePresent("target/classes/META-INF/yang/testfile1.yang"); - v1.assertFilePresent("target/classes/META-INF/yang/testfile2.yang"); - v1.assertFilePresent("target/classes/META-INF/yang/testfile3.yang"); - Verifier v2 = YangToSourcesPluginTestIT.setUp("GenerateTest2/", false); + 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"); + + Verifier v2 = setUp("test-parent/GenerateTest2/", false); v2.executeGoal("clean"); v2.executeGoal("package"); - v2.assertFilePresent("target/classes/META-INF/yang/private.yang"); - v2.assertFileNotPresent("target/classes/META-INF/yang/testfile1.yang"); - v2.assertFileNotPresent("target/classes/META-INF/yang/testfile2.yang"); - v2.assertFileNotPresent("target/classes/META-INF/yang/testfile3.yang"); + + sp = new Properties(); + try (InputStream is = new FileInputStream(v2.getBasedir() + "/it-project.properties")) { + 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"); } + }