2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.client.sdnc;
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;
30 import java.io.IOException;
31 import java.nio.file.Files;
32 import java.nio.file.Paths;
34 import org.junit.Rule;
35 import org.junit.Test;
36 import org.onap.so.BaseIntegrationTest;
37 import org.onap.so.bpmn.BaseTaskTest;
38 import org.onap.so.client.exception.BadResponseException;
39 import org.onap.so.client.exception.MapperException;
40 import org.onap.so.client.sdnc.endpoint.SDNCTopology;
41 import org.skyscreamer.jsonassert.JSONAssert;
43 import com.github.tomakehurst.wiremock.junit.WireMockRule;
45 public class SDNCClientTest extends BaseIntegrationTest {
46 private final static String JSON_FILE_LOCATION = "src/test/resources/__files/";
49 public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(8446));
52 public void getTest() throws BadResponseException, MapperException, IOException {
53 String responseJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientGetResponse.json")));
54 String queryLink = "/topologyQuery";
56 wireMockRule.stubFor(get(urlEqualTo(queryLink))
57 .willReturn(aResponse().withStatus(200)
58 .withHeader("Content-Type", "application/json").withBody(responseJson)));
59 String response = SPY_sdncClient.get(queryLink);
60 JSONAssert.assertEquals(responseJson, response, false);
63 @Test(expected = BadResponseException.class)
64 public void post404Test() throws BadResponseException, MapperException, IOException {
65 String responseJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientPut404Response.json")));
67 String queryLink = "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/";
69 wireMockRule.stubFor(post(urlMatching(queryLink))
70 .willReturn(aResponse().withStatus(200)
71 .withHeader("Content-Type", "application/json").withBody(responseJson)));
73 SPY_sdncClient.post("", SDNCTopology.NETWORK);
77 public void post200Test() throws BadResponseException, MapperException, IOException {
78 String responseJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientPut200Response.json")));
80 String queryLink = "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/";
82 wireMockRule.stubFor(post(urlMatching(queryLink))
83 .willReturn(aResponse().withStatus(200)
84 .withHeader("Content-Type", "application/json").withBody(responseJson)));
86 String response = SPY_sdncClient.post("", SDNCTopology.NETWORK);
87 JSONAssert.assertEquals("", response, false);