1 package org.onap.so.client.sdnc;
3 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
4 import static com.github.tomakehurst.wiremock.client.WireMock.get;
5 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
6 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
7 import static org.hamcrest.CoreMatchers.equalTo;
8 import static org.junit.Assert.assertThat;
12 import javax.ws.rs.core.UriBuilder;
14 import org.junit.Rule;
15 import org.junit.Test;
16 import org.springframework.core.ParameterizedTypeReference;
18 import com.github.tomakehurst.wiremock.junit.WireMockRule;
20 import wiremock.org.apache.http.entity.ContentType;
21 public class BaseClientTest {
25 public WireMockRule wm = new WireMockRule(options().dynamicPort());
28 public void verifyString() {
29 BaseClient<String, String> client = new BaseClient<>();
30 String response = "{\"hello\" : \"world\"}";
31 client.setTargetUrl(UriBuilder.fromUri("http://localhost/test").port(wm.port()).build().toString());
32 wm.stubFor(get(urlEqualTo("/test"))
33 .willReturn(aResponse().withStatus(200).withBody(response).withHeader("Content-Type", ContentType.APPLICATION_JSON.toString())));
35 String result = client.get("", new ParameterizedTypeReference<String>() {});
36 assertThat(result, equalTo(response));
40 public void verifyMap() {
41 BaseClient<String, Map<String, Object>> client = new BaseClient<>();
42 String response = "{\"hello\" : \"world\"}";
43 client.setTargetUrl(UriBuilder.fromUri("http://localhost/test").port(wm.port()).build().toString());
44 wm.stubFor(get(urlEqualTo("/test"))
45 .willReturn(aResponse().withStatus(200).withBody(response).withHeader("Content-Type", ContentType.APPLICATION_JSON.toString())));
47 Map<String, Object> result = client.get("", new ParameterizedTypeReference<Map<String, Object>>() {});
48 assertThat("world", equalTo(result.get("hello")));