aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLusheng Ji <lji@research.att.com>2017-09-21 23:15:18 +0000
committerGerrit Code Review <gerrit@onap.org>2017-09-21 23:15:18 +0000
commit93e76d24e2722d5eb6ec836c279c0a7377b71578 (patch)
tree26ed5ee7b07f0cd2ae7e33e42489f723609641e2
parentb97b0aff982b3125d423102323537ebe23e859f0 (diff)
parent89e739fc9227bedf591fdd11517a4c8077e3a386 (diff)
Merge "junit addon for ves"
-rw-r--r--src/main/java/org/onap/dcae/commonFunction/CommonStartup.java2
-rw-r--r--src/main/java/org/onap/dcae/commonFunction/CustomExceptionLoader.java159
-rw-r--r--src/main/java/org/onap/dcae/commonFunction/DmaapPropertyReader.java16
-rw-r--r--src/main/java/org/onap/dcae/controller/LoadDynamicConfig.java9
-rw-r--r--src/main/java/org/onap/dcae/restapi/RestfulCollectorServlet.java213
-rw-r--r--src/test/java/org/onap/dcae/vestest/TestCommonStartup.java148
-rw-r--r--src/test/java/org/onap/dcae/vestest/TestLoadDynamicConfig.java4
-rw-r--r--src/test/java/org/onap/dcae/vestest/TestSchemaValidation.java117
8 files changed, 431 insertions, 237 deletions
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<JSONObject> fProcessingInputQueue;
+ public static LinkedBlockingQueue<JSONObject> 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<String, JsonArray> map;
- private static final Logger log = LoggerFactory.getLogger(CustomExceptionLoader.class);
-
+ protected static HashMap<String, JsonArray> 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<String, JsonArray>();
+ 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<String, JsonElement> 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<String, JsonArray>();
- 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<String, JsonElement> 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<String, String> dmaap_hash = new HashMap<String, String>();
@@ -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("\"", ""));
}
}
diff --git a/src/main/java/org/onap/dcae/controller/LoadDynamicConfig.java b/src/main/java/org/onap/dcae/controller/LoadDynamicConfig.java
index 7134f3c2..a28bca86 100644
--- a/src/main/java/org/onap/dcae/controller/LoadDynamicConfig.java
+++ b/src/main/java/org/onap/dcae/controller/LoadDynamicConfig.java
@@ -39,8 +39,8 @@ public class LoadDynamicConfig {
private static final Logger log = LoggerFactory.getLogger(LoadDynamicConfig.class);
- public static String propFile = "collector.properties";
- public static String configFile = "/opt/app/KV-Configuration.json";
+ public String propFile = "collector.properties";
+ public String configFile = "/opt/app/KV-Configuration.json";
static String url;
static String retString;
@@ -60,11 +60,12 @@ public class LoadDynamicConfig {
try {
- String jsonData = readFile(configFile);
+ LoadDynamicConfig lc = new LoadDynamicConfig();
+ String jsonData = readFile(lc.configFile);
JSONObject jsonObject = new JSONObject(jsonData);
PropertiesConfiguration conf;
- conf = new PropertiesConfiguration(propFile);
+ conf = new PropertiesConfiguration(lc.propFile);
conf.setEncoding(null);
// update properties based on consul dynamic configuration
diff --git a/src/main/java/org/onap/dcae/restapi/RestfulCollectorServlet.java b/src/main/java/org/onap/dcae/restapi/RestfulCollectorServlet.java
index babb184b..fee9ce1c 100644
--- a/src/main/java/org/onap/dcae/restapi/RestfulCollectorServlet.java
+++ b/src/main/java/org/onap/dcae/restapi/RestfulCollectorServlet.java
@@ -21,6 +21,17 @@
package org.onap.dcae.restapi;
+import java.io.IOException;
+import java.net.URL;
+
+import javax.servlet.ServletException;
+
+import org.apache.tomcat.util.codec.binary.Base64;
+import org.onap.dcae.commonFunction.CommonStartup;
+import org.onap.dcae.commonFunction.VESLogger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import com.att.nsa.apiServer.CommonServlet;
import com.att.nsa.configs.ConfigDbException;
import com.att.nsa.drumlin.service.framework.DrumlinErrorHandler;
@@ -32,97 +43,119 @@ import com.att.nsa.drumlin.till.nv.rrNvReadable;
import com.att.nsa.drumlin.till.nv.rrNvReadable.loadException;
import com.att.nsa.drumlin.till.nv.rrNvReadable.missingReqdSetting;
import com.att.nsa.security.NsaAuthenticator;
+
import com.att.nsa.security.authenticators.SimpleAuthenticator;
import com.att.nsa.security.db.simple.NsaSimpleApiKey;
-import org.apache.tomcat.util.codec.binary.Base64;
-import org.onap.dcae.commonFunction.CommonStartup;
-import org.onap.dcae.commonFunction.VESLogger;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import java.io.IOException;
-import java.net.URL;
-import javax.servlet.ServletException;
-
-public class RestfulCollectorServlet extends CommonServlet {
-
- String authid;
- String authpwd;
- String authlist;
-
- public RestfulCollectorServlet(rrNvReadable settings) throws loadException, missingReqdSetting {
- super(settings, "collector", false);
- authid = settings.getString(CommonStartup.kSetting_authid, null);
- if (authid != null) {
- String authpwdtemp = settings.getString(CommonStartup.kSetting_authpwd, null);
- authpwd = new String(Base64.decodeBase64(authpwdtemp));
- }
- authlist = settings.getString(CommonStartup.kSetting_authlist, null);
- }
-
-
- /**
- * This is called once at server start. Use it to init any shared objects and setup the route mapping.
- */
- @Override
- protected void servletSetup()
- throws rrNvReadable.missingReqdSetting, rrNvReadable.invalidSettingValue, ServletException {
- super.servletSetup();
-
- try {
- // the base class provides a bunch of things like API authentication and ECOMP compliant
- // logging. The Restful Collector likely doesn't need API authentication, so for now,
- // we init the base class services with an in-memory (and empty!) config DB.
- commonServletSetup(ConfigDbType.MEMORY);
-
- VESLogger.setUpEcompLogging();
-
- // setup the servlet routing and error handling
- final DrumlinRequestRouter drr = getRequestRouter();
-
- // you can tell the request router what to do when a particular kind of exception is thrown.
- drr.setHandlerForException(IllegalArgumentException.class, new DrumlinErrorHandler() {
- @Override
- public void handle(DrumlinRequestContext ctx, Throwable cause) {
- sendJsonReply(ctx, HttpStatusCodes.k400_badRequest, cause.getMessage());
- }
- });
-
- // load the routes from the config file
- final URL routes = findStream("routes.conf");
- if (routes == null) {
- throw new rrNvReadable.missingReqdSetting("No routing configuration.");
- }
- final DrumlinPlayishRoutingFileSource drs = new DrumlinPlayishRoutingFileSource(routes);
- drr.addRouteSource(drs);
-
- if (CommonStartup.authflag > 0) {
- NsaAuthenticator<NsaSimpleApiKey> nsaAuth = new SimpleAuthenticator();
- if (authlist != null) {
- String[] authpair = authlist.split("\\|");
- for (String pair : authpair) {
- String[] lineid = pair.split(",");
- String listauthid = lineid[0];
- String listauthpwd = new String(Base64.decodeBase64(lineid[1]));
- ((SimpleAuthenticator) nsaAuth).add(listauthid, listauthpwd);
- }
-
- } else if (authid != null) {
- ((SimpleAuthenticator) nsaAuth).add(authid, authpwd);
- } else {
- //add a default test account
- ((SimpleAuthenticator) nsaAuth).add("admin", "collectorpasscode");
- }
- this.getSecurityManager().addAuthenticator(nsaAuth);
- }
-
- log.info("Restful Collector Servlet is up.");
- } catch (SecurityException | IOException | ConfigDbException e) {
- throw new ServletException(e);
- }
- }
-
-
- private static final long serialVersionUID = 1L;
- private static final Logger log = LoggerFactory.getLogger(RestfulCollectorServlet.class);
+public class RestfulCollectorServlet extends CommonServlet
+{
+ String authid;
+ String authpwd;
+ public String authlist;
+
+ public RestfulCollectorServlet ( rrNvReadable settings ) throws loadException, missingReqdSetting
+ {
+ super ( settings, "collector", false );
+ authid = settings.getString(CommonStartup.kSetting_authid,null);
+ if (authid != null)
+ {
+ String authpwdtemp = settings.getString(CommonStartup.kSetting_authpwd,null);
+ authpwd = new String(Base64.decodeBase64(authpwdtemp));
+ }
+ authlist = settings.getString(CommonStartup.kSetting_authlist,null);
+ }
+
+
+
+
+ /**
+ * This is called once at server start. Use it to init any shared objects and setup the route mapping.
+ */
+ @Override
+ protected void servletSetup () throws rrNvReadable.missingReqdSetting, rrNvReadable.invalidSettingValue, ServletException
+ {
+ super.servletSetup ();
+
+ try
+ {
+ // the base class provides a bunch of things like API authentication and ECOMP compliant
+ // logging. The Restful Collector likely doesn't need API authentication, so for now,
+ // we init the base class services with an in-memory (and empty!) config DB.
+ commonServletSetup ( ConfigDbType.MEMORY );
+
+ VESLogger.setUpEcompLogging();
+
+ // setup the servlet routing and error handling
+ final DrumlinRequestRouter drr = getRequestRouter ();
+
+ // you can tell the request router what to do when a particular kind of exception is thrown.
+ drr.setHandlerForException( IllegalArgumentException.class, new DrumlinErrorHandler()
+ {
+ @Override
+ public void handle ( DrumlinRequestContext ctx, Throwable cause )
+ {
+ sendJsonReply ( ctx, HttpStatusCodes.k400_badRequest, cause.getMessage() );
+ }
+ });
+
+ // load the routes from the config file
+ final URL routes = findStream ( "routes.conf" );
+ if ( routes == null ) throw new rrNvReadable.missingReqdSetting ( "No routing configuration." );
+ final DrumlinPlayishRoutingFileSource drs = new DrumlinPlayishRoutingFileSource ( routes );
+ drr.addRouteSource ( drs );
+
+ if (CommonStartup.authflag > 0) {
+ NsaAuthenticator<NsaSimpleApiKey> NsaAuth;
+ NsaAuth = AuthlistHandler(authlist);
+
+ this.getSecurityManager().addAuthenticator(NsaAuth);
+ }
+
+ log.info ( "Restful Collector Servlet is up." );
+ }
+ catch ( SecurityException e )
+ {
+ throw new ServletException ( e );
+ }
+ catch ( IOException e )
+ {
+ throw new ServletException ( e );
+ }
+ catch ( ConfigDbException e )
+ {
+ throw new ServletException ( e );
+ }
+ }
+
+ public NsaAuthenticator<NsaSimpleApiKey> AuthlistHandler (String authlist)
+ {
+ NsaAuthenticator<NsaSimpleApiKey> NsaAuth = new SimpleAuthenticator ();
+ if (authlist != null)
+ {
+ String authpair[] = authlist.split("\\|");
+ for (String pair: authpair) {
+ String lineid[] = pair.split(",");
+ String listauthid = lineid[0];
+ String listauthpwd = new String(Base64.decodeBase64(lineid[1]));
+ ((SimpleAuthenticator) NsaAuth).add(listauthid,listauthpwd);
+ }
+
+ }
+ else if (authid != null)
+ {
+ ((SimpleAuthenticator) NsaAuth).add(authid,authpwd);
+ }
+ else
+ {
+ //add a default test account
+ ((SimpleAuthenticator) NsaAuth).add("admin","collectorpasscode");
+ }
+ return NsaAuth;
+
+ }
+
+
+ private static final long serialVersionUID = 1L;
+ private static final Logger log = LoggerFactory.getLogger ( RestfulCollectorServlet.class );
}
+
diff --git a/src/test/java/org/onap/dcae/vestest/TestCommonStartup.java b/src/test/java/org/onap/dcae/vestest/TestCommonStartup.java
index 486789d0..06f70183 100644
--- a/src/test/java/org/onap/dcae/vestest/TestCommonStartup.java
+++ b/src/test/java/org/onap/dcae/vestest/TestCommonStartup.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,54 +19,152 @@
*/
package org.onap.dcae.vestest;
+import java.io.FileReader;
+import java.io.IOException;
import java.net.URL;
import java.util.Map;
+import java.util.concurrent.LinkedBlockingQueue;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.onap.dcae.commonFunction.CommonStartup;
+import org.onap.dcae.commonFunction.EventProcessor;
+import org.onap.dcae.commonFunction.CommonStartup.QueueFullException;
+import org.onap.dcae.restapi.RestfulCollectorServlet;
import com.att.nsa.cmdLine.NsaCommandLineUtil;
import com.att.nsa.drumlin.service.framework.DrumlinServlet;
import com.att.nsa.drumlin.till.nv.rrNvReadable.loadException;
+import com.att.nsa.drumlin.till.nv.rrNvReadable.missingReqdSetting;
+import com.att.nsa.security.NsaAuthenticator;
+import com.att.nsa.security.authenticators.SimpleAuthenticator;
+import com.att.nsa.security.db.simple.NsaSimpleApiKey;
+import com.google.gson.JsonParser;
import com.att.nsa.drumlin.till.nv.impl.nvPropertiesFile;
import com.att.nsa.drumlin.till.nv.impl.nvReadableStack;
import com.att.nsa.drumlin.till.nv.impl.nvReadableTable;
public class TestCommonStartup {
- @Before
- public void setUp() throws Exception {
+ String payload = null;
+ @Before
+ public void setUp() throws Exception {
- // process command line arguments
+ // process command line arguments
+ payload = new JsonParser().parse(new FileReader("src/test/resources/VES_valid.txt")).toString();
+ CommonStartup.fProcessingInputQueue = new LinkedBlockingQueue<JSONObject> (CommonStartup.kDefault_MaxQueuedEvents);
+ }
- }
+ @After
+ public void tearDown() throws Exception {
- @After
- public void tearDown() throws Exception {
+ }
- }
+ @Test
+ public void testCommonStartupload() {
- @Test
- public void testCommonStartupload() {
+ String args[] = { "junittest" };
+ final Map<String, String> argMap = NsaCommandLineUtil.processCmdLine(args, true);
+ final String config = NsaCommandLineUtil.getSetting(argMap, "c", "collector.properties");
+ final URL settingStream = DrumlinServlet.findStream(config, CommonStartup.class);
- String args[] = { "junittest" };
- final Map<String, String> argMap = NsaCommandLineUtil.processCmdLine(args, true);
- final String config = NsaCommandLineUtil.getSetting(argMap, "c", "collector.properties");
- final URL settingStream = DrumlinServlet.findStream(config, CommonStartup.class);
+ final nvReadableStack settings = new nvReadableStack();
+ try {
+ settings.push(new nvPropertiesFile(settingStream));
+ } catch (loadException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ settings.push(new nvReadableTable(argMap));
+ Assert.assertEquals("true", "true");
+ }
- final nvReadableStack settings = new nvReadableStack();
- try {
- settings.push(new nvPropertiesFile(settingStream));
- } catch (loadException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- settings.push(new nvReadableTable(argMap));
- Assert.assertEquals("true", "true");
- }
+ @Test
+ public void testhandleevent() {
+ JSONArray jsonArrayMod = new JSONArray().put(new JSONObject(payload));
+ try {
+
+ CommonStartup.handleEvents (jsonArrayMod);
+ } catch ( JSONException | QueueFullException | IOException e) {
+ // TODO Auto-generated catch block
+ //e.printStackTrace();
+ System.out.println("junit reported:" + e.getMessage());
+ }
+ Assert.assertEquals("true", "true");
+ }
+
+
+/*
+ @Test
+ public void testServlet() {
+ try
+ {
+ RestfulCollectorServlet rsv = new RestfulCollectorServlet(null);
+ }
+ catch (NullPointerException|loadException| missingReqdSetting e){
+ System.out.println("junit reported:" + e.getMessage());
+ }
+ Assert.assertEquals("true", "true");
+ }
+*/
+
+
+ @Test
+ public void testEventProcessorinstantiation()
+ {
+ CommonStartup.streamid="fault=sec_fault|syslog=sec_syslog|heartbeat=sec_heartbeat|measurementsForVfScaling=sec_measurement|mobileFlow=sec_mobileflow|other=sec_other|stateChange=sec_statechange|thresholdCrossingAlert=sec_thresholdCrossingAlert|voiceQuality=ves_voicequality|sipSignaling=ves_sipsignaling";
+ EventProcessor ep = new EventProcessor ();
+ Thread epThread=new Thread(ep);
+ epThread.start();
+ Assert.assertEquals("true", "true");
+ epThread.stop();
+
+ }
+
+ @Test
+ public void testAuthListHandler()
+ {
+
+ final Map<String, String> argMap = NsaCommandLineUtil.processCmdLine ( new String[0], true );
+ final String config = NsaCommandLineUtil.getSetting ( argMap, "c", "collector.properties" );
+ final URL settingStream = DrumlinServlet.findStream ( config, CommonStartup.class );
+
+ final nvReadableStack settings = new nvReadableStack ();
+ try {
+ settings.push ( new nvPropertiesFile ( settingStream ) );
+ settings.push ( new nvReadableTable ( argMap ) );
+ } catch (loadException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
+
+ RestfulCollectorServlet rsv = null;
+ NsaAuthenticator<NsaSimpleApiKey> NsaAuth = null;
+ Boolean flag = false;
+ try
+ {
+ rsv = new RestfulCollectorServlet(settings);
+ }
+ catch (NullPointerException|loadException| missingReqdSetting e){
+ System.out.println("junit reported:" + e.getMessage());
+ }
+ String authlist = "secureid,IWRjYWVSb2FkbTEyMyEt|sample1,c2FtcGxlMQ==|vdnsagg,dmRuc2FnZw==";
+ NsaAuth = rsv.AuthlistHandler(authlist);
+ if (NsaAuth != null)
+ {
+ flag = true;
+ }
+ Assert.assertEquals(true, flag);
+
+
+ }
}
+
diff --git a/src/test/java/org/onap/dcae/vestest/TestLoadDynamicConfig.java b/src/test/java/org/onap/dcae/vestest/TestLoadDynamicConfig.java
index 9a50ea0c..902add73 100644
--- a/src/test/java/org/onap/dcae/vestest/TestLoadDynamicConfig.java
+++ b/src/test/java/org/onap/dcae/vestest/TestLoadDynamicConfig.java
@@ -45,8 +45,6 @@ public class TestLoadDynamicConfig {
public void setUp() throws Exception {
- LoadDynamicConfig.propFile = "src/test/resources/testcollector.properties";
- LoadDynamicConfig.configFile = "src/test/resources/controller-config.json";
}
@@ -62,6 +60,8 @@ public class TestLoadDynamicConfig {
Boolean flag=false;
lc = new LoadDynamicConfig();
+ lc.propFile = "src/test/resources/testcollector.properties";
+ lc.configFile = "src/test/resources/controller-config.json";
String data = LoadDynamicConfig.readFile(propop);
assertEquals(data.isEmpty(), flag);
diff --git a/src/test/java/org/onap/dcae/vestest/TestSchemaValidation.java b/src/test/java/org/onap/dcae/vestest/TestSchemaValidation.java
index fabcc6d2..a34b3336 100644
--- a/src/test/java/org/onap/dcae/vestest/TestSchemaValidation.java
+++ b/src/test/java/org/onap/dcae/vestest/TestSchemaValidation.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,10 +21,18 @@ package org.onap.dcae.vestest;
import static org.junit.Assert.*;
+import java.io.ByteArrayInputStream;
+import java.io.FileNotFoundException;
import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
import java.net.URL;
+import java.nio.charset.StandardCharsets;
import java.util.Map;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import org.json.simple.JSONObject;
import org.junit.After;
@@ -32,44 +40,97 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.onap.dcae.commonFunction.CommonStartup;
+import org.onap.dcae.restapi.endpoints.EventReceipt;
+import com.att.nsa.drumlin.service.framework.DrumlinServlet;
+import com.att.nsa.drumlin.service.framework.context.DrumlinRequestContext;
import com.google.gson.JsonParser;
public class TestSchemaValidation {
- CommonStartup cl;
- String schema = null;
- String payload = null;
- String payloadinvalid = null;
+ CommonStartup cl;
+ String schema = null;
+ String payload = null;
+ String payloadinvalid = null;
+
+ @Before
+ public void setUp() throws Exception {
+
+ schema = new JsonParser().parse(new FileReader("etc/CommonEventFormat_27.2.json")).toString();
+ payload = new JsonParser().parse(new FileReader("src/test/resources/VES_valid.txt")).toString();
+ payloadinvalid = new JsonParser().parse(new FileReader("src/test/resources/VES_invalid.txt")).toString();
+
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testsuccessfulschemavalidation() {
+
+ String valresult = CommonStartup.schemavalidate(payload, schema);
+ System.out.println("testsuccessfulschemavalidation:" + valresult);
+ Assert.assertEquals(valresult, "true");
+ }
+
+ @Test
+ public void testunsuccessfulschemavalidation() {
+ String valresult = null;
+ valresult = CommonStartup.schemavalidate(payloadinvalid, schema);
+ System.out.println("testunsuccessfulschemavalidation:" + valresult);
+ Assert.assertFalse(valresult.equals("true"));
+
+ }
+
+
+ @Test
+ public void testeventReceipt() {
+
+ //com.att.nsa.drumlin.service.framework.context.DrumlinRequestContext.DrumlinRequestContext(DrumlinServlet webServlet,
+ //HttpServletRequest req, HttpServletResponse resp, DrumlinConnection s, Map<String, Object> objects, DrumlinRequestRouter router)
+ //HttpServletRequest req = new HttpServletRequest();
+ //HttpServletResponse res = new HttpServletResponse();
+ DrumlinServlet webServlet = new DrumlinServlet();
+ //webServlet.addToBaseContext(key, o);
+ //Map<String,Object> mp = new Map<String, Object>();
+ DrumlinRequestContext ctx = new DrumlinRequestContext(webServlet, null, null, null, null, null);
+ EventReceipt er= new EventReceipt();
+ try {
+ EventReceipt.receiveVESEvent(null);
+ } catch ( NullPointerException e) {
+ // TODO Auto-generated catch block
+
+ }
+
+
+ Assert.assertEquals("true", "true");
- @Before
- public void setUp() throws Exception {
+ }
- schema = new JsonParser().parse(new FileReader("etc/CommonEventFormat_27.2.json")).toString();
- payload = new JsonParser().parse(new FileReader("src/test/resources/VES_valid.txt")).toString();
- payloadinvalid = new JsonParser().parse(new FileReader("src/test/resources/VES_invalid.txt")).toString();
+ @Test
+ public void testsafeclosefr() {
- }
- @After
- public void tearDown() throws Exception {
- }
+ FileReader fr;
+ try {
+ fr = new FileReader("etc/CommonEventFormat_27.2.json");
+ EventReceipt.safeClose(fr);
+ } catch (FileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ Assert.assertEquals("true", "true");
- @Test
- public void testsuccessfulschemavalidation() {
+ }
- String valresult = CommonStartup.schemavalidate(payload, schema);
- System.out.println("testsuccessfulschemavalidation:" + valresult);
- Assert.assertEquals(valresult, "true");
- }
+ @Test
+ public void testsafecloseis() {
- @Test
- public void testunsuccessfulschemavalidation() {
- String valresult = null;
- valresult = CommonStartup.schemavalidate(payloadinvalid, schema);
- System.out.println("testunsuccessfulschemavalidation:" + valresult);
- Assert.assertFalse(valresult.equals("true"));
+ InputStream is = new ByteArrayInputStream(StandardCharsets.UTF_16.encode("randomstring").array());
+ EventReceipt.safeClose(is);
+ Assert.assertEquals("true", "true");
- }
+ }
}