summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/apigateway/provider/src/test
diff options
context:
space:
mode:
authorMichael Dürre <michael.duerre@highstreet-technologies.com>2020-01-30 12:30:58 +0100
committerKAPIL SINGAL <ks220y@att.com>2020-01-31 20:58:11 +0000
commitfb121a32b8b3431e37d2b73a63aac8055983f8f2 (patch)
tree1674d0395da57f4a92531f3d35508c58ff904f60 /sdnr/wt/apigateway/provider/src/test
parent84cf604e3f06942a62ae0478327ec6100787761e (diff)
update apigateway
removed unused code and services Issue-ID: SDNC-1027 Signed-off-by: Michael Dürre <michael.duerre@highstreet-technologies.com> Change-Id: Ia126ed7fcc18331858c502409384cbc0570d6be7
Diffstat (limited to 'sdnr/wt/apigateway/provider/src/test')
-rw-r--r--sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestDatabaseHttpClient.java137
-rw-r--r--sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestHttpClient.java71
-rw-r--r--sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestMediatorServerServlet.java91
-rw-r--r--sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestQueryCallback.java115
-rw-r--r--sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpMsServlet.java88
5 files changed, 0 insertions, 502 deletions
diff --git a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestDatabaseHttpClient.java b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestDatabaseHttpClient.java
deleted file mode 100644
index 791e9bad0..000000000
--- a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestDatabaseHttpClient.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*******************************************************************************
- * ============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.apigateway.test;
-
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.mock;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.when;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.junit.Test;
-import org.onap.ccsdk.features.sdnr.wt.apigateway.database.DatabaseEntryProvider;
-import org.onap.ccsdk.features.sdnr.wt.apigateway.database.DatabaseHttpClient;
-import org.onap.ccsdk.features.sdnr.wt.apigateway.database.MediatorServerInfo;
-import org.onap.ccsdk.features.sdnr.wt.apigateway.database.http.BaseHTTPResponse;
-
-public class TestDatabaseHttpClient {
-
- private static final String ID_1="AWwscPepjf5-TrAFEdUD";
- private static final String HOSTNAME_1="http://192.168.178.89:7070";
- private static final String NAME_1="internal mediatorserver";
- private static final String ID_2="AWwscSCWjf5-TrAFEdUE";
- private static final String HOSTNAME_2="http://192.168.178.89:7071";
- private static final String NAME_2="internal mediatorserver2";
- private static final String ID_3="AWwscSCWjf5-TrAFEdsE";
- private static final String HOSTNAME_3="http://192.168.178.88:7371";
- private static final String NAME_3="test mediatorserver2";
-
- private static final String RESPONSE_VALID="{\n" +
- "\"took\": 3,\n" +
- "\"timed_out\": false,\n" +
- "\"_shards\": {\n" +
- "\"total\": 5,\n" +
- "\"successful\": 5,\n" +
- "\"failed\": 0\n" +
- "},\n" +
- "\"hits\": {\n" +
- "\"total\": 2,\n" +
- "\"max_score\": 1,\n" +
- "\"hits\": [\n" +
- "{\n" +
- "\"_index\": \"mwtn_v1\",\n" +
- "\"_type\": \"mediator-server\",\n" +
- "\"_id\": \"AWwscPepjf5-TrAFEdUD\",\n" +
- "\"_score\": 1,\n" +
- "\"_source\": {\n" +
- "\"name\": \"internal mediatorserver\",\n" +
- "\"url\": \"http://192.168.178.89:7070\"\n" +
- "}\n" +
- "}\n" +
- ",\n" +
- "{\n" +
- "\"_index\": \"mwtn_v1\",\n" +
- "\"_type\": \"mediator-server\",\n" +
- "\"_id\": \"AWwscSCWjf5-TrAFEdUE\",\n" +
- "\"_score\": 1,\n" +
- "\"_source\": {\n" +
- "\"name\": \"internal mediatorserver2\",\n" +
- "\"url\": \"http://192.168.178.89:7071\"\n" +
- "}\n" +
- "}\n" +
- "]\n" +
- "}\n" +
- "}";
-
- private class PublicDatabaseHttpClient extends DatabaseHttpClient{
-
- public PublicDatabaseHttpClient(String base, boolean trustAllCerts) {
- super(base, trustAllCerts);
- }
- @Override
- public BaseHTTPResponse sendRequest(String uri, String method, String body, Map<String, String> headers) {
- return new BaseHTTPResponse(200, RESPONSE_VALID);
- }
- }
- public class PublicDatabaseEntryProvider extends DatabaseEntryProvider {
-
- protected PublicDatabaseEntryProvider() {
- super(new PublicDatabaseHttpClient("http://localhost/",false), 60);
- }
-
- }
- @Test
- public void test() {
-
- final PublicDatabaseHttpClient client = new PublicDatabaseHttpClient("http://localhost/",false);
- Map<String, MediatorServerInfo> entries = client.requestEntries();
- assertEquals("result size is not correct",2,entries.size());
- assertEquals("hostname 1 is not correct",HOSTNAME_1,entries.get(ID_1).getHost());
- assertEquals("name 1 is not correct",NAME_1,entries.get(ID_1).getName());
- assertEquals("hostname 2 is not correct",HOSTNAME_2,entries.get(ID_2).getHost());
- assertEquals("name 2 is not correct",NAME_2,entries.get(ID_2).getName());
- }
- @Test
- public void test2() {
- final PublicDatabaseEntryProvider provider = new PublicDatabaseEntryProvider();
- boolean reloaded = provider.triggerReloadSync();
- assertTrue("data were not reloaded",reloaded);
- try {
- Thread.sleep(1500);
- } catch (InterruptedException e) {
- Thread.interrupted();
- }
-
- System.out.println(provider.printEntries());
- assertEquals("provider has not loaded data",HOSTNAME_1,provider.getHostUrl(ID_1));
- assertEquals("provider has not loaded data",HOSTNAME_2,provider.getHostUrl(ID_2));
- Map<String, MediatorServerInfo> entries2 = new HashMap<String,MediatorServerInfo>();
- entries2.put(ID_3, new MediatorServerInfo(NAME_3, HOSTNAME_3));
- provider.setEntries(entries2);
- assertEquals("provider has not loaded data",HOSTNAME_3,provider.getHostUrl(ID_3));
- try {
- provider.close();
- } catch (Exception e) {
-
- }
-
-
- }
-}
diff --git a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestHttpClient.java b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestHttpClient.java
deleted file mode 100644
index 18e84853a..000000000
--- a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestHttpClient.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*******************************************************************************
- * ============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.apigateway.test;
-
-import static org.junit.Assert.fail;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.ccsdk.features.sdnr.wt.apigateway.database.http.BaseHTTPClient;
-import org.onap.ccsdk.features.sdnr.wt.apigateway.test.helper.HelpServletBase;
-
-public class TestHttpClient {
-
- private static final int PORT =40010;
- private static final String BASEURI = "/test";
-
- private class TestBaseHTTPClient extends BaseHTTPClient {
- public TestBaseHTTPClient() {
- super(String.format("http://localhost:%s%s",PORT,BASEURI));
- }
- public void doTest() {
- String[] methods=new String[] {"GET","POST","PUT","DELETE"};
- Map<String, String> headers=new HashMap<String,String>();
- headers.put("Content-Type","application/json");
- headers.put("Authorization",BaseHTTPClient.getAuthorizationHeaderValue("admin","admin"));
- for(String method:methods) {
- try {
- this.sendRequest(String.format("%s%s", BASEURI,"/abc"), method, "abddef", headers);
- } catch (IOException e) {
- e.printStackTrace();
- fail(String.format("problem with method %s: %s",method,e.getMessage()));
- }
- }
- }
- }
- @Test
- public void test() {
- TestBaseHTTPClient client = new TestBaseHTTPClient();
- client.doTest();
- }
-
-
- @Before
- public void init() throws IOException{
- HelpServletBase.initEsTestWebserver(PORT);
- }
- @After
- public void deinit() {
- HelpServletBase.stopTestWebserver();
- }
-}
diff --git a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestMediatorServerServlet.java b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestMediatorServerServlet.java
deleted file mode 100644
index 2a6f196bd..000000000
--- a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestMediatorServerServlet.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP : CCSDK.apps.sdnr.wt.apigateway
- * ================================================================================
- * Copyright (C) 2018 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.apigateway.test;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.servlet.ServletException;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.ccsdk.features.sdnr.wt.apigateway.MyProperties;
-import org.onap.ccsdk.features.sdnr.wt.apigateway.database.MediatorServerInfo;
-import org.onap.ccsdk.features.sdnr.wt.apigateway.test.helper.HelpMsServlet;
-import org.onap.ccsdk.features.sdnr.wt.apigateway.test.helper.HelpServletBase;
-
-public class TestMediatorServerServlet extends HelpServletBase {
-
- private static final int PORT = 40004;
-
- public TestMediatorServerServlet() {
- super("/ms", PORT);
- }
-
- @Test
- public void test() throws ServletException, IOException {
-
- String tmpFilename = "tmp3.cfg";
- File tmpFile = new File(tmpFilename);
- if (tmpFile.exists()) {
- tmpFile.delete();
- }
- MyProperties.Instantiate(tmpFile, true);
- String query = "{\"query\":{\"match_all\":{}}}";
- HelpMsServlet servlet = new HelpMsServlet();
- this.setServlet(servlet);
- // test diabled message
- servlet.setOfflineStatus(true);
- servlet.setBaseUrl("http://localhost:" + PORT);
- String expectedResponse = "offline";
- testrequest(HTTPMETHOD_GET, query, expectedResponse, false);
- testrequest(HTTPMETHOD_POST, query, expectedResponse, false);
- testrequest(HTTPMETHOD_PUT, query, expectedResponse, false);
- testrequest(HTTPMETHOD_DELETE, query, expectedResponse, false);
-
- servlet.setOfflineStatus(false);
- Map<String, MediatorServerInfo> entries = new HashMap<String,MediatorServerInfo>();
- entries.put("123", new MediatorServerInfo("1", "http://localhost:" + PORT));
- servlet.setMediatorEntries(entries);
- testrequest("/123/test/abc",HTTPMETHOD_GET, query, HelpMsServlet.RESPONSE_GET, true);
- testrequest("/123/test/abc",HTTPMETHOD_POST, query, HelpMsServlet.RESPONSE_POST, true);
- testrequest("/123/test/abc",HTTPMETHOD_PUT, query, HelpMsServlet.RESPONSE_PUT, true);
- testrequest("/123/test/abc",HTTPMETHOD_DELETE, query, HelpMsServlet.RESPONSE_DELETE, true);
- testrequest("/123/test/abc",HTTPMETHOD_OPTIONS, query, "", false);
-
- if (tmpFile.exists()) {
- tmpFile.delete();
- }
-
- }
- @Before
- public void init() throws IOException{
- HelpServletBase.initEsTestWebserver(PORT,"/test");
- }
- @After
- public void deinit() {
- HelpServletBase.stopTestWebserver();
- }
-
-}
diff --git a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestQueryCallback.java b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestQueryCallback.java
deleted file mode 100644
index 3340ec66c..000000000
--- a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestQueryCallback.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*******************************************************************************
- * ============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.apigateway.test;
-
-import static org.junit.Assert.*;
-
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.IOException;
-
-import javax.servlet.ServletException;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.ccsdk.features.sdnr.wt.apigateway.EsServlet.IRequestCallback;
-import org.onap.ccsdk.features.sdnr.wt.apigateway.MyProperties;
-import org.onap.ccsdk.features.sdnr.wt.apigateway.test.helper.HelpEsServlet;
-import org.onap.ccsdk.features.sdnr.wt.apigateway.test.helper.HelpServletBase;
-
-public class TestQueryCallback extends HelpServletBase{
-
- private static final int PORT = 40011;
-
- public TestQueryCallback() {
- super("/database",PORT);
- }
-
- final String LR = "\n";
-
-
- private boolean hasCallback=false;
-
- @Test
- public void test() throws ServletException, IOException {
-
- String tmpFilename = "tmp1.cfg";
- File tmpFile = new File(tmpFilename);
- if (tmpFile.exists())
- tmpFile.delete();
- MyProperties properties = MyProperties.Instantiate(tmpFile,true);
- String query = "{\"query\":{\"match_all\":{}}}";
- String tmpconfigcontent2 = "aai=off" + LR + "aaiHeaders=[]" + LR + "database=http://" + HOST + ":" + PORT + LR
- + "insecure=1" + LR + "cors=1";
- HelpEsServlet servlet = new HelpEsServlet();
- this.setServlet(servlet);
- HelpEsServlet.registerRequestCallback("/mwtn/mediator-server", new IRequestCallback() {
-
- @Override
- public void onRequest(String uri, String method) {
- hasCallback=true;
-
- }
- });
- properties.load(new ByteArrayInputStream(tmpconfigcontent2.getBytes()));
- testrequest("/database/mwtn/mediator-server/_search",HTTPMETHOD_POST, query, HelpEsServlet.RESPONSE_POST, true);
- int wait=10;
- while(wait-->0) {
- if(hasCallback) {
- break;
- }
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- Thread.interrupted();
- }
- }
- assertTrue("no request callback received",hasCallback);
- hasCallback=false;
- testrequest("/database/mwtn/mediatr-server/_search",HTTPMETHOD_POST, query, HelpEsServlet.RESPONSE_POST, true);
- wait=5;
- while(wait-->0) {
- if(hasCallback) {
- break;
- }
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- Thread.interrupted();
- }
- }
- assertFalse("received request callback",hasCallback);
-
-
-
- if (tmpFile.exists())
- tmpFile.delete();
-
-
- }
- @Before
- public void init() throws IOException{
- HelpServletBase.initEsTestWebserver(PORT,"/database");
- }
- @After
- public void deinit() {
- HelpServletBase.stopTestWebserver();
- }
-
-}
diff --git a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpMsServlet.java b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpMsServlet.java
deleted file mode 100644
index 344dff671..000000000
--- a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpMsServlet.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP : CCSDK.apps.sdnr.wt.apigateway
- * ================================================================================
- * Copyright (C) 2018 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.apigateway.test.helper;
-
-import java.io.IOException;
-import java.util.Map;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.onap.ccsdk.features.sdnr.wt.apigateway.MsServlet;
-import org.onap.ccsdk.features.sdnr.wt.apigateway.database.MediatorServerInfo;
-
-public class HelpMsServlet extends MsServlet implements IPublicServlet {
-
- public static final String RESPONSE_GET = "This is the response get";
- public static final String RESPONSE_POST = "This is the response post";
- public static final String RESPONSE_PUT = "This is the response put";
- public static final String RESPONSE_DELETE = "This is the response delete";
- public static final String RESPONSE_OPTIONS = "This is the response options";
- private boolean offline = true;
- private String baseurl;
-
- @Override
- public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- super.doGet(req, resp);
- }
-
- @Override
- public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- super.doPost(req, resp);
- }
-
- @Override
- public void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- super.doPut(req, resp);
- }
-
- @Override
- public void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- super.doOptions(req, resp);
- }
-
- @Override
- public void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- super.doDelete(req, resp);
- }
-
- public void setOfflineStatus(boolean offline) {
- this.offline = offline;
- }
-
- public void setBaseUrl(String url) {
- this.baseurl = url;
- }
-
- @Override
- protected boolean isOff() {
- return this.offline;
- }
-
- @Override
- protected String getBaseUrl(String dbServerId) {
- return this.baseurl;
- }
- public void setMediatorEntries(Map<String, MediatorServerInfo> entries) {
- this.getEntryProvider().setEntries(entries);
- }
-}