X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-parser-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fstmt%2FYangParserTest.java;h=cac44d56546103444a9e1041ff3df07cf3314411;hb=043b7275acc4712d396606005a921415527135c0;hp=6f0aa2189deb7c2f5da08caf5cc5bf91f28246ee;hpb=d0bec11ee49bc089b1992459fe48935aa9745ecb;p=yangtools.git diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserTest.java index 6f0aa2189d..cac44d5654 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserTest.java @@ -12,28 +12,29 @@ 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 static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource; -import java.io.File; +import com.google.common.collect.Range; +import com.google.common.collect.RangeSet; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; -import java.text.DateFormat; import java.text.ParseException; import java.util.ArrayList; import java.util.Collection; -import java.util.Date; import java.util.Iterator; import java.util.List; +import java.util.Optional; import java.util.Set; +import java.util.SortedMap; import org.junit.Before; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; +import org.opendaylight.yangtools.yang.common.QNameModule; +import org.opendaylight.yangtools.yang.common.Revision; import org.opendaylight.yangtools.yang.common.YangConstants; import org.opendaylight.yangtools.yang.common.YangVersion; -import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; +import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode; import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode; import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode; import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition; @@ -55,52 +56,47 @@ import org.opendaylight.yangtools.yang.model.api.Status; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint; +import org.opendaylight.yangtools.yang.model.api.type.Int16TypeDefinition; +import org.opendaylight.yangtools.yang.model.api.type.Int32TypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint; import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint; import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition; +import org.opendaylight.yangtools.yang.model.api.type.Uint32TypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition; import org.opendaylight.yangtools.yang.model.util.type.BaseTypes; +import org.opendaylight.yangtools.yang.parser.impl.DefaultReactors; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException; import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource; -import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; -import org.opendaylight.yangtools.yang.parser.util.YangParseException; +import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction; public class YangParserTest { - public static final String FS = File.separator; - - private final URI fooNS = URI.create("urn:opendaylight.foo"); - private final URI barNS = URI.create("urn:opendaylight.bar"); - private final URI bazNS = URI.create("urn:opendaylight.baz"); - private Date fooRev; - private Date barRev; - private Date bazRev; - - private Set modules; + private static final QNameModule FOO = QNameModule.create(URI.create("urn:opendaylight.foo"), + Revision.of("2013-02-27")); + private static final QNameModule BAR = QNameModule.create(URI.create("urn:opendaylight.bar"), + Revision.of("2013-07-03")); + private static final QNameModule BAZ = QNameModule.create(URI.create("urn:opendaylight.baz"), + Revision.of("2013-02-27")); + + private SchemaContext context; + private Module foo; + private Module bar; + private Module baz; @Before public void init() throws Exception { - final DateFormat simpleDateFormat = SimpleDateFormatUtil.getRevisionFormat(); - fooRev = simpleDateFormat.parse("2013-02-27"); - barRev = simpleDateFormat.parse("2013-07-03"); - bazRev = simpleDateFormat.parse("2013-02-27"); - - modules = TestUtils.loadModules(getClass().getResource("/model").toURI()); - assertEquals(3, modules.size()); + context = TestUtils.loadModules(getClass().getResource("/model").toURI()); + foo = TestUtils.findModule(context, "foo").get(); + bar = TestUtils.findModule(context, "bar").get(); + baz = TestUtils.findModule(context, "baz").get(); } @Test public void testHeaders() throws ParseException { - final Module foo = TestUtils.findModule(modules, "foo"); - assertEquals("foo", foo.getName()); - assertEquals(YangVersion.VERSION_1.toString(), foo.getYangVersion()); - assertEquals(fooNS, foo.getNamespace()); + assertEquals(YangVersion.VERSION_1, foo.getYangVersion()); + assertEquals(FOO.getNamespace(), foo.getNamespace()); assertEquals("foo", foo.getPrefix()); final Set imports = foo.getImports(); @@ -108,38 +104,32 @@ public class YangParserTest { final ModuleImport import2 = TestUtils.findImport(imports, "br"); assertEquals("bar", import2.getModuleName()); - assertEquals(barRev, import2.getRevision()); + assertEquals(BAR.getRevision(), import2.getRevision()); final ModuleImport import3 = TestUtils.findImport(imports, "bz"); assertEquals("baz", import3.getModuleName()); - assertEquals(bazRev, import3.getRevision()); + assertEquals(BAZ.getRevision(), import3.getRevision()); - assertEquals("opendaylight", foo.getOrganization()); - assertEquals("http://www.opendaylight.org/", foo.getContact()); - final Date expectedRevision = TestUtils.createDate("2013-02-27"); - assertEquals(expectedRevision, foo.getRevision()); - assertNull(foo.getReference()); + assertEquals(Optional.of("opendaylight"), foo.getOrganization()); + assertEquals(Optional.of("http://www.opendaylight.org/"), foo.getContact()); + assertEquals(Revision.ofNullable("2013-02-27"), foo.getRevision()); + assertFalse(foo.getReference().isPresent()); } @Test public void testParseList() { - final Module bar = TestUtils.findModule(modules, "bar"); - final URI expectedNamespace = URI.create("urn:opendaylight.bar"); - final String expectedPrefix = "bar"; - final ContainerSchemaNode interfaces = (ContainerSchemaNode) bar.getDataChildByName(QName.create( bar.getQNameModule(), "interfaces")); final ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName(QName.create(bar.getQNameModule(), "ifEntry")); // test SchemaNode args - final QName expectedQName = QName.create(expectedNamespace, barRev, "ifEntry"); - assertEquals(expectedQName, ifEntry.getQName()); - final SchemaPath expectedPath = TestUtils.createPath(true, expectedNamespace, barRev, expectedPrefix, - "interfaces", "ifEntry"); + assertEquals(QName.create(BAR, "ifEntry"), ifEntry.getQName()); + + final SchemaPath expectedPath = TestUtils.createPath(true, BAR, "interfaces", "ifEntry"); assertEquals(expectedPath, ifEntry.getPath()); - assertNull(ifEntry.getDescription()); - assertNull(ifEntry.getReference()); + assertFalse(ifEntry.getDescription().isPresent()); + assertFalse(ifEntry.getReference().isPresent()); assertEquals(Status.CURRENT, ifEntry.getStatus()); assertEquals(0, ifEntry.getUnknownSchemaNodes().size()); // test DataSchemaNode args @@ -150,15 +140,14 @@ public class YangParserTest { // ifEntry should be a context node ? // assertNull(constraints.getWhenCondition()); assertEquals(0, constraints.getMustConstraints().size()); - assertTrue(constraints.isMandatory()); assertEquals(1, (int) constraints.getMinElements()); assertEquals(11, (int) constraints.getMaxElements()); // test AugmentationTarget args - final Set availableAugmentations = ifEntry.getAvailableAugmentations(); + final Set availableAugmentations = ifEntry.getAvailableAugmentations(); assertEquals(2, availableAugmentations.size()); // test ListSchemaNode args final List expectedKey = new ArrayList<>(); - expectedKey.add(QName.create(expectedNamespace, barRev, "ifIndex")); + expectedKey.add(QName.create(BAR, "ifIndex")); assertEquals(expectedKey, ifEntry.getKeyDefinition()); assertFalse(ifEntry.isUserOrdered()); // test DataNodeContainer args @@ -167,185 +156,168 @@ public class YangParserTest { assertEquals(0, ifEntry.getGroupings().size()); assertEquals(0, ifEntry.getUses().size()); - final LeafSchemaNode ifIndex = (LeafSchemaNode) ifEntry.getDataChildByName(QName.create(bar.getQNameModule(), "ifIndex")); + final LeafSchemaNode ifIndex = (LeafSchemaNode) ifEntry.getDataChildByName(QName.create(bar.getQNameModule(), + "ifIndex")); assertEquals(ifEntry.getKeyDefinition().get(0), ifIndex.getQName()); - assertTrue(ifIndex.getType() instanceof UnsignedIntegerTypeDefinition); - assertEquals("minutes", ifIndex.getUnits()); - final LeafSchemaNode ifMtu = (LeafSchemaNode) ifEntry.getDataChildByName(QName.create(bar.getQNameModule(), "ifMtu")); + assertTrue(ifIndex.getType() instanceof Uint32TypeDefinition); + assertEquals(Optional.of("minutes"), ifIndex.getType().getUnits()); + final LeafSchemaNode ifMtu = (LeafSchemaNode) ifEntry.getDataChildByName(QName.create(bar.getQNameModule(), + "ifMtu")); assertEquals(BaseTypes.int32Type(), ifMtu.getType()); } @Test public void testTypedefRangesResolving() throws ParseException { - final Module foo = TestUtils.findModule(modules, "foo"); - final LeafSchemaNode int32Leaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "int32-leaf")); - - final IntegerTypeDefinition leafType = (IntegerTypeDefinition) int32Leaf.getType(); - final QName leafTypeQName = leafType.getQName(); - assertEquals("int32-ext2", leafTypeQName.getLocalName()); - assertEquals(fooNS, leafTypeQName.getNamespace()); - assertEquals(fooRev, leafTypeQName.getRevision()); - assertEquals("mile", leafType.getUnits()); - assertEquals("11", leafType.getDefaultValue()); - - final List ranges = leafType.getRangeConstraints(); + final LeafSchemaNode int32Leaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), + "int32-leaf")); + + final Int32TypeDefinition leafType = (Int32TypeDefinition) int32Leaf.getType(); + assertEquals(QName.create(FOO, "int32-ext2"), leafType.getQName()); + assertEquals(Optional.of("mile"), leafType.getUnits()); + assertEquals(Optional.of("11"), leafType.getDefaultValue()); + + final RangeSet rangeset = leafType.getRangeConstraint().get().getAllowedRanges(); + final Set> ranges = rangeset.asRanges(); assertEquals(1, ranges.size()); - final RangeConstraint range = ranges.get(0); - assertEquals(12, range.getMin().intValue()); - assertEquals(20, range.getMax().intValue()); - - final IntegerTypeDefinition baseType = leafType.getBaseType(); - final QName baseTypeQName = baseType.getQName(); - assertEquals("int32-ext2", baseTypeQName.getLocalName()); - assertEquals(barNS, baseTypeQName.getNamespace()); - assertEquals(barRev, baseTypeQName.getRevision()); - assertEquals("mile", baseType.getUnits()); - assertEquals("11", baseType.getDefaultValue()); - - final List baseTypeRanges = baseType.getRangeConstraints(); - assertEquals(2, baseTypeRanges.size()); - final RangeConstraint baseTypeRange1 = baseTypeRanges.get(0); - assertEquals(3, baseTypeRange1.getMin().intValue()); - assertEquals(9, baseTypeRange1.getMax().intValue()); - final RangeConstraint baseTypeRange2 = baseTypeRanges.get(1); - assertEquals(11, baseTypeRange2.getMin().intValue()); - assertEquals(20, baseTypeRange2.getMax().intValue()); - - final IntegerTypeDefinition base = baseType.getBaseType(); - final QName baseQName = base.getQName(); + + final Range range = ranges.iterator().next(); + assertEquals(12, range.lowerEndpoint().intValue()); + assertEquals(20, range.upperEndpoint().intValue()); + + final Int32TypeDefinition firstBaseType = leafType.getBaseType(); + assertEquals(QName.create(BAR, "int32-ext2"), firstBaseType.getQName()); + assertEquals(Optional.of("mile"), firstBaseType.getUnits()); + assertEquals(Optional.of("11"), firstBaseType.getDefaultValue()); + + final RangeSet firstRangeset = firstBaseType.getRangeConstraint().get().getAllowedRanges(); + final Set> baseRanges = firstRangeset.asRanges(); + assertEquals(2, baseRanges.size()); + + final Iterator> it = baseRanges.iterator(); + final Range baseTypeRange1 = it.next(); + assertEquals(3, baseTypeRange1.lowerEndpoint().intValue()); + assertEquals(9, baseTypeRange1.upperEndpoint().intValue()); + final Range baseTypeRange2 = it.next(); + assertEquals(11, baseTypeRange2.lowerEndpoint().intValue()); + assertEquals(20, baseTypeRange2.upperEndpoint().intValue()); + + final Int32TypeDefinition secondBaseType = firstBaseType.getBaseType(); + final QName baseQName = secondBaseType.getQName(); assertEquals("int32-ext1", baseQName.getLocalName()); - assertEquals(barNS, baseQName.getNamespace()); - assertEquals(barRev, baseQName.getRevision()); - assertNull(base.getUnits()); - assertNull(base.getDefaultValue()); - - final List baseRanges = base.getRangeConstraints(); - assertEquals(1, baseRanges.size()); - final RangeConstraint baseRange = baseRanges.get(0); - assertEquals(2, baseRange.getMin().intValue()); - assertEquals(20, baseRange.getMax().intValue()); - - assertEquals(BaseTypes.int32Type(), base.getBaseType()); + assertEquals(BAR, baseQName.getModule()); + assertEquals(Optional.empty(), secondBaseType.getUnits()); + assertEquals(Optional.empty(), secondBaseType.getDefaultValue()); + + final Set> secondRanges = secondBaseType.getRangeConstraint().get() + .getAllowedRanges().asRanges(); + assertEquals(1, secondRanges.size()); + final Range secondRange = secondRanges.iterator().next(); + assertEquals(2, secondRange.lowerEndpoint().intValue()); + assertEquals(20, secondRange.upperEndpoint().intValue()); + + assertEquals(BaseTypes.int32Type(), secondBaseType.getBaseType()); } @Test public void testTypedefPatternsResolving() { - final Module foo = TestUtils.findModule(modules, "foo"); - final LeafSchemaNode stringleaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "string-leaf")); + final LeafSchemaNode stringleaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), + "string-leaf")); assertTrue(stringleaf.getType() instanceof StringTypeDefinition); final StringTypeDefinition type = (StringTypeDefinition) stringleaf.getType(); final QName typeQName = type.getQName(); assertEquals("string-ext4", typeQName.getLocalName()); - assertEquals(barNS, typeQName.getNamespace()); - assertEquals(barRev, typeQName.getRevision()); - assertNull(type.getUnits()); - assertNull(type.getDefaultValue()); + assertEquals(BAR, typeQName.getModule()); + assertEquals(Optional.empty(), type.getUnits()); + assertEquals(Optional.empty(), type.getDefaultValue()); List patterns = type.getPatternConstraints(); assertEquals(1, patterns.size()); PatternConstraint pattern = patterns.iterator().next(); - assertEquals("^[e-z]*$", pattern.getRegularExpression()); - assertEquals(1, type.getLengthConstraints().size()); + assertEquals("^[e-z]*$", pattern.getJavaPatternString()); + assertEquals(1, type.getLengthConstraint().get().getAllowedRanges().asRanges().size()); final StringTypeDefinition baseType1 = type.getBaseType(); final QName baseType1QName = baseType1.getQName(); assertEquals("string-ext3", baseType1QName.getLocalName()); - assertEquals(barNS, baseType1QName.getNamespace()); - assertEquals(barRev, baseType1QName.getRevision()); - assertNull(baseType1.getUnits()); - assertNull(baseType1.getDefaultValue()); + assertEquals(BAR, baseType1QName.getModule()); + assertEquals(Optional.empty(), baseType1.getUnits()); + assertEquals(Optional.empty(), baseType1.getDefaultValue()); patterns = baseType1.getPatternConstraints(); assertEquals(1, patterns.size()); pattern = patterns.iterator().next(); - assertEquals("^[b-u]*$", pattern.getRegularExpression()); - assertEquals(1, baseType1.getLengthConstraints().size()); + assertEquals("^[b-u]*$", pattern.getJavaPatternString()); + assertEquals(1, baseType1.getLengthConstraint().get().getAllowedRanges().asRanges().size()); final StringTypeDefinition baseType2 = baseType1.getBaseType(); final QName baseType2QName = baseType2.getQName(); assertEquals("string-ext2", baseType2QName.getLocalName()); - assertEquals(barNS, baseType2QName.getNamespace()); - assertEquals(barRev, baseType2QName.getRevision()); - assertNull(baseType2.getUnits()); - assertNull(baseType2.getDefaultValue()); + assertEquals(BAR, baseType2QName.getModule()); + assertEquals(Optional.empty(), baseType2.getUnits()); + assertEquals(Optional.empty(), baseType2.getDefaultValue()); assertTrue(baseType2.getPatternConstraints().isEmpty()); - final List baseType2Lengths = baseType2.getLengthConstraints(); - assertEquals(1, baseType2Lengths.size()); - LengthConstraint length = baseType2Lengths.get(0); - assertEquals(6, length.getMin().intValue()); - assertEquals(10, length.getMax().intValue()); + final RangeSet baseType2Lengths = baseType2.getLengthConstraint().get().getAllowedRanges(); + assertEquals(1, baseType2Lengths.asRanges().size()); + Range length = baseType2Lengths.span(); + assertEquals(6, length.lowerEndpoint().intValue()); + assertEquals(10, length.upperEndpoint().intValue()); final StringTypeDefinition baseType3 = baseType2.getBaseType(); - final QName baseType3QName = baseType3.getQName(); - assertEquals("string-ext1", baseType3QName.getLocalName()); - assertEquals(barNS, baseType3QName.getNamespace()); - assertEquals(barRev, baseType3QName.getRevision()); - assertNull(baseType3.getUnits()); - assertNull(baseType3.getDefaultValue()); + assertEquals(QName.create(BAR, "string-ext1"), baseType3.getQName()); + assertEquals(Optional.empty(), baseType3.getUnits()); + assertEquals(Optional.empty(), baseType3.getDefaultValue()); patterns = baseType3.getPatternConstraints(); assertEquals(1, patterns.size()); pattern = patterns.iterator().next(); - assertEquals("^[a-k]*$", pattern.getRegularExpression()); - final List baseType3Lengths = baseType3.getLengthConstraints(); - assertEquals(1, baseType3Lengths.size()); - length = baseType3Lengths.get(0); - assertEquals(5, length.getMin().intValue()); - assertEquals(11, length.getMax().intValue()); + assertEquals("^[a-k]*$", pattern.getJavaPatternString()); + final RangeSet baseType3Lengths = baseType3.getLengthConstraint().get().getAllowedRanges(); + assertEquals(1, baseType3Lengths.asRanges().size()); + length = baseType3Lengths.span(); + assertEquals(5, length.lowerEndpoint().intValue()); + assertEquals(11, length.upperEndpoint().intValue()); assertEquals(BaseTypes.stringType(), baseType3.getBaseType()); } @Test public void testTypedefInvalidPatternsResolving() { - final Module foo = TestUtils.findModule(modules, "foo"); final LeafSchemaNode invalidPatternStringLeaf = (LeafSchemaNode) foo .getDataChildByName(QName.create(foo.getQNameModule(), "invalid-pattern-string-leaf")); StringTypeDefinition type = (StringTypeDefinition) invalidPatternStringLeaf.getType(); - QName typeQName = type.getQName(); - assertEquals("invalid-string-pattern", typeQName.getLocalName()); - assertEquals(barNS, typeQName.getNamespace()); - assertEquals(barRev, typeQName.getRevision()); - assertNull(type.getUnits()); - assertNull(type.getDefaultValue()); + assertEquals(QName.create(BAR, "invalid-string-pattern"), type.getQName()); + assertEquals(Optional.empty(), type.getUnits()); + assertEquals(Optional.empty(), type.getDefaultValue()); List patterns = type.getPatternConstraints(); assertTrue(patterns.isEmpty()); final LeafSchemaNode invalidDirectStringPatternDefLeaf = (LeafSchemaNode) foo .getDataChildByName(QName.create(foo.getQNameModule(), "invalid-direct-string-pattern-def-leaf")); type = (StringTypeDefinition) invalidDirectStringPatternDefLeaf.getType(); - typeQName = type.getQName(); - assertEquals("string", typeQName.getLocalName()); - assertEquals(YangConstants.RFC6020_YANG_NAMESPACE, typeQName.getNamespace()); - assertNull(typeQName.getRevision()); - assertNull(type.getUnits()); - assertNull(type.getDefaultValue()); + + assertEquals(QName.create(YangConstants.RFC6020_YANG_MODULE, "string"), type.getQName()); + assertEquals(Optional.empty(), type.getUnits()); + assertEquals(Optional.empty(), type.getDefaultValue()); patterns = type.getPatternConstraints(); assertTrue(patterns.isEmpty()); final LeafSchemaNode multiplePatternStringLeaf = (LeafSchemaNode) foo .getDataChildByName(QName.create(foo.getQNameModule(), "multiple-pattern-string-leaf")); type = (StringTypeDefinition) multiplePatternStringLeaf.getType(); - typeQName = type.getQName(); - assertEquals("multiple-pattern-string", typeQName.getLocalName()); - assertEquals(barNS, typeQName.getNamespace()); - assertEquals(barRev, typeQName.getRevision()); - assertNull(type.getUnits()); - assertNull(type.getDefaultValue()); + assertEquals(QName.create(BAR, "multiple-pattern-string"), type.getQName()); + assertEquals(Optional.empty(), type.getUnits()); + assertEquals(Optional.empty(), type.getDefaultValue()); patterns = type.getPatternConstraints(); assertTrue(!patterns.isEmpty()); assertEquals(1, patterns.size()); final PatternConstraint pattern = patterns.iterator().next(); - assertEquals("^[e-z]*$", pattern.getRegularExpression()); - assertEquals(1, type.getLengthConstraints().size()); + assertEquals("^[e-z]*$", pattern.getJavaPatternString()); + assertEquals(1, type.getLengthConstraint().get().getAllowedRanges().asRanges().size()); final LeafSchemaNode multiplePatternDirectStringDefLeaf = (LeafSchemaNode) foo .getDataChildByName(QName.create(foo.getQNameModule(), "multiple-pattern-direct-string-def-leaf")); type = (StringTypeDefinition) multiplePatternDirectStringDefLeaf.getType(); - typeQName = type.getQName(); - assertEquals("string", typeQName.getLocalName()); - assertEquals(fooNS, typeQName.getNamespace()); - assertEquals(fooRev, typeQName.getRevision()); - assertNull(type.getUnits()); - assertNull(type.getDefaultValue()); + assertEquals(QName.create(FOO, "string"), type.getQName()); + assertEquals(Optional.empty(), type.getUnits()); + assertEquals(Optional.empty(), type.getDefaultValue()); patterns = type.getPatternConstraints(); assertTrue(!patterns.isEmpty()); assertEquals(2, patterns.size()); @@ -353,9 +325,9 @@ public class YangParserTest { boolean isEZPattern = false; boolean isADPattern = false; for (final PatternConstraint patternConstraint : patterns) { - if (patternConstraint.getRegularExpression().equals("^[e-z]*$")) { + if (patternConstraint.getJavaPatternString().equals("^[e-z]*$")) { isEZPattern = true; - } else if (patternConstraint.getRegularExpression().equals("^[a-d]*$")) { + } else if (patternConstraint.getJavaPatternString().equals("^[a-d]*$")) { isADPattern = true; } } @@ -365,146 +337,118 @@ public class YangParserTest { @Test public void testTypedefLengthsResolving() { - final Module foo = TestUtils.findModule(modules, "foo"); - - final LeafSchemaNode lengthLeaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "length-leaf")); + final LeafSchemaNode lengthLeaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), + "length-leaf")); final StringTypeDefinition type = (StringTypeDefinition) lengthLeaf.getType(); - final QName typeQName = type.getQName(); - assertEquals("string-ext2", typeQName.getLocalName()); - assertEquals(fooNS, typeQName.getNamespace()); - assertEquals(fooRev, typeQName.getRevision()); - assertNull(type.getUnits()); - assertNull(type.getDefaultValue()); + assertEquals(QName.create(FOO, "string-ext2"), type.getQName()); + assertEquals(Optional.empty(), type.getUnits()); + assertEquals(Optional.empty(), type.getDefaultValue()); assertTrue(type.getPatternConstraints().isEmpty()); - final List typeLengths = type.getLengthConstraints(); - assertEquals(1, typeLengths.size()); - LengthConstraint length = typeLengths.get(0); - assertEquals(7, length.getMin().intValue()); - assertEquals(10, length.getMax().intValue()); + final RangeSet typeLengths = type.getLengthConstraint().get().getAllowedRanges(); + assertEquals(1, typeLengths.asRanges().size()); + Range length = typeLengths.span(); + assertEquals(7, length.lowerEndpoint().intValue()); + assertEquals(10, length.upperEndpoint().intValue()); final StringTypeDefinition baseType1 = type.getBaseType(); - final QName baseType1QName = baseType1.getQName(); - assertEquals("string-ext2", baseType1QName.getLocalName()); - assertEquals(barNS, baseType1QName.getNamespace()); - assertEquals(barRev, baseType1QName.getRevision()); - assertNull(baseType1.getUnits()); - assertNull(baseType1.getDefaultValue()); + assertEquals(QName.create(BAR, "string-ext2"), baseType1.getQName()); + assertEquals(Optional.empty(), baseType1.getUnits()); + assertEquals(Optional.empty(), baseType1.getDefaultValue()); assertTrue(baseType1.getPatternConstraints().isEmpty()); - final List baseType2Lengths = baseType1.getLengthConstraints(); - assertEquals(1, baseType2Lengths.size()); - length = baseType2Lengths.get(0); - assertEquals(6, length.getMin().intValue()); - assertEquals(10, length.getMax().intValue()); + final RangeSet baseType2Lengths = baseType1.getLengthConstraint().get().getAllowedRanges(); + assertEquals(1, baseType2Lengths.asRanges().size()); + length = baseType2Lengths.span(); + assertEquals(6, length.lowerEndpoint().intValue()); + assertEquals(10, length.upperEndpoint().intValue()); final StringTypeDefinition baseType2 = baseType1.getBaseType(); - final QName baseType2QName = baseType2.getQName(); - assertEquals("string-ext1", baseType2QName.getLocalName()); - assertEquals(barNS, baseType2QName.getNamespace()); - assertEquals(barRev, baseType2QName.getRevision()); - assertNull(baseType2.getUnits()); - assertNull(baseType2.getDefaultValue()); + assertEquals(QName.create(BAR, "string-ext1"), baseType2.getQName()); + assertEquals(Optional.empty(), baseType2.getUnits()); + assertEquals(Optional.empty(), baseType2.getDefaultValue()); final List patterns = baseType2.getPatternConstraints(); assertEquals(1, patterns.size()); final PatternConstraint pattern = patterns.iterator().next(); - assertEquals("^[a-k]*$", pattern.getRegularExpression()); - final List baseType3Lengths = baseType2.getLengthConstraints(); - assertEquals(1, baseType3Lengths.size()); - length = baseType3Lengths.get(0); - assertEquals(5, length.getMin().intValue()); - assertEquals(11, length.getMax().intValue()); + assertEquals("^[a-k]*$", pattern.getJavaPatternString()); + final RangeSet baseType3Lengths = baseType2.getLengthConstraint().get().getAllowedRanges(); + assertEquals(1, baseType3Lengths.asRanges().size()); + length = baseType3Lengths.span(); + assertEquals(5, length.lowerEndpoint().intValue()); + assertEquals(11, length.upperEndpoint().intValue()); assertEquals(BaseTypes.stringType(), baseType2.getBaseType()); } @Test public void testTypedefDecimal1() { - final Module foo = TestUtils.findModule(modules, "foo"); - final LeafSchemaNode testleaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "decimal-leaf")); + final LeafSchemaNode testleaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), + "decimal-leaf")); assertTrue(testleaf.getType() instanceof DecimalTypeDefinition); final DecimalTypeDefinition type = (DecimalTypeDefinition) testleaf.getType(); - final QName typeQName = type.getQName(); - assertEquals("my-decimal-type", typeQName.getLocalName()); - assertEquals(barNS, typeQName.getNamespace()); - assertEquals(barRev, typeQName.getRevision()); - assertNull(type.getUnits()); - assertNull(type.getDefaultValue()); - assertEquals(6, type.getFractionDigits().intValue()); - assertEquals(1, type.getRangeConstraints().size()); + assertEquals(QName.create(BAR, "my-decimal-type"), type.getQName()); + assertEquals(Optional.empty(), type.getUnits()); + assertEquals(Optional.empty(), type.getDefaultValue()); + assertEquals(6, type.getFractionDigits()); + assertEquals(1, type.getRangeConstraint().get().getAllowedRanges().asRanges().size()); final DecimalTypeDefinition typeBase = type.getBaseType(); - final QName typeBaseQName = typeBase.getQName(); - assertEquals("decimal64", typeBaseQName.getLocalName()); - assertEquals(barNS, typeBaseQName.getNamespace()); - assertEquals(barRev, typeBaseQName.getRevision()); - assertNull(typeBase.getUnits()); - assertNull(typeBase.getDefaultValue()); - assertEquals(6, typeBase.getFractionDigits().intValue()); - assertEquals(1, typeBase.getRangeConstraints().size()); + assertEquals(QName.create(BAR, "decimal64"), typeBase.getQName()); + assertEquals(Optional.empty(), typeBase.getUnits()); + assertEquals(Optional.empty(), typeBase.getDefaultValue()); + assertEquals(6, typeBase.getFractionDigits()); + assertEquals(1, typeBase.getRangeConstraint().get().getAllowedRanges().asRanges().size()); assertNull(typeBase.getBaseType()); } @Test public void testTypedefDecimal2() { - final Module foo = TestUtils.findModule(modules, "foo"); - final LeafSchemaNode testleaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "decimal-leaf2")); + final LeafSchemaNode testleaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), + "decimal-leaf2")); assertTrue(testleaf.getType() instanceof DecimalTypeDefinition); final DecimalTypeDefinition type = (DecimalTypeDefinition) testleaf.getType(); - final QName typeQName = type.getQName(); - assertEquals("my-decimal-type", typeQName.getLocalName()); - assertEquals(barNS, typeQName.getNamespace()); - assertEquals(barRev, typeQName.getRevision()); - assertNull(type.getUnits()); - assertNull(type.getDefaultValue()); - assertEquals(6, type.getFractionDigits().intValue()); - assertEquals(1, type.getRangeConstraints().size()); + assertEquals(QName.create(BAR, "my-decimal-type"), type.getQName()); + assertEquals(Optional.empty(), type.getUnits()); + assertEquals(Optional.empty(), type.getDefaultValue()); + assertEquals(6, type.getFractionDigits()); + assertEquals(1, type.getRangeConstraint().get().getAllowedRanges().asRanges().size()); final DecimalTypeDefinition baseTypeDecimal = type.getBaseType(); - assertEquals(6, baseTypeDecimal.getFractionDigits().intValue()); + assertEquals(6, baseTypeDecimal.getFractionDigits()); } @Test public void testTypedefUnion() { - final Module foo = TestUtils.findModule(modules, "foo"); - final LeafSchemaNode unionleaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "union-leaf")); + final LeafSchemaNode unionleaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), + "union-leaf")); assertTrue(unionleaf.getType() instanceof UnionTypeDefinition); final UnionTypeDefinition type = (UnionTypeDefinition) unionleaf.getType(); - final QName typeQName = type.getQName(); - assertEquals("my-union-ext", typeQName.getLocalName()); - assertEquals(barNS, typeQName.getNamespace()); - assertEquals(barRev, typeQName.getRevision()); - assertNull(type.getUnits()); - assertNull(type.getDefaultValue()); + assertEquals(QName.create(BAR, "my-union-ext"), type.getQName()); + assertEquals(Optional.empty(), type.getUnits()); + assertEquals(Optional.empty(), type.getDefaultValue()); final UnionTypeDefinition baseType = type.getBaseType(); - final QName baseTypeQName = baseType.getQName(); - assertEquals("my-union", baseTypeQName.getLocalName()); - assertEquals(barNS, baseTypeQName.getNamespace()); - assertEquals(barRev, baseTypeQName.getRevision()); - assertNull(baseType.getUnits()); - assertNull(baseType.getDefaultValue()); + assertEquals(QName.create(BAR, "my-union"), baseType.getQName()); + assertEquals(Optional.empty(), baseType.getUnits()); + assertEquals(Optional.empty(), baseType.getDefaultValue()); final UnionTypeDefinition unionType = baseType.getBaseType(); final List> unionTypes = unionType.getTypes(); assertEquals(2, unionTypes.size()); - final IntegerTypeDefinition unionType1 = (IntegerTypeDefinition) unionTypes.get(0); - final QName unionType1QName = baseType.getQName(); - assertEquals("my-union", unionType1QName.getLocalName()); - assertEquals(barNS, unionType1QName.getNamespace()); - assertEquals(barRev, unionType1QName.getRevision()); - assertNull(unionType1.getUnits()); - assertNull(unionType1.getDefaultValue()); + final Int16TypeDefinition unionType1 = (Int16TypeDefinition) unionTypes.get(0); + assertEquals(QName.create(BAR, "my-union"), baseType.getQName()); + assertEquals(Optional.empty(), unionType1.getUnits()); + assertEquals(Optional.empty(), unionType1.getDefaultValue()); - final List ranges = unionType1.getRangeConstraints(); - assertEquals(1, ranges.size()); - final RangeConstraint range = ranges.get(0); - assertEquals(1, range.getMin().intValue()); - assertEquals(100, range.getMax().intValue()); + final RangeConstraint ranges = unionType1.getRangeConstraint().get(); + assertEquals(1, ranges.getAllowedRanges().asRanges().size()); + final Range range = ranges.getAllowedRanges().span(); + assertEquals((short)1, range.lowerEndpoint()); + assertEquals((short)100, range.upperEndpoint()); assertEquals(BaseTypes.int16Type(), unionType1.getBaseType()); assertEquals(BaseTypes.int32Type(), unionTypes.get(1)); @@ -512,25 +456,19 @@ public class YangParserTest { @Test public void testNestedUnionResolving() { - final Module foo = TestUtils.findModule(modules, "foo"); - final LeafSchemaNode testleaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "custom-union-leaf")); + final LeafSchemaNode testleaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), + "custom-union-leaf")); assertTrue(testleaf.getType() instanceof UnionTypeDefinition); final UnionTypeDefinition type = (UnionTypeDefinition) testleaf.getType(); - final QName testleafTypeQName = type.getQName(); - assertEquals(bazNS, testleafTypeQName.getNamespace()); - assertEquals(bazRev, testleafTypeQName.getRevision()); - assertEquals("union1", testleafTypeQName.getLocalName()); - assertNull(type.getUnits()); - assertNull(type.getDefaultValue()); + assertEquals(QName.create(BAZ, "union1"), type.getQName()); + assertEquals(Optional.empty(), type.getUnits()); + assertEquals(Optional.empty(), type.getDefaultValue()); final UnionTypeDefinition typeBase = type.getBaseType(); - final QName typeBaseQName = typeBase.getQName(); - assertEquals(bazNS, typeBaseQName.getNamespace()); - assertEquals(bazRev, typeBaseQName.getRevision()); - assertEquals("union2", typeBaseQName.getLocalName()); - assertNull(typeBase.getUnits()); - assertNull(typeBase.getDefaultValue()); + assertEquals(QName.create(BAZ, "union2"), typeBase.getQName()); + assertEquals(Optional.empty(), typeBase.getUnits()); + assertEquals(Optional.empty(), typeBase.getDefaultValue()); final UnionTypeDefinition union = typeBase.getBaseType(); final List> unionTypes = union.getTypes(); @@ -539,12 +477,9 @@ public class YangParserTest { assertTrue(unionTypes.get(1) instanceof UnionTypeDefinition); final UnionTypeDefinition unionType1 = (UnionTypeDefinition) unionTypes.get(1); - final QName uniontType1QName = unionType1.getQName(); - assertEquals(barNS, uniontType1QName.getNamespace()); - assertEquals(barRev, uniontType1QName.getRevision()); - assertEquals("nested-union2", uniontType1QName.getLocalName()); - assertNull(unionType1.getUnits()); - assertNull(unionType1.getDefaultValue()); + assertEquals(QName.create(BAR, "nested-union2"), unionType1.getQName()); + assertEquals(Optional.empty(), unionType1.getUnits()); + assertEquals(Optional.empty(), unionType1.getDefaultValue()); final UnionTypeDefinition nestedUnion = unionType1.getBaseType(); final List> nestedUnion2Types = nestedUnion.getTypes(); @@ -553,54 +488,47 @@ public class YangParserTest { assertTrue(nestedUnion2Types.get(0) instanceof UnionTypeDefinition); final UnionTypeDefinition myUnionExt = (UnionTypeDefinition) nestedUnion2Types.get(0); - final QName myUnionExtQName = myUnionExt.getQName(); - assertEquals(barNS, myUnionExtQName.getNamespace()); - assertEquals(barRev, myUnionExtQName.getRevision()); - assertEquals("my-union-ext", myUnionExtQName.getLocalName()); - assertNull(myUnionExt.getUnits()); - assertNull(myUnionExt.getDefaultValue()); + assertEquals(QName.create(BAR, "my-union-ext"), myUnionExt.getQName()); + assertEquals(Optional.empty(), myUnionExt.getUnits()); + assertEquals(Optional.empty(), myUnionExt.getDefaultValue()); final UnionTypeDefinition myUnion = myUnionExt.getBaseType(); - final QName myUnionQName = myUnion.getQName(); - assertEquals(barNS, myUnionQName.getNamespace()); - assertEquals(barRev, myUnionQName.getRevision()); - assertEquals("my-union", myUnionQName.getLocalName()); - assertNull(myUnion.getUnits()); - assertNull(myUnion.getDefaultValue()); + assertEquals(QName.create(BAR, "my-union"), myUnion.getQName()); + assertEquals(Optional.empty(), myUnion.getUnits()); + assertEquals(Optional.empty(), myUnion.getDefaultValue()); final UnionTypeDefinition myUnionBase = myUnion.getBaseType(); final List> myUnionBaseTypes = myUnionBase.getTypes(); assertEquals(2, myUnionBaseTypes.size()); - assertTrue(myUnionBaseTypes.get(0) instanceof IntegerTypeDefinition); + assertTrue(myUnionBaseTypes.get(0) instanceof Int16TypeDefinition); assertEquals(BaseTypes.int32Type(), myUnionBaseTypes.get(1)); - final IntegerTypeDefinition int16Ext = (IntegerTypeDefinition) myUnionBaseTypes.get(0); - final QName int16ExtQName = int16Ext.getQName(); - assertEquals(barNS, int16ExtQName.getNamespace()); - assertEquals(barRev, int16ExtQName.getRevision()); - assertEquals("int16", int16ExtQName.getLocalName()); - assertNull(int16Ext.getUnits()); - assertNull(int16Ext.getDefaultValue()); - final List ranges = int16Ext.getRangeConstraints(); + final Int16TypeDefinition int16Ext = (Int16TypeDefinition) myUnionBaseTypes.get(0); + assertEquals(QName.create(BAR, "int16"), int16Ext.getQName()); + assertEquals(Optional.empty(), int16Ext.getUnits()); + assertEquals(Optional.empty(), int16Ext.getDefaultValue()); + final Set> ranges = int16Ext.getRangeConstraint().get().getAllowedRanges() + .asRanges(); assertEquals(1, ranges.size()); - final RangeConstraint range = ranges.get(0); - assertEquals(1, range.getMin().intValue()); - assertEquals(100, range.getMax().intValue()); + final Range range = ranges.iterator().next(); + assertEquals(1, range.lowerEndpoint().intValue()); + assertEquals(100, range.upperEndpoint().intValue()); assertEquals(BaseTypes.int16Type(), int16Ext.getBaseType()); } @Test public void testChoice() { - final Module foo = TestUtils.findModule(modules, "foo"); - final ContainerSchemaNode transfer = (ContainerSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "transfer")); - final ChoiceSchemaNode how = (ChoiceSchemaNode) transfer.getDataChildByName(QName.create(foo.getQNameModule(), "how")); - final Set cases = how.getCases(); + final ContainerSchemaNode transfer = (ContainerSchemaNode) foo.getDataChildByName( + QName.create(foo.getQNameModule(), "transfer")); + final ChoiceSchemaNode how = (ChoiceSchemaNode) transfer.getDataChildByName( + QName.create(foo.getQNameModule(), "how")); + final SortedMap cases = how.getCases(); assertEquals(5, cases.size()); ChoiceCaseNode input = null; ChoiceCaseNode output = null; - for (final ChoiceCaseNode caseNode : cases) { + for (final ChoiceCaseNode caseNode : cases.values()) { if ("input".equals(caseNode.getQName().getLocalName())) { input = caseNode; } else if ("output".equals(caseNode.getQName().getLocalName())) { @@ -615,16 +543,14 @@ public class YangParserTest { @Test public void testDeviation() { - final Module foo = TestUtils.findModule(modules, "foo"); final Set deviations = foo.getDeviations(); assertEquals(1, deviations.size()); final Deviation dev = deviations.iterator().next(); - assertEquals("system/user ref", dev.getReference()); + assertEquals(Optional.of("system/user ref"), dev.getReference()); - final List path = new ArrayList<>(); - path.add(QName.create(barNS, barRev, "interfaces")); - path.add(QName.create(barNS, barRev, "ifEntry")); - final SchemaPath expectedPath = SchemaPath.create(path, true); + final SchemaPath expectedPath = SchemaPath.create(true, + QName.create(BAR, "interfaces"), + QName.create(BAR, "ifEntry")); assertEquals(expectedPath, dev.getTargetPath()); assertEquals(DeviateKind.ADD, dev.getDeviates().iterator().next().getDeviateType()); @@ -632,8 +558,8 @@ public class YangParserTest { @Test public void testUnknownNode() { - final Module baz = TestUtils.findModule(modules, "baz"); - final ContainerSchemaNode network = (ContainerSchemaNode) baz.getDataChildByName(QName.create(baz.getQNameModule(), "network")); + final ContainerSchemaNode network = (ContainerSchemaNode) baz.getDataChildByName( + QName.create(baz.getQNameModule(), "network")); final List unknownNodes = network.getUnknownSchemaNodes(); assertEquals(1, unknownNodes.size()); final UnknownSchemaNode unknownNode = unknownNodes.get(0); @@ -643,39 +569,34 @@ public class YangParserTest { @Test public void testFeature() { - final Module baz = TestUtils.findModule(modules, "baz"); final Set features = baz.getFeatures(); assertEquals(1, features.size()); } @Test public void testExtension() { - final Module baz = TestUtils.findModule(modules, "baz"); final List extensions = baz.getExtensionSchemaNodes(); assertEquals(1, extensions.size()); final ExtensionDefinition extension = extensions.get(0); assertEquals("name", extension.getArgument()); - assertEquals("Takes as argument a name string. Makes the code generator use the given name in the #define.", + assertEquals( + Optional.of("Takes as argument a name string. Makes the code generator use the given name in the #define."), extension.getDescription()); assertTrue(extension.isYinElement()); } @Test public void testNotification() { - final Module baz = TestUtils.findModule(modules, "baz"); - final String expectedPrefix = "c"; - final Set notifications = baz.getNotifications(); assertEquals(1, notifications.size()); final NotificationDefinition notification = notifications.iterator().next(); // test SchemaNode args - final QName expectedQName = QName.create(bazNS, bazRev, "event"); - assertEquals(expectedQName, notification.getQName()); - final SchemaPath expectedPath = TestUtils.createPath(true, bazNS, bazRev, expectedPrefix, "event"); + assertEquals(QName.create(BAZ, "event"), notification.getQName()); + final SchemaPath expectedPath = SchemaPath.create(true, QName.create(BAZ, "event")); assertEquals(expectedPath, notification.getPath()); - assertNull(notification.getDescription()); - assertNull(notification.getReference()); + assertFalse(notification.getDescription().isPresent()); + assertFalse(notification.getReference().isPresent()); assertEquals(Status.CURRENT, notification.getStatus()); assertEquals(0, notification.getUnknownSchemaNodes().size()); // test DataNodeContainer args @@ -684,36 +605,32 @@ public class YangParserTest { assertEquals(0, notification.getGroupings().size()); assertEquals(0, notification.getUses().size()); - final LeafSchemaNode eventClass = (LeafSchemaNode) notification.getDataChildByName(QName.create(baz.getQNameModule(), "event-class")); + final LeafSchemaNode eventClass = (LeafSchemaNode) notification.getDataChildByName( + QName.create(baz.getQNameModule(), "event-class")); assertTrue(eventClass.getType() instanceof StringTypeDefinition); - final LeafSchemaNode severity = (LeafSchemaNode) notification.getDataChildByName(QName.create(baz.getQNameModule(), "severity")); + final LeafSchemaNode severity = (LeafSchemaNode) notification.getDataChildByName( + QName.create(baz.getQNameModule(), "severity")); assertTrue(severity.getType() instanceof StringTypeDefinition); } @Test public void testRpc() { - final Module baz = TestUtils.findModule(modules, "baz"); - final Set rpcs = baz.getRpcs(); assertEquals(1, rpcs.size()); final RpcDefinition rpc = rpcs.iterator().next(); - assertEquals("Retrieve all or part of a specified configuration.", rpc.getDescription()); - assertEquals("RFC 6241, Section 7.1", rpc.getReference()); + assertEquals(Optional.of("Retrieve all or part of a specified configuration."), rpc.getDescription()); + assertEquals(Optional.of("RFC 6241, Section 7.1"), rpc.getReference()); } @Test public void testTypePath() throws ParseException { - final Module bar = TestUtils.findModule(modules, "bar"); final Set> types = bar.getTypeDefinitions(); // int32-ext1 - final IntegerTypeDefinition int32ext1 = (IntegerTypeDefinition) TestUtils.findTypedef(types, "int32-ext1"); - final QName int32TypedefQName = int32ext1.getQName(); - - assertEquals(barNS, int32TypedefQName.getNamespace()); - assertEquals(barRev, int32TypedefQName.getRevision()); - assertEquals("int32-ext1", int32TypedefQName.getLocalName()); + final Int32TypeDefinition int32ext1 = (Int32TypeDefinition) TestUtils.findTypedef(types, "int32-ext1"); + final QName int32TypedefQName = QName.create(BAR, "int32-ext1"); + assertEquals(int32TypedefQName, int32ext1.getQName()); final SchemaPath typeSchemaPath = int32ext1.getPath(); final Iterable typePath = typeSchemaPath.getPathFromRoot(); @@ -722,21 +639,19 @@ public class YangParserTest { assertFalse(typePathIt.hasNext()); // int32-ext1/int32 - final IntegerTypeDefinition int32 = int32ext1.getBaseType(); + final Int32TypeDefinition int32 = int32ext1.getBaseType(); assertEquals(BaseTypes.int32Type(), int32); } @Test public void testTypePath2() throws ParseException { - final Module bar = TestUtils.findModule(modules, "bar"); final Set> types = bar.getTypeDefinitions(); // my-decimal-type final DecimalTypeDefinition myDecType = (DecimalTypeDefinition) TestUtils.findTypedef(types, "my-decimal-type"); final QName myDecTypeQName = myDecType.getQName(); - assertEquals(barNS, myDecTypeQName.getNamespace()); - assertEquals(barRev, myDecTypeQName.getRevision()); + assertEquals(BAR, myDecTypeQName.getModule()); assertEquals("my-decimal-type", myDecTypeQName.getLocalName()); final SchemaPath typeSchemaPath = myDecType.getPath(); @@ -749,8 +664,7 @@ public class YangParserTest { final DecimalTypeDefinition dec64 = myDecType.getBaseType(); final QName dec64QName = dec64.getQName(); - assertEquals(barNS, dec64QName.getNamespace()); - assertEquals(barRev, dec64QName.getRevision()); + assertEquals(BAR, dec64QName.getModule()); assertEquals("decimal64", dec64QName.getLocalName()); final SchemaPath dec64SchemaPath = dec64.getPath(); @@ -763,22 +677,22 @@ public class YangParserTest { private static void checkOrder(final Collection modules) { final Iterator it = modules.iterator(); - Module m = it.next(); - assertEquals("m2", m.getName()); - m = it.next(); - assertEquals("m4", m.getName()); - m = it.next(); - assertEquals("m6", m.getName()); - m = it.next(); - assertEquals("m8", m.getName()); - m = it.next(); - assertEquals("m7", m.getName()); - m = it.next(); - assertEquals("m5", m.getName()); - m = it.next(); - assertEquals("m3", m.getName()); - m = it.next(); - assertEquals("m1", m.getName()); + Module module = it.next(); + assertEquals("m2", module.getName()); + module = it.next(); + assertEquals("m4", module.getName()); + module = it.next(); + assertEquals("m6", module.getName()); + module = it.next(); + assertEquals("m8", module.getName()); + module = it.next(); + assertEquals("m7", module.getName()); + module = it.next(); + assertEquals("m5", module.getName()); + module = it.next(); + assertEquals("m3", module.getName()); + module = it.next(); + assertEquals("m1", module.getName()); } private static void assertSetEquals(final Set s1, final Set s2) { @@ -791,8 +705,6 @@ public class YangParserTest { @Test public void testSubmodules() { - final Module foo = TestUtils.findModule(modules, "foo"); - final DataSchemaNode id = foo.getDataChildByName(QName.create(foo.getQNameModule(), "id")); assertNotNull(id); final DataSchemaNode subExt = foo.getDataChildByName(QName.create(foo.getQNameModule(), "sub-ext")); @@ -808,32 +720,20 @@ public class YangParserTest { public void unknownStatementInSubmoduleHeaderTest() throws IOException, URISyntaxException, ReactorException { final StatementStreamSource yang1 = sourceForResource("/yang-grammar-test/revisions-extension.yang"); final StatementStreamSource yang2 = sourceForResource("/yang-grammar-test/submodule-header-extension.yang"); - - try { - TestUtils.parseYangSources(yang1, yang2); - } catch (final YangParseException e) { - e.printStackTrace(); - fail("YangParseException should not be thrown"); - } - + TestUtils.parseYangSources(yang1, yang2); } @Test public void unknownStatementBetweenRevisionsTest() throws ReactorException { - - final StatementStreamSource yangModule = sourceForResource("/yang-grammar-test/revisions-extension.yang"); - final StatementStreamSource yangSubmodule = sourceForResource( - "/yang-grammar-test/submodule-header-extension.yang"); - - final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(); - reactor.addSources(yangModule, yangSubmodule); - - final SchemaContext result = reactor.buildEffective(); + final SchemaContext result = DefaultReactors.defaultReactor().newBuild() + .addSource(sourceForResource("/yang-grammar-test/revisions-extension.yang")) + .addSource(sourceForResource("/yang-grammar-test/submodule-header-extension.yang")) + .buildEffective(); assertNotNull(result); } @Test - public void unknownStatementsInStatementsTest() throws ReactorException { + public void unknownStatementsInStatementsTest() { final StatementStreamSource yangFile1 = sourceForResource( "/yang-grammar-test/stmtsep-in-statements.yang"); @@ -842,12 +742,12 @@ public class YangParserTest { final StatementStreamSource yangFile3 = sourceForResource( "/yang-grammar-test/stmtsep-in-statements-sub.yang"); - final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(); - reactor.addSources(yangFile1, yangFile2, yangFile3); + final BuildAction reactor = DefaultReactors.defaultReactor().newBuild() + .addSources(yangFile1, yangFile2, yangFile3); // TODO: change test or create new module in order to respect new statement parser validations try { final SchemaContext result = reactor.buildEffective(); - } catch (final Exception e) { + } catch (final ReactorException e) { assertEquals(SomeModifiersUnresolvedException.class, e.getClass()); assertTrue(e.getCause() instanceof SourceException); assertTrue(e.getCause().getMessage().startsWith("aaa is not a YANG statement or use of extension"));