7fa20f7886ffbda237b686423b65458c01ab5c22
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START======================================================= ONAP :
3  * CCSDK.apps.sdnr.wt.apigateway
4  * ================================================================================ Copyright (C)
5  * 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * ================================================================================ Licensed under
7  * the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License. ============LICENSE_END=========================================================
16  */
17 package org.onap.ccsdk.features.sdnr.wt.apigateway.test;
18
19 import java.io.File;
20 import java.io.IOException;
21 import javax.servlet.ServletException;
22 import org.junit.Test;
23 import org.onap.ccsdk.features.sdnr.wt.apigateway.MyProperties;
24 import org.onap.ccsdk.features.sdnr.wt.apigateway.test.helper.HelpMsServlet;
25 import org.onap.ccsdk.features.sdnr.wt.apigateway.test.helper.HelpServletBase;
26
27 public class TestMediatorServerServlet extends HelpServletBase {
28
29     private static final int PORT = 40004;
30
31     public TestMediatorServerServlet() {
32         super("/ms", PORT);
33     }
34
35     @Test
36     public void test() throws ServletException, IOException {
37
38         String tmpFilename = "tmp3.cfg";
39         File tmpFile = new File(tmpFilename);
40         if (tmpFile.exists()) {
41             tmpFile.delete();
42         }
43         MyProperties.Instantiate(tmpFile, true);
44         String query = "{\"query\":{\"match_all\":{}}}";
45         HelpMsServlet servlet = new HelpMsServlet();
46         this.setServlet(servlet);
47         // test diabled message
48         servlet.setOfflineStatus(true);
49         servlet.setBaseUrl("http://localhost:" + PORT);
50         String expectedResponse = "offline";
51         testrequest(HTTPMETHOD_GET, query, expectedResponse, false);
52         testrequest(HTTPMETHOD_POST, query, expectedResponse, false);
53         testrequest(HTTPMETHOD_PUT, query, expectedResponse, false);
54         testrequest(HTTPMETHOD_DELETE, query, expectedResponse, false);
55
56         servlet.setOfflineStatus(false);
57         testrequest(HTTPMETHOD_GET, query, HelpMsServlet.RESPONSE_GET, true);
58         testrequest(HTTPMETHOD_POST, query, HelpMsServlet.RESPONSE_POST, true);
59         testrequest(HTTPMETHOD_PUT, query, HelpMsServlet.RESPONSE_PUT, true);
60         testrequest(HTTPMETHOD_DELETE, query, HelpMsServlet.RESPONSE_DELETE, true);
61         testrequest(HTTPMETHOD_OPTIONS, query, "", false);
62
63         if (tmpFile.exists()) {
64             tmpFile.delete();
65         }
66
67     }
68
69 }