BUG-4268: clarify length constraint API contract 84/29884/5
authorRobert Varga <robert.varga@pantheon.sk>
Wed, 18 Nov 2015 19:37:01 +0000 (20:37 +0100)
committerRobert Varga <nite@hq.sk>
Wed, 30 Mar 2016 08:04:57 +0000 (08:04 +0000)
The contract did not specify whether the returned constraints are
declared or effective. The intent is to return effective constraints,
which include any constraints imposed by base types -- as is the case
with range constraints.

Change-Id: I0d0582edf87c0a78db3e8664655f139f827217a7
Signed-off-by: Robert Varga <robert.varga@pantheon.sk>
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/type/BinaryTypeDefinition.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/type/StringTypeDefinition.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/LengthRestrictedTypeBuilder.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/YangParserTest.java

index 8d87fca7735456afd225f7886c77d9c60d630d4c..b097fd3d87d6ae81e822ae306fa8fc66bfd7fb70 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.yangtools.yang.model.api.type;
 
 import java.util.List;
-
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 
 /**
@@ -20,21 +19,21 @@ import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
  * 4</a>). <br>
  * The canonical form of a binary value follows the rules in <a
  * href="https://tools.ietf.org/html/rfc4648">[RFC4648]</a>.
- * 
+ *
  * <br>
  * <br>
  * This interface was modeled according to definition in <a
  * href="https://tools.ietf.org/html/rfc6020#section-9.8">[RFC-6020] The binary
  * Built-In Type</a>
- * 
  */
 public interface BinaryTypeDefinition extends TypeDefinition<BinaryTypeDefinition> {
 
     /**
-     * Returns List of number of octets that binary value contains.
-     * 
+     * Returns List of number of octets that binary value contains. These are the effective constraints, e.g. they include
+     * any range constraints imposed by base types.
+     *
      * @return List of number of octets that binary value contains.
-     * 
+     *
      * @see LengthConstraint
      */
     List<LengthConstraint> getLengthConstraints();
index b8fcb0b4e4b330274236dde93322f3602c7d09a8..958e796e517912f32bb75342d6d0d5d0c273ba60 100644 (file)
@@ -8,28 +8,28 @@
 package org.opendaylight.yangtools.yang.model.api.type;
 
 import java.util.List;
-
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 
 /**
- * 
+ *
  * Contains method for getting data from the <code>string</code> YANG built-in
  * type.
  */
 public interface StringTypeDefinition extends TypeDefinition<StringTypeDefinition> {
 
     /**
-     * Returns length constraint specified in the string.
-     * 
+     * Returns length constraint specified in the string. These are the effective constraints, e.g. they include
+     * any length constraints implied by base types.
+     *
      * @return list of length constraint which are specified in the
-     *         <code>lenght</code> substatement of the <code>type</code>
+     *         <code>length</code> substatement of the <code>type</code>
      *         statement
      */
     List<LengthConstraint> getLengthConstraints();
 
     /**
      * Returns patterns specified in the string.
-     * 
+     *
      * @return list of pattern constraints which are specified in the
      *         <code>pattern</code> substatement of the <code>type</code>
      *         statement
index fe217561b1c8df84d1a585cf1da01c0338ddab02..9c1b84bec477e1c54716b40dcacabc9654003fa8 100644 (file)
@@ -138,12 +138,12 @@ public abstract class LengthRestrictedTypeBuilder<T extends TypeDefinition<T>> e
 
     @Override
     final T buildType() {
+        final List<LengthConstraint> baseLengths = findLenghts();
+
         if (lengthAlternatives == null || lengthAlternatives.isEmpty()) {
-            return buildType(ImmutableList.<LengthConstraint>of());
+            return buildType(baseLengths);
         }
 
-        final List<LengthConstraint> baseLengths = findLenghts();
-
         // Run through alternatives and resolve them against the base type
         final List<LengthConstraint> resolvedLengths = ensureResolvedLengths(lengthAlternatives, baseLengths);
 
index 66e65c43813b722f2801361b2a95eaf1028e9bf5..72771f6c04942332419f9242baeddffc486409fd 100644 (file)
@@ -241,7 +241,7 @@ public class YangParserTest {
         assertEquals(1, patterns.size());
         PatternConstraint pattern = patterns.iterator().next();
         assertEquals("^[e-z]*$", pattern.getRegularExpression());
-        assertTrue(type.getLengthConstraints().isEmpty());
+        assertEquals(1, type.getLengthConstraints().size());
 
         StringTypeDefinition baseType1 = type.getBaseType();
         QName baseType1QName = baseType1.getQName();
@@ -254,7 +254,7 @@ public class YangParserTest {
         assertEquals(1, patterns.size());
         pattern = patterns.iterator().next();
         assertEquals("^[b-u]*$", pattern.getRegularExpression());
-        assertTrue(baseType1.getLengthConstraints().isEmpty());
+        assertEquals(1, baseType1.getLengthConstraints().size());
 
         StringTypeDefinition baseType2 = baseType1.getBaseType();
         QName baseType2QName = baseType2.getQName();
@@ -331,7 +331,7 @@ public class YangParserTest {
         assertEquals(1, patterns.size());
         PatternConstraint pattern = patterns.iterator().next();
         assertEquals("^[e-z]*$", pattern.getRegularExpression());
-        assertTrue(type.getLengthConstraints().isEmpty());
+        assertEquals(1, type.getLengthConstraints().size());
 
         final LeafSchemaNode multiplePatternDirectStringDefLeaf = (LeafSchemaNode) foo
                 .getDataChildByName("multiple-pattern-direct-string-def-leaf");