1 /*******************************************************************************
2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
17 ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.apigateway.test;
20 import static org.junit.Assert.*;
22 import java.io.ByteArrayInputStream;
24 import java.io.IOException;
26 import javax.servlet.ServletException;
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.onap.ccsdk.features.sdnr.wt.apigateway.EsServlet.IRequestCallback;
32 import org.onap.ccsdk.features.sdnr.wt.apigateway.MyProperties;
33 import org.onap.ccsdk.features.sdnr.wt.apigateway.test.helper.HelpEsServlet;
34 import org.onap.ccsdk.features.sdnr.wt.apigateway.test.helper.HelpServletBase;
36 public class TestQueryCallback extends HelpServletBase{
38 private static final int PORT = 40011;
40 public TestQueryCallback() {
41 super("/database",PORT);
44 final String LR = "\n";
47 private boolean hasCallback=false;
50 public void test() throws ServletException, IOException {
52 String tmpFilename = "tmp1.cfg";
53 File tmpFile = new File(tmpFilename);
56 MyProperties properties = MyProperties.Instantiate(tmpFile,true);
57 String query = "{\"query\":{\"match_all\":{}}}";
58 String tmpconfigcontent2 = "aai=off" + LR + "aaiHeaders=[]" + LR + "database=http://" + HOST + ":" + PORT + LR
59 + "insecure=1" + LR + "cors=1";
60 HelpEsServlet servlet = new HelpEsServlet();
61 this.setServlet(servlet);
62 HelpEsServlet.registerRequestCallback("/mwtn/mediator-server", new IRequestCallback() {
65 public void onRequest(String uri, String method) {
70 properties.load(new ByteArrayInputStream(tmpconfigcontent2.getBytes()));
71 testrequest("/database/mwtn/mediator-server/_search",HTTPMETHOD_POST, query, HelpEsServlet.RESPONSE_POST, true);
79 } catch (InterruptedException e) {
83 assertTrue("no request callback received",hasCallback);
85 testrequest("/database/mwtn/mediatr-server/_search",HTTPMETHOD_POST, query, HelpEsServlet.RESPONSE_POST, true);
93 } catch (InterruptedException e) {
97 assertFalse("received request callback",hasCallback);
101 if (tmpFile.exists())
107 public void init() throws IOException{
108 HelpServletBase.initEsTestWebserver(PORT,"/database");
111 public void deinit() {
112 HelpServletBase.stopTestWebserver();