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 fa7a3b8 Code cleanup.
fa7a3b8 is described below
commit fa7a3b8b9f8a724e89506ad5d9c4a86e63684223
Author: JamesBognar <[email protected]>
AuthorDate: Sun Jun 6 17:40:18 2021 -0400
Code cleanup.
---
.../org/apache/juneau/http/header/ContentType.java | 1 +
.../org/apache/juneau/rest/client/RestClient.java | 56 ++++----------
.../apache/juneau/rest/mock/MockRestClient.java | 7 +-
.../juneau/rest/Header_ContentType_Test.java | 39 +++++-----
.../rest/Rest_PredefinedStatusCodes_Test.java | 21 +++---
.../rest/annotation/BeanConfig_Swaps_Test.java | 9 ++-
.../apache/juneau/rest/annotation/Body_Test.java | 87 +++++++++++-----------
.../rest/client/RestClient_BasicCalls_Test.java | 23 +++---
8 files changed, 112 insertions(+), 131 deletions(-)
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/ContentType.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/ContentType.java
index 95ab25e..1fb7611 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/ContentType.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/ContentType.java
@@ -77,6 +77,7 @@ public class ContentType extends BasicMediaTypeHeader {
IMAGE_WEBP = of("image/webp"),
MULTIPART_FORM_DATA = of("multipart/form-data"),
TEXT_HTML = of("text/html"),
+ TEXT_OPENAPI = of("text/openapi"),
TEXT_PLAIN = of("text/plain"),
TEXT_XML = of("text/xml"),
WILDCARD = of("*/*");
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 502f013..e5551fe 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
@@ -332,7 +332,6 @@ import org.apache.juneau.http.HttpHeaders;
* <li class='jc'>{@link RestClientBuilder}
* <ul>
* <li class='jm'>{@link RestClientBuilder#header(String,Object)
header(String,Object)}
- * <li class='jm'>{@link
RestClientBuilder#header(String,Object,HttpPartSchema)
header(String,Object,HttpPartSchema)}
* <li class='jm'>{@link RestClientBuilder#header(String,Supplier)
header(String,Supplier<?>)}
* <li class='jm'>{@link
RestClientBuilder#header(String,Supplier,HttpPartSchema)
header(String,Supplier<?>,HttpPartSchema)}
* <li class='jm'>{@link RestClientBuilder#header(Header)
header(Header)}
@@ -342,32 +341,14 @@ import org.apache.juneau.http.HttpHeaders;
* <li class='jc'>{@link RestRequest}
* <ul>
* <li class='jm'>{@link RestRequest#header(String,Object)
header(String,Object)}
- * <li class='jm'>{@link
RestRequest#header(String,Object,HttpPartSchema)
header(String,Object,HttpPartSchema)}
- * <li class='jm'>{@link
RestRequest#header(ListOperation,String,Object)
header(ListOperation,String,Object)}
- * <li class='jm'>{@link
RestRequest#header(ListOperation,String,Object,HttpPartSchema)
header(ListOperation,String,Object,HttpPartSchema)}
+ * <li class='jm'>{@link
RestRequest#header(ListOperation,String,Object) header(AddFlag,String,Object)}
* <li class='jm'>{@link RestRequest#header(Header) header(Header)}
* <li class='jm'>{@link RestRequest#headers(Object...)
headers(Object...)}
- * <li class='jm'>{@link
RestRequest#headers(ListOperation,Object...) headers(ListOperation;Object...)}
+ * <li class='jm'>{@link
RestRequest#headers(ListOperation,Object...) headers(AddFlag;Object...)}
* <li class='jm'>{@link RestRequest#headerPairs(Object...)
headers(Object...)}
* </ul>
* </ul>
*
- * <p>
- * Additionally, methods are provided on the client builder and per request
for all standard HTTP headers
- * such as {@link RestClientBuilder#authorization(Object)
authorization(Object)}.
- *
- * <h5 class='figure'>Example:</h5>
- * <p class='bcode w800'>
- * <jc>// Create a client that adds an Authorization header to every
request.</jc>
- * RestClient <jv>client</jv> =
RestClient.<jsm>create</jsm>().authorization(<js>"Foo"</js>).build();
- *
- * <jc>// Or do it per-request.</jc>
- * String <jv>response</jv> =
<jv>client</jv>.get(<jsf>URI</jsf>).authorization(<js>"Foo"</js>).run().getBody().asString();
- *
- * <jc>// Or use an HttpHeader.</jc>
- * <jv>response</jv> =
<jv>client</jv>.get(<jsf>URI</jsf>).headers(Authorization.<jsm>of</jsm>(<js>"Foo"</js>)).run().getBody().asString();
- * </p>
- *
* <p class='w900'>
* The supplier methods are particularly useful for header values whose values
may change over time (such as <c>Authorization</c> headers
* which may need to change every few minutes).
@@ -408,18 +389,15 @@ import org.apache.juneau.http.HttpHeaders;
* <li class='jc'>{@link RestClientBuilder}
* <ul>
* <li class='jm'>{@link RestClientBuilder#query(String,Object)
query(String,Object)}
- * <li class='jm'>{@link
RestClientBuilder#query(String,Object,HttpPartSchema)
query(String,Object,HttpPartSchema)}
* <li class='jm'>{@link RestClientBuilder#query(String,Supplier)
query(String,Supplier<?>)}
- * <li class='jm'>{@link
RestClientBuilder#query(String,Supplier,HttpPartSchema)
query(String,Supplier<?>,HttpPartSchema)}
- * <li class='jm'>{@link RestClientBuilder#queries(Object...)
queries(Object...)}
* <li class='jm'>{@link RestClientBuilder#queryPairs(Object...)
queryPairs(Object...)}
* </ul>
* <li class='jc'>{@link RestRequest}
* <ul>
* <li class='jm'>{@link RestRequest#query(String,Object)
query(String,Object)}
- * <li class='jm'>{@link
RestRequest#query(ListOperation,String,Object)
query(ListOperation,String,Object)}
+ * <li class='jm'>{@link
RestRequest#query(ListOperation,String,Object) query(AddFlag,String,Object)}
* <li class='jm'>{@link RestRequest#queries(Object...)
queries(Object...)}
- * <li class='jm'>{@link
RestRequest#queries(ListOperation,Object...) queries(ListOperation,Object...)}
+ * <li class='jm'>{@link
RestRequest#queries(ListOperation,Object...) queries(AddFlag,Object...)}
* <li class='jm'>{@link RestRequest#queryPairs(Object...)
queryPairs(Object...)}
* <li class='jm'>{@link RestRequest#queryCustom(Object)
queryCustom(Object)}
* </ul>
@@ -449,18 +427,15 @@ import org.apache.juneau.http.HttpHeaders;
* <li class='jc'>{@link RestClientBuilder}
* <ul>
* <li class='jm'>{@link RestClientBuilder#formData(String,Object)
formData(String,Object)}
- * <li class='jm'>{@link
RestClientBuilder#formData(String,Object,HttpPartSchema)
formData(String,Object,HttpPartSchema)}
* <li class='jm'>{@link
RestClientBuilder#formData(String,Supplier) formData(String,Supplier<?>)}
- * <li class='jm'>{@link
RestClientBuilder#formData(String,Supplier,HttpPartSchema)
formData(String,Supplier<?>,HttpPartSchema)}
- * <li class='jm'>{@link RestClientBuilder#formDatas(Object...)
formDatas(Object...)}
* <li class='jm'>{@link
RestClientBuilder#formDataPairs(Object...) formDataPairs(Object...)}
* </ul>
* <li class='jc'>{@link RestRequest}
* <ul>
* <li class='jm'>{@link RestRequest#formData(String,Object)
formData(String,Object)}
- * <li class='jm'>{@link
RestRequest#formData(ListOperation,String,Object)
formData(ListOperation,String,Object)}
+ * <li class='jm'>{@link
RestRequest#formData(ListOperation,String,Object)
formData(AddFlag,String,Object)}
* <li class='jm'>{@link RestRequest#formDatas(Object...)
formDatas(Object...)}
- * <li class='jm'>{@link
RestRequest#formDatas(ListOperation,Object...)
formDatas(ListOperation,Object...)}
+ * <li class='jm'>{@link
RestRequest#formDatas(ListOperation,Object...) formDatas(AddFlag,Object...)}
* <li class='jm'>{@link RestRequest#formDataPairs(Object...)
formDataPairs(Object...)}
* <li class='jm'>{@link RestRequest#formDataCustom(Object)
formDataCustom(Object)}
* </ul>
@@ -1031,8 +1006,7 @@ import org.apache.juneau.http.HttpHeaders;
*
* <p class='w900'>
* The {@link RestRequest} and {@link RestResponse} objects can also be
extended and integrated by overriding the
- * {@link RestClient#createRequest(URI, String, boolean)} and {@link
RestClient#createResponse(RestRequest, HttpResponse, Parser)} methods.
- *
+ * {@link RestClient#createRequest(URI,String,boolean)} and {@link
RestClient#createResponse(RestRequest,HttpResponse,Parser)} methods.
*
* <ul class='seealso'>
* <li class='link'>{@doc juneau-rest-client}
@@ -2302,8 +2276,8 @@ public class RestClient extends BeanContext implements
HttpClient, Closeable, Re
* and getting the response as a parsed object.
* @throws RestCallException If any authentication errors occurred.
*/
- public RestRequest put(Object uri, String body, String contentType)
throws RestCallException {
- return request(op("PUT", uri,
stringBody(body))).contentType(contentType);
+ public RestRequest put(Object uri, String body, ContentType
contentType) throws RestCallException {
+ return request(op("PUT", uri,
stringBody(body))).header(contentType);
}
/**
@@ -2398,8 +2372,8 @@ public class RestClient extends BeanContext implements
HttpClient, Closeable, Re
* as a parsed object.
* @throws RestCallException If any authentication errors occurred.
*/
- public RestRequest post(Object uri, String body, String contentType)
throws RestCallException {
- return request(op("POST", uri,
stringBody(body))).contentType(contentType);
+ public RestRequest post(Object uri, String body, ContentType
contentType) throws RestCallException {
+ return request(op("POST", uri,
stringBody(body))).header(contentType);
}
/**
@@ -2545,11 +2519,11 @@ public class RestClient extends BeanContext implements
HttpClient, Closeable, Re
if (body instanceof HttpEntity) {
HttpEntity e = (HttpEntity)body;
if (e.getContentType() == null)
-
req.contentType("application/x-www-form-urlencoded");
+
req.header(ContentType.APPLICATION_FORM_URLENCODED);
return req.body(e);
}
if (body instanceof Reader || body instanceof
InputStream)
- return
req.contentType("application/x-www-form-urlencoded").body(body);
+ return
req.header(ContentType.APPLICATION_FORM_URLENCODED).body(body);
return req.body(serializedEntity(body,
urlEncodingSerializer, null).build());
} catch (IOException e) {
throw new RestCallException(null, e, "Could not read
form post body.");
@@ -2669,8 +2643,8 @@ public class RestClient extends BeanContext implements
HttpClient, Closeable, Re
* as a parsed object.
* @throws RestCallException If any authentication errors occurred.
*/
- public RestRequest patch(Object uri, String body, String contentType)
throws RestCallException {
- return request(op("PATCH", uri,
stringBody(body))).contentType(contentType);
+ public RestRequest patch(Object uri, String body, ContentType
contentType) throws RestCallException {
+ return request(op("PATCH", uri,
stringBody(body))).header(contentType);
}
/**
diff --git
a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockRestClient.java
b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockRestClient.java
index 705ff6d..c14c67c 100644
---
a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockRestClient.java
+++
b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockRestClient.java
@@ -39,6 +39,7 @@ import org.apache.juneau.rest.annotation.*;
import org.apache.juneau.rest.client.*;
import org.apache.juneau.rest.client.RestRequest;
import org.apache.juneau.rest.logging.*;
+import org.apache.juneau.http.header.ContentType;
/**
* Mocked {@link RestClient}.
@@ -473,7 +474,7 @@ public class MockRestClient extends RestClient implements
HttpClientConnection {
}
@Override /* RestClient */
- public MockRestRequest put(Object url, String body, String contentType)
throws RestCallException {
+ public MockRestRequest put(Object url, String body, ContentType
contentType) throws RestCallException {
return (MockRestRequest)super.put(url, body, contentType);
}
@@ -488,7 +489,7 @@ public class MockRestClient extends RestClient implements
HttpClientConnection {
}
@Override /* RestClient */
- public MockRestRequest post(Object url, String body, String
contentType) throws RestCallException {
+ public MockRestRequest post(Object url, String body, ContentType
contentType) throws RestCallException {
return (MockRestRequest)super.post(url, body, contentType);
}
@@ -533,7 +534,7 @@ public class MockRestClient extends RestClient implements
HttpClientConnection {
}
@Override /* RestClient */
- public MockRestRequest patch(Object url, String body, String
contentType) throws RestCallException {
+ public MockRestRequest patch(Object url, String body, ContentType
contentType) throws RestCallException {
return (MockRestRequest)super.patch(url, body, contentType);
}
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/rest/Header_ContentType_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/rest/Header_ContentType_Test.java
index 1e5c704..e5cd539 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/rest/Header_ContentType_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/rest/Header_ContentType_Test.java
@@ -18,6 +18,7 @@ import java.io.IOException;
import org.apache.juneau.*;
import org.apache.juneau.http.annotation.Body;
+import org.apache.juneau.http.header.*;
import org.apache.juneau.parser.*;
import org.apache.juneau.rest.annotation.*;
import org.apache.juneau.rest.client.*;
@@ -45,16 +46,16 @@ public class Header_ContentType_Test {
@Test
public void a01_defaultHeadersOnServletAnnotation() throws Exception {
RestClient a = MockRestClient.buildLax(A.class);
- a.put("/a", null, "")
+ a.put("/a", null, ContentType.of(""))
.run()
.assertBody().is("p2");
- a.put("/a", null, "text/p1")
+ a.put("/a", null, ContentType.of("text/p1"))
.run()
.assertBody().is("p1");
- a.put("/a", null, "text/p2")
+ a.put("/a", null, ContentType.of("text/p2"))
.run()
.assertBody().is("p2");
- a.put("/a?noTrace=true", null, "text/p3")
+ a.put("/a?noTrace=true", null, ContentType.of("text/p3"))
.run()
.assertCode().is(415)
.assertBody().contains("Unsupported media-type in
request header 'Content-Type': 'text/p3'");
@@ -80,21 +81,21 @@ public class Header_ContentType_Test {
public void b01_restMethodWithParsersSerializers() throws Exception {
RestClient b = MockRestClient.buildLax(B.class);
b.put("/a",
null).contentType("text/p3").run().assertBody().is("p3");
- b.put("/a?noTrace=true", null, "")
+ b.put("/a?noTrace=true", null, ContentType.of(""))
.run()
.assertCode().is(415)
.assertBody().contains(
"Unsupported media-type in request header
'Content-Type': 'text/p2'",
"Supported media-types: ['text/p3']"
);
- b.put("/a?noTrace=true", null, "text/p1")
+ b.put("/a?noTrace=true", null, ContentType.of("text/p1"))
.run()
.assertCode().is(415)
.assertBody().contains(
"Unsupported media-type in request header
'Content-Type': 'text/p1'",
"Supported media-types: ['text/p3']"
);
- b.put("/a?noTrace=true", null, "text/p2")
+ b.put("/a?noTrace=true", null, ContentType.of("text/p2"))
.run()
.assertCode().is(415)
.assertBody().contains(
@@ -122,10 +123,10 @@ public class Header_ContentType_Test {
@Test
public void c01_restMethodAddParsersSerializersInherit() throws
Exception {
RestClient c = MockRestClient.buildLax(C.class);
- c.put("/a", null, "").run().assertBody().is("p2");
- c.put("/a", null, "text/p1").run().assertBody().is("p1");
- c.put("/a", null, "text/p2").run().assertBody().is("p2");
- c.put("/a", null, "text/p3").run().assertBody().is("p3");
+ c.put("/a", null,
ContentType.of("")).run().assertBody().is("p2");
+ c.put("/a", null,
ContentType.of("text/p1")).run().assertBody().is("p1");
+ c.put("/a", null,
ContentType.of("text/p2")).run().assertBody().is("p2");
+ c.put("/a", null,
ContentType.of("text/p3")).run().assertBody().is("p3");
c.put("/a?noTrace=true", null).contentType("text/p4")
.run()
.assertCode().is(415)
@@ -154,20 +155,20 @@ public class Header_ContentType_Test {
@Test
public void d01_restMethodParserSerializerAnnotations() throws
Exception {
RestClient d = MockRestClient.buildLax(D.class);
- d.put("/a", null, "")
+ d.put("/a", null, ContentType.of(""))
.run()
.assertBody().is("p3");
- d.put("/a", null, "text/p3")
+ d.put("/a", null, ContentType.of("text/p3"))
.run()
.assertBody().is("p3");
- d.put("/a?noTrace=true", null, "text/p1")
+ d.put("/a?noTrace=true", null, ContentType.of("text/p1"))
.run()
.assertCode().is(415)
.assertBody().contains(
"Unsupported media-type in request header
'Content-Type': 'text/p1'",
"Supported media-types: ['text/p3']"
);
- d.put("/a?noTrace=true", null, "text/p2")
+ d.put("/a?noTrace=true", null, ContentType.of("text/p2"))
.run()
.assertCode().is(415)
.assertBody().contains(
@@ -195,16 +196,16 @@ public class Header_ContentType_Test {
@Test
public void e01_restMethodAddParsersSerializersAnnotations() throws
Exception {
RestClient e = MockRestClient.build(E.class);
- e.put("/a", null, "")
+ e.put("/a", null, ContentType.of(""))
.run()
.assertBody().is("p3");
- e.put("/a", null, "text/p1")
+ e.put("/a", null, ContentType.of("text/p1"))
.run()
.assertBody().is("p1");
- e.put("/a", null, "text/p2")
+ e.put("/a", null, ContentType.of("text/p2"))
.run()
.assertBody().is("p2");
- e.put("/a", null, "text/p3")
+ e.put("/a", null, ContentType.of("text/p3"))
.run()
.assertBody().is("p3");
}
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/rest/Rest_PredefinedStatusCodes_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/rest/Rest_PredefinedStatusCodes_Test.java
index b4144a7..7514eb0 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/rest/Rest_PredefinedStatusCodes_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/rest/Rest_PredefinedStatusCodes_Test.java
@@ -13,6 +13,7 @@
package org.apache.juneau.rest;
import static org.junit.runners.MethodSorters.*;
+import static org.apache.juneau.http.header.ContentType.*;
import java.io.*;
@@ -112,61 +113,61 @@ public class Rest_PredefinedStatusCodes_Test {
@Test
public void b01_badRequest() throws Exception {
RestClient b = MockRestClient.buildLax(B.class);
- b.put("/a?noTrace=true", "{f2:'foo'}", "application/json")
+ b.put("/a?noTrace=true", "{f2:'foo'}", APPLICATION_JSON)
.run()
.assertCode().is(400)
.assertBody().contains(
"Unknown property 'f2' encountered while trying
to parse into class"
);
- b.put("/a?noTrace=true", "{f1:'foo', f2:'foo'}",
"application/json")
+ b.put("/a?noTrace=true", "{f1:'foo', f2:'foo'}",
APPLICATION_JSON)
.run()
.assertCode().is(400)
.assertBody().contains(
"Unknown property 'f2' encountered while trying
to parse into class"
);
- b.put("/b?noTrace=true", "{f1:'foo'}", "application/json")
+ b.put("/b?noTrace=true", "{f1:'foo'}", APPLICATION_JSON)
.run()
.assertCode().is(400)
.assertBody().contains(
"Invalid number"
);
- b.put("/c?noTrace=true", "{f1:1}", "application/json")
+ b.put("/c?noTrace=true", "{f1:1}", APPLICATION_JSON)
.run()
.assertCode().is(400)
.assertBody().contains(
"could not be instantiated"
);
- b.put("/d?noTrace=true", "{f1:1}", "application/json")
+ b.put("/d?noTrace=true", "{f1:1}", APPLICATION_JSON)
.run()
.assertCode().is(400)
.assertBody().contains(
"could not be instantiated"
);
- b.put("/e?noTrace=true", "{f1:1}", "application/json")
+ b.put("/e?noTrace=true", "{f1:1}", APPLICATION_JSON)
.run()
.assertCode().is(400)
.assertBody().contains(
"Class is not public"
);
- b.put("/f?noTrace=true", "'foo'", "application/json")
+ b.put("/f?noTrace=true", "'foo'", APPLICATION_JSON)
.run()
.assertCode().is(400)
.assertBody().contains(
"Test error"
);
- b.put("/g/123?noTrace=true&p1=foo", "'foo'", "application/json")
+ b.put("/g/123?noTrace=true&p1=foo", "'foo'", APPLICATION_JSON)
.run()
.assertCode().is(400)
.assertBody().contains(
"Could not parse query parameter 'p1'."
);
- b.put("/g/foo?noTrace=true&p1=1", "'foo'", "application/json")
+ b.put("/g/foo?noTrace=true&p1=1", "'foo'", APPLICATION_JSON)
.run()
.assertCode().is(400)
.assertBody().contains(
"Could not parse path parameter 'a1'."
);
- b.put("/g/123?noTrace=true&p1=1", "'foo'", "application/json")
+ b.put("/g/123?noTrace=true&p1=1", "'foo'", APPLICATION_JSON)
.header("h1", "foo")
.run()
.assertCode().is(400)
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/BeanConfig_Swaps_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/BeanConfig_Swaps_Test.java
index eac2259..a887a9d 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/BeanConfig_Swaps_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/BeanConfig_Swaps_Test.java
@@ -13,6 +13,7 @@
package org.apache.juneau.rest.annotation;
import static org.junit.runners.MethodSorters.*;
+import static org.apache.juneau.http.header.ContentType.*;
import org.apache.juneau.*;
import org.apache.juneau.annotation.*;
@@ -123,10 +124,10 @@ public class BeanConfig_Swaps_Test {
public void a01_swaps() throws Exception {
RestClient a = MockRestClient.build(A1.class);
a.get("/a").json().run().assertBody().is("'A2-0'");
- a.put("/b", "'A2-1'",
"application/json").run().assertBody().is("'A2-1'");
- a.put("/c/A2-2", null,
"application/json").run().assertBody().is("'A2-2'");
+ a.put("/b", "'A2-1'",
APPLICATION_JSON).run().assertBody().is("'A2-1'");
+ a.put("/c/A2-2", null,
APPLICATION_JSON).run().assertBody().is("'A2-2'");
a.get("/d").json().run().assertBody().is("'A3-0'");
- a.put("/e", "'A3-1'",
"application/json").run().assertBody().is("'A3-1'");
- a.put("/f/A3-2", null,
"application/json").run().assertBody().is("'A3-2'");
+ a.put("/e", "'A3-1'",
APPLICATION_JSON).run().assertBody().is("'A3-1'");
+ a.put("/f/A3-2", null,
APPLICATION_JSON).run().assertBody().is("'A3-2'");
}
}
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/Body_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/Body_Test.java
index 1fa2f8f..a1ee503 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/Body_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/Body_Test.java
@@ -15,6 +15,7 @@ package org.apache.juneau.rest.annotation;
import static org.junit.Assert.*;
import static org.junit.runners.MethodSorters.*;
import static org.apache.juneau.internal.IOUtils.*;
+import static org.apache.juneau.http.header.ContentType.*;
import java.io.*;
import java.util.*;
@@ -286,10 +287,10 @@ public class Body_Test {
.run()
.assertCode().is(400);
- a.put("/Map", "{foo:123}", "application/json")
+ a.put("/Map", "{foo:123}", APPLICATION_JSON)
.run()
.assertBody().is("{foo:123}");
- a.put("/Map", "(foo=123)", "text/openapi")
+ a.put("/Map", "(foo=123)", TEXT_OPENAPI)
.run()
.assertCode().is(415);
a.put("/Map?body=(foo=123)", null)
@@ -308,7 +309,7 @@ public class Body_Test {
.run()
.assertCode().is(400);
- a.put("/enum", "'ONE'", "application/json")
+ a.put("/enum", "'ONE'", APPLICATION_JSON)
.run()
.assertBody().is("'ONE'");
a.put("/enum", "ONE")
@@ -330,10 +331,10 @@ public class Body_Test {
.run()
.assertCode().is(400);
- a.put("/Bean", "{f1:'a'}", "application/json")
+ a.put("/Bean", "{f1:'a'}", APPLICATION_JSON)
.run()
.assertBody().is("{f1:'a'}");
- a.put("/Bean", "(f1=a)", "text/openapi")
+ a.put("/Bean", "(f1=a)", TEXT_OPENAPI)
.run()
.assertCode().is(415);
a.put("/Bean?body=(f1=a)", null)
@@ -353,7 +354,7 @@ public class Body_Test {
.assertCode().is(400);
// Content-Type should always be ignored.
- a.put("/InputStream", "'a'", "application/json")
+ a.put("/InputStream", "'a'", APPLICATION_JSON)
.run()
.assertBody().is("'\\'a\\''");
a.put("/InputStream", "'a'")
@@ -370,7 +371,7 @@ public class Body_Test {
.assertBody().is("''");
// Content-Type should always be ignored.
- a.put("/Reader", "'a'", "application/json")
+ a.put("/Reader", "'a'", APPLICATION_JSON)
.run()
.assertBody().is("'\\'a\\''");
a.put("/Reader", "'a'")
@@ -389,7 +390,7 @@ public class Body_Test {
// It's not currently possible to pass in a &body parameter for
InputStream/Reader transforms.
// Input stream transform requests must not specify
Content-Type or else gets resolved as POJO.
- a.put("/InputStreamTransform?noTrace=true", "'a'",
"application/json")
+ a.put("/InputStreamTransform?noTrace=true", "'a'",
APPLICATION_JSON)
.run()
.assertBody().contains("Bad Request");
a.put("/InputStreamTransform", "'a'")
@@ -397,7 +398,7 @@ public class Body_Test {
.assertBody().is("'\\'a\\''");
// Reader transform requests must not specify Content-Type or
else gets resolved as POJO.
- a.put("/ReaderTransform?noTrace=true", "'a'",
"application/json")
+ a.put("/ReaderTransform?noTrace=true", "'a'", APPLICATION_JSON)
.run()
.assertBody().contains("Bad Request");
a.put("/ReaderTransform", "'a'")
@@ -405,7 +406,7 @@ public class Body_Test {
.assertBody().is("'\\'a\\''");
// When Content-Type specified and matched, treated as a parsed
POJO.
- a.put("/StringTransform", "'a'", "application/json")
+ a.put("/StringTransform", "'a'", APPLICATION_JSON)
.run()
.assertBody().is("'a'");
// When Content-Type not matched, treated as plain text.
@@ -470,37 +471,37 @@ public class Body_Test {
@Test
public void b01_onPojos() throws Exception {
RestClient b = MockRestClient.buildLax(B.class);
- b.put("/StringTransform", "'foo'", "application/json")
+ b.put("/StringTransform", "'foo'", APPLICATION_JSON)
.run()
.assertBody().is("'foo'");
// When Content-Type not matched, treated as plain text.
b.put("/StringTransform", "'foo'")
.run()
.assertBody().is("'\\'foo\\''");
- b.put("/Bean", "{f1:'a'}", "application/json")
+ b.put("/Bean", "{f1:'a'}", APPLICATION_JSON)
.run()
.assertBody().is("{f1:'a'}");
- b.put("/Bean", "(f1=a)", "text/openapi")
+ b.put("/Bean", "(f1=a)", TEXT_OPENAPI)
.run()
.assertCode().is(415);
- b.put("/BeanList", "[{f1:'a'}]", "application/json")
+ b.put("/BeanList", "[{f1:'a'}]", APPLICATION_JSON)
.run()
.assertBody().is("[{f1:'a'}]");
- b.put("/BeanList", "(f1=a)", "text/openapi")
+ b.put("/BeanList", "(f1=a)", TEXT_OPENAPI)
.run()
.assertCode().is(415);
b.put("/InputStreamTransform", "a")
.run()
.assertBody().is("'a'");
// When Content-Type matched, treated as parsed POJO.
- b.put("/InputStreamTransform?noTrace=true", "a",
"application/json")
+ b.put("/InputStreamTransform?noTrace=true", "a",
APPLICATION_JSON)
.run()
.assertBody().contains("Bad Request");
b.put("/ReaderTransform", "a")
.run()
.assertBody().is("'a'");
// When Content-Type matched, treated as parsed POJO.
- b.put("/ReaderTransform?noTrace=true", "a", "application/json")
+ b.put("/ReaderTransform?noTrace=true", "a", APPLICATION_JSON)
.run()
.assertBody().contains("Bad Request");
}
@@ -589,55 +590,55 @@ public class Body_Test {
d.put("/String", "a")
.run()
.assertBody().is("a");
- d.put("/String", "a", "application/json")
+ d.put("/String", "a", APPLICATION_JSON)
.run()
.assertBody().is("a");
d.put("/InputStream", "a")
.run()
.assertBody().is("a");
- d.put("/InputStream", "a", "application/json")
+ d.put("/InputStream", "a", APPLICATION_JSON)
.run()
.assertBody().is("a");
d.put("/Reader", "a")
.run()
.assertBody().is("a");
- d.put("/Reader", "a", "application/json")
+ d.put("/Reader", "a", APPLICATION_JSON)
.run()
.assertBody().is("a");
d.put("/StringTransform", "a")
.run()
.assertBody().is("a");
- d.put("/StringTransform?noTrace=true", "a", "application/json")
+ d.put("/StringTransform?noTrace=true", "a", APPLICATION_JSON)
.run()
.assertCode().is(415);
d.put("/InputStreamTransform", "a")
.run()
.assertBody().is("a");
- d.put("/InputStreamTransform", "a", "application/json")
+ d.put("/InputStreamTransform", "a", APPLICATION_JSON)
.run()
.assertBody().is("a");
d.put("/ReaderTransform", "a")
.run()
.assertBody().is("a");
- d.put("/ReaderTransform", "a", "application/json")
+ d.put("/ReaderTransform", "a", APPLICATION_JSON)
.run()
.assertBody().is("a");
d.put("/StringTransformBodyOnPojo", "a")
.run()
.assertBody().is("a");
- d.put("/StringTransformBodyOnPojo?noTrace=true", "a",
"application/json")
+ d.put("/StringTransformBodyOnPojo?noTrace=true", "a",
APPLICATION_JSON)
.run()
.assertCode().is(415);
d.put("/InputStreamTransformBodyOnPojo", "a")
.run()
.assertBody().is("a");
- d.put("/InputStreamTransformBodyOnPojo", "a",
"application/json")
+ d.put("/InputStreamTransformBodyOnPojo", "a", APPLICATION_JSON)
.run()
.assertBody().is("a");
d.put("/ReaderTransformBodyOnPojo", "a")
.run()
.assertBody().is("a");
- d.put("/ReaderTransformBodyOnPojo", "a", "application/json")
+ d.put("/ReaderTransformBodyOnPojo", "a", APPLICATION_JSON)
.run()
.assertBody().is("a");
}
@@ -664,7 +665,7 @@ public class Body_Test {
String expected;
expected =
"{f01:['a','b'],f02:['c','d'],f03:[1,2],f04:[3,4],f05:[['e','f'],['g','h']],f06:[['i','j'],['k','l']],f07:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f08:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f09:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[
[...]
- e.put("/B",
SimpleJsonSerializer.DEFAULT.toString(XBeans.XB.INSTANCE), "application/json")
+ e.put("/B",
SimpleJsonSerializer.DEFAULT.toString(XBeans.XB.INSTANCE), APPLICATION_JSON)
.run()
.assertBody().is(expected);
@@ -674,7 +675,7 @@ public class Body_Test {
.assertBody().is(expected);
expected =
"{f01:['a','b'],f02:['c','d'],f03:[1,2],f04:[3,4],f05:[['e','f'],['g','h']],f06:[['i','j'],['k','l']],f07:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f08:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f09:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[
[...]
- e.put("/C",
SimpleJsonSerializer.DEFAULT.toString(XBeans.XB.INSTANCE), "application/json")
+ e.put("/C",
SimpleJsonSerializer.DEFAULT.toString(XBeans.XB.INSTANCE), APPLICATION_JSON)
.run()
.assertBody().is(expected);
@@ -704,7 +705,7 @@ public class Body_Test {
String expected;
expected =
"{f01:['a','b'],f02:['c','d'],f03:[1,2],f04:[3,4],f05:[['e','f'],['g','h']],f06:[['i','j'],['k','l']],f07:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f08:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f09:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[
[...]
- e2.put("/B",
SimpleJsonSerializer.DEFAULT.copy().applyAnnotations(XBeans.Annotations.class).build().toString(XBeans.XE.INSTANCE),
"application/json")
+ e2.put("/B",
SimpleJsonSerializer.DEFAULT.copy().applyAnnotations(XBeans.Annotations.class).build().toString(XBeans.XE.INSTANCE),
APPLICATION_JSON)
.run()
.assertBody().is(expected);
@@ -714,7 +715,7 @@ public class Body_Test {
.assertBody().is(expected);
expected =
"{f01:['a','b'],f02:['c','d'],f03:[1,2],f04:[3,4],f05:[['e','f'],['g','h']],f06:[['i','j'],['k','l']],f07:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f08:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f09:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[
[...]
- e2.put("/C",
SimpleJsonSerializer.DEFAULT.copy().applyAnnotations(XBeans.Annotations.class).build().toString(XBeans.XE.INSTANCE),
"application/json")
+ e2.put("/C",
SimpleJsonSerializer.DEFAULT.copy().applyAnnotations(XBeans.Annotations.class).build().toString(XBeans.XE.INSTANCE),
APPLICATION_JSON)
.run()
.assertBody().is(expected);
@@ -746,16 +747,16 @@ public class Body_Test {
@Test
public void f01_formPostAsContent() throws Exception {
RestClient f = MockRestClient.build(F.class);
- f.post("/", "{p1:'p1',p2:2}", "application/json")
+ f.post("/", "{p1:'p1',p2:2}", APPLICATION_JSON)
.run()
.assertBody().is("bean=[{p1:'p1',p2:2}],qp1=[null],qp2=[0],hqp1=[false],hqp2=[false]");
- f.post("/", "{}", "application/json")
+ f.post("/", "{}", APPLICATION_JSON)
.run()
.assertBody().is("bean=[{p2:0}],qp1=[null],qp2=[0],hqp1=[false],hqp2=[false]");
- f.post("?p1=p3&p2=4", "{p1:'p1',p2:2}", "application/json")
+ f.post("?p1=p3&p2=4", "{p1:'p1',p2:2}", APPLICATION_JSON)
.run()
.assertBody().is("bean=[{p1:'p1',p2:2}],qp1=[p3],qp2=[4],hqp1=[true],hqp2=[true]");
- f.post("?p1=p3&p2=4", "{}", "application/json")
+ f.post("?p1=p3&p2=4", "{}", APPLICATION_JSON)
.run()
.assertBody().is("bean=[{p2:0}],qp1=[p3],qp2=[4],hqp1=[true],hqp2=[true]");
}
@@ -798,7 +799,7 @@ public class Body_Test {
+ "&f18=(a=a,b=1,c=true)&f18=(a=b,b=2,c=false)"
+ "&f19=@((a=a,b=1,c=true))&f19=@((a=b,b=2,c=false))"
+ "&f20=@((a=a,b=1,c=true))&f20=@((a=b,b=2,c=false))";
- g.post("/", in, "application/x-www-form-urlencoded")
+ g.post("/", in, APPLICATION_FORM_URLENCODED)
.run()
.assertBody().is(in);
}
@@ -842,7 +843,7 @@ public class Body_Test {
+ "&f18=(a=a,b=1,c=true)&f18=(a=b,b=2,c=false)"
+ "&f19=@((a=a,b=1,c=true))&f19=@((a=b,b=2,c=false))"
+ "&f20=@((a=a,b=1,c=true))&f20=@((a=b,b=2,c=false))";
- h.post("/", in, "application/x-www-form-urlencoded")
+ h.post("/", in, APPLICATION_FORM_URLENCODED)
.run()
.assertBody().is(in);
}
@@ -882,7 +883,7 @@ public class Body_Test {
+ "&f18=(a=a,b=1,c=true)&f18=(a=b,b=2,c=false)"
+ "&f19=@((a=a,b=1,c=true))&f19=@((a=b,b=2,c=false))"
+ "&f20=@((a=a,b=1,c=true))&f20=@((a=b,b=2,c=false))";
- h2.post("/", in, "application/x-www-form-urlencoded")
+ h2.post("/", in, APPLICATION_FORM_URLENCODED)
.run()
.assertBody().is(in);
}
@@ -909,19 +910,19 @@ public class Body_Test {
public void i01_required() throws Exception {
RestClient i = MockRestClient.buildLax(I.class);
- i.post("/a", "", "application/json")
+ i.post("/a", "", APPLICATION_JSON)
.run()
.assertCode().is(400)
.assertBody().contains("Required value not provided.");
- i.post("/a", "{}", "application/json")
+ i.post("/a", "{}", APPLICATION_JSON)
.run()
.assertCode().is(200);
- i.post("/b", "", "application/json")
+ i.post("/b", "", APPLICATION_JSON)
.run()
.assertCode().is(400)
.assertBody().contains("Required value not provided.");
- i.post("/b", "{}", "application/json")
+ i.post("/b", "{}", APPLICATION_JSON)
.run()
.assertCode().is(200);
}
@@ -975,7 +976,7 @@ public class Body_Test {
.assertBody().is("null");
String body1 =
SimpleJson.DEFAULT.toString(AList.of(ABean.get()));
- j.post("/c", body1, "application/json")
+ j.post("/c", body1, APPLICATION_JSON)
.run()
.assertCode().is(200)
.assertBody().is("[{a:1,b:'foo'}]");
@@ -985,7 +986,7 @@ public class Body_Test {
.assertBody().is("null");
String body2 =
SimpleJson.DEFAULT.toString(AList.of(Optional.of(ABean.get())));
- j.post("/d", body2, "application/json")
+ j.post("/d", body2, APPLICATION_JSON)
.run()
.assertCode().is(200)
.assertBody().is("[{a:1,b:'foo'}]");
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_BasicCalls_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_BasicCalls_Test.java
index fee2687..2310ba2 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_BasicCalls_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/rest/client/RestClient_BasicCalls_Test.java
@@ -17,6 +17,7 @@ import static org.junit.runners.MethodSorters.*;
import static org.apache.juneau.http.HttpParts.*;
import static org.apache.juneau.http.HttpEntities.*;
import static org.apache.juneau.http.HttpResources.*;
+import static org.apache.juneau.http.header.ContentType.*;
import java.io.*;
import java.net.*;
@@ -138,7 +139,7 @@ public class RestClient_BasicCalls_Test {
@Test
public void a05_put_bodyString() throws Exception {
-
client().build().put("/bean","{f:1}","application/json").run().assertBody().is("{f:1}");
+
client().build().put("/bean","{f:1}",APPLICATION_JSON).run().assertBody().is("{f:1}");
client().build().put("/bean").bodyString("{f:1}").simpleJson().run().assertBody().is("{f:1}");
client().build().put("/bean").bodyString("").simpleJson().run().assertBody().is("{f:0}");
client().build().put("/bean").bodyString(null).simpleJson().run().assertBody().is("null");
@@ -156,7 +157,7 @@ public class RestClient_BasicCalls_Test {
RestClient x = client().build();
for (Object url : urls) {
x.put(url,bean).run().assertBody().is("{f:1}");
-
x.put(url,"{f:1}","application/json").run().assertBody().is("{f:1}");
+
x.put(url,"{f:1}",APPLICATION_JSON).run().assertBody().is("{f:1}");
x.put(url).body(bean).run().assertBody().is("{f:1}");
}
}
@@ -172,7 +173,7 @@ public class RestClient_BasicCalls_Test {
parts("f",1)
);
for (Object body : bodies) {
- client().contentType(body instanceof PartList ?
"application/x-www-form-urlencoded" :
"application/json").build().put("/bean",body).run().assertBody().is("{f:1}");
+ client().header(body instanceof PartList ?
APPLICATION_FORM_URLENCODED :
APPLICATION_JSON).build().put("/bean",body).run().assertBody().is("{f:1}");
}
}
@@ -184,7 +185,7 @@ public class RestClient_BasicCalls_Test {
@Test
public void a09_post_stringBody() throws Exception {
-
client().build().post("/bean","{f:1}","application/json").run().assertBody().is("{f:1}");
+
client().build().post("/bean","{f:1}",APPLICATION_JSON).run().assertBody().is("{f:1}");
}
@Test
@@ -199,7 +200,7 @@ public class RestClient_BasicCalls_Test {
RestClient x = client().build();
for (Object url : urls) {
x.post(url,bean).run().assertBody().is("{f:1}");
-
x.post(url,"{f:1}","application/json").run().assertBody().is("{f:1}");
+
x.post(url,"{f:1}",APPLICATION_JSON).run().assertBody().is("{f:1}");
x.post(url).body(bean).run().assertBody().is("{f:1}");
}
}
@@ -215,7 +216,7 @@ public class RestClient_BasicCalls_Test {
parts("f",1)
);
for (Object body : bodies) {
- client().contentType(body instanceof PartList ?
"application/x-www-form-urlencoded" :
"application/json").build().post("/bean",body).run().assertBody().is("{f:1}");
+ client().header(body instanceof PartList ?
APPLICATION_FORM_URLENCODED :
APPLICATION_JSON).build().post("/bean",body).run().assertBody().is("{f:1}");
}
}
@@ -317,8 +318,8 @@ public class RestClient_BasicCalls_Test {
/*[ 5]*/ part("f","1"),
/*[ 6]*/ stringResource("f=1").build(),
/*[ 7]*/ stringResource("f=1").build(),
- /*[ 8]*/
stringResource("f=1").contentType("application/x-www-form-urlencoded").build(),
- /*[ 9]*/
stringResource("f=1").contentType("application/x-www-form-urlencoded").build(),
+ /*[ 8]*/
stringResource("f=1").contentType(APPLICATION_FORM_URLENCODED).build(),
+ /*[ 9]*/
stringResource("f=1").contentType(APPLICATION_FORM_URLENCODED).build(),
/*[14]*/ s1,
/*[15]*/ s2
);
@@ -341,7 +342,7 @@ public class RestClient_BasicCalls_Test {
@Test
public void a23_patch_fromString() throws Exception {
-
client().build().patch("/bean","{f:1}","application/json").run().assertBody().is("{f:1}");
+
client().build().patch("/bean","{f:1}",APPLICATION_JSON).run().assertBody().is("{f:1}");
}
@Test
@@ -356,7 +357,7 @@ public class RestClient_BasicCalls_Test {
);
RestClient x = client().build();
for (Object body : bodies) {
- x.patch("/bean",body).contentType(body instanceof
PartList ? "application/x-www-form-urlencoded" :
"application/json").run().assertBody().is("{f:1}");
+ x.patch("/bean",body).header(body instanceof PartList ?
APPLICATION_FORM_URLENCODED : APPLICATION_JSON).run().assertBody().is("{f:1}");
}
}
@@ -393,7 +394,7 @@ public class RestClient_BasicCalls_Test {
);
RestClient x = client().build();
for (Object body : bodies) {
- x.request("patch","/bean",body).contentType(body
instanceof PartList ? "application/x-www-form-urlencoded" :
"application/json").run().assertBody().is("{f:1}");
+ x.request("patch","/bean",body).header(body instanceof
PartList ? APPLICATION_FORM_URLENCODED :
APPLICATION_JSON).run().assertBody().is("{f:1}");
}
}