You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by bu...@apache.org on 2020/01/16 07:51:45 UTC

[cxf] branch master updated: CXF-8193: add missing test resource

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

buhhunyx 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 2425fad  CXF-8193: add missing test resource
2425fad is described below

commit 2425fad2eb3a31b643e4f6d23115f3dc146027a7
Author: Alexey Markevich <bu...@gmail.com>
AuthorDate: Thu Jan 16 10:51:13 2020 +0300

    CXF-8193: add missing test resource
---
 .../systest/jaxrs/JAXRSRequestDispatcherTest.java  | 50 +++++++++++-----------
 .../resources/jaxrs_dispatch/book_include.html     | 28 ++++++++++++
 2 files changed, 53 insertions(+), 25 deletions(-)

diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSRequestDispatcherTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSRequestDispatcherTest.java
index ce005aa..7002a30 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSRequestDispatcherTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSRequestDispatcherTest.java
@@ -22,6 +22,7 @@ package org.apache.cxf.systest.jaxrs;
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
 
 import org.apache.cxf.jaxrs.client.WebClient;
@@ -59,18 +60,18 @@ public class JAXRSRequestDispatcherTest extends AbstractBusClientServerTestBase
     }
 
     private void doTestGetBookHTML(String endpointAddress) throws Exception {
-        WebClient client = WebClient.create(endpointAddress);
-        client.accept("text/html");
-        WebClient.getConfig(client).getHttpConduit().getClient().setReceiveTimeout(100000000);
-        XMLSource source = client.accept("text/html").get(XMLSource.class);
+        WebClient client = WebClient.create(endpointAddress)
+            .accept(MediaType.TEXT_HTML);
+
+        XMLSource source = client.get(XMLSource.class);
         Map<String, String> namespaces = new HashMap<>();
         namespaces.put("xhtml", "http://www.w3.org/1999/xhtml");
         namespaces.put("books", "http://www.w3.org/books");
         String value = source.getValue("xhtml:html/xhtml:body/xhtml:ul/books:bookTag", namespaces);
         assertEquals("CXF Rocks", value);
-        Object contentType = client.getResponse().getMetadata().getFirst("Content-Type");
+        Object contentType = client.getResponse().getHeaders().getFirst(HttpHeaders.CONTENT_TYPE);
         assertNotNull("Content-Type should be present", contentType);
-        assertEquals("text/html", contentType.toString());
+        assertEquals(MediaType.TEXT_HTML, contentType.toString());
         assertEquals(MediaType.TEXT_HTML_TYPE, client.getResponse().getMediaType());
     }
 
