aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/common/src/test
diff options
context:
space:
mode:
authorhighstreetherbert <herbert.eiselt@highstreet-technologies.com>2020-07-13 19:05:55 +0200
committerhighstreetherbert <herbert.eiselt@highstreet-technologies.com>2020-07-15 10:40:35 +0200
commit7dfb26b3c3a35fe73684019fbcf68ab6c9cf091a (patch)
treed2b3fac81dcfabd5c463bc2071e1f477236e744c /sdnr/wt/common/src/test
parent5dfcc4c815f930edb9fc9f5f94a9ef6d9791a709 (diff)
SDN-R common Elasticsearch 7.x support
Extend SDN-R common for Elasticsearch 7.x support Issue-ID: SDNC-1284 Signed-off-by: highstreetherbert <herbert.eiselt@highstreet-technologies.com> Change-Id: I4c4f66f73f8adbdf2a9ba4f77d1e2d274ce49892 Signed-off-by: highstreetherbert <herbert.eiselt@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/common/src/test')
-rw-r--r--sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestConfig.java21
-rw-r--r--sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbClient.java10
-rw-r--r--sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbRequests.java74
-rw-r--r--sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestPortstatus.java29
4 files changed, 65 insertions, 69 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 415620415..cbe0b9c4d 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
@@ -21,16 +21,16 @@
*/
package org.onap.ccsdk.features.sdnr.wt.common.test;
-import static org.junit.Assert.*;
+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.lang.reflect.Field;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
-import java.util.Collections;
-import java.util.Map;
import org.junit.After;
import org.junit.Before;
@@ -249,17 +249,4 @@ public class TestConfig {
section.parseLines();
assertTrue(section.getProperty(KEY).length() > " in ".length());
}
-
- public static void setEnv(String key, String value) {
- try {
- Map<String, String> env = System.getenv();
- Class<?> cl = env.getClass();
- Field field = cl.getDeclaredField("m");
- field.setAccessible(true);
- Map<String, String> writableEnv = (Map<String, String>) field.get(env);
- writableEnv.put(key, value);
- } catch (Exception e) {
- throw new IllegalStateException("Failed to set environment variable", e);
- }
- }
}
diff --git a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbClient.java b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbClient.java
index cf9d93052..421a2229c 100644
--- a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbClient.java
+++ b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbClient.java
@@ -21,10 +21,12 @@
*/
package org.onap.ccsdk.features.sdnr.wt.common.test;
-import static org.junit.Assert.*;
-
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.IOException;
-
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
@@ -47,7 +49,7 @@ public class TestDbClient {
@BeforeClass
public static void init() throws Exception {
- dbClient = new HtDatabaseClient(hosts);
+ dbClient = HtDatabaseClient.getClient(hosts);
dbClient.waitForYellowStatus(20000);
}
diff --git a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbRequests.java b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbRequests.java
index 756d70c85..492dfa96e 100644
--- a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbRequests.java
+++ b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbRequests.java
@@ -21,6 +21,18 @@
*/
package org.onap.ccsdk.features.sdnr.wt.common.test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import java.io.IOException;
+import java.text.ParseException;
+import java.util.Arrays;
+import java.util.List;
+import org.json.JSONException;
+import org.json.JSONObject;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -57,20 +69,6 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.responses.SearchResponse;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.UpdateByQueryResponse;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.UpdateResponse;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import java.io.IOException;
-import java.text.ParseException;
-import java.util.Arrays;
-import java.util.List;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-
public class TestDbRequests {
private static HtDatabaseClient dbClient;
@@ -80,7 +78,7 @@ public class TestDbRequests {
@BeforeClass
public static void init() throws Exception {
- dbClient = new HtDatabaseClient(hosts);
+ dbClient = HtDatabaseClient.getClient(hosts);
}
@@ -200,7 +198,7 @@ public class TestDbRequests {
}
this.insert(IDX, ID, JSON);
// delete data
- DeleteRequest request2 = new DeleteRequest(IDX, IDX, ID);
+ DeleteRequest request2 = new DeleteRequest(IDX, dbClient.isVersion7() ? "_doc" : IDX, ID);
DeleteResponse response2 = null;
try {
response2 = dbClient.delete(request2);
@@ -215,7 +213,7 @@ public class TestDbRequests {
fail(e.getMessage());
}
// verify data deleted
- GetRequest request4 = new GetRequest(IDX, IDX, ID);
+ GetRequest request4 = new GetRequest(IDX, dbClient.isVersion7() ? "_doc" : IDX, ID);
GetResponse response4 = null;
try {
response4 = dbClient.get(request4);
@@ -233,8 +231,11 @@ public class TestDbRequests {
*/
private JSONObject defaultMappings(String idx, boolean useStrict) {
String mapping = "{}";
- return new JSONObject(String.format("{\"%s\":{%s\"properties\":%s}}", idx,
- useStrict ? "\"dynamic\": false," : "\"dynamic\": true,", mapping));
+ return dbClient.isVersion7()
+ ? new JSONObject(String.format("{%s\"properties\":%s}",
+ useStrict ? "\"dynamic\": false," : "\"dynamic\": true,", mapping))
+ : new JSONObject(String.format("{\"%s\":{%s\"properties\":%s}}", idx,
+ useStrict ? "\"dynamic\": false," : "\"dynamic\": true,", mapping));
}
@Test
@@ -325,7 +326,7 @@ public class TestDbRequests {
this.insert(IDX, ID, JSON);
this.insert(IDX, ID2, JSON2);
this.insert(IDX, ID3, JSON3);
- SearchRequest request = new SearchRequest(IDX, IDX);
+ SearchRequest request = new SearchRequest(IDX, dbClient.isVersion7() ? "_doc" : IDX);
request.setQuery(QueryBuilders.matchAllQuery());
SearchResponse response = null;
try {
@@ -336,7 +337,7 @@ public class TestDbRequests {
assertNotNull(response);
assertEquals("not all items found", 3, response.getHits().length);
assertEquals("incorrect index", IDX, response.getHits()[0].getIndex());
- assertEquals("incorrect type", IDX, response.getHits()[0].getType());
+ assertEquals("incorrect type", dbClient.isVersion7() ? "_doc" : IDX, response.getHits()[0].getType());
this.deleteIndex(IDX);
}
@@ -354,7 +355,7 @@ public class TestDbRequests {
fail("unable to create index");
}
this.insert(IDX, ID, JSON);
- UpdateRequest request = new UpdateRequest(IDX, IDX, ID);
+ UpdateRequest request = new UpdateRequest(IDX, dbClient.isVersion7() ? "_doc" : IDX, ID);
UpdateResponse response = null;
try {
request.source(new JSONObject(JSON2));
@@ -371,7 +372,7 @@ public class TestDbRequests {
fail(e.getMessage());
}
// verify update
- GetRequest request3 = new GetRequest(IDX, IDX, ID);
+ GetRequest request3 = new GetRequest(IDX, dbClient.isVersion7() ? "_doc" : IDX, ID);
GetResponse response3 = null;
try {
response3 = dbClient.get(request3);
@@ -397,7 +398,7 @@ public class TestDbRequests {
fail("unable to create index");
}
this.insert(IDX, ID, JSON);
- UpdateByQueryRequest request = new UpdateByQueryRequest(IDX, IDX);
+ UpdateByQueryRequest request = new UpdateByQueryRequest(IDX, dbClient.isVersion7() ? "_doc" : IDX);
UpdateByQueryResponse response = null;
try {
request.source(ID, new JSONObject(JSON2));
@@ -414,7 +415,7 @@ public class TestDbRequests {
fail(e.getMessage());
}
// verify update
- GetRequest request3 = new GetRequest(IDX, IDX, ID);
+ GetRequest request3 = new GetRequest(IDX, dbClient.isVersion7() ? "_doc" : IDX, ID);
GetResponse response3 = null;
try {
response3 = dbClient.get(request3);
@@ -434,9 +435,10 @@ public class TestDbRequests {
final String JSON3 = "{ \"node-id\":\"sim3\",\"severity\":\"minor\"}";
final String JSON4 = "{ \"node-id\":\"sim4\",\"severity\":\"warning\"}";
final String JSON5 = "{ \"node-id\":\"sim5\",\"severity\":\"major\"}";
- final String MAPPINGS = String.format("{\"" + IDX + "\":{\"properties\":%s}}",
- "{\"node-id\":{\"type\": \"keyword\"},\"severity\": {\"type\": \"keyword\"}}");
- // create index with mapping keyword
+ final String MAPPINGS =
+ String.format(dbClient.isVersion7() ? "{\"properties\":%s}" : "{\"" + IDX + "\":{\"properties\":%s}}",
+ "{\"node-id\":{\"type\": \"keyword\"},\"severity\": {\"type\": \"keyword\"}}");
+ //create index with mapping keyword
CreateIndexResponse iresponse = null;
try {
if (!dbClient.isExistsIndex(IDX)) {
@@ -449,6 +451,7 @@ public class TestDbRequests {
fail("unable to create index: " + e1.getMessage());
}
+
// fill index
this.insert(IDX, null, JSON);
this.insert(IDX, null, JSON2);
@@ -462,7 +465,7 @@ public class TestDbRequests {
fail(e.getMessage());
}
- SearchRequest request = new SearchRequest(IDX, IDX);
+ SearchRequest request = new SearchRequest(IDX, dbClient.isVersion7() ? "_doc" : IDX);
request.setQuery(QueryBuilders.matchAllQuery().aggregations("severity").size(0));
SearchResponse response = null;
try {
@@ -501,7 +504,7 @@ public class TestDbRequests {
System.out.println(stats.getNodeStatistics());
}
- // @Test
+ //@Test
public void testPreventAutoCreateIndex() {
final String IDX1 = "acidx1";
final String ID1 = "acid1";
@@ -511,7 +514,7 @@ public class TestDbRequests {
ClusterSettingsResponse settingsResponse = null;
String esId = null;
- // set setting to allow autocreate
+ //set setting to allow autocreate
try {
settingsResponse = dbClient.setupClusterSettings(new ClusterSettingsRequest(true));
} catch (IOException e) {
@@ -519,10 +522,10 @@ public class TestDbRequests {
}
assertNotNull(settingsResponse);
assertTrue(settingsResponse.isAcknowledged());
- // test if something new can be created
+ //test if something new can be created
esId = dbClient.doWriteRaw(IDX1, IDX1, ID1, OBJ);
assertEquals(ID1, esId);
- // set setting to deny autocreate
+ //set setting to deny autocreate
try {
settingsResponse = dbClient.setupClusterSettings(new ClusterSettingsRequest(false));
} catch (IOException e) {
@@ -530,10 +533,10 @@ public class TestDbRequests {
}
assertNotNull(settingsResponse);
assertTrue(settingsResponse.isAcknowledged());
- // test if something new cannot be created
+ //test if something new cannot be created
esId = dbClient.doWriteRaw(IDX2, IDX2, ID2, OBJ);
assertNull(esId);
- // set setting to allow autocreate
+ //set setting to allow autocreate
try {
settingsResponse = dbClient.setupClusterSettings(new ClusterSettingsRequest(true));
} catch (IOException e) {
@@ -560,4 +563,5 @@ public class TestDbRequests {
}
}
+
}
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 d073043c2..3ddbcebd0 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
@@ -1,19 +1,22 @@
/*
- * ============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
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2020 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
+ * 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==========================================================================
+ * 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;