You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2021/04/05 02:10:06 UTC
[cxf] branch master updated: Added tests for WebClient::language()
and Variant
This is an automated email from the ASF dual-hosted git repository.
reta pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/master by this push:
new 44f995e Added tests for WebClient::language() and Variant
44f995e is described below
commit 44f995e629a0c81c017aba0f295aced291926dac
Author: reta <dr...@gmail.com>
AuthorDate: Sun Apr 4 22:09:40 2021 -0400
Added tests for WebClient::language() and Variant
---
.../org/apache/cxf/jaxrs/client/WebClientTest.java | 6 ++++
.../org/apache/cxf/systest/jaxrs/BookStore.java | 7 +++++
.../systest/jaxrs/JAXRSClientServerBookTest.java | 35 +++++++++++++++-------
3 files changed, 38 insertions(+), 10 deletions(-)
diff --git a/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java b/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
index 10830d3..d37a6b9 100644
--- a/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
+++ b/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
@@ -338,6 +338,12 @@ public class WebClientTest {
assertEquals(auth, wc.getHeaders().getFirst(HttpHeaders.AUTHORIZATION));
}
+ @Test
+ public void testLanguageHeader() {
+ WebClient wc = WebClient.create("http://foo").language("en_CA");
+ assertEquals("en_CA", wc.getHeaders().getFirst(HttpHeaders.CONTENT_LANGUAGE));
+ }
+
private static class ParamConverterProviderImpl implements ParamConverterProvider {
@SuppressWarnings("unchecked")
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
index 570d519..cd434d5 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
@@ -351,6 +351,13 @@ public class BookStore {
public Book echoXmlBook(Book book) {
return book;
}
+
+ @POST
+ @Path("/echoxmlbook-i18n")
+ @Produces("application/xml")
+ public Response echoXmlBooki18n(Book book, @HeaderParam(HttpHeaders.CONTENT_LANGUAGE) String language) {
+ return Response.ok(new Book(book.getName() + "-" + language, book.getId())).build();
+ }
// Only books with id consisting of 3 or 4 digits of the numbers between 5 and 9 are accepted
@POST
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
index 641b99d..42a78e8 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
@@ -34,6 +34,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.zip.GZIPInputStream;
@@ -44,6 +45,7 @@ import javax.ws.rs.ServerErrorException;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Entity;
import javax.ws.rs.client.ResponseProcessingException;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Form;
@@ -53,6 +55,7 @@ import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Variant;
import javax.ws.rs.ext.ReaderInterceptor;
import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
@@ -2014,6 +2017,24 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase {
assertEquals("book", r.readEntity(String.class));
}
@Test
+ public void testEchoBookWithLanguage() throws Exception {
+ final Book book = new Book("CXF in Action", 100);
+ WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/echoxmlbook-i18n");
+ wc.type("application/xml").accept("application/xml").language("en_CA");
+ Response r = wc.post(book);
+ assertEquals(200, r.getStatus());
+ assertEquals(book.getName() + "-en_CA", r.readEntity(Book.class).getName());
+ }
+ @Test
+ public void testEchoBookEntityWithLocale() throws Exception {
+ final Book book = new Book("CXF in Action", 100);
+ WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/echoxmlbook-i18n");
+ wc.type("application/xml").accept("application/xml").language("en_CA");
+ Response r = wc.post(Entity.entity(book, new Variant(MediaType.APPLICATION_XML_TYPE, Locale.UK, null)));
+ assertEquals(200, r.getStatus());
+ assertEquals(book.getName() + "-en_GB", r.readEntity(Book.class).getName());
+ }
+ @Test
public void testEmpty202() throws Exception {
WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/empty202");
WebClient.getConfig(wc).getRequestContext().put(Message.PROCESS_202_RESPONSE_ONEWAY_OR_PARTIAL, false);
@@ -2924,11 +2945,8 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase {
}
- private static void getAndCompareAsStrings(String address,
- String resourcePath,
- String acceptType,
- String expectedContentType,
- int status) throws Exception {
+ private static void getAndCompareAsStrings(String address, String resourcePath, String acceptType,
+ String expectedContentType, int status) throws Exception {
String expected = IOUtils.toString(
JAXRSClientServerBookTest.class.getResourceAsStream(resourcePath));
getAndCompare(address,
@@ -2938,11 +2956,8 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase {
status);
}
- private static void getAndCompare(String address,
- String expectedValue,
- String acceptType,
- String expectedContentType,
- int expectedStatus) throws Exception {
+ private static void getAndCompare(String address, String expectedValue, String acceptType,
+ String expectedContentType, int expectedStatus) throws Exception {
CloseableHttpClient client = HttpClientBuilder.create().build();
HttpGet get = new HttpGet(address);
get.addHeader("Accept", acceptType);