Bug 6022: Deviation statement is not fully available in the YANG parser output 52/40752/9
authorIgor Foltin <ifoltin@cisco.com>
Thu, 23 Jun 2016 07:11:36 +0000 (09:11 +0200)
committerRobert Varga <nite@hq.sk>
Tue, 19 Jul 2016 08:22:12 +0000 (08:22 +0000)
- deviation statement can now contain one or more deviate statements
as it is defined in rfc6020
- deviate statement now provides more information about deviated statements

Change-Id: I38ebb5932626df9a0c2de00220474a88ca7f2bc9
Signed-off-by: Igor Foltin <ifoltin@cisco.com>
13 files changed:
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/DeviateDefinition.java [new file with mode: 0644]
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/DeviateKind.java [new file with mode: 0644]
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/Deviation.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/DeviateStatement.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/DeviateStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/Utils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/DeviateEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/DeviationEffectiveStatementImpl.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/DeviationStmtTest.java [new file with mode: 0644]
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveModuleTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserWithContextTest.java
yang/yang-parser-impl/src/test/resources/deviation-stmt-test/foo.yang [new file with mode: 0644]

diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/DeviateDefinition.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/DeviateDefinition.java
new file mode 100644 (file)
index 0000000..7b42318
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * 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.model.api;
+
+import com.google.common.annotations.Beta;
+import java.util.Collection;
+import java.util.Set;
+
+/**
+ * Interface describing YANG 'deviate' statement
+ *
+ * The 'deviate' statement defines how the device's implementation of
+ * the target node deviates from its original definition.
+ * The argument is one of the strings "not-supported", "add", "replace", or "delete".
+ */
+@Beta
+public interface DeviateDefinition {
+
+    /**
+     *
+     * @return enum which describes the type of this deviate statement
+     */
+    DeviateKind getDeviateType();
+
+    /**
+     *
+     * @return value of the deviated config statement or null if it is not deviated
+     */
+    Boolean getDeviatedConfig();
+
+    /**
+     *
+     * @return value of the deviated default statement or null if it is not deviated
+     */
+    String getDeviatedDefault();
+
+    /**
+     *
+     * @return value of the deviated mandatory statement or null if it is not deviated
+     */
+    Boolean getDeviatedMandatory();
+
+    /**
+     *
+     * @return value of the deviated max-elements statement or null if it is not deviated
+     */
+    Integer getDeviatedMaxElements();
+
+    /**
+     *
+     * @return value of the deviated min-elements statement or null if it is not deviated
+     */
+    Integer getDeviatedMinElements();
+
+    /**
+     *
+     * @return set of the deviated must statements
+     */
+    Set<MustDefinition> getDeviatedMusts();
+
+    /**
+     *
+     * @return deviated type statement or null if it is not deviated
+     */
+    TypeDefinition<?> getDeviatedType();
+
+    /**
+     *
+     * @return collection of the deviated unique statements
+     */
+    Collection<UniqueConstraint> getDeviatedUniques();
+
+    /**
+     *
+     * @return value of the deviated units statement or null if it is not deviated
+     */
+    String getDeviatedUnits();
+}
diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/DeviateKind.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/DeviateKind.java
new file mode 100644 (file)
index 0000000..4fa9d0f
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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.model.api;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Enum describing YANG deviation 'deviate' statement. It defines how the
+ * device's implementation of the target node deviates from its original
+ * definition.
+ */
+public enum DeviateKind {
+
+    NOT_SUPPORTED("not-supported"), ADD("add"), REPLACE("replace"), DELETE("delete");
+
+    private final String keyword;
+
+    DeviateKind(final String keyword) {
+        this.keyword = Preconditions.checkNotNull(keyword);
+    }
+
+    /**
+     * @return String that corresponds to the yang keyword.
+     */
+    public String getKeyword() {
+        return keyword;
+    }
+}
index 2a29cb83801a17f4d9ac340fe8fe1c415c697c3f..75b20b192de21a826dfef440878a6543f48937a7 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.model.api;
 
