Merge changes I412fb3fc,Iccef8d2e
[yangtools.git] / yang / yang-maven-plugin-it / src / test / java / org / opendaylight / yangtools / yang2sources / plugin / it / YangToSourcesPluginTestIT.java
index feb051e820b84e5b9f7a96ca0de4664c4693eca1..daf737089d1bff86c2297fd263255d31cf716d58 100644 (file)
@@ -15,7 +15,9 @@ 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.List;
 import java.util.Properties;
 
 import org.apache.maven.it.VerificationException;
@@ -31,7 +33,7 @@ public class YangToSourcesPluginTestIT {
     // TODO Test yang files in transitive dependencies
 
     @Test
-    public void testYangRootNotExist() {
+    public void testYangRootNotExist() throws URISyntaxException {
         try {
             setUp("YangRootNotExist/", false);
         } catch (VerificationException e) {
@@ -47,13 +49,13 @@ public class YangToSourcesPluginTestIT {
     }
 
     @Test
-    public void testCorrect() throws VerificationException {
+    public void testCorrect() throws Exception {
         Verifier v = setUp("Correct/", false);
         verifyCorrectLog(v);
     }
 
     @Test
-    public void testAdditionalConfiguration() throws VerificationException {
+    public void testAdditionalConfiguration() throws Exception {
         Verifier v = setUp("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}");
@@ -65,7 +67,7 @@ public class YangToSourcesPluginTestIT {
     }
 
     @Test
-    public void testMissingYangInDep() throws VerificationException {
+    public void testMissingYangInDep() throws Exception {
         try {
             setUp("MissingYangInDep/", false);
         } catch (VerificationException e) {
@@ -78,6 +80,21 @@ public class YangToSourcesPluginTestIT {
         fail("Verification exception should have been thrown");
     }
 
+    @Test
+    public void testNamingConflict() throws Exception {
+        Verifier v = setUp("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 {
         v.verifyErrorFreeLog();
         v.verifyTextInLog("[INFO] yang-to-sources: YANG files parsed from");
@@ -86,14 +103,21 @@ public class YangToSourcesPluginTestIT {
     }
 
     @Test
-    public void testNoGenerators() throws VerificationException {
+    public void testNoGenerators() throws Exception {
         Verifier v = setUp("NoGenerators/", false);
         v.verifyErrorFreeLog();
         v.verifyTextInLog("[WARNING] yang-to-sources: No code generators provided");
     }
 
     @Test
-    public void testUnknownGenerator() throws VerificationException {
+    public void testInvalidVersion() throws Exception {
+        Verifier v = setUp("InvalidVersion/", false);
+        v.verifyErrorFreeLog();
+        v.verifyTextInLog("[WARNING] yang-to-sources: Dependency resolution conflict:");
+    }
+
+    @Test
+    public void testUnknownGenerator() throws Exception {
         Verifier v = setUp("UnknownGenerator/", true);
         v.verifyTextInLog("[ERROR] yang-to-sources: Unable to generate sources with unknown generator");
         v.verifyTextInLog("java.lang.ClassNotFoundException: unknown");
@@ -103,7 +127,7 @@ public class YangToSourcesPluginTestIT {
     }
 
     @Test
-    public void testNoYangFiles() throws VerificationException {
+    public void testNoYangFiles() throws Exception {
         Verifier v = setUp("NoYangFiles/", false);
         v.verifyTextInLog("[INFO] yang-to-sources: No input files found");
     }
@@ -125,10 +149,10 @@ public class YangToSourcesPluginTestIT {
     }
 
     static Verifier setUp(String project, boolean ignoreF)
-            throws VerificationException {
+            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)
             verifier.addCliOption("-fn");
@@ -139,15 +163,15 @@ public class YangToSourcesPluginTestIT {
     }
 
     @Test
-    public void testNoOutputDir() throws VerificationException {
+    public void testNoOutputDir() throws Exception {
         Verifier v = YangToSourcesPluginTestIT.setUp("NoOutputDir/", false);
         verifyCorrectLog(v);
     }
 
     @Test
-    public void testFindResourceOnCp() throws VerificationException {
+    public void testFindResourceOnCp() throws Exception {
         Verifier v1 = new Verifier(new File(getClass().getResource(
-                "/GenerateTest1/pom.xml").getPath()).getParent());
+                "/GenerateTest1/pom.xml").toURI()).getParent());
         v1.setSystemProperties(props);
         v1.executeGoal("clean");
         v1.executeGoal("package");