Fixed bug in resolving groupings. 08/1908/2
authorMartin Vitez <mvitez@cisco.com>
Tue, 15 Oct 2013 14:55:21 +0000 (16:55 +0200)
committerMartin Vitez <mvitez@cisco.com>
Tue, 15 Oct 2013 15:01:02 +0000 (17:01 +0200)
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 <mvitez@cisco.com>
16 files changed:
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleBuilder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/GroupingUtils.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/GroupingTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TestUtils.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/UsesAugmentTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserWithContextTest.java
yang/yang-parser-impl/src/test/resources/augment-test/augment-in-augment/bar.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/augment-test/augment-in-augment/baz.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/augment-test/augment-in-augment/foo.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/context-test/deviation-test.yang
yang/yang-parser-impl/src/test/resources/context-test/test2.yang
yang/yang-parser-impl/src/test/resources/model/bar.yang [moved from yang/yang-parser-impl/src/test/resources/model/types.yang with 92% similarity]
yang/yang-parser-impl/src/test/resources/model/baz.yang [moved from yang/yang-parser-impl/src/test/resources/model/custom.yang with 88% similarity]
yang/yang-parser-impl/src/test/resources/model/foo.yang [moved from yang/yang-parser-impl/src/test/resources/model/nodes.yang with 86% similarity]

index e49a181717dacce38eb7fa82daff8001f50dc19c..fb9cf06831db52d6602f7cff0cb5318920c7cf5b 100644 (file)
@@ -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.");
index 14718e6a4bcf132cf4abe378ed06a44a52c22094..80fb2c4479176af7e49a88303dfb08b8473f1f56 100644 (file)
@@ -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);
             }
         }
index 6ee61357e55563b6d68812802f4c94e14b7db453..dfa7bc4830b850f3d93d8742f54b2c7d0060e5e8 100644 (file)
@@ -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<Module> 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<QName> 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<AugmentationSchema> 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<DataSchemaNode> 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<QName> 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<ChoiceCaseNode> 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<QName> 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<DataSchemaNode> 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<DataSchemaNode> 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<DataSchemaNode> 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<DataSchemaNode> 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<DataSchemaNode> destroyChildren = destroy.getChildNodes();
         assertEquals(1, destroyChildren.size());
-
     }
 
 }
