2  * ============LICENSE_START=======================================================
 
   3  * ONAP : CCSDK.apps.sdnr.wt.apigateway
 
   4  * ================================================================================
 
   5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
 
   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
 
  12  *      http://www.apache.org/licenses/LICENSE-2.0
 
  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=========================================================
 
  21 package org.onap.ccsdk.features.sdnr.wt.apigateway.test;
 
  23 import java.io.ByteArrayInputStream;
 
  25 import java.io.IOException;
 
  26 import javax.servlet.ServletException;
 
  27 import org.junit.After;
 
  28 import org.junit.Before;
 
  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.HelpServletBase;
 
  32 import org.onap.ccsdk.features.sdnr.wt.apigateway.test.helper.HelpTilesServlet;
 
  34 public class TestTilesServlet extends HelpServletBase {
 
  36     private static final int PORT = 40001;
 
  38     public TestTilesServlet() {
 
  39         super("/tiles", PORT);
 
  44     public void test() throws ServletException, IOException {
 
  45         String tmpFilename = "tmp.cfg";
 
  46         File tmpFile = new File(tmpFilename);
 
  49         MyProperties properties = MyProperties.Instantiate(tmpFile, true);
 
  50         String query = "{\"query\":{\"match_all\":{}}}";
 
  51         String tmpconfigcontent = "aai=off" + LR + "aaiHeaders=[]" + LR + "database=off" + LR + "tiles=off" + LR
 
  52             + "insecure=0" + LR + "cors=0";
 
  53         String tmpconfigcontent2 = "aai=off" + LR + "aaiHeaders=[]" + LR + "database=off" + LR
 
  54             + "tiles=http://" + HOST + ":" + PORT + LR + "insecure=1" + LR + "cors=1";
 
  55         this.setServlet(new HelpTilesServlet());
 
  56         // test disabled message
 
  57         properties.load(new ByteArrayInputStream(tmpconfigcontent.getBytes()));
 
  58         String expectedResponse = "offline";
 
  59         testrequest(HTTPMETHOD_GET, query, expectedResponse, false);
 
  60         testrequest(HTTPMETHOD_POST, query, expectedResponse, false);
 
  61         testrequest(HTTPMETHOD_PUT, query, expectedResponse, false);
 
  62         testrequest(HTTPMETHOD_DELETE, query, expectedResponse, false);
 
  64         // initEsTestWebserver(port);
 
  65         properties.load(new ByteArrayInputStream(tmpconfigcontent2.getBytes()));
 
  66         testrequest(HTTPMETHOD_GET, query, HelpTilesServlet.RESPONSE_GET, true);
 
  67         testrequest(HTTPMETHOD_POST, query, HelpTilesServlet.RESPONSE_POST, true);
 
  68         testrequest(HTTPMETHOD_PUT, query, HelpTilesServlet.RESPONSE_PUT, true);
 
  69         testrequest(HTTPMETHOD_DELETE, query, HelpTilesServlet.RESPONSE_DELETE, true);
 
  70         testrequest(HTTPMETHOD_OPTIONS, query, "", false);
 
  71         // stopTestWebserver();
 
  77     public void init() throws IOException {
 
  78         HelpServletBase.initEsTestWebserver(PORT);
 
  82     public void deinit() {
 
  83         HelpServletBase.stopTestWebserver();