Add support for BigDecimal to netconf mapping. 04/3404/1
authorMaros Marsalek <mmarsale@cisco.com>
Tue, 3 Dec 2013 15:37:43 +0000 (16:37 +0100)
committerMaros Marsalek <mmarsale@cisco.com>
Tue, 3 Dec 2013 15:37:43 +0000 (16:37 +0100)
Change-Id: Iffc1d679105899f0b66a5b62020dfedd17931b45
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
opendaylight/config/yang-test/src/main/yang/config-test-impl.yang
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/resolving/SimpleAttributeResolvingStrategy.java
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 df636fd0ef3297eb3f87870afa38d8cd18098cf5..ba5021ea099361fd5d548e318a6448811020177f 100644 (file)
@@ -119,6 +119,12 @@ module config-test-impl {
                 type tt:extend-enum;
             }
 
+            leaf sleep-factor {
+                type decimal64 {
+                    fraction-digits 2;
+                }
+            }
+
            container dto-c {
                 leaf simple-arg {
                     type uint32;
index 3b881579f1b4547ecdebbd287387a9b2b3f68aee..e1b8ecf17ee50c1a4895d73301025faabd5f88e6 100644 (file)
@@ -16,6 +16,7 @@ import org.slf4j.LoggerFactory;
 
 import javax.management.openmbean.SimpleType;
 import java.lang.reflect.Method;
+import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.util.Date;
 import java.util.Map;
@@ -65,6 +66,7 @@ final class SimpleAttributeResolvingStrategy extends AbstractAttributeResolvingS
         resolverPlugins.put(Date.class.getCanonicalName(), new DateResolver());
         resolverPlugins.put(Character.class.getCanonicalName(), new CharResolver());
         resolverPlugins.put(BigInteger.class.getCanonicalName(), new BigIntegerResolver());
+        resolverPlugins.put(BigDecimal.class.getCanonicalName(), new BigDecimalResolver());
     }
 
     static interface Resolver {
@@ -106,6 +108,14 @@ final class SimpleAttributeResolvingStrategy extends AbstractAttributeResolvingS
         }
     }
 
+    static class BigDecimalResolver extends DefaultResolver {
+
+        @Override
+        protected Object parseObject(Class<?> type, String value) throws Exception {
+            return new BigDecimal(value);
+        }
+    }
+
     static class CharResolver extends DefaultResolver {
 
         @Override
index 73d39c616221403737d5cfe7f52315b043fc19d5..d91e38db33bf9206c96c18ba178dbfaa2ef115d7 100644 (file)
@@ -137,6 +137,7 @@ public class NetconfMappingTest extends AbstractConfigTest {
         checkTypeConfigAttribute(response);
         checkTypedefs(response);
         checkEnum(response);
+        checkBigDecimal(response);
 
         edit("netconfMessages/editConfig_remove.xml");
 
@@ -162,6 +163,11 @@ public class NetconfMappingTest extends AbstractConfigTest {
         verifyNoMoreInteractions(netconfOperationRouter);
     }
 
+    private void checkBigDecimal(Element response) {
+        int size = response.getElementsByTagName("sleep-factor").getLength();
+        assertEquals(1, size);
+    }
+
     private void closeSession() throws NetconfDocumentedException, ParserConfigurationException, SAXException,
             IOException {
         DefaultCloseSession closeOp = new DefaultCloseSession(NETCONF_SESSION_ID);
index 2233b41a850d34e0bcd15937d5e56ae1d158280e..caa0094c4b2b31a1259df17b536ebdb84d89a8b6 100644 (file)
 
                     <name>test1</name>
 
+                    <sleep-factor>
+                        2.00
+                    </sleep-factor>
+
                     <extended>
                             1
                     </extended>