summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/common/src/test/java
diff options
context:
space:
mode:
authorMichael Dürre <michael.duerre@highstreet-technologies.com>2020-03-24 09:28:54 +0100
committerMichael Dürre <michael.duerre@highstreet-technologies.com>2020-03-24 09:29:09 +0100
commitf95c9b53afee12372046d2f6194aa0d44b42c6db (patch)
tree727e43ace9b8fa3eee4e37ca9fb65ddf42dfb26d /sdnr/wt/common/src/test/java
parentbc9425a00d19b75b149fbbf0c4ea7345de8721d5 (diff)
fix waitforyellow in dbclient
fix esclient and setup Issue-ID: SDNC-1133 Signed-off-by: Michael Dürre <michael.duerre@highstreet-technologies.com> Change-Id: I0326e84383602f3401f615bc8342fd091f401e8e
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/TestDbQueries.java65
-rw-r--r--sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestPortstatus.java76
2 files changed, 138 insertions, 3 deletions
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 21c68b3ae..93d4b1af6 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
@@ -52,7 +52,7 @@ public class TestDbQueries {
"}";
private static final String MATCH_QUERY_KEY2 = "node-id";
private static final Object MATCH_QUERY_VALUE2 = "sim2";
- private static final String BOOL_QUERY = "{\n" +
+ private static final String BOOL_QUERY_MUST = "{\n" +
" \"query\": {\n" +
" \"bool\": {\n" +
" \"must\": [\n" +
@@ -70,6 +70,46 @@ public class TestDbQueries {
" }\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" +
@@ -189,13 +229,32 @@ public class TestDbQueries {
testEquals("match query is wrong", MATCH_QUERY, QueryBuilders.matchQuery(MATCH_QUERY_KEY, MATCH_QUERY_VALUE));
}
@Test
- public void testBool() {
- testEquals("bool query is wrong", BOOL_QUERY,
+ public void testBoolMust() {
+ testEquals("bool query is wrong", BOOL_QUERY_MUST,
QueryBuilders.boolQuery().
must(QueryBuilders.matchQuery(MATCH_QUERY_KEY, MATCH_QUERY_VALUE)).
must(QueryBuilders.matchQuery(MATCH_QUERY_KEY2, MATCH_QUERY_VALUE2)));
}
@Test
+ public void testBoolMustSingle() {
+ testEquals("bool single query is wrong", BOOL_QUERY_MUST_SINGLE,
+ QueryBuilders.boolQuery().
+ must(QueryBuilders.matchQuery(MATCH_QUERY_KEY, MATCH_QUERY_VALUE)));
+ }
+ @Test
+ public void testBoolShould() {
+ testEquals("bool query is wrong", BOOL_QUERY_SHOULD,
+ QueryBuilders.boolQuery().
+ should(QueryBuilders.matchQuery(MATCH_QUERY_KEY, MATCH_QUERY_VALUE)).
+ should(QueryBuilders.matchQuery(MATCH_QUERY_KEY2, MATCH_QUERY_VALUE2)));
+ }
+ @Test
+ public void testBoolShouldSingle() {
+ testEquals("bool single query is wrong", BOOL_QUERY_SHOULD_SINGLE,
+ QueryBuilders.boolQuery().
+ should(QueryBuilders.matchQuery(MATCH_QUERY_KEY, MATCH_QUERY_VALUE)));
+ }
+ @Test
public void testRange() {
testEquals("range query is wrong", RANGE_QUERY, QueryBuilders.rangeQuery(RANGE_QUERY_KEY).lte(RANGE_QUERY_LTEND));
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
new file mode 100644
index 000000000..379142db2
--- /dev/null
+++ b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestPortstatus.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * ============LICENSE_START========================================================================
+ * ONAP : ccsdk feature sdnr wt
+ * =================================================================================================
+ * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
+ * =================================================================================================
+ * 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. See the License for the specific language governing permissions and limitations under
+ * the License.
+ * ============LICENSE_END==========================================================================
+ ******************************************************************************/
+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;
+import java.time.Instant;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.ccsdk.features.sdnr.wt.common.database.Portstatus;
+import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo;
+
+public class TestPortstatus extends Mockito{
+
+
+ @Test
+ public void testIsAvailable() throws IOException {
+ assertFalse("Port status should be false", Portstatus.isAvailable("localhost", 4567) );
+ ServerSocket serverSocket = new ServerSocket(4567);
+ assertTrue("Port status should be true", Portstatus.isAvailable("localhost", 4567) );
+ serverSocket.close();
+ }
+
+ @Test
+ public void testWaitIsAvailable() throws IOException {
+ ServerSocket serverSocket = new ServerSocket(4567);
+ assertTrue("Port status should be true", Portstatus.waitSecondsTillAvailable(5, "localhost", 4567) );
+ serverSocket.close();
+ }
+
+ @Test
+ public void testWaitIsAvailableHostInfo() throws IOException {
+ ServerSocket serverSocket = new ServerSocket(4567);
+ assertTrue("Port status should be true", Portstatus.waitSecondsTillAvailable(5, new HostInfo("localhost", 4567)) );
+ serverSocket.close();
+ }
+
+ @Test
+ public void testWaitTillAvailable() throws IOException {
+ Instant start = Instant.now();
+ assertFalse("Port status should be false", Portstatus.waitSecondsTillAvailable(5, "localhost", 4567) );
+ Instant end = Instant.now();
+ long seconds = Duration.between(start, end).getSeconds();
+ assertTrue("Port status timeout 5 expected and not between 3 .. 7 seconds", 3 < seconds && seconds < 7 );
+ }
+
+ @Test
+ public void testWaitTillAvailableHostinfo() throws IOException {
+ Instant start = Instant.now();
+ assertFalse("Port status should be false", Portstatus.waitSecondsTillAvailable(5, new HostInfo("localhost", 4567)));
+ Instant end = Instant.now();
+ long seconds = Duration.between(start, end).getSeconds();
+ assertTrue("Port status timeout 5 expected and not between 3 .. 7 seconds", 3 < seconds && seconds < 7 );
+ }
+
+
+}