summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/common/src/test/java
diff options
context:
space:
mode:
authorMichael Dürre <michael.duerre@highstreet-technologies.com>2020-09-03 10:58:59 +0200
committerMichael Dürre <michael.duerre@highstreet-technologies.com>2020-09-03 10:59:11 +0200
commita452cd75ddae953c881e507ee9223961387e9355 (patch)
treec386204f67a14642e75d3caa3060bf1c1892b7d8 /sdnr/wt/common/src/test/java
parent4756715c82c0d71f934d47620031893bc92a1344 (diff)
update common
fixed unit tests and clean up some code Issue-ID: CCSDK-2725 Signed-off-by: Michael Dürre <michael.duerre@highstreet-technologies.com> Change-Id: I3624b3c69bbfb17ea6e28f26d96e2f77107721d4
Diffstat (limited to 'sdnr/wt/common/src/test/java')
-rw-r--r--sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestConfig.java6
-rw-r--r--sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbQueries.java218
-rw-r--r--sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestJsonAssert.java4
-rw-r--r--sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestPomfile.java17
-rw-r--r--sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestPortstatus.java3
-rw-r--r--sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/helper/HelpServlet.java5
-rw-r--r--sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/helper/HelpServletBase.java2
7 files changed, 181 insertions, 74 deletions
diff --git a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestConfig.java b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestConfig.java
index cbe0b9c4d..7f1dc962c 100644
--- a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestConfig.java
+++ b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestConfig.java
@@ -25,13 +25,11 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
-
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -53,6 +51,8 @@ public class TestConfig {
private static final int TESTVALUE1 = 123;
private static final int TESTVALUE1_2 = 1234;
private static final boolean TESTVALUE2 = true;
+ private static final String TESTCOMMENT1 = "my comment for this value";
+ private static final String TESTCOMMENT1_2 = "my comment line 2 for this value";
private static final String TESTVALUE3 = "http://localhost:2223";
private static final String TESTVALUE4 = "httasdasdas";
private static final String TESTCONTENT1 = " [test]\n" + TESTKEY1 + "=" + TESTVALUE1 + "\n" + "#her a comment\n"
@@ -102,6 +102,8 @@ public class TestConfig {
Section section = confiuration.addSection(SECTIONNAME);
section.setProperty(TESTKEY1, String.valueOf(TESTVALUE1));
+ section.addComment(TESTKEY1, TESTCOMMENT1);
+ section.addComment(TESTKEY1, TESTCOMMENT1_2);
section.setProperty(TESTKEY2, String.valueOf(TESTVALUE2));
section.setProperty(TESTKEY3, String.valueOf(TESTVALUE3));
confiuration.save();
diff --git a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbQueries.java b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbQueries.java
index 127908c08..b2e5e857f 100644
--- a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbQueries.java
+++ b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbQueries.java
@@ -30,76 +30,194 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.queries.BoolQueryBuilder;
import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilder;
import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders;
import org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder;
-import org.onap.ccsdk.features.sdnr.wt.common.test.JSONAssert;
public class TestDbQueries {
+ // @formatter:off
private static final String MATCH_ALL_QUERY =
- "{\n" + " \"query\": {\n" + " \"match_all\" : {\n" + " }\n" + " }\n" + "}";
+ "{\n"
+ + " \"query\": {\n"
+ + " \"match_all\" : {\n"
+ + " }\n"
+ + " }\n"
+ + "}";
private static final String MATCH_QUERY_KEY = "is-required";
private static final Object MATCH_QUERY_VALUE = true;
- private static final String MATCH_QUERY = "{\n" + " \"query\": {\n" + " \"match\" : {\n"
- + " \"" + MATCH_QUERY_KEY + "\" : " + MATCH_QUERY_VALUE + "\n" + " }\n" + " }\n" + "}";
+ private static final String MATCH_QUERY = "{\n"
+ + " \"query\": {\n"
+ + " \"match\" : {\n"
+ + " \""
+ + MATCH_QUERY_KEY + "\" : "
+ + MATCH_QUERY_VALUE + "\n"
+ + " }\n"
+ + " }\n"
+ + "}";
private static final String MATCH_QUERY_KEY2 = "node-id";
private static final Object MATCH_QUERY_VALUE2 = "sim2";
private static final String BOOL_QUERY_MUST =
- "{\n" + " \"query\": {\n" + " \"bool\": {\n" + " \"must\": [\n" + " {\n"
- + " \"match\": {\n" + " \"" + MATCH_QUERY_KEY + "\": "
- + MATCH_QUERY_VALUE + "\n" + " }\n" + " },\n"
- + " {\n" + " \"match\": {\n" + " \""
- + MATCH_QUERY_KEY2 + "\":" + MATCH_QUERY_VALUE2 + " \n" + " }\n"
- + " }\n" + " ]\n" + " }\n" + " }\n" + "}";
- private static final String BOOL_QUERY_MUST_SINGLE = "{\n" + " \"query\": {\n" + " \"bool\": {\n"
- + " \"must\": {\n" + " \"match\": {\n" + " \""
- + MATCH_QUERY_KEY + "\": " + MATCH_QUERY_VALUE + "\n" + " }\n" + " }\n"
- + " }\n" + " }\n" + "}";
- private static final String BOOL_QUERY_SHOULD = "{\n" + " \"query\": {\n" + " \"bool\": {\n"
- + " \"should\": [\n" + " {\n" + " \"match\": {\n"
- + " \"" + MATCH_QUERY_KEY + "\": " + MATCH_QUERY_VALUE + "\n"
- + " }\n" + " },\n" + " {\n"
- + " \"match\": {\n" + " \"" + MATCH_QUERY_KEY2 + "\":"
- + MATCH_QUERY_VALUE2 + " \n" + " }\n" + " }\n" + " ]\n"
- + " }\n" + " }\n" + "}";
- private static final String BOOL_QUERY_SHOULD_SINGLE = "{\n" + " \"query\": {\n" + " \"bool\": {\n"
- + " \"should\": {\n" + " \"match\": {\n" + " \""
- + MATCH_QUERY_KEY + "\": " + MATCH_QUERY_VALUE + "\n" + " }\n" + " }\n"
- + " }\n" + " }\n" + "}";
+ "{\n"
+ + " \"query\": {\n"
+ + " \"bool\": {\n"
+ + " \"must\": [\n"
+ + " {\n"
+ + " \"match\": {\n"
+ + " \""
+ + MATCH_QUERY_KEY + "\": "
+ + MATCH_QUERY_VALUE + "\n"
+ + " }\n"
+ + " },\n"
+ + " {\n"
+ + " \"match\": {\n"
+ + " \""
+ + MATCH_QUERY_KEY2 + "\":"
+ + MATCH_QUERY_VALUE2 + " \n"
+ + " }\n"
+ + " }\n"
+ + " ]\n"
+ + " }\n"
+ + " }\n"
+ + "}";
+ private static final String BOOL_QUERY_MUST_SINGLE = "{\n"
+ + " \"query\": {\n"
+ + " \"bool\": {\n"
+ + " \"must\": {\n"
+ + " \"match\": {\n"
+ + " \""
+ + MATCH_QUERY_KEY + "\": "
+ + MATCH_QUERY_VALUE + "\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + "}";
+ private static final String BOOL_QUERY_SHOULD = "{\n"
+ + " \"query\": {\n"
+ + " \"bool\": {\n"
+ + " \"should\": [\n"
+ + " {\n"
+ + " \"match\": {\n"
+ + " \""
+ + MATCH_QUERY_KEY + "\": "
+ + MATCH_QUERY_VALUE + "\n"
+ + " }\n"
+ + " },\n"
+ + " {\n"
+ + " \"match\": {\n"
+ + " \""
+ + MATCH_QUERY_KEY2 + "\":"
+ + MATCH_QUERY_VALUE2 + " \n"
+ + " }\n"
+ + " }\n"
+ + " ]\n"
+ + " }\n"
+ + " }\n"
+ + "}";
+ private static final String BOOL_QUERY_SHOULD_SINGLE = "{\n"
+ + " \"query\": {\n"
+ + " \"bool\": {\n"
+ + " \"should\": {\n"
+ + " \"match\": {\n"
+ + " \""
+ + MATCH_QUERY_KEY + "\": "
+ + MATCH_QUERY_VALUE + "\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + "}";
private static final String RANGE_QUERY_KEY = "timestamp";
private static final String RANGE_QUERY_LTEND = "2017-08-10T20:00:00.0Z";
- private static final String RANGE_QUERY = "{\n" + " \"query\": {\n" + " \"range\" : {\n"
- + " \"" + RANGE_QUERY_KEY + "\" : {\n" + " \"lte\" : \"" + RANGE_QUERY_LTEND
- + "\",\n" + " \"boost\": 2.0\n" + " }\n" + " }\n" + " }\n" + "}";
- private static final String RANGEBOOL_QUERY = "{\n" + " \"query\": {\n" + " \"bool\": {\n"
- + " \"must\": [\n" + " {\n" + " \"match\": {\n"
- + " \"is-required\": true\n" + " }\n" + " },\n"
- + " {\n" + " \"regexp\": {\n" + " \"node-id\": {\n"
+ private static final String RANGE_QUERY = "{\n"
+ + " \"query\": {\n"
+ + " \"range\" : {\n"
+ + " \"" + RANGE_QUERY_KEY + "\" : {\n"
+ + " \"lte\" : \"" + RANGE_QUERY_LTEND + "\",\n"
+ + " \"boost\": 2.0\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + "}";
+ private static final String RANGEBOOL_QUERY = "{\n"
+ + " \"query\": {\n"
+ + " \"bool\": {\n"
+ + " \"must\": [\n"
+ + " {\n"
+ + " \"match\": {\n"
+ + " \"is-required\": true\n"
+ + " }\n"
+ + " },\n"
+ + " {\n"
+ + " \"regexp\": {\n"
+ + " \"node-id\": {\n"
+ " \"max_determinized_states\": 10000,\n"
- + " \"flags\": \"ALL\",\n" + " \"value\": \"sim.*\"\n"
- + " }\n" + " }\n" + " }\n" + " ]\n"
- + " }\n" + " }\n" + "}";
+ + " \"flags\": \"ALL\",\n"
+ + " \"value\": \"sim.*\"\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + " ]\n"
+ + " }\n"
+ + " }\n"
+ + "}";
private static final String AGG_FIELD = "severity";
private static final String AGG_QUERY =
- "{\n" + " \"query\": {\n" + " \"match_all\": {}\n" + " },\n" + " \"aggs\": {\n"
- + " \"severity\": {\n" + " \"terms\": {\n" + " \"field\": \""
- + AGG_FIELD + "\"\n" + " }\n" + " }\n" + " }\n" + "}";
+ "{\n"
+ + " \"query\": {\n"
+ + " \"match_all\": {}\n"
+ + " },\n"
+ + " \"aggs\": {\n"
+ + " \"severity\": {\n"
+ + " \"terms\": {\n"
+ + " \"field\": \"" + AGG_FIELD + "\"\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + "}";
private static final long FROMANDSIZE_QUERY_SIZE = 20;
private static final long FROMANDSIZE_QUERY_FROM = 120;
- private static final String FROMANDSIZE_QUERY = "{\n" + " \"size\": " + FROMANDSIZE_QUERY_SIZE + ",\n"
- + " \"query\": {\n" + " \"match_all\": {}\n" + " },\n" + " \"from\":"
- + FROMANDSIZE_QUERY_FROM + "\n" + "}";
+ private static final String FROMANDSIZE_QUERY = "{\n"
+ + " \"size\": " + FROMANDSIZE_QUERY_SIZE + ",\n"
+ + " \"query\": {\n"
+ + " \"match_all\": {}\n"
+ + " },\n"
+ + " \"from\":" + FROMANDSIZE_QUERY_FROM + "\n"
+ + "}";
private static final String TERMQUERY_KEY = "node-id";
private static final String TERMQUERY_VALUE = "abc";
- private static final String TERM_QUERY = "{\n" + " \"query\": {\n" + " \"term\": {\n" + " \""
- + TERMQUERY_KEY + "\": \"" + TERMQUERY_VALUE + "\"\n" + " }\n" + " }\n" + "}";
+ private static final String TERM_QUERY = "{\n"
+ + " \"query\": {\n"
+ + " \"term\": {\n"
+ + " \"" + TERMQUERY_KEY + "\": \"" + TERMQUERY_VALUE + "\"\n"
+ + " }\n"
+ + " }\n"
+ + "}";
private static final String SORTING_PROPERTY = "node-id";
- private static final String SORTING_QUERY_ASC = "{\n" + " \"query\": {\n" + " \"match_all\": {}\n"
- + " },\n" + " \"sort\": [\n" + " {\n" + " \"" + SORTING_PROPERTY + "\": {\n"
- + " \"order\": \"asc\"\n" + " }\n" + " }\n" + " ]\n" + "}";
- private static final String SORTING_QUERY_DESC = "{\n" + " \"query\": {\n" + " \"match_all\": {}\n"
- + " },\n" + " \"sort\": [\n" + " {\n" + " \"" + SORTING_PROPERTY + "\": {\n"
- + " \"order\": \"desc\"\n" + " }\n" + " }\n" + " ]\n" + "}";
-
+ private static final String SORTING_QUERY_ASC = "{\n"
+ + " \"query\": {\n"
+ + " \"match_all\": {}\n"
+ + " },\n"
+ + " \"sort\": [\n"
+ + " {\n"
+ + " \"" + SORTING_PROPERTY + "\": {\n"
+ + " \"order\": \"asc\"\n"
+ + " }\n"
+ + " }\n"
+ + " ]\n"
+ + "}";
+ private static final String SORTING_QUERY_DESC = "{\n"
+ + " \"query\": {\n"
+ + " \"match_all\": {}\n"
+ + " },\n"
+ + " \"sort\": [\n"
+ + " {\n"
+ + " \"" + SORTING_PROPERTY + "\": {\n"
+ + " \"order\": \"desc\"\n"
+ + " }\n"
+ + " }\n"
+ + " ]\n"
+ + "}";
+ // @formatter:on
private void testEquals(String message, String json, QueryBuilder query) {
this.testEquals(message, json, query, true);
}
diff --git a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestJsonAssert.java b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestJsonAssert.java
index 72eba38e8..4ce92b130 100644
--- a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestJsonAssert.java
+++ b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestJsonAssert.java
@@ -21,13 +21,13 @@
*/
package org.onap.ccsdk.features.sdnr.wt.common.test;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import org.json.JSONArray;
import org.json.JSONException;
import org.junit.Test;
import org.onap.ccsdk.features.sdnr.wt.common.HtAssert;
-import org.onap.ccsdk.features.sdnr.wt.common.test.JSONAssert;
public class TestJsonAssert {
diff --git a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestPomfile.java b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestPomfile.java
index 9de285d1b..7089a809d 100644
--- a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestPomfile.java
+++ b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestPomfile.java
@@ -24,12 +24,9 @@ package org.onap.ccsdk.features.sdnr.wt.common.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
-
import java.io.ByteArrayInputStream;
-import java.io.FileInputStream;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
-
import org.junit.Test;
import org.onap.ccsdk.features.sdnr.wt.common.file.PomFile;
import org.onap.ccsdk.features.sdnr.wt.common.file.PomPropertiesFile;
@@ -39,17 +36,16 @@ public class TestPomfile {
private static final String TESTPROPERTY_KEY = "elasticsearch-rest-client.version";
private static final String TESTPROPERTY_VALUE = "6.4.3";
- private static final String POMFILENAME = "pom.xml";
+ private static final String POMFILENAME = "/testpom.xml";
private static final String POM_PROPERTY = "#Generated by org.apache.felix.bundleplugin\n"
+ "#Tue Nov 19 11:20:33 CET 2019\n" + "version=0.7.0-SNAPSHOT\n"
+ "groupId=org.onap.ccsdk.features.sdnr.wt\n" + "artifactId=sdnr-wt-data-provider-provider\n";
- //private static final Date DATE_EXPECTED = new Date(119, 10, 19, 11, 20, 33);
@Test
public void test() {
PomFile pom = null;
try {
- pom = new PomFile(new FileInputStream(POMFILENAME));
+ pom = new PomFile(this.getClass().getResourceAsStream(POMFILENAME));
} catch (ParserConfigurationException | SAXException | IOException e) {
fail(e.getMessage());
}
@@ -59,14 +55,9 @@ public class TestPomfile {
}
@Test
- public void testProp() {
+ public void testProp() throws IOException {
PomPropertiesFile file = null;
- try {
- file = new PomPropertiesFile(new ByteArrayInputStream(POM_PROPERTY.getBytes()));
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ file = new PomPropertiesFile(new ByteArrayInputStream(POM_PROPERTY.getBytes()));
assertNotNull(file);
assertNotNull(file.getBuildDate());
}
diff --git a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestPortstatus.java b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestPortstatus.java
index 3ddbcebd0..ec18e0a84 100644
--- a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestPortstatus.java
+++ b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestPortstatus.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP : ccsdk features
* ================================================================================
- * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
+ * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
* All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,7 +22,6 @@ package org.onap.ccsdk.features.sdnr.wt.common.test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-
import java.io.IOException;
import java.net.ServerSocket;
import java.time.Duration;
diff --git a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/helper/HelpServlet.java b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/helper/HelpServlet.java
index a6f77c72d..a99e1222a 100644
--- a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/helper/HelpServlet.java
+++ b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/helper/HelpServlet.java
@@ -89,13 +89,11 @@ public class HelpServlet extends BaseServlet implements IPublicServlet {
@Override
protected boolean doTrustAll() {
- // TODO Auto-generated method stub
return false;
}
@Override
protected void trustAll(boolean trust) {
- // TODO Auto-generated method stub
}
@@ -120,13 +118,11 @@ public class HelpServlet extends BaseServlet implements IPublicServlet {
@Override
protected boolean trustInsecure() {
- // TODO Auto-generated method stub
return false;
}
@Override
protected boolean isCorsEnabled() {
- // TODO Auto-generated method stub
return false;
}
@@ -135,6 +131,5 @@ public class HelpServlet extends BaseServlet implements IPublicServlet {
*/
public void setOffline(boolean b) {
this.isoff = b;
-
}
}
diff --git a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/helper/HelpServletBase.java b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/helper/HelpServletBase.java
index c163c746f..dbdaace34 100644
--- a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/helper/HelpServletBase.java
+++ b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/helper/HelpServletBase.java
@@ -46,10 +46,12 @@ import javax.servlet.http.HttpServletResponse;
import org.junit.After;
import org.junit.Before;
+
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
+@SuppressWarnings("restriction")
public class HelpServletBase {
public static final String RESPONSE_GET = "This is the response get";