diff options
author | Dan Timoney <dt5972@att.com> | 2018-07-25 14:48:58 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-07-25 14:48:58 +0000 |
commit | c99b602cf71da724073bedb6a30f2e0659a9dbde (patch) | |
tree | b3c3636ee8a962915cb439ed4e1c0c19e6c47a32 | |
parent | 47099b56dcecba622e574b37c0167a061d6f667b (diff) | |
parent | 3c74f62d1b4892560554e52e709e87769bd26ba0 (diff) |
Merge "support legacy enumeration mapping"
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 f7a229d5..e8f73e8c 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 e7f1e18b..d5ca04d7 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 00000000..2aaaf8aa --- /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 00000000..bae0bdb1 --- /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 00000000..d0fb2971 --- /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 |