fd76be7af1765112bb1ee2c9a27d9d4b05c00c0f
[ccsdk/features.git] / sdnr / wt / apigateway / provider / src / test / java / org / onap / ccsdk / features / sdnr / wt / apigateway / test / TestAaiServlet.java
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.HelpAaiServlet;
32 import org.onap.ccsdk.features.sdnr.wt.apigateway.test.helper.HelpEsServlet;
33 import org.onap.ccsdk.features.sdnr.wt.apigateway.test.helper.HelpServletBase;
34
35 public class TestAaiServlet extends HelpServletBase{
36
37         public TestAaiServlet() {
38                 super("/aai",40001);
39         }
40         
41         @Test
42         public void test() throws ServletException, IOException {
43                 
44                 String tmpFilename = "tmp.cfg";
45                 File tmpFile = new File(tmpFilename);
46                 if (tmpFile.exists())
47                         tmpFile.delete();
48                 MyProperties properties = MyProperties.Instantiate(tmpFile,true);
49                 String query = "{\"query\":{\"match_all\":{}}}";
50                 String tmpconfigcontent = "aai=off" + LR + "aaiHeaders=[]" + LR + "database=off" + LR + "insecure=0" + LR
51                                 + "cors=0";
52                 String tmpconfigcontent2 = "aai=http://" + HOST + ":" + this.port + LR + "aaiHeaders=[]" + LR + "database=off"+ LR
53                                 + "insecure=1" + LR + "cors=1";
54                 this.setServlet(new HelpAaiServlet());
55                 // test diabled message
56                 properties.load(new ByteArrayInputStream(tmpconfigcontent.getBytes()));
57                 String expectedResponse = "offline";
58                 testrequest(HTTPMETHOD_GET, query, expectedResponse, false);
59                 testrequest(HTTPMETHOD_POST, query, expectedResponse, false);
60                 testrequest(HTTPMETHOD_PUT, query, expectedResponse, false);
61                 testrequest(HTTPMETHOD_DELETE, query, expectedResponse, false);
62                 
63                 // initEsTestWebserver(port);
64                 properties.load(new ByteArrayInputStream(tmpconfigcontent2.getBytes()));
65                 testrequest(HTTPMETHOD_GET, query, HelpEsServlet.RESPONSE_GET, true);
66                 testrequest(HTTPMETHOD_POST, query, HelpEsServlet.RESPONSE_POST, true);
67                 testrequest(HTTPMETHOD_PUT, query, HelpEsServlet.RESPONSE_PUT, true);
68                 testrequest(HTTPMETHOD_DELETE, query, HelpEsServlet.RESPONSE_DELETE, true);
69                 testrequest(HTTPMETHOD_OPTIONS, query, "", false);
70                 // stopTestWebserver();
71                 if (tmpFile.exists())
72                         tmpFile.delete();
73                 
74         }
75
76 }