Add support for enums as configuration attributes in config and netconf subsystem. 02/3202/3
authorMaros Marsalek <mmarsale@cisco.com>
Thu, 28 Nov 2013 12:54:50 +0000 (13:54 +0100)
committerMaros Marsalek <mmarsale@cisco.com>
Thu, 28 Nov 2013 15:23:40 +0000 (16:23 +0100)
Change-Id: Ieb6054e2136a2eaf834105f9c1cff6db8668d507
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/attribute/JavaAttribute.java
opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/attribute/SimpleTypeResolver.java
opendaylight/config/yang-test/src/main/yang/config-test-impl.yang
opendaylight/netconf/config-netconf-connector/src/test/java/org/opendaylight/controller/netconf/confignetconfconnector/NetconfMappingTest.java
opendaylight/netconf/netconf-util/src/test/resources/netconfMessages/editConfig.xml

index 73c7e227be8abc03aed2bb7a5b3dc8204fe240f8..325ca9ee06fd1bd9d29d56a94cedc0871aac77c7 100644 (file)
@@ -121,15 +121,21 @@ public class JavaAttribute extends AbstractAttribute implements TypedAttribute {
 
         if (isArray()) {
             return getArrayType();
 
         if (isArray()) {
             return getArrayType();
+        } else if (isEnum(baseType)) {
+            return getSimpleType(baseType);
         } else if (isDerivedType(baseType)) {
             return getCompositeType(baseType, baseTypeDefinition);
         }
 
         } else if (isDerivedType(baseType)) {
             return getCompositeType(baseType, baseTypeDefinition);
         }
 
-        return getSimpleType();
+        return getSimpleType(getType());
     }
 
     }
 
-    private OpenType<?> getSimpleType() {
-        SimpleType<?> simpleType = SimpleTypeResolver.getSimpleType(getType());
+    private boolean isEnum(Type baseType) {
+        return baseType.getFullyQualifiedName().equals(Enum.class.getName());
+    }
+
+    private OpenType<?> getSimpleType(Type type) {
+        SimpleType<?> simpleType = SimpleTypeResolver.getSimpleType(type);
         return simpleType;
     }
 
         return simpleType;
     }
 
index 61ad74d7eebfdfe47e6c59e4844a4d18bbe2af70..87b55f3756a0e042c98c89739d91bf0f92ab5285 100644 (file)
@@ -39,26 +39,21 @@ public class SimpleTypeResolver {
         return expectedSimpleType;
     }
 
         return expectedSimpleType;
     }
 
