diff options
5 files changed, 33 insertions, 25 deletions
diff --git a/sli/common/pom.xml b/sli/common/pom.xml index ebb4f0953..5007bedfd 100755 --- a/sli/common/pom.xml +++ b/sli/common/pom.xml @@ -90,11 +90,6 @@ <artifactId>sal-binding-api</artifactId> </dependency> - <dependency> - <groupId>com.att.eelf</groupId> - <artifactId>eelf-core</artifactId> - </dependency> - <!-- Testing Dependencies --> <dependency> <groupId>junit</groupId> diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/MetricLogger.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/MetricLogger.java index 9d263456c..b4bd2017e 100644 --- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/MetricLogger.java +++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/MetricLogger.java @@ -300,9 +300,11 @@ public class MetricLogger { } protected String formatString(String str) { - str = str.replaceAll("\\R",""); // this will strip all new line characters - str = str.replaceAll("\\|","%7C"); //log records should not contain a pipe, encode the pipe character - return str; + if (str != null) { + str = str.replaceAll("\\R", ""); // this will strip all new line characters + str = str.replaceAll("\\|", "%7C"); // log records should not contain a pipe, encode the pipe character + } + return str; } public static void resetContext() { diff --git a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/TestMetricLogger.java b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/TestMetricLogger.java index 31a419bb1..971a700f5 100644 --- a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/TestMetricLogger.java +++ b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/TestMetricLogger.java @@ -129,7 +129,14 @@ public class TestMetricLogger { logger.asIso8601(System.currentTimeMillis()); } - - + @Test + public void formatString() { + String output = logger.formatString("\n"); + assertEquals("",output); + output = logger.formatString("|"); + assertEquals("%7C",output); + output = logger.formatString(null); + assertEquals(null,output); + } } 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")); } } |