This repository has been archived by the owner on Jul 4, 2020. It is now read-only.
/
HelloWorldIT.java
51 lines (43 loc) · 1.67 KB
/
HelloWorldIT.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package org.hidetake.tokenizer;
import static org.junit.Assert.assertEquals;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.core.Response;
import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.jaxrs.client.WebClient;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.map.MappingJsonFactory;
import org.junit.BeforeClass;
import org.junit.Test;
public class HelloWorldIT {
private static String endpointUrl;
@BeforeClass
public static void beforeClass() {
endpointUrl = System.getProperty("service.url");
}
@Test
public void testPing() throws Exception {
WebClient client = WebClient.create(endpointUrl + "/hello/echo/SierraTangoNevada");
Response r = client.accept("text/plain").get();
assertEquals(Response.Status.OK.getStatusCode(), r.getStatus());
String value = IOUtils.toString((InputStream)r.getEntity());
assertEquals("SierraTangoNevada", value);
}
@Test
public void testJsonRoundtrip() throws Exception {
List<Object> providers = new ArrayList<Object>();
providers.add(new org.codehaus.jackson.jaxrs.JacksonJsonProvider());
JsonBean inputBean = new JsonBean();
inputBean.setVal1("Maple");
WebClient client = WebClient.create(endpointUrl + "/hello/jsonBean", providers);
Response r = client.accept("application/json")
.type("application/json")
.post(inputBean);
assertEquals(Response.Status.OK.getStatusCode(), r.getStatus());
MappingJsonFactory factory = new MappingJsonFactory();
JsonParser parser = factory.createJsonParser((InputStream)r.getEntity());
JsonBean output = parser.readValueAs(JsonBean.class);
assertEquals("Maple", output.getVal2());
}
}