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