aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/common/src/test
diff options
context:
space:
mode:
authorMichael Dürre <michael.duerre@highstreet-technologies.com>2020-02-24 11:17:47 +0100
committerMichael Dürre <michael.duerre@highstreet-technologies.com>2020-02-24 11:18:16 +0100
commit64d0d3d599e0ea26ec1613b2befd411ad08f884d (patch)
tree5e9ea5e1a68bd2e836ab1f50fa51753b89a03735 /sdnr/wt/common/src/test
parenta2041a822f0406742edbd7a1074a73f9c838c0bf (diff)
update common lib
add some more es functionality Issue-ID: SDNC-1082 Signed-off-by: Michael Dürre <michael.duerre@highstreet-technologies.com> Change-Id: Ic7a9b0922ddd9d389e1ab6e1df3201874409a883
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.java24
-rw-r--r--sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbRequests.java59
-rw-r--r--sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestEsData.java111
3 files changed, 194 insertions, 0 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 591ea49dd..fd0c255dd 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,9 +21,13 @@ import static org.junit.Assert.*;
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;
import org.junit.Test;
@@ -230,4 +234,24 @@ public class TestConfig {
}
}
+ @Test
+ public void testEnvPropert() {
+ final String KEY = "basada";
+ Section section = new Section("test");
+ section.addLine(KEY+"=${USER} in ${HOME}");
+ 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/TestDbRequests.java b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestDbRequests.java
index 36bbebefd..9fdfeb2d2 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
@@ -24,7 +24,9 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo;
import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.ClusterHealthRequest;
+import org.onap.ccsdk.features.sdnr.wt.common.database.requests.CreateAliasRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.CreateIndexRequest;
+import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteAliasRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteByQueryRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteIndexRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteRequest;
@@ -36,12 +38,14 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.requests.SearchRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.UpdateByQueryRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.UpdateRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.ClusterHealthResponse;
+import org.onap.ccsdk.features.sdnr.wt.common.database.responses.CreateAliasResponse;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.CreateIndexResponse;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.DeleteByQueryResponse;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.DeleteIndexResponse;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.DeleteResponse;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.GetResponse;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.IndexResponse;
+import org.onap.ccsdk.features.sdnr.wt.common.database.responses.ListIndicesResponse;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.NodeStatsResponse;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.SearchResponse;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.UpdateByQueryResponse;
@@ -53,6 +57,7 @@ import static org.junit.Assert.assertNotNull;
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;
@@ -96,6 +101,53 @@ public class TestDbRequests {
public void testCount() {
}
+ @Test
+ public void testIndexAndAliasList() {
+ final String ALIAS="asdoi32kmasd";
+ final String IDX=ALIAS+"-v1";
+ CreateIndexRequest request = new CreateIndexRequest(IDX);
+ CreateIndexResponse response = null;
+ try {
+ response = dbClient.createIndex(request);
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ assertNotNull(response);
+
+ CreateAliasRequest request3 = new CreateAliasRequest(IDX,ALIAS);
+ CreateAliasResponse response3 = null;
+ try {
+ response3 = dbClient.createAlias(request3);
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ assertNotNull(response3);
+ assertTrue(response3.isResponseSucceeded());
+
+ assertTrue("index not existing", dbClient.isExistsIndex(IDX));
+ ListIndicesResponse response2=null;
+ try {
+ response2 = dbClient.getIndices();
+ } catch (ParseException | IOException e) {
+ fail(e.getMessage());
+ }
+ assertNotNull(response2);
+ assertNotNull(response2.getEntries());
+ assertTrue(response2.getEntries().size()>0);
+
+ DeleteIndexRequest request11 = new DeleteIndexRequest(IDX);
+
+ DeleteIndexResponse response11 = null;
+ try {
+ response11 = dbClient.deleteIndex(request11);
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ assertNotNull(response11);
+ assertFalse("index still existing", dbClient.isExistsIndex(IDX));
+ this.deleteAlias(IDX, ALIAS);
+ this.deleteIndex(IDX);
+ }
@Test
public void testCreateAndDeleteIndex() {
@@ -401,6 +453,13 @@ public class TestDbRequests {
System.out.println(stats.getNodesInfo());
System.out.println(stats.getNodeStatistics());
}
+ private void deleteAlias(String idx,String alias) {
+ try {
+ dbClient.deleteAlias( new DeleteAliasRequest(idx,alias));
+ } catch (IOException e) {
+
+ }
+ }
private void deleteIndex(String idx) {
try {
dbClient.deleteIndex( new DeleteIndexRequest(idx));
diff --git a/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestEsData.java b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestEsData.java
new file mode 100644
index 000000000..d88df96a0
--- /dev/null
+++ b/sdnr/wt/common/src/test/java/org/onap/ccsdk/features/sdnr/wt/common/test/TestEsData.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * ============LICENSE_START========================================================================
+ * ONAP : ccsdk feature sdnr wt
+ * =================================================================================================
+ * 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
+ *
+ * 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.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.text.ParseException;
+
+import org.junit.Test;
+import org.onap.ccsdk.features.sdnr.wt.common.database.data.AliasesEntry;
+import org.onap.ccsdk.features.sdnr.wt.common.database.data.AliasesEntryList;
+import org.onap.ccsdk.features.sdnr.wt.common.database.data.EsVersion;
+import org.onap.ccsdk.features.sdnr.wt.common.database.data.IndicesEntry;
+import org.onap.ccsdk.features.sdnr.wt.common.database.data.IndicesEntryList;
+
+/**
+ * @author Michael Dürre
+ *
+ */
+public class TestEsData {
+
+
+ @Test
+ public void testVersion() {
+ EsVersion version=null;
+ try {
+ version = new EsVersion("2.3.4");
+ } catch (ParseException e) {
+ fail(e.getMessage());
+ }
+ assertNotNull(version);
+ assertEquals(2, version.getMajor());
+ assertEquals(3, version.getMinor());
+ assertEquals(4, version.getRevision());
+
+ EsVersion versionNewer = new EsVersion(5,0,0);
+ EsVersion versionOlder = new EsVersion(2,2,0);
+
+ assertTrue(version.isOlderOrEqualThan(versionNewer));
+ assertTrue(version.isNewerOrEqualThan(versionOlder));
+
+ }
+ @Test
+ public void testIndices() {
+ IndicesEntryList list = new IndicesEntryList();
+ IndicesEntry entry=null;
+ try {
+ entry=new IndicesEntry("yellow open inventoryequipment-v1 5nNPRbJ3T9arMxqxBbJKyQ 5 1 2 3 1.2kb 2.4kb");
+ list.add(entry);
+ list.add(new IndicesEntry("yellow open networkelement-connection-v1 5nNPRbJ3T9arMxqxBbJKyQ 5 1 0 0 1.2kb 1.2kb"));
+ list.add(new IndicesEntry("yellow open faultlog-v1 5nNPRbJ3T9arMxqxBbJKyQ 5 1 0 0 1.2kb 1.2kb"));
+ list.add(new IndicesEntry("yellow open eventlog-v1 5nNPRbJ3T9arMxqxBbJKyQ 5 1 0 0 1.2kb 1.2kb"));
+ } catch (ParseException e) {
+ fail(e.getMessage());
+ }
+ assertEquals(4, list.size());
+ assertNotNull(list.findByIndex("eventlog-v1"));
+ assertNull(list.findByIndex("faultcurrent"));
+ assertNotNull(entry);
+ assertEquals("yellow",entry.getStatus());
+ assertEquals("open", entry.getStatus2());
+ assertEquals("inventoryequipment-v1", entry.getName());
+ assertEquals("5nNPRbJ3T9arMxqxBbJKyQ", entry.getHash());
+ assertEquals(5, entry.getShards());
+ assertEquals(1, entry.getReplicas());
+ assertEquals(2, entry.getC1());
+ assertEquals(3, entry.getC2());
+ assertEquals("1.2kb", entry.getSize1());
+ assertEquals("2.4kb", entry.getSize2());
+
+ }
+ @Test
+ public void testAliases() {
+ AliasesEntryList list = new AliasesEntryList();
+ AliasesEntry entry=null;
+ try {
+ entry=new AliasesEntry("networkelement-connection networkelement-connection-v1 - - -");
+ list.add(entry);
+ list.add(new AliasesEntry("faultcurrent faultcurrent-v1 - - -"));
+ list.add(new AliasesEntry("faultlog faultlog-v1 - - -"));
+ list.add(new AliasesEntry("maintenancemode maintenancemode-v1 - - -"));
+ } catch (ParseException e) {
+ fail(e.getMessage());
+ }
+ assertEquals(4, list.size());
+ assertNotNull(list.findByAlias("faultcurrent"));
+ assertNull(list.findByAlias("eventlog"));
+ assertNotNull(entry);
+ assertEquals("networkelement-connection",entry.getAlias());
+ assertEquals("networkelement-connection-v1", entry.getIndex());
+ }
+}