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;
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;
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;
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;
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");
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
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());
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());
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");
+ }
+ }
}