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