@@ -79,10 +80,10 @@ public class JAXRSRequestDispatcherTest extends AbstractBusClientServerTestBase
     public void testGetBookJSPRequestScope() throws Exception {
         String endpointAddress =
             "http://localhost:" + PORT + "/the/bookstore2/books/html/123";
-        WebClient client = WebClient.create(endpointAddress);
-        client.accept("text/html");
-        WebClient.getConfig(client).getHttpConduit().getClient().setReceiveTimeout(100000000);
-        String data = client.accept("text/html").get(String.class);
+        WebClient client = WebClient.create(endpointAddress)
+            .accept(MediaType.TEXT_HTML);
+
+        String data = client.get(String.class);
         assertTrue(data.contains("<h1>Request Book 123</h1>"));
         assertTrue(data.contains("<books:bookName>CXF in Action</books:bookName>"));
 
@@ -93,10 +94,10 @@ public class JAXRSRequestDispatcherTest extends AbstractBusClientServerTestBase
     public void testGetBookJSPSessionScope() throws Exception {
         String endpointAddress =
             "http://localhost:" + PORT + "/the/bookstore3/books/html/456";
-        WebClient client = WebClient.create(endpointAddress);
-        client.accept("text/html");
-        WebClient.getConfig(client).getHttpConduit().getClient().setReceiveTimeout(100000000);
-        String data = client.accept("text/html").get(String.class);
+        WebClient client = WebClient.create(endpointAddress)
+            .accept(MediaType.TEXT_HTML);
+
+        String data = client.get(String.class);
         assertTrue(data.contains("<h1>Session Book 456</h1>"));
         assertTrue(data.contains("<books:bookName>CXF in Action</books:bookName>"));
     }
@@ -105,10 +106,10 @@ public class JAXRSRequestDispatcherTest extends AbstractBusClientServerTestBase
     public void testGetBookHTMLFromDefaultServlet() throws Exception {
         String endpointAddress =
             "http://localhost:" + PORT + "/the/bookstore4/books/html/123";
-        WebClient client = WebClient.create(endpointAddress);
-        client.accept("text/html");
-        WebClient.getConfig(client).getHttpConduit().getClient().setReceiveTimeout(100000000);
-        XMLSource source = client.accept("text/html").get(XMLSource.class);
+        WebClient client = WebClient.create(endpointAddress)
+            .accept(MediaType.TEXT_HTML);
+
+        XMLSource source = client.get(XMLSource.class);
         Map<String, String> namespaces = new HashMap<>();
         namespaces.put("xhtml", "http://www.w3.org/1999/xhtml");
         namespaces.put("books", "http://www.w3.org/books");
@@ -136,18 +137,17 @@ public class JAXRSRequestDispatcherTest extends AbstractBusClientServerTestBase
     @Test
     public void testGetTextWelcomeFile() throws Exception {
         String address = "http://localhost:" + PORT + "/welcome2/welcome.txt";
-        WebClient client = WebClient.create(address);
-        client.accept("text/plain");
+        WebClient client = WebClient.create(address)
+            .accept(MediaType.TEXT_PLAIN);
         String welcome = client.get(String.class);
-        System.out.println(welcome);
         assertEquals("Welcome", welcome);
     }
 
     private void doTestGetBookHTMLFromWelcomeList(String address) throws Exception {
-        WebClient client = WebClient.create(address);
-        client.accept("text/html");
-        WebClient.getConfig(client).getHttpConduit().getClient().setReceiveTimeout(100000000);
-        XMLSource source = client.accept("text/html").get(XMLSource.class);
+        WebClient client = WebClient.create(address)
+            .accept(MediaType.TEXT_HTML);
+
+        XMLSource source = client.get(XMLSource.class);
         Map<String, String> namespaces = new HashMap<>();
         namespaces.put("xhtml", "http://www.w3.org/1999/xhtml");
         namespaces.put("books", "http://www.w3.org/books");
diff --git a/systests/jaxrs/src/test/resources/jaxrs_dispatch/book_include.html b/systests/jaxrs/src/test/resources/jaxrs_dispatch/book_include.html
new file mode 100644
index 0000000..58fc58b
--- /dev/null
+++ b/systests/jaxrs/src/test/resources/jaxrs_dispatch/book_include.html
@@ -0,0 +1,28 @@
+<!--
+	Licensed to the Apache Software Foundation (ASF) under one
+	or more contributor license agreements. See the NOTICE file
+	distributed with this work for additional information
+	regarding copyright ownership. The ASF licenses this file
+	to you under the Apache License, Version 2.0 (the
+	"License"); you may not use this file except in compliance
+	with the License. You may obtain a copy of the License at
+	
+	http://www.apache.org/licenses/LICENSE-2.0
+	
+	Unless required by applicable law or agreed to in writing,
+	software distributed under the License is distributed on an
+	"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+	KIND, either express or implied. See the License for the
+	specific language governing permissions and limitations
+	under the License.
+-->
+<html xmlns="http://www.w3.org/1999/xhtml"
+      xmlns:books="http://www.w3.org/books">
+<head> <title>Testing XML Example</title> </head>
+<body>
+	<h1>Book</h1>
+	<ul>
+	   <books:bookTag>CXF Rocks</books:bookTag>
+	</ul>
+</body>
+</html>