Merge "Add support for enums as configuration attributes in config and netconf subsys...
authorEd Warnicke <eaw@cisco.com>
Fri, 29 Nov 2013 11:18:20 +0000 (11:18 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 29 Nov 2013 11:18:20 +0000 (11:18 +0000)
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();
+        } else if (isEnum(baseType)) {
+            return getSimpleType(baseType);
         } 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;
     }
 
index 61ad74d7eebfdfe47e6c59e4844a4d18bbe2af70..87b55f3756a0e042c98c89739d91bf0f92ab5285 100644 (file)
@@ -39,26 +39,21 @@ public class SimpleTypeResolver {
         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
-        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(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);
index 977aa6a87eb60c83ac1a2cb8a5a1b22e277f5c4b..df636fd0ef3297eb3f87870afa38d8cd18098cf5 100644 (file)
@@ -115,12 +115,10 @@ module config-test-impl {
                 type tt:extend-twice;
             }
 
-/* TODO Add support for enums
-
             leaf extended-enum {
                 type tt:extend-enum;
             }
-*/
+
            container dto-c {
                 leaf simple-arg {
                     type uint32;
index 80b903b219216ca16aa6be122e9e4d2e6e899982..73d39c616221403737d5cfe7f52315b043fc19d5 100644 (file)
@@ -132,10 +132,11 @@ public class NetconfMappingTest extends AbstractConfigTest {
         // check after edit
         commit();
         Element response = getConfigRunning();
-        System.err.println(XmlUtil.toString(response));
+
         checkBinaryLeafEdited(response);
         checkTypeConfigAttribute(response);
         checkTypedefs(response);
+        checkEnum(response);
 
         edit("netconfMessages/editConfig_remove.xml");
 
@@ -367,6 +368,26 @@ public class NetconfMappingTest extends AbstractConfigTest {
         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")
index d44652bf13949a19386d38c73d8edec5e2d7b4cd..2233b41a850d34e0bcd15937d5e56ae1d158280e 100644 (file)
                             1
                     </extended-twice>
 
+                    <extended-enum>
+                        TWO
+                    </extended-enum>
+
                     <simple-long-2>44</simple-long-2>
                     <binaryLeaf>8</binaryLeaf>
                     <binaryLeaf>1</binaryLeaf>