From 573a504e2cb3463c7daa3a452ecabb1c5f38a4a5 Mon Sep 17 00:00:00 2001 From: Martin Vitez Date: Tue, 15 Oct 2013 16:55:21 +0200 Subject: [PATCH] Fixed bug in resolving groupings. Fixed bug which cause that nodes added by uses were generated duplicated. Updated tests, minor code refactoring. Change-Id: I695fef3ec65baae40c2b57bc68054f930f1fdd84 Signed-off-by: Martin Vitez --- .../parser/builder/impl/ModuleBuilder.java | 5 + .../yang/parser/util/GroupingUtils.java | 16 +- .../yang/parser/impl/AugmentTest.java | 264 ++++++++------- .../yang/parser/impl/GroupingTest.java | 34 +- .../yangtools/yang/parser/impl/TestUtils.java | 43 ++- .../yang/parser/impl/UsesAugmentTest.java | 2 +- .../yang/parser/impl/YangParserTest.java | 301 +++++++++--------- .../impl/YangParserWithContextTest.java | 58 ++-- .../augment-test/augment-in-augment/bar.yang | 49 +++ .../augment-test/augment-in-augment/baz.yang | 94 ++++++ .../augment-test/augment-in-augment/foo.yang | 62 ++++ .../context-test/deviation-test.yang | 2 +- .../test/resources/context-test/test2.yang | 2 +- .../resources/model/{types.yang => bar.yang} | 8 +- .../resources/model/{custom.yang => baz.yang} | 30 +- .../resources/model/{nodes.yang => foo.yang} | 44 +-- 16 files changed, 627 insertions(+), 387 deletions(-) create mode 100644 yang/yang-parser-impl/src/test/resources/augment-test/augment-in-augment/bar.yang create mode 100644 yang/yang-parser-impl/src/test/resources/augment-test/augment-in-augment/baz.yang create mode 100644 yang/yang-parser-impl/src/test/resources/augment-test/augment-in-augment/foo.yang rename yang/yang-parser-impl/src/test/resources/model/{types.yang => bar.yang} (92%) rename yang/yang-parser-impl/src/test/resources/model/{custom.yang => baz.yang} (88%) rename yang/yang-parser-impl/src/test/resources/model/{nodes.yang => foo.yang} (86%) diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleBuilder.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleBuilder.java index e49a181717..fb9cf06831 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleBuilder.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleBuilder.java @@ -434,6 +434,11 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { } else { // ... or 'uses' statement if (parent instanceof UsesNodeBuilder) { + if (augmentTargetStr.startsWith("/")) { + throw new YangParseException(name, line, + "If 'augment' statement is a substatement to the 'uses' statement, it cannot contain absolute path (" + + augmentTargetStr + ")"); + } ((UsesNodeBuilder) parent).addAugment(builder); } else { throw new YangParseException(name, line, "Augment can be declared only under module or uses statement."); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/GroupingUtils.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/GroupingUtils.java index 14718e6a4b..80fb2c4479 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/GroupingUtils.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/GroupingUtils.java @@ -213,7 +213,7 @@ public final class GroupingUtils { // child nodes for (DataSchemaNodeBuilder child : usesNode.getTargetChildren()) { if (child instanceof GroupingMember) { - ((GroupingMember) child).setAddedByUses(true); + setAddedByUsesToNode((GroupingMember)child); } if (child instanceof GroupingMember) { @@ -265,6 +265,17 @@ public final class GroupingUtils { } } + private static void setAddedByUsesToNode(GroupingMember node) { + node.setAddedByUses(true); + if (node instanceof DataNodeContainerBuilder) { + for (DataSchemaNodeBuilder child : ((DataNodeContainerBuilder)node).getChildNodeBuilders()) { + if (child instanceof GroupingMember) { + setAddedByUsesToNode((GroupingMember)child); + } + } + } + } + /** * Read data defined in target grouping builder, make a copy and add them to * uses node builder. @@ -324,6 +335,9 @@ public final class GroupingUtils { } if (!exists) { DataSchemaNodeBuilder copy = CopyUtils.copy(childNode, parent, true); + if (copy instanceof GroupingMember) { + setAddedByUsesToNode((GroupingMember)copy); + } collection.add(copy); } } diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentTest.java index 6ee61357e5..dfa7bc4830 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentTest.java @@ -14,13 +14,14 @@ import java.net.URI; import java.text.DateFormat; import java.text.ParseException; 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.Set; -import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; @@ -36,81 +37,74 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.model.util.BaseTypes; public class AugmentTest { + private static final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); + + private static final URI fooNS = URI.create("urn:opendaylight.foo"); + private static final URI barNS = URI.create("urn:opendaylight.bar"); + private static final URI bazNS = URI.create("urn:opendaylight.baz"); + private static Date fooRev; + private static Date barRev; + private static Date bazRev; + private static final String foo = "foo"; + private static final String bar = "bar"; + private static final String baz = "baz"; + private static QName q0; + private static QName q1; + private static QName q2; - private final URI types1NS = URI.create("urn:simple.nodes.test"); - private final URI types2NS = URI.create("urn:simple.types.test"); - private final URI types3NS = URI.create("urn:custom.nodes.test"); - private Date types1Rev; - private Date types2Rev; - private Date types3Rev; - private final String t1 = "n"; - private final String t2 = "t"; - private final String t3 = "c"; - private QName q0; - private QName q1; - private QName q2; - - private final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); private Set modules; - @Before - public void init() throws FileNotFoundException, ParseException { - types1Rev = simpleDateFormat.parse("2013-02-27"); - types2Rev = simpleDateFormat.parse("2013-07-03"); - types3Rev = simpleDateFormat.parse("2013-02-27"); + @BeforeClass + public static void init() throws FileNotFoundException, ParseException { + fooRev = simpleDateFormat.parse("2013-10-13"); + barRev = simpleDateFormat.parse("2013-10-14"); + bazRev = simpleDateFormat.parse("2013-10-15"); - q0 = new QName(types2NS, types2Rev, t2, "interfaces"); - q1 = new QName(types2NS, types2Rev, t2, "ifEntry"); - q2 = new QName(types3NS, types3Rev, t3, "augment-holder"); - - modules = TestUtils.loadModules(getClass().getResource("/model").getPath()); - assertEquals(3, modules.size()); + q0 = new QName(barNS, barRev, bar, "interfaces"); + q1 = new QName(barNS, barRev, bar, "ifEntry"); + q2 = new QName(bazNS, bazRev, baz, "augment-holder"); } @Test - public void testAugmentParsing() { + public void testAugmentParsing() throws Exception { + modules = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment").getPath()); SchemaPath expectedSchemaPath; - QName[] qnames = new QName[3]; - qnames[0] = q0; - qnames[1] = q1; - qnames[2] = q2; + List qnames = new ArrayList<>(); + qnames.add(q0); + qnames.add(q1); + qnames.add(q2); - // testfile1 - Module module1 = TestUtils.findModule(modules, "nodes"); + // foo.yang + Module module1 = TestUtils.findModule(modules, "foo"); Set augmentations = module1.getAugmentations(); assertEquals(1, augmentations.size()); AugmentationSchema augment = augmentations.iterator().next(); assertNotNull(augment); - expectedSchemaPath = new SchemaPath(Arrays.asList(qnames), true); + expectedSchemaPath = new SchemaPath(qnames, true); assertEquals(expectedSchemaPath, augment.getTargetPath()); Set augmentChildren = augment.getChildNodes(); - assertEquals(5, augmentChildren.size()); + assertEquals(4, augmentChildren.size()); for (DataSchemaNode dsn : augmentChildren) { TestUtils.checkIsAugmenting(dsn, false); } LeafSchemaNode ds0ChannelNumber = (LeafSchemaNode) augment.getDataChildByName("ds0ChannelNumber"); LeafSchemaNode interfaceId = (LeafSchemaNode) augment.getDataChildByName("interface-id"); - LeafSchemaNode myType = (LeafSchemaNode) augment.getDataChildByName("my-type"); ContainerSchemaNode schemas = (ContainerSchemaNode) augment.getDataChildByName("schemas"); ChoiceNode odl = (ChoiceNode) augment.getDataChildByName("odl"); assertNotNull(ds0ChannelNumber); assertNotNull(interfaceId); - assertNotNull(myType); assertNotNull(schemas); assertNotNull(odl); - qnames = new QName[4]; - qnames[0] = q0; - qnames[1] = q1; - qnames[2] = q2; - // leaf ds0ChannelNumber - qnames[3] = new QName(types1NS, types1Rev, t1, "ds0ChannelNumber"); - expectedSchemaPath = new SchemaPath(Arrays.asList(qnames), true); + QName qname = new QName(fooNS, fooRev, foo, "ds0ChannelNumber"); + qnames.add(qname); + assertEquals(qname, ds0ChannelNumber.getQName()); + expectedSchemaPath = new SchemaPath(qnames, true); assertEquals(expectedSchemaPath, ds0ChannelNumber.getPath()); assertFalse(ds0ChannelNumber.isAugmenting()); // type of leaf ds0ChannelNumber @@ -120,37 +114,40 @@ public class AugmentTest { assertEquals(expectedSchemaPath, ds0ChannelNumber.getType().getPath()); // leaf interface-id - qnames[3] = new QName(types1NS, types1Rev, t1, "interface-id"); - expectedSchemaPath = new SchemaPath(Arrays.asList(qnames), true); + qname = new QName(fooNS, fooRev, foo, "interface-id"); + assertEquals(qname, interfaceId.getQName()); + qnames.set(3, qname); + expectedSchemaPath = new SchemaPath(qnames, true); assertEquals(expectedSchemaPath, interfaceId.getPath()); assertFalse(interfaceId.isAugmenting()); - // leaf my-type - qnames[3] = new QName(types1NS, types1Rev, t1, "my-type"); - expectedSchemaPath = new SchemaPath(Arrays.asList(qnames), true); - assertEquals(expectedSchemaPath, myType.getPath()); - assertFalse(myType.isAugmenting()); - // container schemas - qnames[3] = new QName(types1NS, types1Rev, t1, "schemas"); - expectedSchemaPath = new SchemaPath(Arrays.asList(qnames), true); + qname = new QName(fooNS, fooRev, foo, "schemas"); + assertEquals(qname, schemas.getQName()); + qnames.set(3, qname); + expectedSchemaPath = new SchemaPath(qnames, true); assertEquals(expectedSchemaPath, schemas.getPath()); assertFalse(schemas.isAugmenting()); // choice odl - qnames[3] = new QName(types1NS, types1Rev, t1, "odl"); - expectedSchemaPath = new SchemaPath(Arrays.asList(qnames), true); + qname = new QName(fooNS, fooRev, foo, "odl"); + assertEquals(qname, odl.getQName()); + qnames.set(3, qname); + expectedSchemaPath = new SchemaPath(qnames, true); assertEquals(expectedSchemaPath, odl.getPath()); assertFalse(odl.isAugmenting()); - // testfile3 - Module module3 = TestUtils.findModule(modules, "custom"); + // baz.yang + Module module3 = TestUtils.findModule(modules, "baz"); augmentations = module3.getAugmentations(); - assertEquals(2, augmentations.size()); + assertEquals(3, augmentations.size()); AugmentationSchema augment1 = null; AugmentationSchema augment2 = null; + AugmentationSchema augment3 = null; for (AugmentationSchema as : augmentations) { - if ("if:ifType='ds0'".equals(as.getWhenCondition().toString())) { + if (as.getWhenCondition() == null) { + augment3 = as; + } else if ("if:ifType='ds0'".equals(as.getWhenCondition().toString())) { augment1 = as; } else if ("if:ifType='ds2'".equals(as.getWhenCondition().toString())) { augment2 = as; @@ -158,6 +155,7 @@ public class AugmentTest { } assertNotNull(augment1); assertNotNull(augment2); + assertNotNull(augment3); assertEquals(1, augment1.getChildNodes().size()); ContainerSchemaNode augmentHolder = (ContainerSchemaNode) augment1.getDataChildByName("augment-holder"); @@ -166,73 +164,86 @@ public class AugmentTest { assertEquals(1, augment2.getChildNodes().size()); ContainerSchemaNode augmentHolder2 = (ContainerSchemaNode) augment2.getDataChildByName("augment-holder2"); assertNotNull(augmentHolder2); + + assertEquals(1, augment3.getChildNodes().size()); + LeafSchemaNode pause = (LeafSchemaNode) augment3.getDataChildByName("pause"); + assertNotNull(pause); } @Test - public void testAugmentResolving() throws ParseException { - Module module2 = TestUtils.findModule(modules, "types"); + public void testAugmentResolving() throws Exception { + modules = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment").getPath()); + Module module2 = TestUtils.findModule(modules, "bar"); ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName("interfaces"); ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName("ifEntry"); - ContainerSchemaNode augmentedContainer = (ContainerSchemaNode) ifEntry.getDataChildByName("augment-holder"); - TestUtils.checkIsAugmenting(augmentedContainer, true); - // testfile1.yang - // augment "/data:interfaces/data:ifEntry/t3:augment-holder" - LeafSchemaNode ds0ChannelNumber = (LeafSchemaNode) augmentedContainer.getDataChildByName("ds0ChannelNumber"); - LeafSchemaNode interfaceId = (LeafSchemaNode) augmentedContainer.getDataChildByName("interface-id"); - LeafSchemaNode myType = (LeafSchemaNode) augmentedContainer.getDataChildByName("my-type"); - ContainerSchemaNode schemas = (ContainerSchemaNode) augmentedContainer.getDataChildByName("schemas"); - ChoiceNode odl = (ChoiceNode) augmentedContainer.getDataChildByName("odl"); + SchemaPath expectedPath; + List qnames = new ArrayList<>(); + qnames.add(q0); + qnames.add(q1); + qnames.add(q2); + + // baz.yang + // augment "/br:interfaces/br:ifEntry" { + ContainerSchemaNode augmentHolder = (ContainerSchemaNode) ifEntry.getDataChildByName("augment-holder"); + TestUtils.checkIsAugmenting(augmentHolder, true); + assertEquals(q2, augmentHolder.getQName()); + expectedPath = new SchemaPath(qnames, true); + assertEquals(expectedPath, augmentHolder.getPath()); + + // foo.yang + // augment "/br:interfaces/br:ifEntry/bz:augment-holder" + LeafSchemaNode ds0ChannelNumber = (LeafSchemaNode) augmentHolder.getDataChildByName("ds0ChannelNumber"); + LeafSchemaNode interfaceId = (LeafSchemaNode) augmentHolder.getDataChildByName("interface-id"); + ContainerSchemaNode schemas = (ContainerSchemaNode) augmentHolder.getDataChildByName("schemas"); + ChoiceNode odl = (ChoiceNode) augmentHolder.getDataChildByName("odl"); assertNotNull(ds0ChannelNumber); assertNotNull(interfaceId); - assertNotNull(myType); assertNotNull(schemas); assertNotNull(odl); - SchemaPath expectedPath; - QName[] qnames = new QName[4]; - qnames[0] = q0; - qnames[1] = q1; - qnames[2] = q2; - // leaf ds0ChannelNumber - qnames[3] = new QName(types1NS, types1Rev, t1, "ds0ChannelNumber"); - expectedPath = new SchemaPath(Arrays.asList(qnames), true); + QName qname = new QName(fooNS, fooRev, foo, "ds0ChannelNumber"); + assertEquals(qname, ds0ChannelNumber.getQName()); + qnames.add(qname); + expectedPath = new SchemaPath(qnames, true); assertEquals(expectedPath, ds0ChannelNumber.getPath()); // leaf interface-id - qnames[3] = new QName(types1NS, types1Rev, t1, "interface-id"); - expectedPath = new SchemaPath(Arrays.asList(qnames), true); + qname = new QName(fooNS, fooRev, foo, "interface-id"); + assertEquals(qname, interfaceId.getQName()); + qnames.set(3, qname); + expectedPath = new SchemaPath(qnames, true); assertEquals(expectedPath, interfaceId.getPath()); - // leaf my-type - qnames[3] = new QName(types1NS, types1Rev, t1, "my-type"); - expectedPath = new SchemaPath(Arrays.asList(qnames), true); - assertEquals(expectedPath, myType.getPath()); - // container schemas - qnames[3] = new QName(types1NS, types1Rev, t1, "schemas"); - expectedPath = new SchemaPath(Arrays.asList(qnames), true); + qname = new QName(fooNS, fooRev, foo, "schemas"); + assertEquals(qname, schemas.getQName()); + qnames.set(3, qname); + expectedPath = new SchemaPath(qnames, true); assertEquals(expectedPath, schemas.getPath()); // choice odl - qnames[3] = new QName(types1NS, types1Rev, t1, "odl"); - expectedPath = new SchemaPath(Arrays.asList(qnames), true); + qname = new QName(fooNS, fooRev, foo, "odl"); + assertEquals(qname, odl.getQName()); + qnames.set(3, qname); + expectedPath = new SchemaPath(qnames, true); assertEquals(expectedPath, odl.getPath()); } @Test - public void testAugmentChoice() throws ParseException { - Module module2 = TestUtils.findModule(modules, "types"); + public void testAugmentedChoice() throws Exception { + modules = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment").getPath()); + Module module2 = TestUtils.findModule(modules, "bar"); ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName("interfaces"); ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName("ifEntry"); - ContainerSchemaNode augmentedContainer = (ContainerSchemaNode) ifEntry.getDataChildByName("augment-holder"); - TestUtils.checkIsAugmenting(augmentedContainer, true); + ContainerSchemaNode augmentedHolder = (ContainerSchemaNode) ifEntry.getDataChildByName("augment-holder"); + TestUtils.checkIsAugmenting(augmentedHolder, true); - // testfile1.yang - // augment "/data:interfaces/data:ifEntry/t3:augment-holder" - ChoiceNode odl = (ChoiceNode) augmentedContainer.getDataChildByName("odl"); + // foo.yang + // augment "/br:interfaces/br:ifEntry/bz:augment-holder" + ChoiceNode odl = (ChoiceNode) augmentedHolder.getDataChildByName("odl"); assertNotNull(odl); Set cases = odl.getCases(); assertEquals(4, cases.size()); @@ -260,61 +271,69 @@ public class AugmentTest { assertNotNull(node3); SchemaPath expectedPath; - QName[] qnames = new QName[5]; - qnames[0] = q0; - qnames[1] = q1; - qnames[2] = q2; - qnames[3] = new QName(types1NS, types1Rev, t1, "odl"); + List qnames = new ArrayList<>(); + qnames.add(q0); + qnames.add(q1); + qnames.add(q2); + qnames.add(new QName(fooNS, fooRev, foo, "odl")); // case id - qnames[4] = new QName(types1NS, types1Rev, t1, "id"); - expectedPath = new SchemaPath(Arrays.asList(qnames), true); + QName qname = new QName(fooNS, fooRev, foo, "id"); + assertEquals(qname, id.getQName()); + qnames.add(qname); + expectedPath = new SchemaPath(qnames, true); assertEquals(expectedPath, id.getPath()); Set idChildren = id.getChildNodes(); assertEquals(1, idChildren.size()); // case node1 - qnames[4] = new QName(types1NS, types1Rev, t1, "node1"); - expectedPath = new SchemaPath(Arrays.asList(qnames), true); + qname = new QName(fooNS, fooRev, foo, "node1"); + assertEquals(qname, node1.getQName()); + qnames.set(4, qname); + expectedPath = new SchemaPath(qnames, true); assertEquals(expectedPath, node1.getPath()); Set node1Children = node1.getChildNodes(); assertTrue(node1Children.isEmpty()); // case node2 - qnames[4] = new QName(types1NS, types1Rev, t1, "node2"); - expectedPath = new SchemaPath(Arrays.asList(qnames), true); + qname = new QName(fooNS, fooRev, foo, "node2"); + assertEquals(qname, node2.getQName()); + qnames.set(4, qname); + expectedPath = new SchemaPath(qnames, true); assertEquals(expectedPath, node2.getPath()); Set node2Children = node2.getChildNodes(); assertTrue(node2Children.isEmpty()); // case node3 - qnames[4] = new QName(types1NS, types1Rev, t1, "node3"); - expectedPath = new SchemaPath(Arrays.asList(qnames), true); + qname = new QName(fooNS, fooRev, foo, "node3"); + assertEquals(qname, node3.getQName()); + qnames.set(4, qname); + expectedPath = new SchemaPath(qnames, true); assertEquals(expectedPath, node3.getPath()); Set node3Children = node3.getChildNodes(); assertEquals(1, node3Children.size()); // test cases - qnames = new QName[6]; - qnames[0] = q0; - qnames[1] = q1; - qnames[2] = q2; - qnames[3] = new QName(types1NS, types1Rev, t1, "odl"); + qnames.clear(); + qnames.add(q0); + qnames.add(q1); + qnames.add(q2); + qnames.add(new QName(fooNS, fooRev, foo, "odl")); // case id child - qnames[4] = new QName(types1NS, types1Rev, t1, "id"); - qnames[5] = new QName(types1NS, types1Rev, t1, "id"); + qnames.add(new QName(fooNS, fooRev, foo, "id")); + qnames.add(new QName(fooNS, fooRev, foo, "id")); LeafSchemaNode caseIdChild = (LeafSchemaNode) idChildren.iterator().next(); assertNotNull(caseIdChild); - expectedPath = new SchemaPath(Arrays.asList(qnames), true); + expectedPath = new SchemaPath(qnames, true); assertEquals(expectedPath, caseIdChild.getPath()); // case node3 child - qnames[4] = new QName(types1NS, types1Rev, t1, "node3"); - qnames[5] = new QName(types1NS, types1Rev, t1, "node3"); + qnames.set(4, new QName(fooNS, fooRev, foo, "node3")); + qnames.set(5, new QName(fooNS, fooRev, foo, "node3")); ContainerSchemaNode caseNode3Child = (ContainerSchemaNode) node3Children.iterator().next(); assertNotNull(caseNode3Child); - expectedPath = new SchemaPath(Arrays.asList(qnames), true); + expectedPath = new SchemaPath(qnames, true); assertEquals(expectedPath, caseNode3Child.getPath()); } @@ -399,7 +418,6 @@ public class AugmentTest { assertEquals(expectedPath, destroy.getPath()); Set destroyChildren = destroy.getChildNodes(); assertEquals(1, destroyChildren.size()); - } } diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/GroupingTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/GroupingTest.java index f89c76208b..56852d7f29 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/GroupingTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/GroupingTest.java @@ -45,7 +45,7 @@ public class GroupingTest { @Test public void testRefine() { - Module testModule = TestUtils.findModule(modules, "nodes"); + Module testModule = TestUtils.findModule(modules, "foo"); ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName("peer"); ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName("destination"); @@ -108,7 +108,7 @@ public class GroupingTest { @Test public void testGrouping() { - Module testModule = TestUtils.findModule(modules, "custom"); + Module testModule = TestUtils.findModule(modules, "baz"); Set groupings = testModule.getGroupings(); assertEquals(1, groupings.size()); GroupingDefinition grouping = groupings.iterator().next(); @@ -121,14 +121,14 @@ public class GroupingTest { // suffix _u = added by uses // suffix _g = defined in grouping - Module testModule = TestUtils.findModule(modules, "custom"); + Module testModule = TestUtils.findModule(modules, "baz"); // get grouping Set groupings = testModule.getGroupings(); assertEquals(1, groupings.size()); GroupingDefinition grouping = groupings.iterator().next(); - testModule = TestUtils.findModule(modules, "nodes"); + testModule = TestUtils.findModule(modules, "foo"); // get node containing uses ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName("peer"); @@ -224,7 +224,7 @@ public class GroupingTest { // suffix _u = added by uses // suffix _g = defined in grouping - Module testModule = TestUtils.findModule(modules, "custom"); + Module testModule = TestUtils.findModule(modules, "baz"); // get grouping Set groupings = testModule.getGroupings(); @@ -232,7 +232,7 @@ public class GroupingTest { GroupingDefinition grouping = groupings.iterator().next(); // get node containing uses - Module destination = TestUtils.findModule(modules, "nodes"); + Module destination = TestUtils.findModule(modules, "foo"); // check uses Set uses = destination.getUses(); @@ -341,18 +341,27 @@ public class GroupingTest { GroupingDefinition gz = null; GroupingDefinition gzz = null; for (GroupingDefinition gd : groupings) { - if ("grouping-U".equals(gd.getQName().getLocalName())) + String name = gd.getQName().getLocalName(); + switch (name) { + case "grouping-U": gu = gd; - if ("grouping-V".equals(gd.getQName().getLocalName())) + break; + case "grouping-V": gv = gd; - if ("grouping-X".equals(gd.getQName().getLocalName())) + break; + case "grouping-X": gx = gd; - if ("grouping-Y".equals(gd.getQName().getLocalName())) + break; + case "grouping-Y": gy = gd; - if ("grouping-Z".equals(gd.getQName().getLocalName())) + break; + case "grouping-Z": gz = gd; - if ("grouping-ZZ".equals(gd.getQName().getLocalName())) + break; + case "grouping-ZZ": gzz = gd; + break; + } } assertNotNull(gu); assertNotNull(gv); @@ -377,6 +386,7 @@ public class GroupingTest { ContainerSchemaNode containerV = (ContainerSchemaNode)gv.getDataChildByName("container-grouping-V"); assertNotNull(containerV); expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-V", "container-grouping-V"); + assertEquals(expectedPath, containerV.getPath()); assertEquals(2, containerV.getChildNodes().size()); // grouping-V/container-grouping-V/leaf-grouping-X LeafSchemaNode leafXinContainerV = (LeafSchemaNode)containerV.getDataChildByName("leaf-grouping-X"); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TestUtils.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TestUtils.java index 5d690280a0..96053b6b7b 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TestUtils.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TestUtils.java @@ -45,12 +45,11 @@ final class TestUtils { YangModelParser parser = new YangParserImpl(); final File testDir = new File(resourceDirectory); final String[] fileList = testDir.list(); - final List testFiles = new ArrayList(); - if(fileList == null) { + final List testFiles = new ArrayList<>(); + if (fileList == null) { throw new FileNotFoundException(resourceDirectory); } - for (int i = 0; i < fileList.length; i++) { - String fileName = fileList[i]; + for (String fileName : fileList) { testFiles.add(new File(testDir, fileName)); } return parser.parseYangModels(testFiles); @@ -58,37 +57,36 @@ final class TestUtils { public static Set loadModules(List input) throws IOException { final YangModelParser parser = new YangParserImpl(); - final Set modules = new HashSet( - parser.parseYangModelsFromStreams(input)); - for(InputStream stream : input) { + final Set modules = new HashSet<>(parser.parseYangModelsFromStreams(input)); + for (InputStream stream : input) { stream.close(); } return modules; } - public static Module loadModule(final InputStream stream) throws - IOException { + public static Module loadModule(final InputStream stream) throws IOException { final YangModelParser parser = new YangParserImpl(); final List input = Collections.singletonList(stream); - final Set modules = new HashSet( - parser.parseYangModelsFromStreams(input)); + final Set modules = new HashSet<>(parser.parseYangModelsFromStreams(input)); stream.close(); return modules.iterator().next(); } - public static Module loadModuleWithContext(final InputStream stream, final SchemaContext context) throws IOException { + public static Module loadModuleWithContext(final InputStream stream, final SchemaContext context) + throws IOException { final YangModelParser parser = new YangParserImpl(); final List input = Collections.singletonList(stream); - final Set modules = new HashSet(parser.parseYangModelsFromStreams(input, context)); + final Set modules = new HashSet<>(parser.parseYangModelsFromStreams(input, context)); stream.close(); return modules.iterator().next(); } - public static Set loadModulesWithContext(final List input, final SchemaContext context) throws IOException { + public static Set loadModulesWithContext(final List input, final SchemaContext context) + throws IOException { final YangModelParser parser = new YangParserImpl(); - final Set modules = new HashSet(parser.parseYangModelsFromStreams(input, context)); - for(InputStream is : input) { - if(is != null) { + final Set modules = new HashSet<>(parser.parseYangModelsFromStreams(input, context)); + for (InputStream is : input) { + if (is != null) { is.close(); } } @@ -106,8 +104,7 @@ final class TestUtils { return result; } - public static ModuleImport findImport(Set imports, - String prefix) { + public static ModuleImport findImport(Set imports, String prefix) { ModuleImport result = null; for (ModuleImport moduleImport : imports) { if (moduleImport.getPrefix().equals(prefix)) { @@ -118,8 +115,7 @@ final class TestUtils { return result; } - public static TypeDefinition findTypedef( - Set> typedefs, String name) { + public static TypeDefinition findTypedef(Set> typedefs, String name) { TypeDefinition result = null; for (TypeDefinition td : typedefs) { if (td.getQName().getLocalName().equals(name)) { @@ -130,9 +126,8 @@ final class TestUtils { return result; } - public static SchemaPath createPath(boolean absolute, URI namespace, - Date revision, String prefix, String... names) { - List path = new ArrayList(); + public static SchemaPath createPath(boolean absolute, URI namespace, Date revision, String prefix, String... names) { + List path = new ArrayList<>(); for (String name : names) { path.add(new QName(namespace, revision, prefix, name)); } diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/UsesAugmentTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/UsesAugmentTest.java index 47edbc2c87..9b69af60e6 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/UsesAugmentTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/UsesAugmentTest.java @@ -235,7 +235,7 @@ public class UsesAugmentTest { path.offer(expectedQName); expectedPath = new SchemaPath(path, true); assertEquals(expectedPath, order.getPath()); - assertFalse(order.isAddedByUses()); + assertTrue(order.isAddedByUses()); assertTrue(order.isAugmenting()); assertEquals(2, order.getChildNodes().size()); // * |-- |-- |-- |-- |-- leaf delete diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserTest.java index 6f2c354072..4662edc11e 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserTest.java @@ -57,20 +57,20 @@ import org.opendaylight.yangtools.yang.model.util.Uint32; import org.opendaylight.yangtools.yang.model.util.UnionType; public class YangParserTest { - private final URI nodesNS = URI.create("urn:simple.nodes.test"); - private final URI typesNS = URI.create("urn:simple.types.test"); - private final URI customNS = URI.create("urn:custom.nodes.test"); - private Date nodesRev; - private Date typesRev; - private Date customRev; + 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; @Before public void init() throws FileNotFoundException, ParseException { - nodesRev = TestUtils.simpleDateFormat.parse("2013-02-27"); - typesRev = TestUtils.simpleDateFormat.parse("2013-07-03"); - customRev = TestUtils.simpleDateFormat.parse("2013-02-27"); + fooRev = TestUtils.simpleDateFormat.parse("2013-02-27"); + barRev = TestUtils.simpleDateFormat.parse("2013-07-03"); + bazRev = TestUtils.simpleDateFormat.parse("2013-02-27"); modules = TestUtils.loadModules(getClass().getResource("/model").getPath()); assertEquals(3, modules.size()); @@ -78,35 +78,35 @@ public class YangParserTest { @Test public void testHeaders() throws ParseException { - Module test = TestUtils.findModule(modules, "nodes"); + Module foo = TestUtils.findModule(modules, "foo"); - assertEquals("nodes", test.getName()); - assertEquals("1", test.getYangVersion()); - assertEquals(nodesNS, test.getNamespace()); - assertEquals("n", test.getPrefix()); + assertEquals("foo", foo.getName()); + assertEquals("1", foo.getYangVersion()); + assertEquals(fooNS, foo.getNamespace()); + assertEquals("foo", foo.getPrefix()); - Set imports = test.getImports(); + Set imports = foo.getImports(); assertEquals(2, imports.size()); - ModuleImport import2 = TestUtils.findImport(imports, "t"); - assertEquals("types", import2.getModuleName()); - assertEquals(typesRev, import2.getRevision()); + ModuleImport import2 = TestUtils.findImport(imports, "br"); + assertEquals("bar", import2.getModuleName()); + assertEquals(barRev, import2.getRevision()); - ModuleImport import3 = TestUtils.findImport(imports, "c"); - assertEquals("custom", import3.getModuleName()); - assertEquals(customRev, import3.getRevision()); + ModuleImport import3 = TestUtils.findImport(imports, "bz"); + assertEquals("baz", import3.getModuleName()); + assertEquals(bazRev, import3.getRevision()); - assertEquals("opendaylight", test.getOrganization()); - assertEquals("http://www.opendaylight.org/", test.getContact()); + assertEquals("opendaylight", foo.getOrganization()); + assertEquals("http://www.opendaylight.org/", foo.getContact()); Date expectedRevision = TestUtils.createDate("2013-02-27"); - assertEquals(expectedRevision, test.getRevision()); - assertEquals(" WILL BE DEFINED LATER", test.getReference()); + assertEquals(expectedRevision, foo.getRevision()); + assertEquals(" WILL BE DEFINED LATER", foo.getReference()); } @Test public void testOrderingTypedef() { - Module test = TestUtils.findModule(modules, "types"); - Set> typedefs = test.getTypeDefinitions(); + Module bar = TestUtils.findModule(modules, "bar"); + Set> typedefs = bar.getTypeDefinitions(); String[] expectedOrder = new String[] { "int32-ext1", "int32-ext2", "my-decimal-type", "my-union", "my-union-ext", "nested-union2", "string-ext1", "string-ext2", "string-ext3", "string-ext4" }; String[] actualOrder = new String[typedefs.size()]; @@ -121,9 +121,9 @@ public class YangParserTest { @Test public void testOrderingChildNodes() { - Module test = TestUtils.findModule(modules, "nodes"); + Module foo = TestUtils.findModule(modules, "foo"); AugmentationSchema augment1 = null; - for (AugmentationSchema as : test.getAugmentations()) { + for (AugmentationSchema as : foo.getAugmentations()) { if ("if:ifType='ds0'".equals(as.getWhenCondition().toString())) { augment1 = as; break; @@ -145,9 +145,9 @@ public class YangParserTest { @Test public void testOrderingNestedChildNodes1() { - Module test = TestUtils.findModule(modules, "nodes"); + Module foo = TestUtils.findModule(modules, "foo"); - Set childNodes = test.getChildNodes(); + Set childNodes = foo.getChildNodes(); String[] expectedOrder = new String[] { "address", "addresses", "custom-union-leaf", "data", "datas", "decimal-leaf", "decimal-leaf2", "ext", "how", "int32-leaf", "length-leaf", "mycont", "peer", "port", "string-leaf", "transfer", "union-leaf" }; @@ -163,8 +163,8 @@ public class YangParserTest { @Test public void testOrderingNestedChildNodes2() { - Module test = TestUtils.findModule(modules, "custom"); - Set groupings = test.getGroupings(); + Module baz = TestUtils.findModule(modules, "baz"); + Set groupings = baz.getGroupings(); assertEquals(1, groupings.size()); GroupingDefinition target = groupings.iterator().next(); @@ -182,17 +182,17 @@ public class YangParserTest { @Test public void testParseList() { - Module test = TestUtils.findModule(modules, "types"); - URI expectedNamespace = URI.create("urn:simple.types.test"); - String expectedPrefix = "t"; + Module bar = TestUtils.findModule(modules, "bar"); + URI expectedNamespace = URI.create("urn:opendaylight.bar"); + String expectedPrefix = "bar"; - ContainerSchemaNode interfaces = (ContainerSchemaNode) test.getDataChildByName("interfaces"); + ContainerSchemaNode interfaces = (ContainerSchemaNode) bar.getDataChildByName("interfaces"); ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName("ifEntry"); // test SchemaNode args - QName expectedQName = new QName(expectedNamespace, typesRev, expectedPrefix, "ifEntry"); + QName expectedQName = new QName(expectedNamespace, barRev, expectedPrefix, "ifEntry"); assertEquals(expectedQName, ifEntry.getQName()); - SchemaPath expectedPath = TestUtils.createPath(true, expectedNamespace, typesRev, expectedPrefix, "interfaces", + SchemaPath expectedPath = TestUtils.createPath(true, expectedNamespace, barRev, expectedPrefix, "interfaces", "ifEntry"); assertEquals(expectedPath, ifEntry.getPath()); assertNull(ifEntry.getDescription()); @@ -212,8 +212,8 @@ public class YangParserTest { Set availableAugmentations = ifEntry.getAvailableAugmentations(); assertEquals(2, availableAugmentations.size()); // test ListSchemaNode args - List expectedKey = new ArrayList(); - expectedKey.add(new QName(expectedNamespace, typesRev, expectedPrefix, "ifIndex")); + List expectedKey = new ArrayList<>(); + expectedKey.add(new QName(expectedNamespace, barRev, expectedPrefix, "ifIndex")); assertEquals(expectedKey, ifEntry.getKeyDefinition()); assertFalse(ifEntry.isUserOrdered()); // test DataNodeContainer args @@ -230,15 +230,15 @@ public class YangParserTest { @Test public void testTypedefRangesResolving() throws ParseException { - Module testModule = TestUtils.findModule(modules, "nodes"); - LeafSchemaNode int32Leaf = (LeafSchemaNode) testModule.getDataChildByName("int32-leaf"); + Module foo = TestUtils.findModule(modules, "foo"); + LeafSchemaNode int32Leaf = (LeafSchemaNode) foo.getDataChildByName("int32-leaf"); ExtendedType leafType = (ExtendedType) int32Leaf.getType(); QName leafTypeQName = leafType.getQName(); assertEquals("int32-ext2", leafTypeQName.getLocalName()); - assertEquals("n", leafTypeQName.getPrefix()); - assertEquals(nodesNS, leafTypeQName.getNamespace()); - assertEquals(nodesRev, leafTypeQName.getRevision()); + assertEquals("foo", leafTypeQName.getPrefix()); + assertEquals(fooNS, leafTypeQName.getNamespace()); + assertEquals(fooRev, leafTypeQName.getRevision()); assertNull(leafType.getUnits()); assertNull(leafType.getDefaultValue()); assertTrue(leafType.getLengthConstraints().isEmpty()); @@ -252,9 +252,9 @@ public class YangParserTest { ExtendedType baseType = (ExtendedType) leafType.getBaseType(); QName baseTypeQName = baseType.getQName(); assertEquals("int32-ext2", baseTypeQName.getLocalName()); - assertEquals("t", baseTypeQName.getPrefix()); - assertEquals(typesNS, baseTypeQName.getNamespace()); - assertEquals(typesRev, baseTypeQName.getRevision()); + assertEquals("bar", baseTypeQName.getPrefix()); + assertEquals(barNS, baseTypeQName.getNamespace()); + assertEquals(barRev, baseTypeQName.getRevision()); assertEquals("mile", baseType.getUnits()); assertEquals("11", baseType.getDefaultValue()); assertTrue(leafType.getLengthConstraints().isEmpty()); @@ -271,9 +271,9 @@ public class YangParserTest { ExtendedType base = (ExtendedType) baseType.getBaseType(); QName baseQName = base.getQName(); assertEquals("int32-ext1", baseQName.getLocalName()); - assertEquals("t", baseQName.getPrefix()); - assertEquals(typesNS, baseQName.getNamespace()); - assertEquals(typesRev, baseQName.getRevision()); + assertEquals("bar", baseQName.getPrefix()); + assertEquals(barNS, baseQName.getNamespace()); + assertEquals(barRev, baseQName.getRevision()); assertNull(base.getUnits()); assertNull(base.getDefaultValue()); assertTrue(leafType.getLengthConstraints().isEmpty()); @@ -289,15 +289,15 @@ public class YangParserTest { @Test public void testTypedefPatternsResolving() { - Module testModule = TestUtils.findModule(modules, "nodes"); - LeafSchemaNode stringleaf = (LeafSchemaNode) testModule.getDataChildByName("string-leaf"); + Module foo = TestUtils.findModule(modules, "foo"); + LeafSchemaNode stringleaf = (LeafSchemaNode) foo.getDataChildByName("string-leaf"); ExtendedType type = (ExtendedType) stringleaf.getType(); QName typeQName = type.getQName(); assertEquals("string-ext4", typeQName.getLocalName()); - assertEquals("t", typeQName.getPrefix()); - assertEquals(typesNS, typeQName.getNamespace()); - assertEquals(typesRev, typeQName.getRevision()); + assertEquals("bar", typeQName.getPrefix()); + assertEquals(barNS, typeQName.getNamespace()); + assertEquals(barRev, typeQName.getRevision()); assertNull(type.getUnits()); assertNull(type.getDefaultValue()); List patterns = type.getPatternConstraints(); @@ -310,9 +310,9 @@ public class YangParserTest { ExtendedType baseType1 = (ExtendedType) type.getBaseType(); QName baseType1QName = baseType1.getQName(); assertEquals("string-ext3", baseType1QName.getLocalName()); - assertEquals("t", baseType1QName.getPrefix()); - assertEquals(typesNS, baseType1QName.getNamespace()); - assertEquals(typesRev, baseType1QName.getRevision()); + assertEquals("bar", baseType1QName.getPrefix()); + assertEquals(barNS, baseType1QName.getNamespace()); + assertEquals(barRev, baseType1QName.getRevision()); assertNull(baseType1.getUnits()); assertNull(baseType1.getDefaultValue()); patterns = baseType1.getPatternConstraints(); @@ -325,9 +325,9 @@ public class YangParserTest { ExtendedType baseType2 = (ExtendedType) baseType1.getBaseType(); QName baseType2QName = baseType2.getQName(); assertEquals("string-ext2", baseType2QName.getLocalName()); - assertEquals("t", baseType2QName.getPrefix()); - assertEquals(typesNS, baseType2QName.getNamespace()); - assertEquals(typesRev, baseType2QName.getRevision()); + assertEquals("bar", baseType2QName.getPrefix()); + assertEquals(barNS, baseType2QName.getNamespace()); + assertEquals(barRev, baseType2QName.getRevision()); assertNull(baseType2.getUnits()); assertNull(baseType2.getDefaultValue()); assertTrue(baseType2.getPatternConstraints().isEmpty()); @@ -341,9 +341,9 @@ public class YangParserTest { ExtendedType baseType3 = (ExtendedType) baseType2.getBaseType(); QName baseType3QName = baseType3.getQName(); assertEquals("string-ext1", baseType3QName.getLocalName()); - assertEquals("t", baseType3QName.getPrefix()); - assertEquals(typesNS, baseType3QName.getNamespace()); - assertEquals(typesRev, baseType3QName.getRevision()); + assertEquals("bar", baseType3QName.getPrefix()); + assertEquals(barNS, baseType3QName.getNamespace()); + assertEquals(barRev, baseType3QName.getRevision()); assertNull(baseType3.getUnits()); assertNull(baseType3.getDefaultValue()); patterns = baseType3.getPatternConstraints(); @@ -362,16 +362,16 @@ public class YangParserTest { @Test public void testTypedefLengthsResolving() { - Module testModule = TestUtils.findModule(modules, "nodes"); + Module foo = TestUtils.findModule(modules, "foo"); - LeafSchemaNode lengthLeaf = (LeafSchemaNode) testModule.getDataChildByName("length-leaf"); + LeafSchemaNode lengthLeaf = (LeafSchemaNode) foo.getDataChildByName("length-leaf"); ExtendedType type = (ExtendedType) lengthLeaf.getType(); QName typeQName = type.getQName(); assertEquals("string-ext2", typeQName.getLocalName()); - assertEquals("n", typeQName.getPrefix()); - assertEquals(nodesNS, typeQName.getNamespace()); - assertEquals(nodesRev, typeQName.getRevision()); + assertEquals("foo", typeQName.getPrefix()); + assertEquals(fooNS, typeQName.getNamespace()); + assertEquals(fooRev, typeQName.getRevision()); assertNull(type.getUnits()); assertNull(type.getDefaultValue()); assertTrue(type.getPatternConstraints().isEmpty()); @@ -385,9 +385,9 @@ public class YangParserTest { ExtendedType baseType1 = (ExtendedType) type.getBaseType(); QName baseType1QName = baseType1.getQName(); assertEquals("string-ext2", baseType1QName.getLocalName()); - assertEquals("t", baseType1QName.getPrefix()); - assertEquals(typesNS, baseType1QName.getNamespace()); - assertEquals(typesRev, baseType1QName.getRevision()); + assertEquals("bar", baseType1QName.getPrefix()); + assertEquals(barNS, baseType1QName.getNamespace()); + assertEquals(barRev, baseType1QName.getRevision()); assertNull(baseType1.getUnits()); assertNull(baseType1.getDefaultValue()); assertTrue(baseType1.getPatternConstraints().isEmpty()); @@ -401,9 +401,9 @@ public class YangParserTest { ExtendedType baseType2 = (ExtendedType) baseType1.getBaseType(); QName baseType2QName = baseType2.getQName(); assertEquals("string-ext1", baseType2QName.getLocalName()); - assertEquals("t", baseType2QName.getPrefix()); - assertEquals(typesNS, baseType2QName.getNamespace()); - assertEquals(typesRev, baseType2QName.getRevision()); + assertEquals("bar", baseType2QName.getPrefix()); + assertEquals(barNS, baseType2QName.getNamespace()); + assertEquals(barRev, baseType2QName.getRevision()); assertNull(baseType2.getUnits()); assertNull(baseType2.getDefaultValue()); List patterns = baseType2.getPatternConstraints(); @@ -422,15 +422,15 @@ public class YangParserTest { @Test public void testTypedefDecimal1() { - Module testModule = TestUtils.findModule(modules, "nodes"); - LeafSchemaNode testleaf = (LeafSchemaNode) testModule.getDataChildByName("decimal-leaf"); + Module foo = TestUtils.findModule(modules, "foo"); + LeafSchemaNode testleaf = (LeafSchemaNode) foo.getDataChildByName("decimal-leaf"); ExtendedType type = (ExtendedType) testleaf.getType(); QName typeQName = type.getQName(); assertEquals("my-decimal-type", typeQName.getLocalName()); - assertEquals("n", typeQName.getPrefix()); - assertEquals(nodesNS, typeQName.getNamespace()); - assertEquals(nodesRev, typeQName.getRevision()); + assertEquals("foo", typeQName.getPrefix()); + assertEquals(fooNS, typeQName.getNamespace()); + assertEquals(fooRev, typeQName.getRevision()); assertNull(type.getUnits()); assertNull(type.getDefaultValue()); assertEquals(4, (int) type.getFractionDigits()); @@ -441,9 +441,9 @@ public class YangParserTest { ExtendedType typeBase = (ExtendedType) type.getBaseType(); QName typeBaseQName = typeBase.getQName(); assertEquals("my-decimal-type", typeBaseQName.getLocalName()); - assertEquals("t", typeBaseQName.getPrefix()); - assertEquals(typesNS, typeBaseQName.getNamespace()); - assertEquals(typesRev, typeBaseQName.getRevision()); + assertEquals("bar", typeBaseQName.getPrefix()); + assertEquals(barNS, typeBaseQName.getNamespace()); + assertEquals(barRev, typeBaseQName.getRevision()); assertNull(typeBase.getUnits()); assertNull(typeBase.getDefaultValue()); assertNull(typeBase.getFractionDigits()); @@ -457,15 +457,15 @@ public class YangParserTest { @Test public void testTypedefDecimal2() { - Module testModule = TestUtils.findModule(modules, "nodes"); - LeafSchemaNode testleaf = (LeafSchemaNode) testModule.getDataChildByName("decimal-leaf2"); + Module foo = TestUtils.findModule(modules, "foo"); + LeafSchemaNode testleaf = (LeafSchemaNode) foo.getDataChildByName("decimal-leaf2"); ExtendedType type = (ExtendedType) testleaf.getType(); QName typeQName = type.getQName(); assertEquals("my-decimal-type", typeQName.getLocalName()); - assertEquals("t", typeQName.getPrefix()); - assertEquals(typesNS, typeQName.getNamespace()); - assertEquals(typesRev, typeQName.getRevision()); + assertEquals("bar", typeQName.getPrefix()); + assertEquals(barNS, typeQName.getNamespace()); + assertEquals(barRev, typeQName.getRevision()); assertNull(type.getUnits()); assertNull(type.getDefaultValue()); assertNull(type.getFractionDigits()); @@ -479,15 +479,15 @@ public class YangParserTest { @Test public void testTypedefUnion() { - Module testModule = TestUtils.findModule(modules, "nodes"); - LeafSchemaNode unionleaf = (LeafSchemaNode) testModule.getDataChildByName("union-leaf"); + Module foo = TestUtils.findModule(modules, "foo"); + LeafSchemaNode unionleaf = (LeafSchemaNode) foo.getDataChildByName("union-leaf"); ExtendedType type = (ExtendedType) unionleaf.getType(); QName typeQName = type.getQName(); assertEquals("my-union-ext", typeQName.getLocalName()); - assertEquals("t", typeQName.getPrefix()); - assertEquals(typesNS, typeQName.getNamespace()); - assertEquals(typesRev, typeQName.getRevision()); + assertEquals("bar", typeQName.getPrefix()); + assertEquals(barNS, typeQName.getNamespace()); + assertEquals(barRev, typeQName.getRevision()); assertNull(type.getUnits()); assertNull(type.getDefaultValue()); assertNull(type.getFractionDigits()); @@ -498,9 +498,9 @@ public class YangParserTest { ExtendedType baseType = (ExtendedType) type.getBaseType(); QName baseTypeQName = baseType.getQName(); assertEquals("my-union", baseTypeQName.getLocalName()); - assertEquals("t", baseTypeQName.getPrefix()); - assertEquals(typesNS, baseTypeQName.getNamespace()); - assertEquals(typesRev, baseTypeQName.getRevision()); + assertEquals("bar", baseTypeQName.getPrefix()); + assertEquals(barNS, baseTypeQName.getNamespace()); + assertEquals(barRev, baseTypeQName.getRevision()); assertNull(baseType.getUnits()); assertNull(baseType.getDefaultValue()); assertNull(baseType.getFractionDigits()); @@ -515,9 +515,9 @@ public class YangParserTest { ExtendedType unionType1 = (ExtendedType) unionTypes.get(0); QName unionType1QName = baseType.getQName(); assertEquals("my-union", unionType1QName.getLocalName()); - assertEquals("t", unionType1QName.getPrefix()); - assertEquals(typesNS, unionType1QName.getNamespace()); - assertEquals(typesRev, unionType1QName.getRevision()); + assertEquals("bar", unionType1QName.getPrefix()); + assertEquals(barNS, unionType1QName.getNamespace()); + assertEquals(barRev, unionType1QName.getRevision()); assertNull(unionType1.getUnits()); assertNull(unionType1.getDefaultValue()); assertNull(unionType1.getFractionDigits()); @@ -535,14 +535,14 @@ public class YangParserTest { @Test public void testNestedUnionResolving() { - Module testModule = TestUtils.findModule(modules, "nodes"); - LeafSchemaNode testleaf = (LeafSchemaNode) testModule.getDataChildByName("custom-union-leaf"); + Module foo = TestUtils.findModule(modules, "foo"); + LeafSchemaNode testleaf = (LeafSchemaNode) foo.getDataChildByName("custom-union-leaf"); ExtendedType type = (ExtendedType) testleaf.getType(); QName testleafTypeQName = type.getQName(); - assertEquals(customNS, testleafTypeQName.getNamespace()); - assertEquals(customRev, testleafTypeQName.getRevision()); - assertEquals("c", testleafTypeQName.getPrefix()); + assertEquals(bazNS, testleafTypeQName.getNamespace()); + assertEquals(bazRev, testleafTypeQName.getRevision()); + assertEquals("baz", testleafTypeQName.getPrefix()); assertEquals("union1", testleafTypeQName.getLocalName()); assertNull(type.getUnits()); assertNull(type.getDefaultValue()); @@ -553,9 +553,9 @@ public class YangParserTest { ExtendedType typeBase = (ExtendedType) type.getBaseType(); QName typeBaseQName = typeBase.getQName(); - assertEquals(customNS, typeBaseQName.getNamespace()); - assertEquals(customRev, typeBaseQName.getRevision()); - assertEquals("c", typeBaseQName.getPrefix()); + assertEquals(bazNS, typeBaseQName.getNamespace()); + assertEquals(bazRev, typeBaseQName.getRevision()); + assertEquals("baz", typeBaseQName.getPrefix()); assertEquals("union2", typeBaseQName.getLocalName()); assertNull(typeBase.getUnits()); assertNull(typeBase.getDefaultValue()); @@ -572,9 +572,9 @@ public class YangParserTest { ExtendedType unionType1 = (ExtendedType) unionTypes.get(1); QName uniontType1QName = unionType1.getQName(); - assertEquals(typesNS, uniontType1QName.getNamespace()); - assertEquals(typesRev, uniontType1QName.getRevision()); - assertEquals("t", uniontType1QName.getPrefix()); + assertEquals(barNS, uniontType1QName.getNamespace()); + assertEquals(barRev, uniontType1QName.getRevision()); + assertEquals("bar", uniontType1QName.getPrefix()); assertEquals("nested-union2", uniontType1QName.getLocalName()); assertNull(unionType1.getUnits()); assertNull(unionType1.getDefaultValue()); @@ -591,9 +591,9 @@ public class YangParserTest { ExtendedType myUnionExt = (ExtendedType) nestedUnion2Types.get(1); QName myUnionExtQName = myUnionExt.getQName(); - assertEquals(typesNS, myUnionExtQName.getNamespace()); - assertEquals(typesRev, myUnionExtQName.getRevision()); - assertEquals("t", myUnionExtQName.getPrefix()); + assertEquals(barNS, myUnionExtQName.getNamespace()); + assertEquals(barRev, myUnionExtQName.getRevision()); + assertEquals("bar", myUnionExtQName.getPrefix()); assertEquals("my-union-ext", myUnionExtQName.getLocalName()); assertNull(myUnionExt.getUnits()); assertNull(myUnionExt.getDefaultValue()); @@ -604,9 +604,9 @@ public class YangParserTest { ExtendedType myUnion = (ExtendedType) myUnionExt.getBaseType(); QName myUnionQName = myUnion.getQName(); - assertEquals(typesNS, myUnionQName.getNamespace()); - assertEquals(typesRev, myUnionQName.getRevision()); - assertEquals("t", myUnionQName.getPrefix()); + assertEquals(barNS, myUnionQName.getNamespace()); + assertEquals(barRev, myUnionQName.getRevision()); + assertEquals("bar", myUnionQName.getPrefix()); assertEquals("my-union", myUnionQName.getLocalName()); assertNull(myUnion.getUnits()); assertNull(myUnion.getDefaultValue()); @@ -623,9 +623,9 @@ public class YangParserTest { ExtendedType int16Ext = (ExtendedType) myUnionBaseTypes.get(0); QName int16ExtQName = int16Ext.getQName(); - assertEquals(typesNS, int16ExtQName.getNamespace()); - assertEquals(typesRev, int16ExtQName.getRevision()); - assertEquals("t", int16ExtQName.getPrefix()); + assertEquals(barNS, int16ExtQName.getNamespace()); + assertEquals(barRev, int16ExtQName.getRevision()); + assertEquals("bar", int16ExtQName.getPrefix()); assertEquals("int16", int16ExtQName.getLocalName()); assertNull(int16Ext.getUnits()); assertNull(int16Ext.getDefaultValue()); @@ -643,8 +643,8 @@ public class YangParserTest { @Test public void testChoice() { - Module testModule = TestUtils.findModule(modules, "nodes"); - ContainerSchemaNode transfer = (ContainerSchemaNode) testModule.getDataChildByName("transfer"); + Module foo = TestUtils.findModule(modules, "foo"); + ContainerSchemaNode transfer = (ContainerSchemaNode) foo.getDataChildByName("transfer"); ChoiceNode how = (ChoiceNode) transfer.getDataChildByName("how"); Set cases = how.getCases(); assertEquals(5, cases.size()); @@ -665,16 +665,15 @@ public class YangParserTest { @Test public void testDeviation() { - Module testModule = TestUtils.findModule(modules, "nodes"); - Set deviations = testModule.getDeviations(); + Module foo = TestUtils.findModule(modules, "foo"); + Set deviations = foo.getDeviations(); assertEquals(1, deviations.size()); Deviation dev = deviations.iterator().next(); - assertEquals("system/user ref", dev.getReference()); - List path = new ArrayList(); - path.add(new QName(typesNS, typesRev, "t", "interfaces")); - path.add(new QName(typesNS, typesRev, "t", "ifEntry")); + List path = new ArrayList<>(); + path.add(new QName(barNS, barRev, "br", "interfaces")); + path.add(new QName(barNS, barRev, "br", "ifEntry")); SchemaPath expectedPath = new SchemaPath(path, true); assertEquals(expectedPath, dev.getTargetPath()); @@ -683,8 +682,8 @@ public class YangParserTest { @Test public void testUnknownNode() { - Module testModule = TestUtils.findModule(modules, "custom"); - ContainerSchemaNode network = (ContainerSchemaNode) testModule.getDataChildByName("network"); + Module baz = TestUtils.findModule(modules, "baz"); + ContainerSchemaNode network = (ContainerSchemaNode) baz.getDataChildByName("network"); List unknownNodes = network.getUnknownSchemaNodes(); assertEquals(1, unknownNodes.size()); UnknownSchemaNode unknownNode = unknownNodes.get(0); @@ -694,15 +693,15 @@ public class YangParserTest { @Test public void testFeature() { - Module testModule = TestUtils.findModule(modules, "custom"); - Set features = testModule.getFeatures(); + Module baz = TestUtils.findModule(modules, "baz"); + Set features = baz.getFeatures(); assertEquals(1, features.size()); } @Test public void testExtension() { - Module testModule = TestUtils.findModule(modules, "custom"); - List extensions = testModule.getExtensionSchemaNodes(); + Module baz = TestUtils.findModule(modules, "baz"); + List extensions = baz.getExtensionSchemaNodes(); assertEquals(1, extensions.size()); ExtensionDefinition extension = extensions.get(0); assertEquals("name", extension.getArgument()); @@ -711,17 +710,17 @@ public class YangParserTest { @Test public void testNotification() { - Module testModule = TestUtils.findModule(modules, "custom"); + Module baz = TestUtils.findModule(modules, "baz"); String expectedPrefix = "c"; - Set notifications = testModule.getNotifications(); + Set notifications = baz.getNotifications(); assertEquals(1, notifications.size()); NotificationDefinition notification = notifications.iterator().next(); // test SchemaNode args - QName expectedQName = new QName(customNS, customRev, expectedPrefix, "event"); + QName expectedQName = new QName(bazNS, bazRev, expectedPrefix, "event"); assertEquals(expectedQName, notification.getQName()); - SchemaPath expectedPath = TestUtils.createPath(true, customNS, customRev, expectedPrefix, "event"); + SchemaPath expectedPath = TestUtils.createPath(true, bazNS, bazRev, expectedPrefix, "event"); assertEquals(expectedPath, notification.getPath()); assertNull(notification.getDescription()); assertNull(notification.getReference()); @@ -743,9 +742,9 @@ public class YangParserTest { @Test public void testRpc() { - Module testModule = TestUtils.findModule(modules, "custom"); + Module baz = TestUtils.findModule(modules, "baz"); - Set rpcs = testModule.getRpcs(); + Set rpcs = baz.getRpcs(); assertEquals(1, rpcs.size()); RpcDefinition rpc = rpcs.iterator().next(); @@ -761,16 +760,16 @@ public class YangParserTest { @Test public void testTypePath() throws ParseException { - Module test = TestUtils.findModule(modules, "types"); - Set> types = test.getTypeDefinitions(); + Module bar = TestUtils.findModule(modules, "bar"); + Set> types = bar.getTypeDefinitions(); // int32-ext1 ExtendedType int32ext1 = (ExtendedType) TestUtils.findTypedef(types, "int32-ext1"); QName int32TypedefQName = int32ext1.getQName(); - assertEquals(typesNS, int32TypedefQName.getNamespace()); - assertEquals(typesRev, int32TypedefQName.getRevision()); - assertEquals("t", int32TypedefQName.getPrefix()); + assertEquals(barNS, int32TypedefQName.getNamespace()); + assertEquals(barRev, int32TypedefQName.getRevision()); + assertEquals("bar", int32TypedefQName.getPrefix()); assertEquals("int32-ext1", int32TypedefQName.getLocalName()); SchemaPath typeSchemaPath = int32ext1.getPath(); @@ -785,16 +784,16 @@ public class YangParserTest { @Test public void testTypePath2() throws ParseException { - Module test = TestUtils.findModule(modules, "types"); - Set> types = test.getTypeDefinitions(); + Module bar = TestUtils.findModule(modules, "bar"); + Set> types = bar.getTypeDefinitions(); // my-decimal-type ExtendedType myDecType = (ExtendedType) TestUtils.findTypedef(types, "my-decimal-type"); QName myDecTypeQName = myDecType.getQName(); - assertEquals(typesNS, myDecTypeQName.getNamespace()); - assertEquals(typesRev, myDecTypeQName.getRevision()); - assertEquals("t", myDecTypeQName.getPrefix()); + assertEquals(barNS, myDecTypeQName.getNamespace()); + assertEquals(barRev, myDecTypeQName.getRevision()); + assertEquals("bar", myDecTypeQName.getPrefix()); assertEquals("my-decimal-type", myDecTypeQName.getLocalName()); SchemaPath typeSchemaPath = myDecType.getPath(); 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 3975cdd2e9..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 @@ -52,16 +52,14 @@ public class YangParserWithContextTest { @Test public void testTypeFromContext() throws Exception { - SchemaContext context = null; 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); @@ -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")).iterator().next(); + 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,13 +268,13 @@ public class YangParserWithContextTest { @Test public void testIdentity() throws Exception { - SchemaContext context = 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 = null; + Module module; try (InputStream stream = new FileInputStream(getClass().getResource("/context-test/test3.yang").getPath())) { module = TestUtils.loadModuleWithContext(stream, context); } @@ -302,13 +300,13 @@ public class YangParserWithContextTest { @Test public void testUnknownNodes() throws Exception { - SchemaContext context = 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 = null; + Module module; try (InputStream stream = new FileInputStream(getClass().getResource("/context-test/test3.yang").getPath())) { module = TestUtils.loadModuleWithContext(stream, context); } @@ -330,7 +328,7 @@ public class YangParserWithContextTest { @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())) { @@ -343,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") @@ -376,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); @@ -400,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()); diff --git a/yang/yang-parser-impl/src/test/resources/augment-test/augment-in-augment/bar.yang b/yang/yang-parser-impl/src/test/resources/augment-test/augment-in-augment/bar.yang new file mode 100644 index 0000000000..733e100367 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/augment-test/augment-in-augment/bar.yang @@ -0,0 +1,49 @@ +module bar { + yang-version 1; + namespace "urn:opendaylight.bar"; + prefix "bar"; + + organization "opendaylight"; + contact "http://www.opendaylight.org/"; + + revision "2013-10-14" { + reference " WILL BE DEFINED LATER"; + } + + container interfaces { + grouping ifEntry { + container augment-holder; + } + list ifEntry { + key "ifIndex"; + + leaf ifIndex { + type uint32; + units minutes; + } + + leaf ifMtu { + type int32; + } + + min-elements 1; + max-elements 11; + } + } + + container controller { + choice switch { + case start { + leaf start { + type int8; + } + } + case stop { + leaf stop { + type int16; + } + } + } + } + +} diff --git a/yang/yang-parser-impl/src/test/resources/augment-test/augment-in-augment/baz.yang b/yang/yang-parser-impl/src/test/resources/augment-test/augment-in-augment/baz.yang new file mode 100644 index 0000000000..eced11f837 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/augment-test/augment-in-augment/baz.yang @@ -0,0 +1,94 @@ +module baz { + yang-version 1; + namespace "urn:opendaylight.baz"; + prefix "baz"; + + import bar { + prefix "br"; + revision-date 2013-10-14; + } + + organization "opendaylight"; + contact "http://www.opendaylight.org/"; + + revision "2013-10-15" { + reference " WILL BE DEFINED LATER"; + } + + + augment "/br:interfaces/br:ifEntry" { + when "if:ifType='ds0'"; + container augment-holder { + description "Description for augment holder"; + } + } + + augment "/br:interfaces/br:ifEntry" { + when "if:ifType='ds2'"; + container augment-holder2 { + description "Description for augment holder"; + } + } + + augment "/br:controller/br:switch" { + leaf pause { + type int32; + } + } + + grouping target { + anyxml data { + config true; + description "Copy of the source datastore subset."; + mandatory false; + must "test-condition-text"; + reference "test-no-reference"; + status "obsolete"; + when "test-when-text"; + } + choice how { + description "test choice description"; + default interval; + case interval { + leaf interval { + type uint16; + default 30; + units minutes; + } + } + case daily { + leaf daily { + type empty; + } + leaf time-of-day { + type string; + units 24-hour-clock; + default 1am; + } + } + } + leaf address { + type string; + description "Target IP address"; + mandatory true; + } + container port { + description "Target port container"; + } + list addresses { + key "id"; + leaf id { + type int8; + } + } + grouping target-inner { + description "target-inner default description"; + leaf inner-grouping-id { + type int8; + } + } + + opendaylight; + } + +} diff --git a/yang/yang-parser-impl/src/test/resources/augment-test/augment-in-augment/foo.yang b/yang/yang-parser-impl/src/test/resources/augment-test/augment-in-augment/foo.yang new file mode 100644 index 0000000000..abe14561fd --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/augment-test/augment-in-augment/foo.yang @@ -0,0 +1,62 @@ +module foo { + yang-version 1; + namespace "urn:opendaylight.foo"; + prefix "foo"; + + import bar { + prefix "br"; + revision-date 2013-10-14; + } + + import baz { + prefix "bz"; + revision-date 2013-10-15; + } + + organization "opendaylight"; + contact "http://www.opendaylight.org/"; + + revision "2013-10-13" { + reference " WILL BE DEFINED LATER"; + } + + + augment "/br:interfaces/br:ifEntry/bz:augment-holder" { + when "if:ifType='ds0'"; + leaf ds0ChannelNumber { + type string; + } + leaf interface-id { + type leafref { + path "/if:interfaces/if:interface/if:name"; + } + } + container schemas { + } + choice odl { + leaf id { + type int8; + } + case node1 { + description "node1"; + } + case node2 { + description "node2"; + } + container node3 { + description "node3"; + } + } + } + + + uses bz:target { + augment "how/interval" { + description "inner augment"; + leaf name { + type string; + } + } + } + +} diff --git a/yang/yang-parser-impl/src/test/resources/context-test/deviation-test.yang b/yang/yang-parser-impl/src/test/resources/context-test/deviation-test.yang index eafcb56f89..360fbcec7d 100644 --- a/yang/yang-parser-impl/src/test/resources/context-test/deviation-test.yang +++ b/yang/yang-parser-impl/src/test/resources/context-test/deviation-test.yang @@ -3,7 +3,7 @@ module deviation-test { namespace "urn:simple.deviation.test"; prefix "dev"; - import types { + import bar { prefix "t"; revision-date 2013-07-03; } diff --git a/yang/yang-parser-impl/src/test/resources/context-test/test2.yang b/yang/yang-parser-impl/src/test/resources/context-test/test2.yang index 588d066fad..48c0e092cb 100644 --- a/yang/yang-parser-impl/src/test/resources/context-test/test2.yang +++ b/yang/yang-parser-impl/src/test/resources/context-test/test2.yang @@ -4,7 +4,7 @@ module test2 { namespace "urn:simple.demo.test2"; prefix "t2"; - import custom { + import baz { prefix "data"; } diff --git a/yang/yang-parser-impl/src/test/resources/model/types.yang b/yang/yang-parser-impl/src/test/resources/model/bar.yang similarity index 92% rename from yang/yang-parser-impl/src/test/resources/model/types.yang rename to yang/yang-parser-impl/src/test/resources/model/bar.yang index bff9543009..db9ac6d356 100644 --- a/yang/yang-parser-impl/src/test/resources/model/types.yang +++ b/yang/yang-parser-impl/src/test/resources/model/bar.yang @@ -1,11 +1,11 @@ -module types { +module bar { yang-version 1; - namespace "urn:simple.types.test"; - prefix "t"; + namespace "urn:opendaylight.bar"; + prefix "bar"; organization "opendaylight"; contact "http://www.opendaylight.org/"; - description "This is types-data test description"; + description "This model define custom type definitions"; revision "2013-07-03" { reference " WILL BE DEFINED LATER"; diff --git a/yang/yang-parser-impl/src/test/resources/model/custom.yang b/yang/yang-parser-impl/src/test/resources/model/baz.yang similarity index 88% rename from yang/yang-parser-impl/src/test/resources/model/custom.yang rename to yang/yang-parser-impl/src/test/resources/model/baz.yang index 77f109d0e6..ec8a6f752e 100644 --- a/yang/yang-parser-impl/src/test/resources/model/custom.yang +++ b/yang/yang-parser-impl/src/test/resources/model/baz.yang @@ -1,10 +1,10 @@ -module custom { +module baz { yang-version 1; - namespace "urn:custom.nodes.test"; - prefix "c"; + namespace "urn:opendaylight.baz"; + prefix "baz"; - import types { - prefix "types"; + import bar { + prefix "br"; revision-date 2013-07-03; } @@ -22,18 +22,18 @@ module custom { typedef union2 { type union { type int32; - type types:nested-union2; + type br:nested-union2; } } - augment "/types:interfaces/types:ifEntry" { + augment "/br:interfaces/br:ifEntry" { when "if:ifType='ds0'"; container augment-holder { description "Description for augment holder"; } } - augment "/types:interfaces/types:ifEntry" { + augment "/br:interfaces/br:ifEntry" { when "if:ifType='ds2'"; container augment-holder2 { description "Description for augment holder"; @@ -59,8 +59,7 @@ module custom { } extension c-define { - description - "Takes as argument a name string. Makes the code generator use the given name in the #define."; + description "Takes as argument a name string. Makes the code generator use the given name in the #define."; argument "name" { yin-element "true"; } @@ -77,9 +76,7 @@ module custom { } rpc get-config { - description - "Retrieve all or part of a specified configuration."; - + description "Retrieve all or part of a specified configuration."; reference "RFC 6241, Section 7.1"; input { @@ -121,9 +118,8 @@ module custom { } anyxml filter { - description - "Subtree or XPath filter to use."; - c:c-define element-attributes; + description "Subtree or XPath filter to use."; + baz:c-define element-attributes; } } @@ -189,7 +185,7 @@ module custom { } } typedef group-type { - type types:my-decimal-type; + type br:my-decimal-type; } opendaylight; diff --git a/yang/yang-parser-impl/src/test/resources/model/nodes.yang b/yang/yang-parser-impl/src/test/resources/model/foo.yang similarity index 86% rename from yang/yang-parser-impl/src/test/resources/model/nodes.yang rename to yang/yang-parser-impl/src/test/resources/model/foo.yang index 1389db1c53..126a977281 100644 --- a/yang/yang-parser-impl/src/test/resources/model/nodes.yang +++ b/yang/yang-parser-impl/src/test/resources/model/foo.yang @@ -1,15 +1,15 @@ -module nodes { +module foo { yang-version 1; - namespace "urn:simple.nodes.test"; - prefix "n"; + namespace "urn:opendaylight.foo"; + prefix "foo"; - import types { - prefix "t"; + import bar { + prefix "br"; revision-date 2013-07-03; } - import custom { - prefix "c"; + import baz { + prefix "bz"; revision-date 2013-02-27; } @@ -21,49 +21,49 @@ module nodes { } leaf int32-leaf { - type t:int32-ext2 { + type br:int32-ext2 { range "12..max"; } } leaf string-leaf { - type t:string-ext4; + type br:string-ext4; } leaf length-leaf { - type t:string-ext2 { + type br:string-ext2 { length "7..max"; } } leaf decimal-leaf { - type t:my-decimal-type { + type br:my-decimal-type { fraction-digits 4; } } leaf decimal-leaf2 { - type t:my-decimal-type; + type br:my-decimal-type; } container ext { - c:c-define "MY_INTERFACES"; + bz:c-define "MY_INTERFACES"; } leaf union-leaf { - type t:my-union-ext; + type br:my-union-ext; } - deviation /t:interfaces/t:ifEntry { + deviation /br:interfaces/br:ifEntry { deviate add { - default "admin"; // new users are 'admin' by default + default "admin"; config "true"; } reference "system/user ref"; } leaf custom-union-leaf { - type c:union1; + type bz:union1; } container transfer { @@ -109,7 +109,7 @@ module nodes { status obsolete; } - augment "/t:interfaces/t:ifEntry/c:augment-holder" { + augment "/br:interfaces/br:ifEntry/bz:augment-holder" { when "if:ifType='ds0'"; leaf ds0ChannelNumber { type string; @@ -120,7 +120,7 @@ module nodes { } } leaf my-type { - type t:int32-ext2; + type br:int32-ext2; } container schemas { } @@ -151,8 +151,8 @@ module nodes { } } - uses c:target { - augment "/mycont/innercont" { + uses bz:target { + augment "how/interval" { description "inner augment"; leaf name { type string; @@ -162,7 +162,7 @@ module nodes { container peer { container destination { - uses c:target { + uses bz:target { refine address { default "1.2.3.4"; description "IP address of target node"; -- 2.36.6