[CCSDK-1985]GR Toolkit Refactor
[ccsdk/sli/plugins.git] / grToolkit / provider / src / test / java / org / onap / ccsdk / sli / plugins / grtoolkit / connection / ConnectionManagerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights
6  *                      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
22 package org.onap.ccsdk.sli.plugins.grtoolkit.connection;
23
24 import com.github.tomakehurst.wiremock.junit.WireMockRule;
25
26 import org.junit.Rule;
27 import org.junit.Test;
28
29 import static org.junit.Assert.*;
30
31 import static com.github.tomakehurst.wiremock.client.WireMock.*;
32
33 public class ConnectionManagerTest {
34     @Rule
35     public WireMockRule wireMockRule = new WireMockRule(9999);
36
37     @Test
38     public void getConnectionResponseWithInput() throws Exception {
39         stubFor(post(urlEqualTo("/post"))
40                         .willReturn(aResponse().withStatus(200)));
41         ConnectionResponse response = ConnectionManager.getConnectionResponse("http://localhost:9999/post", ConnectionManager.HttpMethod.POST, "", "creds:creds");
42         assertNotNull(response);
43         assertEquals(200, response.statusCode);
44     }
45
46     @Test
47     public void getConnectionResponseWithCredentials() throws Exception {
48         stubFor(post(urlEqualTo("/post"))
49                         .willReturn(aResponse().withStatus(200)));
50         ConnectionResponse response = ConnectionManager.getConnectionResponse("http://localhost:9999/post", ConnectionManager.HttpMethod.POST, "", "creds:creds");
51         assertNotNull(response);
52         assertEquals(200, response.statusCode);
53     }
54
55     @Test
56     public void getConnectionResponse() throws Exception {
57         stubFor(get(urlEqualTo("/get"))
58                         .willReturn(aResponse().withStatus(200)
59                         .withBody("Multi\nLine\nResponse")));
60         ConnectionResponse response = ConnectionManager.getConnectionResponse("http://localhost:9999/get", ConnectionManager.HttpMethod.GET, null, null);
61         assertNotNull(response);
62         assertEquals(200, response.statusCode);
63         assertEquals("MultiLineResponse", response.content);
64     }
65 }