replace all fixed wiremock ports
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / client / sdnc / SDNCClientIT.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.client.sdnc;
22
23 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.get;
25 import static com.github.tomakehurst.wiremock.client.WireMock.post;
26 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
27 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
28
29 import java.io.IOException;
30 import java.nio.file.Files;
31 import java.nio.file.Paths;
32
33 import org.junit.Test;
34 import org.onap.so.BaseIntegrationTest;
35 import org.onap.so.client.exception.BadResponseException;
36 import org.onap.so.client.exception.MapperException;
37 import org.onap.so.client.sdnc.endpoint.SDNCTopology;
38 import org.skyscreamer.jsonassert.JSONAssert;
39
40 public class SDNCClientIT extends BaseIntegrationTest {
41         private final static String JSON_FILE_LOCATION = "src/test/resources/__files/";
42         
43     @Test
44     public void getTest() throws BadResponseException, MapperException, IOException {
45         String responseJson =  new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientGetResponse.json")));
46         String queryLink = "/topologyQuery";            
47                                      
48         wireMockServer.stubFor(get(urlEqualTo(queryLink))
49                 .willReturn(aResponse().withStatus(200)
50                         .withHeader("Content-Type", "application/json").withBody(responseJson)));
51         String response = SPY_sdncClient.get(queryLink);
52         JSONAssert.assertEquals(responseJson, response, false);
53     }
54     
55     @Test(expected = BadResponseException.class)
56     public void post404Test() throws BadResponseException, MapperException, IOException {
57         String responseJson =  new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientPut404Response.json")));
58         
59         String queryLink = "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/";
60                         
61         wireMockServer.stubFor(post(urlMatching(queryLink))
62                 .willReturn(aResponse().withStatus(200)
63                         .withHeader("Content-Type", "application/json").withBody(responseJson)));
64         
65         SPY_sdncClient.post("", SDNCTopology.NETWORK);
66     }
67     
68     @Test
69     public void post200Test() throws BadResponseException, MapperException, IOException {
70         String responseJson =  new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientPut200Response.json")));
71         
72         String queryLink = "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/";
73                         
74         wireMockServer.stubFor(post(urlMatching(queryLink))
75                 .willReturn(aResponse().withStatus(200)
76                         .withHeader("Content-Type", "application/json").withBody(responseJson)));
77         
78         String response = SPY_sdncClient.post("", SDNCTopology.NETWORK);
79         JSONAssert.assertEquals(responseJson, response, true);
80     }
81 }