Yang-maven-plugin refactored + fixed bugs.
[controller.git] / opendaylight / sal / yang-prototype / code-generator / maven-yang-plugin-it / src / test / java / org / opendaylight / controller / yang2sources / plugin / it / YangToSourcesPluginTest.java
index 267e35ab605fc469a3785655956c0edcdf35407a..e77ec6c46b87b2a04bd61a46d036079f3ce4870c 100644 (file)
@@ -8,7 +8,7 @@
 package org.opendaylight.controller.yang2sources.plugin.it;
 
 import static org.junit.Assert.*;
-import static org.junit.matchers.JUnitMatchers.containsString;
+import static org.junit.matchers.JUnitMatchers.*;
 
 import java.io.File;
 
@@ -18,16 +18,18 @@ import org.junit.Test;
 
 public class YangToSourcesPluginTest {
 
+    // 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 unknown");
+                    "[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 unknown");
+                    "Caused by: org.apache.maven.plugin.MojoExecutionException: yang-to-sources: Unable to parse yang files from ");
             return;
         }
 
@@ -38,16 +40,34 @@ public class YangToSourcesPluginTest {
     public void testCorrect() throws VerificationException {
         Verifier v = setUp("Correct/", false);
         verifyCorrectLog(v);
+    }
+
+    @Test
+    public void testAdditionalConfiguration() throws VerificationException {
+        Verifier v = setUp("AdditionalConfig/", false);
+        v.verifyTextInLog("[INFO] yang-to-sources: Additional configuration picked up for : org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: {nm1=abcd=a.b.c.d, nm2=abcd2=a.b.c.d.2}");
+        v.verifyTextInLog("[INFO] yang-to-sources: Additional configuration picked up for : org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: {c1=config}");
+    }
+
+    @Test
+    public void testMissingYangInDep() throws VerificationException {
+        try {
+            setUp("MissingYangInDep/", false);
+        } catch (VerificationException e) {
+            assertVerificationException(
+                    e,
+                    "org.opendaylight.controller.yang.parser.util.YangValidationException: Not existing module imported:unknownDep:2013-02-27 by:private:2013-02-27");
+            return;
+        }
 
+        fail("Verification exception should have been thrown");
     }
 
     static void verifyCorrectLog(Verifier v) throws VerificationException {
         v.verifyErrorFreeLog();
-        v.verifyTextInLog("[INFO] yang-to-sources: yang files parsed from");
+        v.verifyTextInLog("[INFO] yang-to-sources: YANG files parsed from");
         v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl");
         v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: null");
-        v.verifyTextInLog("[INFO] yang-to-sources: Resource provider instantiated from org.opendaylight.controller.yang2sources.spi.ResourceProviderTestImpl");
-        v.verifyTextInLog("[INFO] yang-to-sources: Resource provider org.opendaylight.controller.yang2sources.spi.ResourceProviderTestImpl call successful");
     }
 
     @Test
@@ -70,7 +90,7 @@ public class YangToSourcesPluginTest {
     @Test
     public void testNoYangFiles() throws VerificationException {
         Verifier v = setUp("NoYangFiles/", false);
-        v.verifyTextInLog("[WARNING] yang-to-sources: No yang file found in ");
+        v.verifyTextInLog("[INFO] yang-to-sources: YANG files parsed from []");
         v.verifyTextInLog("[INFO] yang-to-sources: Code generator instantiated from org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl");
         v.verifyTextInLog("[INFO] yang-to-sources: Sources generated by org.opendaylight.controller.yang2sources.spi.CodeGeneratorTestImpl: null");
     }
@@ -90,43 +110,29 @@ public class YangToSourcesPluginTest {
         return verifier;
     }
 
-    @Test
-    public void testNoGeneratorsResources() throws VerificationException {
-        Verifier v = YangToSourcesPluginTest.setUp("NoGenerators_resources/",
-                false);
-        v.verifyErrorFreeLog();
-        v.verifyTextInLog("[WARNING] yang-to-sources: No resource provider classes provided");
-    }
-
-    @Test
-    public void testUnknownGeneratorResources() throws VerificationException {
-        Verifier v = YangToSourcesPluginTest.setUp(
-                "UnknownGenerator_resources/", true);
-        v.verifyTextInLog("[ERROR] yang-to-sources: Unable to provide resources with unknown resource provider");
-        v.verifyTextInLog("java.lang.ClassNotFoundException: unknown");
-        v.verifyTextInLog("[INFO] yang-to-sources: Resource provider instantiated from org.opendaylight.controller.yang2sources.spi.ResourceProviderTestImpl");
-        v.verifyTextInLog("[INFO] yang-to-sources: Resource provider org.opendaylight.controller.yang2sources.spi.ResourceProviderTestImpl call successful");
-        v.verifyTextInLog("[ERROR] yang-to-sources: One or more code resource provider failed, including failed list(resourceProviderClass=exception) {unknown=java.lang.ClassNotFoundException}");
-    }
-
     @Test
     public void testNoOutputDir() throws VerificationException {
-        Verifier v = YangToSourcesPluginTest.setUp("NoOutputDir/",
-                false);
+        Verifier v = YangToSourcesPluginTest.setUp("NoOutputDir/", false);
         verifyCorrectLog(v);
     }
 
     @Test
     public void testFindResourceOnCp() throws VerificationException {
-        Verifier v1 = new Verifier(new File("src/test/resources/GenerateTest1/").getAbsolutePath());
+        Verifier v1 = new Verifier(
+                new File("src/test/resources/GenerateTest1/").getAbsolutePath());
+        v1.executeGoal("clean");
         v1.executeGoal("package");
-        v1.assertFilePresent("target/external-resources/testfile1.yang");
-        v1.assertFilePresent("target/external-resources/testfile2.yang");
-        v1.assertFilePresent("target/external-resources/testfile3.yang");
+        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 = YangToSourcesPluginTest.setUp("GenerateTest2/",
-                false);
+        Verifier v2 = YangToSourcesPluginTest.setUp("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");
     }
 
 }