From 89e739fc9227bedf591fdd11517a4c8077e3a386 Mon Sep 17 00:00:00 2001 From: Vijay Date: Thu, 21 Sep 2017 22:37:28 +0000 Subject: junit addon for ves Issue-ID:DCAEGEN2-82 Change-Id: Ic1ddd426545b3ccce331ec753dd6dbb7077babc9 Signed-off-by: Vijay --- .../onap/dcae/commonFunction/CommonStartup.java | 2 +- .../dcae/commonFunction/CustomExceptionLoader.java | 159 +++++++++++---------- .../dcae/commonFunction/DmaapPropertyReader.java | 16 +-- 3 files changed, 89 insertions(+), 88 deletions(-) (limited to 'src/main/java/org/onap/dcae/commonFunction') diff --git a/src/main/java/org/onap/dcae/commonFunction/CommonStartup.java b/src/main/java/org/onap/dcae/commonFunction/CommonStartup.java index 4bcfaab5..878aaa43 100644 --- a/src/main/java/org/onap/dcae/commonFunction/CommonStartup.java +++ b/src/main/java/org/onap/dcae/commonFunction/CommonStartup.java @@ -335,7 +335,7 @@ public class CommonStartup extends NsaBaseEndpoint implements Runnable { return result; } - static LinkedBlockingQueue fProcessingInputQueue; + public static LinkedBlockingQueue fProcessingInputQueue; private static ApiServer fTomcatServer = null; private static final Logger log = LoggerFactory.getLogger(CommonStartup.class); diff --git a/src/main/java/org/onap/dcae/commonFunction/CustomExceptionLoader.java b/src/main/java/org/onap/dcae/commonFunction/CustomExceptionLoader.java index 0ed39710..c6666d63 100644 --- a/src/main/java/org/onap/dcae/commonFunction/CustomExceptionLoader.java +++ b/src/main/java/org/onap/dcae/commonFunction/CustomExceptionLoader.java @@ -20,31 +20,33 @@ package org.onap.dcae.commonFunction; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.HashMap; + +import java.util.Map.Entry; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonIOException; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map.Entry; public class CustomExceptionLoader { - public static HashMap map; - private static final Logger log = LoggerFactory.getLogger(CustomExceptionLoader.class); - + protected static HashMap map = null; + private static final Logger log = LoggerFactory.getLogger ( CustomExceptionLoader.class ); + //For standalone test //LoadMap Invoked from servletSetup /* - public static void main(String[] args) { + public static void main(String[] args) { System.out.println("CustomExceptionLoader.main --> Arguments -- ExceptionConfig file: " + args[0] + "StatusCode:" + args[1]+ " Error Msg:" + args[2]); CommonStartup.exceptionConfig = args[0]; @@ -60,73 +62,72 @@ public class CustomExceptionLoader { } */ + + public static void LoadMap () { + + map = new HashMap(); + FileReader fr = null; + try { + JsonElement root = null; + fr = new FileReader(CommonStartup.exceptionConfig); + root = new JsonParser().parse(fr); + JsonObject jsonObject = root.getAsJsonObject().get("code").getAsJsonObject(); + + for (Entry entry : jsonObject.entrySet()) { + map.put(entry.getKey(), (JsonArray) entry.getValue()); + } + + log.debug("CustomExceptionLoader.LoadMap --> Map loaded - " + map); + } catch (JsonIOException e) { + e.printStackTrace(); + } catch (JsonSyntaxException e) { + e.printStackTrace(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + finally { + if (fr != null) { + try { + fr.close(); + } catch (IOException e) { + log.error("Error closing file reader stream : " +e.toString()); + } + } + } + } - public static void LoadMap() { - - map = new HashMap(); - FileReader fr = null; - try { - JsonElement root = null; - fr = new FileReader(CommonStartup.exceptionConfig); - root = new JsonParser().parse(fr); - JsonObject jsonObject = root.getAsJsonObject().get("code").getAsJsonObject(); - - for (Entry entry : jsonObject.entrySet()) { - map.put(entry.getKey(), (JsonArray) entry.getValue()); - } - - log.debug("CustomExceptionLoader.LoadMap --> Map loaded - " + map); - fr.close(); - } catch (JsonIOException e) { - log.error("json IO exception occured " + e.getLocalizedMessage(), e); - } catch (JsonSyntaxException e) { - log.error("JsonSyntaxException occured " + e.getLocalizedMessage(), e); - } catch (FileNotFoundException e) { - log.error("FileNotFoundException occured " + e.getLocalizedMessage(), e); - } catch (Exception e) { - log.error("exception occured " + e.getLocalizedMessage(), e); - } finally { - if (fr != null) { - try { - fr.close(); - } catch (IOException e) { - log.error("Error closing file reader stream : " + e.getLocalizedMessage(), e); - } - } - } - } - - public static String[] LookupMap(String error, String errorMsg) { - - String[] retarray = null; - - log.debug("CustomExceptionLoader.LookupMap -->" + " HTTP StatusCode:" + error + " Msg:" - + errorMsg); - try { - - JsonArray jarray = map.get(error); - for (int i = 0; i < jarray.size(); i++) { - - JsonElement val = jarray.get(i).getAsJsonObject().get("Reason"); - JsonArray ec = (JsonArray) jarray.get(i).getAsJsonObject().get("ErrorCode"); - log.trace("CustomExceptionLoader.LookupMap Parameter -> Error msg : " + errorMsg - + " Reason text being matched:" + val); - if (errorMsg.contains(val.toString().replace("\"", ""))) { - log.trace( - "CustomExceptionLoader.LookupMap Successful! Exception matched to error message StatusCode:" - + ec.get(0) + "ErrorMessage:" + ec.get(1)); - retarray = new String[2]; - retarray[0] = ec.get(0).toString(); - retarray[1] = ec.get(1).toString(); - return retarray; - } - } - - } catch (Exception e) { - System.out.println(e.getMessage()); - } - - return retarray; - } + public static String[] LookupMap (String error, String errormsg) { + + String[] retarray = null; + + log.debug("CustomExceptionLoader.LookupMap -->" + " HTTP StatusCode:" + error + " Msg:" + errormsg); + try{ + + JsonArray jarray = map.get(error); + for (int i = 0; i < jarray.size(); i++) { + + JsonElement val = jarray.get(i).getAsJsonObject().get("Reason"); + JsonArray ec = (JsonArray) jarray.get(i).getAsJsonObject().get("ErrorCode"); + log.trace("CustomExceptionLoader.LookupMap Parameter -> Error msg : " + errormsg + " Reason text being matched:" + val); + if (errormsg.contains(val.toString().replace("\"", ""))){ + log.trace("CustomExceptionLoader.LookupMap Successful! Exception matched to error message StatusCode:" + ec.get(0).toString() + "ErrorMessage:" + ec.get(1).toString()); + retarray = new String[2]; + retarray[0]=ec.get(0).toString(); + retarray[1]=ec.get(1).toString(); + return retarray; + } + } + + } + catch (Exception e) + { + System.out.println(e.getMessage()); + } + + return retarray; + } } + diff --git a/src/main/java/org/onap/dcae/commonFunction/DmaapPropertyReader.java b/src/main/java/org/onap/dcae/commonFunction/DmaapPropertyReader.java index 971d61ab..cb4e3af6 100644 --- a/src/main/java/org/onap/dcae/commonFunction/DmaapPropertyReader.java +++ b/src/main/java/org/onap/dcae/commonFunction/DmaapPropertyReader.java @@ -46,8 +46,8 @@ public class DmaapPropertyReader { private static final String CAMBRIA_HOSTS = "cambria.hosts"; private static final String USER = " USER:"; private static final String PWD = " PWD:"; - private static final String BASIC_AUTH_PASSWORD = "basicAuthPassword"; - private static final String BASIC_AUTH_USERNAME = "basicAuthUsername"; + private static final String BA_PWD = "basicAuthPassword"; + private static final String BA_UNAME = "basicAuthUsername"; public HashMap dmaap_hash = new HashMap(); @@ -68,8 +68,8 @@ public class DmaapPropertyReader { jsonObject.get(i).getAsJsonObject().get("cambria.topic"), HOST_URL, jsonObject.get(i).getAsJsonObject().get(CAMBRIA_URL), jsonObject.get(i).getAsJsonObject().get(CAMBRIA_HOSTS), PWD, - jsonObject.get(i).getAsJsonObject().get(BASIC_AUTH_PASSWORD), USER, - jsonObject.get(i).getAsJsonObject().get(BASIC_AUTH_USERNAME), + jsonObject.get(i).getAsJsonObject().get(BA_PWD), USER, + jsonObject.get(i).getAsJsonObject().get(BA_UNAME), jsonObject.get(i).getAsJsonObject().get("name"))); String convertedname = jsonObject.get(i).getAsJsonObject().get("name") @@ -88,15 +88,15 @@ public class DmaapPropertyReader { jsonObject.get(i).getAsJsonObject().get(CAMBRIA_URL).toString() .replace("\"", "")); } - if (jsonObject.get(i).getAsJsonObject().get(BASIC_AUTH_PASSWORD) != null) { + if (jsonObject.get(i).getAsJsonObject().get(BA_PWD) != null) { dmaap_hash.put(convertedname + ".basicAuthPassword", jsonObject.get(i).getAsJsonObject() - .get(BASIC_AUTH_PASSWORD).toString().replace("\"", "")); + .get(BA_PWD).toString().replace("\"", "")); } - if (jsonObject.get(i).getAsJsonObject().get(BASIC_AUTH_USERNAME) != null) { + if (jsonObject.get(i).getAsJsonObject().get(BA_UNAME) != null) { dmaap_hash.put(convertedname + ".basicAuthUsername", jsonObject.get(i).getAsJsonObject() - .get(BASIC_AUTH_USERNAME).toString().replace("\"", "")); + .get(BA_UNAME).toString().replace("\"", "")); } } -- cgit 1.2.3-korg