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=770e32781228aed569418229b1360b12396b861b;hb=5e6134e6824f2663516d51a1b5195883d35589a2;hp=e2d889e78e58c5090c24151096279294621a7b70;hpb=e1b6b81250a756e9e05706136e5808fa41a4efc1;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..770e327812 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,22 +12,32 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; 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.Optional; 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 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 @@ -63,28 +73,14 @@ public class YangToSourcesPluginTestIT { } 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 " + + "[unknownDep] was not found."); 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"); @@ -128,7 +124,7 @@ public class YangToSourcesPluginTestIT { } static Verifier setUp(final String project, final boolean ignoreF) - throws VerificationException, URISyntaxException { + throws VerificationException, URISyntaxException, IOException { final URL path = YangToSourcesPluginTestIT.class.getResource("/" + project + "pom.xml"); File parent = new File(path.toURI()); @@ -136,6 +132,17 @@ public class YangToSourcesPluginTestIT { if (ignoreF) { verifier.addCliOption("-fn"); } + if (GLOBAL_SETTINGS_OVERRIDE != null) { + verifier.addCliOption("-gs"); + verifier.addCliOption(GLOBAL_SETTINGS_OVERRIDE); + } else if (getEffectiveSettingsXML().isPresent()) { + verifier.addCliOption("-gs"); + verifier.addCliOption(getEffectiveSettingsXML().get()); + } + if (USER_SETTINGS_OVERRIDE != null) { + verifier.addCliOption("-s"); + verifier.addCliOption(USER_SETTINGS_OVERRIDE); + } verifier.setMavenDebug(true); verifier.executeGoal("generate-sources"); return verifier; @@ -149,36 +156,44 @@ public class YangToSourcesPluginTestIT { @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"); - + String buildDir = getMavenBuildDirectory(v1); 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 = 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")) { - sp.load(is); - } - buildDir = sp.getProperty("target.dir"); - + buildDir = getMavenBuildDirectory(v2); 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"); } + private static String getMavenBuildDirectory(Verifier verifier) throws IOException { + Properties sp = new Properties(); + try (InputStream is = new FileInputStream(verifier.getBasedir() + "/it-project.properties")) { + sp.load(is); + } + return sp.getProperty("target.dir"); + } + + private static Optional getEffectiveSettingsXML() throws URISyntaxException, VerificationException, IOException { + final URL path = YangToSourcesPluginTestIT.class.getResource("/test-parent/pom.xml"); + File buildDir = new File(path.toURI()).getParentFile().getParentFile().getParentFile(); + File effectiveSettingsXML = new File(buildDir, "effective-settings.xml"); + if (effectiveSettingsXML.exists()) { + return Optional.of(effectiveSettingsXML.getAbsolutePath()); + } else { + fail(effectiveSettingsXML.getAbsolutePath()); + return Optional.empty(); + } + } + }