Merge "Fix for Bug 308."
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / parser / impl / YangParserNegativeTest.java
index b66fb83e92d186742999bb1741faf27f7eed8b84..d11a422432464c2b66eafe0bc896dc10a6d25fb0 100644 (file)
@@ -7,16 +7,15 @@
  */
 package org.opendaylight.yangtools.yang.parser.impl;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import java.io.*;
+import java.util.*;
 
 import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser;
 import org.opendaylight.yangtools.yang.parser.util.YangParseException;
 import org.opendaylight.yangtools.yang.parser.util.YangValidationException;
 
@@ -64,7 +63,8 @@ public class YangParserNegativeTest {
                 }
             }
         } catch (YangParseException e) {
-            assertEquals("Error in module 'test3' at line 10: Error in augment parsing: failed to find augment target",
+            assertEquals(
+                    "Error in module 'test3' at line 10: Error in augment parsing: failed to find augment target: augment /data:unknown",
                     e.getMessage());
         }
     }
@@ -196,4 +196,48 @@ public class YangParserNegativeTest {
         }
     }
 
+    @Test
+    public void testMandatoryInAugment() throws IOException {
+        try {
+            try (InputStream stream1 = new FileInputStream(getClass().getResource("/negative-scenario/testfile8.yang")
+                    .getPath());
+                    InputStream stream2 = new FileInputStream(getClass().getResource(
+                            "/negative-scenario/testfile7.yang").getPath())) {
+                TestUtils.loadModules(Arrays.asList(stream1, stream2));
+                fail("YangParseException should by thrown");
+            }
+        } catch (YangParseException e) {
+            String expected = "Error in module 'testfile7' at line 18: Error in augment parsing: cannot augment mandatory node linkleaf";
+            assertEquals(expected, e.getMessage());
+        }
+    }
+
+    @Test
+    public void testWrongDependenciesDir() throws Exception {
+        try {
+            File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").getPath());
+            File dependenciesDir = new File("/invalid");
+            YangModelParser parser = new YangParserImpl();
+            parser.parseYangModels(yangFile, dependenciesDir);
+            fail("Exception should by thrown");
+        } catch (IllegalStateException e) {
+            String expected = File.separator + "invalid does not exists";
+            assertEquals(expected, e.getMessage());
+        }
+    }
+
+    @Test
+    public void testWrongDependenciesDir2() throws Exception {
+        try {
+            File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").getPath());
+            File dependenciesDir = new File(getClass().getResource("/model").getPath());
+            YangModelParser parser = new YangParserImpl();
+            parser.parseYangModels(yangFile, dependenciesDir);
+            fail("Exception should by thrown");
+        } catch (YangValidationException e) {
+            String expected = "Not existing module imported";
+            assertTrue(e.getMessage().contains(expected));
+        }
+    }
+
 }