Adding rest service for so monitoring
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / client / sdnc / BaseClientTest.java
1 package org.onap.so.client.sdnc;
2
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;
9
10 import java.util.Map;
11
12 import javax.ws.rs.core.UriBuilder;
13
14 import org.junit.Rule;
15 import org.junit.Test;
16 import org.springframework.core.ParameterizedTypeReference;
17
18 import com.github.tomakehurst.wiremock.junit.WireMockRule;
19
20 import wiremock.org.apache.http.entity.ContentType;
21 public class BaseClientTest {
22
23         
24         @Rule
25         public WireMockRule wm = new WireMockRule(options().dynamicPort());
26         
27         @Test
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())));
34                 
35                 String result = client.get("", new ParameterizedTypeReference<String>() {});
36                 assertThat(result, equalTo(response));
37         }
38         
39         @Test
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())));
46                 
47                 Map<String, Object> result = client.get("", new ParameterizedTypeReference<Map<String, Object>>() {});
48                 assertThat("world", equalTo(result.get("hello")));
49         }
50 }