Bug 4645: Fixed code-implied defaults. 49/29849/4
authorTony Tkacik <ttkacik@cisco.com>
Wed, 18 Nov 2015 11:44:01 +0000 (12:44 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 18 Nov 2015 13:07:11 +0000 (13:07 +0000)
As turned out in parser some YANG types default values
were incorrectly hard-coded in code since Hydrogen
and were unnoticed till automated addition of
 default values in MD-SAL.

Change-Id: I1be1b8ec2358d794fa3ff51a71f392326271b55c
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BitsType.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/StringType.java
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BitsTypeTest.java
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/StringTypeTest.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/type/BitsSpecificationEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/type/BooleanEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/type/StringEffectiveStatementImpl.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/effective/build/test/EffectiveStatementTypeTest.java

index 43b44442af21d4b5bd86791475324bc7bef30085..b277834f07ca87f643e354006f45fda9290d3bf5 100644 (file)
@@ -80,7 +80,8 @@ public final class BitsType implements BitsTypeDefinition {
      */
     @Override
     public Object getDefaultValue() {
-        return bits;
+        // FIXME: Return real bits.
+        return null;
     }
 
     /*
index 79f27fcc0f1dfeaae88e46f13d7fccfc6bd26c6c..7477ff0de5d72d53c4fab8420e045334b2477938 100644 (file)
@@ -28,7 +28,7 @@ import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
 public final class StringType implements StringTypeDefinition, Immutable {
     private static final QName NAME = BaseTypes.STRING_QNAME;
     private static final SchemaPath PATH = SchemaPath.create(true, NAME);
-    private static final String DEFAULT_VALUE = "";
+    private static final String DEFAULT_VALUE = null;
     private static final String DESCRIPTION = "";
     private static final String REFERENCE = "";
     private final List<LengthConstraint> lengthStatements;
index 47e8a76a831c3aea9657a7198ffd59ae21fe77ce..017c4423a1f04da7cdfd1714f4218867129ef273 100644 (file)
@@ -7,6 +7,11 @@
  */
 package org.opendaylight.yangtools.yang.model.util;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
+import java.util.Collections;
+import java.util.List;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
@@ -15,13 +20,6 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.Status;
 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
 
-
-import java.util.Collections;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-
 public class BitsTypeTest {
 
     @Mock
@@ -42,7 +40,7 @@ public class BitsTypeTest {
         assertNotEquals("Description should not be null", null, bitsType.toString());
         assertNotEquals("Reference is not null", null, bitsType.getReference());
         assertEquals("BaseType should be null", null, bitsType.getBaseType());
-        assertEquals("Default value should be list of bit", listBit, bitsType.getDefaultValue());
+        assertEquals("Default value should be null", null, bitsType.getDefaultValue());
         assertEquals("getPath should equal schemaPath", schemaPath, bitsType.getPath());
         assertEquals("Status should be CURRENT", Status.CURRENT, bitsType.getStatus());
         assertEquals("Should be empty list", Collections.EMPTY_LIST, bitsType.getUnknownSchemaNodes());
index 095fb58a793348d2f59ade888ec1fad87538c104..81811aa4c23491a7131eb4b948220899fe0baab0 100644 (file)
@@ -7,12 +7,17 @@
  */
 package org.opendaylight.yangtools.yang.model.util;
 
-import static org.junit.Assert.*;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
 import java.sql.Types;
-import org.opendaylight.yangtools.yang.model.api.Status;
 import org.junit.Before;
 import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
 
 public class StringTypeTest {
 
@@ -33,7 +38,7 @@ public class StringTypeTest {
     @Test
     public void testGetters() {
         assertEquals(string.getUnits(), "");
-        assertEquals(string.getDefaultValue(), "");
+        assertNull(string.getDefaultValue());
         assertEquals(string.getDescription(), "");
         assertEquals(string.getReference(), "");
         assertEquals(string.getQName(), BaseTypes.STRING_QNAME);
index 8bf9bde82904a61b7c6a0e8a6717ea1f644613ef..06726e7f2137f1413770916b00c502d5f6e76b38 100644 (file)
@@ -74,7 +74,8 @@ public class BitsSpecificationEffectiveStatementImpl extends
 
     @Override
     public Object getDefaultValue() {
-        return bits;
+        // FIXME: Should return real value
+        return null;
     }
 
     @Override
index 62be89ca2f3b5ad9297bc2ce3b25eb62ddc86c1d..3981beabba45d000b11d08dd96578900efcfd359 100644 (file)
@@ -50,7 +50,7 @@ public class BooleanEffectiveStatementImpl extends DeclaredEffectiveStatementBas
 
     @Override
     public Object getDefaultValue() {
-        return false;
+        return null;
     }
 
     @Override
index dfc98894b8dc764cbee765ec141f51ae86ef3cbf..b9a9673b79111aa84204e35b073274786ca1479f 100644 (file)
@@ -32,7 +32,6 @@ public class StringEffectiveStatementImpl extends DeclaredEffectiveStatementBase
     public static final String LOCAL_NAME = TypeUtils.STRING;
     private static final QName QNAME = QName.create(YangConstants.RFC6020_YANG_MODULE, LOCAL_NAME);
     private static final SchemaPath PATH = SchemaPath.create(true, QNAME);
-    private static final String DEFAULT_VALUE = "";
     private static final String DESCRIPTION = "The string built-in type represents human-readable strings in YANG. "
             + "Legal characters are tab, carriage return, line feed, and the legal "
             + "characters of Unicode and ISO/IEC 10646";
@@ -76,7 +75,7 @@ public class StringEffectiveStatementImpl extends DeclaredEffectiveStatementBase
 
     @Override
     public Object getDefaultValue() {
-        return DEFAULT_VALUE;
+        return null;
     }
 
     @Override
@@ -149,8 +148,7 @@ public class StringEffectiveStatementImpl extends DeclaredEffectiveStatementBase
         builder.append(QNAME);
         builder.append(", path=");
         builder.append(PATH);
-        builder.append(", defaultValue=");
-        builder.append(DEFAULT_VALUE);
+        builder.append(", defaultValue=null");
         builder.append(", description=");
         builder.append(DESCRIPTION);
         builder.append(", reference=");
index 22199d97454e84a6e710ad8b10b044d5b86eadd4..451f94f7dfe7f9a5ab918ca2abc9647723066d88 100644 (file)
@@ -13,6 +13,7 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+
 import java.util.List;
 import org.junit.Before;
 import org.junit.Test;
@@ -118,7 +119,7 @@ public class EffectiveStatementTypeTest {
         assertFalse(bitsEff.equals("test"));
         assertTrue(bitsEff.equals(bitsEffSecond));
         assertEquals(3, bitsEff.getBits().size());
-        assertEquals(3, ((List<?>) bitsEff.getDefaultValue()).size());
+        assertNull(bitsEff.getDefaultValue());
 
         assertNotNull(bitEff.getPath());
         assertNotNull(bitEff.getUnknownSchemaNodes());
@@ -146,7 +147,7 @@ public class EffectiveStatementTypeTest {
 
         assertNull(booleanEff.getBaseType());
         assertEquals("", booleanEff.getUnits());
-        assertTrue(booleanEff.getDefaultValue().equals(false));
+        assertNull(booleanEff.getDefaultValue());
         assertEquals("boolean", booleanEff.getQName().getLocalName());
         assertNull(booleanEff.getPath().getParent().getParent());
         assertNotNull(booleanEff.getUnknownSchemaNodes());
@@ -482,7 +483,7 @@ public class EffectiveStatementTypeTest {
         assertEquals("string", stringEff.getQName().getLocalName());
         assertEquals("CURRENT", stringEff.getStatus().toString());
         assertEquals("", stringEff.getUnits());
-        assertEquals("", stringEff.getDefaultValue());
+        assertNull(stringEff.getDefaultValue());
         assertNotNull(stringEff.getUnknownSchemaNodes());
         assertNull(stringEff.getBaseType());
         assertNotNull(stringEff.getDescription());