diff options
author | Smokowski, Kevin (ks6305) <ks6305@att.com> | 2018-08-01 18:04:04 +0000 |
---|---|---|
committer | Smokowski, Kevin (ks6305) <ks6305@att.com> | 2018-08-01 18:04:42 +0000 |
commit | de9fb16753eefa333dc3e44330062621b17b2ac2 (patch) | |
tree | 657c8770540154ad85f22034325d7264ce34a4ac | |
parent | c99b602cf71da724073bedb6a30f2e0659a9dbde (diff) |
remove static bool
Don't use static boolean for legacy enumeration mapping, add additional parameter to the function
Change-Id: I5d8963a208f3ffdd3af83216aa55f7d34ee39eb9
Issue-ID: CCSDK-396
Signed-off-by: Smokowski, Kevin (ks6305) <ks6305@att.com>
-rw-r--r-- | sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java | 27 | ||||
-rw-r--r-- | sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelperTest.java | 7 |
2 files changed, 19 insertions, 15 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 e8f73e8c3..f87b7d3c3 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,11 +50,6 @@ 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) { @@ -88,25 +83,37 @@ public class MdsalHelper { } public static Properties toProperties(Properties props, Object fromObj) { + return toProperties(props, fromObj, false); + } + + public static Properties toProperties(Properties props, Object fromObj, Boolean useLegacyEnumerationMapping) { Class fromClass = null; if (fromObj != null) { fromClass = fromObj.getClass(); } - return toProperties(props, "", fromObj, fromClass); + return toProperties(props, "", fromObj, fromClass,useLegacyEnumerationMapping ); } public static Properties toProperties(Properties props, String pfx, Object fromObj) { + return toProperties(props, pfx, fromObj, false); + } + + public static Properties toProperties(Properties props, String pfx, Object fromObj, Boolean useLegacyEnumerationMapping) { Class fromClass = null; if (fromObj != null) { fromClass = fromObj.getClass(); } - return toProperties(props, pfx, fromObj, fromClass); + return toProperties(props, pfx, fromObj, fromClass, useLegacyEnumerationMapping); } public static Properties toProperties(Properties props, String pfx, Object fromObj, Class fromClass) { + return toProperties(props, pfx, fromObj, fromClass, false); + } + + public static Properties toProperties(Properties props, String pfx, Object fromObj, Class fromClass, Boolean useLegacyEnumerationMapping) { if (fromObj == null) { return props; @@ -121,7 +128,7 @@ public class MdsalHelper { List fromList = (List) fromObj; for (int i = 0; i < fromList.size(); i++) { - toProperties(props, pfx + "[" + i + "]", fromList.get(i), fromClass); + toProperties(props, pfx + "[" + i + "]", fromList.get(i), fromClass, useLegacyEnumerationMapping); } props.setProperty(pfx + "_length", Integer.toString(fromList.size())); @@ -365,7 +372,7 @@ public class MdsalHelper { m.setAccessible(isAccessible); } if (retValue != null) { - toProperties(props, propNamePfx + "." + fieldName, retValue, returnType); + toProperties(props, propNamePfx + "." + fieldName, retValue, returnType, useLegacyEnumerationMapping); } } catch (Exception e) { @@ -398,7 +405,7 @@ public class MdsalHelper { // this array. Type paramType = m.getGenericReturnType(); Type elementType = ((ParameterizedType) paramType).getActualTypeArguments()[0]; - toProperties(props, propNamePfx + "." + fieldName, retList, (Class) elementType); + toProperties(props, propNamePfx + "." + fieldName, retList, (Class) elementType, useLegacyEnumerationMapping); } catch (Exception e) { LOG.error("Caught exception trying to convert List returned by " + fromClass.getName() + "." + m.getName() + "() to Properties entry", e); 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 d5ca04d75..307c69c7d 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 @@ -147,7 +147,6 @@ public class MdsalHelperTest extends TestCase { // 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")); @@ -156,9 +155,8 @@ public class MdsalHelperTest extends TestCase { // 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()); + MdsalHelper.toProperties(props, new WrapperObj(), true); assertEquals("_4COS", props.getProperty("wrapper-obj.cos-model-type")); } @@ -166,9 +164,8 @@ public class MdsalHelperTest extends TestCase { // 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()); + MdsalHelper.toProperties(props, new WrapperObj(), true); assertEquals("HelloWorld", props.getProperty("wrapper-obj.cos-model-type")); } } |