update old version
[ccsdk/features.git] / sdnr / wt / apigateway / provider / src / test / java / org / onap / ccsdk / features / sdnr / wt / apigateway / test / TestHttpClient.java
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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
15  * the License.
16  * ============LICENSE_END==========================================================================
17  ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.apigateway.test;
19
20 import static org.junit.Assert.fail;
21
22 import java.io.IOException;
23 import java.util.HashMap;
24 import java.util.Map;
25
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.onap.ccsdk.features.sdnr.wt.apigateway.database.http.BaseHTTPClient;
30 import org.onap.ccsdk.features.sdnr.wt.apigateway.test.helper.HelpServletBase;
31
32 public class TestHttpClient {
33
34         private static final int PORT =40010;
35         private static final String BASEURI = "/test";
36         
37         private class TestBaseHTTPClient extends BaseHTTPClient {
38                 public TestBaseHTTPClient() {
39                         super(String.format("http://localhost:%s%s",PORT,BASEURI));
40                 }
41                 public void doTest() {
42                         String[] methods=new String[] {"GET","POST","PUT","DELETE"};
43                         Map<String, String> headers=new HashMap<String,String>();
44                         headers.put("Content-Type","application/json");
45                         headers.put("Authorization",BaseHTTPClient.getAuthorizationHeaderValue("admin","admin"));
46                         for(String method:methods) {
47                                 try {
48                                         this.sendRequest(String.format("%s%s", BASEURI,"/abc"), method, "abddef", headers);
49                                 } catch (IOException e) {
50                                         e.printStackTrace();
51                                         fail(String.format("problem with method %s: %s",method,e.getMessage()));
52                                 }
53                         }
54                 }
55         }
56         @Test
57         public void test() {
58                 TestBaseHTTPClient client = new TestBaseHTTPClient();
59                 client.doTest();
60         }       
61         
62         
63         @Before
64         public void init() throws IOException{  
65                 HelpServletBase.initEsTestWebserver(PORT);
66         }
67         @After
68         public void deinit() {
69                 HelpServletBase.stopTestWebserver();
70         }
71 }