24926385209e0f97215955fd73a4633a30362283
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / client / sdnc / SDNCClientTest.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.urlEqualTo;
26 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
27
28 import java.io.IOException;
29 import java.nio.file.Files;
30 import java.nio.file.Paths;
31
32 import org.junit.Rule;
33 import org.junit.Test;
34 import org.onap.so.bpmn.BaseTaskTest;
35 import org.onap.so.client.exception.BadResponseException;
36 import org.onap.so.client.exception.MapperException;
37 import org.skyscreamer.jsonassert.JSONAssert;
38
39 import com.github.tomakehurst.wiremock.junit.WireMockRule;
40
41 public class SDNCClientTest extends BaseTaskTest {
42         private final static String JSON_FILE_LOCATION = "src/test/resources/__files/";
43         
44         @Rule
45     public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(8446)); 
46         
47     @Test
48     public void getTest() throws BadResponseException, MapperException, IOException {
49         String responseJson =  new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientGetResponse.json")));
50         String queryLink = "/topologyQuery";            
51                                      
52         wireMockRule.stubFor(get(urlEqualTo(queryLink))
53                 .willReturn(aResponse().withStatus(200)
54                         .withHeader("Content-Type", "application/json").withBody(responseJson)));
55         String response = SPY_sdncClient.get(queryLink);
56         JSONAssert.assertEquals(responseJson, response, false);
57     }
58 }