diff options
author | m.miernik <m.miernik@samsung.com> | 2021-06-25 08:28:31 +0200 |
---|---|---|
committer | m.miernik <m.miernik@samsung.com> | 2021-06-25 08:30:05 +0200 |
commit | 410cfa4eb6ff554aebb28633a7fc253c8c2b3649 (patch) | |
tree | 515f1d685e5db780deeecd4fa5b7a20990c79b47 /sdnr/wt/apigateway/provider/src | |
parent | cb7e5aa3c0445882a2bc04222573c1563b98117b (diff) |
Add unit tests for apigateway
Add unit tests for TilesServlet.java and TopologyServlet.java
Issue-ID: SDNC-1579
Change-Id: I4fd1da6c425d9ecf22d0b85e550d866130c0efef
Signed-off-by: m.miernik <m.miernik@samsung.com>
Diffstat (limited to 'sdnr/wt/apigateway/provider/src')
4 files changed, 291 insertions, 0 deletions
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 new file mode 100644 index 000000000..d7adf2fbb --- /dev/null +++ b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestTilesServlet.java @@ -0,0 +1,85 @@ +/* + * ============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, HelpTilesServlet.RESPONSE_GET, true); + testrequest(HTTPMETHOD_POST, query, HelpTilesServlet.RESPONSE_POST, true); + testrequest(HTTPMETHOD_PUT, query, HelpTilesServlet.RESPONSE_PUT, true); + testrequest(HTTPMETHOD_DELETE, query, HelpTilesServlet.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 new file mode 100644 index 000000000..08d19b4ee --- /dev/null +++ b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/TestTopologyServlet.java @@ -0,0 +1,84 @@ +/* + * ============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, HelpTopologyServlet.RESPONSE_GET, true); + testrequest(HTTPMETHOD_POST, query, HelpTopologyServlet.RESPONSE_POST, true); + testrequest(HTTPMETHOD_PUT, query, HelpTopologyServlet.RESPONSE_PUT, true); + testrequest(HTTPMETHOD_DELETE, query, HelpTopologyServlet.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/HelpTilesServlet.java b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpTilesServlet.java new file mode 100644 index 000000000..e847b289e --- /dev/null +++ b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpTilesServlet.java @@ -0,0 +1,61 @@ +/* + * ============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; + 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"; + + @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 new file mode 100644 index 000000000..2532fe0bc --- /dev/null +++ b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpTopologyServlet.java @@ -0,0 +1,61 @@ +/* + * ============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; + 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"; + + @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); + } +} |