summaryrefslogtreecommitdiffstats
path: root/lib/doorman/src/test
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2020-04-10 13:23:51 +0000
committerGerrit Code Review <gerrit@onap.org>2020-04-10 13:23:51 +0000
commit285e59c81eef63b53e4089d2b9f5f6204becae38 (patch)
tree1f12da98320d00a9836a53d2daf2e0d905daf091 /lib/doorman/src/test
parent62edf48439a0a6b59619c03280b96c1226ad77f0 (diff)
parent5a893ea54e5f8a251be4bb774a9e187ee366de6c (diff)
Merge "Addressing issues from review"
Diffstat (limited to 'lib/doorman/src/test')
-rw-r--r--lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/MessageQueueDataItem.java150
-rw-r--r--lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/MessageQueueTest.java378
-rw-r--r--lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/MessageQueueTestResult.java184
-rw-r--r--lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/tc1/Classifier.java21
-rw-r--r--lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/tc1/Handler.java4
-rw-r--r--lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/tc2/Classifier.java21
-rw-r--r--lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/tc2/Handler.java75
-rw-r--r--lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/testutil/DbUtil.java150
-rw-r--r--lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/testutil/FileUtil.java30
-rw-r--r--lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/util/TestJsonUtil.java23
10 files changed, 495 insertions, 541 deletions
diff --git a/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/MessageQueueDataItem.java b/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/MessageQueueDataItem.java
index 32e94e5d3..e14e32545 100644
--- a/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/MessageQueueDataItem.java
+++ b/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/MessageQueueDataItem.java
@@ -8,84 +8,84 @@ import org.onap.ccsdk.features.lib.doorman.data.MessageStatus;
public class MessageQueueDataItem implements Comparable<MessageQueueDataItem> {
- public Date timeStamp;
- public String extMessageId;
- public MessageStatus status;
- public MessageAction action;
+ public Date timeStamp;
+ public String extMessageId;
+ public MessageStatus status;
+ public MessageAction action;
- @Override
- public int compareTo(MessageQueueDataItem other) {
- int c = timeStamp.compareTo(other.timeStamp);
- if (c == 0) {
- if (action != null && other.status != null) {
- return -1;
- }
- if (status != null && other.action != null) {
- return 1;
- }
- }
- return c;
- }
+ @Override
+ public int compareTo(MessageQueueDataItem other) {
+ int c = timeStamp.compareTo(other.timeStamp);
+ if (c == 0) {
+ if (action != null && other.status != null) {
+ return -1;
+ }
+ if (status != null && other.action != null) {
+ return 1;
+ }
+ }
+ return c;
+ }
- @Override
- public int hashCode() {
- return System.identityHashCode(extMessageId);
- }
+ @Override
+ public int hashCode() {
+ return System.identityHashCode(extMessageId);
+ }
- @Override
- public boolean equals(Object o) {
- if (o == null || !(o instanceof MessageQueueDataItem)) {
- return false;
- }
- MessageQueueDataItem other = (MessageQueueDataItem) o;
- if (!extMessageId.equals(other.extMessageId)) {
- return false;
- }
- if (status != null && (other.status == null || status.status != other.status.status)) {
- return false;
- }
- if (action != null) {
- if (other.action == null || action.action != other.action.action) {
- return false;
- }
- if (action.action == MessageActionValue.HOLD || action.action == MessageActionValue.RETURN_HOLD) {
- if (action.holdTime != other.action.holdTime) {
- return false;
- }
- } else if (action.action == MessageActionValue.RETURN_COMPLETE) {
- if (!action.resolution.equals(other.action.resolution)) {
- return false;
- }
- }
- }
- return true;
- }
+ @Override
+ public boolean equals(Object o) {
+ if (o == null || !(o instanceof MessageQueueDataItem)) {
+ return false;
+ }
+ MessageQueueDataItem other = (MessageQueueDataItem) o;
+ if (!extMessageId.equals(other.extMessageId)) {
+ return false;
+ }
+ if (status != null && (other.status == null || status.getStatus() != other.status.getStatus())) {
+ return false;
+ }
+ if (action != null) {
+ if (other.action == null || action.getAction() != other.action.getAction()) {
+ return false;
+ }
+ if (action.getAction() == MessageActionValue.HOLD || action.getAction() == MessageActionValue.RETURN_HOLD) {
+ if (action.getHoldTime() != other.action.getHoldTime()) {
+ return false;
+ }
+ } else if (action.getAction() == MessageActionValue.RETURN_COMPLETE) {
+ if (!action.getResolution().equals(other.action.getResolution())) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
- @Override
- public String toString() {
- StringBuilder ss = new StringBuilder();
- if (timeStamp != null) {
- ss.append(df.format(timeStamp)).append(" | ");
- }
- if (status != null) {
- ss.append("STATUS: ");
- } else {
- ss.append("ACTION: ");
- }
- ss.append(String.format("%-20s | ", extMessageId));
- if (status != null) {
- ss.append(status.status);
- } else {
- ss.append(action.action);
- if (action.holdTime > 0) {
- ss.append(" | ").append(action.holdTime);
- }
- if (action.resolution != null) {
- ss.append(" | ").append(action.resolution);
- }
- }
- return ss.toString();
- }
+ @Override
+ public String toString() {
+ StringBuilder ss = new StringBuilder();
+ if (timeStamp != null) {
+ ss.append(df.format(timeStamp)).append(" | ");
+ }
+ if (status != null) {
+ ss.append("STATUS: ");
+ } else {
+ ss.append("ACTION: ");
+ }
+ ss.append(String.format("%-20s | ", extMessageId));
+ if (status != null) {
+ ss.append(status.getStatus());
+ } else {
+ ss.append(action.getAction());
+ if (action.getHoldTime() > 0) {
+ ss.append(" | ").append(action.getHoldTime());
+ }
+ if (action.getResolution() != null) {
+ ss.append(" | ").append(action.getResolution());
+ }
+ }
+ return ss.toString();
+ }
- private static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+ private static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
}
diff --git a/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/MessageQueueTest.java b/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/MessageQueueTest.java
index ca1c4910d..b2f69dbcf 100644
--- a/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/MessageQueueTest.java
+++ b/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/MessageQueueTest.java
@@ -32,191 +32,195 @@ import org.slf4j.LoggerFactory;
@RunWith(Parameterized.class)
public class MessageQueueTest {
- private static final Logger log = LoggerFactory.getLogger(MessageQueueTest.class);
-
- private String test;
-
- public MessageQueueTest(String test) {
- this.test = test;
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void test() throws Exception {
- log.info("#########################################################################");
- log.info("MessageQueueTest: " + test + " started");
-
- String testSetupJson = readResource("it/" + test + "/test.json");
- Map<String, Object> testSetup = (Map<String, Object>) JsonUtil.jsonToData(testSetupJson);
-
- Map<String, MessageQueueHandler> handlerMap = new HashMap<>();
-
- for (Object o : (List<Object>) testSetup.get("handler_list")) {
- Map<String, Object> handlerSetup = (Map<String, Object>) o;
- String queueType = (String) handlerSetup.get("queue_type");
- String handlerClassName = (String) handlerSetup.get("handler_class");
- try {
- Class<?> handlerClass = Class.forName("org.onap.ccsdk.features.lib.doorman.it." + test + "." + handlerClassName);
- MessageQueueHandler handler = (MessageQueueHandler) handlerClass.newInstance();
- handlerMap.put(queueType, handler);
- log.info("Handler found for queue type: " + queueType + ": " + handlerClass.getName());
- } catch (Exception e) {
- }
- }
-
- MessageInterceptorFactory factory = setupMessageInterceptorFactory(handlerMap, new Classifier(), new Processor());
-
- List<Object> requestList = (List<Object>) testSetup.get("request_list");
-
- List<Thread> threadList = new ArrayList<>();
-
- for (int i = 0; i < requestList.size(); i++) {
- Map<String, Object> requestSetup = (Map<String, Object>) requestList.get(i);
-
- MessageData request = new MessageData();
- request.param = (Map<String, Object>) requestSetup.get("request_param");
- Map<String, Object> requestBodyData = (Map<String, Object>) requestSetup.get("request_body");
- if (requestBodyData != null) {
- request.body = JsonUtil.dataToJson(requestBodyData);
- } else {
- request.body = readResource("it/" + test + "/" + requestSetup.get("request_body_file"));
- }
-
- MessageData response = new MessageData();
- response.param = (Map<String, Object>) requestSetup.get("response_param");
- Map<String, Object> responseBodyData = (Map<String, Object>) requestSetup.get("response_body");
- if (responseBodyData != null) {
- response.body = JsonUtil.dataToJson(responseBodyData);
- } else {
- response.body = readResource("it/" + test + "/" + requestSetup.get("response_body_file"));
- }
-
- long startTime = (Long) requestSetup.get("start_time");
- long processTime = (Long) requestSetup.get("process_time");
-
- MessageInterceptor interceptor = factory.create();
-
- Thread t = new Thread((Runnable) () -> {
- try {
- Thread.sleep(startTime);
- } catch (InterruptedException e) {
- }
-
- MessageData r = interceptor.processRequest(request);
-
- if (r == null) {
- try {
- Thread.sleep(processTime);
- } catch (InterruptedException e) {
- }
-
- interceptor.processResponse(response);
- }
-
- }, "Message-" + i);
-
- threadList.add(t);
- t.start();
- }
-
- for (Thread t : threadList) {
- t.join();
- }
-
- log.info("MessageQueueTest: " + test + " completed");
- log.info("Result:");
-
- String testResultJson = readResource("it/" + test + "/result.json");
- Map<String, Object> testResult = (Map<String, Object>) JsonUtil.jsonToData(testResultJson);
- MessageQueueTestResult.checkResult(testResult);
- }
-
- private static class Classifier implements MessageClassifier {
-
- @Override
- public Queue determineQueue(MessageData request) {
- Queue q = new Queue();
- q.type = (String) request.param.get("queue_type");
- q.id = (String) request.param.get("queue_id");
- return q;
- }
-
- @Override
- public String getExtMessageId(MessageData request) {
- return (String) request.param.get("request_id");
- }
- }
-
- private static class Processor implements MessageProcessor {
-
- @Override
- public void processMessage(MessageData request) {
- long processTime = (Long) request.param.get("process_time");
- try {
- Thread.sleep(processTime);
- } catch (InterruptedException e) {
- }
- }
- }
-
- public static MessageInterceptorFactory setupMessageInterceptorFactory(Map<String, MessageQueueHandler> handlerMap, MessageClassifier classifier, MessageProcessor processor) {
- LockHelperImpl lockHelper = new LockHelperImpl();
- lockHelper.setDataSource(DbUtil.getDataSource());
- lockHelper.setLockWait(5);
- lockHelper.setRetryCount(10);
-
- MessageDaoImpl messageDao = new MessageDaoImpl();
- messageDao.setDataSource(DbUtil.getDataSource());
-
- MessageInterceptorFactoryImpl f = new MessageInterceptorFactoryImpl();
- f.setMessageDao(messageDao);
- f.setLockHelper(lockHelper);
- f.setLockTimeout(20);
- f.setHandlerMap(handlerMap);
- f.setMessageClassifier(classifier);
- f.setMessageProcessor(processor);
- return f;
- }
-
- @Parameters(name = "{0}")
- public static Collection<Object[]> allTests() {
- List<Object[]> ll = new ArrayList<>();
-
- String[] tcList = list("it");
- for (String tc : tcList) {
- ll.add(new Object[] { tc });
- }
- return ll;
- }
-
- private static String[] list(String dir) {
- try {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- URL url = loader.getResource(dir);
- String path = url.getPath();
- return new File(path).list();
- } catch (Exception e) {
- log.warn("Error getting directory list for: " + dir + ": " + e.getMessage(), e);
- return new String[0];
- }
- }
-
- private static String readResource(String resource) {
- try {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- InputStream ins = loader.getResourceAsStream(resource);
- BufferedReader in = new BufferedReader(new InputStreamReader(ins));
- StringBuilder ss = new StringBuilder();
- String line = in.readLine();
- while (line != null) {
- ss.append(line).append('\n');
- line = in.readLine();
- }
- in.close();
- return ss.toString();
- } catch (Exception e) {
- log.warn("Error reading resource: " + resource + ": " + e.getMessage(), e);
- return null;
- }
- }
+ private static final Logger log = LoggerFactory.getLogger(MessageQueueTest.class);
+
+ private String test;
+
+ public MessageQueueTest(String test) {
+ this.test = test;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void test() throws Exception {
+ log.info("#########################################################################");
+ log.info("MessageQueueTest: " + test + " started");
+
+ String testSetupJson = readResource("it/" + test + "/test.json");
+ Map<String, Object> testSetup = (Map<String, Object>) JsonUtil.jsonToData(testSetupJson);
+
+ Map<String, MessageQueueHandler> handlerMap = new HashMap<>();
+
+ for (Object o : (List<Object>) testSetup.get("handler_list")) {
+ Map<String, Object> handlerSetup = (Map<String, Object>) o;
+ String queueType = (String) handlerSetup.get("queue_type");
+ String handlerClassName = (String) handlerSetup.get("handler_class");
+ try {
+ Class<?> handlerClass =
+ Class.forName("org.onap.ccsdk.features.lib.doorman.it." + test + "." + handlerClassName);
+ MessageQueueHandler handler = (MessageQueueHandler) handlerClass.newInstance();
+ handlerMap.put(queueType, handler);
+ log.info("Handler found for queue type: " + queueType + ": " + handlerClass.getName());
+ } catch (Exception e) {
+ }
+ }
+
+ MessageInterceptorFactory factory =
+ setupMessageInterceptorFactory(handlerMap, new Classifier(), new Processor());
+
+ List<Object> requestList = (List<Object>) testSetup.get("request_list");
+
+ List<Thread> threadList = new ArrayList<>();
+
+ for (int i = 0; i < requestList.size(); i++) {
+ Map<String, Object> requestSetup = (Map<String, Object>) requestList.get(i);
+
+ Map<String, Object> requestParam = (Map<String, Object>) requestSetup.get("request_param");
+ Map<String, Object> requestBodyData = (Map<String, Object>) requestSetup.get("request_body");
+ String requestBody = null;
+ if (requestBodyData != null) {
+ requestBody = JsonUtil.dataToJson(requestBodyData);
+ } else {
+ requestBody = readResource("it/" + test + "/" + requestSetup.get("request_body_file"));
+ }
+ MessageData request = new MessageData(requestParam, requestBody);
+
+ Map<String, Object> responseParam = (Map<String, Object>) requestSetup.get("response_param");
+ Map<String, Object> responseBodyData = (Map<String, Object>) requestSetup.get("response_body");
+ String responseBody = null;
+ if (responseBodyData != null) {
+ responseBody = JsonUtil.dataToJson(responseBodyData);
+ } else {
+ responseBody = readResource("it/" + test + "/" + requestSetup.get("response_body_file"));
+ }
+ MessageData response = new MessageData(responseParam, responseBody);
+
+ long startTime = (Long) requestSetup.get("start_time");
+ long processTime = (Long) requestSetup.get("process_time");
+
+ MessageInterceptor interceptor = factory.create();
+
+ Thread t = new Thread((Runnable) () -> {
+ try {
+ Thread.sleep(startTime);
+ } catch (InterruptedException e) {
+ }
+
+ MessageData r = interceptor.processRequest(request);
+
+ if (r == null) {
+ try {
+ Thread.sleep(processTime);
+ } catch (InterruptedException e) {
+ }
+
+ interceptor.processResponse(response);
+ }
+
+ }, "Message-" + i);
+
+ threadList.add(t);
+ t.start();
+ }
+
+ for (Thread t : threadList) {
+ t.join();
+ }
+
+ log.info("MessageQueueTest: " + test + " completed");
+ log.info("Result:");
+
+ String testResultJson = readResource("it/" + test + "/result.json");
+ Map<String, Object> testResult = (Map<String, Object>) JsonUtil.jsonToData(testResultJson);
+ MessageQueueTestResult.checkResult(testResult);
+ }
+
+ private static class Classifier implements MessageClassifier {
+
+ @Override
+ public Queue determineQueue(MessageData request) {
+ String queueType = (String) request.getParam().get("queue_type");
+ String queueId = (String) request.getParam().get("queue_id");
+ return new Queue(queueType, queueId);
+ }
+
+ @Override
+ public String getExtMessageId(MessageData request) {
+ return (String) request.getParam().get("request_id");
+ }
+ }
+
+ private static class Processor implements MessageProcessor {
+
+ @Override
+ public void processMessage(MessageData request) {
+ long processTime = (Long) request.getParam().get("process_time");
+ try {
+ Thread.sleep(processTime);
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+
+ public static MessageInterceptorFactory setupMessageInterceptorFactory(Map<String, MessageQueueHandler> handlerMap,
+ MessageClassifier classifier, MessageProcessor processor) {
+ LockHelperImpl lockHelper = new LockHelperImpl();
+ lockHelper.setDataSource(DbUtil.getDataSource());
+ lockHelper.setLockWait(5);
+ lockHelper.setRetryCount(10);
+
+ MessageDaoImpl messageDao = new MessageDaoImpl();
+ messageDao.setDataSource(DbUtil.getDataSource());
+
+ MessageInterceptorFactoryImpl f = new MessageInterceptorFactoryImpl();
+ f.setMessageDao(messageDao);
+ f.setLockHelper(lockHelper);
+ f.setLockTimeout(20);
+ f.setHandlerMap(handlerMap);
+ f.setMessageClassifier(classifier);
+ f.setMessageProcessor(processor);
+ return f;
+ }
+
+ @Parameters(name = "{0}")
+ public static Collection<Object[]> allTests() {
+ List<Object[]> ll = new ArrayList<>();
+
+ String[] tcList = list("it");
+ for (String tc : tcList) {
+ ll.add(new Object[] {tc});
+ }
+ return ll;
+ }
+
+ private static String[] list(String dir) {
+ try {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ URL url = loader.getResource(dir);
+ String path = url.getPath();
+ return new File(path).list();
+ } catch (Exception e) {
+ log.warn("Error getting directory list for: " + dir + ": " + e.getMessage(), e);
+ return new String[0];
+ }
+ }
+
+ private static String readResource(String resource) {
+ try {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ InputStream ins = loader.getResourceAsStream(resource);
+ BufferedReader in = new BufferedReader(new InputStreamReader(ins));
+ StringBuilder ss = new StringBuilder();
+ String line = in.readLine();
+ while (line != null) {
+ ss.append(line).append('\n');
+ line = in.readLine();
+ }
+ in.close();
+ return ss.toString();
+ } catch (Exception e) {
+ log.warn("Error reading resource: " + resource + ": " + e.getMessage(), e);
+ return null;
+ }
+ }
}
diff --git a/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/MessageQueueTestResult.java b/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/MessageQueueTestResult.java
index 71a2eeafb..9d297d52f 100644
--- a/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/MessageQueueTestResult.java
+++ b/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/MessageQueueTestResult.java
@@ -1,7 +1,6 @@
package org.onap.ccsdk.features.lib.doorman.it;
import static org.junit.Assert.fail;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -19,102 +18,101 @@ import org.slf4j.LoggerFactory;
public class MessageQueueTestResult {
- private static final Logger log = LoggerFactory.getLogger(MessageQueueTest.class);
+ private static final Logger log = LoggerFactory.getLogger(MessageQueueTest.class);
- public static List<MessageQueueDataItem> readResult(String queueType, String queueId) {
- MessageDaoImpl messageDao = new MessageDaoImpl();
- messageDao.setDataSource(DbUtil.getDataSource());
+ public static List<MessageQueueDataItem> readResult(String queueType, String queueId) {
+ MessageDaoImpl messageDao = new MessageDaoImpl();
+ messageDao.setDataSource(DbUtil.getDataSource());
- Queue q = new Queue();
- q.type = queueType;
- q.id = queueId;
+ Queue q = new Queue(queueType, queueId);
- List<Message> messageList = messageDao.readMessageQueue(q);
+ List<Message> messageList = messageDao.readMessageQueue(q);
- List<MessageQueueDataItem> ll = new ArrayList<>();
- if (messageList != null) {
- for (Message m : messageList) {
- if (m.statusHistory != null) {
- for (MessageStatus s : m.statusHistory) {
- MessageQueueDataItem item = new MessageQueueDataItem();
- item.extMessageId = m.extMessageId;
- item.status = s;
- item.timeStamp = s.timestamp;
- ll.add(item);
- }
- }
- if (m.actionHistory != null) {
- for (MessageAction a : m.actionHistory) {
- MessageQueueDataItem item = new MessageQueueDataItem();
- item.extMessageId = m.extMessageId;
- item.action = a;
- item.timeStamp = a.timestamp;
- ll.add(item);
- }
- }
- }
- }
- Collections.sort(ll);
- return ll;
- }
+ List<MessageQueueDataItem> ll = new ArrayList<>();
+ if (messageList != null) {
+ for (Message m : messageList) {
+ if (m.getStatusHistory() != null) {
+ for (MessageStatus s : m.getStatusHistory()) {
+ MessageQueueDataItem item = new MessageQueueDataItem();
+ item.extMessageId = m.getExtMessageId();
+ item.status = s;
+ item.timeStamp = s.getTimestamp();
+ ll.add(item);
+ }
+ }
+ if (m.getActionHistory() != null) {
+ for (MessageAction a : m.getActionHistory()) {
+ MessageQueueDataItem item = new MessageQueueDataItem();
+ item.extMessageId = m.getExtMessageId();
+ item.action = a;
+ item.timeStamp = a.getTimestamp();
+ ll.add(item);
+ }
+ }
+ }
+ }
+ Collections.sort(ll);
+ return ll;
+ }
- @SuppressWarnings("unchecked")
- public static void checkResult(Map<String, Object> testResult) {
- List<Object> resultSetupList = (List<Object>) testResult.get("queue_list");
- if (resultSetupList != null) {
- for (Object o : resultSetupList) {
- Map<String, Object> resultSetup = (Map<String, Object>) o;
- String queueType = (String) resultSetup.get("queue_type");
- String queueId = (String) resultSetup.get("queue_id");
- log.info(queueType + "::" + queueId);
- List<MessageQueueDataItem> itemList = MessageQueueTestResult.readResult(queueType, queueId);
- for (MessageQueueDataItem item : itemList) {
- log.info(" --- " + item);
- }
+ @SuppressWarnings("unchecked")
+ public static void checkResult(Map<String, Object> testResult) {
+ List<Object> resultSetupList = (List<Object>) testResult.get("queue_list");
+ if (resultSetupList != null) {
+ for (Object o : resultSetupList) {
+ Map<String, Object> resultSetup = (Map<String, Object>) o;
+ String queueType = (String) resultSetup.get("queue_type");
+ String queueId = (String) resultSetup.get("queue_id");
+ log.info(queueType + "::" + queueId);
+ List<MessageQueueDataItem> itemList = MessageQueueTestResult.readResult(queueType, queueId);
+ for (MessageQueueDataItem item : itemList) {
+ log.info(" --- " + item);
+ }
- List<Object> checkSequenceList = (List<Object>) resultSetup.get("check_sequence_list");
- for (int i = 0; i < checkSequenceList.size(); i++) {
- List<Object> checkSequence = (List<Object>) checkSequenceList.get(i);
- List<MessageQueueDataItem> checkItemList = new ArrayList<>();
- for (Object o2 : checkSequence) {
- String[] ss = ((String) o2).split("\\|");
- MessageQueueDataItem item = new MessageQueueDataItem();
- item.extMessageId = ss[1].trim();
- if (ss[0].trim().equals("STATUS")) {
- item.status = new MessageStatus();
- item.status.status = MessageStatusValue.valueOf(ss[2].trim());
- } else {
- item.action = new MessageAction();
- item.action.action = MessageActionValue.valueOf(ss[2].trim());
- if (item.action.action == MessageActionValue.HOLD || item.action.action == MessageActionValue.RETURN_HOLD) {
- item.action.holdTime = Integer.parseInt(ss[3].trim());
- } else if (item.action.action == MessageActionValue.RETURN_COMPLETE) {
- item.action.resolution = ss[3].trim();
- }
- }
- checkItemList.add(item);
- }
- List<MessageQueueDataItem> itemList1 = new ArrayList<>(itemList);
- itemList1.retainAll(checkItemList);
- if (!itemList1.equals(checkItemList)) {
- log.info("Expected sequence #" + i + " not found");
- log.info("Expected sequence:");
- for (MessageQueueDataItem item : checkItemList) {
- log.info(" --- " + item);
- }
- log.info("Found sequence:");
- for (MessageQueueDataItem item : itemList1) {
- log.info(" --- " + item);
- }
- fail("Expected sequence #" + i + " not found");
- } else {
- log.info("Expected sequence #" + i + " found in the result:");
- for (MessageQueueDataItem item : checkItemList) {
- log.info(" --- " + item);
- }
- }
- }
- }
- }
- }
+ List<Object> checkSequenceList = (List<Object>) resultSetup.get("check_sequence_list");
+ for (int i = 0; i < checkSequenceList.size(); i++) {
+ List<Object> checkSequence = (List<Object>) checkSequenceList.get(i);
+ List<MessageQueueDataItem> checkItemList = new ArrayList<>();
+ for (Object o2 : checkSequence) {
+ String[] ss = ((String) o2).split("\\|");
+ MessageQueueDataItem item = new MessageQueueDataItem();
+ item.extMessageId = ss[1].trim();
+ if (ss[0].trim().equals("STATUS")) {
+ item.status = new MessageStatus(MessageStatusValue.valueOf(ss[2].trim()));
+ } else {
+ MessageActionValue action = MessageActionValue.valueOf(ss[2].trim());
+ int holdTime = 0;
+ String resolution = null;
+ if (action == MessageActionValue.HOLD || action == MessageActionValue.RETURN_HOLD) {
+ holdTime = Integer.parseInt(ss[3].trim());
+ } else if (action == MessageActionValue.RETURN_COMPLETE) {
+ resolution = ss[3].trim();
+ }
+ item.action = new MessageAction(action, resolution, holdTime, null);
+ }
+ checkItemList.add(item);
+ }
+ List<MessageQueueDataItem> itemList1 = new ArrayList<>(itemList);
+ itemList1.retainAll(checkItemList);
+ if (!itemList1.equals(checkItemList)) {
+ log.info("Expected sequence #" + i + " not found");
+ log.info("Expected sequence:");
+ for (MessageQueueDataItem item : checkItemList) {
+ log.info(" --- " + item);
+ }
+ log.info("Found sequence:");
+ for (MessageQueueDataItem item : itemList1) {
+ log.info(" --- " + item);
+ }
+ fail("Expected sequence #" + i + " not found");
+ } else {
+ log.info("Expected sequence #" + i + " found in the result:");
+ for (MessageQueueDataItem item : checkItemList) {
+ log.info(" --- " + item);
+ }
+ }
+ }
+ }
+ }
+ }
}
diff --git a/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/tc1/Classifier.java b/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/tc1/Classifier.java
deleted file mode 100644
index 254fd4ce4..000000000
--- a/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/tc1/Classifier.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package org.onap.ccsdk.features.lib.doorman.it.tc1;
-
-import org.onap.ccsdk.features.lib.doorman.MessageClassifier;
-import org.onap.ccsdk.features.lib.doorman.data.MessageData;
-import org.onap.ccsdk.features.lib.doorman.data.Queue;
-
-public class Classifier implements MessageClassifier {
-
- @Override
- public Queue determineQueue(MessageData request) {
- Queue q = new Queue();
- q.type = "Cluster";
- q.id = "test-queue";
- return q;
- }
-
- @Override
- public String getExtMessageId(MessageData request) {
- return (String) request.param.get("request_id");
- }
-}
diff --git a/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/tc1/Handler.java b/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/tc1/Handler.java
index f57fdbc36..8ee7b6a89 100644
--- a/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/tc1/Handler.java
+++ b/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/tc1/Handler.java
@@ -4,7 +4,7 @@ import org.onap.ccsdk.features.lib.doorman.impl.MessageHandlerBaseImpl;
public class Handler extends MessageHandlerBaseImpl {
- public Handler() {
+ public Handler() {
- }
+ }
}
diff --git a/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/tc2/Classifier.java b/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/tc2/Classifier.java
deleted file mode 100644
index a32f74650..000000000
--- a/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/tc2/Classifier.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package org.onap.ccsdk.features.lib.doorman.it.tc2;
-
-import org.onap.ccsdk.features.lib.doorman.MessageClassifier;
-import org.onap.ccsdk.features.lib.doorman.data.MessageData;
-import org.onap.ccsdk.features.lib.doorman.data.Queue;
-
-public class Classifier implements MessageClassifier {
-
- @Override
- public Queue determineQueue(MessageData request) {
- Queue q = new Queue();
- q.type = "Cluster";
- q.id = "test-queue";
- return q;
- }
-
- @Override
- public String getExtMessageId(MessageData request) {
- return (String) request.param.get("request_id");
- }
-}
diff --git a/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/tc2/Handler.java b/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/tc2/Handler.java
index 35b811c5f..0be64372d 100644
--- a/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/tc2/Handler.java
+++ b/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/it/tc2/Handler.java
@@ -9,45 +9,44 @@ import org.onap.ccsdk.features.lib.doorman.util.JsonUtil;
public class Handler extends MessageHandlerBaseImpl {
- public Handler() {
- setMaxParallelCount(100);
- setUpdateWaitTime(20);
- }
+ public Handler() {
+ setMaxParallelCount(100);
+ setUpdateWaitTime(20);
+ }
- @SuppressWarnings("unchecked")
- @Override
- protected String determineUpdateGroup(Message msg) {
- if (msg.request.body != null) {
- Map<String, Object> body = (Map<String, Object>) JsonUtil.jsonToData(msg.request.body);
- String op = (String) body.get("operation");
- String entityId = (String) body.get("entity_id");
- if ("update".equals(op)) {
- return entityId;
- }
- }
- return super.determineUpdateGroup(msg);
- }
+ @SuppressWarnings("unchecked")
+ @Override
+ protected String determineUpdateGroup(Message msg) {
+ if (msg.getRequest().getBody() != null) {
+ Map<String, Object> body = (Map<String, Object>) JsonUtil.jsonToData(msg.getRequest().getBody());
+ String op = (String) body.get("operation");
+ String entityId = (String) body.get("entity_id");
+ if ("update".equals(op)) {
+ return entityId;
+ }
+ }
+ return super.determineUpdateGroup(msg);
+ }
- @Override
- protected long determineUpdateSequence(Message msg) {
- if (msg.request.param != null) {
- Long n = (Long) msg.request.param.get("sequence_number");
- if (n != null) {
- return n;
- }
- }
- return super.determineUpdateSequence(msg);
- }
+ @Override
+ protected long determineUpdateSequence(Message msg) {
+ if (msg.getRequest().getParam() != null) {
+ Long n = (Long) msg.getRequest().getParam().get("sequence_number");
+ if (n != null) {
+ return n;
+ }
+ }
+ return super.determineUpdateSequence(msg);
+ }
- @Override
- protected MessageData completeResponse(Resolution r, Message msg) {
- if (r == Resolution.SKIPPED) {
- MessageData response = new MessageData();
- response.param = new HashMap<>();
- response.param.put("http_code", 200L);
- response.body = "{ \"status\": \"success\" }";
- return response;
- }
- return super.completeResponse(r, msg);
- }
+ @Override
+ protected MessageData completeResponse(Resolution r, Message msg) {
+ if (r == Resolution.SKIPPED) {
+ Map<String, Object> param = new HashMap<>();
+ param.put("http_code", 200L);
+ String body = "{ \"status\": \"success\" }";
+ return new MessageData(param, body);
+ }
+ return super.completeResponse(r, msg);
+ }
}
diff --git a/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/testutil/DbUtil.java b/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/testutil/DbUtil.java
index 1e525b4b2..b6ce6ca03 100644
--- a/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/testutil/DbUtil.java
+++ b/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/testutil/DbUtil.java
@@ -6,87 +6,83 @@ import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
-
import javax.sql.DataSource;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DbUtil {
- private static final Logger log = LoggerFactory.getLogger(DbUtil.class);
-
- private static DataSource dataSource = null;
-
- public static synchronized DataSource getDataSource() {
- if (dataSource == null) {
- String url = "jdbc:h2:mem:app;DB_CLOSE_DELAY=-1";
-
- dataSource = new DataSource() {
-
- @Override
- public <T> T unwrap(Class<T> arg0) throws SQLException {
- return null;
- }
-
- @Override
- public boolean isWrapperFor(Class<?> arg0) throws SQLException {
- return false;
- }
-
- @Override
- public void setLoginTimeout(int arg0) throws SQLException {
- }
-
- @Override
- public void setLogWriter(PrintWriter arg0) throws SQLException {
- }
-
- @Override
- public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException {
- return null;
- }
-
- @Override
- public int getLoginTimeout() throws SQLException {
- return 0;
- }
-
- @Override
- public PrintWriter getLogWriter() throws SQLException {
- return null;
- }
-
- @Override
- public Connection getConnection(String username, String password) throws SQLException {
- return null;
- }
-
- @Override
- public Connection getConnection() throws SQLException {
- return DriverManager.getConnection(url);
- }
- };
-
- try {
- String script = FileUtil.read("/schema.sql");
-
- String[] sqlList = script.split(";");
- try (Connection con = dataSource.getConnection()) {
- for (String sql : sqlList) {
- if (!sql.trim().isEmpty()) {
- sql = sql.trim();
- try (PreparedStatement ps = con.prepareStatement(sql)) {
- log.info("Executing statement:\n" + sql);
- ps.execute();
- }
- }
- }
- }
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- return dataSource;
- }
+ private static final Logger log = LoggerFactory.getLogger(DbUtil.class);
+
+ private static DataSource dataSource = null;
+
+ public static synchronized DataSource getDataSource() {
+ if (dataSource == null) {
+ String url = "jdbc:h2:mem:app;DB_CLOSE_DELAY=-1";
+
+ dataSource = new DataSource() {
+
+ @Override
+ public <T> T unwrap(Class<T> arg0) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public boolean isWrapperFor(Class<?> arg0) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public void setLoginTimeout(int arg0) throws SQLException {}
+
+ @Override
+ public void setLogWriter(PrintWriter arg0) throws SQLException {}
+
+ @Override
+ public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException {
+ return null;
+ }
+
+ @Override
+ public int getLoginTimeout() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public PrintWriter getLogWriter() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Connection getConnection(String username, String password) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Connection getConnection() throws SQLException {
+ return DriverManager.getConnection(url);
+ }
+ };
+
+ try {
+ String script = FileUtil.read("/schema.sql");
+
+ String[] sqlList = script.split(";");
+ try (Connection con = dataSource.getConnection()) {
+ for (String sql : sqlList) {
+ if (!sql.trim().isEmpty()) {
+ sql = sql.trim();
+ try (PreparedStatement ps = con.prepareStatement(sql)) {
+ log.info("Executing statement:\n" + sql);
+ ps.execute();
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return dataSource;
+ }
}
diff --git a/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/testutil/FileUtil.java b/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/testutil/FileUtil.java
index 5ae92b4fc..4958fe376 100644
--- a/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/testutil/FileUtil.java
+++ b/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/testutil/FileUtil.java
@@ -6,19 +6,19 @@ import java.io.InputStreamReader;
public class FileUtil {
- public static String read(String fileName) throws Exception {
- String ss = "";
- try (InputStream is = DbUtil.class.getResourceAsStream(fileName)) {
- try (InputStreamReader isr = new InputStreamReader(is)) {
- try (BufferedReader in = new BufferedReader(isr)) {
- String s = in.readLine();
- while (s != null) {
- ss += s + '\n';
- s = in.readLine();
- }
- }
- }
- }
- return ss;
- }
+ public static String read(String fileName) throws Exception {
+ String ss = "";
+ try (InputStream is = DbUtil.class.getResourceAsStream(fileName)) {
+ try (InputStreamReader isr = new InputStreamReader(is)) {
+ try (BufferedReader in = new BufferedReader(isr)) {
+ String s = in.readLine();
+ while (s != null) {
+ ss += s + '\n';
+ s = in.readLine();
+ }
+ }
+ }
+ }
+ return ss;
+ }
}
diff --git a/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/util/TestJsonUtil.java b/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/util/TestJsonUtil.java
index f0ac87e24..7d4bd9456 100644
--- a/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/util/TestJsonUtil.java
+++ b/lib/doorman/src/test/java/org/onap/ccsdk/features/lib/doorman/util/TestJsonUtil.java
@@ -1,7 +1,6 @@
package org.onap.ccsdk.features.lib.doorman.util;
import java.util.Map;
-
import org.junit.Assert;
import org.junit.Test;
import org.onap.ccsdk.features.lib.doorman.testutil.FileUtil;
@@ -11,16 +10,16 @@ import org.slf4j.LoggerFactory;
public class TestJsonUtil {
- private static final Logger log = LoggerFactory.getLogger(TestJsonUtil.class);
+ private static final Logger log = LoggerFactory.getLogger(TestJsonUtil.class);
- @SuppressWarnings("unchecked")
- @Test
- public void testJsonConversion() throws Exception {
- String json1 = FileUtil.read("/test1.json");
- Map<String, Object> data1 = (Map<String, Object>) JsonUtil.jsonToData(json1);
- String convJson1 = JsonUtil.dataToJson(data1);
- log.info("Converted JSON:\n" + convJson1);
- Map<String, Object> convData1 = (Map<String, Object>) JsonUtil.jsonToData(convJson1);
- Assert.assertEquals(data1, convData1);
- }
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testJsonConversion() throws Exception {
+ String json1 = FileUtil.read("/test1.json");
+ Map<String, Object> data1 = (Map<String, Object>) JsonUtil.jsonToData(json1);
+ String convJson1 = JsonUtil.dataToJson(data1);
+ log.info("Converted JSON:\n" + convJson1);
+ Map<String, Object> convData1 = (Map<String, Object>) JsonUtil.jsonToData(convJson1);
+ Assert.assertEquals(data1, convData1);
+ }
}