use of org.apache.cxf.jaxrs.client.WebClient in project cxf by apache.
the class JAXRSSoapBookTest method testPostBookTransform.
@Test
public void testPostBookTransform() throws Exception {
String address = "http://localhost:" + PORT + "/test/v1/rest-transform/bookstore/books";
TransformOutInterceptor out = new TransformOutInterceptor();
out.setOutTransformElements(Collections.singletonMap("{http://www.example.org/books}*", "{http://www.example.org/super-books}*"));
TransformInInterceptor in = new TransformInInterceptor();
Map<String, String> map = new HashMap<>();
// If Book2 didn't have {http://www.example.org/books}Book
// then we'd just do '"*" : "{http://www.example.org/books}*'
// but given that we have TheBook being returned, we need
map.put("TheBook", "{http://www.example.org/books}Book");
map.put("id", "{http://www.example.org/books}id");
in.setInTransformElements(map);
WebClient client = WebClient.create(address);
WebClient.getConfig(client).getInInterceptors().add(in);
WebClient.getConfig(client).getOutInterceptors().add(out);
Book2 book = client.type("application/xml").accept("text/xml").post(new Book2(), Book2.class);
assertEquals(124L, book.getId());
}
use of org.apache.cxf.jaxrs.client.WebClient in project cxf by apache.
the class JAXRSUriInfoTest method checkUriInfo.
private void checkUriInfo(String address, String path, String pathParam) {
WebClient wc = WebClient.create(address);
wc.accept("text/plain");
String data = wc.get(String.class);
assertEquals("http://localhost:" + PORT + "/app/v1/," + path + "," + pathParam, data);
}
use of org.apache.cxf.jaxrs.client.WebClient in project cxf by apache.
the class JAXRSUriInfoTest method checkUriInfoXForwarded.
private void checkUriInfoXForwarded(String address, String path, String pathParam) {
WebClient wc = WebClient.create(address);
wc.accept("text/plain");
wc.header("USE_XFORWARDED", true);
String data = wc.get(String.class);
assertEquals("https://external:8090/reverse/app/v1/," + path + "," + pathParam, data);
}
use of org.apache.cxf.jaxrs.client.WebClient in project cxf by apache.
the class AbstractSwagger2ServiceDescriptionTest method testApiListingIsProperlyReturnedYAML.
@Test
@Ignore
public void testApiListingIsProperlyReturnedYAML() throws Exception {
final WebClient client = createWebClient("/swagger.yaml");
try {
final Response r = client.get();
assertEquals(Status.OK.getStatusCode(), r.getStatus());
// REVISIT find a better way of reliably comparing two yaml instances.
// I noticed that yaml.load instantiates a Map and
// for an integer valued key, an Integer or a String is arbitrarily instantiated,
// which leads to the assertion error. So, we serilialize the yamls and compare the re-serialized texts.
Yaml yaml = new Yaml();
assertEquals(yaml.load(getExpectedValue(getExpectedFileYaml(), getPort())).toString(), yaml.load(IOUtils.readStringFromStream((InputStream) r.getEntity())).toString());
} finally {
client.close();
}
}
use of org.apache.cxf.jaxrs.client.WebClient in project cxf by apache.
the class AbstractSwagger2ServiceDescriptionTest method testNonUiResource.
@Test
public void testNonUiResource() {
// Test that Swagger UI resources do not interfere with
// application-specific ones.
WebClient uiClient = WebClient.create("http://localhost:" + getPort() + "/css/book.css").accept("text/css");
String css = uiClient.get(String.class);
assertThat(css, equalTo("body { background-color: lightblue; }"));
}
Aggregations