summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java19
-rw-r--r--sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelperTest.java30
-rw-r--r--sli/provider/src/test/java/org/opendaylight/yang/gen/v1/test/CosModelType.java51
-rw-r--r--sli/provider/src/test/java/org/opendaylight/yang/gen/v1/test/WrapperObj.java10
-rw-r--r--sli/provider/src/test/resources/EnumerationMapping.properties1
5 files changed, 107 insertions, 4 deletions
diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java
index e50b99742..10478ddd1 100644
--- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java
+++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java
@@ -50,7 +50,12 @@ public class MdsalHelper {
private static final Logger LOG = LoggerFactory.getLogger(MdsalHelper.class);
private static Properties yangMappingProperties = new Properties();
-
+ protected static boolean useLegacyEnumerationMapping = false;
+
+ public static void useLegacyEnumerationMapping(Boolean bool) {
+ useLegacyEnumerationMapping = bool;
+ }
+
@Deprecated
public static void setProperties(Properties input) {
setYangMappingProperties(input);
@@ -188,9 +193,15 @@ public class MdsalHelper {
}
if (retValue != null) {
String propName = propNamePfx + "." + fieldName;
- Method method = retValue.getClass().getMethod("getName");
- String yangValue = (String) method.invoke(retValue);
- props.setProperty(propName, yangValue);
+ if(useLegacyEnumerationMapping) {
+ propVal = retValue.toString();
+ props.setProperty(propName, mapEnumeratedValue(fieldName, propVal));
+ }else {
+ Method method = retValue.getClass().getMethod("getName");
+ String yangValue = (String) method.invoke(retValue);
+ props.setProperty(propName, yangValue);
+ }
+
}
} catch (Exception e) {
LOG.error(
diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelperTest.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelperTest.java
index e7f1e18b9..d5ca04d75 100644
--- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelperTest.java
+++ b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelperTest.java
@@ -36,6 +36,8 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;
import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.ExecuteGraphInputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.execute.graph.input.SliParameter;
import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.execute.graph.input.SliParameterBuilder;
+import org.opendaylight.yang.gen.v1.test.CosModelType;
+import org.opendaylight.yang.gen.v1.test.WrapperObj;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddressBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -141,4 +143,32 @@ public class MdsalHelperTest extends TestCase {
assertEquals("SomethingElse",MdsalHelper.toJavaEnum("Something.Else"));
assertEquals("MyTestString",MdsalHelper.toJavaEnum("my-test-string"));
}
+
+ // During the default enumeration mapping no properties file is needed, the yang value is returned
+ // by the java object
+ public void testDefaultEnumerationMapping() throws Exception {
+ MdsalHelper.useLegacyEnumerationMapping(false);
+ Properties props = new Properties();
+ MdsalHelper.toProperties(props, new WrapperObj());
+ assertEquals("4COS", props.getProperty("wrapper-obj.cos-model-type"));
+ }
+
+ // When no properties file exists the default java value will be returned if legacy enumeration
+ // mapping is enabled
+ public void testLegacyEnumerationMappingNoProperties() throws Exception {
+ MdsalHelper.useLegacyEnumerationMapping(true);
+ Properties props = new Properties();
+ MdsalHelper.toProperties(props, new WrapperObj());
+ assertEquals("_4COS", props.getProperty("wrapper-obj.cos-model-type"));
+ }
+
+ // When a properties file exists & legacy enumeration mapping is enabled the value from the
+ // properties file should be returned
+ public void testLegacyEnumerationMappingWithProperties() throws Exception {
+ MdsalHelper.loadProperties("src/test/resources/EnumerationMapping.properties");
+ MdsalHelper.useLegacyEnumerationMapping(true);
+ Properties props = new Properties();
+ MdsalHelper.toProperties(props, new WrapperObj());
+ assertEquals("HelloWorld", props.getProperty("wrapper-obj.cos-model-type"));
+ }
}
diff --git a/sli/provider/src/test/java/org/opendaylight/yang/gen/v1/test/CosModelType.java b/sli/provider/src/test/java/org/opendaylight/yang/gen/v1/test/CosModelType.java
new file mode 100644
index 000000000..2aaaf8aa3
--- /dev/null
+++ b/sli/provider/src/test/java/org/opendaylight/yang/gen/v1/test/CosModelType.java
@@ -0,0 +1,51 @@
+package org.opendaylight.yang.gen.v1.test;
+
+public enum CosModelType {
+ _4COS(0, "4COS"),
+
+ _6COS(1, "6COS")
+ ;
+
+ private static final java.util.Map<java.lang.Integer, CosModelType> VALUE_MAP;
+
+ static {
+ final com.google.common.collect.ImmutableMap.Builder<java.lang.Integer, CosModelType> b = com.google.common.collect.ImmutableMap.builder();
+ for (CosModelType enumItem : CosModelType.values()) {
+ b.put(enumItem.value, enumItem);
+ }
+
+ VALUE_MAP = b.build();
+ }
+
+ private final java.lang.String name;
+ private final int value;
+
+ private CosModelType(int value, java.lang.String name) {
+ this.value = value;
+ this.name = name;
+ }
+
+ /**
+ * Returns the name of the enumeration item as it is specified in the input yang.
+ *
+ * @return the name of the enumeration item as it is specified in the input yang
+ */
+ public java.lang.String getName() {
+ return name;
+ }
+
+ /**
+ * @return integer value
+ */
+ public int getIntValue() {
+ return value;
+ }
+
+ /**
+ * @param valueArg integer value
+ * @return corresponding CosModelType item
+ */
+ public static CosModelType forValue(int valueArg) {
+ return VALUE_MAP.get(valueArg);
+ }
+} \ No newline at end of file
diff --git a/sli/provider/src/test/java/org/opendaylight/yang/gen/v1/test/WrapperObj.java b/sli/provider/src/test/java/org/opendaylight/yang/gen/v1/test/WrapperObj.java
new file mode 100644
index 000000000..bae0bdb1c
--- /dev/null
+++ b/sli/provider/src/test/java/org/opendaylight/yang/gen/v1/test/WrapperObj.java
@@ -0,0 +1,10 @@
+package org.opendaylight.yang.gen.v1.test;
+
+public class WrapperObj {
+
+ CosModelType cosModel = CosModelType._4COS;
+
+ public CosModelType getCosModelType() {
+ return cosModel;
+ }
+}
diff --git a/sli/provider/src/test/resources/EnumerationMapping.properties b/sli/provider/src/test/resources/EnumerationMapping.properties
new file mode 100644
index 000000000..d0fb29710
--- /dev/null
+++ b/sli/provider/src/test/resources/EnumerationMapping.properties
@@ -0,0 +1 @@
+yang.cos-model-type._4COS=HelloWorld \ No newline at end of file