Remove redundant modifiers
[yangtools.git] / yang / yang-maven-plugin-it / src / test / java / org / opendaylight / yangtools / yang2sources / plugin / it / YangToSourcesPluginTestIT.java
index 663bf571e58b524e965266a5912f23b16c50ac27..1365e560c72a04e425f156d902f9ef76a0f293a5 100644 (file)
@@ -7,39 +7,39 @@
  */
 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.InputStream;
 import java.net.URISyntaxException;
 import java.net.URL;
-import java.util.List;
+import java.util.Arrays;
 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
-    public void testYangRootNotExist() throws URISyntaxException {
-        try {
-            setUp("test-parent/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
@@ -55,9 +55,11 @@ public class YangToSourcesPluginTestIT {
         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
@@ -67,29 +69,15 @@ 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 " +
+                    "[ModuleIdentifierImpl{name='unknownDep', namespace=null, revision=2013-02-27}");
             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<String> 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(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");
@@ -126,19 +114,28 @@ public class YangToSourcesPluginTestIT {
         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));
     }
 
-    static Verifier setUp(String project, boolean ignoreF)
+    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());
-        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.executeGoal("generate-sources");
         return verifier;
@@ -159,7 +156,7 @@ public class YangToSourcesPluginTestIT {
 
         Properties sp = new Properties();
         try (InputStream is = new FileInputStream(v1.getBasedir() + "/it-project.properties")) {
-             sp.load(is);
+            sp.load(is);
         }
         String buildDir = sp.getProperty("target.dir");
 
@@ -174,7 +171,7 @@ public class YangToSourcesPluginTestIT {
 
         sp = new Properties();
         try (InputStream is = new FileInputStream(v2.getBasedir() + "/it-project.properties")) {
-             sp.load(is);
+            sp.load(is);
         }
         buildDir = sp.getProperty("target.dir");