Fix IT test instantiation
[yangtools.git] / yang / yang-maven-plugin-it / src / test / java / org / opendaylight / yangtools / yang2sources / plugin / it / YangToSourcesPluginTestIT.java
index 7b1e11e4660e73348ee1610774e53c79983f812c..770e32781228aed569418229b1360b12396b861b 100644 (file)
@@ -19,6 +19,7 @@ import java.io.InputStream;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.Arrays;
+import java.util.Optional;
 import java.util.Properties;
 import org.apache.maven.it.VerificationException;
 import org.apache.maven.it.Verifier;
@@ -134,6 +135,9 @@ public class YangToSourcesPluginTestIT {
         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");
@@ -152,8 +156,7 @@ 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");
 
@@ -162,8 +165,7 @@ public class YangToSourcesPluginTestIT {
         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");
 
@@ -182,4 +184,16 @@ public class YangToSourcesPluginTestIT {
         return sp.getProperty("target.dir");
     }
 
+    private static Optional<String> 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();
+        }
+    }
+
 }