From 00a00a68862effd791ce3f127d0ddd5903598b89 Mon Sep 17 00:00:00 2001 From: Pooja03 Date: Wed, 28 Mar 2018 18:28:37 +0530 Subject: Added UniversalVesAdapter TestCases in the Mapper Adding remaining UniversalVesAdapter TestCases in Mapper Change-Id: Ic49bbbe2b4c4e242b1e91edfe565c7918e4b24e5 Issue-ID: DCAEGEN2-335 Signed-off-by: Pooja03 --- .../utils/MapperConfigUtils.java | 36 ++++++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'UniversalVesAdapter/src/main/java/org/onap/universalvesadapter') diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/MapperConfigUtils.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/MapperConfigUtils.java index e94cdf5..4e67ed6 100644 --- a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/MapperConfigUtils.java +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/MapperConfigUtils.java @@ -237,7 +237,7 @@ public class MapperConfigUtils { } if (null != evaluation.getOperand()) { - if (EnumUtils.isValidEnum(JoinOperator.class, evaluation.getOperand())) { + if (MapperConfigUtils.isValidEnum(JoinOperator.class, evaluation.getOperand())) { // if(JOIN_OPERATOR.contains(evaluation.getOperand())){ switch (JoinOperator.valueOf(evaluation.getOperand())) { case AND: @@ -251,7 +251,7 @@ public class MapperConfigUtils { } } - if (EnumUtils.isValidEnum(ExpressionOperator.class, evaluation.getOperand())) { + if (MapperConfigUtils.isValidEnum(ExpressionOperator.class, evaluation.getOperand())) { // if(EXPR_OPERATOR.contains(evaluation.getOperand())){ // currently it is assumed field being compared is first level @@ -261,7 +261,7 @@ public class MapperConfigUtils { if (null != field && null != evaluation.getDatatype() && actualObj.has(field)) { switch (ExpressionOperator.valueOf(evaluation.getOperand())) { case EQUALS: - if (EnumUtils.isValidEnum(DataType.class, evaluation.getDatatype())) { + if (MapperConfigUtils.isValidEnum(DataType.class, evaluation.getDatatype())) { switch (DataType.valueOf(evaluation.getDatatype())) { case STRING: if (null != actualObj.get(field)) @@ -276,7 +276,7 @@ public class MapperConfigUtils { } else return false; case STARTSWITH: - if (EnumUtils.isValidEnum(DataType.class, evaluation.getDatatype())) { + if (MapperConfigUtils.isValidEnum(DataType.class, evaluation.getDatatype())) { switch (DataType.valueOf(evaluation.getDatatype())) { case STRING: if (null != actualObj.get(field)) @@ -287,7 +287,7 @@ public class MapperConfigUtils { } else return false; case ENDSWITH: - if (EnumUtils.isValidEnum(DataType.class, evaluation.getDatatype())) { + if (MapperConfigUtils.isValidEnum(DataType.class, evaluation.getDatatype())) { switch (DataType.valueOf(evaluation.getDatatype())) { case STRING: if (null != actualObj.get(field)) @@ -298,7 +298,7 @@ public class MapperConfigUtils { } else return false; case CONTAINS: - if (EnumUtils.isValidEnum(DataType.class, evaluation.getDatatype())) { + if (MapperConfigUtils.isValidEnum(DataType.class, evaluation.getDatatype())) { switch (DataType.valueOf(evaluation.getDatatype())) { case STRING: if (null != actualObj.get(field)) @@ -318,5 +318,29 @@ public class MapperConfigUtils { return false; } + /** + *

Checks if the specified name is a valid enum for the class.

+ * + *

This method differs from {@link Enum#valueOf} in that checks if the name is + * a valid enum without needing to catch the exception.

+ * + * @param the type of the enumeration + * @param enumClass the class of the enum to query, not null + * @param enumName the enum name, null returns false + * @return true if the enum name is valid, otherwise false + */ + + public static > boolean isValidEnum(final Class enumClass, final String enumName) { + if (enumName == null) { + return false; + } + try { + Enum.valueOf(enumClass, enumName); + return true; + } catch (final IllegalArgumentException ex) { + return false; + } + } + } -- cgit 1.2.3-korg