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=0d8ed824bfec91e7988e53b8164f121eefa6ada3;hb=573a504e2cb3463c7daa3a452ecabb1c5f38a4a5;hp=6117b256964aa7335c1a46db9b3c32cc9606f910;hpb=c87589087031a10996e0c11740d8a9f41b991c05;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 6117b25696..0d8ed824bf 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 @@ -9,6 +9,7 @@ package org.opendaylight.yangtools.yang.parser.impl; import static org.junit.Assert.*; +import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.net.URI; @@ -20,7 +21,6 @@ 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; @@ -41,27 +41,25 @@ 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.util.ExtendedType; import com.google.common.collect.Lists; -@Ignore public class YangParserWithContextTest { private final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); private final YangParserImpl parser = new YangParserImpl(); @Test public void testTypeFromContext() throws Exception { - SchemaContext context = null; - String resource = "/types/ietf-inet-types@2010-09-24.yang"; + String resource = "/ietf/ietf-inet-types@2010-09-24.yang"; InputStream stream = new FileInputStream(getClass().getResource(resource).getPath()); - context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream))); + SchemaContext context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream))); stream.close(); - Module module = null; resource = "/context-test/test1.yang"; InputStream stream2 = new FileInputStream(getClass().getResource(resource).getPath()); - module = TestUtils.loadModuleWithContext(stream2, context); + Module module = TestUtils.loadModuleWithContext(stream2, context); stream2.close(); assertNotNull(module); @@ -82,7 +80,7 @@ public class YangParserWithContextTest { assertEquals("port-number", qname.getLocalName()); ExtendedType dscpExt = (ExtendedType) TestUtils.findTypedef(module.getTypeDefinitions(), "dscp-ext"); - List ranges = dscpExt.getRanges(); + List ranges = dscpExt.getRangeConstraints(); assertEquals(1, ranges.size()); RangeConstraint range = ranges.get(0); assertEquals(0L, range.getMin()); @@ -91,13 +89,13 @@ public class YangParserWithContextTest { @Test public void testUsesFromContext() throws Exception { - SchemaContext context = null; - try (InputStream stream1 = new FileInputStream(getClass().getResource("/model/custom.yang").getPath()); - InputStream stream2 = new FileInputStream(getClass().getResource("/model/types.yang").getPath()); - InputStream stream3 = new FileInputStream(getClass().getResource("/model/nodes.yang").getPath())) { + SchemaContext context; + try (InputStream stream1 = new FileInputStream(getClass().getResource("/model/baz.yang").getPath()); + InputStream stream2 = new FileInputStream(getClass().getResource("/model/bar.yang").getPath()); + InputStream stream3 = new FileInputStream(getClass().getResource("/model/foo.yang").getPath())) { context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream1, stream2, stream3))); } - Module testModule = null; + Module testModule; try (InputStream stream = new FileInputStream(getClass().getResource("/context-test/test2.yang").getPath())) { testModule = TestUtils.loadModuleWithContext(stream, context); } @@ -107,7 +105,7 @@ public class YangParserWithContextTest { // suffix _g = defined in grouping from context // get grouping - Module contextModule = context.findModuleByNamespace(URI.create("urn:custom.nodes.test")); + Module contextModule = context.findModuleByNamespace(URI.create("urn:opendaylight.baz")).iterator().next(); assertNotNull(contextModule); Set groupings = contextModule.getGroupings(); assertEquals(1, groupings.size()); @@ -194,13 +192,13 @@ public class YangParserWithContextTest { @Test public void testUsesRefineFromContext() throws Exception { - SchemaContext context = null; - try (InputStream stream1 = new FileInputStream(getClass().getResource("/model/custom.yang").getPath()); - InputStream stream2 = new FileInputStream(getClass().getResource("/model/types.yang").getPath()); - InputStream stream3 = new FileInputStream(getClass().getResource("/model/nodes.yang").getPath())) { + SchemaContext context; + try (InputStream stream1 = new FileInputStream(getClass().getResource("/model/baz.yang").getPath()); + InputStream stream2 = new FileInputStream(getClass().getResource("/model/bar.yang").getPath()); + InputStream stream3 = new FileInputStream(getClass().getResource("/model/foo.yang").getPath())) { context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream1, stream2, stream3))); } - Module module = null; + Module module; try (InputStream stream = new FileInputStream(getClass().getResource("/context-test/test2.yang").getPath())) { module = TestUtils.loadModuleWithContext(stream, context); } @@ -213,8 +211,8 @@ public class YangParserWithContextTest { UsesNode usesNode = usesNodes.iterator().next(); // test grouping path - List path = new ArrayList(); - QName qname = new QName(URI.create("urn:custom.nodes.test"), simpleDateFormat.parse("2013-02-27"), "c", + List path = new ArrayList<>(); + QName qname = new QName(URI.create("urn:opendaylight.baz"), simpleDateFormat.parse("2013-02-27"), "baz", "target"); path.add(qname); SchemaPath expectedPath = new SchemaPath(path, true); @@ -270,12 +268,13 @@ public class YangParserWithContextTest { @Test public void testIdentity() throws Exception { - SchemaContext context = null; - try (InputStream stream = new FileInputStream(getClass().getResource("/types/custom-types-test@2012-4-4.yang") - .getPath())) { - context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream))); - } - Module module = null; + SchemaContext context; + File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").getPath()); + File dependenciesDir = new File(getClass().getResource("/ietf").getPath()); + YangModelParser parser = new YangParserImpl(); + context = parser.resolveSchemaContext(parser.parseYangModels(yangFile, dependenciesDir)); + + Module module; try (InputStream stream = new FileInputStream(getClass().getResource("/context-test/test3.yang").getPath())) { module = TestUtils.loadModuleWithContext(stream, context); } @@ -301,13 +300,13 @@ public class YangParserWithContextTest { @Test public void testUnknownNodes() throws Exception { - SchemaContext context = null; - try (InputStream stream = new FileInputStream(getClass().getResource("/types/custom-types-test@2012-4-4.yang") - .getPath())) { - context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream))); - } + SchemaContext context; + File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").getPath()); + File dependenciesDir = new File(getClass().getResource("/ietf").getPath()); + YangModelParser parser = new YangParserImpl(); + context = parser.resolveSchemaContext(parser.parseYangModels(yangFile, dependenciesDir)); - Module module = null; + Module module; try (InputStream stream = new FileInputStream(getClass().getResource("/context-test/test3.yang").getPath())) { module = TestUtils.loadModuleWithContext(stream, context); } @@ -323,12 +322,13 @@ public class YangParserWithContextTest { assertEquals("custom", unType.getPrefix()); assertEquals("mountpoint", unType.getLocalName()); assertEquals("point", un.getNodeParameter()); + assertNotNull(un.getExtensionDefinition()); } @Test public void testAugment() throws Exception { // load first module - SchemaContext context = null; + SchemaContext context; String resource = "/context-augment-test/test4.yang"; try (InputStream stream = new FileInputStream(getClass().getResource(resource).getPath())) { @@ -341,7 +341,7 @@ public class YangParserWithContextTest { ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName("ifEntry"); // load another modules and parse them against already existing context - Set modules = null; + Set modules; try (InputStream stream1 = new FileInputStream(getClass().getResource("/context-augment-test/test1.yang") .getPath()); InputStream stream2 = new FileInputStream(getClass().getResource("/context-augment-test/test2.yang") @@ -374,15 +374,15 @@ public class YangParserWithContextTest { @Test public void testDeviation() throws Exception { // load first module - SchemaContext context = null; - String resource = "/model/types.yang"; + SchemaContext context; + String resource = "/model/bar.yang"; try (InputStream stream = new FileInputStream(getClass().getResource(resource).getPath())) { context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream))); } // load another modules and parse them against already existing context - Set modules = null; + Set modules; try (InputStream stream = new FileInputStream(getClass().getResource("/context-test/deviation-test.yang") .getPath())) { List input = Lists.newArrayList(stream); @@ -398,12 +398,12 @@ public class YangParserWithContextTest { assertEquals("system/user ref", dev.getReference()); - URI expectedNS = URI.create("urn:simple.types.test"); + URI expectedNS = URI.create("urn:opendaylight.bar"); DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date expectedRev = simpleDateFormat.parse("2013-07-03"); - List path = new ArrayList(); - path.add(new QName(expectedNS, expectedRev, "t", "interfaces")); - path.add(new QName(expectedNS, expectedRev, "t", "ifEntry")); + List path = new ArrayList<>(); + path.add(new QName(expectedNS, expectedRev, "bar", "interfaces")); + path.add(new QName(expectedNS, expectedRev, "bar", "ifEntry")); SchemaPath expectedPath = new SchemaPath(path, true); assertEquals(expectedPath, dev.getTargetPath());