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 89e56ee REST refactoring.
89e56ee is described below
commit 89e56ee663f747fdf7d34e5a3b5c188971a8409d
Author: JamesBognar <[email protected]>
AuthorDate: Thu Feb 18 11:35:09 2021 -0500
REST refactoring.
---
.../juneau/examples/rest/RootResourcesTest.java | 16 +--
.../org/apache/juneau/rest/test/ConfigTest.java | 2 +-
.../apache/juneau/rest/client/ResponseBody.java | 89 +++++++++-----
.../apache/juneau/rest/client/ResponseHeader.java | 30 ++---
.../org/apache/juneau/rest/client/RestClient.java | 12 +-
.../apache/juneau/rest/client/RestResponse.java | 6 +-
.../assertion/FluentResponseBodyAssertion.java | 4 +-
.../assertion/FluentResponseHeaderAssertion.java | 32 +++++
.../java/org/apache/juneau/rest/RequestBody.java | 36 +++++-
.../java/org/apache/juneau/rest/RequestHeader.java | 10 +-
.../org/apache/juneau/rest/RequestQueryParam.java | 10 +-
.../java/org/apache/juneau/rest/RestRequest.java | 20 ++-
.../org/apache/juneau/rest/args/HeaderArg.java | 6 +-
.../java/org/apache/juneau/rest/args/QueryArg.java | 8 +-
.../assertions/FluentRequestBodyAssertion.java} | 134 ++++++++-------------
.../juneau/rest/client/RestCallException_Test.java | 2 +-
.../client/RestClient_Config_BeanContext_Test.java | 134 ++++++++++-----------
.../client/RestClient_Config_Context_Test.java | 26 ++--
.../rest/client/RestClient_Config_Parser_Test.java | 4 +-
.../client/RestClient_Config_RestClient_Test.java | 42 +++----
.../rest/client/RestClient_Marshalls_Test.java | 98 +++++++--------
.../rest/client/RestClient_Response_Body_Test.java | 16 +--
.../client/RestClient_Response_Headers_Test.java | 26 ++--
23 files changed, 411 insertions(+), 352 deletions(-)
diff --git
a/juneau-examples/juneau-examples-rest-jetty-ftest/src/test/java/org/apache/juneau/examples/rest/RootResourcesTest.java
b/juneau-examples/juneau-examples-rest-jetty-ftest/src/test/java/org/apache/juneau/examples/rest/RootResourcesTest.java
index 7574537..76d4db0 100644
---
a/juneau-examples/juneau-examples-rest-jetty-ftest/src/test/java/org/apache/juneau/examples/rest/RootResourcesTest.java
+++
b/juneau-examples/juneau-examples-rest-jetty-ftest/src/test/java/org/apache/juneau/examples/rest/RootResourcesTest.java
@@ -38,11 +38,11 @@ public class RootResourcesTest extends RestTestcase {
public void testJson() throws Exception {
RestClient client = SamplesMicroservice.DEFAULT_CLIENT;
- ResourceDescription[] x =
client.get("").run().getBody().as(ResourceDescription[].class);
+ ResourceDescription[] x =
client.get("").run().getBody().asType(ResourceDescription[].class);
assertEquals("helloWorld", x[0].getName());
assertEquals("Hello World", x[0].getDescription());
- OMap x2 = jsonClient.get("api").run().getBody().as(OMap.class);
+ OMap x2 =
jsonClient.get("api").run().getBody().asType(OMap.class);
String s = x2.getMap("info").getString("description");
if (debug) System.err.println(s);
assertTrue(s, s.startsWith("Example of a router resource
page"));
@@ -55,11 +55,11 @@ public class RootResourcesTest extends RestTestcase {
public void testXml() throws Exception {
try (RestClient client =
SamplesMicroservice.client().xml().build()) {
- ResourceDescription[] x =
client.get("").run().getBody().as(ResourceDescription[].class);
+ ResourceDescription[] x =
client.get("").run().getBody().asType(ResourceDescription[].class);
assertEquals("helloWorld", x[0].getName());
assertEquals("Hello World", x[0].getDescription());
- OMap x2 =
jsonClient.get("api").run().getBody().as(OMap.class);
+ OMap x2 =
jsonClient.get("api").run().getBody().asType(OMap.class);
String s = x2.getMap("info").getString("description");
if (debug) System.err.println(s);
assertTrue(s, s.startsWith("Example of a router
resource page"));
@@ -73,11 +73,11 @@ public class RootResourcesTest extends RestTestcase {
public void testHtmlStripped() throws Exception {
try (RestClient client =
SamplesMicroservice.client().parsers(HtmlParser.DEFAULT).accept("text/html+stripped").build())
{
- ResourceDescription[] x =
client.get("").run().getBody().as(ResourceDescription[].class);
+ ResourceDescription[] x =
client.get("").run().getBody().asType(ResourceDescription[].class);
assertEquals("helloWorld", x[0].getName());
assertEquals("Hello World", x[0].getDescription());
- OMap x2 =
jsonClient.get("api").run().getBody().as(OMap.class);
+ OMap x2 =
jsonClient.get("api").run().getBody().asType(OMap.class);
String s = x2.getMap("info").getString("description");
if (debug) System.err.println(s);
assertTrue(s, s.startsWith("Example of a router
resource page"));
@@ -90,7 +90,7 @@ public class RootResourcesTest extends RestTestcase {
@Test
public void testJsonSchema() throws Exception {
try (RestClient client =
SamplesMicroservice.client().parsers(JsonParser.DEFAULT).accept("text/json+schema").build())
{
- OMap m = client.get("").run().getBody().as(OMap.class);
+ OMap m =
client.get("").run().getBody().asType(OMap.class);
if (debug) System.err.println(m);
client.closeQuietly();
}
@@ -101,7 +101,7 @@ public class RootResourcesTest extends RestTestcase {
//====================================================================================================
@Test
public void testOptionsPage() throws Exception {
- Swagger o =
jsonClient.get("api").run().getBody().as(Swagger.class);
+ Swagger o =
jsonClient.get("api").run().getBody().asType(Swagger.class);
if (debug) System.err.println(o);
assertEquals("Example of a router resource page.",
o.getInfo().getDescription());
}
diff --git
a/juneau-microservice/juneau-microservice-ftest/src/test/java/org/apache/juneau/rest/test/ConfigTest.java
b/juneau-microservice/juneau-microservice-ftest/src/test/java/org/apache/juneau/rest/test/ConfigTest.java
index 217b261..2eaf940 100644
---
a/juneau-microservice/juneau-microservice-ftest/src/test/java/org/apache/juneau/rest/test/ConfigTest.java
+++
b/juneau-microservice/juneau-microservice-ftest/src/test/java/org/apache/juneau/rest/test/ConfigTest.java
@@ -36,7 +36,7 @@ public class ConfigTest extends RestTestcase {
public void test() throws Exception {
RestClient c =
TestMicroservice.client().accept("text/json+simple").build();
- Map<String,Map<String,Object>> m =
c.get(URL).run().getBody().as(Map.class, String.class, OMap.class);
+ Map<String,Map<String,Object>> m =
c.get(URL).run().getBody().asType(Map.class, String.class, OMap.class);
Config cf = Config.create().memStore().build().load(m);
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/ResponseBody.java
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/ResponseBody.java
index 297eeea..aedc868 100644
---
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/ResponseBody.java
+++
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/ResponseBody.java
@@ -99,7 +99,7 @@ public class ResponseBody implements HttpEntity {
private final HttpEntity entity;
private HttpPartSchema schema;
private Parser parser;
- private byte[] cache;
+ private byte[] body;
private boolean cached;
boolean isConsumed;
@@ -195,13 +195,13 @@ public class ResponseBody implements HttpEntity {
@SuppressWarnings("resource")
public InputStream asInputStream() throws IOException {
try {
- if (cache != null)
- return new ByteArrayInputStream(cache);
+ if (body != null)
+ return new ByteArrayInputStream(body);
if (cached) {
- cache = IOUtils.readBytes(entity.getContent());
+ body = IOUtils.readBytes(entity.getContent());
response.close();
- return new ByteArrayInputStream(cache);
+ return new ByteArrayInputStream(body);
}
if (isConsumed && ! entity.isRepeatable())
@@ -311,16 +311,16 @@ public class ResponseBody implements HttpEntity {
* @throws RestCallException If an exception occurred.
*/
public byte[] asBytes() throws RestCallException {
- if (cache == null) {
+ if (body == null) {
try {
- cache = IOUtils.readBytes(entity.getContent());
+ body = IOUtils.readBytes(entity.getContent());
} catch (IOException e) {
throw new RestCallException(response, e, "Could
not read response body.");
} finally {
response.close();
}
}
- return cache;
+ return body;
}
@@ -507,7 +507,7 @@ public class ResponseBody implements HttpEntity {
*
* <ul class='notes'>
* <li>
- * Use the {@link #as(Class)} method instead if you don't
need a parameterized map/collection.
+ * Use the {@link #asType(Class)} method instead if you
don't need a parameterized map/collection.
* <li>
* You can also specify any of the following types:
* <ul class='compact'>
@@ -540,12 +540,12 @@ public class ResponseBody implements HttpEntity {
* </ul>
* @see BeanSession#getClassMeta(Class) for argument syntax for maps
and collections.
*/
- public <T> T as(Type type, Type...args) throws RestCallException {
- return as(getClassMeta(type, args));
+ public <T> T asType(Type type, Type...args) throws RestCallException {
+ return asType(getClassMeta(type, args));
}
/**
- * Same as {@link #as(Type,Type...)} except optimized for a
non-parameterized class.
+ * Same as {@link #asType(Type,Type...)} except optimized for a
non-parameterized class.
*
* <p>
* This is the preferred parse method for simple types since you don't
need to cast the results.
@@ -587,19 +587,19 @@ public class ResponseBody implements HttpEntity {
*
* @param <T>
* The class type of the object being created.
- * See {@link #as(Type,Type...)} for details.
+ * See {@link #asType(Type,Type...)} for details.
* @param type The object type to create.
* @return The parsed object.
* @throws RestCallException
* If the input contains a syntax error or is malformed, or is not
valid for the specified type, or if a connection
* error occurred.
*/
- public <T> T as(Class<T> type) throws RestCallException {
- return as(getClassMeta(type));
+ public <T> T asType(Class<T> type) throws RestCallException {
+ return asType(getClassMeta(type));
}
/**
- * Same as {@link #as(Class)} except allows you to predefine complex
data types using the {@link ClassMeta} API.
+ * Same as {@link #asType(Class)} except allows you to predefine
complex data types using the {@link ClassMeta} API.
*
* <h5 class='section'>Examples:</h5>
* <p class='bcode w800'>
@@ -646,7 +646,7 @@ public class ResponseBody implements HttpEntity {
* @see BeanSession#getClassMeta(Class) for argument syntax for maps
and collections.
*/
@SuppressWarnings("unchecked")
- public <T> T as(ClassMeta<T> type) throws RestCallException {
+ public <T> T asType(ClassMeta<T> type) throws RestCallException {
try {
Class<?> ic = type.getInnerClass();
@@ -736,7 +736,7 @@ public class ResponseBody implements HttpEntity {
}
/**
- * Same as {@link #as(Class)} but allows you to run the call
asynchronously.
+ * Same as {@link #asType(Class)} but allows you to run the call
asynchronously.
*
* <ul class='notes'>
* <li>
@@ -760,14 +760,14 @@ public class ResponseBody implements HttpEntity {
new Callable<T>() {
@Override /* Callable */
public T call() throws Exception {
- return as(type);
+ return asType(type);
}
}
);
}
/**
- * Same as {@link #as(ClassMeta)} but allows you to run the call
asynchronously.
+ * Same as {@link #asType(ClassMeta)} but allows you to run the call
asynchronously.
*
* <ul class='notes'>
* <li>
@@ -780,7 +780,7 @@ public class ResponseBody implements HttpEntity {
*
* @param <T>
* The class type of the object being created.
- * See {@link #as(Type, Type...)} for details.
+ * See {@link #asType(Type, Type...)} for details.
* @param type The object type to create.
* @return The future object.
* @throws RestCallException If the executor service was not defined.
@@ -793,14 +793,14 @@ public class ResponseBody implements HttpEntity {
new Callable<T>() {
@Override /* Callable */
public T call() throws Exception {
- return as(type);
+ return asType(type);
}
}
);
}
/**
- * Same as {@link #as(Type,Type...)} but allows you to run the call
asynchronously.
+ * Same as {@link #asType(Type,Type...)} but allows you to run the call
asynchronously.
*
* <ul class='notes'>
* <li>
@@ -813,7 +813,7 @@ public class ResponseBody implements HttpEntity {
*
* @param <T>
* The class type of the object being created.
- * See {@link #as(Type, Type...)} for details.
+ * See {@link #asType(Type, Type...)} for details.
* @param type
* The object type to create.
* <br>Can be any of the following: {@link ClassMeta}, {@link
Class}, {@link ParameterizedType}, {@link GenericArrayType}
@@ -832,7 +832,7 @@ public class ResponseBody implements HttpEntity {
new Callable<T>() {
@Override /* Callable */
public T call() throws Exception {
- return as(type, args);
+ return asType(type, args);
}
}
);
@@ -904,16 +904,43 @@ public class ResponseBody implements HttpEntity {
*
* @param length The max length of the returned string.
* @return The truncated string.
- * @throws RestCallException
- * <ul>
- * <li>If a connection error occurred.
- * </ul>
+ * @throws RestCallException If a problem occurred trying to read from
the reader.
*/
public String asAbbreviatedString(int length) throws RestCallException {
return StringUtils.abbreviate(asString(), length);
}
/**
+ * Returns the HTTP body content as a simple hexadecimal character
string.
+ *
+ * <h5 class='section'>Example:</h5>
+ * <p class='bcode w800'>
+ * 0123456789ABCDEF
+ * </p>
+ *
+ * @return The incoming input from the connection as a plain string.
+ * @throws RestCallException If a problem occurred trying to read from
the reader.
+ */
+ public String asHex() throws RestCallException {
+ return toHex(asBytes());
+ }
+
+ /**
+ * Returns the HTTP body content as a simple space-delimited
hexadecimal character string.
+ *
+ * <h5 class='section'>Example:</h5>
+ * <p class='bcode w800'>
+ * 01 23 45 67 89 AB CD EF
+ * </p>
+ *
+ * @return The incoming input from the connection as a plain string.
+ * @throws RestCallException If a problem occurred trying to read from
the reader.
+ */
+ public String asSpacedHex() throws RestCallException {
+ return toSpacedHex(asBytes());
+ }
+
+ /**
* Parses the output from the body into the specified type and then
wraps that in a {@link PojoRest}.
*
* <p>
@@ -928,7 +955,7 @@ public class ResponseBody implements HttpEntity {
* </ul>
*/
public PojoRest asPojoRest(Class<?> innerType) throws RestCallException
{
- return new PojoRest(as(innerType));
+ return new PojoRest(asType(innerType));
}
/**
@@ -1188,7 +1215,7 @@ public class ResponseBody implements HttpEntity {
*/
@Override /* HttpEntity */
public long getContentLength() {
- return cache != null ? cache.length : entity.getContentLength();
+ return body != null ? body.length : entity.getContentLength();
}
/**
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/ResponseHeader.java
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/ResponseHeader.java
index 38379df..2afa920 100644
---
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/ResponseHeader.java
+++
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/ResponseHeader.java
@@ -320,12 +320,12 @@ public class ResponseHeader implements Header {
* @return The converted type, or <jk>null</jk> if header is not
present.
* @throws RestCallException If value could not be parsed.
*/
- public <T> Optional<T> as(Type type, Type...args) throws
RestCallException {
- return as(request.getClassMeta(type, args));
+ public <T> Optional<T> asType(Type type, Type...args) throws
RestCallException {
+ return asType(request.getClassMeta(type, args));
}
/**
- * Same as {@link #as(Type,Type...)} but sets the value in a mutable
for fluent calls.
+ * Same as {@link #asType(Type,Type...)} but sets the value in a
mutable for fluent calls.
*
* @param m The mutable to set the parsed header value in.
* @param <T> The type to convert to.
@@ -335,8 +335,8 @@ public class ResponseHeader implements Header {
* @throws RestCallException If value could not be parsed.
*/
@SuppressWarnings("unchecked")
- public <T> RestResponse as(Mutable<T> m, Type type, Type...args) throws
RestCallException {
- m.set((T)as(type, args).orElse(null));
+ public <T> RestResponse asType(Mutable<T> m, Type type, Type...args)
throws RestCallException {
+ m.set((T)asType(type, args).orElse(null));
return response;
}
@@ -348,12 +348,12 @@ public class ResponseHeader implements Header {
* @return The converted type, or <jk>null</jk> if header is not
present.
* @throws RestCallException If value could not be parsed.
*/
- public <T> Optional<T> as(Class<T> type) throws RestCallException {
- return as(request.getClassMeta(type));
+ public <T> Optional<T> asType(Class<T> type) throws RestCallException {
+ return asType(request.getClassMeta(type));
}
/**
- * Same as {@link #as(Class)} but sets the value in a mutable for
fluent calls.
+ * Same as {@link #asType(Class)} but sets the value in a mutable for
fluent calls.
*
* @param m The mutable to set the parsed header value in.
* @param <T> The type to convert to.
@@ -361,8 +361,8 @@ public class ResponseHeader implements Header {
* @return The response object (for method chaining).
* @throws RestCallException If value could not be parsed.
*/
- public <T> RestResponse as(Mutable<T> m, Class<T> type) throws
RestCallException {
- m.set(as(type).orElse(null));
+ public <T> RestResponse asType(Mutable<T> m, Class<T> type) throws
RestCallException {
+ m.set(asType(type).orElse(null));
return response;
}
@@ -374,7 +374,7 @@ public class ResponseHeader implements Header {
* @return The converted type, or <jk>null</jk> if header is not
present.
* @throws RestCallException If value could not be parsed.
*/
- public <T> Optional<T> as(ClassMeta<T> type) throws RestCallException {
+ public <T> Optional<T> asType(ClassMeta<T> type) throws
RestCallException {
try {
return ofNullable(parser.parse(HEADER, schema,
getValue(), type));
} catch (ParseException e) {
@@ -383,7 +383,7 @@ public class ResponseHeader implements Header {
}
/**
- * Same as {@link #as(ClassMeta)} but sets the value in a mutable for
fluent calls.
+ * Same as {@link #asType(ClassMeta)} but sets the value in a mutable
for fluent calls.
*
* @param m The mutable to set the parsed header value in.
* @param <T> The type to convert to.
@@ -391,8 +391,8 @@ public class ResponseHeader implements Header {
* @return The response object (for method chaining).
* @throws RestCallException If value could not be parsed.
*/
- public <T> RestResponse as(Mutable<T> m, ClassMeta<T> type) throws
RestCallException {
- m.set(as(type).orElse(null));
+ public <T> RestResponse asType(Mutable<T> m, ClassMeta<T> type) throws
RestCallException {
+ m.set(asType(type).orElse(null));
return response;
}
@@ -405,7 +405,7 @@ public class ResponseHeader implements Header {
* Matcher <jv>matcher</jv> = <jv>client</jv>
* .get(<jsf>URI</jsf>)
* .run()
- *
.getHeader(<js>"Content-Type"</js>).asMatcher(Pattern.<jsm>compile</jsm>(<js>"application/(.*)"</js>));
+ *
.getResponseHeader(<js>"Content-Type"</js>).asMatcher(Pattern.<jsm>compile</jsm>(<js>"application/(.*)"</js>));
*
* <jk>if</jk> (<jv>matcher</jv>.matches()) {
* String <jv>mediaType</jv> = <jv>matcher</jv>.group(1);
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
index 940a184..eb07958 100644
---
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
+++
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
@@ -604,8 +604,8 @@ import org.apache.juneau.utils.*;
* <ul>
* <li class='jm'><c>{@link ResponseHeader#exists() exists()}
<jk>returns</jk> <jk>boolean</jk></c>
* <li class='jm'><c>{@link ResponseHeader#asString() asString()}
<jk>returns</jk> String</c>
- * <li class='jm'><c>{@link ResponseHeader#as(Type,Type...)
as(Type,Type...)} <jk>returns</jk> T</c>
- * <li class='jm'><c>{@link ResponseHeader#as(Class)
as(Class<T>)} <jk>returns</jk> T</c>
+ * <li class='jm'><c>{@link ResponseHeader#asType(Type,Type...)
asType(Type,Type...)} <jk>returns</jk> T</c>
+ * <li class='jm'><c>{@link ResponseHeader#asType(Class)
asType(Class<T>)} <jk>returns</jk> T</c>
* <li class='jm'><c>{@link ResponseHeader#asMatcher(Pattern)
asMatcher(Pattern)} <jk>returns</jk> {@link Matcher}</c>
* <li class='jm'><c>{@link ResponseHeader#asMatcher(String)
asMatcher(String)} <jk>returns</jk> {@link Matcher}</c>
* <li class='jm'><c>{@link ResponseHeader#asHeader(Class)
asHeader(Class<T <jk>extends</jk> BasicHeader> c)} <jk>returns</jk>
{@link BasicHeader}</c>
@@ -681,8 +681,8 @@ import org.apache.juneau.utils.*;
* <li class='jm'><c>{@link ResponseBody#asReader(Charset)
asReader(Charset)} <jk>returns</jk> Reader</c>
* <li class='jm'><c>{@link ResponseBody#pipeTo(OutputStream)
pipeTo(OutputStream)} <jk>returns</jk> {@link RestResponse}</c>
* <li class='jm'><c>{@link ResponseBody#pipeTo(Writer)
pipeTo(Writer)} <jk>returns</jk> {@link RestResponse}</c>
- * <li class='jm'><c>{@link ResponseBody#as(Type,Type...)
as(Type,Type...)} <jk>returns</jk> T</c>
- * <li class='jm'><c>{@link ResponseBody#as(Class)
as(Class<T>)} <jk>returns</jk> T</c>
+ * <li class='jm'><c>{@link ResponseBody#asType(Type,Type...)
asType(Type,Type...)} <jk>returns</jk> T</c>
+ * <li class='jm'><c>{@link ResponseBody#asType(Class)
asType(Class<T>)} <jk>returns</jk> T</c>
* <li class='jm'><c>{@link ResponseBody#asFuture(Class)
asFuture(Class<T>)} <jk>returns</jk> Future<T></c>
* <li class='jm'><c>{@link ResponseBody#asFuture(Type,Type...)
asFuture(Type,Type...)} <jk>returns</jk> Future<T></c>
* <li class='jm'><c>{@link ResponseBody#asString() asString()}
<jk>returns</jk> String</c>
@@ -3188,7 +3188,7 @@ public class RestClient extends BeanContext implements
HttpClient, Closeable, Re
if (Throwable.class.isAssignableFrom(rt))
rc.ignoreErrors();
res = rc.run();
- Object v =
res.getBody().as(ror.getReturnType());
+ Object v =
res.getBody().asType(ror.getReturnType());
if (v == null && rt.isPrimitive())
v =
ClassInfo.of(rt).getPrimitiveDefault();
if
(rt.getName().equals(res.getStringHeader("Exception-Name").orElse(null)))
@@ -3308,7 +3308,7 @@ public class RestClient extends BeanContext implements
HttpClient, Closeable, Re
try {
RestRequest rc =
request("POST", uri, true).serializer(serializer).body(args);
- Object v =
rc.run().getBody().as(method.getGenericReturnType());
+ Object v =
rc.run().getBody().asType(method.getGenericReturnType());
if (v == null &&
method.getReturnType().isPrimitive())
v =
ClassInfo.of(method.getReturnType()).getPrimitiveDefault();
return v;
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestResponse.java
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestResponse.java
index 871d066..0f418fc 100644
---
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestResponse.java
+++
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestResponse.java
@@ -250,7 +250,7 @@ public class RestResponse implements HttpResponse {
* @throws RestCallException If REST call failed.
*/
public Optional<ContentType> getContentType() throws RestCallException {
- return getResponseHeader("Content-Type").as(ContentType.class);
+ return
getResponseHeader("Content-Type").asType(ContentType.class);
}
/**
@@ -450,10 +450,10 @@ public class RestResponse implements HttpResponse {
String name = pm.getPartName();
ClassMeta<?> type =
rc.getClassMeta(method.getGenericReturnType());
if (pt == RESPONSE_HEADER)
- return
getResponseHeader(name).parser(pp).schema(schema).as(type).orElse(null);
+ return
getResponseHeader(name).parser(pp).schema(schema).asType(type).orElse(null);
if (pt == RESPONSE_STATUS)
return getStatusCode();
- return
getBody().schema(schema).as(type);
+ return
getBody().schema(schema).asType(type);
}
});
}
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/assertion/FluentResponseBodyAssertion.java
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/assertion/FluentResponseBodyAssertion.java
index b8b1937..a5554ff 100644
---
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/assertion/FluentResponseBodyAssertion.java
+++
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/assertion/FluentResponseBodyAssertion.java
@@ -143,7 +143,7 @@ public class FluentResponseBodyAssertion<R> extends
FluentAssertion<R> {
* Provides the ability to perform fluent-style assertions on this
response body.
*
* <p>
- * Converts the body to a type using {@link ResponseBody#as(Class)} and
then returns the value as an object assertion.
+ * Converts the body to a type using {@link ResponseBody#asType(Class)}
and then returns the value as an object assertion.
*
* <h5 class='section'>Examples:</h5>
* <p class='bcode w800'>
@@ -266,7 +266,7 @@ public class FluentResponseBodyAssertion<R> extends
FluentAssertion<R> {
private <T> T valueAsType(Class<T> c) throws AssertionError {
try {
- return value.cache().as(c);
+ return value.cache().asType(c);
} catch (RestCallException e) {
throw error(e, "Exception occurred during call.");
}
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/assertion/FluentResponseHeaderAssertion.java
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/assertion/FluentResponseHeaderAssertion.java
index a5bb230..5963f41 100644
---
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/assertion/FluentResponseHeaderAssertion.java
+++
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/assertion/FluentResponseHeaderAssertion.java
@@ -89,6 +89,38 @@ public class FluentResponseHeaderAssertion<R> extends
FluentBaseAssertion<String
return new FluentZonedDateTimeAssertion<>(this,
value.asDateHeader().asZonedDateTime().orElse(null), returns());
}
+ /**
+ * Provides the ability to perform fluent-style assertions on this
response body.
+ *
+ * <p>
+ * Converts the body to a type using {@link ResponseBody#asType(Class)}
and then returns the value as an object assertion.
+ *
+ * <h5 class='section'>Examples:</h5>
+ * <p class='bcode w800'>
+ * <jc>// Validates the response body bean is the expected
value.</jc>
+ * <jv>client</jv>
+ * .get(<js>"/myBean"</js>)
+ * .run()
+ *
.assertBody().asType(MyBean.<jk>class</jk>).json().is(<js>"{foo:'bar'}"</js>);
+ * </p>
+ *
+ * <ul class='notes'>
+ * <li>
+ * If no charset was found on the
<code>Content-Type</code> response header, <js>"UTF-8"</js> is assumed.
+ * <li>
+ * When using this method, the body is automatically
cached by calling the {@link ResponseBody#cache()}.
+ * <li>
+ * The input stream is automatically closed after this
call.
+ * </ul>
+ *
+ * @param type The object type to create.
+ * @return A new fluent assertion object.
+ * @throws RestCallException If REST call failed.
+ */
+ public <V> FluentObjectAssertion<V,R> asType(Class<V> type) throws
RestCallException {
+ return new
FluentObjectAssertion<>(value.asType(type).orElse(null), returns());
+ }
+
// <FluentSetters>
@Override /* GENERATED - Assertion */
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestBody.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestBody.java
index accb37b..5927855 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestBody.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestBody.java
@@ -245,12 +245,27 @@ public class RequestBody {
* @throws IOException If a problem occurred trying to read from the
reader.
*/
public String asString() throws IOException {
- if (body == null)
- body = readBytes(getInputStream(), 1024);
+ cache();
return new String(body, UTF8);
}
/**
+ * Returns the HTTP body content as a plain string.
+ *
+ * <ul class='notes'>
+ * <li>
+ * If {@code allowHeaderParams} init parameter is true,
then first looks for {@code &body=xxx} in the URL query string.
+ * </ul>
+ *
+ * @return The incoming input from the connection as a plain string.
+ * @throws IOException If a problem occurred trying to read from the
reader.
+ */
+ public byte[] asBytes() throws IOException {
+ cache();
+ return body;
+ }
+
+ /**
* Returns the HTTP body content as a simple hexadecimal character
string.
*
* <h5 class='section'>Example:</h5>
@@ -262,8 +277,7 @@ public class RequestBody {
* @throws IOException If a problem occurred trying to read from the
reader.
*/
public String asHex() throws IOException {
- if (body == null)
- body = readBytes(getInputStream(), 1024);
+ cache();
return toHex(body);
}
@@ -279,8 +293,7 @@ public class RequestBody {
* @throws IOException If a problem occurred trying to read from the
reader.
*/
public String asSpacedHex() throws IOException {
- if (body == null)
- body = readBytes(getInputStream(), 1024);
+ cache();
return toSpacedHex(body);
}
@@ -508,6 +521,17 @@ public class RequestBody {
return contentLength == 0 ?
req.getHttpServletRequest().getContentLength() : contentLength;
}
+ /**
+ * Caches the body in memory for reuse.
+ *
+ * @return This object (for method chaining).
+ * @throws IOException If error occurs while reading stream.
+ */
+ public RequestBody cache() throws IOException {
+ if (body == null)
+ body = readBytes(getInputStream(), 1024);
+ return this;
+ }
//-----------------------------------------------------------------------------------------------------------------
// Helper methods
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestHeader.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestHeader.java
index 65a1d31..ec1d72b 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestHeader.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestHeader.java
@@ -277,8 +277,8 @@ public class RequestHeader implements Header {
* @return The converted type, or {@link Optional#empty()} if the
header is not present.
* @throws HttpException If value could not be parsed.
*/
- public <T> Optional<T> as(Type type, Type...args) throws HttpException {
- return as(request.getBeanSession().getClassMeta(type, args));
+ public <T> Optional<T> asType(Type type, Type...args) throws
HttpException {
+ return asType(request.getBeanSession().getClassMeta(type,
args));
}
/**
@@ -289,8 +289,8 @@ public class RequestHeader implements Header {
* @return The converted type, or {@link Optional#empty()} if the
header is not present.
* @throws HttpException If value could not be parsed.
*/
- public <T> Optional<T> as(Class<T> type) throws HttpException {
- return as(request.getBeanSession().getClassMeta(type));
+ public <T> Optional<T> asType(Class<T> type) throws HttpException {
+ return asType(request.getBeanSession().getClassMeta(type));
}
/**
@@ -301,7 +301,7 @@ public class RequestHeader implements Header {
* @return The converted type, or {@link Optional#empty()} if the
header is not present.
* @throws HttpException If value could not be parsed.
*/
- public <T> Optional<T> as(ClassMeta<T> type) throws HttpException {
+ public <T> Optional<T> asType(ClassMeta<T> type) throws HttpException {
try {
return Optional.ofNullable(parser.parse(HEADER, schema,
asString().orElse(null), type));
} catch (ParseException e) {
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestQueryParam.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestQueryParam.java
index 19fe371..6af47f7 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestQueryParam.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RequestQueryParam.java
@@ -250,8 +250,8 @@ public class RequestQueryParam implements NameValuePair {
* @return The converted type, or {@link Optional#empty()} if the
parameter is not present.
* @throws HttpException If value could not be parsed.
*/
- public <T> Optional<T> as(Type type, Type...args) throws HttpException {
- return as(request.getBeanSession().getClassMeta(type, args));
+ public <T> Optional<T> asType(Type type, Type...args) throws
HttpException {
+ return asType(request.getBeanSession().getClassMeta(type,
args));
}
/**
@@ -262,8 +262,8 @@ public class RequestQueryParam implements NameValuePair {
* @return The converted type, or {@link Optional#empty()} if the
parameter is not present.
* @throws HttpException If value could not be parsed.
*/
- public <T> Optional<T> as(Class<T> type) throws HttpException {
- return as(request.getBeanSession().getClassMeta(type));
+ public <T> Optional<T> asType(Class<T> type) throws HttpException {
+ return asType(request.getBeanSession().getClassMeta(type));
}
/**
@@ -274,7 +274,7 @@ public class RequestQueryParam implements NameValuePair {
* @return The converted type, or {@link Optional#empty()} if the
parameter is not present.
* @throws HttpException If value could not be parsed.
*/
- public <T> Optional<T> as(ClassMeta<T> type) throws HttpException {
+ public <T> Optional<T> asType(ClassMeta<T> type) throws HttpException {
try {
return Optional.ofNullable(parser.parse(HEADER, schema,
asString().orElse(null), type));
} catch (ParseException e) {
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java
index c2114b1..45eb25c 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java
@@ -226,6 +226,22 @@ public final class RestRequest extends
HttpServletRequestWrapper {
//-----------------------------------------------------------------------------------------------------------------
/**
+ * Returns a fluent assertion for the request body.
+ *
+ * <h5 class='section'>Example:</h5>
+ * <p class='bcode w800'>
+ * <jc>// Validates the request body contains "foo".</jc>
+ * <jv>request</jv>
+ * .assertBody().is(<js>"foo"</js>);
+ * </p>
+ *
+ * @return A new fluent assertion on the body, never <jk>null</jk>.
+ */
+ public FluentRequestBodyAssertion<RestRequest> assertBody() {
+ return new FluentRequestBodyAssertion<RestRequest>(getBody(),
this);
+ }
+
+ /**
* Returns a fluent assertion for the specified header.
*
* <h5 class='section'>Example:</h5>
@@ -1303,11 +1319,11 @@ public final class RestRequest extends
HttpServletRequestWrapper {
if (pt ==
HttpPartType.BODY)
return
getBody().schema(schema).asType(type);
if (pt == QUERY)
- return
getRequestQuery().getLast(name).parser(pp).schema(schema).as(type);
+ return
getRequestQuery().getLast(name).parser(pp).schema(schema).asType(type);
if (pt == FORMDATA)
return
getFormData().get(pp, schema, name, type);
if (pt == HEADER)
- return
getRequestHeaders().getLast(name).parser(pp).schema(schema).as(type);
+ return
getRequestHeaders().getLast(name).parser(pp).schema(schema).asType(type);
if (pt == PATH)
return
getPathMatch().get(pp, schema, name, type);
}
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/HeaderArg.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/HeaderArg.java
index ea14493..d48188a 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/HeaderArg.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/HeaderArg.java
@@ -105,17 +105,17 @@ public class HeaderArg implements RestOperationArg {
if (multi) {
Collection c = cm.isArray() ? new ArrayList<>() :
(Collection)(cm.canCreateNewInstance() ? cm.newInstance() : new OList());
- rh.getAll(name).stream().map(x ->
x.parser(ps).schema(schema).as(cm.getElementType()).orElse(null)).forEach(x ->
c.add(x));
+ rh.getAll(name).stream().map(x ->
x.parser(ps).schema(schema).asType(cm.getElementType()).orElse(null)).forEach(x
-> c.add(x));
return cm.isArray() ? ArrayUtils.toArray(c,
cm.getElementType().getInnerClass()) : c;
}
if (cm.isMapOrBean() && isOneOf(name, "*", "")) {
OMap m = new OMap();
for (RequestHeader e : rh.getAll())
- m.put(e.getName(), e.parser(ps).schema(schema
== null ? null :
schema.getProperty(e.getName())).as(cm.getValueType()).orElse(null));
+ m.put(e.getName(), e.parser(ps).schema(schema
== null ? null :
schema.getProperty(e.getName())).asType(cm.getValueType()).orElse(null));
return req.getBeanSession().convertToType(m, cm);
}
- return
rh.getLast(name).parser(ps).schema(schema).as(type.innerType()).orElse(null);
+ return
rh.getLast(name).parser(ps).schema(schema).asType(type.innerType()).orElse(null);
}
}
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/QueryArg.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/QueryArg.java
index ecf142e..f876698 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/QueryArg.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/args/QueryArg.java
@@ -30,7 +30,7 @@ import org.apache.juneau.rest.annotation.*;
* Resolves method parameters and parameter types annotated with {@link Query}
on {@link RestOp}-annotated Java methods.
*
* <p>
- * The parameter value is resolved using <c><jv>call</jv>.{@link
RestCall#getRestRequest() getRestRequest}().{@link
RestRequest#getRequestQuery() getQuery}().{@link RequestQueryParams#get(String)
get}(<jv>name</jv>).{@link RequestQueryParam#as(Class) as}(<jv>type</jv>)</c>
+ * The parameter value is resolved using <c><jv>call</jv>.{@link
RestCall#getRestRequest() getRestRequest}().{@link
RestRequest#getRequestQuery() getQuery}().{@link RequestQueryParams#get(String)
get}(<jv>name</jv>).{@link RequestQueryParam#asType(Class)
asType}(<jv>type</jv>)</c>
* with a {@link HttpPartSchema schema} derived from the {@link Query}
annotation.
*/
public class QueryArg implements RestOperationArg {
@@ -102,17 +102,17 @@ public class QueryArg implements RestOperationArg {
if (multi) {
Collection c = cm.isArray() ? new ArrayList<>() :
(Collection)(cm.canCreateNewInstance() ? cm.newInstance() : new OList());
- rh.getAll(name).stream().map(x ->
x.parser(ps).schema(schema).as(cm.getElementType()).orElse(null)).forEach(x ->
c.add(x));
+ rh.getAll(name).stream().map(x ->
x.parser(ps).schema(schema).asType(cm.getElementType()).orElse(null)).forEach(x
-> c.add(x));
return cm.isArray() ? ArrayUtils.toArray(c,
cm.getElementType().getInnerClass()) : c;
}
if (cm.isMapOrBean() && isOneOf(name, "*", "")) {
OMap m = new OMap();
for (RequestQueryParam e : rh.getAll())
- m.put(e.getName(), e.parser(ps).schema(schema
== null ? null :
schema.getProperty(e.getName())).as(cm.getValueType()).orElse(null));
+ m.put(e.getName(), e.parser(ps).schema(schema
== null ? null :
schema.getProperty(e.getName())).asType(cm.getValueType()).orElse(null));
return req.getBeanSession().convertToType(m, cm);
}
- return
rh.getLast(name).parser(ps).schema(schema).as(type.innerType()).orElse(null);
+ return
rh.getLast(name).parser(ps).schema(schema).asType(type.innerType()).orElse(null);
}
}
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/assertion/FluentResponseBodyAssertion.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/assertions/FluentRequestBodyAssertion.java
similarity index 62%
copy from
juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/assertion/FluentResponseBodyAssertion.java
copy to
juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/assertions/FluentRequestBodyAssertion.java
index b8b1937..29d6a0a 100644
---
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/assertion/FluentResponseBodyAssertion.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/assertions/FluentRequestBodyAssertion.java
@@ -10,24 +10,25 @@
// * "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.client.assertion;
+package org.apache.juneau.rest.assertions;
+import java.io.*;
import java.util.function.*;
import org.apache.juneau.assertions.*;
import org.apache.juneau.http.exception.*;
import org.apache.juneau.internal.*;
-import org.apache.juneau.rest.client.*;
+import org.apache.juneau.rest.*;
/**
- * Used for fluent assertion calls against {@link ResponseBody} objects.
+ * Used for fluent assertion calls against {@link RequestBody} objects.
*
* @param <R> The return type.
*/
-@FluentSetters(returns="FluentResponseBodyAssertion<R>")
-public class FluentResponseBodyAssertion<R> extends FluentAssertion<R> {
+@FluentSetters(returns="FluentRequestBodyAssertion<R>")
+public class FluentRequestBodyAssertion<R> extends FluentAssertion<R> {
- private final ResponseBody value;
+ private final RequestBody value;
/**
* Constructor.
@@ -35,72 +36,37 @@ public class FluentResponseBodyAssertion<R> extends
FluentAssertion<R> {
* @param value The object being tested.
* @param returns The object to return after the test.
*/
- public FluentResponseBodyAssertion(ResponseBody value, R returns) {
+ public FluentRequestBodyAssertion(RequestBody value, R returns) {
super(null, returns);
this.value = value;
throwable(BadRequest.class);
}
/**
- * Provides the ability to perform fluent-style assertions on this
response body.
+ * Provides the ability to perform fluent-style assertions on this
request body.
*
* <h5 class='section'>Examples:</h5>
* <p class='bcode w800'>
- * <jc>// Validates the response body equals the text "OK".</jc>
- * <jv>client</jv>
- * .get(<jsf>URI</jsf>)
- * .run()
+ * <jc>// Validates the request body equals the text "OK".</jc>
+ * <jv>request</jv>
* .assertBody().is(<js>"OK"</js>);
- *
- * <jc>// Validates the response body contains the text "OK".</jc>
- * <jv>client</jv>
- * .get(<jsf>URI</jsf>)
- * .run()
- * .assertBody().contains(<js>"OK"</js>);
- *
- * <jc>// Validates the response body passes a predicate test.</jc>
- * <jv>client</jv>
- * .get(<jsf>URI</jsf>)
- * .run()
- * .assertBody().passes(<jv>x</jv> ->
<jv>x</jv>.contains(<js>"OK"</js>));
- *
- * <jc>// Validates the response body matches a regular
expression.</jc>
- * <jv>client</jv>
- * .get(<jsf>URI</jsf>)
- * .run()
- * .assertBody().matches(<js>".*OK.*"</js>);
- *
- * <jc>// Validates the response body matches a regular expression
using regex flags.</jc>
- * <jv>client</jv>
- * .get(<jsf>URI</jsf>)
- * .run()
- * .assertBody().matches(<js>".*OK.*"</js>,
<jsf>MULTILINE</jsf> & <jsf>CASE_INSENSITIVE</jsf>);
- *
- * <jc>// Validates the response body matches a regular expression
in the form of an existing Pattern.</jc>
- * Pattern <jv>p</jv> =
Pattern.<jsm>compile</jsm>(<js>".*OK.*"</js>);
- * <jv>client</jv>
- * .get(<jsf>URI</jsf>)
- * .run()
- * .assertBody().matches(<jv>p</jv>);
* </p>
*
* <p>
- * The assertion test returns the original response object allowing you
to chain multiple requests like so:
+ * The assertion test returns the original request object allowing you
to chain multiple requests like so:
* <p class='bcode w800'>
- * <jc>// Validates the response body matches a regular
expression.</jc>
- * MyBean <jv>bean</jv> = <jv>client</jv>
- * .get(<jsf>URI</jsf>)
- * .run()
- * .assertBody().matches(<js>".*OK.*"</js>);
- * .assertBody().doesNotMatch(<js>".*ERROR.*"</js>)
- * .getBody().as(MyBean.<jk>class</jk>);
+ * <jc>// Validates the request body matches a regular
expression.</jc>
+ * MyBean <jv>bean</jv> = <jv>request</jv>
+ * .assertBody().asString().matches(<js>".*OK.*"</js>);
+ *
.assertBody().asString().doesNotMatch(<js>".*ERROR.*"</js>)
+ * .getBody().asType(MyBean.<jk>class</jk>);
* </p>
*
* <ul class='notes'>
* <li>
- * If no charset was found on the
<code>Content-Type</code> response header, <js>"UTF-8"</js> is assumed.
+ * If no charset was found on the
<code>Content-Type</code> request header, <js>"UTF-8"</js> is assumed.
* <li>
- * When using this method, the body is automatically
cached by calling the {@link ResponseBody#cache()}.
+ * When using this method, the body is automatically
cached by calling the {@link RequestBody#cache()}.
* <li>
* The input stream is automatically closed after this
call.
* </ul>
@@ -112,62 +78,56 @@ public class FluentResponseBodyAssertion<R> extends
FluentAssertion<R> {
}
/**
- * Provides the ability to perform fluent-style assertions on the bytes
of the response body.
+ * Provides the ability to perform fluent-style assertions on the bytes
of the request body.
*
* <h5 class='section'>Examples:</h5>
* <p class='bcode w800'>
- * <jc>// Validates the response body equals the text "foo".</jc>
- * <jv>client</jv>
- * .get(<jsf>URI</jsf>)
- * .run()
- * .assertBodyBytes().hex().is(<js>"666F6F"</js>);
+ * <jc>// Validates the request body equals the text "foo".</jc>
+ * <jv>request</jv>
+ * .assertBody().asBytes().hex().is(<js>"666F6F"</js>);
* </p>
*
* <ul class='notes'>
* <li>
- * If no charset was found on the
<code>Content-Type</code> response header, <js>"UTF-8"</js> is assumed.
+ * If no charset was found on the
<code>Content-Type</code> request header, <js>"UTF-8"</js> is assumed.
* <li>
- * When using this method, the body is automatically
cached by calling the {@link ResponseBody#cache()}.
+ * When using this method, the body is automatically
cached by calling the {@link RequestBody#cache()}.
* <li>
* The input stream is automatically closed after this
call.
* </ul>
*
* @return A new fluent assertion object.
- * @throws RestCallException If REST call failed.
*/
- public FluentByteArrayAssertion<R> asBytes() throws RestCallException {
+ public FluentByteArrayAssertion<R> asBytes() {
return new FluentByteArrayAssertion<>(valueAsBytes(),
returns());
}
/**
- * Provides the ability to perform fluent-style assertions on this
response body.
+ * Provides the ability to perform fluent-style assertions on this
request body.
*
* <p>
- * Converts the body to a type using {@link ResponseBody#as(Class)} and
then returns the value as an object assertion.
+ * Converts the body to a type using {@link RequestBody#asType(Class)}
and then returns the value as an object assertion.
*
* <h5 class='section'>Examples:</h5>
* <p class='bcode w800'>
- * <jc>// Validates the response body bean is the expected
value.</jc>
- * <jv>client</jv>
- * .get(<js>"/myBean"</js>)
- * .run()
+ * <jc>// Validates the request body bean is the expected
value.</jc>
+ * <jv>request</jv>
*
.assertBody().asType(MyBean.<jk>class</jk>).json().is(<js>"{foo:'bar'}"</js>);
* </p>
*
* <ul class='notes'>
* <li>
- * If no charset was found on the
<code>Content-Type</code> response header, <js>"UTF-8"</js> is assumed.
+ * If no charset was found on the
<code>Content-Type</code> request header, <js>"UTF-8"</js> is assumed.
* <li>
- * When using this method, the body is automatically
cached by calling the {@link ResponseBody#cache()}.
+ * When using this method, the body is automatically
cached by calling the {@link RequestBody#cache()}.
* <li>
* The input stream is automatically closed after this
call.
* </ul>
*
* @param type The object type to create.
* @return A new fluent assertion object.
- * @throws RestCallException If REST call failed.
*/
- public <V> FluentObjectAssertion<V,R> asType(Class<V> type) throws
RestCallException {
+ public <V> FluentObjectAssertion<V,R> asType(Class<V> type) {
return new FluentObjectAssertion<>(valueAsType(type),
returns());
}
@@ -175,7 +135,7 @@ public class FluentResponseBodyAssertion<R> extends
FluentAssertion<R> {
* Asserts that the value equals the specified value.
*
* @param value The value to check against.
- * @return The response object (for method chaining).
+ * @return The request object (for method chaining).
* @throws AssertionError If assertion failed.
*/
public R isEqual(String value) throws AssertionError {
@@ -186,7 +146,7 @@ public class FluentResponseBodyAssertion<R> extends
FluentAssertion<R> {
* Asserts that the body contains the specified value.
*
* @param values The value to check against.
- * @return The response object (for method chaining).
+ * @return The request object (for method chaining).
* @throws AssertionError If assertion failed.
*/
public R is(String values) throws AssertionError {
@@ -197,7 +157,7 @@ public class FluentResponseBodyAssertion<R> extends
FluentAssertion<R> {
* Asserts that the text contains all of the specified substrings.
*
* @param values The values to check against.
- * @return The response object (for method chaining).
+ * @return The request object (for method chaining).
* @throws AssertionError If assertion failed.
*/
public R contains(String...values) throws AssertionError {
@@ -208,7 +168,7 @@ public class FluentResponseBodyAssertion<R> extends
FluentAssertion<R> {
* Asserts that the body doesn't contain any of the specified
substrings.
*
* @param values The values to check against.
- * @return The response object (for method chaining).
+ * @return The request object (for method chaining).
* @throws AssertionError If assertion failed.
*/
public R doesNotContain(String...values) throws AssertionError {
@@ -218,7 +178,7 @@ public class FluentResponseBodyAssertion<R> extends
FluentAssertion<R> {
/**
* Asserts that the body is empty.
*
- * @return The response object (for method chaining).
+ * @return The request object (for method chaining).
* @throws AssertionError If assertion failed.
*/
public R isEmpty() {
@@ -228,7 +188,7 @@ public class FluentResponseBodyAssertion<R> extends
FluentAssertion<R> {
/**
* Asserts that the body is not empty.
*
- * @return The response object (for method chaining).
+ * @return The request object (for method chaining).
* @throws AssertionError If assertion failed.
*/
public R isNotEmpty() {
@@ -239,7 +199,7 @@ public class FluentResponseBodyAssertion<R> extends
FluentAssertion<R> {
* Asserts that the value passes the specified predicate test.
*
* @param test The predicate to use to test the value.
- * @return The response object (for method chaining).
+ * @return The request object (for method chaining).
* @throws AssertionError If assertion failed.
*/
public R passes(Predicate<String> test) throws AssertionError {
@@ -251,7 +211,7 @@ public class FluentResponseBodyAssertion<R> extends
FluentAssertion<R> {
private String valueAsString() throws AssertionError {
try {
return value.cache().asString();
- } catch (RestCallException e) {
+ } catch (IOException e) {
throw error(e, "Exception occurred during call.");
}
}
@@ -259,15 +219,15 @@ public class FluentResponseBodyAssertion<R> extends
FluentAssertion<R> {
private byte[] valueAsBytes() throws AssertionError {
try {
return value.cache().asBytes();
- } catch (RestCallException e) {
+ } catch (IOException e) {
throw error(e, "Exception occurred during call.");
}
}
private <T> T valueAsType(Class<T> c) throws AssertionError {
try {
- return value.cache().as(c);
- } catch (RestCallException e) {
+ return value.cache().asType(c);
+ } catch (IOException e) {
throw error(e, "Exception occurred during call.");
}
}
@@ -275,19 +235,19 @@ public class FluentResponseBodyAssertion<R> extends
FluentAssertion<R> {
// <FluentSetters>
@Override /* GENERATED - Assertion */
- public FluentResponseBodyAssertion<R> msg(String msg, Object...args) {
+ public FluentRequestBodyAssertion<R> msg(String msg, Object...args) {
super.msg(msg, args);
return this;
}
@Override /* GENERATED - Assertion */
- public FluentResponseBodyAssertion<R> stderr() {
+ public FluentRequestBodyAssertion<R> stderr() {
super.stderr();
return this;
}
@Override /* GENERATED - Assertion */
- public FluentResponseBodyAssertion<R> stdout() {
+ public FluentRequestBodyAssertion<R> stdout() {
super.stdout();
return this;
}
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestCallException_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestCallException_Test.java
index 983fd3a..339f40e 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestCallException_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestCallException_Test.java
@@ -61,7 +61,7 @@ public class RestCallException_Test {
}
try {
- client().build().post("/echo",new
StringEntity("{f:")).run().getBody().as(ABean.class);
+ client().build().post("/echo",new
StringEntity("{f:")).run().getBody().asType(ABean.class);
fail();
} catch (RestCallException e) {
assertThrowable(e.getCause(ParseException.class)).contains("Could not find
'}'");
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Config_BeanContext_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Config_BeanContext_Test.java
index 023670d..8ba94d1 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Config_BeanContext_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Config_BeanContext_Test.java
@@ -106,8 +106,8 @@ public class RestClient_Config_BeanContext_Test {
.cacheBody()
.assertBody().is("1")
.assertHeader("X").is("1");
- assertEquals(1,x.getBody().as(A2a.class).f);
- assertEquals(1,x.getResponseHeader("X").as(A2a.class).get().f);
+ assertEquals(1,x.getBody().asType(A2a.class).f);
+
assertEquals(1,x.getResponseHeader("X").asType(A2a.class).get().f);
}
public static class A3 {
@@ -136,8 +136,8 @@ public class RestClient_Config_BeanContext_Test {
.cacheBody()
.assertBody().is("{f1:1,f2:2}")
.assertHeader("X").is("f1=1,f2=2");
- assertEquals(2,x.getBody().as(A3.class).f2);
- assertEquals(2,x.getResponseHeader("X").as(A3.class).get().f2);
+ assertEquals(2,x.getBody().asType(A3.class).f2);
+
assertEquals(2,x.getResponseHeader("X").asType(A3.class).get().f2);
}
public static interface A4a {
@@ -181,8 +181,8 @@ public class RestClient_Config_BeanContext_Test {
.assertBody()
.is("{f1:1}")
.assertHeader("X").is("f1=1");
- assertEquals(0,x.getBody().as(A4b.class).f2);
- assertEquals(0,x.getResponseHeader("X").as(A4b.class).get().f2);
+ assertEquals(0,x.getBody().asType(A4b.class).f2);
+
assertEquals(0,x.getResponseHeader("X").asType(A4b.class).get().f2);
x = client(A2b.class)
.beanProperties(A4b.class,"f1")
@@ -193,8 +193,8 @@ public class RestClient_Config_BeanContext_Test {
.cacheBody()
.assertBody().is("{f1:1}")
.assertHeader("X").is("f1=1");
- assertEquals(0,x.getBody().as(A4b.class).f2);
- assertEquals(0,x.getResponseHeader("X").as(A4b.class).get().f2);
+ assertEquals(0,x.getBody().asType(A4b.class).f2);
+
assertEquals(0,x.getResponseHeader("X").asType(A4b.class).get().f2);
x = client(A2b.class)
.beanProperties(A4b.class,"f1")
@@ -205,8 +205,8 @@ public class RestClient_Config_BeanContext_Test {
.cacheBody()
.assertBody().is("{f1:1}")
.assertHeader("X").is("f1=1");
- assertEquals(0,x.getBody().as(A4b.class).f2);
- assertEquals(0,x.getResponseHeader("X").as(A4b.class).get().f2);
+ assertEquals(0,x.getBody().asType(A4b.class).f2);
+
assertEquals(0,x.getResponseHeader("X").asType(A4b.class).get().f2);
x = client(A2b.class)
.beanProperties(A4b.class,"f1")
@@ -217,8 +217,8 @@ public class RestClient_Config_BeanContext_Test {
.cacheBody()
.assertBody().is("{f1:1}")
.assertHeader("X").is("f1=1");
- assertEquals(0,x.getBody().as(A4b.class).f2);
- assertEquals(0,x.getResponseHeader("X").as(A4b.class).get().f2);
+ assertEquals(0,x.getBody().asType(A4b.class).f2);
+
assertEquals(0,x.getResponseHeader("X").asType(A4b.class).get().f2);
x = client(A2b.class)
.interfaces(A4a.class)
@@ -229,8 +229,8 @@ public class RestClient_Config_BeanContext_Test {
.cacheBody()
.assertBody().is("{f3:3}")
.assertHeader("X").is("f3=3");
- assertEquals(3,x.getBody().as(A4b.class).f3);
- assertEquals(3,x.getResponseHeader("X").as(A4b.class).get().f3);
+ assertEquals(3,x.getBody().asType(A4b.class).f3);
+
assertEquals(3,x.getResponseHeader("X").asType(A4b.class).get().f3);
}
public static class A5 {
@@ -270,8 +270,8 @@ public class RestClient_Config_BeanContext_Test {
.cacheBody()
.assertBody().is("{f1:1,f2:2}")
.assertHeader("X").is("f1=1,f2=2");
- assertEquals(2,x.getBody().as(A5.class).f2);
- assertEquals(2,x.getResponseHeader("X").as(A5.class).get().f2);
+ assertEquals(2,x.getBody().asType(A5.class).f2);
+
assertEquals(2,x.getResponseHeader("X").asType(A5.class).get().f2);
}
public static class A6 {}
@@ -421,8 +421,8 @@ public class RestClient_Config_BeanContext_Test {
.cacheBody()
.assertBody().is("{f1:1,f2:2}")
.assertHeader("X").is("f1=1,f2=2");
- assertEquals("1/0",x.getBody().as(A9.class).toString());
-
assertEquals("1/0",x.getResponseHeader("X").as(A9.class).get().toString());
+ assertEquals("1/0",x.getBody().asType(A9.class).toString());
+
assertEquals("1/0",x.getResponseHeader("X").asType(A9.class).get().toString());
x = client(A2b.class)
.beanPropertiesReadOnly(A9.class,"f2")
@@ -433,8 +433,8 @@ public class RestClient_Config_BeanContext_Test {
.cacheBody()
.assertBody().is("{f1:1,f2:2}")
.assertHeader("X").is("f1=1,f2=2");
- assertEquals("1/0",x.getBody().as(A9.class).toString());
-
assertEquals("1/0",x.getResponseHeader("X").as(A9.class).get().toString());
+ assertEquals("1/0",x.getBody().asType(A9.class).toString());
+
assertEquals("1/0",x.getResponseHeader("X").asType(A9.class).get().toString());
x = client(A2b.class)
.beanPropertiesReadOnly("O9","f2")
@@ -445,8 +445,8 @@ public class RestClient_Config_BeanContext_Test {
.cacheBody()
.assertBody().is("{f1:1,f2:2}")
.assertHeader("X").is("f1=1,f2=2");
- assertEquals("1/0",x.getBody().as(A9.class).toString());
-
assertEquals("1/0",x.getResponseHeader("X").as(A9.class).get().toString());
+ assertEquals("1/0",x.getBody().asType(A9.class).toString());
+
assertEquals("1/0",x.getResponseHeader("X").asType(A9.class).get().toString());
}
@Test
@@ -462,8 +462,8 @@ public class RestClient_Config_BeanContext_Test {
.cacheBody()
.assertBody().is("{f1:1}")
.assertHeader("X").is("f1=1");
- assertEquals("1/0",x.getBody().as(A9.class).toString());
-
assertEquals("1/0",x.getResponseHeader("X").as(A9.class).get().toString());
+ assertEquals("1/0",x.getBody().asType(A9.class).toString());
+
assertEquals("1/0",x.getResponseHeader("X").asType(A9.class).get().toString());
x = client(A2b.class)
.beanPropertiesWriteOnly(A9.class,"f2")
@@ -474,8 +474,8 @@ public class RestClient_Config_BeanContext_Test {
.cacheBody()
.assertBody().is("{f1:1}")
.assertHeader("X").is("f1=1");
- assertEquals("1/0",x.getBody().as(A9.class).toString());
-
assertEquals("1/0",x.getResponseHeader("X").as(A9.class).get().toString());
+ assertEquals("1/0",x.getBody().asType(A9.class).toString());
+
assertEquals("1/0",x.getResponseHeader("X").asType(A9.class).get().toString());
x = client(A2b.class)
.beanPropertiesWriteOnly("A9","f2")
@@ -486,8 +486,8 @@ public class RestClient_Config_BeanContext_Test {
.cacheBody()
.assertBody().is("{f1:1}")
.assertHeader("X").is("f1=1");
- assertEquals("1/0",x.getBody().as(A9.class).toString());
-
assertEquals("1/0",x.getResponseHeader("X").as(A9.class).get().toString());
+ assertEquals("1/0",x.getBody().asType(A9.class).toString());
+
assertEquals("1/0",x.getResponseHeader("X").asType(A9.class).get().toString());
}
@Test
@@ -568,15 +568,15 @@ public class RestClient_Config_BeanContext_Test {
@Test
public void a15_dictionary() throws Exception {
- Object o =
client().dictionary(A15a.class,A15b.class).addRootType().addBeanTypes().build().post("/echoBody",A15a.get()).run().cacheBody().assertBody().contains("{_type:'foo',foo:'1'}").getBody().as(Object.class);;
+ Object o =
client().dictionary(A15a.class,A15b.class).addRootType().addBeanTypes().build().post("/echoBody",A15a.get()).run().cacheBody().assertBody().contains("{_type:'foo',foo:'1'}").getBody().asType(Object.class);;
assertTrue(o instanceof A15a);
OMap m = OMap.of("x",A15a.get(),"y",A15b.get());
- m =
client().dictionary(A15a.class,A15b.class).addRootType().addBeanTypes().build().post("/echoBody",m).run().cacheBody().assertBody().is("{x:{_type:'foo',foo:'1'},y:{_type:'bar',foo:'2'}}").getBody().as(OMap.class);;
+ m =
client().dictionary(A15a.class,A15b.class).addRootType().addBeanTypes().build().post("/echoBody",m).run().cacheBody().assertBody().is("{x:{_type:'foo',foo:'1'},y:{_type:'bar',foo:'2'}}").getBody().asType(OMap.class);;
assertTrue(m.get("x") instanceof A15a);
assertTrue(m.get("y") instanceof A15b);
- A15c x =
client().dictionaryOn(A15c.class,A15a.class,A15b.class).addRootType().addBeanTypes().build().post("/echoBody",A15c.get()).run().cacheBody().assertBody().is("{foo:{_type:'foo',foo:'1'}}").getBody().as(A15c.class);;
+ A15c x =
client().dictionaryOn(A15c.class,A15a.class,A15b.class).addRootType().addBeanTypes().build().post("/echoBody",A15c.get()).run().cacheBody().assertBody().is("{foo:{_type:'foo',foo:'1'}}").getBody().asType(A15c.class);;
assertTrue(x.foo instanceof A15a);
}
@@ -594,9 +594,9 @@ public class RestClient_Config_BeanContext_Test {
@Test
public void a16_disableIgnorePropertiesWithoutSetters() throws
Exception {
- A16 x =
client().build().post("/echoBody",A16.get()).run().cacheBody().assertBody().contains("{foo:'foo'}").getBody().as(A16.class);
+ A16 x =
client().build().post("/echoBody",A16.get()).run().cacheBody().assertBody().contains("{foo:'foo'}").getBody().asType(A16.class);
assertNull(x.foo);
-
assertThrown(()->client().disableIgnoreMissingSetters().build().post("/echoBody",A16.get()).run().cacheBody().assertBody().contains("{foo:'foo'}").getBody().as(A16.class)).contains("Setter
or public field not defined");
+
assertThrown(()->client().disableIgnoreMissingSetters().build().post("/echoBody",A16.get()).run().cacheBody().assertBody().contains("{foo:'foo'}").getBody().asType(A16.class)).contains("Setter
or public field not defined");
}
public static class A17 {
@@ -612,9 +612,9 @@ public class RestClient_Config_BeanContext_Test {
@Test
public void a17_disableIgnoreTransientFields() throws Exception {
- A17 x =
client().build().post("/echoBody",A17.get()).run().cacheBody().assertBody().contains("{foo:'1'}").getBody().as(A17.class);;
+ A17 x =
client().build().post("/echoBody",A17.get()).run().cacheBody().assertBody().contains("{foo:'1'}").getBody().asType(A17.class);;
assertNull(x.bar);
- x =
client().disableIgnoreTransientFields().build().post("/echoBody",A17.get()).run().cacheBody().assertBody().contains("{bar:'2',foo:'1'}").getBody().as(A17.class);
+ x =
client().disableIgnoreTransientFields().build().post("/echoBody",A17.get()).run().cacheBody().assertBody().contains("{bar:'2',foo:'1'}").getBody().asType(A17.class);
assertEquals("2",x.bar);
}
@@ -624,8 +624,8 @@ public class RestClient_Config_BeanContext_Test {
@Test
public void a18_disableIgnoreUnknownNullBeanProperties() throws
Exception {
- client().build().post("/echoBody",new
StringReader("{foo:'1',bar:null}")).run().cacheBody().assertBody().contains("{foo:'1',bar:null}").getBody().as(A18.class);;
-
assertThrown(()->client().disableIgnoreUnknownNullBeanProperties().build().post("/echoBody",new
StringReader("{foo:'1',bar:null}")).run().cacheBody().assertBody().contains("{foo:'1',bar:null}").getBody().as(A18.class)).contains("Unknown
property 'bar'");
+ client().build().post("/echoBody",new
StringReader("{foo:'1',bar:null}")).run().cacheBody().assertBody().contains("{foo:'1',bar:null}").getBody().asType(A18.class);;
+
assertThrown(()->client().disableIgnoreUnknownNullBeanProperties().build().post("/echoBody",new
StringReader("{foo:'1',bar:null}")).run().cacheBody().assertBody().contains("{foo:'1',bar:null}").getBody().asType(A18.class)).contains("Unknown
property 'bar'");
}
public static interface A19 {
@@ -635,9 +635,9 @@ public class RestClient_Config_BeanContext_Test {
@Test
public void a19_disableInterfaceProxies() throws Exception {
- A19 x = client().build().post("/echoBody",new
StringReader("{foo:'1'}")).run().cacheBody().assertBody().contains("{foo:'1'}").getBody().as(A19.class);;
+ A19 x = client().build().post("/echoBody",new
StringReader("{foo:'1'}")).run().cacheBody().assertBody().contains("{foo:'1'}").getBody().asType(A19.class);;
assertEquals("1",x.getFoo());
-
assertThrown(()->client().disableInterfaceProxies().build().post("/echoBody",new
StringReader("{foo:'1'}")).run().cacheBody().assertBody().contains("{foo:'1'}").getBody().as(A19.class)).contains("could
not be instantiated");
+
assertThrown(()->client().disableInterfaceProxies().build().post("/echoBody",new
StringReader("{foo:'1'}")).run().cacheBody().assertBody().contains("{foo:'1'}").getBody().asType(A19.class)).contains("could
not be instantiated");
}
public static class A20 {
@@ -653,9 +653,9 @@ public class RestClient_Config_BeanContext_Test {
@Test
public void a20_fluentSetters() throws Exception {
- A20 x =
client().findFluentSetters().build().post("/echoBody",new
StringReader("{foo:'1'}")).run().cacheBody().assertBody().contains("{foo:'1'}").getBody().as(A20.class);;
+ A20 x =
client().findFluentSetters().build().post("/echoBody",new
StringReader("{foo:'1'}")).run().cacheBody().assertBody().contains("{foo:'1'}").getBody().asType(A20.class);;
assertEquals("1",x.getFoo());
- x =
client().findFluentSetters(A20.class).build().post("/echoBody",new
StringReader("{foo:'1'}")).run().cacheBody().assertBody().contains("{foo:'1'}").getBody().as(A20.class);;
+ x =
client().findFluentSetters(A20.class).build().post("/echoBody",new
StringReader("{foo:'1'}")).run().cacheBody().assertBody().contains("{foo:'1'}").getBody().asType(A20.class);;
assertEquals("1",x.getFoo());
}
@@ -682,7 +682,7 @@ public class RestClient_Config_BeanContext_Test {
@Test
public void a21_ignoreInvocationExceptionsOnGetters() throws Exception {
assertThrown(()->client().build().post("/echoBody",A21.get()).run()).contains("Could
not call getValue() on property 'bar'");
- A21 x =
client().ignoreInvocationExceptionsOnGetters().build().post("/echoBody",A21.get()).run().cacheBody().assertBody().contains("{foo:'1'}").getBody().as(A21.class);;
+ A21 x =
client().ignoreInvocationExceptionsOnGetters().build().post("/echoBody",A21.get()).run().cacheBody().assertBody().contains("{foo:'1'}").getBody().asType(A21.class);;
assertEquals("1",x.getFoo());
}
@@ -711,8 +711,8 @@ public class RestClient_Config_BeanContext_Test {
@Test
public void a22_ignoreInvocationExceptionsOnSetters() throws Exception {
-
assertThrown(()->client().build().post("/echoBody",A22.get()).run().getBody().as(A22.class)).contains("Error
occurred trying to set property 'bar'");
- A22 x =
client().ignoreInvocationExceptionsOnSetters().build().post("/echoBody",A22.get()).run().cacheBody().getBody().as(A22.class);;
+
assertThrown(()->client().build().post("/echoBody",A22.get()).run().getBody().asType(A22.class)).contains("Error
occurred trying to set property 'bar'");
+ A22 x =
client().ignoreInvocationExceptionsOnSetters().build().post("/echoBody",A22.get()).run().cacheBody().getBody().asType(A22.class);;
assertEquals("1",x.getFoo());
}
@@ -722,8 +722,8 @@ public class RestClient_Config_BeanContext_Test {
@Test
public void a23_ignoreUnknownBeanProperties() throws Exception {
- assertThrown(()->client().build().post("/echoBody",new
StringReader("{foo:'1',bar:'2'}")).run().getBody().as(A23.class)).contains("Unknown
property 'bar' encountered");
- A23 x =
client().ignoreUnknownBeanProperties().build().post("/echoBody",new
StringReader("{foo:'1',bar:'2'}")).run().cacheBody().getBody().as(A23.class);;
+ assertThrown(()->client().build().post("/echoBody",new
StringReader("{foo:'1',bar:'2'}")).run().getBody().asType(A23.class)).contains("Unknown
property 'bar' encountered");
+ A23 x =
client().ignoreUnknownBeanProperties().build().post("/echoBody",new
StringReader("{foo:'1',bar:'2'}")).run().cacheBody().getBody().asType(A23.class);;
assertEquals("1",x.foo);
}
@@ -746,11 +746,11 @@ public class RestClient_Config_BeanContext_Test {
@Test
public void a24_implClass() throws Exception {
- A24a x =
client().implClass(A24a.class,A24b.class).build().post("/echoBody",new
StringReader("{foo:1}")).run().getBody().as(A24a.class);
+ A24a x =
client().implClass(A24a.class,A24b.class).build().post("/echoBody",new
StringReader("{foo:1}")).run().getBody().asType(A24a.class);
assertEquals(1,x.getFoo());
assertTrue(x instanceof A24b);
- x =
client().implClasses(AMap.of(A24a.class,A24b.class)).build().post("/echoBody",new
StringReader("{foo:1}")).run().getBody().as(A24a.class);
+ x =
client().implClasses(AMap.of(A24a.class,A24b.class)).build().post("/echoBody",new
StringReader("{foo:1}")).run().getBody().asType(A24a.class);
assertEquals(1,x.getFoo());
assertTrue(x instanceof A24b);
}
@@ -779,9 +779,9 @@ public class RestClient_Config_BeanContext_Test {
@Test
public void a25_interfaceClass() throws Exception {
- A25a x =
client().interfaceClass(A25b.class,A25a.class).build().post("/echoBody",A25b.get()).run().cacheBody().assertBody().is("{foo:1}").getBody().as(A25b.class);
+ A25a x =
client().interfaceClass(A25b.class,A25a.class).build().post("/echoBody",A25b.get()).run().cacheBody().assertBody().is("{foo:1}").getBody().asType(A25b.class);
assertEquals(1,x.getFoo());
- x =
client().interfaces(A25a.class).build().post("/echoBody",A25b.get()).run().assertBody().is("{foo:1}").getBody().as(A25b.class);
+ x =
client().interfaces(A25a.class).build().post("/echoBody",A25b.get()).run().assertBody().is("{foo:1}").getBody().asType(A25b.class);
assertEquals(1,x.getFoo());
}
@@ -796,13 +796,13 @@ public class RestClient_Config_BeanContext_Test {
@Test
public void a26_locale() throws Exception {
- A26 x =
client().locale(Locale.UK).build().post("/echoBody",A26.get()).run().cacheBody().assertBody().is("{foo:1}").getBody().as(A26.class);
+ A26 x =
client().locale(Locale.UK).build().post("/echoBody",A26.get()).run().cacheBody().assertBody().is("{foo:1}").getBody().asType(A26.class);
assertEquals(1,x.foo);
}
@Test
public void a27_mediaType() throws Exception {
- A26 x =
client().mediaType(MediaType.JSON).build().post("/echoBody",A26.get()).run().cacheBody().assertBody().is("{foo:1}").getBody().as(A26.class);
+ A26 x =
client().mediaType(MediaType.JSON).build().post("/echoBody",A26.get()).run().cacheBody().assertBody().is("{foo:1}").getBody().asType(A26.class);
assertEquals(1,x.foo);
}
@@ -826,13 +826,13 @@ public class RestClient_Config_BeanContext_Test {
@Test
public void a28_notBeanClasses() throws Exception {
- A28 x =
client().notBeanClasses(A28.class).build().post("/echoBody",A28.get()).run().cacheBody().assertBody().is("'1'").getBody().as(A28.class);
+ A28 x =
client().notBeanClasses(A28.class).build().post("/echoBody",A28.get()).run().cacheBody().assertBody().is("'1'").getBody().asType(A28.class);
assertEquals(1,x.foo);
}
@Test
public void a29_notBeanPackages() throws Exception {
- A28 x =
client().notBeanPackages(A28.class.getPackage()).build().post("/echoBody",A28.get()).run().cacheBody().assertBody().is("'1'").getBody().as(A28.class);
+ A28 x =
client().notBeanPackages(A28.class.getPackage()).build().post("/echoBody",A28.get()).run().cacheBody().assertBody().is("'1'").getBody().asType(A28.class);
assertEquals(1,x.foo);
}
@@ -863,7 +863,7 @@ public class RestClient_Config_BeanContext_Test {
@Test
public void a30_beanInterceptor() throws Exception {
- A30a x =
client().beanInterceptor(A30a.class,A30b.class).build().post("/echoBody",A30a.get()).run().cacheBody().assertBody().is("{foo:'xfoo'}").getBody().as(A30a.class);
+ A30a x =
client().beanInterceptor(A30a.class,A30b.class).build().post("/echoBody",A30a.get()).run().cacheBody().assertBody().is("{foo:'xfoo'}").getBody().asType(A30a.class);
assertEquals("foo",x.foo);
assertTrue(A30b.getterCalled);
assertTrue(A30b.setterCalled);
@@ -882,9 +882,9 @@ public class RestClient_Config_BeanContext_Test {
@Test
public void a31_propertyNamer() throws Exception {
- A31 x =
client().propertyNamer(PropertyNamerDLC.class).build().post("/echoBody",A31.get()).run().cacheBody().assertBody().is("{'foo-bar':'fooBar'}").getBody().as(A31.class);
+ A31 x =
client().propertyNamer(PropertyNamerDLC.class).build().post("/echoBody",A31.get()).run().cacheBody().assertBody().is("{'foo-bar':'fooBar'}").getBody().asType(A31.class);
assertEquals("fooBar",x.fooBar);
- x =
client().propertyNamer(A31.class,PropertyNamerDLC.class).build().post("/echoBody",A31.get()).run().cacheBody().assertBody().is("{'foo-bar':'fooBar'}").getBody().as(A31.class);
+ x =
client().propertyNamer(A31.class,PropertyNamerDLC.class).build().post("/echoBody",A31.get()).run().cacheBody().assertBody().is("{'foo-bar':'fooBar'}").getBody().asType(A31.class);
assertEquals("fooBar",x.fooBar);
}
@@ -901,9 +901,9 @@ public class RestClient_Config_BeanContext_Test {
@Test
public void a32_sortProperties() throws Exception {
- A32 x =
client().sortProperties().build().post("/echoBody",A32.get()).run().cacheBody().assertBody().is("{bar:2,baz:3,foo:1}").getBody().as(A32.class);
+ A32 x =
client().sortProperties().build().post("/echoBody",A32.get()).run().cacheBody().assertBody().is("{bar:2,baz:3,foo:1}").getBody().asType(A32.class);
assertEquals(1,x.foo);
- x =
client().sortProperties(A32.class).build().post("/echoBody",A32.get()).run().cacheBody().assertBody().is("{bar:2,baz:3,foo:1}").getBody().as(A32.class);
+ x =
client().sortProperties(A32.class).build().post("/echoBody",A32.get()).run().cacheBody().assertBody().is("{bar:2,baz:3,foo:1}").getBody().asType(A32.class);
assertEquals(1,x.foo);
}
@@ -923,7 +923,7 @@ public class RestClient_Config_BeanContext_Test {
@Test
public void a33_stopClass() throws Exception {
- A33b x =
client().stopClass(A33b.class,A33a.class).build().post("/echoBody",A33b.get()).run().cacheBody().assertBody().is("{bar:2}").getBody().as(A33b.class);
+ A33b x =
client().stopClass(A33b.class,A33a.class).build().post("/echoBody",A33b.get()).run().cacheBody().assertBody().is("{bar:2}").getBody().asType(A33b.class);
assertEquals(0,x.foo);
assertEquals(2,x.bar);
}
@@ -946,7 +946,7 @@ public class RestClient_Config_BeanContext_Test {
@Test
public void a34_swaps() throws Exception {
- A34a x =
client().swaps(A34b.class).build().post("/echoBody",A34a.get()).run().cacheBody().assertBody().is("1").getBody().as(A34a.class);
+ A34a x =
client().swaps(A34b.class).build().post("/echoBody",A34a.get()).run().cacheBody().assertBody().is("1").getBody().asType(A34a.class);
assertEquals(1,x.foo);
}
@@ -961,7 +961,7 @@ public class RestClient_Config_BeanContext_Test {
@Test
public void a35_timeZone() throws Exception {
- A35 x =
client().timeZone(TimeZone.getTimeZone("Z")).build().post("/echoBody",A35.get()).run().cacheBody().assertBody().is("{foo:1}").getBody().as(A35.class);
+ A35 x =
client().timeZone(TimeZone.getTimeZone("Z")).build().post("/echoBody",A35.get()).run().cacheBody().assertBody().is("{foo:1}").getBody().asType(A35.class);
assertEquals(1,x.foo);
}
@@ -976,15 +976,15 @@ public class RestClient_Config_BeanContext_Test {
@Test
public void a36_typeName() throws Exception {
- A36 x =
client().typeName(A36.class,"foo").addRootType().build().post("/echoBody",A36.get()).run().cacheBody().assertBody().is("{_type:'foo',foo:1}").getBody().as(A36.class);
+ A36 x =
client().typeName(A36.class,"foo").addRootType().build().post("/echoBody",A36.get()).run().cacheBody().assertBody().is("{_type:'foo',foo:1}").getBody().asType(A36.class);
assertEquals(1,x.foo);
}
@Test
public void a37_typePropertyName() throws Exception {
- A36 x =
client().typeName(A36.class,"foo").typePropertyName("X").addRootType().build().post("/echoBody",A36.get()).run().cacheBody().assertBody().is("{X:'foo',foo:1}").getBody().as(A36.class);
+ A36 x =
client().typeName(A36.class,"foo").typePropertyName("X").addRootType().build().post("/echoBody",A36.get()).run().cacheBody().assertBody().is("{X:'foo',foo:1}").getBody().asType(A36.class);
assertEquals(1,x.foo);
- x =
client().typeName(A36.class,"foo").typePropertyName(A36.class,"X").addRootType().build().post("/echoBody",A36.get()).run().cacheBody().assertBody().is("{X:'foo',foo:1}").getBody().as(A36.class);
+ x =
client().typeName(A36.class,"foo").typePropertyName(A36.class,"X").addRootType().build().post("/echoBody",A36.get()).run().cacheBody().assertBody().is("{X:'foo',foo:1}").getBody().asType(A36.class);
assertEquals(1,x.foo);
}
@@ -1011,7 +1011,7 @@ public class RestClient_Config_BeanContext_Test {
@Test
public void a38_useEnumNames() throws Exception {
- A38b x =
client().useEnumNames().build().post("/echoBody",A38b.get()).run().cacheBody().assertBody().is("{foo:'ONE'}").getBody().as(A38b.class);
+ A38b x =
client().useEnumNames().build().post("/echoBody",A38b.get()).run().cacheBody().assertBody().is("{foo:'ONE'}").getBody().asType(A38b.class);
assertEquals(A38a.ONE,x.foo);
}
@@ -1034,7 +1034,7 @@ public class RestClient_Config_BeanContext_Test {
@Test
public void a39_useJavaIntrospector() throws Exception {
- A39 x =
client().useJavaBeanIntrospector().build().post("/echoBody",A39.get()).run().cacheBody().assertBody().is("{foo:1}").getBody().as(A39.class);
+ A39 x =
client().useJavaBeanIntrospector().build().post("/echoBody",A39.get()).run().cacheBody().assertBody().is("{foo:1}").getBody().asType(A39.class);
assertEquals(1,x.foo);
}
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Config_Context_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Config_Context_Test.java
index d1cce19..76a0f54 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Config_Context_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Config_Context_Test.java
@@ -50,7 +50,7 @@ public class RestClient_Config_Context_Test {
@Test
public void a01_addMap() throws Exception {
-
client().add(OMap.of(SERIALIZER_keepNullProperties,true)).build().post("/echoBody",new
A1()).run().cacheBody().assertBody().is("{foo:null}").getBody().as(A1.class);
+
client().add(OMap.of(SERIALIZER_keepNullProperties,true)).build().post("/echoBody",new
A1()).run().cacheBody().assertBody().is("{foo:null}").getBody().asType(A1.class);
}
public static class A2 {
@@ -68,7 +68,7 @@ public class RestClient_Config_Context_Test {
@Test
public void a02_addToStringObject() throws Exception {
-
client().addTo(BEAN_notBeanClasses,A2.class).build().post("/echoBody",A2.fromString("bar")).run().cacheBody().assertBody().is("'bar'").getBody().as(A2.class);
+
client().addTo(BEAN_notBeanClasses,A2.class).build().post("/echoBody",A2.fromString("bar")).run().cacheBody().assertBody().is("'bar'").getBody().asType(A2.class);
}
public static class A3a {
@@ -89,13 +89,13 @@ public class RestClient_Config_Context_Test {
@Test
public void a03_appendToStringObject() throws Exception {
- A3a x =
client().appendTo(BEAN_swaps,A3b.class).build().post("/echoBody",A3a.get()).run().cacheBody().assertBody().is("1").getBody().as(A3a.class);
+ A3a x =
client().appendTo(BEAN_swaps,A3b.class).build().post("/echoBody",A3a.get()).run().cacheBody().assertBody().is("1").getBody().asType(A3a.class);
assertEquals(1,x.foo);
}
@Test
public void a04_prependToStringObject() throws Exception {
- A3a x =
client().prependTo(BEAN_swaps,A3b.class).build().post("/echoBody",A3a.get()).run().cacheBody().assertBody().is("1").getBody().as(A3a.class);
+ A3a x =
client().prependTo(BEAN_swaps,A3b.class).build().post("/echoBody",A3a.get()).run().cacheBody().assertBody().is("1").getBody().asType(A3a.class);
assertEquals(1,x.foo);
}
@@ -110,7 +110,7 @@ public class RestClient_Config_Context_Test {
@Test
public void a05_apply() throws Exception {
-
MockRestClient.create(A.class).json().apply(SimpleJsonSerializer.DEFAULT.getContextProperties()).build().post("/echoBody",A5.get()).run().cacheBody().assertBody().is("{foo:1}").getBody().as(A5.class);
+
MockRestClient.create(A.class).json().apply(SimpleJsonSerializer.DEFAULT.getContextProperties()).build().post("/echoBody",A5.get()).run().cacheBody().assertBody().is("{foo:1}").getBody().asType(A5.class);
}
public static class A6a {
@@ -140,28 +140,28 @@ public class RestClient_Config_Context_Test {
new A6b();
new A6c();
new A6d().foo();
-
client().applyAnnotations(A6b.class).build().post("/echoBody",A6a.get()).run().cacheBody().assertBody().is("{bar:2,baz:3,foo:1}").getBody().as(A6a.class);
-
client().applyAnnotations(A6c.class).build().post("/echoBody",A6a.get()).run().cacheBody().assertBody().is("{bar:2,baz:3,foo:1}").getBody().as(A6a.class);
-
client().applyAnnotations(A6d.class.getMethod("foo")).build().post("/echoBody",A6a.get()).run().cacheBody().assertBody().is("{bar:2,baz:3,foo:1}").getBody().as(A6a.class);
+
client().applyAnnotations(A6b.class).build().post("/echoBody",A6a.get()).run().cacheBody().assertBody().is("{bar:2,baz:3,foo:1}").getBody().asType(A6a.class);
+
client().applyAnnotations(A6c.class).build().post("/echoBody",A6a.get()).run().cacheBody().assertBody().is("{bar:2,baz:3,foo:1}").getBody().asType(A6a.class);
+
client().applyAnnotations(A6d.class.getMethod("foo")).build().post("/echoBody",A6a.get()).run().cacheBody().assertBody().is("{bar:2,baz:3,foo:1}").getBody().asType(A6a.class);
AnnotationList al =
ClassInfo.of(A6c.class).getAnnotationList(ConfigAnnotationFilter.INSTANCE);
VarResolverSession vr = VarResolver.DEFAULT.createSession();
-
client().applyAnnotations(al,vr).build().post("/echoBody",A6a.get()).run().cacheBody().assertBody().is("{bar:2,baz:3,foo:1}").getBody().as(A6a.class);
+
client().applyAnnotations(al,vr).build().post("/echoBody",A6a.get()).run().cacheBody().assertBody().is("{bar:2,baz:3,foo:1}").getBody().asType(A6a.class);
}
@Test
public void a07_removeFrom() throws Exception {
- A3a x =
client().appendTo(BEAN_swaps,A3b.class).removeFrom(BEAN_swaps,A3b.class).build().post("/echoBody",A3a.get()).run().cacheBody().assertBody().is("{foo:1}").getBody().as(A3a.class);
+ A3a x =
client().appendTo(BEAN_swaps,A3b.class).removeFrom(BEAN_swaps,A3b.class).build().post("/echoBody",A3a.get()).run().cacheBody().assertBody().is("{foo:1}").getBody().asType(A3a.class);
assertEquals(1,x.foo);
}
@Test
public void a08_setStringObject() throws Exception {
-
MockRestClient.create(A.class).json().set(JSON_simpleMode,true).build().post("/echoBody",A3a.get()).run().cacheBody().assertBody().is("{foo:1}").getBody().as(A3a.class);
+
MockRestClient.create(A.class).json().set(JSON_simpleMode,true).build().post("/echoBody",A3a.get()).run().cacheBody().assertBody().is("{foo:1}").getBody().asType(A3a.class);
}
@Test
public void a09_annotations() throws Exception {
-
client().annotations(BeanAnnotation.create(A6a.class).sort(true).build()).build().post("/echoBody",A6a.get()).run().cacheBody().assertBody().is("{bar:2,baz:3,foo:1}").getBody().as(A6a.class);
+
client().annotations(BeanAnnotation.create(A6a.class).sort(true).build()).build().post("/echoBody",A6a.get()).run().cacheBody().assertBody().is("{bar:2,baz:3,foo:1}").getBody().asType(A6a.class);
}
public static interface A10a {
@@ -183,7 +183,7 @@ public class RestClient_Config_Context_Test {
@Test
public void a10_putAllTo() throws Exception {
- A10a x =
client().implClass(A10a.class,A10b.class).build().post("/echoBody",new
StringReader("{foo:1}")).run().getBody().as(A10a.class);
+ A10a x =
client().implClass(A10a.class,A10b.class).build().post("/echoBody",new
StringReader("{foo:1}")).run().getBody().asType(A10a.class);
assertEquals(1,x.getFoo());
assertTrue(x instanceof A10b);
}
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Config_Parser_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Config_Parser_Test.java
index 940ea0a..5a8f1fa 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Config_Parser_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Config_Parser_Test.java
@@ -46,7 +46,7 @@ public class RestClient_Config_Parser_Test {
@Test
public void a02_parser_strict() throws Exception {
-
assertThrown(()->MockRestClient.create(A.class).json().strict().build().post("/echoBody",new
StringReader("{f:1}")).run().getBody().as(A2.class)).contains("Unquoted
attribute detected.");
+
assertThrown(()->MockRestClient.create(A.class).json().strict().build().post("/echoBody",new
StringReader("{f:1}")).run().getBody().asType(A2.class)).contains("Unquoted
attribute detected.");
}
public static class A3 {
@@ -55,7 +55,7 @@ public class RestClient_Config_Parser_Test {
@Test
public void a03_parser_trimStringsOnRead() throws Exception {
- A3 x =
client().trimStringsOnRead().build().post("/echoBody",new StringReader("{f:' 1
'}")).run().getBody().as(A3.class);
+ A3 x =
client().trimStringsOnRead().build().post("/echoBody",new StringReader("{f:' 1
'}")).run().getBody().asType(A3.class);
assertEquals("1",x.f);
}
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Config_RestClient_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Config_RestClient_Test.java
index 84c80af..86db999 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Config_RestClient_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Config_RestClient_Test.java
@@ -360,7 +360,7 @@ public class RestClient_Config_RestClient_Test {
@Test
public void a08_marshall() throws Exception {
RestClient rc =
MockRestClient.create(A.class).marshall(Xml.DEFAULT).build();
- ABean b =
rc.post("/echoBody",bean).run().cacheBody().assertBody().is("<object><f>1</f></object>").getBody().as(ABean.class);
+ ABean b =
rc.post("/echoBody",bean).run().cacheBody().assertBody().is("<object><f>1</f></object>").getBody().asType(ABean.class);
assertObject(b).isSameJsonAs(bean);
}
@@ -370,18 +370,18 @@ public class RestClient_Config_RestClient_Test {
assertThrown(()->x.post("/echoBody",bean).run()).contains("Content-Type not
specified on request. Cannot match correct serializer. Use
contentType(String) or mediaType(String) to specify transport language.");
-
assertThrown(()->x.post("/echoBody",bean).contentType("text/json").run().getBody().as(ABean.class)).contains("Content-Type
not specified in response header. Cannot find appropriate parser.");
+
assertThrown(()->x.post("/echoBody",bean).contentType("text/json").run().getBody().asType(ABean.class)).contains("Content-Type
not specified in response header. Cannot find appropriate parser.");
- ABean b =
x.post("/echoBody",bean).accept("text/xml").contentType("text/xml").run().cacheBody().assertBody().is("<object><f>1</f></object>").getBody().as(ABean.class);
+ ABean b =
x.post("/echoBody",bean).accept("text/xml").contentType("text/xml").run().cacheBody().assertBody().is("<object><f>1</f></object>").getBody().asType(ABean.class);
assertObject(b).isSameJsonAs(bean);
- b =
x.post("/echoBody",bean).mediaType("text/xml").run().cacheBody().assertBody().is("<object><f>1</f></object>").getBody().as(ABean.class);
+ b =
x.post("/echoBody",bean).mediaType("text/xml").run().cacheBody().assertBody().is("<object><f>1</f></object>").getBody().asType(ABean.class);
assertObject(b).isSameJsonAs(bean);
- b =
x.post("/echoBody",bean).accept("text/json").contentType("text/json").run().cacheBody().assertBody().is("{\"f\":1}").getBody().as(ABean.class);
+ b =
x.post("/echoBody",bean).accept("text/json").contentType("text/json").run().cacheBody().assertBody().is("{\"f\":1}").getBody().asType(ABean.class);
assertObject(b).isSameJsonAs(bean);
- b =
x.post("/echoBody",bean).mediaType("text/json").run().cacheBody().assertBody().is("{\"f\":1}").getBody().as(ABean.class);
+ b =
x.post("/echoBody",bean).mediaType("text/json").run().cacheBody().assertBody().is("{\"f\":1}").getBody().asType(ABean.class);
assertObject(b).isSameJsonAs(bean);
}
@@ -389,11 +389,11 @@ public class RestClient_Config_RestClient_Test {
public void a10_serializer_parser() throws Exception {
RestClient x =
MockRestClient.create(A.class).serializer(XmlSerializer.class).parser(XmlParser.class).build();
- ABean b =
x.post("/echoBody",bean).run().cacheBody().assertBody().is("<object><f>1</f></object>").getBody().as(ABean.class);
+ ABean b =
x.post("/echoBody",bean).run().cacheBody().assertBody().is("<object><f>1</f></object>").getBody().asType(ABean.class);
assertObject(b).isSameJsonAs(bean);
x =
MockRestClient.create(A.class).serializer(XmlSerializer.DEFAULT).parser(XmlParser.DEFAULT).build();
- b =
x.post("/echoBody",bean).run().cacheBody().assertBody().is("<object><f>1</f></object>").getBody().as(ABean.class);
+ b =
x.post("/echoBody",bean).run().cacheBody().assertBody().is("<object><f>1</f></object>").getBody().asType(ABean.class);
assertObject(b).isSameJsonAs(bean);
assertThrown(()->MockRestClient.create(A.class).prependTo(RESTCLIENT_serializers,String.class).build()).contains("RESTCLIENT_serializers
property had invalid class of type 'java.lang.String'");
assertThrown(()->MockRestClient.create(A.class).prependTo(RESTCLIENT_serializers,"").build()).contains("RESTCLIENT_serializers
property had invalid object of type 'java.lang.String'");
@@ -408,36 +408,36 @@ public class RestClient_Config_RestClient_Test {
assertThrown(()->x.post("/echoBody",bean).run()).contains("Content-Type not
specified on request. Cannot match correct serializer. Use
contentType(String) or mediaType(String) to specify transport language.");
-
assertThrown(()->x.post("/echoBody",bean).contentType("text/json").run().getBody().as(ABean.class)).contains("Content-Type
not specified in response header. Cannot find appropriate parser.");
+
assertThrown(()->x.post("/echoBody",bean).contentType("text/json").run().getBody().asType(ABean.class)).contains("Content-Type
not specified in response header. Cannot find appropriate parser.");
- ABean b =
x.post("/echoBody",bean).accept("text/xml").contentType("text/xml").run().cacheBody().assertBody().is("<object><f>1</f></object>").getBody().as(ABean.class);
+ ABean b =
x.post("/echoBody",bean).accept("text/xml").contentType("text/xml").run().cacheBody().assertBody().is("<object><f>1</f></object>").getBody().asType(ABean.class);
assertObject(b).isSameJsonAs(bean);
- b =
x.post("/echoBody",bean).mediaType("text/xml").run().cacheBody().assertBody().is("<object><f>1</f></object>").getBody().as(ABean.class);
+ b =
x.post("/echoBody",bean).mediaType("text/xml").run().cacheBody().assertBody().is("<object><f>1</f></object>").getBody().asType(ABean.class);
assertObject(b).isSameJsonAs(bean);
- b =
x.post("/echoBody",bean).accept("text/json").contentType("text/json").run().cacheBody().assertBody().is("{\"f\":1}").getBody().as(ABean.class);
+ b =
x.post("/echoBody",bean).accept("text/json").contentType("text/json").run().cacheBody().assertBody().is("{\"f\":1}").getBody().asType(ABean.class);
assertObject(b).isSameJsonAs(bean);
- b =
x.post("/echoBody",bean).mediaType("text/json").run().cacheBody().assertBody().is("{\"f\":1}").getBody().as(ABean.class);
+ b =
x.post("/echoBody",bean).mediaType("text/json").run().cacheBody().assertBody().is("{\"f\":1}").getBody().asType(ABean.class);
assertObject(b).isSameJsonAs(bean);
final RestClient x2 =
MockRestClient.create(A.class).serializers(XmlSerializer.DEFAULT,JsonSerializer.DEFAULT).parsers(XmlParser.DEFAULT,JsonParser.DEFAULT).build();
assertThrown(()->x2.post("/echoBody",bean).run()).contains("Content-Type not
specified on request. Cannot match correct serializer. Use
contentType(String) or mediaType(String) to specify transport language.");
-
assertThrown(()->x2.post("/echoBody",bean).contentType("text/json").run().getBody().as(ABean.class)).contains("Content-Type
not specified in response header. Cannot find appropriate parser.");
+
assertThrown(()->x2.post("/echoBody",bean).contentType("text/json").run().getBody().asType(ABean.class)).contains("Content-Type
not specified in response header. Cannot find appropriate parser.");
- b =
x2.post("/echoBody",bean).accept("text/xml").contentType("text/xml").run().cacheBody().assertBody().is("<object><f>1</f></object>").getBody().as(ABean.class);
+ b =
x2.post("/echoBody",bean).accept("text/xml").contentType("text/xml").run().cacheBody().assertBody().is("<object><f>1</f></object>").getBody().asType(ABean.class);
assertObject(b).isSameJsonAs(bean);
- b =
x2.post("/echoBody",bean).mediaType("text/xml").run().cacheBody().assertBody().is("<object><f>1</f></object>").getBody().as(ABean.class);
+ b =
x2.post("/echoBody",bean).mediaType("text/xml").run().cacheBody().assertBody().is("<object><f>1</f></object>").getBody().asType(ABean.class);
assertObject(b).isSameJsonAs(bean);
- b =
x2.post("/echoBody",bean).accept("text/json").contentType("text/json").run().cacheBody().assertBody().is("{\"f\":1}").getBody().as(ABean.class);
+ b =
x2.post("/echoBody",bean).accept("text/json").contentType("text/json").run().cacheBody().assertBody().is("{\"f\":1}").getBody().asType(ABean.class);
assertObject(b).isSameJsonAs(bean);
- b =
x2.post("/echoBody",bean).mediaType("text/json").run().cacheBody().assertBody().is("{\"f\":1}").getBody().as(ABean.class);
+ b =
x2.post("/echoBody",bean).mediaType("text/json").run().cacheBody().assertBody().is("{\"f\":1}").getBody().asType(ABean.class);
assertObject(b).isSameJsonAs(bean);
}
@@ -483,13 +483,13 @@ public class RestClient_Config_RestClient_Test {
@Test
public void a12_partSerializer_partParser() throws Exception {
RestClient x =
client(A12.class).header("Foo",bean).partSerializer(A12a.class).partParser(A12b.class).build();
- ABean b =
x.get("/").header("Foo",bean).run().assertHeader("Foo").is("x{f:1}").getResponseHeader("Foo").as(ABean.class).get();
+ ABean b =
x.get("/").header("Foo",bean).run().assertHeader("Foo").is("x{f:1}").getResponseHeader("Foo").asType(ABean.class).get();
assertEquals("{f:1}",b.toString());
- b =
x.get().header("Foo",bean).run().assertHeader("Foo").is("x{f:1}").getResponseHeader("Foo").as(ABean.class).get();
+ b =
x.get().header("Foo",bean).run().assertHeader("Foo").is("x{f:1}").getResponseHeader("Foo").asType(ABean.class).get();
assertEquals("{f:1}",b.toString());
x = client(A12.class).header("Foo",bean).partSerializer(new
A12a()).partParser(new A12b()).build();
- b =
x.get("/").header("Foo",bean).run().assertHeader("Foo").is("x{f:1}").getResponseHeader("Foo").as(ABean.class).get();
+ b =
x.get("/").header("Foo",bean).run().assertHeader("Foo").is("x{f:1}").getResponseHeader("Foo").asType(ABean.class).get();
assertEquals("{f:1}",b.toString());
}
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Marshalls_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Marshalls_Test.java
index 94157aa..f39e750 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Marshalls_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Marshalls_Test.java
@@ -79,36 +79,36 @@ public class RestClient_Marshalls_Test {
RestClient x9 = client().openApi().build();
RestClient x10 = client().htmlDoc().build();
RestClient x11 = client().htmlStrippedDoc().build();
-
x1.post("/a01",bean).header("X-Accept","application/json+simple").header("X-Content-Type","application/json+simple").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x2.post("/a01",bean).header("X-Accept","application/json").header("X-Content-Type","application/json").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x3.post("/a01",bean).header("X-Accept","text/xml").header("X-Content-Type","text/xml").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x4.post("/a01",bean).header("X-Accept","text/html").header("X-Content-Type","text/html").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x5.post("/a01",bean).header("X-Accept","text/plain").header("X-Content-Type","text/plain").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x6.post("/a01",bean).header("X-Accept","octal/msgpack").header("X-Content-Type","octal/msgpack").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x7.post("/a01",bean).header("X-Accept","text/uon").header("X-Content-Type","text/uon").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x8.post("/a01",bean).header("X-Accept","application/x-www-form-urlencoded").header("X-Content-Type","application/x-www-form-urlencoded").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x9.post("/a01",bean).header("X-Accept","text/openapi").header("X-Content-Type","text/openapi").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x10.post("/a01",bean).header("X-Accept","text/html").header("X-Content-Type","text/html").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x11.post("/a01",bean).header("X-Accept","text/html").header("X-Content-Type","text/html+stripped").run().assertCode().is(200).getBody().as(Bean.class).check();
+
x1.post("/a01",bean).header("X-Accept","application/json+simple").header("X-Content-Type","application/json+simple").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x2.post("/a01",bean).header("X-Accept","application/json").header("X-Content-Type","application/json").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x3.post("/a01",bean).header("X-Accept","text/xml").header("X-Content-Type","text/xml").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x4.post("/a01",bean).header("X-Accept","text/html").header("X-Content-Type","text/html").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x5.post("/a01",bean).header("X-Accept","text/plain").header("X-Content-Type","text/plain").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x6.post("/a01",bean).header("X-Accept","octal/msgpack").header("X-Content-Type","octal/msgpack").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x7.post("/a01",bean).header("X-Accept","text/uon").header("X-Content-Type","text/uon").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x8.post("/a01",bean).header("X-Accept","application/x-www-form-urlencoded").header("X-Content-Type","application/x-www-form-urlencoded").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x9.post("/a01",bean).header("X-Accept","text/openapi").header("X-Content-Type","text/openapi").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x10.post("/a01",bean).header("X-Accept","text/html").header("X-Content-Type","text/html").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x11.post("/a01",bean).header("X-Accept","text/html").header("X-Content-Type","text/html+stripped").run().assertCode().is(200).getBody().asType(Bean.class).check();
// With override
-
x1.post("/a01",bean).header("Accept","application/json").header("Content-Type","application/json").header("X-Accept","application/json").header("X-Content-Type","application/json").run().assertCode().is(200).getBody().as(Bean.class).check();
+
x1.post("/a01",bean).header("Accept","application/json").header("Content-Type","application/json").header("X-Accept","application/json").header("X-Content-Type","application/json").run().assertCode().is(200).getBody().asType(Bean.class).check();
}
@Test
public void a02_singleLanguages_perRequest() throws Exception {
RestClient x = client().build();
-
x.post("/a01",bean).header("X-Accept","application/json+simple").header("X-Content-Type","application/json+simple").simpleJson().run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("X-Accept","application/json").header("X-Content-Type","application/json").json().run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("X-Accept","text/xml").header("X-Content-Type","text/xml").xml().run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("X-Accept","text/html").header("X-Content-Type","text/html").html().run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("X-Accept","text/plain").header("X-Content-Type","text/plain").plainText().run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("X-Accept","octal/msgpack").header("X-Content-Type","octal/msgpack").msgPack().run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("X-Accept","text/uon").header("X-Content-Type","text/uon").uon().run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("X-Accept","application/x-www-form-urlencoded").header("X-Content-Type","application/x-www-form-urlencoded").urlEnc().run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("X-Accept","text/openapi").header("X-Content-Type","text/openapi").openApi().run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("X-Accept","text/html").header("X-Content-Type","text/html").htmlDoc().run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("X-Accept","text/html").header("X-Content-Type","text/html+stripped").htmlStrippedDoc().run().assertCode().is(200).getBody().as(Bean.class).check();
+
x.post("/a01",bean).header("X-Accept","application/json+simple").header("X-Content-Type","application/json+simple").simpleJson().run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("X-Accept","application/json").header("X-Content-Type","application/json").json().run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("X-Accept","text/xml").header("X-Content-Type","text/xml").xml().run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("X-Accept","text/html").header("X-Content-Type","text/html").html().run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("X-Accept","text/plain").header("X-Content-Type","text/plain").plainText().run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("X-Accept","octal/msgpack").header("X-Content-Type","octal/msgpack").msgPack().run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("X-Accept","text/uon").header("X-Content-Type","text/uon").uon().run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("X-Accept","application/x-www-form-urlencoded").header("X-Content-Type","application/x-www-form-urlencoded").urlEnc().run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("X-Accept","text/openapi").header("X-Content-Type","text/openapi").openApi().run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("X-Accept","text/html").header("X-Content-Type","text/html").htmlDoc().run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("X-Accept","text/html").header("X-Content-Type","text/html+stripped").htmlStrippedDoc().run().assertCode().is(200).getBody().asType(Bean.class).check();
}
@Test
@@ -124,14 +124,14 @@ public class RestClient_Marshalls_Test {
@Test
public void b01_multiLanguages() throws Exception {
RestClient x =
client().simpleJson().json().xml().html().plainText().msgPack().uon().urlEnc().openApi().build();
-
x.post("/a01",bean).header("Accept","application/json").header("Content-Type","application/json").header("X-Accept","application/json").header("X-Content-Type","application/json").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("Accept","text/xml").header("Content-Type","text/xml").header("X-Accept","text/xml").header("X-Content-Type","text/xml").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("Accept","text/html").header("Content-Type","text/html").header("X-Accept","text/html").header("X-Content-Type","text/html").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("Accept","text/plain").header("Content-Type","text/plain").header("X-Accept","text/plain").header("X-Content-Type","text/plain").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("Accept","octal/msgpack").header("Content-Type","octal/msgpack").header("X-Accept","octal/msgpack").header("X-Content-Type","octal/msgpack").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("Accept","text/uon").header("Content-Type","text/uon").header("X-Accept","text/uon").header("X-Content-Type","text/uon").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("Accept","application/x-www-form-urlencoded").header("Content-Type","application/x-www-form-urlencoded").header("X-Accept","application/x-www-form-urlencoded").header("X-Content-Type","application/x-www-form-urlencoded").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("Accept","text/openapi").header("Content-Type","text/openapi").header("X-Accept","text/openapi").header("X-Content-Type","text/openapi").run().assertCode().is(200).getBody().as(Bean.class).check();
+
x.post("/a01",bean).header("Accept","application/json").header("Content-Type","application/json").header("X-Accept","application/json").header("X-Content-Type","application/json").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("Accept","text/xml").header("Content-Type","text/xml").header("X-Accept","text/xml").header("X-Content-Type","text/xml").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("Accept","text/html").header("Content-Type","text/html").header("X-Accept","text/html").header("X-Content-Type","text/html").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("Accept","text/plain").header("Content-Type","text/plain").header("X-Accept","text/plain").header("X-Content-Type","text/plain").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("Accept","octal/msgpack").header("Content-Type","octal/msgpack").header("X-Accept","octal/msgpack").header("X-Content-Type","octal/msgpack").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("Accept","text/uon").header("Content-Type","text/uon").header("X-Accept","text/uon").header("X-Content-Type","text/uon").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("Accept","application/x-www-form-urlencoded").header("Content-Type","application/x-www-form-urlencoded").header("X-Accept","application/x-www-form-urlencoded").header("X-Content-Type","application/x-www-form-urlencoded").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("Accept","text/openapi").header("Content-Type","text/openapi").header("X-Accept","text/openapi").header("X-Content-Type","text/openapi").run().assertCode().is(200).getBody().asType(Bean.class).check();
assertThrown(()->x.post("/a01",bean).run()).contains("Content-Type not
specified on request. Cannot match correct serializer. Use
contentType(String) or mediaType(String) to specify transport language.");
}
@@ -143,14 +143,14 @@ public class RestClient_Marshalls_Test {
@Test
public void c01_universal() throws Exception {
RestClient x = client().universal().build();
-
x.post("/a01",bean).header("Accept","application/json").header("Content-Type","application/json").header("X-Accept","application/json").header("X-Content-Type","application/json").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("Accept","text/xml").header("Content-Type","text/xml").header("X-Accept","text/xml").header("X-Content-Type","text/xml").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("Accept","text/html").header("Content-Type","text/html").header("X-Accept","text/html").header("X-Content-Type","text/html").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("Accept","text/plain").header("Content-Type","text/plain").header("X-Accept","text/plain").header("X-Content-Type","text/plain").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("Accept","octal/msgpack").header("Content-Type","octal/msgpack").header("X-Accept","octal/msgpack").header("X-Content-Type","octal/msgpack").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("Accept","text/uon").header("Content-Type","text/uon").header("X-Accept","text/uon").header("X-Content-Type","text/uon").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("Accept","application/x-www-form-urlencoded").header("Content-Type","application/x-www-form-urlencoded").header("X-Accept","application/x-www-form-urlencoded").header("X-Content-Type","application/x-www-form-urlencoded").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("Accept","text/openapi").header("Content-Type","text/openapi").header("X-Accept","text/openapi").header("X-Content-Type","text/openapi").run().assertCode().is(200).getBody().as(Bean.class).check();
+
x.post("/a01",bean).header("Accept","application/json").header("Content-Type","application/json").header("X-Accept","application/json").header("X-Content-Type","application/json").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("Accept","text/xml").header("Content-Type","text/xml").header("X-Accept","text/xml").header("X-Content-Type","text/xml").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("Accept","text/html").header("Content-Type","text/html").header("X-Accept","text/html").header("X-Content-Type","text/html").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("Accept","text/plain").header("Content-Type","text/plain").header("X-Accept","text/plain").header("X-Content-Type","text/plain").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("Accept","octal/msgpack").header("Content-Type","octal/msgpack").header("X-Accept","octal/msgpack").header("X-Content-Type","octal/msgpack").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("Accept","text/uon").header("Content-Type","text/uon").header("X-Accept","text/uon").header("X-Content-Type","text/uon").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("Accept","application/x-www-form-urlencoded").header("Content-Type","application/x-www-form-urlencoded").header("X-Accept","application/x-www-form-urlencoded").header("X-Content-Type","application/x-www-form-urlencoded").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("Accept","text/openapi").header("Content-Type","text/openapi").header("X-Accept","text/openapi").header("X-Content-Type","text/openapi").run().assertCode().is(200).getBody().asType(Bean.class).check();
assertThrown(()->x.post("/a01",bean).run()).contains("Content-Type not
specified on request. Cannot match correct serializer. Use
contentType(String) or mediaType(String) to specify transport language.");
}
@@ -163,23 +163,23 @@ public class RestClient_Marshalls_Test {
@Test
public void d01_universal() throws Exception {
RestClient x =
client().universal().header("Accept","application/json").header("Content-Type","application/json").build();
-
x.post("/a01",bean).header("Accept","application/json").header("Content-Type","application/json").header("X-Accept","application/json").header("X-Content-Type","application/json").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("Accept","text/xml").header("Content-Type","text/xml").header("X-Accept","text/xml").header("X-Content-Type","text/xml").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("Accept","text/html").header("Content-Type","text/html").header("X-Accept","text/html").header("X-Content-Type","text/html").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("Accept","text/plain").header("Content-Type","text/plain").header("X-Accept","text/plain").header("X-Content-Type","text/plain").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("Accept","octal/msgpack").header("Content-Type","octal/msgpack").header("X-Accept","octal/msgpack").header("X-Content-Type","octal/msgpack").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("Accept","text/uon").header("Content-Type","text/uon").header("X-Accept","text/uon").header("X-Content-Type","text/uon").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("Accept","application/x-www-form-urlencoded").header("Content-Type","application/x-www-form-urlencoded").header("X-Accept","application/x-www-form-urlencoded").header("X-Content-Type","application/x-www-form-urlencoded").run().assertCode().is(200).getBody().as(Bean.class).check();
-
x.post("/a01",bean).header("Accept","text/openapi").header("Content-Type","text/openapi").header("X-Accept","text/openapi").header("X-Content-Type","text/openapi").run().assertCode().is(200).getBody().as(Bean.class).check();
+
x.post("/a01",bean).header("Accept","application/json").header("Content-Type","application/json").header("X-Accept","application/json").header("X-Content-Type","application/json").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("Accept","text/xml").header("Content-Type","text/xml").header("X-Accept","text/xml").header("X-Content-Type","text/xml").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("Accept","text/html").header("Content-Type","text/html").header("X-Accept","text/html").header("X-Content-Type","text/html").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("Accept","text/plain").header("Content-Type","text/plain").header("X-Accept","text/plain").header("X-Content-Type","text/plain").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("Accept","octal/msgpack").header("Content-Type","octal/msgpack").header("X-Accept","octal/msgpack").header("X-Content-Type","octal/msgpack").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("Accept","text/uon").header("Content-Type","text/uon").header("X-Accept","text/uon").header("X-Content-Type","text/uon").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("Accept","application/x-www-form-urlencoded").header("Content-Type","application/x-www-form-urlencoded").header("X-Accept","application/x-www-form-urlencoded").header("X-Content-Type","application/x-www-form-urlencoded").run().assertCode().is(200).getBody().asType(Bean.class).check();
+
x.post("/a01",bean).header("Accept","text/openapi").header("Content-Type","text/openapi").header("X-Accept","text/openapi").header("X-Content-Type","text/openapi").run().assertCode().is(200).getBody().asType(Bean.class).check();
// Default
-
x.post("/a01",bean).header("X-Accept","application/json").header("X-Content-Type","application/json").run().assertCode().is(200).getBody().as(Bean.class).check();
+
x.post("/a01",bean).header("X-Accept","application/json").header("X-Content-Type","application/json").run().assertCode().is(200).getBody().asType(Bean.class).check();
}
@Test
public void d03_nullMarshalls() throws Exception {
RestClient x =
client().marshall(null).marshalls(Json.DEFAULT,null).build();
-
x.post("/a01",bean).header("X-Accept","application/json").header("X-Content-Type","application/json").run().assertCode().is(200).getBody().as(Bean.class).check();
+
x.post("/a01",bean).header("X-Accept","application/json").header("X-Content-Type","application/json").run().assertCode().is(200).getBody().asType(Bean.class).check();
}
//------------------------------------------------------------------------------------------------------------------
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Response_Body_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Response_Body_Test.java
index 65c7774..a61eb5a 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Response_Body_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Response_Body_Test.java
@@ -100,9 +100,9 @@ public class RestClient_Response_Body_Test {
@Test
public void a02_overrideParser() throws Exception {
RestClient x = client().build();
- ABean b =
x.post("/echo",bean).run().getBody().parser(JsonParser.DEFAULT).as(ABean.class);
+ ABean b =
x.post("/echo",bean).run().getBody().parser(JsonParser.DEFAULT).asType(ABean.class);
assertObject(b).asJson().is("{f:1}");
-
assertThrown(()->x.post("/echo",bean).run().getBody().parser(XmlParser.DEFAULT).as(ABean.class)).contains("ParseError
at [row,col]:[1,1]");
+
assertThrown(()->x.post("/echo",bean).run().getBody().parser(XmlParser.DEFAULT).asType(ABean.class)).contains("ParseError
at [row,col]:[1,1]");
assertThrown(()->x.post("/echo",bean).run().getBody().parser(XmlParser.DEFAULT).assertValue().asType(ABean.class)).contains("ParseError
at [row,col]:[1,1]");
}
@@ -209,22 +209,22 @@ public class RestClient_Response_Body_Test {
@Test
public void a07_asType() throws Exception {
- List<Integer> x1 =
testClient().entity(stringEntity("[1,2]")).get().run().getBody().as(List.class,Integer.class);
+ List<Integer> x1 =
testClient().entity(stringEntity("[1,2]")).get().run().getBody().asType(List.class,Integer.class);
assertObject(x1).asJson().is("[1,2]");
- ABean x3 =
testClient().entity(stringEntity("{f:1}")).get().run().getBody().as(ABean.class);
+ ABean x3 =
testClient().entity(stringEntity("{f:1}")).get().run().getBody().asType(ABean.class);
assertObject(x3).asJson().is("{f:1}");
- HttpEntity x5 =
testClient().entity(stringEntity("{f:1}")).get().run().getBody().as(ResponseBody.class);
+ HttpEntity x5 =
testClient().entity(stringEntity("{f:1}")).get().run().getBody().asType(ResponseBody.class);
assertTrue(x5 instanceof ResponseBody);
- HttpEntity x6 =
testClient().entity(stringEntity("{f:1}")).get().run().getBody().as(HttpEntity.class);
+ HttpEntity x6 =
testClient().entity(stringEntity("{f:1}")).get().run().getBody().asType(HttpEntity.class);
assertTrue(x6 instanceof ResponseBody);
plainTestClient().entity(stringEntity("foo")).get().run().assertBody().asType(A7a.class).passes(x->((A7a)x).x.equals("foo"));
plainTestClient().entity(stringEntity("foo")).get().run().assertBody().asType(A7b.class).passes(x->((A7b)x).x.equals("foo"));
-
assertThrown(()->plainTestClient().entity(stringEntity("foo")).headers(header("Content-Type","foo")).get().run().getBody().as(A7c.class)).exists().contains("Unsupported
media-type","'foo'");
-
assertThrown(()->testClient().entity(stringEntity("")).get().run().getBody().as(A7c.class)).contains("foo");
+
assertThrown(()->plainTestClient().entity(stringEntity("foo")).headers(header("Content-Type","foo")).get().run().getBody().asType(A7c.class)).exists().contains("Unsupported
media-type","'foo'");
+
assertThrown(()->testClient().entity(stringEntity("")).get().run().getBody().asType(A7c.class)).contains("foo");
Future<ABean> x8 =
testClient().entity(stringEntity("{f:1}")).get().run().getBody().asFuture(ABean.class);
assertObject(x8.get()).asJson().is("{f:1}");
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Response_Headers_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Response_Headers_Test.java
index 6dbc18c..bac5c35 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Response_Headers_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_Response_Headers_Test.java
@@ -105,44 +105,44 @@ public class RestClient_Response_Headers_Test {
@SuppressWarnings("unchecked")
@Test
public void a04_asType() throws Exception {
- Integer i =
checkFooClient().build().get("/echo").header("Foo","123").run().getResponseHeader("Foo").as(Integer.class).orElse(null);
+ Integer i =
checkFooClient().build().get("/echo").header("Foo","123").run().getResponseHeader("Foo").asType(Integer.class).orElse(null);
assertEquals(123, i.intValue());
Mutable<Integer> m1 = Mutable.create();
-
checkFooClient().build().get("/echo").header("Foo","123").run().getResponseHeader("Foo").as(m1,Integer.class);
+
checkFooClient().build().get("/echo").header("Foo","123").run().getResponseHeader("Foo").asType(m1,Integer.class);
assertEquals(123, m1.get().intValue());
- List<Integer> l = (List<Integer>)
checkFooClient().build().get("/echo").header("Foo","1,2").run().getResponseHeader("Foo").as(LinkedList.class,Integer.class).get();
+ List<Integer> l = (List<Integer>)
checkFooClient().build().get("/echo").header("Foo","1,2").run().getResponseHeader("Foo").asType(LinkedList.class,Integer.class).get();
assertObject(l).asJson().is("[1,2]");
Mutable<Integer> m2 = Mutable.create();
-
checkFooClient().build().get("/echo").header("Foo","1,2").run().getResponseHeader("Foo").as(m2,LinkedList.class,Integer.class);
+
checkFooClient().build().get("/echo").header("Foo","1,2").run().getResponseHeader("Foo").asType(m2,LinkedList.class,Integer.class);
ClassMeta<LinkedList<Integer>> cm1 =
BeanContext.DEFAULT.getClassMeta(LinkedList.class, Integer.class);
ClassMeta<Integer> cm2 =
BeanContext.DEFAULT.getClassMeta(Integer.class);
- l =
checkFooClient().build().get("/echo").header("Foo","1,2").run().getResponseHeader("Foo").as(cm1).get();
+ l =
checkFooClient().build().get("/echo").header("Foo","1,2").run().getResponseHeader("Foo").asType(cm1).get();
assertObject(l).asJson().is("[1,2]");
Mutable<LinkedList<Integer>> m3 = Mutable.create();
-
checkFooClient().build().get("/echo").header("Foo","1,2").run().getResponseHeader("Foo").as(m3,cm1);
+
checkFooClient().build().get("/echo").header("Foo","1,2").run().getResponseHeader("Foo").asType(m3,cm1);
assertObject(m3.get()).asJson().is("[1,2]");
-
assertThrown(()->checkFooClient().build().get("/echo").header("Foo","foo").run().getResponseHeader("Foo").as(m2,cm1)).contains("Invalid
number");
+
assertThrown(()->checkFooClient().build().get("/echo").header("Foo","foo").run().getResponseHeader("Foo").asType(m2,cm1)).contains("Invalid
number");
- Optional<List<Integer>> o1 =
checkFooClient().build().get("/echo").header("Foo","1,2").run().getResponseHeader("Foo").as(LinkedList.class,Integer.class);
+ Optional<List<Integer>> o1 =
checkFooClient().build().get("/echo").header("Foo","1,2").run().getResponseHeader("Foo").asType(LinkedList.class,Integer.class);
assertObject(o1.get()).asJson().is("[1,2]");
- o1 =
checkFooClient().build().get("/echo").header("Foo","1,2").run().getResponseHeader("Bar").as(LinkedList.class,Integer.class);
+ o1 =
checkFooClient().build().get("/echo").header("Foo","1,2").run().getResponseHeader("Bar").asType(LinkedList.class,Integer.class);
assertFalse(o1.isPresent());
- Optional<Integer> o2 =
checkFooClient().build().get("/echo").header("Foo","1").run().getResponseHeader("Foo").as(Integer.class);
+ Optional<Integer> o2 =
checkFooClient().build().get("/echo").header("Foo","1").run().getResponseHeader("Foo").asType(Integer.class);
assertEquals(1, o2.get().intValue());
- o2 =
checkFooClient().build().get("/echo").header("Foo","1").run().getResponseHeader("Bar").as(Integer.class);
+ o2 =
checkFooClient().build().get("/echo").header("Foo","1").run().getResponseHeader("Bar").asType(Integer.class);
assertFalse(o2.isPresent());
- o2 =
checkFooClient().build().get("/echo").header("Foo","1").run().getResponseHeader("Foo").as(cm2);
+ o2 =
checkFooClient().build().get("/echo").header("Foo","1").run().getResponseHeader("Foo").asType(cm2);
assertEquals(1, o2.get().intValue());
- o2 =
checkFooClient().build().get("/echo").header("Foo","1").run().getResponseHeader("Bar").as(cm2);
+ o2 =
checkFooClient().build().get("/echo").header("Foo","1").run().getResponseHeader("Bar").asType(cm2);
assertFalse(o2.isPresent());
assertTrue(checkFooClient().build().get("/echo").header("Foo","foo").run().getResponseHeader("Foo").asMatcher("foo").matches());