e24ca339a329e010262febbf2b0da00fd2ddb216
[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.post;
26 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
27 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
28 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
29
30 import java.io.IOException;
31 import java.nio.file.Files;
32 import java.nio.file.Paths;
33
34 import org.junit.Rule;
35 import org.junit.Test;
36 import org.onap.so.bpmn.BaseTaskTest;
37 import org.onap.so.client.exception.BadResponseException;
38 import org.onap.so.client.exception.MapperException;
39 import org.onap.so.client.sdnc.endpoint.SDNCTopology;
40 import org.skyscreamer.jsonassert.JSONAssert;
41
42 import com.github.tomakehurst.wiremock.junit.WireMockRule;
43
44 public class SDNCClientTest extends BaseTaskTest {
45         private final static String JSON_FILE_LOCATION = "src/test/resources/__files/";
46         
47         @Rule
48     public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(8446)); 
49         
50     @Test
51     public void getTest() throws BadResponseException, MapperException, IOException {
52         String responseJson =  new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientGetResponse.json")));
53         String queryLink = "/topologyQuery";            
54                                      
55         wireMockRule.stubFor(get(urlEqualTo(queryLink))
56                 .willReturn(aResponse().withStatus(200)
57                         .withHeader("Content-Type", "application/json").withBody(responseJson)));
58         String response = SPY_sdncClient.get(queryLink);
59         JSONAssert.assertEquals(responseJson, response, false);
60     }
61     
62     @Test(expected = BadResponseException.class)
63     public void post404Test() throws BadResponseException, MapperException, IOException {
64         String responseJson =  new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientPut404Response.json")));
65         
66         String queryLink = "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/";
67                         
68         wireMockRule.stubFor(post(urlMatching(queryLink))
69                 .willReturn(aResponse().withStatus(200)
70                         .withHeader("Content-Type", "application/json").withBody(responseJson)));
71         
72         SPY_sdncClient.post("", SDNCTopology.NETWORK);
73     }
74     
75     @Test
76     public void post200Test() throws BadResponseException, MapperException, IOException {
77         String responseJson =  new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientPut200Response.json")));
78         
79         String queryLink = "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/";
80                         
81         wireMockRule.stubFor(post(urlMatching(queryLink))
82                 .willReturn(aResponse().withStatus(200)
83                         .withHeader("Content-Type", "application/json").withBody(responseJson)));
84         
85         String response = SPY_sdncClient.post("", SDNCTopology.NETWORK);
86         JSONAssert.assertEquals("", response, false);
87     }
88 }