Repository: cxf Updated Branches: refs/heads/3.0.x-fixes 8e4970d93 -> 6499e0d57
[CXF-7119] Adding a test Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/6499e0d5 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/6499e0d5 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/6499e0d5 Branch: refs/heads/3.0.x-fixes Commit: 6499e0d577d734abcc045ca0f80ff983e9d31ab6 Parents: a6e0532 Author: Sergey Beryozkin <[email protected]> Authored: Thu Nov 24 11:02:43 2016 +0000 Committer: Sergey Beryozkin <[email protected]> Committed: Thu Nov 24 11:08:37 2016 +0000 ---------------------------------------------------------------------- .../jaxrs/JAXRSClientServerBookTest.java | 129 ++++++++----------- 1 file changed, 57 insertions(+), 72 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/6499e0d5/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java ---------------------------------------------------------------------- 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 a46c868..61bfc3b 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 @@ -407,10 +407,7 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { private void doTestUseParamBeanWebClient(String address) { WebClient wc = WebClient.create(address); - wc.path("100"); - wc.query("id_2", "20"); - wc.query("id3", "3"); - wc.query("id4", "123"); + wc.path("100").query("id_2", "20").query("id3", "3").query("id4", "123"); Book book = wc.get(Book.class); assertEquals(123L, book.getId()); } @@ -426,8 +423,7 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { public void testGetIntroChapterFromSelectedBook2() { String address = "http://localhost:" + PORT + "/bookstore/"; WebClient wc = WebClient.create(address); - wc.path("books[id=le=123]"); - wc.path("chapter"); + wc.path("books[id=le=123]").path("chapter"); wc.accept("application/xml"); Chapter chapter = wc.get(Chapter.class); assertEquals("chapter 1", chapter.getTitle()); @@ -488,7 +484,6 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { @Test public void testProxyBeanParam2() throws Exception { BookStore store = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class); - WebClient.getConfig(store).getHttpConduit().getClient().setReceiveTimeout(10000000L); BookStore.BookBean2 bean = new BookStore.BookBean2(); bean.setId(100L); bean.setId2(23L); @@ -964,21 +959,21 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { + "org.apache.cxf.systest.jaxrs.BookNotFoundFault: Book Exception</ns1:faultstring>" + "</ns1:XMLFault>"; getAndCompare("http://localhost:" + PORT + "/bookstore/propagate-exception2", - data, "application/xml", 500); + data, "application/xml", null, 500); } @Test public void testPropogateException3() throws Exception { String data = "<nobook/>"; getAndCompare("http://localhost:" + PORT + "/bookstore/propagate-exception3", - data, "application/xml", 500); + data, "application/xml", null, 500); } @Test public void testPropogateException4() throws Exception { String data = "<nobook/>"; getAndCompare("http://localhost:" + PORT + "/bookstore/propogateExceptionVar/1", - data, "application/xml", 500); + data, "application/xml", null, 500); } @Test @@ -1064,7 +1059,7 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { public void testWebApplicationException() throws Exception { getAndCompare("http://localhost:" + PORT + "/bookstore/webappexception", "This is a WebApplicationException", - "application/xml", 500); + "application/xml", null, 500); } @Test @@ -1199,7 +1194,7 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/bookurl/http%3A%2F%2Ftest.com%2Frss%2F123", "resources/expected_get_book123.txt", - "application/xml", 200); + "application/xml", "application/xml", 200); } @Test @@ -1416,21 +1411,21 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/bookquery?" + "urlid=http%3A%2F%2Ftest.com%2Frss%2F123", "resources/expected_get_book123.txt", - "application/xml", 200); + "application/xml", "application/xml", 200); } @Test public void testGetGenericBook() throws Exception { getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/genericbooks/123", "resources/expected_get_book123.txt", - "application/xml", 200); + "application/xml", "application/xml", 200); } @Test public void testGetGenericResponseBook() throws Exception { getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/genericresponse/123", "resources/expected_get_book123.txt", - "application/xml", 200); + "application/xml", "application/xml", 200); } @Test @@ -1438,21 +1433,21 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/bookidarray?" + "id=1&id=2&id=3", "resources/expected_get_book123.txt", - "application/xml", 200); + "application/xml", "application/xml", 200); } @Test public void testNoRootResourceException() throws Exception { getAndCompare("http://localhost:" + PORT + "/nobookstore/webappexception", "", - "application/xml", 404); + "application/xml", null, 404); } @Test public void testNoPathMatch() throws Exception { getAndCompare("http://localhost:" + PORT + "/bookstore/bookqueries", "", - "application/xml", 404); + "application/xml", null, 404); } @Test @@ -1472,13 +1467,13 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { public void testWriteAndFailEarly() throws Exception { getAndCompare("http://localhost:" + PORT + "/bookstore/books/fail-early", "This is supposed to go on the wire", - "application/bar, text/plain", 410); + "application/bar, text/plain", null, 410); } @Test public void testWriteAndFailLate() throws Exception { getAndCompare("http://localhost:" + PORT + "/bookstore/books/fail-late", - "", "application/bar", 410); + "", "application/bar", null, 410); } @@ -1486,14 +1481,14 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { public void testAcceptTypeMismatch() throws Exception { getAndCompare("http://localhost:" + PORT + "/bookstore/booknames/123", "", - "foo/bar", 406); + "foo/bar", null, 406); } @Test public void testWrongHttpMethod() throws Exception { getAndCompare("http://localhost:" + PORT + "/bookstore/unsupportedcontenttype", "", - "foo/bar", 405); + "foo/bar", null, 405); } @Test @@ -1501,7 +1496,7 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { getAndCompare("http://localhost:" + PORT + "/bookstore/wrongparametertype?p=1", "Parameter Class java.util.Map has no constructor with single String " + "parameter, static valueOf(String) or fromString(String) methods", - "*/*", 500); + "*/*", null, 500); } @Test @@ -1522,14 +1517,14 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { public void testExceptionDuringConstruction() throws Exception { getAndCompare("http://localhost:" + PORT + "/bookstore/exceptionconstruction?p=1", "", - "foo/bar", 404); + "foo/bar", null, 404); } @Test public void testSubresourceMethodNotFound() throws Exception { getAndCompare("http://localhost:" + PORT + "/bookstore/interface/thesubresource", "", - "foo/bar", 404); + "foo/bar", null, 404); } @Test @@ -1653,7 +1648,7 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { public void testGetBookCustomExpression() throws Exception { getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/books/custom/123", "resources/expected_get_book123.txt", - "application/xml", 200); + "application/xml", "application/xml", 200); } @Test @@ -1759,7 +1754,7 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/books/search" + "?_s=name==CXF*;id=ge=123;id=lt=124", "resources/expected_get_book123.txt", - "application/xml", 200); + "application/xml", "application/xml", 200); } @Test @@ -1788,7 +1783,7 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { public void testGetBook123CGLIB() throws Exception { getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/books/123/cglib", "resources/expected_get_book123.txt", - "application/xml", 200); + "application/xml", "application/xml", 200); } @Test @@ -1893,19 +1888,19 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { public void testGetBook123() throws Exception { getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/books/123", "resources/expected_get_book123.txt", - "application/xml", 200); + "application/xml", "application/xml", 200); getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/books/query?bookId=123", "resources/expected_get_book123.txt", - "application/xml", 200); + "application/xml", "application/xml", 200); getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/books/defaultquery", "resources/expected_get_book123.txt", - "application/xml", 200); + "application/xml", "application/xml", 200); getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/books/missingquery", "resources/expected_get_book123.txt", - "application/xml", 200); + "application/xml", "application/xml", 200); getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/books/123", "resources/expected_get_book123json.txt", @@ -1931,36 +1926,36 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { public void testGetBookBuffer() throws Exception { getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/books/buffer", "resources/expected_get_book123.txt", - "application/bar", 200); + "application/bar", "application/bar", 200); } @Test public void testGetBookBySegment() throws Exception { getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/segment/matrix2;first=12;second=3", "resources/expected_get_book123.txt", - "application/xml", 200); + "application/xml", "application/xml", 200); getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore;bar/segment;foo/" + "matrix2;first=12;second=3;third", "resources/expected_get_book123.txt", - "application/xml", 200); + "application/xml", "application/xml", 200); } @Test public void testGetBookByListOfSegments() throws Exception { getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/segment/list/1/2/3", "resources/expected_get_book123.txt", - "application/xml", 200); + "application/xml", "application/xml", 200); } @Test public void testGetBookByMatrixParameters() throws Exception { getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/segment/matrix;first=12;second=3", "resources/expected_get_book123.txt", - "application/xml", 200); + "application/xml", "application/xml", 200); getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore;bar;first=12/segment;foo;" + "second=3/matrix;third", "resources/expected_get_book123.txt", - "application/xml", 200); + "application/xml", "application/xml", 200); } @Test @@ -1968,7 +1963,7 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { getAndCompareAsStrings( "http://localhost:" + PORT + "/bookstore/segment;first=12;second=3/matrix-middle", "resources/expected_get_book123.txt", - "application/xml", 200); + "application/xml", "application/xml", 200); } @Test @@ -2039,7 +2034,7 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { public void testGetBookElement() throws Exception { getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/books/element", "resources/expected_get_book123.txt", - "application/xml", 200); + "application/xml", "application/xml", 200); } @Test @@ -2078,7 +2073,7 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { public void testGetBookAdapter() throws Exception { getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/books/adapter", "resources/expected_get_book123.txt", - "application/xml", 200); + "application/xml", "application/xml", 200); } @Test @@ -2115,7 +2110,7 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { public void testGetBookAdapterInterface() throws Exception { getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/books/interface/adapter", "resources/expected_get_book123.txt", - "application/xml", 200); + "application/xml", "application/xml", 200); } @Test @@ -2154,7 +2149,7 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { public void testGetBook123FromSub() throws Exception { getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/interface/subresource", "resources/expected_get_book123.txt", - "application/xml", 200); + "application/xml", "application/xml", 200); getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/books/123", "resources/expected_get_book123json.txt", @@ -2236,7 +2231,7 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/booksubresource/123/chapters/sub/1/recurse", "resources/expected_get_chapter1_utf.txt", - "application/xml", 200); + "application/xml", "application/xml", 200); getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/booksubresource/123/chapters/sub/1/recurse2", "resources/expected_get_chapter1.txt", @@ -2256,7 +2251,7 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { public void testGetBook123ReturnString() throws Exception { getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/booknames/123", "resources/expected_get_book123_returnstring.txt", - "text/plain", 200); + "text/plain", "text/plain", 200); } @Test @@ -2440,7 +2435,7 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/cd/123", "resources/expected_get_cdjson.txt", - "application/json", 200); + "application/json", "application/json", 200); } @@ -2532,7 +2527,7 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/cd/123", "resources/expected_get_cd.txt", - "application/xml", 200); + "application/xml", "application/xml", 200); } @Test @@ -2555,7 +2550,7 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { public void testGetCDWithMultiContentTypesJSON() throws Exception { getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/cdwithmultitypes/123", "resources/expected_get_cdjson.txt", - "application/json", 200); + "application/json", "application/json", 200); getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/cdwithmultitypes/123", "resources/expected_get_cdjson.txt", "*/*,application/xml;q=0.9,application/json", "application/json", 200); @@ -2635,6 +2630,20 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { } @Test + public void testNonExistentWithGetCustomEx() throws Exception { + String address = "http://localhostt/bookstore"; + BookStore c = JAXRSClientFactory.create(address, BookStore.class); + WebClient.getConfig(c).getInFaultInterceptors().add(new CustomFaultInInterceptor()); + try { + c.getBook("123"); + fail("Exception expected"); + } catch (ProcessingException ex) { + assertEquals("UnknownHostException: Microservice at http://localhostt/bookstore/bookstore/books/123/" + + " is not available", ex.getMessage()); + } + } + + @Test public void testBadlyQuotedHeaders() throws Exception { String endpointAddress = @@ -2670,19 +2679,6 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { } - private void getAndCompareAsStrings(String address, - String resourcePath, - String acceptType, - int status) throws Exception { - String expected = getStringFromInputStream( - getClass().getResourceAsStream(resourcePath)); - getAndCompare(address, - expected, - acceptType, - acceptType, - status); - } - private void getAndCompareAsStrings(String address, String resourcePath, String acceptType, @@ -2700,17 +2696,6 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { private void getAndCompare(String address, String expectedValue, String acceptType, - int expectedStatus) throws Exception { - getAndCompare(address, - expectedValue, - acceptType, - null, - expectedStatus); - } - - private void getAndCompare(String address, - String expectedValue, - String acceptType, String expectedContentType, int expectedStatus) throws Exception { GetMethod get = new GetMethod(address);