-    private static final Map<String, SimpleType<?>> JAVA_TYPE_TO_SIMPLE_TYPE = Maps
-            .newHashMap();
+    private static final Map<String, SimpleType<?>> JAVA_TYPE_TO_SIMPLE_TYPE = Maps.newHashMap();
     static {
         // TODO add all
     static {
         // TODO add all
-        JAVA_TYPE_TO_SIMPLE_TYPE.put(Integer.class.getName(),
-                SimpleType.INTEGER);
+        JAVA_TYPE_TO_SIMPLE_TYPE.put(Integer.class.getName(), SimpleType.INTEGER);
         JAVA_TYPE_TO_SIMPLE_TYPE.put(int.class.getName(), SimpleType.INTEGER);
         JAVA_TYPE_TO_SIMPLE_TYPE.put(Short.class.getName(), SimpleType.SHORT);
         JAVA_TYPE_TO_SIMPLE_TYPE.put(short.class.getName(), SimpleType.SHORT);
         JAVA_TYPE_TO_SIMPLE_TYPE.put(Long.class.getName(), SimpleType.LONG);
         JAVA_TYPE_TO_SIMPLE_TYPE.put(long.class.getName(), SimpleType.LONG);
         JAVA_TYPE_TO_SIMPLE_TYPE.put(String.class.getName(), SimpleType.STRING);
         JAVA_TYPE_TO_SIMPLE_TYPE.put(int.class.getName(), SimpleType.INTEGER);
         JAVA_TYPE_TO_SIMPLE_TYPE.put(Short.class.getName(), SimpleType.SHORT);
         JAVA_TYPE_TO_SIMPLE_TYPE.put(short.class.getName(), SimpleType.SHORT);
         JAVA_TYPE_TO_SIMPLE_TYPE.put(Long.class.getName(), SimpleType.LONG);
         JAVA_TYPE_TO_SIMPLE_TYPE.put(long.class.getName(), SimpleType.LONG);
         JAVA_TYPE_TO_SIMPLE_TYPE.put(String.class.getName(), SimpleType.STRING);
-        JAVA_TYPE_TO_SIMPLE_TYPE.put(Boolean.class.getName(),
-                SimpleType.BOOLEAN);
-        JAVA_TYPE_TO_SIMPLE_TYPE.put(boolean.class.getName(),
-                SimpleType.BOOLEAN);
-        JAVA_TYPE_TO_SIMPLE_TYPE.put(BigInteger.class.getName(),
-                SimpleType.BIGINTEGER);
-        JAVA_TYPE_TO_SIMPLE_TYPE.put(BigDecimal.class.getName(),
-                SimpleType.BIGDECIMAL);
+        JAVA_TYPE_TO_SIMPLE_TYPE.put(Enum.class.getName(), SimpleType.STRING);
+        JAVA_TYPE_TO_SIMPLE_TYPE.put(Boolean.class.getName(), SimpleType.BOOLEAN);
+        JAVA_TYPE_TO_SIMPLE_TYPE.put(boolean.class.getName(), SimpleType.BOOLEAN);
+        JAVA_TYPE_TO_SIMPLE_TYPE.put(BigInteger.class.getName(), SimpleType.BIGINTEGER);
+        JAVA_TYPE_TO_SIMPLE_TYPE.put(BigDecimal.class.getName(), SimpleType.BIGDECIMAL);
         JAVA_TYPE_TO_SIMPLE_TYPE.put(Byte.class.getName(), SimpleType.BYTE);
         JAVA_TYPE_TO_SIMPLE_TYPE.put(byte.class.getName(), SimpleType.BYTE);
         JAVA_TYPE_TO_SIMPLE_TYPE.put(Date.class.getName(), SimpleType.DATE);
         JAVA_TYPE_TO_SIMPLE_TYPE.put(Byte.class.getName(), SimpleType.BYTE);
         JAVA_TYPE_TO_SIMPLE_TYPE.put(byte.class.getName(), SimpleType.BYTE);
         JAVA_TYPE_TO_SIMPLE_TYPE.put(Date.class.getName(), SimpleType.DATE);
index 977aa6a87eb60c83ac1a2cb8a5a1b22e277f5c4b..df636fd0ef3297eb3f87870afa38d8cd18098cf5 100644 (file)
@@ -115,12 +115,10 @@ module config-test-impl {
                 type tt:extend-twice;
             }
 
                 type tt:extend-twice;
             }
 
-/* TODO Add support for enums
-
             leaf extended-enum {
                 type tt:extend-enum;
             }
             leaf extended-enum {
                 type tt:extend-enum;
             }
-*/
+
            container dto-c {
                 leaf simple-arg {
                     type uint32;
            container dto-c {
                 leaf simple-arg {
                     type uint32;
index eabc2b9394bb903558106b433c6c8944207b21f9..c57817edda7334aea91a09d6bd5b2ea13e6b285a 100644 (file)
@@ -150,10 +150,11 @@ public class NetconfMappingTest extends AbstractConfigTest {
         // check after edit
         commit();
         Element response = getConfigRunning();
         // check after edit
         commit();
         Element response = getConfigRunning();
-        System.err.println(XmlUtil.toString(response));
+
         checkBinaryLeafEdited(response);
         checkTypeConfigAttribute(response);
         checkTypedefs(response);
         checkBinaryLeafEdited(response);
         checkTypeConfigAttribute(response);
         checkTypedefs(response);
+        checkEnum(response);
 
         edit("netconfMessages/editConfig_remove.xml");
 
 
         edit("netconfMessages/editConfig_remove.xml");
 
@@ -385,6 +386,26 @@ public class NetconfMappingTest extends AbstractConfigTest {
         assertEquals(1, children.getLength());
     }
 
         assertEquals(1, children.getLength());
     }
 
+    private void checkEnum(final Element response) {
+        XmlElement modulesElement = XmlElement.fromDomElement(response).getOnlyChildElement("data")
+                .getOnlyChildElement("modules");
+
+        String enumName = "extended-enum";
+        String enumContent = "TWO";
+
+        for (XmlElement moduleElement : modulesElement.getChildElements("module")) {
+            String name = moduleElement.getOnlyChildElement("name").getTextContent();
+            if(name.equals("test1")) {
+                XmlElement enumAttr = moduleElement.getOnlyChildElement(enumName);
+                assertEquals(enumContent, enumAttr.getTextContent());
+
+                return;
+            }
+        }
+
+        fail("Enum attribute " + enumName + ":" + enumContent + " not present in " + XmlUtil.toString(response));
+    }
+
     private void checkTypeConfigAttribute(Element response) {
 
         XmlElement modulesElement = XmlElement.fromDomElement(response).getOnlyChildElement("data")
     private void checkTypeConfigAttribute(Element response) {
 
         XmlElement modulesElement = XmlElement.fromDomElement(response).getOnlyChildElement("data")
index ce52e49365e2749c58267b1368f37d682efd5bed..57359474acaa4c93b04e0d6181cb1c0f93c9e8c2 100644 (file)
                             1
                     </extended-twice>
 
                             1
                     </extended-twice>
 
+                    <extended-enum>
+                        TWO
+                    </extended-enum>
+
                     <simple-long-2>44</simple-long-2>
                     <binaryLeaf>8</binaryLeaf>
                     <binaryLeaf>1</binaryLeaf>
                     <simple-long-2>44</simple-long-2>
                     <binaryLeaf>8</binaryLeaf>
                     <binaryLeaf>1</binaryLeaf>