Merge "Added getModifiedChild to DataTreeCandidateNode."
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / parser / impl / YangParserTest.java
index ebd6b6e5246ec0a3b1db1b10c64256724c3e52e4..760bee4bb05bb2999a51b5f46f7a443252d8a750 100644 (file)
@@ -12,13 +12,16 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
+import java.io.IOException;
 import java.io.InputStream;
 import java.math.BigInteger;
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
@@ -31,6 +34,7 @@ import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -60,6 +64,7 @@ import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
 import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.model.util.Decimal64;
 import org.opendaylight.yangtools.yang.model.util.ExtendedType;
 import org.opendaylight.yangtools.yang.model.util.Int16;
@@ -68,6 +73,7 @@ import org.opendaylight.yangtools.yang.model.util.StringType;
 import org.opendaylight.yangtools.yang.model.util.Uint32;
 import org.opendaylight.yangtools.yang.model.util.UnionType;
 import org.opendaylight.yangtools.yang.parser.builder.impl.BuilderUtils;
+import org.opendaylight.yangtools.yang.parser.util.YangParseException;
 
 public class YangParserTest {
     public static final String FS = File.separator;
@@ -129,7 +135,7 @@ public class YangParserTest {
 
         ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName("ifEntry");
         // test SchemaNode args
-        QName expectedQName = new QName(expectedNamespace, barRev, expectedPrefix, "ifEntry");
+        QName expectedQName = QName.create(expectedNamespace, barRev, "ifEntry");
         assertEquals(expectedQName, ifEntry.getQName());
         SchemaPath expectedPath = TestUtils.createPath(true, expectedNamespace, barRev, expectedPrefix, "interfaces",
                 "ifEntry");
@@ -152,7 +158,7 @@ public class YangParserTest {
         assertEquals(2, availableAugmentations.size());
         // test ListSchemaNode args
         List<QName> expectedKey = new ArrayList<>();
-        expectedKey.add(new QName(expectedNamespace, barRev, expectedPrefix, "ifIndex"));
+        expectedKey.add(QName.create(expectedNamespace, barRev, "ifIndex"));
         assertEquals(expectedKey, ifEntry.getKeyDefinition());
         assertFalse(ifEntry.isUserOrdered());
         // test DataNodeContainer args
@@ -656,8 +662,8 @@ public class YangParserTest {
         assertEquals("system/user ref", dev.getReference());
 
         List<QName> path = new ArrayList<>();
-        path.add(new QName(barNS, barRev, "br", "interfaces"));
-        path.add(new QName(barNS, barRev, "br", "ifEntry"));
+        path.add(QName.create(barNS, barRev, "interfaces"));
+        path.add(QName.create(barNS, barRev, "ifEntry"));
         SchemaPath expectedPath = SchemaPath.create(path, true);
 
         assertEquals(expectedPath, dev.getTargetPath());
@@ -704,7 +710,7 @@ public class YangParserTest {
 
         NotificationDefinition notification = notifications.iterator().next();
         // test SchemaNode args
-        QName expectedQName = new QName(bazNS, bazRev, expectedPrefix, "event");
+        QName expectedQName = QName.create(bazNS, bazRev, "event");
         assertEquals(expectedQName, notification.getQName());
         SchemaPath expectedPath = TestUtils.createPath(true, bazNS, bazRev, expectedPrefix, "event");
         assertEquals(expectedPath, notification.getPath());
@@ -923,4 +929,55 @@ public class YangParserTest {
         assertEquals(2, foo.getAugmentations().size());
     }
 
+    @Test
+    public void unknownStatementInSubmoduleHeaderTest() throws IOException, URISyntaxException {
+
+        File yang = new File(getClass().getResource("/yang-grammar-test/submodule-header-extension.yang").toURI());
+
+        try {
+            YangParserImpl.getInstance().parseFile(yang, yang.getParentFile());
+        } catch (YangSyntaxErrorException | YangParseException e) {
+            e.printStackTrace();
+            fail("YangSyntaxErrorException or YangParseException should not be thrown");
+        }
+
+    }
+
+    @Test
+    public void unknownStatementBetweenRevisionsTest() throws IOException, URISyntaxException {
+
+        File yangModul = new File(getClass().getResource("/yang-grammar-test/revisions-extension.yang").toURI());
+        File yangSubmodul = new File(getClass().getResource("/yang-grammar-test/submodule-header-extension.yang")
+                .toURI());
+
+        List<File> yangs = new ArrayList<File>();
+        yangs.add(yangModul);
+        yangs.add(yangSubmodul);
+
+        try {
+            YangParserImpl.getInstance().parseFiles(yangs);
+        } catch (YangParseException e) {
+            e.printStackTrace();
+            fail("YangParseException should not be thrown");
+        }
+    }
+
+    @Test
+    public void unknownStatementsInStatementsTest() throws IOException, URISyntaxException {
+        File yangModule1 = new File(getClass().getResource("/yang-grammar-test/stmtsep-in-statements.yang").toURI());
+        File yangModule2 = new File(getClass().getResource("/yang-grammar-test/stmtsep-in-statements2.yang").toURI());
+        File yangSubModule = new File(getClass().getResource("/yang-grammar-test/stmtsep-in-statements-sub.yang").toURI());
+
+        List<File> yangs = new ArrayList<File>();
+        yangs.add(yangModule1);
+        yangs.add(yangModule2);
+        yangs.add(yangSubModule);
+
+        try {
+            YangParserImpl.getInstance().parseFiles(yangs);
+        } catch (YangParseException e) {
+            e.printStackTrace();
+            fail("YangParseException should not be thrown");
+        }
+    }
 }