X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-parser-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Fimpl%2FYangParserWithContextTest.java;h=7b0a59a367f06cf244edecbb7d8c122add62df18;hb=85a9a2f03fba2912e6824d546c7b250c442b201a;hp=f7ed184300a639069854b8cde0e3edac25b2aa86;hpb=b3e9bdc78ca793648a8cc69b68af0c7f46727cd4;p=yangtools.git diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserWithContextTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserWithContextTest.java index f7ed184300..7b0a59a367 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserWithContextTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserWithContextTest.java @@ -12,19 +12,21 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import com.google.common.collect.Lists; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; +import java.math.BigInteger; import java.net.URI; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Map; import java.util.Set; - -import org.junit.Ignore; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode; @@ -45,11 +47,9 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; import org.opendaylight.yangtools.yang.model.api.UsesNode; import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint; -import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser; +import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser; import org.opendaylight.yangtools.yang.model.util.ExtendedType; -import com.google.common.collect.Lists; - public class YangParserWithContextTest { private final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); private final YangParserImpl parser = new YangParserImpl(); @@ -73,22 +73,20 @@ public class YangParserWithContextTest { QName qname = leafType.getQName(); assertEquals(URI.create("urn:simple.demo.test1"), qname.getNamespace()); assertEquals(simpleDateFormat.parse("2013-06-18"), qname.getRevision()); - assertEquals("t1", qname.getPrefix()); assertEquals("port-number", qname.getLocalName()); ExtendedType leafBaseType = (ExtendedType) leafType.getBaseType(); qname = leafBaseType.getQName(); assertEquals(URI.create("urn:ietf:params:xml:ns:yang:ietf-inet-types"), qname.getNamespace()); assertEquals(simpleDateFormat.parse("2010-09-24"), qname.getRevision()); - assertEquals("inet", qname.getPrefix()); assertEquals("port-number", qname.getLocalName()); ExtendedType dscpExt = (ExtendedType) TestUtils.findTypedef(module.getTypeDefinitions(), "dscp-ext"); List ranges = dscpExt.getRangeConstraints(); assertEquals(1, ranges.size()); RangeConstraint range = ranges.get(0); - assertEquals(0L, range.getMin()); - assertEquals(63L, range.getMax()); + assertEquals(BigInteger.ZERO, range.getMin()); + assertEquals(BigInteger.valueOf(63), range.getMax()); } @Test @@ -277,8 +275,8 @@ public class YangParserWithContextTest { SchemaContext context; File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").toURI()); File dependenciesDir = new File(getClass().getResource("/ietf").toURI()); - YangModelParser parser = new YangParserImpl(); - context = parser.resolveSchemaContext(parser.parseYangModels(yangFile, dependenciesDir)); + YangContextParser parser = new YangParserImpl(); + context = parser.parseFile(yangFile, dependenciesDir); Module module; try (InputStream stream = new FileInputStream(new File(getClass().getResource("/context-test/test3.yang") @@ -294,14 +292,12 @@ public class YangParserWithContextTest { QName idQName = identity.getQName(); assertEquals(URI.create("urn:simple.demo.test3"), idQName.getNamespace()); assertEquals(simpleDateFormat.parse("2013-06-18"), idQName.getRevision()); - assertEquals("t3", idQName.getPrefix()); assertEquals("pt", idQName.getLocalName()); IdentitySchemaNode baseIdentity = identity.getBaseIdentity(); QName idBaseQName = baseIdentity.getQName(); assertEquals(URI.create("urn:custom.types.demo"), idBaseQName.getNamespace()); assertEquals(simpleDateFormat.parse("2012-04-16"), idBaseQName.getRevision()); - assertEquals("iit", idBaseQName.getPrefix()); assertEquals("service-type", idBaseQName.getLocalName()); } @@ -310,8 +306,8 @@ public class YangParserWithContextTest { SchemaContext context; File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").toURI()); File dependenciesDir = new File(getClass().getResource("/ietf").toURI()); - YangModelParser parser = new YangParserImpl(); - context = parser.resolveSchemaContext(parser.parseYangModels(yangFile, dependenciesDir)); + YangContextParser parser = new YangParserImpl(); + context = parser.parseFile(yangFile, dependenciesDir); Module module; try (InputStream stream = new FileInputStream(new File(getClass().getResource("/context-test/test3.yang") @@ -327,38 +323,27 @@ public class YangParserWithContextTest { QName unType = un.getNodeType(); assertEquals(URI.create("urn:custom.types.demo"), unType.getNamespace()); assertEquals(simpleDateFormat.parse("2012-04-16"), unType.getRevision()); - assertEquals("custom", unType.getPrefix()); assertEquals("mountpoint", unType.getLocalName()); assertEquals("point", un.getNodeParameter()); assertNotNull(un.getExtensionDefinition()); } - @Ignore @Test public void testAugment() throws Exception { // load first module - SchemaContext context; String resource = "/context-augment-test/test4.yang"; - - try (InputStream stream = new FileInputStream(new File(getClass().getResource(resource).toURI()))) { - context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream))); - } + SchemaContext context = parser.parseFiles(Collections.singleton(new File(getClass().getResource(resource) + .toURI()))); // load another modules and parse them against already existing context - Set modules; - try (InputStream stream1 = new FileInputStream(new File(getClass().getResource( - "/context-augment-test/test1.yang").toURI())); - InputStream stream2 = new FileInputStream(new File(getClass().getResource( - "/context-augment-test/test2.yang").toURI())); - InputStream stream3 = new FileInputStream(new File(getClass().getResource( - "/context-augment-test/test3.yang").toURI()))) { - List input = Lists.newArrayList(stream1, stream2, stream3); - modules = TestUtils.loadModulesWithContext(input, context); - } + File test1 = new File(getClass().getResource("/context-augment-test/test1.yang").toURI()); + File test2 = new File(getClass().getResource("/context-augment-test/test2.yang").toURI()); + File test3 = new File(getClass().getResource("/context-augment-test/test3.yang").toURI()); + Set modules = parser.parseFiles(Arrays.asList(test1, test2, test3), context).getModules(); assertNotNull(modules); - Module t3 = TestUtils.findModule(modules, "test4"); - ContainerSchemaNode interfaces = (ContainerSchemaNode) t3.getDataChildByName("interfaces"); + Module t4 = TestUtils.findModule(modules, "test4"); + ContainerSchemaNode interfaces = (ContainerSchemaNode) t4.getDataChildByName("interfaces"); ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName("ifEntry"); // test augmentation process