BUG-6150: add an import statement special-case 58/48258/1
authorVratko Polak <vrpolak@cisco.com>
Thu, 10 Nov 2016 13:41:15 +0000 (14:41 +0100)
committerRobert Varga <rovarga@cisco.com>
Fri, 11 Nov 2016 13:28:18 +0000 (14:28 +0100)
This is just a hack to get the bug unblocked, a follow-up
patch is needed to really fix the underlying assumptions
about when a statement should be populated into the map.

Unit tests added.

Change-Id: I80273f1971981d62214e3cabfe687d5fcb61abd3
Signed-off-by: Robert Varga <rovarga@cisco.com>
Signed-off-by: Vratko Polak <vrpolak@cisco.com>
(cherry picked from commit bbce2ddf4f0cfced8ea5ad85d709ce62ffdea41b)

yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ContextBuilder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentArgumentParsingTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug6150Test.java [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/bugs/bug6150/aug-first.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/bugs/bug6150/aug-second.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/bugs/bug6150/target.yang [new file with mode: 0644]

index 17695cb40474cf19f0ac0a163b1094b0ac296eea..62ac6e5f774ac1400a203a2188533aa3de2f037d 100644 (file)
@@ -56,4 +56,12 @@ abstract class ContextBuilder<A, D extends DeclaredStatement<A>, E extends Effec
     StatementIdentifier createIdentifier() {
         return new StatementIdentifier(definition.getStatementName(), rawArg);
     }
+
+    /**
+     * {@inheritDoc}
+     *
+     * @throws SourceException when a source-level problem is found
+     */
+    @Override
+    public abstract StatementContextBase<A, D, E> build();
 }
