This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new 59e0154 Tests.
59e0154 is described below
commit 59e0154fe66bd5793f01a96994d383d77c870037
Author: JamesBognar <[email protected]>
AuthorDate: Sun May 13 20:12:54 2018 -0400
Tests.
---
.../apache/juneau/rest/test/ParsersResource.java | 151 -------------------
.../java/org/apache/juneau/rest/test/Root.java | 2 -
.../apache/juneau/rest/test/JacocoDummyTest.java | 38 -----
.../org/apache/juneau/rest/test/ParsersTest.java | 138 -----------------
.../apache/juneau/rest/test/SerializersTest.java | 130 ----------------
.../org/apache/juneau/rest/test/_TestSuite.java | 3 -
.../java/org/apache/juneau/rest/mock/MockRest.java | 18 ++-
.../org/apache/juneau/rest/RestParamsTest.java | 6 +-
.../org/apache/juneau/rest/StatusCodesTest.java | 22 +--
.../juneau/rest/annotation/BodyAnnotationTest.java | 140 ++++++++---------
.../rest/annotation/FormDataAnnotationTest.java | 24 +--
.../rest/annotation/HasFormDataAnnotationTest.java | 20 +--
.../rest/annotation/RestResourceParsersTest.java | 167 +++++++++++++++++++++
.../rest/annotation/RestResourcePojoSwapsTest.java | 4 +-
.../annotation/RestResourceSerializersTest.java | 151 +++++++++++--------
.../juneau/rest/headers/ContentEncodingTest.java | 16 +-
16 files changed, 383 insertions(+), 647 deletions(-)
diff --git
a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/ParsersResource.java
b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/ParsersResource.java
deleted file mode 100644
index 03f19ce..0000000
---
a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/ParsersResource.java
+++ /dev/null
@@ -1,151 +0,0 @@
-//
***************************************************************************************************************************
-// * 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. *
-//
***************************************************************************************************************************
-package org.apache.juneau.rest.test;
-
-import static org.apache.juneau.internal.IOUtils.*;
-import static org.apache.juneau.http.HttpMethodName.*;
-
-import org.apache.juneau.*;
-import org.apache.juneau.parser.*;
-import org.apache.juneau.plaintext.*;
-import org.apache.juneau.rest.*;
-import org.apache.juneau.rest.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- * Validates correct parser is used.
- */
-@RestResource(
- path="/testParsers",
- parsers=ParsersResource.TestParserA.class,
- serializers=PlainTextSerializer.class
-)
-public class ParsersResource extends BasicRestServlet {
- private static final long serialVersionUID = 1L;
-
- public static class TestParserA extends ReaderParser {
-
- public TestParserA(PropertyStore ps) {
- super(ps, "text/a");
- }
-
- @Override /* Parser */
- public ReaderParserSession createSession(ParserSessionArgs
args) {
- return new ReaderParserSession(args) {
-
- @Override /* ParserSession */
- @SuppressWarnings("unchecked")
- protected <T> T doParse(ParserPipe pipe,
ClassMeta<T> type) throws Exception {
- return (T)("text/a - " +
read(pipe.getReader()).trim());
- }
- };
- }
- }
-
-
//====================================================================================================
- // Parser defined on class.
-
//====================================================================================================
- @RestMethod(name=PUT, path="/testParserOnClass")
- public String testParserOnClass(@Body String in) {
- return in;
- }
-
-
//====================================================================================================
- // Parser defined on method.
-
//====================================================================================================
- @RestMethod(name=PUT, path="/testParserOnMethod",
parsers=TestParserB.class)
- public String testParserOnMethod(@Body String in) {
- return in;
- }
-
- public static class TestParserB extends ReaderParser {
-
- public TestParserB(PropertyStore ps) {
- super(ps, "text/b");
- }
-
- @Override /* Parser */
- public ReaderParserSession createSession(ParserSessionArgs
args) {
- return new ReaderParserSession(args) {
-
- @Override /* ParserSession */
- @SuppressWarnings("unchecked")
- protected <T> T doParse(ParserPipe pipe,
ClassMeta<T> type) throws Exception {
- return (T)("text/b - " +
read(pipe.getReader()).trim());
- }
- };
- }
- }
-
-
//====================================================================================================
- // Parser overridden on method.
-
//====================================================================================================
- @RestMethod(name=PUT, path="/testParserOverriddenOnMethod",
parsers={TestParserB.class,TestParserC.class}, inherit="PARSERS")
- public String testParserOverriddenOnMethod(@Body String in) {
- return in;
- }
-
- public static class TestParserC extends ReaderParser {
-
- public TestParserC(PropertyStore ps) {
- super(ps, "text/c");
- }
-
- @Override /* Parser */
- public ReaderParserSession createSession(ParserSessionArgs
args) {
- return new ReaderParserSession(args) {
-
- @Override /* ParserSession */
- @SuppressWarnings("unchecked")
- protected <T> T doParse(ParserPipe pipe,
ClassMeta<T> type) throws Exception {
- return (T)("text/c - " +
read(pipe.getReader()).trim());
- }
- };
- }
- }
-
-
//====================================================================================================
- // Parser with different Accept than Content-Type.
-
//====================================================================================================
- @RestMethod(name=PUT, path="/testParserWithDifferentMediaTypes",
parsers={TestParserD.class}, inherit="PARSERS")
- public String testParserWithDifferentMediaTypes(@Body String in) {
- return in;
- }
-
- public static class TestParserD extends ReaderParser {
-
- public TestParserD(PropertyStore ps) {
- super(ps, "text/d");
- }
-
- @Override /* Parser */
- public ReaderParserSession createSession(ParserSessionArgs
args) {
- return new ReaderParserSession(args) {
-
- @Override /* ParserSession */
- @SuppressWarnings("unchecked")
- protected <T> T doParse(ParserPipe pipe,
ClassMeta<T> type) throws Exception {
- return (T)("text/d - " +
read(pipe.getReader()).trim());
- }
- };
- }
- }
-
-
//====================================================================================================
- // Check for valid error response.
-
//====================================================================================================
- @RestMethod(name=PUT, path="/testValidErrorResponse")
- public String testValidErrorResponse(@Body String in) {
- return in;
- }
-}
diff --git
a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/Root.java
b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/Root.java
index 35e6222..7588d71 100644
---
a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/Root.java
+++
b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/Root.java
@@ -34,11 +34,9 @@ import org.apache.juneau.rest.test.client.*;
HtmlDocLinksResource.class,
InterfaceProxyResource.class,
LargePojosResource.class,
- ParsersResource.class,
PathsResource.class,
RequestBeanProxyResource.class,
RestClient2Resource.class,
- SerializersResource.class,
ThirdPartyProxyResource.class,
UrisResource.class,
ShutdownResource.class,
diff --git
a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/JacocoDummyTest.java
b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/JacocoDummyTest.java
deleted file mode 100644
index 7761000..0000000
---
a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/JacocoDummyTest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-//
***************************************************************************************************************************
-// * 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. *
-//
***************************************************************************************************************************
-package org.apache.juneau.rest.test;
-
-import java.lang.reflect.*;
-
-import org.apache.juneau.rest.util.*;
-import org.junit.*;
-
-public class JacocoDummyTest {
-
-
//====================================================================================================
- // Dummy code to add test coverage in Jacoco.
-
//====================================================================================================
- @Test
- public void accessPrivateConstructorsOnStaticUtilityClasses() throws
Exception {
-
- Class<?>[] classes = new Class[] {
- RestUtils.class
- };
-
- for (Class<?> c : classes) {
- Constructor<?> c1 = c.getDeclaredConstructor();
- c1.setAccessible(true);
- c1.newInstance();
- }
- }
-}
diff --git
a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/ParsersTest.java
b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/ParsersTest.java
deleted file mode 100644
index 3a1d073..0000000
---
a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/ParsersTest.java
+++ /dev/null
@@ -1,138 +0,0 @@
-//
***************************************************************************************************************************
-// * 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. *
-//
***************************************************************************************************************************
-package org.apache.juneau.rest.test;
-
-import static javax.servlet.http.HttpServletResponse.*;
-import static org.apache.juneau.microservice.testutils.TestUtils.*;
-import static org.junit.Assert.*;
-
-import org.apache.juneau.rest.client.*;
-import org.junit.*;
-
-public class ParsersTest extends RestTestcase {
-
- private static String URL = "/testParsers";
- private static boolean debug = false;
-
-
//====================================================================================================
- // Parser defined on class.
-
//====================================================================================================
- @Test
- public void testParserOnClass() throws Exception {
- RestClient client = TestMicroservice.DEFAULT_CLIENT_PLAINTEXT;
- String url = URL + "/testParserOnClass";
-
- String r = client.doPut(url,
"test1").contentType("text/a").getResponseAsString();
- assertEquals("text/a - test1", r);
-
- try {
- client.doPut(url + "?noTrace=true",
"test1").contentType("text/b").getResponseAsString();
- fail("Exception expected");
- } catch (RestCallException e) {
- checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
- "Unsupported media-type in request header
'Content-Type': 'text/b'",
- "Supported media-types: ['text/a"
- );
- }
-
- r = client.doPut(url,
"'test1'").contentType("text/json").accept("text/json").getResponseAsString();
- assertEquals("\"test1\"", r);
- }
-
-
//====================================================================================================
- // Parser defined on method.
-
//====================================================================================================
- @Test
- public void testParserOnMethod() throws Exception {
- RestClient client = TestMicroservice.DEFAULT_CLIENT_PLAINTEXT;
- String url = URL + "/testParserOnMethod";
-
- String r = client.doPut(url,
"test2").contentType("text/b").getResponseAsString();
- assertEquals("text/b - test2", r);
-
- try {
- client.doPut(url + "?noTrace=true",
"test2").contentType("text/a").getResponseAsString();
- fail("Exception expected");
- } catch (RestCallException e) {
- checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
- "Unsupported media-type in request header
'Content-Type': 'text/a'",
- "Supported media-types: ['text/b']"
- );
- }
-
- try {
- r = client.doPut(url + "?noTrace=true",
"'test2'").contentType("text/json").getResponseAsString();
- fail("Exception expected");
- } catch (RestCallException e) {
- checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
- "Unsupported media-type in request header
'Content-Type': 'text/json'",
- "Supported media-types: ['text/b']"
- );
- }
- }
-
-
//====================================================================================================
- // Parser overridden on method.
-
//====================================================================================================
- @Test
- public void testParserOverriddenOnMethod() throws Exception {
- RestClient client = TestMicroservice.DEFAULT_CLIENT_PLAINTEXT;
- String url = URL + "/testParserOverriddenOnMethod";
-
- String r = client.doPut(url,
"test3").contentType("text/a").getResponseAsString();
- assertEquals("text/a - test3", r);
-
- r = client.doPut(url,
"test3").contentType("text/b").getResponseAsString();
- assertEquals("text/b - test3", r);
-
- r = client.doPut(url,
"'test3'").contentType("text/json").getResponseAsString();
- assertEquals("test3", r);
- }
-
-
//====================================================================================================
- // Parser with different Accept than Content-Type.
-
//====================================================================================================
- @Test
- public void testParserWithDifferentMediaTypes() throws Exception {
- RestClient client = TestMicroservice.DEFAULT_CLIENT_PLAINTEXT;
- String url = URL + "/testParserWithDifferentMediaTypes";
-
- String r = client.doPut(url,
"test4").contentType("text/a").getResponseAsString();
- assertEquals("text/a - test4", r);
-
- r = client.doPut(url,
"test4").contentType("text/d").getResponseAsString();
- assertEquals("text/d - test4", r);
-
- r = client.doPut(url,
"'test4'").contentType("text/json").getResponseAsString();
- assertEquals("test4", r);
- }
-
-
//====================================================================================================
- // Check for valid error response.
-
//====================================================================================================
- @Test
- public void testValidErrorResponse() throws Exception {
- RestClient client = TestMicroservice.DEFAULT_CLIENT_PLAINTEXT;
- String url = URL + "/testValidErrorResponse";
-
- try {
- client.doPut(url + "?noTrace=true",
"test1").contentType("text/bad").getResponseAsString();
- fail("Exception expected");
- } catch (RestCallException e) {
- checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
- "Unsupported media-type in request header
'Content-Type': 'text/bad'",
- "Supported media-types: ['text/a"
- );
- }
- }
-}
diff --git
a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/SerializersTest.java
b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/SerializersTest.java
deleted file mode 100644
index c65880d..0000000
---
a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/SerializersTest.java
+++ /dev/null
@@ -1,130 +0,0 @@
-//
***************************************************************************************************************************
-// * 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. *
-//
***************************************************************************************************************************
-package org.apache.juneau.rest.test;
-
-import static javax.servlet.http.HttpServletResponse.*;
-import static org.apache.juneau.microservice.testutils.TestUtils.*;
-import static org.junit.Assert.*;
-
-import org.apache.juneau.rest.client.*;
-import org.junit.*;
-
-public class SerializersTest extends RestTestcase {
-
- private static String URL = "/testSerializers";
- private static boolean debug = false;
- private RestClient client = TestMicroservice.DEFAULT_CLIENT;
-
-
-
//====================================================================================================
- // Serializer defined on class.
-
//====================================================================================================
- @Test
- public void testSerializerOnClass() throws Exception {
- String url = URL + "/testSerializerOnClass";
-
- String r =
client.doGet(url).accept("text/a").getResponseAsString();
- assertEquals("text/a - test1", r);
-
- try {
- client.doGet(url +
"?noTrace=true").accept("text/b").getResponseAsString();
- fail("Exception expected");
- } catch (RestCallException e) {
- checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE,
- "Unsupported media-type in request header
'Accept': 'text/b'",
- "Supported media-types: ['text/a',");
- }
-
- r = client.doGet(url).accept("text/json").getResponseAsString();
- assertEquals("\"test1\"", r);
- }
-
-
//====================================================================================================
- // Serializer defined on method.
-
//====================================================================================================
- @Test
- public void testSerializerOnMethod() throws Exception {
- String url = URL + "/testSerializerOnMethod";
-
- try {
- client.doGet(url +
"?noTrace=true").accept("text/a").getResponseAsString();
- fail("Exception expected");
- } catch (RestCallException e) {
- checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE,
- "Unsupported media-type in request header
'Accept': 'text/a'",
- "Supported media-types: ['text/b']"
- );
- }
-
- try {
- client.doGet(url +
"?noTrace=true").accept("text/json").getResponseAsString();
- fail("Exception expected");
- } catch (RestCallException e) {
- checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE,
- "Unsupported media-type in request header
'Accept': 'text/json'",
- "Supported media-types: ['text/b']"
- );
- }
- }
-
-
//====================================================================================================
- // Serializer overridden on method.
-
//====================================================================================================
- @Test
- public void testSerializerOverriddenOnMethod() throws Exception {
- String url = URL + "/testSerializerOverriddenOnMethod";
-
- String r =
client.doGet(url).accept("text/a").getResponseAsString();
- assertEquals("text/c - test3", r);
-
- r = client.doGet(url).accept("text/b").getResponseAsString();
- assertEquals("text/b - test3", r);
-
- r = client.doGet(url).accept("text/json").getResponseAsString();
- assertEquals("\"test3\"", r);
- }
-
-
//====================================================================================================
- // Serializer with different Accept than Content-Type.
-
//====================================================================================================
- @Test
- public void testSerializerWithDifferentMediaTypes() throws Exception {
- String url = URL + "/testSerializerWithDifferentMediaTypes";
-
- String r =
client.doGet(url).accept("text/a").getResponseAsString();
- assertEquals("text/d - test4", r);
-
- r = client.doGet(url).accept("text/d").getResponseAsString();
- assertEquals("text/d - test4", r);
-
- r = client.doGet(url).accept("text/json").getResponseAsString();
- assertEquals("\"test4\"", r);
- }
-
-
//====================================================================================================
- // Check for valid 406 error response.
-
//====================================================================================================
- @Test
- public void test406() throws Exception {
- String url = URL + "/test406";
-
- try {
- client.doGet(url +
"?noTrace=true").accept("text/bad").getResponseAsString();
- fail("Exception expected");
- } catch (RestCallException e) {
- checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE,
- "Unsupported media-type in request header
'Accept': 'text/bad'",
- "Supported media-types: ['text/a");
- }
- }
-}
diff --git
a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/_TestSuite.java
b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/_TestSuite.java
index b409348..c83cba8 100644
---
a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/_TestSuite.java
+++
b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/_TestSuite.java
@@ -32,13 +32,10 @@ import org.junit.runners.Suite.*;
HtmlDocTest.class,
HtmlDocLinksTest.class,
InterfaceProxyTest.class,
- JacocoDummyTest.class,
LargePojosTest.class,
- ParsersTest.class,
PathsTest.class,
RequestBeanProxyTest.class,
RestClientTest.class,
- SerializersTest.class,
ThirdPartyProxyTest.class,
})
public class _TestSuite {
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/mock/MockRest.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/mock/MockRest.java
index 6d3adb8..6771ed5 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/mock/MockRest.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/mock/MockRest.java
@@ -80,11 +80,23 @@ public class MockRest {
*
* @param method The HTTP method
* @param path The URI path.
- * @param pathArgs Optional path arguments.
+ * @param body The body of the request.
* @return A new servlet request.
* @throws Exception
*/
- public MockServletRequest request(String method, String path,
Object...pathArgs) throws Exception {
- return MockServletRequest.create(method, path,
pathArgs).restContext(rc);
+ public MockServletRequest request(String method, String path, Object
body) throws Exception {
+ return MockServletRequest.create(method,
path).body(body).restContext(rc);
+ }
+
+ /**
+ * Performs a REST request against the REST interface.
+ *
+ * @param method The HTTP method
+ * @param path The URI path.
+ * @return A new servlet request.
+ * @throws Exception
+ */
+ public MockServletRequest request(String method, String path) throws
Exception {
+ return request(method, path, null);
}
}
diff --git
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/RestParamsTest.java
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/RestParamsTest.java
index 50e6665..00c724d 100644
---
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/RestParamsTest.java
+++
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/RestParamsTest.java
@@ -139,15 +139,15 @@ public class RestParamsTest {
}
@Test
public void a03_InputStream() throws Exception {
- a.request("POST",
"/InputStream").body("foo").execute().assertBody("foo");
+ a.request("POST", "/InputStream",
"foo").execute().assertBody("foo");
}
@Test
public void a04_ServletInputStream() throws Exception {
- a.request("POST",
"/ServletInputStream").body("foo").execute().assertBody("foo");
+ a.request("POST", "/ServletInputStream",
"foo").execute().assertBody("foo");
}
@Test
public void a05_Reader() throws Exception {
- a.request("POST",
"/Reader").body("foo").execute().assertBody("foo");
+ a.request("POST", "/Reader", "foo").execute().assertBody("foo");
}
@Test
public void a06_OutputStream() throws Exception {
diff --git
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/StatusCodesTest.java
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/StatusCodesTest.java
index c0f96c5..422cd95 100644
---
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/StatusCodesTest.java
+++
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/StatusCodesTest.java
@@ -43,7 +43,7 @@ public class StatusCodesTest {
@Test
public void a01a_OK() throws Exception {
- a.request("PUT", "/").body("foo").execute().assertStatus(200);
+ a.request("PUT", "/", "foo").execute().assertStatus(200);
}
//=================================================================================================================
@@ -108,7 +108,7 @@ public class StatusCodesTest {
@Test
public void b01a_nonExistentBeanProperties() throws Exception {
- b.request("PUT",
"/nonExistentBeanProperties?noTrace=true").body("{f2:'foo'}").json().execute()
+ b.request("PUT", "/nonExistentBeanProperties?noTrace=true",
"{f2:'foo'}").json().execute()
.assertStatus(400)
.assertBodyContains(
"Unknown property 'f2' encountered while trying
to parse into class 'org.apache.juneau.rest.StatusCodesTest$B$B01'"
@@ -116,7 +116,7 @@ public class StatusCodesTest {
}
@Test
public void b01b_nonExistentBeanProperties() throws Exception {
- b.request("PUT",
"/nonExistentBeanProperties?noTrace=true").body("{f1:'foo',
f2:'foo'}").json().execute()
+ b.request("PUT", "/nonExistentBeanProperties?noTrace=true",
"{f1:'foo', f2:'foo'}").json().execute()
.assertStatus(400)
.assertBodyContains(
"Unknown property 'f2' encountered while trying
to parse into class 'org.apache.juneau.rest.StatusCodesTest$B$B01'"
@@ -124,7 +124,7 @@ public class StatusCodesTest {
}
@Test
public void b02_wrongDataType() throws Exception {
- b.request("PUT",
"/wrongDataType?noTrace=true").body("{f1:'foo'}").json().execute()
+ b.request("PUT", "/wrongDataType?noTrace=true",
"{f1:'foo'}").json().execute()
.assertStatus(400)
.assertBodyContains(
"Invalid number"
@@ -132,7 +132,7 @@ public class StatusCodesTest {
}
@Test
public void b03_parseIntoNonConstructableBean() throws Exception {
- b.request("PUT",
"/parseIntoNonConstructableBean?noTrace=true").body("{f1:1}").json().execute()
+ b.request("PUT", "/parseIntoNonConstructableBean?noTrace=true",
"{f1:1}").json().execute()
.assertStatus(400)
.assertBodyContains(
"could not be instantiated"
@@ -140,7 +140,7 @@ public class StatusCodesTest {
}
@Test
public void b04_parseIntoNonStaticInnerClass() throws Exception {
- b.request("PUT",
"/parseIntoNonStaticInnerClass?noTrace=true").body("{f1:1}").json().execute()
+ b.request("PUT", "/parseIntoNonStaticInnerClass?noTrace=true",
"{f1:1}").json().execute()
.assertStatus(400)
.assertBodyContains(
"could not be instantiated"
@@ -148,7 +148,7 @@ public class StatusCodesTest {
}
@Test
public void b05_parseIntoNonStaticInnerClass() throws Exception {
- b.request("PUT",
"/parseIntoNonPublicInnerClass?noTrace=true").body("{f1:1}").json().execute()
+ b.request("PUT", "/parseIntoNonPublicInnerClass?noTrace=true",
"{f1:1}").json().execute()
.assertStatus(400)
.assertBodyContains(
"Class is not public"
@@ -156,7 +156,7 @@ public class StatusCodesTest {
}
@Test
public void b06_thrownConstructorException() throws Exception {
- b.request("PUT",
"/thrownConstructorException?noTrace=true").body("'foo'").json().execute()
+ b.request("PUT", "/thrownConstructorException?noTrace=true",
"'foo'").json().execute()
.assertStatus(400)
.assertBodyContains(
"Test error"
@@ -164,7 +164,7 @@ public class StatusCodesTest {
}
@Test
public void b07a_setParameterToInvalidTypes_Query() throws Exception {
- b.request("PUT",
"/setParameterToInvalidTypes/123?noTrace=true&p1=foo").body("'foo'").json().execute()
+ b.request("PUT",
"/setParameterToInvalidTypes/123?noTrace=true&p1=foo", "'foo'").json().execute()
.assertStatus(400)
.assertBodyContains(
"Could not convert QUERY 'p1' to type 'int'"
@@ -172,7 +172,7 @@ public class StatusCodesTest {
}
@Test
public void b07a_setParameterToInvalidTypes_Path() throws Exception {
- b.request("PUT",
"/setParameterToInvalidTypes/foo?noTrace=true&p1=1").body("'foo'").json().execute()
+ b.request("PUT",
"/setParameterToInvalidTypes/foo?noTrace=true&p1=1", "'foo'").json().execute()
.assertStatus(400)
.assertBodyContains(
"Could not convert PATH 'a1' to type 'int'"
@@ -180,7 +180,7 @@ public class StatusCodesTest {
}
@Test
public void b07a_setParameterToInvalidTypes_Header() throws Exception {
- b.request("PUT",
"/setParameterToInvalidTypes/123?noTrace=true&p1=1").header("h1",
"foo").body("'foo'").json().execute()
+ b.request("PUT",
"/setParameterToInvalidTypes/123?noTrace=true&p1=1", "'foo'").header("h1",
"foo").json().execute()
.assertStatus(400)
.assertBodyContains(
"Could not convert HEADER 'h1' to type 'int'"
diff --git
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/BodyAnnotationTest.java
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/BodyAnnotationTest.java
index 5c9389f..3599e95 100644
---
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/BodyAnnotationTest.java
+++
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/BodyAnnotationTest.java
@@ -121,139 +121,139 @@ public class BodyAnnotationTest {
@Test
public void a01a_onParameter_String() throws Exception {
- a.request("PUT",
"/String").body("'foo'").json().execute().assertBody("'foo'");
+ a.request("PUT", "/String",
"'foo'").json().execute().assertBody("'foo'");
}
@Test
public void a01b_onParameter_String_noContentType() throws Exception {
// If no Content-Type specified, should be treated as
plain-text.
- a.request("PUT",
"/String").body("'foo'").execute().assertBody("'\\'foo\\''");
+ a.request("PUT", "/String",
"'foo'").execute().assertBody("'\\'foo\\''");
}
@Test
public void a01c_onParameter_String_noContentType_other() throws
Exception {
// If Content-Type not matched, should be treated as plain-text.
- a.request("PUT",
"/String").body("'foo'").contentType("").execute().assertBody("'\\'foo\\''");
- a.request("PUT",
"/String").body("'foo'").contentType("text/plain").execute().assertBody("'\\'foo\\''");
+ a.request("PUT", "/String",
"'foo'").contentType("").execute().assertBody("'\\'foo\\''");
+ a.request("PUT", "/String",
"'foo'").contentType("text/plain").execute().assertBody("'\\'foo\\''");
}
@Test
public void a02a_onParameter_Integer() throws Exception {
- a.request("PUT",
"/Integer").body("123").json().execute().assertBody("123");
+ a.request("PUT", "/Integer",
"123").json().execute().assertBody("123");
}
@Test
public void a02b_onParameter_Integer_noContentType() throws Exception {
// Integer takes in a String arg, so it can be parsed without
Content-Type.
- a.request("PUT",
"/Integer").body("123").execute().assertBody("123");
+ a.request("PUT", "/Integer", "123").execute().assertBody("123");
}
@Test
public void a03a_onParameter_int() throws Exception {
- a.request("PUT",
"/int").body("123").json().execute().assertBody("123");
+ a.request("PUT", "/int",
"123").json().execute().assertBody("123");
}
@Test
public void a03b_onParameter_int_noContentType() throws Exception {
- a.request("PUT",
"/int?noTrace=true").body("123").execute().assertBodyContains("Unsupported
Media Type");
+ a.request("PUT", "/int?noTrace=true",
"123").execute().assertBodyContains("Unsupported Media Type");
}
@Test
public void a04a_onParameter_Boolean() throws Exception {
- a.request("PUT",
"/Boolean").body("true").json().execute().assertBody("true");
+ a.request("PUT", "/Boolean",
"true").json().execute().assertBody("true");
}
@Test
public void a04b_onParameter_Boolean_noContentType() throws Exception {
// Boolean takes in a String arg, so it can be parsed without
Content-Type.
- a.request("PUT",
"/Boolean").body("true").execute().assertBody("true");
+ a.request("PUT", "/Boolean",
"true").execute().assertBody("true");
}
@Test
public void a05a_onParameter_boolean() throws Exception {
- a.request("PUT",
"/boolean").body("true").json().execute().assertBody("true");
+ a.request("PUT", "/boolean",
"true").json().execute().assertBody("true");
}
@Test
public void a05b_onParameter_boolean_noContentType() throws Exception {
- a.request("PUT",
"/boolean?noTrace=true").body("true").execute().assertBodyContains("Unsupported
Media Type");
+ a.request("PUT", "/boolean?noTrace=true",
"true").execute().assertBodyContains("Unsupported Media Type");
}
@Test
public void a06a_onParameter_float() throws Exception {
- a.request("PUT",
"/float").body("1.23").json().execute().assertBody("1.23");
+ a.request("PUT", "/float",
"1.23").json().execute().assertBody("1.23");
}
@Test
public void a06b_onParameter_float_noContentType() throws Exception {
- a.request("PUT",
"/float?noTrace=true").body("1.23").execute().assertBodyContains("Unsupported
Media Type");
+ a.request("PUT", "/float?noTrace=true",
"1.23").execute().assertBodyContains("Unsupported Media Type");
}
@Test
public void a07a_onParameter_Float() throws Exception {
- a.request("PUT",
"/Float").body("1.23").json().execute().assertBody("1.23");
+ a.request("PUT", "/Float",
"1.23").json().execute().assertBody("1.23");
}
@Test
public void a07b_onParameter_Float_noContentType() throws Exception {
// Float takes in a String arg, so it can be parsed without
Content-Type.
- a.request("PUT",
"/Float").body("1.23").execute().assertBody("1.23");
+ a.request("PUT", "/Float", "1.23").execute().assertBody("1.23");
}
@Test
public void a08a_onParameter_Map() throws Exception {
- a.request("PUT",
"/Map").body("{foo:123}").json().execute().assertBody("{foo:123}");
+ a.request("PUT", "/Map",
"{foo:123}").json().execute().assertBody("{foo:123}");
}
@Test
public void a08b_onParameter_Map_noContentType() throws Exception {
- a.request("PUT",
"/Map?noTrace=true").body("{foo:123}").execute().assertBodyContains("Unsupported
Media Type");
+ a.request("PUT", "/Map?noTrace=true",
"{foo:123}").execute().assertBodyContains("Unsupported Media Type");
}
@Test
public void a09a_onParameter_enum() throws Exception {
- a.request("PUT",
"/enum").body("'ONE'").json().execute().assertBody("'ONE'");
+ a.request("PUT", "/enum",
"'ONE'").json().execute().assertBody("'ONE'");
}
@Test
public void a09b_onParameter_enum_noContentType() throws Exception {
- a.request("PUT",
"/enum").body("ONE").execute().assertBody("'ONE'");
+ a.request("PUT", "/enum", "ONE").execute().assertBody("'ONE'");
}
@Test
public void a11a_onParameter_Bean() throws Exception {
- a.request("PUT",
"/Bean").body("{f1:'a'}").json().execute().assertBody("{f1:'a'}");
+ a.request("PUT", "/Bean",
"{f1:'a'}").json().execute().assertBody("{f1:'a'}");
}
@Test
public void a11b_onParameter_Bean_noContentType() throws Exception {
- a.request("PUT",
"/Bean?noTrace=true").body("{f1:'a'}").execute().assertBodyContains("Unsupported
Media Type");
+ a.request("PUT", "/Bean?noTrace=true",
"{f1:'a'}").execute().assertBodyContains("Unsupported Media Type");
}
@Test
public void a12a_onParameter_InputStream() throws Exception {
// Content-Type should always be ignored.
- a.request("PUT",
"/InputStream").body("'a'").json().execute().assertBody("'\\'a\\''");
+ a.request("PUT", "/InputStream",
"'a'").json().execute().assertBody("'\\'a\\''");
}
@Test
public void a12b_onParameter_InputStream_noContentType() throws
Exception {
- a.request("PUT",
"/InputStream").body("'a'").execute().assertBody("'\\'a\\''");
+ a.request("PUT", "/InputStream",
"'a'").execute().assertBody("'\\'a\\''");
}
@Test
public void a13a_onParameter_Reader() throws Exception {
// Content-Type should always be ignored.
- a.request("PUT",
"/Reader").body("'a'").json().execute().assertBody("'\\'a\\''");
+ a.request("PUT", "/Reader",
"'a'").json().execute().assertBody("'\\'a\\''");
}
@Test
public void a13b_onParameter_Reader_noContentType() throws Exception {
- a.request("PUT",
"/Reader").body("'a'").execute().assertBody("'\\'a\\''");
+ a.request("PUT", "/Reader",
"'a'").execute().assertBody("'\\'a\\''");
}
@Test
public void a14a_onParameter_InputStreamTransform() throws Exception {
// Input stream transform requests must not specify
Content-Type or else gets resolved as POJO.
- a.request("PUT",
"/InputStreamTransform?noTrace=true").body("'a'").json().execute().assertBodyContains("Bad
Request");
+ a.request("PUT", "/InputStreamTransform?noTrace=true",
"'a'").json().execute().assertBodyContains("Bad Request");
}
@Test
public void a14b_onParameter_InputStreamTransform_noContentType()
throws Exception {
- a.request("PUT",
"/InputStreamTransform").body("'a'").execute().assertBody("'\\'a\\''");
+ a.request("PUT", "/InputStreamTransform",
"'a'").execute().assertBody("'\\'a\\''");
}
@Test
public void a15a_onParameter_ReaderTransform() throws Exception {
// Reader transform requests must not specify Content-Type or
else gets resolved as POJO.
- a.request("PUT",
"/ReaderTransform?noTrace=true").body("'a'").json().execute().assertBodyContains("Bad
Request");
+ a.request("PUT", "/ReaderTransform?noTrace=true",
"'a'").json().execute().assertBodyContains("Bad Request");
}
@Test
public void a15b_onParameter_ReaderTransform_noContentType() throws
Exception {
- a.request("PUT",
"/ReaderTransform").body("'a'").execute().assertBody("'\\'a\\''");
+ a.request("PUT", "/ReaderTransform",
"'a'").execute().assertBody("'\\'a\\''");
}
@Test
public void a16a_onParameter_StringTransform() throws Exception {
// When Content-Type specified and matched, treated as a parsed
POJO.
- a.request("PUT",
"/StringTransform").body("'a'").json().execute().assertBody("'a'");
+ a.request("PUT", "/StringTransform",
"'a'").json().execute().assertBody("'a'");
}
@Test
public void a16b_onParameter_StringTransform_noContentType() throws
Exception {
// When Content-Type not matched, treated as plain text.
- a.request("PUT",
"/StringTransform").body("'a'").execute().assertBody("'\\'a\\''");
+ a.request("PUT", "/StringTransform",
"'a'").execute().assertBody("'\\'a\\''");
}
//=================================================================================================================
@@ -311,46 +311,46 @@ public class BodyAnnotationTest {
@Test
public void b01a_onPojo_StringTransform() throws Exception {
- b.request("PUT",
"/StringTransform").body("'foo'").json().execute().assertBody("'foo'");
+ b.request("PUT", "/StringTransform",
"'foo'").json().execute().assertBody("'foo'");
}
@Test
public void b01b_onPojo_StringTransform_noContentType() throws
Exception {
// When Content-Type not matched, treated as plain text.
- b.request("PUT",
"/StringTransform").body("'foo'").execute().assertBody("'\\'foo\\''");
+ b.request("PUT", "/StringTransform",
"'foo'").execute().assertBody("'\\'foo\\''");
}
@Test
public void b02a_onPojo_Bean() throws Exception {
- b.request("PUT",
"/Bean").body("{f1:'a'}").json().execute().assertBody("{f1:'a'}");
+ b.request("PUT", "/Bean",
"{f1:'a'}").json().execute().assertBody("{f1:'a'}");
}
@Test
public void b02b_onPojo_Bean_noContentType() throws Exception {
- b.request("PUT",
"/Bean?noTrace=true").body("{f1:'a'}").execute().assertBodyContains("Unsupported
Media Type");
+ b.request("PUT", "/Bean?noTrace=true",
"{f1:'a'}").execute().assertBodyContains("Unsupported Media Type");
}
@Test
public void b03a_onPojo_BeanList() throws Exception {
- b.request("PUT",
"/BeanList").body("[{f1:'a'}]").json().execute().assertBody("[{f1:'a'}]");
+ b.request("PUT", "/BeanList",
"[{f1:'a'}]").json().execute().assertBody("[{f1:'a'}]");
}
@Test
public void b03b_onPojo_BeanList_noContentType() throws Exception {
- b.request("PUT",
"/BeanList?noTrace=true").body("[{f1:'a'}]").execute().assertBodyContains("Unsupported
Media Type");
+ b.request("PUT", "/BeanList?noTrace=true",
"[{f1:'a'}]").execute().assertBodyContains("Unsupported Media Type");
}
@Test
public void b04a_onPojo_InputStreamTransform() throws Exception {
- b.request("PUT",
"/InputStreamTransform").body("a").execute().assertBody("'a'");
+ b.request("PUT", "/InputStreamTransform",
"a").execute().assertBody("'a'");
}
@Test
public void b04b_onPojo_InputStreamTransform_withContentType() throws
Exception {
// When Content-Type matched, treated as parsed POJO.
- b.request("PUT",
"/InputStreamTransform?noTrace=true").body("a").json().execute().assertBodyContains("Bad
Request");
+ b.request("PUT", "/InputStreamTransform?noTrace=true",
"a").json().execute().assertBodyContains("Bad Request");
}
@Test
public void b05a_onPojo_ReaderTransform() throws Exception {
- b.request("PUT",
"/ReaderTransform").body("a").execute().assertBody("'a'");
+ b.request("PUT", "/ReaderTransform",
"a").execute().assertBody("'a'");
}
@Test
public void b05b_onPojo_ReaderTransform_withContentType() throws
Exception {
// When Content-Type matched, treated as parsed POJO.
- b.request("PUT",
"/ReaderTransform?noTrace=true").body("a").json().execute().assertBodyContains("Bad
Request");
+ b.request("PUT", "/ReaderTransform?noTrace=true",
"a").json().execute().assertBodyContains("Bad Request");
}
//=================================================================================================================
@@ -530,75 +530,75 @@ public class BodyAnnotationTest {
@Test
public void d01a_noMediaTypes_String() throws Exception {
- d.request("PUT", "/String").body("a").execute().assertBody("a");
+ d.request("PUT", "/String", "a").execute().assertBody("a");
}
@Test
public void d01b_noMediaTypes_String_withContentType() throws Exception
{
- d.request("PUT",
"/String").body("a").json().execute().assertBody("a");
+ d.request("PUT", "/String",
"a").json().execute().assertBody("a");
}
@Test
public void d02a_noMediaTypes_InputStream() throws Exception {
- d.request("PUT",
"/InputStream").body("a").execute().assertBody("a");
+ d.request("PUT", "/InputStream", "a").execute().assertBody("a");
}
@Test
public void d02b_noMediaTypes_InputStream_withContentType() throws
Exception {
- d.request("PUT",
"/InputStream").body("a").json().execute().assertBody("a");
+ d.request("PUT", "/InputStream",
"a").json().execute().assertBody("a");
}
@Test
public void d03a_noMediaTypes_Reader() throws Exception {
- d.request("PUT", "/Reader").body("a").execute().assertBody("a");
+ d.request("PUT", "/Reader", "a").execute().assertBody("a");
}
@Test
public void d03b_noMediaTypes_Reader_withContentType() throws Exception
{
- d.request("PUT",
"/Reader").body("a").json().execute().assertBody("a");
+ d.request("PUT", "/Reader",
"a").json().execute().assertBody("a");
}
@Test
public void d04a_noMediaTypes_StringTransform() throws Exception {
- d.request("PUT",
"/StringTransform").body("a").execute().assertBody("a");
+ d.request("PUT", "/StringTransform",
"a").execute().assertBody("a");
}
@Test
public void d04b_noMediaTypes_StringTransform_withContentType() throws
Exception {
- d.request("PUT",
"/StringTransform?noTrace=true").body("a").json().execute().assertStatus(415);
+ d.request("PUT", "/StringTransform?noTrace=true",
"a").json().execute().assertStatus(415);
}
@Test
public void d05a_noMediaTypes_InputStreamTransform() throws Exception {
- d.request("PUT",
"/InputStreamTransform").body("a").execute().assertBody("a");
+ d.request("PUT", "/InputStreamTransform",
"a").execute().assertBody("a");
}
@Test
public void d05b_noMediaTypes_InputStreamTransform_withContentType()
throws Exception {
- d.request("PUT",
"/InputStreamTransform").body("a").json().execute().assertBody("a");
+ d.request("PUT", "/InputStreamTransform",
"a").json().execute().assertBody("a");
}
@Test
public void d06a_noMediaTypes_ReaderTransform() throws Exception {
- d.request("PUT",
"/ReaderTransform").body("a").execute().assertBody("a");
+ d.request("PUT", "/ReaderTransform",
"a").execute().assertBody("a");
}
@Test
public void d06b_noMediaTypes_ReaderTransform_withContentType() throws
Exception {
- d.request("PUT",
"/ReaderTransform").body("a").json().execute().assertBody("a");
+ d.request("PUT", "/ReaderTransform",
"a").json().execute().assertBody("a");
}
@Test
public void d07a_noMediaTypes_StringTransformBodyOnPojo() throws
Exception {
- d.request("PUT",
"/StringTransformBodyOnPojo").body("a").execute().assertBody("a");
+ d.request("PUT", "/StringTransformBodyOnPojo",
"a").execute().assertBody("a");
}
@Test
public void
d07b_noMediaTypes_StringTransformBodyOnPojo_withContentType() throws Exception {
- d.request("PUT",
"/StringTransformBodyOnPojo?noTrace=true").body("a").json().execute().assertStatus(415);
+ d.request("PUT", "/StringTransformBodyOnPojo?noTrace=true",
"a").json().execute().assertStatus(415);
}
@Test
public void d08a_noMediaTypes_InputStreamTransformBodyOnPojo() throws
Exception {
- d.request("PUT",
"/InputStreamTransformBodyOnPojo").body("a").execute().assertBody("a");
+ d.request("PUT", "/InputStreamTransformBodyOnPojo",
"a").execute().assertBody("a");
}
@Test
public void
d08b_noMediaTypes_InputStreamTransformBodyOnPojo_withContentType() throws
Exception {
- d.request("PUT",
"/InputStreamTransformBodyOnPojo").body("a").json().execute().assertBody("a");
+ d.request("PUT", "/InputStreamTransformBodyOnPojo",
"a").json().execute().assertBody("a");
}
@Test
public void d09a_noMediaTypes_ReaderTransformBodyOnPojo() throws
Exception {
- d.request("PUT",
"/ReaderTransformBodyOnPojo").body("a").execute().assertBody("a");
+ d.request("PUT", "/ReaderTransformBodyOnPojo",
"a").execute().assertBody("a");
}
@Test
public void
d09b_noMediaTypes_ReaderTransformBodyOnPojo_withContentType() throws Exception {
- d.request("PUT",
"/ReaderTransformBodyOnPojo").body("a").json().execute().assertBody("a");
+ d.request("PUT", "/ReaderTransformBodyOnPojo",
"a").json().execute().assertBody("a");
}
//=================================================================================================================
@@ -621,22 +621,22 @@ public class BodyAnnotationTest {
@Test
public void e01_complexPojos_B_body() throws Exception {
String expected =
"{f01:['a','b'],f02:['c','d'],f03:[1,2],f04:[3,4],f05:[['e','f'],['g','h']],f06:[['i','j'],['k','l']],f07:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f08:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f09:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}
[...]
- e.request("PUT",
"/B").body(JsonSerializer.DEFAULT_LAX.toString(DTOs.B.INSTANCE)).json().execute().assertBody(expected);
+ e.request("PUT", "/B",
JsonSerializer.DEFAULT_LAX.toString(DTOs.B.INSTANCE)).json().execute().assertBody(expected);
}
@Test
public void e02_complexPojos_B_bodyParam() throws Exception {
String expected =
"{f01:['a','b'],f02:['c','d'],f03:[1,2],f04:[3,4],f05:[['e','f'],['g','h']],f06:[['i','j'],['k','l']],f07:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f08:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f09:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}
[...]
- e.request("PUT", "/B?body=" +
UonSerializer.DEFAULT.serialize(DTOs.B.INSTANCE)).body("a").execute().assertBody(expected);
+ e.request("PUT", "/B?body=" +
UonSerializer.DEFAULT.serialize(DTOs.B.INSTANCE),
"a").execute().assertBody(expected);
}
@Test
public void e03_complexPojos_C_body() throws Exception {
String expected =
"{f01:['a','b'],f02:['c','d'],f03:[1,2],f04:[3,4],f05:[['e','f'],['g','h']],f06:[['i','j'],['k','l']],f07:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f08:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f09:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}
[...]
- e.request("PUT",
"/C").body(JsonSerializer.DEFAULT_LAX.toString(DTOs.B.INSTANCE)).json().execute().assertBody(expected);
+ e.request("PUT", "/C",
JsonSerializer.DEFAULT_LAX.toString(DTOs.B.INSTANCE)).json().execute().assertBody(expected);
}
@Test
public void e04_complexPojos_C_bodyParam() throws Exception {
String expected =
"{f01:['a','b'],f02:['c','d'],f03:[1,2],f04:[3,4],f05:[['e','f'],['g','h']],f06:[['i','j'],['k','l']],f07:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f08:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f09:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}
[...]
- e.request("PUT", "/C?body=" +
UonSerializer.DEFAULT.serialize(DTOs.B.INSTANCE)).body("a").execute().assertBody(expected);
+ e.request("PUT", "/C?body=" +
UonSerializer.DEFAULT.serialize(DTOs.B.INSTANCE),
"a").execute().assertBody(expected);
}
//=================================================================================================================
@@ -661,10 +661,10 @@ public class BodyAnnotationTest {
@Test
public void f01_formPostAsContent() throws Exception {
- f.request("POST",
"/").body("{p1:'p1',p2:2}").json().execute().assertBody("bean=[{p1:'p1',p2:2}],qp1=[null],qp2=[0],hqp1=[false],hqp2=[false]");
- f.request("POST",
"/").body("{}").json().execute().assertBody("bean=[{p2:0}],qp1=[null],qp2=[0],hqp1=[false],hqp2=[false]");
- f.request("POST",
"?p1=p3&p2=4").body("{p1:'p1',p2:2}").json().execute().assertBody("bean=[{p1:'p1',p2:2}],qp1=[p3],qp2=[4],hqp1=[true],hqp2=[true]");
- f.request("POST",
"?p1=p3&p2=4").body("{}").json().execute().assertBody("bean=[{p2:0}],qp1=[p3],qp2=[4],hqp1=[true],hqp2=[true]");
+ f.request("POST", "/",
"{p1:'p1',p2:2}").json().execute().assertBody("bean=[{p1:'p1',p2:2}],qp1=[null],qp2=[0],hqp1=[false],hqp2=[false]");
+ f.request("POST", "/",
"{}").json().execute().assertBody("bean=[{p2:0}],qp1=[null],qp2=[0],hqp1=[false],hqp2=[false]");
+ f.request("POST", "?p1=p3&p2=4",
"{p1:'p1',p2:2}").json().execute().assertBody("bean=[{p1:'p1',p2:2}],qp1=[p3],qp2=[4],hqp1=[true],hqp2=[true]");
+ f.request("POST", "?p1=p3&p2=4",
"{}").json().execute().assertBody("bean=[{p2:0}],qp1=[p3],qp2=[4],hqp1=[true],hqp2=[true]");
}
//=================================================================================================================
@@ -705,7 +705,7 @@ public class BodyAnnotationTest {
+ "&f18=(a=a,b=1,c=true)&f18=(a=b,b=2,c=false)"
+ "&f19=@((a=a,b=1,c=true))&f19=@((a=b,b=2,c=false))"
+ "&f20=@((a=a,b=1,c=true))&f20=@((a=b,b=2,c=false))";
- g.request("POST",
"/").body(in).urlEnc().execute().assertBody(in);
+ g.request("POST", "/", in).urlEnc().execute().assertBody(in);
}
//=================================================================================================================
@@ -751,6 +751,6 @@ public class BodyAnnotationTest {
+ "&f18=(a=a,b=1,c=true)&f18=(a=b,b=2,c=false)"
+ "&f19=@((a=a,b=1,c=true))&f19=@((a=b,b=2,c=false))"
+ "&f20=@((a=a,b=1,c=true))&f20=@((a=b,b=2,c=false))";
- h.request("POST",
"/").body(in).urlEnc().execute().assertBody(in);
+ h.request("POST", "/", in).urlEnc().execute().assertBody(in);
}
}
diff --git
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/FormDataAnnotationTest.java
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/FormDataAnnotationTest.java
index b882768..e4c163c 100644
---
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/FormDataAnnotationTest.java
+++
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/FormDataAnnotationTest.java
@@ -45,18 +45,18 @@ public class FormDataAnnotationTest {
@Test
public void a01() throws Exception {
- a.request("POST",
"").body("p1=p1&p2=2").contentType("application/x-www-form-urlencoded").execute().assertBody("p1=[p1,p1,p1],p2=[2,2,2]");
- a.request("POST",
"").body("p1&p2").contentType("application/x-www-form-urlencoded").execute().assertBody("p1=[null,null,null],p2=[0,null,0]");
- a.request("POST",
"").body("p1=&p2=").contentType("application/x-www-form-urlencoded").execute().assertBody("p1=[,,],p2=[0,,0]");
+ a.request("POST", "",
"p1=p1&p2=2").contentType("application/x-www-form-urlencoded").execute().assertBody("p1=[p1,p1,p1],p2=[2,2,2]");
+ a.request("POST", "",
"p1&p2").contentType("application/x-www-form-urlencoded").execute().assertBody("p1=[null,null,null],p2=[0,null,0]");
+ a.request("POST", "",
"p1=&p2=").contentType("application/x-www-form-urlencoded").execute().assertBody("p1=[,,],p2=[0,,0]");
a.request("POST",
"").contentType("application/x-www-form-urlencoded").execute().assertBody("p1=[null,null,null],p2=[0,null,0]");
- a.request("POST",
"").body("p1").contentType("application/x-www-form-urlencoded").execute().assertBody("p1=[null,null,null],p2=[0,null,0]");
- a.request("POST",
"").body("p1=").contentType("application/x-www-form-urlencoded").execute().assertBody("p1=[,,],p2=[0,null,0]");
- a.request("POST",
"").body("p2").contentType("application/x-www-form-urlencoded").execute().assertBody("p1=[null,null,null],p2=[0,null,0]");
- a.request("POST",
"").body("p2=").contentType("application/x-www-form-urlencoded").execute().assertBody("p1=[null,null,null],p2=[0,,0]");
- a.request("POST",
"").body("p1=foo&p2").contentType("application/x-www-form-urlencoded").execute().assertBody("p1=[foo,foo,foo],p2=[0,null,0]");
- a.request("POST",
"").body("p1&p2=1").contentType("application/x-www-form-urlencoded").execute().assertBody("p1=[null,null,null],p2=[1,1,1]");
+ a.request("POST", "",
"p1").contentType("application/x-www-form-urlencoded").execute().assertBody("p1=[null,null,null],p2=[0,null,0]");
+ a.request("POST", "",
"p1=").contentType("application/x-www-form-urlencoded").execute().assertBody("p1=[,,],p2=[0,null,0]");
+ a.request("POST", "",
"p2").contentType("application/x-www-form-urlencoded").execute().assertBody("p1=[null,null,null],p2=[0,null,0]");
+ a.request("POST", "",
"p2=").contentType("application/x-www-form-urlencoded").execute().assertBody("p1=[null,null,null],p2=[0,,0]");
+ a.request("POST", "",
"p1=foo&p2").contentType("application/x-www-form-urlencoded").execute().assertBody("p1=[foo,foo,foo],p2=[0,null,0]");
+ a.request("POST", "",
"p1&p2=1").contentType("application/x-www-form-urlencoded").execute().assertBody("p1=[null,null,null],p2=[1,1,1]");
String x = "a%2Fb%25c%3Dd+e"; // [x/y%z=a+b]
- a.request("POST",
"").body("p1="+x+"&p2=1").contentType("application/x-www-form-urlencoded").execute().assertBody("p1=[a/b%c=d
e,a/b%c=d e,a/b%c=d e],p2=[1,1,1]");
+ a.request("POST", "",
"p1="+x+"&p2=1").contentType("application/x-www-form-urlencoded").execute().assertBody("p1=[a/b%c=d
e,a/b%c=d e,a/b%c=d e],p2=[1,1,1]");
}
//=================================================================================================================
@@ -75,8 +75,8 @@ public class FormDataAnnotationTest {
@Test
public void b01() throws Exception {
- b.request("POST",
"").body("p1=p1").contentType("application/x-www-form-urlencoded").execute().assertBody("p1=[p1,p1,p1]");
- b.request("POST",
"").body("p1='p1'").contentType("application/x-www-form-urlencoded").execute().assertBody("p1=['p1','p1',p1]");
+ b.request("POST", "",
"p1=p1").contentType("application/x-www-form-urlencoded").execute().assertBody("p1=[p1,p1,p1]");
+ b.request("POST", "",
"p1='p1'").contentType("application/x-www-form-urlencoded").execute().assertBody("p1=['p1','p1',p1]");
}
//=================================================================================================================
diff --git
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/HasFormDataAnnotationTest.java
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/HasFormDataAnnotationTest.java
index aca492b..7f2573e 100644
---
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/HasFormDataAnnotationTest.java
+++
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/HasFormDataAnnotationTest.java
@@ -43,17 +43,17 @@ public class HasFormDataAnnotationTest {
@Test
public void a01_post() throws Exception {
- a.request("POST",
"").body("p1=p1&p2=2").execute().assertBody("p1=[true,true],p2=[true,true]");
- a.request("POST",
"").body("p1&p2").execute().assertBody("p1=[true,true],p2=[true,true]");
- a.request("POST",
"").body("p1=&p2=").execute().assertBody("p1=[true,true],p2=[true,true]");
+ a.request("POST", "",
"p1=p1&p2=2").execute().assertBody("p1=[true,true],p2=[true,true]");
+ a.request("POST", "",
"p1&p2").execute().assertBody("p1=[true,true],p2=[true,true]");
+ a.request("POST", "",
"p1=&p2=").execute().assertBody("p1=[true,true],p2=[true,true]");
a.request("POST",
"/").execute().assertBody("p1=[false,false],p2=[false,false]");
- a.request("POST",
"").body("p1").execute().assertBody("p1=[true,true],p2=[false,false]");
- a.request("POST",
"").body("p1=").execute().assertBody("p1=[true,true],p2=[false,false]");
- a.request("POST",
"").body("p2").execute().assertBody("p1=[false,false],p2=[true,true]");
- a.request("POST",
"").body("p2=").execute().assertBody("p1=[false,false],p2=[true,true]");
- a.request("POST",
"").body("p1=foo&p2").execute().assertBody("p1=[true,true],p2=[true,true]");
- a.request("POST",
"").body("p1&p2=1").execute().assertBody("p1=[true,true],p2=[true,true]");
+ a.request("POST", "",
"p1").execute().assertBody("p1=[true,true],p2=[false,false]");
+ a.request("POST", "",
"p1=").execute().assertBody("p1=[true,true],p2=[false,false]");
+ a.request("POST", "",
"p2").execute().assertBody("p1=[false,false],p2=[true,true]");
+ a.request("POST", "",
"p2=").execute().assertBody("p1=[false,false],p2=[true,true]");
+ a.request("POST", "",
"p1=foo&p2").execute().assertBody("p1=[true,true],p2=[true,true]");
+ a.request("POST", "",
"p1&p2=1").execute().assertBody("p1=[true,true],p2=[true,true]");
String x = "a%2Fb%25c%3Dd+e"; // [x/y%z=a+b]
- a.request("POST",
"").body("p1="+x+"&p2=1").execute().assertBody("p1=[true,true],p2=[true,true]");
+ a.request("POST", "",
"p1="+x+"&p2=1").execute().assertBody("p1=[true,true],p2=[true,true]");
}
}
diff --git
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestResourceParsersTest.java
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestResourceParsersTest.java
new file mode 100644
index 0000000..ef60920
--- /dev/null
+++
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestResourceParsersTest.java
@@ -0,0 +1,167 @@
+//
***************************************************************************************************************************
+// * 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. *
+//
***************************************************************************************************************************
+package org.apache.juneau.rest.annotation;
+
+import static org.apache.juneau.http.HttpMethodName.*;
+import static org.apache.juneau.internal.IOUtils.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.rest.mock.*;
+import org.junit.*;
+import org.junit.runners.*;
+
+/**
+ * Tests that validate the behavior of @RestMethod(parsers).
+ */
+@SuppressWarnings({"javadoc"})
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class RestResourceParsersTest {
+
+
//=================================================================================================================
+ // Setup
+
//=================================================================================================================
+
+ public static class PA extends ReaderParser {
+ public PA(PropertyStore ps) {
+ super(ps, "text/a");
+ }
+ @Override /* Parser */
+ public ReaderParserSession createSession(ParserSessionArgs
args) {
+ return new ReaderParserSession(args) {
+ @Override /* ParserSession */
+ @SuppressWarnings("unchecked")
+ protected <T> T doParse(ParserPipe pipe,
ClassMeta<T> type) throws Exception {
+ return (T)("text/a - " +
read(pipe.getReader()).trim());
+ }
+ };
+ }
+ }
+
+ public static class PB extends ReaderParser {
+ public PB(PropertyStore ps) {
+ super(ps, "text/b");
+ }
+ @Override /* Parser */
+ public ReaderParserSession createSession(ParserSessionArgs
args) {
+ return new ReaderParserSession(args) {
+ @Override /* ParserSession */
+ @SuppressWarnings("unchecked")
+ protected <T> T doParse(ParserPipe pipe,
ClassMeta<T> type) throws Exception {
+ return (T)("text/b - " +
read(pipe.getReader()).trim());
+ }
+ };
+ }
+ }
+
+ public static class PC extends ReaderParser {
+ public PC(PropertyStore ps) {
+ super(ps, "text/c");
+ }
+ @Override /* Parser */
+ public ReaderParserSession createSession(ParserSessionArgs
args) {
+ return new ReaderParserSession(args) {
+ @Override /* ParserSession */
+ @SuppressWarnings("unchecked")
+ protected <T> T doParse(ParserPipe pipe,
ClassMeta<T> type) throws Exception {
+ return (T)("text/c - " +
read(pipe.getReader()).trim());
+ }
+ };
+ }
+ }
+
+ public static class PD extends ReaderParser {
+ public PD(PropertyStore ps) {
+ super(ps, "text/d");
+ }
+ @Override /* Parser */
+ public ReaderParserSession createSession(ParserSessionArgs
args) {
+ return new ReaderParserSession(args) {
+ @Override /* ParserSession */
+ @SuppressWarnings("unchecked")
+ protected <T> T doParse(ParserPipe pipe,
ClassMeta<T> type) throws Exception {
+ return (T)("text/d - " +
read(pipe.getReader()).trim());
+ }
+ };
+ }
+ }
+
+
//=================================================================================================================
+ // Basic tests
+
//=================================================================================================================
+
+ @RestResource(parsers=PA.class)
+ public static class A {
+ @RestMethod(name=PUT, path="/parserOnClass")
+ public String a01(@Body String in) {
+ return in;
+ }
+ @RestMethod(name=PUT, path="/parserOnMethod", parsers=PB.class)
+ public String a02(@Body String in) {
+ return in;
+ }
+ @RestMethod(name=PUT, path="/parserOverriddenOnMethod",
parsers={PB.class,PC.class}, inherit="PARSERS")
+ public String a03(@Body String in) {
+ return in;
+ }
+ @RestMethod(name=PUT, path="/parserWithDifferentMediaTypes",
parsers={PD.class}, inherit="PARSERS")
+ public String a04(@Body String in) {
+ return in;
+ }
+ @RestMethod(name=PUT, path="/validErrorResponse")
+ public String a05(@Body String in) {
+ return in;
+ }
+ }
+ static MockRest a = MockRest.create(A.class);
+
+ @Test
+ public void a01_parserOnClass() throws Exception {
+ a.request("PUT", "/parserOnClass",
"test1").contentType("text/a").execute().assertBody("text/a - test1");
+ a.request("PUT", "/parserOnClass?noTrace=true",
"test1").contentType("text/b").execute()
+ .assertStatus(415)
+ .assertBodyContains(
+ "Unsupported media-type in request header
'Content-Type': 'text/b'",
+ "Supported media-types: ['text/a"
+ );
+ }
+ @Test
+ public void a02_parserOnMethod() throws Exception {
+ a.request("PUT", "/parserOnMethod",
"test2").contentType("text/b").execute().assertBody("text/b - test2");
+ a.request("PUT", "/parserOnMethod?noTrace=true",
"test2").contentType("text/a").execute()
+ .assertStatus(415)
+ .assertBodyContains(
+ "Unsupported media-type in request header
'Content-Type': 'text/a'",
+ "Supported media-types: ['text/b']"
+ );
+ }
+ @Test
+ public void a03_parserOverriddenOnMethod() throws Exception {
+ a.request("PUT", "/parserOverriddenOnMethod",
"test3").contentType("text/a").execute().assertBody("text/a - test3");
+ a.request("PUT", "/parserOverriddenOnMethod",
"test3").contentType("text/b").execute().assertBody("text/b - test3");
+ }
+ @Test
+ public void a04_parserWithDifferentMediaTypes() throws Exception {
+ a.request("PUT", "/parserWithDifferentMediaTypes",
"test4").contentType("text/a").execute().assertBody("text/a - test4");
+ a.request("PUT", "/parserWithDifferentMediaTypes",
"test4").contentType("text/d").execute().assertBody("text/d - test4");
+ }
+ @Test
+ public void a05_validErrorResponse() throws Exception {
+ a.request("PUT", "/validErrorResponse?noTrace=true",
"test1").contentType("text/bad").execute()
+ .assertStatus(415)
+ .assertBodyContains(
+ "Unsupported media-type in request header
'Content-Type': 'text/bad'",
+ "Supported media-types: ['text/a"
+ );
+ }
+}
diff --git
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestResourcePojoSwapsTest.java
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestResourcePojoSwapsTest.java
index 9790891..95b2552 100644
---
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestResourcePojoSwapsTest.java
+++
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestResourcePojoSwapsTest.java
@@ -119,14 +119,14 @@ public class RestResourcePojoSwapsTest {
@Test
public void a01_classTransformOverridesParentClassTransform() throws
Exception {
a.request("GET",
"/classTransformOverridesParentClassTransform").json().execute().assertBody("'A2-0'");
- a.request("PUT",
"/classTransformOverridesParentClassTransform").json().body("'A2-1'").execute().assertBody("'A2-1'");
+ a.request("PUT",
"/classTransformOverridesParentClassTransform",
"'A2-1'").json().execute().assertBody("'A2-1'");
a.request("PUT",
"/classTransformOverridesParentClassTransform/A2-2").json().execute().assertBody("'A2-2'");
}
@Test
public void a02_methodTransformOverridesClassTransform() throws
Exception {
a.request("GET",
"/methodTransformOverridesClassTransform").json().execute().assertBody("'A3-0'");
- a.request("PUT",
"/methodTransformOverridesClassTransform").json().body("'A3-1'").execute().assertBody("'A3-1'");
+ a.request("PUT", "/methodTransformOverridesClassTransform",
"'A3-1'").json().execute().assertBody("'A3-1'");
a.request("PUT",
"/methodTransformOverridesClassTransform/A3-2").json().execute().assertBody("'A3-2'");
}
}
diff --git
a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/SerializersResource.java
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestResourceSerializersTest.java
similarity index 50%
rename from
juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/SerializersResource.java
rename to
juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestResourceSerializersTest.java
index 5a67893..79540a7 100644
---
a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/SerializersResource.java
+++
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/annotation/RestResourceSerializersTest.java
@@ -10,35 +10,34 @@
// * "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. *
//
***************************************************************************************************************************
-package org.apache.juneau.rest.test;
+package org.apache.juneau.rest.annotation;
import static org.apache.juneau.http.HttpMethodName.*;
import org.apache.juneau.*;
-import org.apache.juneau.rest.*;
-import org.apache.juneau.rest.annotation.*;
+import org.apache.juneau.rest.mock.*;
import org.apache.juneau.serializer.*;
+import org.junit.*;
+import org.junit.runners.*;
/**
- * JUnit automated testcase resource.
+ * Tests that validate the behavior of @RestMethod(serializers).
*/
-@RestResource(
- path="/testSerializers",
- serializers=SerializersResource.TestSerializerA.class
-)
-public class SerializersResource extends BasicRestServlet {
- private static final long serialVersionUID = 1L;
+@SuppressWarnings({"javadoc"})
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class RestResourceSerializersTest {
- public static class TestSerializerA extends WriterSerializer {
+
//=================================================================================================================
+ // Setup
+
//=================================================================================================================
- public TestSerializerA(PropertyStore ps) {
+ public static class SA extends WriterSerializer {
+ public SA(PropertyStore ps) {
super(ps, "text/a", null);
}
-
@Override /* Serializer */
public WriterSerializerSession
createSession(SerializerSessionArgs args) {
return new WriterSerializerSession(args) {
-
@Override /* SerializerSession */
protected void doSerialize(SerializerPipe out,
Object o) throws Exception {
out.getWriter().write("text/a - " + o);
@@ -47,16 +46,13 @@ public class SerializersResource extends BasicRestServlet {
}
}
- public static class TestSerializerB extends WriterSerializer {
-
- public TestSerializerB(PropertyStore ps) {
+ public static class SB extends WriterSerializer {
+ public SB(PropertyStore ps) {
super(ps, "text/b", null);
}
-
@Override /* Serializer */
public WriterSerializerSession
createSession(SerializerSessionArgs args) {
return new WriterSerializerSession(args) {
-
@Override /* SerializerSession */
protected void doSerialize(SerializerPipe out,
Object o) throws Exception {
out.getWriter().write("text/b - " + o);
@@ -65,40 +61,13 @@ public class SerializersResource extends BasicRestServlet {
}
}
-
//====================================================================================================
- // Serializer defined on class.
-
//====================================================================================================
- @RestMethod(name=GET, path="/testSerializerOnClass")
- public String testSerializerOnClass() {
- return "test1";
- }
-
-
//====================================================================================================
- // Serializer defined on method.
-
//====================================================================================================
- @RestMethod(name=GET, path="/testSerializerOnMethod",
serializers=TestSerializerB.class)
- public String testSerializerOnMethod() {
- return "test2";
- }
-
-
//====================================================================================================
- // Serializer overridden on method.
-
//====================================================================================================
- @RestMethod(name=GET, path="/testSerializerOverriddenOnMethod",
serializers={TestSerializerB.class,TestSerializerC.class},
inherit="SERIALIZERS")
- public String testSerializerOverriddenOnMethod() {
- return "test3";
- }
-
- public static class TestSerializerC extends WriterSerializer {
-
- public TestSerializerC(PropertyStore ps) {
+ public static class SC extends WriterSerializer {
+ public SC(PropertyStore ps) {
super(ps, "text/a", null);
}
-
@Override /* Serializer */
public WriterSerializerSession
createSession(SerializerSessionArgs args) {
return new WriterSerializerSession(args) {
-
@Override /* SerializerSession */
protected void doSerialize(SerializerPipe out,
Object o) throws Exception {
out.getWriter().write("text/c - " + o);
@@ -107,20 +76,10 @@ public class SerializersResource extends BasicRestServlet {
}
}
-
//====================================================================================================
- // Serializer with different Accept than Content-Type.
-
//====================================================================================================
- @RestMethod(name=GET, path="/testSerializerWithDifferentMediaTypes",
serializers={TestSerializerD.class}, inherit="SERIALIZERS")
- public String testSerializerWithDifferentMediaTypes() {
- return "test4";
- }
-
- public static class TestSerializerD extends WriterSerializer {
-
- public TestSerializerD(PropertyStore ps) {
+ public static class SD extends WriterSerializer {
+ public SD(PropertyStore ps) {
super(ps, "text/d", "text/a,text/d");
}
-
@Override /* Serializer */
public WriterSerializerSession
createSession(SerializerSessionArgs args) {
return new WriterSerializerSession(args) {
@@ -133,11 +92,71 @@ public class SerializersResource extends BasicRestServlet {
}
}
-
//====================================================================================================
- // Check for valid 406 error response.
-
//====================================================================================================
- @RestMethod(name=GET, path="/test406")
- public String test406() {
- return "test406";
+
//=================================================================================================================
+ // Basic tests
+
//=================================================================================================================
+
+ @RestResource(serializers=SA.class)
+ public static class A {
+ @RestMethod(name=GET, path="/serializerOnClass")
+ public String a01() {
+ return "test1";
+ }
+ @RestMethod(name=GET, path="/serializerOnMethod",
serializers=SB.class)
+ public String a02() {
+ return "test2";
+ }
+ @RestMethod(name=GET, path="/serializerOverriddenOnMethod",
serializers={SB.class,SC.class}, inherit="SERIALIZERS")
+ public String a03() {
+ return "test3";
+ }
+ @RestMethod(name=GET,
path="/serializerWithDifferentMediaTypes", serializers={SD.class},
inherit="SERIALIZERS")
+ public String a04() {
+ return "test4";
+ }
+ @RestMethod(name=GET, path="/validErrorResponse")
+ public String a05() {
+ return "test406";
+ }
+ }
+ static MockRest a = MockRest.create(A.class);
+
+ @Test
+ public void a01_serializerOnClass() throws Exception {
+ a.request("GET",
"/serializerOnClass").accept("text/a").execute().assertBody("text/a - test1");
+ a.request("GET",
"/serializerOnClass?noTrace=true").accept("text/b").execute()
+ .assertStatus(406)
+ .assertBodyContains(
+ "Unsupported media-type in request header
'Accept': 'text/b'",
+ "Supported media-types: ['text/a'"
+ );
+ }
+ @Test
+ public void a02_serializerOnMethod() throws Exception {
+ a.request("GET",
"/serializerOnMethod?noTrace=true").accept("text/a").execute()
+ .assertStatus(406)
+ .assertBodyContains(
+ "Unsupported media-type in request header
'Accept': 'text/a'",
+ "Supported media-types: ['text/b']"
+ );
+ }
+ @Test
+ public void a03_serializerOverriddenOnMethod() throws Exception {
+ a.request("GET",
"/serializerOverriddenOnMethod").accept("text/a").execute().assertBody("text/c
- test3");
+ a.request("GET",
"/serializerOverriddenOnMethod").accept("text/b").execute().assertBody("text/b
- test3");
+ }
+ @Test
+ public void a04_serializerWithDifferentMediaTypes() throws Exception {
+ a.request("GET",
"/serializerWithDifferentMediaTypes").accept("text/a").execute().assertBody("text/d
- test4");
+ a.request("GET",
"/serializerWithDifferentMediaTypes").accept("text/d").execute().assertBody("text/d
- test4");
+ }
+ @Test
+ public void a05_validErrorResponse() throws Exception {
+ a.request("GET",
"/validErrorResponse?noTrace=true").accept("text/bad").execute()
+ .assertStatus(406)
+ .assertBodyContains(
+ "Unsupported media-type in request header
'Accept': 'text/bad'",
+ "Supported media-types: ['text/a"
+ );
}
}
diff --git
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/headers/ContentEncodingTest.java
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/headers/ContentEncodingTest.java
index e82c24d..7c37789 100644
---
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/headers/ContentEncodingTest.java
+++
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/headers/ContentEncodingTest.java
@@ -54,13 +54,13 @@ public class ContentEncodingTest {
@Test
public void a01_noCompression() throws Exception {
- a.request("PUT", "/").body("foo").execute().assertBody("foo");
- a.request("PUT",
"/").body("foo").contentEncoding("").execute().assertBody("foo");
- a.request("PUT",
"/").body("foo").contentEncoding("identity").execute().assertBody("foo");
+ a.request("PUT", "/", "foo").execute().assertBody("foo");
+ a.request("PUT", "/",
"foo").contentEncoding("").execute().assertBody("foo");
+ a.request("PUT", "/",
"foo").contentEncoding("identity").execute().assertBody("foo");
}
@Test
public void a02_noCompression_invalid() throws Exception {
- a.request("PUT",
"?noTrace=true").body(compress("foo")).contentEncoding("mycoding").execute()
+ a.request("PUT", "?noTrace=true",
compress("foo")).contentEncoding("mycoding").execute()
.assertStatus(415)
.assertBodyContains(
"Unsupported encoding in request header
'Content-Encoding': 'mycoding'",
@@ -83,12 +83,12 @@ public class ContentEncodingTest {
@Test
public void b01_withCompression_identity() throws Exception {
- b.request("PUT", "/").body("foo").execute().assertBody("foo");
- b.request("PUT",
"/").body("foo").contentEncoding("").execute().assertBody("foo");
- b.request("PUT",
"/").body("foo").contentEncoding("identity").execute().assertBody("foo");
+ b.request("PUT", "/", "foo").execute().assertBody("foo");
+ b.request("PUT", "/",
"foo").contentEncoding("").execute().assertBody("foo");
+ b.request("PUT", "/",
"foo").contentEncoding("identity").execute().assertBody("foo");
}
@Test
public void b02_withCompression_gzip() throws Exception {
- b.request("PUT",
"/").body(compress("foo")).contentEncoding("mycoding").execute().assertBody("foo");
+ b.request("PUT", "/",
compress("foo")).contentEncoding("mycoding").execute().assertBody("foo");
}
}
--
To stop receiving notification emails like this one, please contact
[email protected].