-import com.google.common.base.Preconditions;
 import java.util.List;
 
 /**
@@ -20,28 +19,6 @@ import java.util.List;
  */
 public interface Deviation {
 
-    /**
-     * Enum describing YANG deviation 'deviate' statement. It defines how the
-     * device's implementation of the target node deviates from its original
-     * definition.
-     */
-    enum Deviate {
-        NOT_SUPPORTED("not-supported"), ADD("add"), REPLACE("replace"), DELETE("delete");
-
-        private final String keyword;
-
-        Deviate(final String keyword) {
-            this.keyword = Preconditions.checkNotNull(keyword);
-        }
-
-        /**
-         * @return String that corresponds to the yang keyword.
-         */
-        public String getKeyword() {
-            return keyword;
-        }
-    }
-
     /**
      * @return SchemaPath that identifies the node in the schema tree where a
      *         deviation from the module occurs.
@@ -49,9 +26,16 @@ public interface Deviation {
     SchemaPath getTargetPath();
 
     /**
-     * @return deviate statement of this deviation
+     *
+     * @return List of all deviate statements defined in this deviation
+     */
+    List<DeviateDefinition> getDeviates();
+
+    /**
+     *
+     * @return textual description of this deviation
      */
-    Deviate getDeviate();
+    String getDescription();
 
     /**
      * @return textual cross-reference to an external document that provides
index 6308381916a01a400b0602194a9a8b77f7cac0d8..5b7b02a47b6d2de8c95d6bc0a46a883b48e624de 100644 (file)
@@ -9,11 +9,11 @@ package org.opendaylight.yangtools.yang.model.api.stmt;
 
 import javax.annotation.Nonnull;
 
-import org.opendaylight.yangtools.yang.model.api.Deviation;
+import org.opendaylight.yangtools.yang.model.api.DeviateKind;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 
-public interface DeviateStatement extends DeclaredStatement<Deviation.Deviate> {
+public interface DeviateStatement extends DeclaredStatement<DeviateKind> {
 
     @Nonnull
-    Deviation.Deviate getValue();
+    DeviateKind getValue();
 }
index 325181c97d3a0dad0611b05661dbaa6075c5b387..6aaa6fba278a94840cbf6aae0d06c5f894fcab1e 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 import static org.opendaylight.yangtools.yang.parser.spi.SubstatementValidator.MAX;
 
 import javax.annotation.Nonnull;
-import org.opendaylight.yangtools.yang.model.api.Deviation;
+import org.opendaylight.yangtools.yang.model.api.DeviateKind;
 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.DeviateStatement;
@@ -20,7 +20,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DeviateEffectiveStatementImpl;
 
-public class DeviateStatementImpl extends AbstractDeclaredStatement<Deviation.Deviate> implements DeviateStatement {
+public class DeviateStatementImpl extends AbstractDeclaredStatement<DeviateKind> implements DeviateStatement {
     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(Rfc6020Mapping
             .DEVIATE)
             .add(Rfc6020Mapping.CONFIG, 0, 1)
@@ -34,44 +34,41 @@ public class DeviateStatementImpl extends AbstractDeclaredStatement<Deviation.De
             .add(Rfc6020Mapping.UNITS, 0, 1)
             .build();
 
-    protected DeviateStatementImpl(
-            StmtContext<Deviation.Deviate, DeviateStatement, ?> context) {
+    protected DeviateStatementImpl(StmtContext<DeviateKind, DeviateStatement, ?> context) {
         super(context);
     }
 
-    public static class Definition extends AbstractStatementSupport<Deviation.Deviate, DeviateStatement,
-            EffectiveStatement<Deviation.Deviate, DeviateStatement>> {
+    public static class Definition extends AbstractStatementSupport<DeviateKind, DeviateStatement,
+            EffectiveStatement<DeviateKind, DeviateStatement>> {
 
         public Definition() {
             super(Rfc6020Mapping.DEVIATE);
         }
 
-        @Override public Deviation.Deviate parseArgumentValue(
-                StmtContext<?, ?, ?> ctx, String value) {
+        @Override public DeviateKind parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
             return Utils.parseDeviateFromString(ctx, value);
         }
 
-        @Override public DeviateStatement createDeclared(
-                StmtContext<Deviation.Deviate, DeviateStatement, ?> ctx) {
+        @Override public DeviateStatement createDeclared(StmtContext<DeviateKind, DeviateStatement, ?> ctx) {
             return new DeviateStatementImpl(ctx);
         }
 
-        @Override public EffectiveStatement<Deviation.Deviate, DeviateStatement> createEffective(
-                StmtContext<Deviation.Deviate, DeviateStatement, EffectiveStatement<Deviation.Deviate,
+        @Override public EffectiveStatement<DeviateKind, DeviateStatement> createEffective(
+                StmtContext<DeviateKind, DeviateStatement, EffectiveStatement<DeviateKind,
                         DeviateStatement>> ctx) {
             return new DeviateEffectiveStatementImpl(ctx);
         }
 
         @Override
-        public void onFullDefinitionDeclared(StmtContext.Mutable<Deviation.Deviate, DeviateStatement,
-                EffectiveStatement<Deviation.Deviate, DeviateStatement>> stmt) {
+        public void onFullDefinitionDeclared(StmtContext.Mutable<DeviateKind, DeviateStatement,
+                EffectiveStatement<DeviateKind, DeviateStatement>> stmt) {
             super.onFullDefinitionDeclared(stmt);
             SUBSTATEMENT_VALIDATOR.validate(stmt);
         }
     }
 
     @Nonnull @Override
-    public Deviation.Deviate getValue() {
+    public DeviateKind getValue() {
         return argument();
     }
 }
index c797294da592fc9268aa6e1ad0b9867899c9c7e0..73376d7d72c4f360ec0f9044339464c7db0b6c2a 100644 (file)
@@ -38,8 +38,7 @@ import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementParser;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
-import org.opendaylight.yangtools.yang.model.api.Deviation;
-import org.opendaylight.yangtools.yang.model.api.Deviation.Deviate;
+import org.opendaylight.yangtools.yang.model.api.DeviateKind;
 import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
@@ -292,10 +291,10 @@ public final class Utils {
             .add("YiSyllables")
             .add("YijingHexagramSymbols").build();
 
-    private static final Map<String, Deviate> KEYWORD_TO_DEVIATE_MAP;
+    private static final Map<String, DeviateKind> KEYWORD_TO_DEVIATE_MAP;
     static {
-        Builder<String, Deviate> keywordToDeviateMapBuilder = ImmutableMap.builder();
-        for (Deviate deviate : Deviation.Deviate.values()) {
+        Builder<String, DeviateKind> keywordToDeviateMapBuilder = ImmutableMap.builder();
+        for (DeviateKind deviate : DeviateKind.values()) {
             keywordToDeviateMapBuilder.put(deviate.getKeyword(), deviate);
         }
         KEYWORD_TO_DEVIATE_MAP = keywordToDeviateMapBuilder.build();
@@ -574,7 +573,7 @@ public final class Utils {
                 .isAssignableFrom(UnknownStatementImpl.class);
     }
 
-    public static Deviation.Deviate parseDeviateFromString(final StmtContext<?, ?, ?> ctx, final String deviateKeyword) {
+    public static DeviateKind parseDeviateFromString(final StmtContext<?, ?, ?> ctx, final String deviateKeyword) {
         return Preconditions.checkNotNull(KEYWORD_TO_DEVIATE_MAP.get(deviateKeyword),
                 "String '%s' is not valid deviate argument. Statement source at %s", deviateKeyword,
                 ctx.getStatementSourceReference());
index 9b8288b2495882c01df8c7474f288c55380d5b39..c56f146c010607b0b0de2c57dc26df0c93fc7488 100644 (file)
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
-import org.opendaylight.yangtools.yang.model.api.Deviation;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import java.util.Collection;
+import java.util.Objects;
+import java.util.Set;
+import org.opendaylight.yangtools.yang.model.api.DeviateDefinition;
+import org.opendaylight.yangtools.yang.model.api.DeviateKind;
+import org.opendaylight.yangtools.yang.model.api.MustDefinition;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.UniqueConstraint;
 import org.opendaylight.yangtools.yang.model.api.stmt.DeviateStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 
-public final class DeviateEffectiveStatementImpl extends DeclaredEffectiveStatementBase<Deviation.Deviate, DeviateStatement> {
-    public DeviateEffectiveStatementImpl(final StmtContext<Deviation.Deviate, DeviateStatement, ?> ctx) {
+public final class DeviateEffectiveStatementImpl
+        extends DeclaredEffectiveStatementBase<DeviateKind, DeviateStatement> implements DeviateDefinition {
+
+    private final DeviateKind deviateType;
+    private final Boolean deviatedConfig;
+    private final String deviatedDefault;
+    private final Boolean deviatedMandatory;
+    private final Integer deviatedMaxElements;
+    private final Integer deviatedMinElements;
+    private final Set<MustDefinition> deviatedMustDefinitions;
+    private final TypeDefinition<?> deviatedType;
+    private final Collection<UniqueConstraint> deviatedUniqueConstraints;
+    private final String deviatedUnits;
+
+
+    public DeviateEffectiveStatementImpl(final StmtContext<DeviateKind, DeviateStatement, ?> ctx) {
         super(ctx);
+
+        this.deviateType = argument();
+
+        final ConfigEffectiveStatementImpl configStmt = firstEffective(ConfigEffectiveStatementImpl.class);
+        this.deviatedConfig = configStmt == null ? null : configStmt.argument();
+        final DefaultEffectiveStatementImpl defaultStmt = firstEffective(DefaultEffectiveStatementImpl.class);
+        this.deviatedDefault = defaultStmt == null ? null : defaultStmt.argument();
+        final MandatoryEffectiveStatement mandatoryStmt = firstEffective(MandatoryEffectiveStatement.class);
+        this.deviatedMandatory = mandatoryStmt == null ? null : mandatoryStmt.argument();
+        final MaxElementsEffectiveStatementImpl maxElementsStmt = firstEffective(MaxElementsEffectiveStatementImpl.class);
+        this.deviatedMaxElements = maxElementsStmt == null ? null : Integer.valueOf(maxElementsStmt.argument());
+        final MinElementsEffectiveStatementImpl minElementsStmt = firstEffective(MinElementsEffectiveStatementImpl.class);
+        this.deviatedMinElements = minElementsStmt == null ? null : minElementsStmt.argument();
+        final TypeEffectiveStatement<TypeStatement> typeStmt = firstEffective(TypeEffectiveStatement.class);
+        this.deviatedType = typeStmt == null ? null : typeStmt.getTypeDefinition();
+        final UnitsEffectiveStatementImpl unitsStmt = firstEffective(UnitsEffectiveStatementImpl.class);
+        this.deviatedUnits = unitsStmt == null ? null : unitsStmt.argument();
+
+        this.deviatedMustDefinitions = ImmutableSet.copyOf(allSubstatementsOfType(MustDefinition.class));
+        this.deviatedUniqueConstraints = ImmutableList.copyOf(allSubstatementsOfType(UniqueConstraint.class));
+    }
+
+    @Override
+    public DeviateKind getDeviateType() {
+        return deviateType;
+    }
+
+    @Override
+    public Boolean getDeviatedConfig() {
+        return deviatedConfig;
+    }
+
+    @Override
+    public String getDeviatedDefault() {
+        return deviatedDefault;
+    }
+
+    @Override
+    public Boolean getDeviatedMandatory() {
+        return deviatedMandatory;
+    }
+
+    @Override
+    public Integer getDeviatedMaxElements() {
+        return deviatedMaxElements;
+    }
+
+    @Override
+    public Integer getDeviatedMinElements() {
+        return deviatedMinElements;
+    }
+
+    @Override
+    public Set<MustDefinition> getDeviatedMusts() {
+        return deviatedMustDefinitions;
+    }
+
+    @Override
+    public TypeDefinition<?> getDeviatedType() {
+        return deviatedType;
+    }
+
+    @Override
+    public Collection<UniqueConstraint> getDeviatedUniques() {
+        return deviatedUniqueConstraints;
+    }
+
+    @Override
+    public String getDeviatedUnits() {
+        return deviatedUnits;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        DeviateEffectiveStatementImpl other = (DeviateEffectiveStatementImpl) obj;
+        return Objects.equals(deviateType, other.deviateType) &&
+                Objects.equals(deviatedConfig, other.deviatedConfig) &&
+                Objects.equals(deviatedDefault, other.deviatedDefault) &&
+                Objects.equals(deviatedMandatory, other.deviatedMandatory) &&
+                Objects.equals(deviatedMaxElements, other.deviatedMaxElements) &&
+                Objects.equals(deviatedMinElements, other.deviatedMinElements) &&
+                Objects.equals(deviatedMustDefinitions, other.deviatedMustDefinitions) &&
+                Objects.equals(deviatedType, other.deviatedType) &&
+                Objects.equals(deviatedUniqueConstraints, other.deviatedUniqueConstraints) &&
+                Objects.equals(deviatedUnits, other.deviatedUnits);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(deviateType, deviatedConfig, deviatedDefault, deviatedMandatory, deviatedMaxElements,
+                deviatedMinElements, deviatedMustDefinitions, deviatedType, deviatedUniqueConstraints, deviatedUnits);
     }
 }
\ No newline at end of file
index b66abf8c67bd7aa3fdd00c3bd819fa05b4fed7f4..e4c0e85f61ab2ee00182a3d9acbdf1329f1c701c 100644 (file)
@@ -12,6 +12,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
 import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.yang.model.api.DeviateDefinition;
 import org.opendaylight.yangtools.yang.model.api.Deviation;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
@@ -23,16 +24,19 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 public class DeviationEffectiveStatementImpl extends DeclaredEffectiveStatementBase<SchemaNodeIdentifier, DeviationStatement>
         implements Deviation, Immutable {
     private final SchemaPath targetPath;
-    private final Deviate deviate;
+    private final String description;
     private final String reference;
     private final List<UnknownSchemaNode> unknownSchemaNodes;
+    private final List<DeviateDefinition> deviateDefinitions;
 
     public DeviationEffectiveStatementImpl(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
         super(ctx);
         this.targetPath = ctx.getStatementArgument().asSchemaPath();
 
-        DeviateEffectiveStatementImpl deviateStmt = firstEffective(DeviateEffectiveStatementImpl.class);
-        this.deviate = (deviateStmt == null) ? null : deviateStmt.argument();
+        this.deviateDefinitions = ImmutableList.copyOf(allSubstatementsOfType(DeviateDefinition.class));
+
+        DescriptionEffectiveStatementImpl descriptionStmt = firstEffective(DescriptionEffectiveStatementImpl.class);
+        this.description = (descriptionStmt == null) ? null : descriptionStmt.argument();
 
         ReferenceEffectiveStatementImpl referenceStmt = firstEffective(ReferenceEffectiveStatementImpl.class);
         this.reference = (referenceStmt == null) ? null : referenceStmt.argument();
@@ -52,8 +56,13 @@ public class DeviationEffectiveStatementImpl extends DeclaredEffectiveStatementB
     }
 
     @Override
-    public Deviate getDeviate() {
-        return deviate;
+    public List<DeviateDefinition> getDeviates() {
+        return deviateDefinitions;
+    }
+
+    @Override
+    public String getDescription() {
+        return description;
     }
 
     @Override
@@ -71,7 +80,8 @@ public class DeviationEffectiveStatementImpl extends DeclaredEffectiveStatementB
         final int prime = 31;
         int result = 1;
         result = prime * result + Objects.hashCode(targetPath);
-        result = prime * result + Objects.hashCode(deviate);
+        result = prime * result + Objects.hashCode(deviateDefinitions);
+        result = prime * result + Objects.hashCode(description);
         result = prime * result + Objects.hashCode(reference);
         return result;
     }
@@ -91,7 +101,10 @@ public class DeviationEffectiveStatementImpl extends DeclaredEffectiveStatementB
         if (!Objects.equals(targetPath, other.targetPath)) {
             return false;
         }
-        if (!Objects.equals(deviate, other.deviate)) {
+        if (!Objects.equals(deviateDefinitions, other.deviateDefinitions)) {
+            return false;
+        }
+        if (!Objects.equals(description, other.description)) {
             return false;
         }
         if (!Objects.equals(reference, other.reference)) {
@@ -104,7 +117,8 @@ public class DeviationEffectiveStatementImpl extends DeclaredEffectiveStatementB
     public String toString() {
         return DeviationEffectiveStatementImpl.class.getSimpleName() + "[" +
                 "targetPath=" + targetPath +
-                ", deviate=" + deviate +
+                ", deviates=" + deviateDefinitions +
+                ", description=" + description +
                 ", reference=" + reference +
                 "]";
     }
diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/DeviationStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/DeviationStmtTest.java
new file mode 100644 (file)
index 0000000..5745783
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * 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.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.text.ParseException;
+import java.util.Date;
+import java.util.List;
+import java.util.Set;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+import org.opendaylight.yangtools.yang.model.api.DeviateDefinition;
+import org.opendaylight.yangtools.yang.model.api.DeviateKind;
+import org.opendaylight.yangtools.yang.model.api.Deviation;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
+
+public class DeviationStmtTest {
+
+    private static final StatementStreamSource FOO_MODULE =
+            new YangStatementSourceImpl("/deviation-stmt-test/foo.yang", false);
+
+    @Test
+    public void testDeviationAndDeviate() throws ReactorException, ParseException {
+        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+        reactor.addSources(FOO_MODULE);
+
+        final SchemaContext schemaContext = reactor.buildEffective();
+        assertNotNull(schemaContext);
+
+        final Date revision = SimpleDateFormatUtil.getRevisionFormat().parse("2016-06-23");
+
+        final Module testModule = schemaContext.findModuleByName("foo", revision);
+        assertNotNull(testModule);
+
+        final Set<Deviation> deviations = testModule.getDeviations();
+        assertEquals(4, deviations.size());
+
+        for (Deviation deviation : deviations) {
+            final List<DeviateDefinition> deviates = deviation.getDeviates();
+            final String targetLocalName = deviation.getTargetPath().getLastComponent().getLocalName();
+            if ("test-leaf".equals(targetLocalName)) {
+                assertEquals("test-leaf is not supported", deviation.getDescription());
+                assertEquals(1, deviates.size());
+                assertEquals(DeviateKind.NOT_SUPPORTED, deviates.iterator().next().getDeviateType());
+            } else if ("test-leaf-2".equals(targetLocalName)) {
+                assertEquals(1, deviates.size());
+                assertEquals(DeviateKind.ADD, deviates.iterator().next().getDeviateType());
+                assertEquals("added-def-val", deviates.iterator().next().getDeviatedDefault());
+                assertFalse(deviates.iterator().next().getDeviatedConfig());
+            } else if ("test-leaf-list".equals(targetLocalName)) {
+                assertEquals(3, deviates.size());
+                for (DeviateDefinition deviate : deviates) {
+                    if (DeviateKind.ADD.equals(deviate.getDeviateType())) {
+                        assertEquals(12, deviate.getDeviatedMaxElements().intValue());
+                        assertTrue(deviate.getDeviatedMandatory());
+                    } else if (DeviateKind.REPLACE.equals(deviate.getDeviateType())) {
+                        assertEquals(5, deviate.getDeviatedMinElements().intValue());
+                        assertTrue(deviate.getDeviatedType() instanceof UnsignedIntegerTypeDefinition);
+                    } else {
+                        assertEquals(2, deviate.getDeviatedMusts().size());
+                        assertEquals("minutes", deviate.getDeviatedUnits());
+                    }
+                }
+            } else {
+                assertEquals(1, deviation.getDeviates().size());
+                assertEquals(DeviateKind.DELETE, deviates.iterator().next().getDeviateType());
+                assertEquals(2, deviates.iterator().next().getDeviatedUniques().size());
+            }
+        }
+    }
+}
index 7345f40ad8aafb1fcb3d051ae6b25ff593ddc202..e7c881e8bc56de7528e3a5425491e6b986416597 100644 (file)
@@ -23,6 +23,7 @@ import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DeviateKind;
 import org.opendaylight.yangtools.yang.model.api.Deviation;
 import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
 import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
@@ -117,7 +118,7 @@ public class EffectiveModuleTest {
         final Deviation deviationStmt = deviations.iterator().next();
         assertNotNull(deviationStmt);
         assertEquals(contSchemaPath, deviationStmt.getTargetPath());
-        assertEquals(Deviation.Deviate.ADD, deviationStmt.getDeviate());
+        assertEquals(DeviateKind.ADD, deviationStmt.getDeviates().iterator().next().getDeviateType());
         assertEquals("deviate reference", deviationStmt.getReference());
 
         final Set<IdentitySchemaNode> identities = rootModule.getIdentities();
index a541a29151aec5d1486674f1af865a8dde907aa4..1db68b08aafa3e306a9016de5bddd10911148bad 100644 (file)
@@ -13,6 +13,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+
 import java.io.File;
 import java.io.IOException;
 import java.net.URI;
@@ -36,8 +37,8 @@ import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DeviateKind;
 import org.opendaylight.yangtools.yang.model.api.Deviation;
-import org.opendaylight.yangtools.yang.model.api.Deviation.Deviate;
 import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
 import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
@@ -621,7 +622,7 @@ public class YangParserTest {
         SchemaPath expectedPath = SchemaPath.create(path, true);
 
         assertEquals(expectedPath, dev.getTargetPath());
-        assertEquals(Deviate.ADD, dev.getDeviate());
+        assertEquals(DeviateKind.ADD, dev.getDeviates().iterator().next().getDeviateType());
     }
 
     @Test
index c76545fd4eb314c970d435d1bfdac53b5ee7f576..7bd1a3e5d97c4822069f0ad3ff8e0d49af5e20e7 100644 (file)
@@ -11,6 +11,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+
 import java.net.URI;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
@@ -26,8 +27,8 @@ import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DeviateKind;
 import org.opendaylight.yangtools.yang.model.api.Deviation;
-import org.opendaylight.yangtools.yang.model.api.Deviation.Deviate;
 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
@@ -462,7 +463,7 @@ public class YangParserWithContextTest {
         SchemaPath expectedPath = SchemaPath.create(path, true);
 
         assertEquals(expectedPath, dev.getTargetPath());
-        assertEquals(Deviate.ADD, dev.getDeviate());
+        assertEquals(DeviateKind.ADD, dev.getDeviates().iterator().next().getDeviateType());
     }
 
 }
diff --git a/yang/yang-parser-impl/src/test/resources/deviation-stmt-test/foo.yang b/yang/yang-parser-impl/src/test/resources/deviation-stmt-test/foo.yang
new file mode 100644 (file)
index 0000000..d94b76f
--- /dev/null
@@ -0,0 +1,88 @@
+module foo {
+    namespace "foo-namespace";
+    prefix "foo-prefix";
+
+    revision "2016-06-23" {
+        description "Initial revision";
+    }
+
+    deviation "/test-container/test-leaf" {
+        description "test-leaf is not supported";
+        deviate not-supported;
+    }
+
+    deviation "/test-container/test-leaf-2" {
+        deviate add {
+            default "added-def-val";
+            config false;
+        }
+    }
+
+    deviation "/test-container/test-leaf-list" {
+        deviate add {
+            max-elements 12;
+            mandatory true;
+        }
+
+        deviate replace {
+            min-elements 5;
+            type uint32;
+        }
+
+        deviate delete {
+            must "daytime or time";
+            must "time or daytime";
+            units minutes;
+        }
+    }
+
+    deviation "/test-container/test-list" {
+        deviate delete {
+            unique "list-leaf-1 list-leaf-2";
+            unique "list-leaf-3 list-leaf-4";
+        }
+    }
+
+    container test-container {
+        leaf test-leaf {
+            type string;
+        }
+
+        leaf test-leaf-2 {
+            type string;
+        }
+
+        leaf-list test-leaf-list {
+            type int32;
+            min-elements 3;
+            must "daytime or time";
+            units minutes;
+        }
+
+        list test-list {
+            key key-leaf;
+            unique "list-leaf-1 list-leaf-2";
+            unique "list-leaf-3 list-leaf-4";
+
+            leaf key-leaf {
+                type string;
+            }
+
+            leaf list-leaf-1 {
+                type string;
+            }
+
+            leaf list-leaf-2 {
+                type string;
+            }
+
+            leaf list-leaf-3 {
+                type string;
+            }
+
+            leaf list-leaf-4 {
+                type string;
+            }
+        }
+    }
+}
\ No newline at end of file