diff options
author | 2021-07-30 10:27:03 +0530 | |
---|---|---|
committer | 2021-07-30 10:27:45 +0530 | |
commit | 0c8d2c3d7dfd79a25107480af718d3d76cd45f39 (patch) | |
tree | 5b41bdc44fcee689bd1f3dfaba48354f4953d1df /sdnr/wt/apigateway/provider/src/test | |
parent | e4f3ee3ce9264c6ca41928e49c3075d4ca99eb0f (diff) |
Refactor unit tests
Refactor unit tests for apigateway
Issue-ID: CCSDK-3402
Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Change-Id: Ib5e5eb522a77d1df4a5a8feccc5c9e7d8a942b83
Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/apigateway/provider/src/test')
9 files changed, 33 insertions, 305 deletions
diff --git a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestAaiServlet.java b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestAaiServlet.java index 200949ec2..3436c36f2 100644 --- a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestAaiServlet.java +++ b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestAaiServlet.java @@ -29,6 +29,7 @@ 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.test.helper.HelpAaiServlet; +import org.onap.ccsdk.features.sdnr.wt.apigateway.test.helper.HelpEsServlet; import org.onap.ccsdk.features.sdnr.wt.apigateway.test.helper.HelpServletBase; public class TestAaiServlet extends HelpServletBase { @@ -63,10 +64,10 @@ public class TestAaiServlet extends HelpServletBase { // initEsTestWebserver(port); properties.load(new ByteArrayInputStream(tmpconfigcontent2.getBytes())); - testrequest(HTTPMETHOD_GET, query, RESPONSE_GET, true); - testrequest(HTTPMETHOD_POST, query, RESPONSE_POST, true); - testrequest(HTTPMETHOD_PUT, query, RESPONSE_PUT, true); - testrequest(HTTPMETHOD_DELETE, query, RESPONSE_DELETE, true); + testrequest(HTTPMETHOD_GET, query, HelpEsServlet.RESPONSE_GET, true); + testrequest(HTTPMETHOD_POST, query, HelpEsServlet.RESPONSE_POST, true); + testrequest(HTTPMETHOD_PUT, query, HelpEsServlet.RESPONSE_PUT, true); + testrequest(HTTPMETHOD_DELETE, query, HelpEsServlet.RESPONSE_DELETE, true); testrequest(HTTPMETHOD_OPTIONS, query, "", false); // stopTestWebserver(); if (tmpFile.exists()) diff --git a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestDatabaseServlet.java b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestDatabaseServlet.java index 7067bbeef..45eac88cd 100644 --- a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestDatabaseServlet.java +++ b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestDatabaseServlet.java @@ -37,8 +37,12 @@ public class TestDatabaseServlet extends HelpServletBase { super("/database", PORT); } + + final String LR = "\n"; + + @Test public void test() throws ServletException, IOException { @@ -63,10 +67,10 @@ public class TestDatabaseServlet extends HelpServletBase { // initEsTestWebserver(port); properties.load(new ByteArrayInputStream(tmpconfigcontent2.getBytes())); - testrequest(HTTPMETHOD_GET, query, RESPONSE_GET, true); - testrequest(HTTPMETHOD_POST, query, RESPONSE_POST, true); - testrequest(HTTPMETHOD_PUT, query, RESPONSE_PUT, true); - testrequest(HTTPMETHOD_DELETE, query, RESPONSE_DELETE, true); + testrequest(HTTPMETHOD_GET, query, HelpEsServlet.RESPONSE_GET, true); + testrequest(HTTPMETHOD_POST, query, HelpEsServlet.RESPONSE_POST, true); + testrequest(HTTPMETHOD_PUT, query, HelpEsServlet.RESPONSE_PUT, true); + testrequest(HTTPMETHOD_DELETE, query, HelpEsServlet.RESPONSE_DELETE, true); testrequest(HTTPMETHOD_OPTIONS, query, "", false); // stopTestWebserver(); diff --git a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestTilesServlet.java b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestTilesServlet.java deleted file mode 100644 index 30ec53d4d..000000000 --- a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestTilesServlet.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP : CCSDK.apps.sdnr.wt.apigateway - * ================================================================================ - * 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 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.MyProperties; -import org.onap.ccsdk.features.sdnr.wt.apigateway.test.helper.HelpServletBase; -import org.onap.ccsdk.features.sdnr.wt.apigateway.test.helper.HelpTilesServlet; - -public class TestTilesServlet extends HelpServletBase { - - private static final int PORT = 40001; - - public TestTilesServlet() { - super("/tiles", PORT); - } - - - @Test - public void test() throws ServletException, IOException { - String tmpFilename = "tmp.cfg"; - File tmpFile = new File(tmpFilename); - if (tmpFile.exists()) - tmpFile.delete(); - MyProperties properties = MyProperties.Instantiate(tmpFile, true); - String query = "{\"query\":{\"match_all\":{}}}"; - String tmpconfigcontent = "aai=off" + LR + "aaiHeaders=[]" + LR + "database=off" + LR + "tiles=off" + LR - + "insecure=0" + LR + "cors=0"; - String tmpconfigcontent2 = "aai=off" + LR + "aaiHeaders=[]" + LR + "database=off" + LR - + "tiles=http://" + HOST + ":" + PORT + LR + "insecure=1" + LR + "cors=1"; - this.setServlet(new HelpTilesServlet()); - // test disabled message - properties.load(new ByteArrayInputStream(tmpconfigcontent.getBytes())); - 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); - - // initEsTestWebserver(port); - properties.load(new ByteArrayInputStream(tmpconfigcontent2.getBytes())); - testrequest(HTTPMETHOD_GET, query, RESPONSE_GET, true); - testrequest(HTTPMETHOD_POST, query, RESPONSE_POST, true); - testrequest(HTTPMETHOD_PUT, query, RESPONSE_PUT, true); - testrequest(HTTPMETHOD_DELETE, query, RESPONSE_DELETE, true); - testrequest(HTTPMETHOD_OPTIONS, query, "", false); - // stopTestWebserver(); - if (tmpFile.exists()) - tmpFile.delete(); - } - - @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/TestTopologyServlet.java b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestTopologyServlet.java deleted file mode 100644 index 9b9692388..000000000 --- a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestTopologyServlet.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP : CCSDK.apps.sdnr.wt.apigateway - * ================================================================================ - * 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 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.MyProperties; -import org.onap.ccsdk.features.sdnr.wt.apigateway.test.helper.HelpServletBase; -import org.onap.ccsdk.features.sdnr.wt.apigateway.test.helper.HelpTopologyServlet; - -public class TestTopologyServlet extends HelpServletBase { - - private static final int PORT = 40001; - - public TestTopologyServlet() { - super("/topology", PORT); - } - - @Test - public void test() throws ServletException, IOException { - String tmpFilename = "tmp.cfg"; - File tmpFile = new File(tmpFilename); - if (tmpFile.exists()) - tmpFile.delete(); - MyProperties properties = MyProperties.Instantiate(tmpFile, true); - String query = "{\"query\":{\"match_all\":{}}}"; - String tmpconfigcontent = "aai=off" + LR + "aaiHeaders=[]" + LR + "database=off" + LR + "tiles=off" + LR - + "topology=off" + LR + "insecure=0" + LR + "cors=0"; - String tmpconfigcontent2 = "aai=off" + LR + "aaiHeaders=[]" + LR + "database=off" + LR + "tiles=off" + LR - + "topology=http://" + HOST + ":" + PORT + LR + "insecure=1" + LR + "cors=1"; - this.setServlet(new HelpTopologyServlet()); - // test disabled message - properties.load(new ByteArrayInputStream(tmpconfigcontent.getBytes())); - 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); - - // initEsTestWebserver(port); - properties.load(new ByteArrayInputStream(tmpconfigcontent2.getBytes())); - testrequest(HTTPMETHOD_GET, query, RESPONSE_GET, true); - testrequest(HTTPMETHOD_POST, query, RESPONSE_POST, true); - testrequest(HTTPMETHOD_PUT, query, RESPONSE_PUT, true); - testrequest(HTTPMETHOD_DELETE, query, RESPONSE_DELETE, true); - testrequest(HTTPMETHOD_OPTIONS, query, "", false); - // stopTestWebserver(); - if (tmpFile.exists()) - tmpFile.delete(); - } - - @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/helper/HelpAaiServlet.java b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpAaiServlet.java index 513fe0e57..5d4c8f507 100644 --- a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpAaiServlet.java +++ b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpAaiServlet.java @@ -29,6 +29,11 @@ import org.onap.ccsdk.features.sdnr.wt.apigateway.AaiServlet; public class HelpAaiServlet extends AaiServlet implements IPublicServlet { private static final long serialVersionUID = 1L; + 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"; @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { diff --git a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpEsServlet.java b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpEsServlet.java index 8e031e9a9..fe89c9fc4 100644 --- a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpEsServlet.java +++ b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpEsServlet.java @@ -30,6 +30,12 @@ public class HelpEsServlet extends EsServlet implements IPublicServlet { private static final long serialVersionUID = 6502905928958752573L; + 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"; + @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { super.doGet(req, resp); diff --git a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpServletBase.java b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpServletBase.java index f0247c031..4048012bb 100644 --- a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpServletBase.java +++ b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpServletBase.java @@ -52,11 +52,6 @@ public class HelpServletBase { public static final String HTTPMETHOD_PUT = "PUT"; public static final String HTTPMETHOD_DELETE = "DELETE"; public static final String HTTPMETHOD_OPTIONS = "OPTIONS"; - 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 IPublicServlet servlet; private static HttpServer server; private static ExecutorService httpThreadPool; @@ -175,23 +170,23 @@ public class HelpServletBase { OutputStream os = null; try { if (method.equals(HTTPMETHOD_GET)) { - t.sendResponseHeaders(200, RESPONSE_GET.length()); + t.sendResponseHeaders(200, HelpEsServlet.RESPONSE_GET.length()); os = t.getResponseBody(); - os.write(RESPONSE_GET.getBytes()); + os.write(HelpEsServlet.RESPONSE_GET.getBytes()); } else if (method.equals(HTTPMETHOD_POST)) { - t.sendResponseHeaders(200, RESPONSE_POST.length()); + t.sendResponseHeaders(200, HelpEsServlet.RESPONSE_POST.length()); os = t.getResponseBody(); - os.write(RESPONSE_POST.getBytes()); + os.write(HelpEsServlet.RESPONSE_POST.getBytes()); } else if (method.equals(HTTPMETHOD_PUT)) { - t.sendResponseHeaders(200, RESPONSE_PUT.length()); + t.sendResponseHeaders(200, HelpEsServlet.RESPONSE_PUT.length()); os = t.getResponseBody(); - os.write(RESPONSE_PUT.getBytes()); + os.write(HelpEsServlet.RESPONSE_PUT.getBytes()); } else if (method.equals(HTTPMETHOD_DELETE)) { - t.sendResponseHeaders(200, RESPONSE_DELETE.length()); + t.sendResponseHeaders(200, HelpEsServlet.RESPONSE_DELETE.length()); os = t.getResponseBody(); - os.write(RESPONSE_DELETE.getBytes()); + os.write(HelpEsServlet.RESPONSE_DELETE.getBytes()); } else if (method.equals(HTTPMETHOD_OPTIONS)) { - t.sendResponseHeaders(200, RESPONSE_OPTIONS.length()); + t.sendResponseHeaders(200, HelpEsServlet.RESPONSE_OPTIONS.length()); //os = t.getResponseBody(); //os.write(RESPONSE_OPTIONS.getBytes()); } else { diff --git a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpTilesServlet.java b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpTilesServlet.java deleted file mode 100644 index cae5d93b9..000000000 --- a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpTilesServlet.java +++ /dev/null @@ -1,57 +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 javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.onap.ccsdk.features.sdnr.wt.apigateway.TilesServlet; - -public class HelpTilesServlet extends TilesServlet implements IPublicServlet { - - private static final long serialVersionUID = 1L; - - @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); - } -} diff --git a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpTopologyServlet.java b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpTopologyServlet.java deleted file mode 100644 index 18c6d9ffe..000000000 --- a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpTopologyServlet.java +++ /dev/null @@ -1,57 +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 javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.onap.ccsdk.features.sdnr.wt.apigateway.TopologyServlet; - -public class HelpTopologyServlet extends TopologyServlet implements IPublicServlet { - - private static final long serialVersionUID = 1L; - - @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); - } -} |