This is an automated email from the ASF dual-hosted git repository.

reta pushed a commit to branch 3.3.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit fc3272a4cea2c666d6d5ecb9e08e073ceb001b43
Author: reta <[email protected]>
AuthorDate: Sun Apr 4 22:09:40 2021 -0400

    Added tests for WebClient::language() and Variant
    
    (cherry picked from commit 44f995e629a0c81c017aba0f295aced291926dac)
    (cherry picked from commit d07fea085ff28a391e226b0327681304cdb5e370)
    
    # Conflicts:
    #   
systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
---
 .../org/apache/cxf/jaxrs/client/WebClientTest.java |  6 +++
 .../org/apache/cxf/systest/jaxrs/BookStore.java    |  7 +++
 .../systest/jaxrs/JAXRSClientServerBookTest.java   | 50 +++++++++++-----------
 3 files changed, 38 insertions(+), 25 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 150e696..9fea548 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
@@ -331,6 +331,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 6418293..20f5560 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 389cbaf..9564f9c 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
@@ -35,6 +35,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;
 
@@ -45,6 +46,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;
@@ -54,6 +56,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;
@@ -2017,6 +2020,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);
@@ -2448,7 +2469,6 @@ public class JAXRSClientServerBookTest extends 
AbstractBusClientServerTestBase {
 
     @Test
     public void testGetChapterChapter() throws Exception {
-
         getAndCompareAsStrings("http://localhost:";
                                + PORT + 
"/bookstore/booksubresource/123/chapters/sub/1/recurse",
                                "resources/expected_get_chapter1_utf.txt",
@@ -2461,7 +2481,6 @@ public class JAXRSClientServerBookTest extends 
AbstractBusClientServerTestBase {
 
     @Test
     public void testGetChapterWithParentIds() throws Exception {
-
         getAndCompareAsStrings(
             "http://localhost:"; + PORT + 
"/bookstore/booksubresource/123/chapters/sub/1/recurse2/ids",
             "resources/expected_get_chapter1.txt",
@@ -2535,7 +2554,6 @@ public class JAXRSClientServerBookTest extends 
AbstractBusClientServerTestBase {
         }
     }
 
-
     @Test
     public void testAddBookCustomFailureStatus() throws Exception {
         String endpointAddress = "http://localhost:"; + PORT + 
"/bookstore/books/customstatus";
@@ -2637,7 +2655,6 @@ public class JAXRSClientServerBookTest extends 
AbstractBusClientServerTestBase {
 
     @Test
     public void testGetCDs() throws Exception {
-
         WebClient wc = WebClient.create("http://localhost:"; + PORT + 
"/bookstore/cds");
         CDs cds = wc.get(CDs.class);
         Collection<CD> collection = cds.getCD();
@@ -2648,7 +2665,6 @@ public class JAXRSClientServerBookTest extends 
AbstractBusClientServerTestBase {
 
     @Test
     public void testGetCDJSON() throws Exception {
-
         getAndCompareAsStrings("http://localhost:"; + PORT + 
"/bookstore/cd/123",
                                "resources/expected_get_cdjson.txt",
                                "application/json", "application/json", 200);
@@ -2676,7 +2692,6 @@ public class JAXRSClientServerBookTest extends 
AbstractBusClientServerTestBase {
         }
     }
 
-
     @Test
     public void testMutipleAcceptHeader() throws Exception {
         String endpointAddress =
@@ -2734,7 +2749,6 @@ public class JAXRSClientServerBookTest extends 
AbstractBusClientServerTestBase {
 
     @Test
     public void testGetCDsJSON() throws Exception {
-
         String endpointAddress =
             "http://localhost:"; + PORT + "/bookstore/cds";
 
@@ -2761,7 +2775,6 @@ public class JAXRSClientServerBookTest extends 
AbstractBusClientServerTestBase {
 
     @Test
     public void testGetCDXML() throws Exception {
-
         getAndCompareAsStrings("http://localhost:"; + PORT + 
"/bookstore/cd/123",
                                "resources/expected_get_cd.txt",
                                "application/xml", "application/xml", 200);
@@ -2769,7 +2782,6 @@ public class JAXRSClientServerBookTest extends 
AbstractBusClientServerTestBase {
 
     @Test
     public void testGetCDWithMultiContentTypesXML() throws Exception {
-
         getAndCompareAsStrings("http://localhost:"; + PORT + 
"/bookstore/cdwithmultitypes/123",
                                "resources/expected_get_cd.txt",
                                "application/json;q=0.8,application/xml,*/*", 
"application/xml", 200);
@@ -2777,7 +2789,6 @@ public class JAXRSClientServerBookTest extends 
AbstractBusClientServerTestBase {
 
     @Test
     public void testGetCDWithMultiContentTypesCustomXML() throws Exception {
-
         getAndCompareAsStrings("http://localhost:"; + PORT + 
"/bookstore/cdwithmultitypes/123",
                                "resources/expected_get_cd.txt",
                                "application/bar+xml", "application/bar+xml", 
200);
@@ -2826,7 +2837,6 @@ public class JAXRSClientServerBookTest extends 
AbstractBusClientServerTestBase {
 
     @Test
     public void testQuotedHeaders() throws Exception {
-
         String endpointAddress =
             "http://localhost:"; + PORT + "/bookstore/quotedheaders";
         WebClient wc = WebClient.create(endpointAddress);
@@ -2850,7 +2860,6 @@ public class JAXRSClientServerBookTest extends 
AbstractBusClientServerTestBase {
         List<Object> header4 = r.getMetadata().get("SomeHeader4");
         assertEquals(1, header4.size());
         assertEquals("\"\"", header4.get(0));
-
     }
 
     @Test
@@ -2869,7 +2878,6 @@ public class JAXRSClientServerBookTest extends 
AbstractBusClientServerTestBase {
 
     @Test
     public void testBadlyQuotedHeaders() throws Exception {
-
         String endpointAddress =
             "http://localhost:"; + PORT + "/bookstore/badlyquotedheaders";
 
@@ -2899,7 +2907,6 @@ public class JAXRSClientServerBookTest extends 
AbstractBusClientServerTestBase {
         assertEquals("\"other quoted\"", r3values.get(1));
         assertEquals("text", r3values.get(2));
         assertEquals("blah", r3values.get(3));
-
     }
 
     @Test
@@ -2932,12 +2939,8 @@ public class JAXRSClientServerBookTest extends 
AbstractBusClientServerTestBase {
         };
     }
 
-
-    private void getAndCompareAsStrings(String address,
-                                        String resourcePath,
-                                        String acceptType,
-                                        String expectedContentType,
-                                        int status) throws Exception {
+    private void getAndCompareAsStrings(String address, String resourcePath, 
String acceptType, 
+            String expectedContentType, int status) throws Exception {
         String expected = getStringFromInputStream(
                               getClass().getResourceAsStream(resourcePath));
         getAndCompare(address,
@@ -2947,11 +2950,8 @@ public class JAXRSClientServerBookTest extends 
AbstractBusClientServerTestBase {
                       status);
     }
 
-    private void getAndCompare(String address,
-                               String expectedValue,
-                               String acceptType,
-                               String expectedContentType,
-                               int expectedStatus) throws Exception {
+    private 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);

Reply via email to