Fix NotificationDefinition 71/64871/8
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 29 Oct 2017 21:48:41 +0000 (22:48 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 3 Nov 2017 10:56:32 +0000 (11:56 +0100)
NotificationDefinition should provide MustDefinitions directly, as
it cannot have any other constraints.

Change-Id: Icf38b5b832979fafac8c38b09b108509014fc48c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
12 files changed:
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ConstraintDefinition.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/MustConstraintAware.java [new file with mode: 0644]
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/NotificationDefinition.java
yang/yang-model-export/src/main/java/org/opendaylight/yangtools/yang/model/export/SchemaContextEmitter.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/NotificationEffectiveStatementImpl.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc7950/Bug6871Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5518Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/DeviationResolutionTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/GroupingTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/MustAndWhenStmtTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserSimpleTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserWithContextTest.java

index 1f9ee7277125c11c94a2ef49e4a4b5f151b3302b..47f8cf0d83a2cd4d007b53ee9b3827be853c4527 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.model.api;
 
-import java.util.Set;
 import javax.annotation.Nullable;
 
 /**
@@ -16,16 +15,7 @@ import javax.annotation.Nullable;
  * YANG element therefore if the constraint doesn't have sense for some element
  * then the method returns <code>null</code> value.
  */
-public interface ConstraintDefinition extends WhenConditionAware {
-    /**
-     * Specifies the rules which the node which contains <code>must</code> YANG
-     * substatement has to match.
-     *
-     * @return set of <code>MustDefinition</code> (XPath) instances which
-     *         represents the concrete data constraints
-     */
-    Set<MustDefinition> getMustConstraints();
-
+public interface ConstraintDefinition extends MustConstraintAware, WhenConditionAware {
     /**
      * Expreses if the presence of the data element for which this constraint is
      * specified is|isn't required.
diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/MustConstraintAware.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/MustConstraintAware.java
new file mode 100644 (file)
index 0000000..609ff1f
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies, s.r.o. 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.model.api;
+
+import java.util.Collection;
+
+/**
+ * Mix-in interface for nodes which can define must constraints.
+ *
+ * @author Robert Varga
+ */
+public interface MustConstraintAware {
+    /**
+     * Specifies the rules which the node which contains <code>must</code> YANG substatement has to match.
+     *
+     * @return collection of <code>MustDefinition</code> (XPath) instances which represents the concrete data
+     *         constraints
+     */
+    Collection<MustDefinition> getMustConstraints();
+}
index 95d1dd3cb860bd21940d8dea132776d4c7d48ec3..ad3577e4598d4962939b9713fb1ea18e962ff19e 100644 (file)
@@ -7,24 +7,11 @@
  */
 package org.opendaylight.yangtools.yang.model.api;
 
-import javax.annotation.Nullable;
-
 /**
  * Interface describing YANG 'notification' statement. The notification
  * statement is used to define a NETCONF notification.
  */
-public interface NotificationDefinition extends SchemaNode, DataNodeContainer, AugmentationTarget, CopyableNode {
+public interface NotificationDefinition extends SchemaNode, DataNodeContainer, AugmentationTarget, CopyableNode,
+        MustConstraintAware {
 
-    /**
-     * All implementations should override this method.
-     * The default definition of this method is used only in YANG 1.0 (RFC6020) implementation of
-     * NotificationDefinition which does not support any constraints.
-     * YANG notification statement has been changed in YANG 1.1 (RFC7950) and now allows must constraints.
-     *
-     * @return the constraints associated with this NotificationDefinition
-     */
-     // FIXME: version 2.0.0: make this method non-default
-    @Nullable default ConstraintDefinition getConstraints() {
-        return null;
-    }
 }
index 7f8172df969b268e4c55d7979a8732a43be6a047..989ecafcdf8dabbc2bb059915fc8a720a8e44207 100644 (file)
@@ -1843,7 +1843,7 @@ abstract class SchemaContextEmitter {
 
         }
 
-        private void emitMustNodes(final Set<MustDefinition> mustConstraints) {
+        private void emitMustNodes(final Collection<MustDefinition> mustConstraints) {
             for (final MustDefinition must : mustConstraints) {
                 emitMust(must);
             }
@@ -2226,7 +2226,9 @@ abstract class SchemaContextEmitter {
 
             super.writer.startNotificationNode(notification.getQName());
             // FIXME: BUG-2444: *(ifFeatureNode )
-            emitConstraints(notification.getConstraints());
+            for (final MustDefinition mustCondition : notification.getMustConstraints()) {
+                emitMust(mustCondition);
+            }
             emitDocumentedNode(notification);
             emitDataNodeContainer(notification);
             emitUnknownStatementNodes(notification.getUnknownSchemaNodes());
index a48a212de1afe986de9830961594758a4e6e53af..eab05cf65d65eefc99ffc5e30c10ea005fba3f2a 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Objects;
@@ -17,7 +18,7 @@ import java.util.Set;
 import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
+import org.opendaylight.yangtools.yang.model.api.MustDefinition;
 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
@@ -31,11 +32,11 @@ public class NotificationEffectiveStatementImpl extends
         AbstractEffectiveDocumentedDataNodeContainer<QName, NotificationStatement> implements NotificationDefinition {
     private final QName qname;
     private final SchemaPath path;
-    private final ConstraintDefinition constraints;
     private final Set<AugmentationSchemaNode> augmentations;
     private final List<UnknownSchemaNode> unknownNodes;
     private final boolean augmenting;
     private final boolean addedByUses;
+    private final Collection<MustDefinition> mustConstraints;
 
     public NotificationEffectiveStatementImpl(
             final StmtContext<QName, NotificationStatement, EffectiveStatement<QName, NotificationStatement>> ctx) {
@@ -43,8 +44,6 @@ public class NotificationEffectiveStatementImpl extends
         this.qname = ctx.getStatementArgument();
         this.path = ctx.getSchemaPath().get();
 
-        this.constraints = EffectiveConstraintDefinitionImpl.forParent(this);
-
         // initSubstatementCollections
         final List<UnknownSchemaNode> unknownNodesInit = new ArrayList<>();
         final Set<AugmentationSchemaNode> augmentationsInit = new LinkedHashSet<>();
@@ -60,6 +59,7 @@ public class NotificationEffectiveStatementImpl extends
         }
         this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
         this.augmentations = ImmutableSet.copyOf(augmentationsInit);
+        this.mustConstraints = ImmutableSet.copyOf(this.allSubstatementsOfType(MustDefinition.class));
 
         // initCopyType
         final CopyHistory copyTypesFromOriginal = ctx.getCopyHistory();
@@ -84,8 +84,8 @@ public class NotificationEffectiveStatementImpl extends
     }
 
     @Override
-    public ConstraintDefinition getConstraints() {
-        return constraints;
+    public Collection<MustDefinition> getMustConstraints() {
+        return mustConstraints;
     }
 
     @Override
index b7febbe8ad0123476e7f572ec0cecd2ccf726d20..46a6be1940b102bbf3873e483668f5270460235d 100644 (file)
@@ -13,6 +13,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.util.Collection;
 import java.util.Set;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.Revision;
@@ -37,7 +38,7 @@ public class Bug6871Test {
         final Set<NotificationDefinition> notifications = foo.getNotifications();
         assertEquals(1, notifications.size());
         final NotificationDefinition myNotification = notifications.iterator().next();
-        Set<MustDefinition> mustConstraints = myNotification.getConstraints().getMustConstraints();
+        Collection<MustDefinition> mustConstraints = myNotification.getMustConstraints();
         assertEquals(2, mustConstraints.size());
 
         final Set<RpcDefinition> rpcs = foo.getRpcs();
index 331fd8fa6af4d4af8d38e33a41c38b3b72af5da0..a299e0f2924c932765df054dea13637d19dc58ac 100644 (file)
@@ -11,7 +11,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
-import java.util.Set;
+import java.util.Collection;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
@@ -28,7 +28,7 @@ public class Bug5518Test {
         final DataSchemaNode dataChildByName = context.getDataChildByName(QName.create("foo", "root"));
         assertTrue(dataChildByName instanceof ContainerSchemaNode);
         final ContainerSchemaNode root = (ContainerSchemaNode) dataChildByName;
-        final Set<MustDefinition> mustConstraints = root.getConstraints().getMustConstraints();
+        final Collection<MustDefinition> mustConstraints = root.getConstraints().getMustConstraints();
         assertEquals(1, mustConstraints.size());
         final MustDefinition must = mustConstraints.iterator().next();
         assertEquals("not(deref(.)/../same-pass)", must.getXpath().toString());
index 7168c747b65c3f57841b75accff8272acf392e1e..bafaf7df9b0b7ef38813fc9ee3f7607e12a2f1e8 100644 (file)
@@ -100,7 +100,7 @@ public class DeviationResolutionTest {
         assertEquals(2, output.getConstraints().getMustConstraints().size());
 
         final NotificationDefinition myNotification = barModule.getNotifications().iterator().next();
-        assertEquals(2, myNotification.getConstraints().getMustConstraints().size());
+        assertEquals(2, myNotification.getMustConstraints().size());
 
         final AnyXmlSchemaNode myAnyxml = (AnyXmlSchemaNode) barModule.getDataChildByName(
                 QName.create(barModule.getQNameModule(), "my-anyxml"));
index 6381924a0d544b1c33b7c4660d3fcaf3f4484b91..c03f6aaed2d70667ff5bb259d68cb5f569d7c35e 100644 (file)
@@ -104,7 +104,7 @@ public class GroupingTest {
         assertEquals(Optional.of("address reference added by refine"), refineLeaf.getReference());
         assertFalse(refineLeaf.isConfiguration());
         assertFalse(refineLeaf.getConstraints().isMandatory());
-        final Set<MustDefinition> leafMustConstraints = refineLeaf.getConstraints().getMustConstraints();
+        final Collection<MustDefinition> leafMustConstraints = refineLeaf.getConstraints().getMustConstraints();
         assertEquals(1, leafMustConstraints.size());
         final MustDefinition leafMust = leafMustConstraints.iterator().next();
         assertEquals("ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)", leafMust.toString());
@@ -112,7 +112,7 @@ public class GroupingTest {
 
         // container port
         assertNotNull(refineContainer);
-        final Set<MustDefinition> mustConstraints = refineContainer.getConstraints().getMustConstraints();
+        final Collection<MustDefinition> mustConstraints = refineContainer.getConstraints().getMustConstraints();
         assertTrue(mustConstraints.isEmpty());
         assertEquals(Optional.of("description of port defined by refine"), refineContainer.getDescription());
         assertEquals(Optional.of("port reference added by refine"), refineContainer.getReference());
index 8ddabcebbdaac655bbb30f65b92b4a624ff336a9..b33289d6e909b6d75e0ff92e1ce94cef09768c4e 100644 (file)
@@ -16,9 +16,9 @@ import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
 
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.Optional;
-import java.util.Set;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
@@ -51,7 +51,7 @@ public class MustAndWhenStmtTest {
         assertNotNull(container);
         assertTrue(container.isPresenceContainer());
 
-        final Set<MustDefinition> musts = container.getConstraints().getMustConstraints();
+        final Collection<MustDefinition> musts = container.getConstraints().getMustConstraints();
         assertEquals(2, musts.size());
 
         final Iterator<MustDefinition> mustsIterator = musts.iterator();
index 4ea6c6d2bd8e57e1510eac7f7b0826302c5d5b09..7fd9b2078fc9bbcb27770ec2e1dd183dfa0b5634 100644 (file)
@@ -15,6 +15,7 @@ import static org.junit.Assert.assertTrue;
 
 import java.net.URI;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.Optional;
 import java.util.Set;
@@ -73,7 +74,7 @@ public class YangParserSimpleTest {
         assertFalse(data.isConfiguration());
         final ConstraintDefinition constraints = data.getConstraints();
         assertEquals("class != 'wheel'", constraints.getWhenCondition().get().toString());
-        final Set<MustDefinition> mustConstraints = constraints.getMustConstraints();
+        final Collection<MustDefinition> mustConstraints = constraints.getMustConstraints();
         assertEquals(2, constraints.getMustConstraints().size());
 
         final String must1 = "ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)";
@@ -119,7 +120,7 @@ public class YangParserSimpleTest {
         // constraints
         final ConstraintDefinition constraints = nodes.getConstraints();
         assertEquals("class != 'wheel'", constraints.getWhenCondition().get().toString());
-        final Set<MustDefinition> mustConstraints = constraints.getMustConstraints();
+        final Collection<MustDefinition> mustConstraints = constraints.getMustConstraints();
         assertEquals(2, constraints.getMustConstraints().size());
 
         final String must1 = "ifType != 'atm' or (ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)";
index af378b1ee4c1f2b6ec6b863d5f7c2ecf4a5808b7..5da099328eff67424d047fbb950a8edecf594f15 100644 (file)
@@ -16,6 +16,7 @@ import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResour
 import com.google.common.collect.Iterables;
 import java.net.URI;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
@@ -261,14 +262,14 @@ public class YangParserWithContextTest {
         assertEquals(Optional.of("address reference added by refine"), refineLeaf.getReference());
         assertFalse(refineLeaf.isConfiguration());
         assertTrue(refineLeaf.getConstraints().isMandatory());
-        final Set<MustDefinition> leafMustConstraints = refineLeaf.getConstraints().getMustConstraints();
+        final Collection<MustDefinition> leafMustConstraints = refineLeaf.getConstraints().getMustConstraints();
         assertEquals(1, leafMustConstraints.size());
         final MustDefinition leafMust = leafMustConstraints.iterator().next();
         assertEquals("ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)", leafMust.toString());
 
         // container port
         assertNotNull(refineContainer);
-        final Set<MustDefinition> mustConstraints = refineContainer.getConstraints().getMustConstraints();
+        final Collection<MustDefinition> mustConstraints = refineContainer.getConstraints().getMustConstraints();
         assertTrue(mustConstraints.isEmpty());
         assertEquals(Optional.of("description of port defined by refine"), refineContainer.getDescription());
         assertEquals(Optional.of("port reference added by refine"), refineContainer.getReference());