index f89c76208b22638777c90ae3cb9b0f7de23b1a3c..56852d7f2900cf628423a2a354445f5fe3fd3610 100644 (file)
@@ -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<GroupingDefinition> 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<GroupingDefinition> 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<GroupingDefinition> 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<UsesNode> 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");
index 5d690280a04543d43387730a974cb5a1ecda3e23..96053b6b7bb5b5f128971cbef41c0c0c0e8bf936 100644 (file)
@@ -45,12 +45,11 @@ final class TestUtils {
         YangModelParser parser = new YangParserImpl();
         final File testDir = new File(resourceDirectory);
         final String[] fileList = testDir.list();
-        final List<File> testFiles = new ArrayList<File>();
-        if(fileList == null) {
+        final List<File> 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<Module> loadModules(List<InputStream> input) throws IOException {
         final YangModelParser parser = new YangParserImpl();
-        final Set<Module> modules = new HashSet<Module>(
-                parser.parseYangModelsFromStreams(input));
-        for(InputStream stream : input) {
+        final Set<Module> 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<InputStream> input = Collections.singletonList(stream);
-        final Set<Module> modules = new HashSet<Module>(
-                parser.parseYangModelsFromStreams(input));
+        final Set<Module> 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<InputStream> input = Collections.singletonList(stream);
-        final Set<Module> modules = new HashSet<Module>(parser.parseYangModelsFromStreams(input, context));
+        final Set<Module> modules = new HashSet<>(parser.parseYangModelsFromStreams(input, context));
         stream.close();
         return modules.iterator().next();
     }
 
-    public static Set<Module> loadModulesWithContext(final List<InputStream> input, final SchemaContext context) throws IOException {
+    public static Set<Module> loadModulesWithContext(final List<InputStream> input, final SchemaContext context)
+            throws IOException {
         final YangModelParser parser = new YangParserImpl();
-        final Set<Module> modules = new HashSet<Module>(parser.parseYangModelsFromStreams(input, context));
-        for(InputStream is : input) {
-            if(is != null) {
+        final Set<Module> 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<ModuleImport> imports,
-            String prefix) {
+    public static ModuleImport findImport(Set<ModuleImport> 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<TypeDefinition<?>> typedefs, String name) {
+    public static TypeDefinition<?> findTypedef(Set<TypeDefinition<?>> 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<QName> path = new ArrayList<QName>();
+    public static SchemaPath createPath(boolean absolute, URI namespace, Date revision, String prefix, String... names) {
+        List<QName> path = new ArrayList<>();
         for (String name : names) {
             path.add(new QName(namespace, revision, prefix, name));
         }
index 47edbc2c87bfb63e2e282dc961e2fe6fe3e09963..9b69af60e69e9bdf6c01182dcd46457cbb6c5f38 100644 (file)
@@ -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
index 6f2c354072d6368b8696ef85d0dd0049001e38aa..4662edc11ee7b4f08faf0f212ba905eebdeaac73 100644 (file)
@@ -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<Module> 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<ModuleImport> imports = test.getImports();
+        Set<ModuleImport> 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<TypeDefinition<?>> typedefs = test.getTypeDefinitions();
+        Module bar = TestUtils.findModule(modules, "bar");
+        Set<TypeDefinition<?>> 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<DataSchemaNode> childNodes = test.getChildNodes();
+        Set<DataSchemaNode> 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<GroupingDefinition> groupings = test.getGroupings();
+        Module baz = TestUtils.findModule(modules, "baz");
+        Set<GroupingDefinition> 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<AugmentationSchema> availableAugmentations = ifEntry.getAvailableAugmentations();
         assertEquals(2, availableAugmentations.size());
         // test ListSchemaNode args
-        List<QName> expectedKey = new ArrayList<QName>();
-        expectedKey.add(new QName(expectedNamespace, typesRev, expectedPrefix, "ifIndex"));
+        List<QName> 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<PatternConstraint> 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<PatternConstraint> 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<ChoiceCaseNode> 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<Deviation> deviations = testModule.getDeviations();
+        Module foo = TestUtils.findModule(modules, "foo");
+        Set<Deviation> deviations = foo.getDeviations();
         assertEquals(1, deviations.size());
         Deviation dev = deviations.iterator().next();
-
         assertEquals("system/user ref", dev.getReference());
 
-        List<QName> path = new ArrayList<QName>();
-        path.add(new QName(typesNS, typesRev, "t", "interfaces"));
-        path.add(new QName(typesNS, typesRev, "t", "ifEntry"));
+        List<QName> 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<UnknownSchemaNode> 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<FeatureDefinition> features = testModule.getFeatures();
+        Module baz = TestUtils.findModule(modules, "baz");
+        Set<FeatureDefinition> features = baz.getFeatures();
         assertEquals(1, features.size());
     }
 
     @Test
     public void testExtension() {
-        Module testModule = TestUtils.findModule(modules, "custom");
-        List<ExtensionDefinition> extensions = testModule.getExtensionSchemaNodes();
+        Module baz = TestUtils.findModule(modules, "baz");
+        List<ExtensionDefinition> 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<NotificationDefinition> notifications = testModule.getNotifications();
+        Set<NotificationDefinition> 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<RpcDefinition> rpcs = testModule.getRpcs();
+        Set<RpcDefinition> 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<TypeDefinition<?>> types = test.getTypeDefinitions();
+        Module bar = TestUtils.findModule(modules, "bar");
+        Set<TypeDefinition<?>> 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<TypeDefinition<?>> types = test.getTypeDefinitions();
+        Module bar = TestUtils.findModule(modules, "bar");
+        Set<TypeDefinition<?>> 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();
index 3975cdd2e9787c4b36144222ddc5e5645ab9d5db..0d8ed824bfec91e7988e53b8164f121eefa6ada3 100644 (file)
@@ -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<GroupingDefinition> 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<QName> path = new ArrayList<QName>();
-        QName qname = new QName(URI.create("urn:custom.nodes.test"), simpleDateFormat.parse("2013-02-27"), "c",
+        List<QName> 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<Module> modules = null;
+        Set<Module> 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<Module> modules = null;
+        Set<Module> modules;
         try (InputStream stream = new FileInputStream(getClass().getResource("/context-test/deviation-test.yang")
                 .getPath())) {
             List<InputStream> 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<QName> path = new ArrayList<QName>();
-        path.add(new QName(expectedNS, expectedRev, "t", "interfaces"));
-        path.add(new QName(expectedNS, expectedRev, "t", "ifEntry"));
+        List<QName> 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 (file)
index 0000000..733e100
--- /dev/null
@@ -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 (file)
index 0000000..eced11f
--- /dev/null
@@ -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 (file)
index 0000000..abe1456
--- /dev/null
@@ -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;
+            }
+        }
+    }
+
+}
index eafcb56f89d0268bcb0333fdbefe787cda343893..360fbcec7dc875cdfabfbf8ac28fdfd8bde2a5ba 100644 (file)
@@ -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;
     }
index 588d066faddb1a24a1abcf6649321006a3bae3f8..48c0e092cb80cf4fa0f0a3f370fc0a069c88d431 100644 (file)
@@ -4,7 +4,7 @@ module test2 {
     namespace "urn:simple.demo.test2";
     prefix "t2";
 
-    import custom {
+    import baz {
         prefix "data";
     }
 
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 bff9543009b0e2b6b9d0c5863f171e42ae2c3cbb..db9ac6d356e4bf671aa30abec586c727100e2603 100644 (file)
@@ -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";
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 77f109d0e63800f98fb8707dd6d7fe5aa06847cd..ec8a6f752ea8834f57536c1f280e82217ed67bfc 100644 (file)
@@ -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;
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 1389db1c5319c55e0f03abd747c235c8057a38c2..126a97728136857265e0e9d10ce617530093e2a0 100644 (file)
@@ -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";