index 6d13a5320bd3fe244ba4de74dd6ac5bad12fe2bd..207a283c816dda2829eb0d842312a40010686c3e 100644 (file)
@@ -390,7 +390,7 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
 
                 final StatementDefinition stmtDef = getDefinition().getPublicView();
                 if (stmtDef != Rfc6020Mapping.AUGMENT && stmtDef != Rfc6020Mapping.DEVIATION
-                        && stmtDef != Rfc6020Mapping.TYPE) {
+                        && stmtDef != Rfc6020Mapping.IMPORT && stmtDef != Rfc6020Mapping.TYPE) {
                     potential = substatements.get(createIdentifier());
                 }
                 if (potential == null) {
index 8313267f71b138b1d13f2bcb1d73a41999a50b2e..0f4c8fd22d4a124e45ee26d65c4e9c653d9c0c01 100644 (file)
@@ -25,20 +25,19 @@ public class AugmentArgumentParsingTest {
 
     private static final YangStatementSourceImpl IMPORTED = new YangStatementSourceImpl(
             "/semantic-statement-parser/augment-arg-parsing/imported.yang", false);
-
-    private static YangStatementSourceImpl VALID_ARGS = new YangStatementSourceImpl(
+    private static final YangStatementSourceImpl VALID_ARGS = new YangStatementSourceImpl(
             "/semantic-statement-parser/augment-arg-parsing/root-valid-aug-args.yang", false);
-    private static YangStatementSourceImpl INVALID_REL1 = new YangStatementSourceImpl(
+    private static final YangStatementSourceImpl INVALID_REL1 = new YangStatementSourceImpl(
             "/semantic-statement-parser/augment-arg-parsing/root-invalid-rel1.yang", false);
-    private static YangStatementSourceImpl INVALID_REL2 = new YangStatementSourceImpl(
+    private static final YangStatementSourceImpl INVALID_REL2 = new YangStatementSourceImpl(
             "/semantic-statement-parser/augment-arg-parsing/root-invalid-rel2.yang", false);
-    private static YangStatementSourceImpl INVALID_ABS = new YangStatementSourceImpl(
+    private static final YangStatementSourceImpl INVALID_ABS = new YangStatementSourceImpl(
             "/semantic-statement-parser/augment-arg-parsing/root-invalid-abs.yang", false);
-    private static YangStatementSourceImpl INVALID_ABS_PREFIXED_NO_IMP = new YangStatementSourceImpl(
+    private static final YangStatementSourceImpl INVALID_ABS_PREFIXED_NO_IMP = new YangStatementSourceImpl(
             "/semantic-statement-parser/augment-arg-parsing/root-invalid-abs-no-imp.yang", false);
-    private static YangStatementSourceImpl INVALID_EMPTY = new YangStatementSourceImpl(
+    private static final YangStatementSourceImpl INVALID_EMPTY = new YangStatementSourceImpl(
             "/semantic-statement-parser/augment-arg-parsing/root-invalid-empty.yang", false);
-    private static YangStatementSourceImpl INVALID_XPATH = new YangStatementSourceImpl(
+    private static final YangStatementSourceImpl INVALID_XPATH = new YangStatementSourceImpl(
             "/semantic-statement-parser/augment-arg-parsing/root-invalid-xpath.yang", false);
 
     @Test
diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug6150Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug6150Test.java
new file mode 100644 (file)
index 0000000..18c91a4
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.yangtools.yang.stmt;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
+
+public class Bug6150Test {
+
+    private static final YangStatementSourceImpl TARGET = new YangStatementSourceImpl(
+            "/bugs/bug6150/target.yang", false);
+    private static final YangStatementSourceImpl AUGMENT_FIRST = new YangStatementSourceImpl(
+            "/bugs/bug6150/aug-first.yang", false);
+    private static final YangStatementSourceImpl AUGMENT_SECOND = new YangStatementSourceImpl(
+            "/bugs/bug6150/aug-second.yang", false);
+
+    private static void addSources(final BuildAction reactor, final YangStatementSourceImpl... sources) {
+        for (YangStatementSourceImpl source : sources) {
+            reactor.addSource(source);
+        }
+    }
+
+    @Test
+    public void effectiveAugmentFirstTest() throws ReactorException {
+        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+        addSources(reactor, TARGET, AUGMENT_FIRST);
+        final SchemaContext result = reactor.buildEffective();
+        assertNotNull(result);
+    }
+
+    @Test
+    public void effectiveAugmentSecondTest() throws ReactorException {
+        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+        addSources(reactor, TARGET, AUGMENT_SECOND);
+        final SchemaContext result = reactor.buildEffective();
+        assertNotNull(result);
+    }
+
+    @Test
+    public void effectiveAugmentBothTest() throws ReactorException {
+        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+        addSources(reactor, TARGET, AUGMENT_FIRST, AUGMENT_SECOND);
+        final SchemaContext result = reactor.buildEffective();
+        assertNotNull(result);
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/resources/bugs/bug6150/aug-first.yang b/yang/yang-parser-impl/src/test/resources/bugs/bug6150/aug-first.yang
new file mode 100644 (file)
index 0000000..faeb5b3
--- /dev/null
@@ -0,0 +1,21 @@
+module aug-first {
+
+  namespace "odl:test:bug6150:aug-first";
+  prefix "af";
+  revision 2016-11-10;
+
+  import target {
+    prefix tf;
+  }
+  import target {
+    prefix ts;
+  }
+
+  // With Bug present, this fails because tf got overwritten.
+  augment "/tf:target" {
+    leaf added-leaf {
+      type string;
+    }
+  }
+
+}
diff --git a/yang/yang-parser-impl/src/test/resources/bugs/bug6150/aug-second.yang b/yang/yang-parser-impl/src/test/resources/bugs/bug6150/aug-second.yang
new file mode 100644 (file)
index 0000000..5551af5
--- /dev/null
@@ -0,0 +1,21 @@
+module aug-second {
+
+  namespace "odl:test:bug6150:aug-second";
+  prefix "as";
+  revision 2016-11-10;
+
+  import target {
+    prefix tf;
+  }
+  import target {
+    prefix ts;
+  }
+
+  // With Bug present, this works just because tf is not involved.
+  augment "/ts:target" {
+    leaf added-leaf {
+      type string;
+    }
+  }
+
+}
diff --git a/yang/yang-parser-impl/src/test/resources/bugs/bug6150/target.yang b/yang/yang-parser-impl/src/test/resources/bugs/bug6150/target.yang
new file mode 100644 (file)
index 0000000..157bf38
--- /dev/null
@@ -0,0 +1,11 @@
+module target {
+
+  namespace "odl:test:bug6150:target";
+  prefix "t";
+  revision 2016-11-10;
+
+  container target {
+    presence "Augmentations go here.";
+  }
+
+}