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 797be14 Better assertion methods in RestClient.
797be14 is described below
commit 797be144549deaf938cc16ab08de7087b0dd3ded
Author: JamesBognar <[email protected]>
AuthorDate: Sun May 24 11:02:02 2020 -0400
Better assertion methods in RestClient.
---
.../apache/juneau/utils/FluentIntAssertion.java | 116 +++++
.../apache/juneau/utils/FluentStringAssertion.java | 267 +++++++++++
.../juneau/rest/test/client/RestClientTest.java | 14 +-
.../apache/juneau/rest/client2/MarshallTest.java | 78 +--
.../apache/juneau/rest/client2/RestClientTest.java | 529 +++++++++++----------
.../org/apache/juneau/rest/client2/RestClient.java | 18 +-
.../apache/juneau/rest/client2/RestResponse.java | 171 ++++++-
.../juneau/rest/client2/RestResponseBody.java | 217 ++-------
.../rest/client2/RestResponseBodyAssertion.java | 84 ++++
.../juneau/rest/client2/RestResponseHeader.java | 150 +-----
.../rest/client2/RestResponseHeaderAssertion.java | 82 ++++
.../client2/RestResponseStatusCodeAssertion.java | 40 ++
12 files changed, 1112 insertions(+), 654 deletions(-)
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/FluentIntAssertion.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/FluentIntAssertion.java
new file mode 100644
index 0000000..92d142d
--- /dev/null
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/FluentIntAssertion.java
@@ -0,0 +1,116 @@
+//
***************************************************************************************************************************
+// * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file *
+// * distributed with this work for additional information regarding copyright
ownership. The ASF licenses this file *
+// * to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance *
+// * with the License. You may obtain a copy of the License at
*
+// *
*
+// * http://www.apache.org/licenses/LICENSE-2.0
*
+// *
*
+// * Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an *
+// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the *
+// * specific language governing permissions and limitations under the
License. *
+//
***************************************************************************************************************************
+package org.apache.juneau.utils;
+
+
+import java.util.function.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.marshall.*;
+
+/**
+ * Used for fluent assertion calls.
+ *
+ * <h5 class='section'>Example:</h5>
+ * <p class='bcode w800'>
+ * <jc>// Validates the response status code is 200 or 404.</jc>
+ * client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ * .assertStatus().isOneOf(200,404);
+ * </p>
+ * @param <R> The return type.
+ */
+public class FluentIntAssertion<R> {
+
+ private final int value;
+ private final R returns;
+
+ /**
+ * Constructor.
+ *
+ * @param value The value being tested.
+ * @param returns The object to return after the test.
+ */
+ public FluentIntAssertion(int value, R returns) {
+ this.value = value;
+ this.returns = returns;
+ }
+
+ /**
+ * Asserts that the value equals the specified value.
+ *
+ * @param value The value to check against.
+ * @return The response object (for method chaining).
+ * @throws AssertionError If assertion failed.
+ */
+ public R equals(int value) throws AssertionError {
+ if (this.value != value)
+ throw new BasicAssertionError("Unexpected
value.\n\tExpected=[{0}]\n\tActual=[{1}]", value, this.value);
+ return returns;
+ }
+
+ /**
+ * Asserts that the value equals the specified value.
+ *
+ * @param value The value to check against.
+ * @return The response object (for method chaining).
+ * @throws AssertionError If assertion failed.
+ */
+ public R notEquals(int value) throws AssertionError {
+ if (this.value == value)
+ throw new BasicAssertionError("Unexpected
value.\n\tExpected not=[{0}]\n\tActual=[{1}]", value, this.value);
+ return returns;
+ }
+
+ /**
+ * Asserts that the value is one of the specified values.
+ *
+ * @param values The values to check against.
+ * @return The response object (for method chaining).
+ * @throws AssertionError If assertion failed.
+ */
+ public R isOneOf(int...values) throws AssertionError {
+ for (int v : values)
+ if (this.value == v)
+ return returns;
+ throw new BasicAssertionError("Expected value not
found.\n\tExpected=[{0}]\n\tActual=[{1}]", SimpleJson.DEFAULT.toString(values),
value);
+ }
+
+ /**
+ * Asserts that the value is one of the specified values.
+ *
+ * @param values The values to check against.
+ * @return The response object (for method chaining).
+ * @throws AssertionError If assertion failed.
+ */
+ public R isNotOneOf(int...values) throws AssertionError {
+ for (int v : values)
+ if (this.value == v)
+ throw new BasicAssertionError("Unexpected value
found.\n\tUnexpected=[{0}]\n\tActual=[{1}]", v, value);
+ return returns;
+ }
+
+ /**
+ * 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).
+ * @throws AssertionError If assertion failed.
+ */
+ public R passes(Predicate<Integer> test) throws AssertionError {
+ if (! test.test(value))
+ throw new BasicAssertionError("Value did not pass
predicate test.\n\tValue=[{0}]", value);
+ return returns;
+ }
+}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/FluentStringAssertion.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/FluentStringAssertion.java
new file mode 100644
index 0000000..1e75a23
--- /dev/null
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/FluentStringAssertion.java
@@ -0,0 +1,267 @@
+//
***************************************************************************************************************************
+// * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file *
+// * distributed with this work for additional information regarding copyright
ownership. The ASF licenses this file *
+// * to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance *
+// * with the License. You may obtain a copy of the License at
*
+// *
*
+// * http://www.apache.org/licenses/LICENSE-2.0
*
+// *
*
+// * Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an *
+// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the *
+// * specific language governing permissions and limitations under the
License. *
+//
***************************************************************************************************************************
+package org.apache.juneau.utils;
+
+
+import java.util.function.*;
+import java.util.regex.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.internal.*;
+
+/**
+ * Used for fluent assertion calls.
+ *
+ * <h5 class='section'>Example:</h5>
+ * <p class='bcode w800'>
+ * <jc>// Validates the response body of an HTTP call is the text
"OK".</jc>
+ * client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ * .assertBody().equals(<js>"OK"</js>);
+ * </p>
+ * @param <R> The return type.
+ */
+public class FluentStringAssertion<R> {
+
+ private final String text;
+ private final R returns;
+
+ /**
+ * Constructor.
+ *
+ * @param text The text being tested.
+ * @param returns The object to return after the test.
+ */
+ public FluentStringAssertion(String text, R returns) {
+ this.text = text;
+ this.returns = returns;
+ }
+
+ /**
+ * Asserts that the text equals the specified value.
+ *
+ * @param value The value to check against.
+ * @return The response object (for method chaining).
+ * @throws AssertionError If assertion failed.
+ */
+ public R equals(String value) throws AssertionError {
+ if (! StringUtils.isEquals(value, text)) {
+ if (value != null && value.startsWith("x")) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Text did not equal expected.");
+ sb.append("\nExpected:
[").append(value.replaceAll("\\\\", "\\\\\\\\").replaceAll("\n",
"\\\\n").replaceAll("\t", "\\\\t")).append("]");
+ sb.append("\nActual :
[").append(text.replaceAll("\\\\", "\\\\\\\\").replaceAll("\n",
"\\\\n").replaceAll("\t", "\\\\t")).append("]");
+ System.err.println(sb.toString());
+ }
+ throw new BasicAssertionError("Text did not equal
expected.\n\tExpected=[{0}]\n\tActual=[{1}]", value, text);
+ }
+ return returns;
+ }
+
+ /**
+ * Asserts that the text equals the specified value.
+ *
+ * @param value The value to check against.
+ * @return The response object (for method chaining).
+ * @throws AssertionError If assertion failed.
+ */
+ public R doesNotEqual(String value) throws AssertionError {
+ if (StringUtils.isEquals(value, text)) {
+ if (value != null && value.startsWith("x")) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Text equaled unexpected.");
+ sb.append("\nText:
[").append(value.replaceAll("\\\\", "\\\\\\\\").replaceAll("\n",
"\\\\n").replaceAll("\t", "\\\\t")).append("]");
+ System.err.println(sb.toString());
+ }
+ throw new BasicAssertionError("Text equaled
unexpected.\n\tText=[{1}]", value, text);
+ }
+ return returns;
+ }
+
+ /**
+ * Asserts that the text contains all of the specified substrings.
+ *
+ * @param values The values to check against.
+ * @return The response object (for method chaining).
+ * @throws AssertionError If assertion failed.
+ */
+ public R contains(String...values) throws AssertionError {
+ for (String substring : values)
+ if (! StringUtils.contains(text, substring)) {
+ if (substring.startsWith("x")) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Text did not contain
expected substring.");
+ sb.append("\nSubstring:
[").append(substring.replaceAll("\\\\", "\\\\\\\\").replaceAll("\n",
"\\\\n").replaceAll("\t", "\\\\t")).append("]");
+ sb.append("\nText :
[").append(text.replaceAll("\\\\", "\\\\\\\\").replaceAll("\n",
"\\\\n").replaceAll("\t", "\\\\t")).append("]");
+ System.err.println(sb.toString());
+ }
+ throw new BasicAssertionError("Text did not
contain expected substring.\n\tExpected=[{0}]\n\tActual=[{1}]", substring,
text);
+ }
+ return returns;
+ }
+
+ /**
+ * Asserts that the text doesn't contain any of the specified
substrings.
+ *
+ * @param values The values to check against.
+ * @return The response object (for method chaining).
+ * @throws AssertionError If assertion failed.
+ */
+ public R doesNotContain(String...values) throws AssertionError {
+ for (String substring : values)
+ if (StringUtils.contains(text, substring)) {
+ if (substring.startsWith("x")) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Text contained unexpected
substring.");
+ sb.append("\nSubstring:
[").append(substring.replaceAll("\\\\", "\\\\\\\\").replaceAll("\n",
"\\\\n").replaceAll("\t", "\\\\t")).append("]");
+ sb.append("\nText :
[").append(text.replaceAll("\\\\", "\\\\\\\\").replaceAll("\n",
"\\\\n").replaceAll("\t", "\\\\t")).append("]");
+ System.err.println(sb.toString());
+ }
+ throw new BasicAssertionError("Text contained
unexpected substring.\n\tExpected=[{0}]\n\tActual=[{1}]", substring, text);
+ }
+ return returns;
+ }
+
+ /**
+ * Asserts that the text is not null.
+ *
+ * <p>
+ * Equivalent to {@link #isNotEmpty()}.
+ *
+ * @return The response object (for method chaining).
+ * @throws AssertionError If assertion failed.
+ */
+ public R exists() throws AssertionError {
+ if (text == null)
+ throw new BasicAssertionError("Text was null.");
+ return returns;
+ }
+
+ /**
+ * Asserts that the text is not null.
+ *
+ * @return The response object (for method chaining).
+ * @throws AssertionError If assertion failed.
+ */
+ public R isNotNull() throws AssertionError {
+ if (text == null)
+ throw new BasicAssertionError("Text was null.");
+ return returns;
+ }
+
+ /**
+ * Asserts that the text is not null or empty.
+ *
+ * @return The response object (for method chaining).
+ * @throws AssertionError If assertion failed.
+ */
+ public R isNotEmpty() throws AssertionError {
+ if (text == null)
+ throw new BasicAssertionError("Text was null.");
+ if (text.isEmpty())
+ throw new BasicAssertionError("Text was emtpy.");
+ return returns;
+ }
+
+ /**
+ * Asserts that the text passes the specified predicate test.
+ *
+ * @param test The predicate to use to test the value.
+ * @return The response object (for method chaining).
+ * @throws AssertionError If assertion failed.
+ */
+ public R passes(Predicate<String> test) throws AssertionError {
+ if (! test.test(text))
+ throw new BasicAssertionError("Text did not pass
predicate test.\n\tText=[{0}]", text);
+ return returns;
+ }
+
+ /**
+ * Asserts that the text matches the specified regular expression.
+ *
+ * @param regex The pattern to test for.
+ * @return The response object (for method chaining).
+ * @throws AssertionError If assertion failed.
+ */
+ public R matches(String regex) throws AssertionError {
+ return matches(regex, 0);
+ }
+
+ /**
+ * Asserts that the text doesn't match the specified regular expression.
+ *
+ * @param regex The pattern to test for.
+ * @return The response object (for method chaining).
+ * @throws AssertionError If assertion failed.
+ */
+ public R doesNotMatch(String regex) throws AssertionError {
+ return doesNotMatch(regex, 0);
+ }
+
+ /**
+ * Asserts that the text matches the specified regular expression.
+ *
+ * @param regex The pattern to test for.
+ * @param flags Pattern match flags. See {@link
Pattern#compile(String, int)}.
+ * @return The response object (for method chaining).
+ * @throws AssertionError If assertion failed.
+ */
+ public R matches(String regex, int flags) throws AssertionError {
+ Pattern p = Pattern.compile(regex, flags);
+ if (! p.matcher(text).matches())
+ throw new BasicAssertionError("Text did not match
expected pattern.\n\tPattern=[{0}]\n\tText=[{1}]", regex, text);
+ return returns;
+ }
+
+ /**
+ * Asserts that the text doesn't match the specified regular expression.
+ *
+ * @param regex The pattern to test for.
+ * @param flags Pattern match flags. See {@link
Pattern#compile(String, int)}.
+ * @return The response object (for method chaining).
+ * @throws AssertionError If assertion failed.
+ */
+ public R doesNotMatch(String regex, int flags) throws AssertionError {
+ Pattern p = Pattern.compile(regex, flags);
+ if (p.matcher(text).matches())
+ throw new BasicAssertionError("Text matched unexpected
pattern.\n\tPattern=[{0}]\n\tText=[{1}]", regex, text);
+ return returns;
+ }
+
+ /**
+ * Asserts that the text matches the specified regular expression
pattern.
+ *
+ * @param pattern The pattern to test for.
+ * @return The response object (for method chaining).
+ * @throws AssertionError If assertion failed.
+ */
+ public R matches(Pattern pattern) throws AssertionError {
+ if (! pattern.matcher(text).matches())
+ throw new BasicAssertionError("Text did not match
expected pattern.\n\tPattern=[{0}]\n\tText=[{1}]", pattern.pattern(), text);
+ return returns;
+ }
+
+ /**
+ * Asserts that the text doesn't match the specified regular expression
pattern.
+ *
+ * @param pattern The pattern to test for.
+ * @return The response object (for method chaining).
+ * @throws AssertionError If assertion failed.
+ */
+ public R doesNotMatch(Pattern pattern) throws AssertionError {
+ if (pattern.matcher(text).matches())
+ throw new BasicAssertionError("Text matched unexpected
pattern.\n\tPattern=[{0}]\n\tText=[{1}]", pattern.pattern(), text);
+ return returns;
+ }
+}
diff --git
a/juneau-microservice/juneau-microservice-ftest/src/test/java/org/apache/juneau/rest/test/client/RestClientTest.java
b/juneau-microservice/juneau-microservice-ftest/src/test/java/org/apache/juneau/rest/test/client/RestClientTest.java
index 1e8cdbe..873cfad 100644
---
a/juneau-microservice/juneau-microservice-ftest/src/test/java/org/apache/juneau/rest/test/client/RestClientTest.java
+++
b/juneau-microservice/juneau-microservice-ftest/src/test/java/org/apache/juneau/rest/test/client/RestClientTest.java
@@ -40,7 +40,7 @@ public class RestClientTest extends RestTestcase {
.run()
.getStatusCode(rc)
.cacheBody()
- .getBody().assertContains("SUCCESS")
+ .assertBody().contains("SUCCESS")
.getBody().asString(r);
assertEquals("xxxSUCCESSxxx", r.get());
assertEquals(200, rc.get().intValue());
@@ -48,11 +48,10 @@ public class RestClientTest extends RestTestcase {
try {
c.post(URL, new StringEntity("xxxFAILURExxx"))
.run()
- .getBody()
- .assertContains("SUCCESS");
+ .assertBody().contains("SUCCESS");
fail();
} catch (AssertionError e) {
- assertTrue(e.getLocalizedMessage().contains("Response
did not have the expected substring for body."));
+ // OK
}
}
@@ -69,7 +68,7 @@ public class RestClientTest extends RestTestcase {
.run()
.getStatusCode(rc)
.cacheBody()
- .getBody().assertValue(x -> ! x.contains("FAILURE"))
+ .assertBody().passes(x -> ! x.contains("FAILURE"))
.getBody().asString(r);
assertEquals("xxxSUCCESSxxx", r.get());
assertEquals(200, rc.get().intValue());
@@ -77,11 +76,10 @@ public class RestClientTest extends RestTestcase {
try {
c.post(URL, new StringEntity("xxxFAILURExxx"))
.run()
- .getBody()
- .assertValue(x -> ! x.contains("FAILURE"));
+ .assertBody().passes(x -> !
x.contains("FAILURE"));
fail();
} catch (AssertionError e) {
- assertTrue(e.getLocalizedMessage().contains("Response
did not have the expected value for body."));
+ // OK
}
}
diff --git
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/MarshallTest.java
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/MarshallTest.java
index 4ff3856..2eeeb86 100644
---
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/MarshallTest.java
+++
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/MarshallTest.java
@@ -85,55 +85,55 @@ public class MarshallTest {
.header("X-Accept", "application/json+simple")
.header("X-Content-Type", "application/json+simple")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
a1b.post("/a01", bean)
.header("X-Accept", "application/json")
.header("X-Content-Type", "application/json")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
a1c.post("/a01", bean)
.header("X-Accept", "text/xml")
.header("X-Content-Type", "text/xml")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
a1d.post("/a01", bean)
.header("X-Accept", "text/html")
.header("X-Content-Type", "text/html")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
a1e.post("/a01", bean)
.header("X-Accept", "text/plain")
.header("X-Content-Type", "text/plain")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
a1f.post("/a01", bean)
.header("X-Accept", "octal/msgpack")
.header("X-Content-Type", "octal/msgpack")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
a1g.post("/a01", bean)
.header("X-Accept", "text/uon")
.header("X-Content-Type", "text/uon")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
a1h.post("/a01", bean)
.header("X-Accept", "application/x-www-form-urlencoded")
.header("X-Content-Type",
"application/x-www-form-urlencoded")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
a1i.post("/a01", bean)
.header("X-Accept", "text/openapi")
.header("X-Content-Type", "text/openapi")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
}
@@ -145,7 +145,7 @@ public class MarshallTest {
.header("X-Accept", "application/json")
.header("X-Content-Type", "application/json")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
}
@@ -160,8 +160,8 @@ public class MarshallTest {
.header("X-Content-Type", "application/json")
.body("{f:1}")
.run()
- .assertStatusCode(200)
- .getBody().assertValue("{\"f\":1}");
+ .assertStatusCode().equals(200)
+ .assertBody().equals("{\"f\":1}");
}
//------------------------------------------------------------------------------------------------------------------
@@ -189,7 +189,7 @@ public class MarshallTest {
.header("X-Accept", "application/json")
.header("X-Content-Type", "application/json")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
b1.post("/a01", bean)
.header("Accept", "text/xml")
@@ -197,7 +197,7 @@ public class MarshallTest {
.header("X-Accept", "text/xml")
.header("X-Content-Type", "text/xml")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
b1.post("/a01", bean)
.header("Accept", "text/html")
@@ -205,7 +205,7 @@ public class MarshallTest {
.header("X-Accept", "text/html")
.header("X-Content-Type", "text/html")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
b1.post("/a01", bean)
.header("Accept", "text/plain")
@@ -213,7 +213,7 @@ public class MarshallTest {
.header("X-Accept", "text/plain")
.header("X-Content-Type", "text/plain")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
b1.post("/a01", bean)
.header("Accept", "octal/msgpack")
@@ -221,7 +221,7 @@ public class MarshallTest {
.header("X-Accept", "octal/msgpack")
.header("X-Content-Type", "octal/msgpack")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
b1.post("/a01", bean)
.header("Accept", "text/uon")
@@ -229,7 +229,7 @@ public class MarshallTest {
.header("X-Accept", "text/uon")
.header("X-Content-Type", "text/uon")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
b1.post("/a01", bean)
.header("Accept", "application/x-www-form-urlencoded")
@@ -237,7 +237,7 @@ public class MarshallTest {
.header("X-Accept", "application/x-www-form-urlencoded")
.header("X-Content-Type",
"application/x-www-form-urlencoded")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
b1.post("/a01", bean)
.header("Accept", "text/openapi")
@@ -245,7 +245,7 @@ public class MarshallTest {
.header("X-Accept", "text/openapi")
.header("X-Content-Type", "text/openapi")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
}
@@ -256,7 +256,7 @@ public class MarshallTest {
.header("X-Accept", "nil")
.header("X-Content-Type", "text/plain")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
}
@@ -277,7 +277,7 @@ public class MarshallTest {
.header("X-Accept", "application/json")
.header("X-Content-Type", "application/json")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
c1.post("/a01", bean)
.header("Accept", "text/xml")
@@ -285,7 +285,7 @@ public class MarshallTest {
.header("X-Accept", "text/xml")
.header("X-Content-Type", "text/xml")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
c1.post("/a01", bean)
.header("Accept", "text/html")
@@ -293,7 +293,7 @@ public class MarshallTest {
.header("X-Accept", "text/html")
.header("X-Content-Type", "text/html")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
c1.post("/a01", bean)
.header("Accept", "text/plain")
@@ -301,7 +301,7 @@ public class MarshallTest {
.header("X-Accept", "text/plain")
.header("X-Content-Type", "text/plain")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
c1.post("/a01", bean)
.header("Accept", "octal/msgpack")
@@ -309,7 +309,7 @@ public class MarshallTest {
.header("X-Accept", "octal/msgpack")
.header("X-Content-Type", "octal/msgpack")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
c1.post("/a01", bean)
.header("Accept", "text/uon")
@@ -317,7 +317,7 @@ public class MarshallTest {
.header("X-Accept", "text/uon")
.header("X-Content-Type", "text/uon")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
c1.post("/a01", bean)
.header("Accept", "application/x-www-form-urlencoded")
@@ -325,7 +325,7 @@ public class MarshallTest {
.header("X-Accept", "application/x-www-form-urlencoded")
.header("X-Content-Type",
"application/x-www-form-urlencoded")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
c1.post("/a01", bean)
.header("Accept", "text/openapi")
@@ -333,7 +333,7 @@ public class MarshallTest {
.header("X-Accept", "text/openapi")
.header("X-Content-Type", "text/openapi")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
}
@@ -343,7 +343,7 @@ public class MarshallTest {
.header("X-Accept", "nil")
.header("X-Content-Type", "text/plain")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
}
@@ -366,7 +366,7 @@ public class MarshallTest {
.header("X-Accept", "application/json")
.header("X-Content-Type", "application/json")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
d1.post("/a01", bean)
.header("Accept", "text/xml")
@@ -374,7 +374,7 @@ public class MarshallTest {
.header("X-Accept", "text/xml")
.header("X-Content-Type", "text/xml")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
d1.post("/a01", bean)
.header("Accept", "text/html")
@@ -382,7 +382,7 @@ public class MarshallTest {
.header("X-Accept", "text/html")
.header("X-Content-Type", "text/html")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
d1.post("/a01", bean)
.header("Accept", "text/plain")
@@ -390,7 +390,7 @@ public class MarshallTest {
.header("X-Accept", "text/plain")
.header("X-Content-Type", "text/plain")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
d1.post("/a01", bean)
.header("Accept", "octal/msgpack")
@@ -398,7 +398,7 @@ public class MarshallTest {
.header("X-Accept", "octal/msgpack")
.header("X-Content-Type", "octal/msgpack")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
d1.post("/a01", bean)
.header("Accept", "text/uon")
@@ -406,7 +406,7 @@ public class MarshallTest {
.header("X-Accept", "text/uon")
.header("X-Content-Type", "text/uon")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
d1.post("/a01", bean)
.header("Accept", "application/x-www-form-urlencoded")
@@ -414,7 +414,7 @@ public class MarshallTest {
.header("X-Accept", "application/x-www-form-urlencoded")
.header("X-Content-Type",
"application/x-www-form-urlencoded")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
d1.post("/a01", bean)
.header("Accept", "text/openapi")
@@ -422,7 +422,7 @@ public class MarshallTest {
.header("X-Accept", "text/openapi")
.header("X-Content-Type", "text/openapi")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
}
@@ -432,7 +432,7 @@ public class MarshallTest {
.header("X-Accept", "application/json")
.header("X-Content-Type", "application/json")
.run()
- .assertStatusCode(200)
+ .assertStatusCode().equals(200)
.getBody().as(Bean.class).check();
}
}
\ No newline at end of file
diff --git
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClientTest.java
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClientTest.java
index 8790db5..5951ecc 100644
---
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClientTest.java
+++
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClientTest.java
@@ -215,9 +215,9 @@ public class RestClientTest {
.build()
.get("/echo")
.run()
- .getBody().assertContains("A1: 1", "A2: 2")
- .getHeader("B1").assertValue("1")
- .getHeader("B2").assertValue("2")
+ .assertBody().contains("A1: 1", "A2: 2")
+ .assertHeader("B1").equals("1")
+ .assertHeader("B2").equals("2")
;
}
@@ -240,8 +240,8 @@ public class RestClientTest {
.build()
.get("/echo")
.run()
- .getBody().assertContains("A1: 1")
- .getHeader("B1").assertValue("1");
+ .assertBody().contains("A1: 1")
+ .assertHeader("B1").equals("1");
}
@Test
@@ -260,7 +260,7 @@ public class RestClientTest {
.build()
.get("/echo")
.run()
- .getBody().assertContains("HTTP GET /echo");
+ .assertBody().contains("HTTP GET /echo");
assertTrue(b1.get());
}
@@ -273,7 +273,7 @@ public class RestClientTest {
.build()
.get("/echo")
.run()
- .getBody().assertContains("HTTP GET /echo","Foo: bar");
+ .assertBody().contains("HTTP GET /echo","Foo: bar");
}
@Test
@@ -334,7 +334,7 @@ public class RestClientTest {
.build()
.get("/echo")
.run()
- .getBody().assertContains("HTTP GET /echo");
+ .assertBody().contains("HTTP GET /echo");
}
//------------------------------------------------------------------------------------------------------------------
@@ -365,7 +365,7 @@ public class RestClientTest {
.build()
.get("/echo")
.run()
- .getBody().assertContains("OK");
+ .assertBody().contains("OK");
}
//------------------------------------------------------------------------------------------------------------------
@@ -383,7 +383,7 @@ public class RestClientTest {
.get("/checkHeader")
.header("Foo","baz")
.run()
- .getBody().assertValue("['bar','baz']");
+ .assertBody().equals("['bar','baz']");
}
@Test
@@ -397,7 +397,7 @@ public class RestClientTest {
.get("/checkHeader")
.header("Foo", bean)
.run()
- .getBody().assertValue("['f=1','f=1']");
+ .assertBody().equals("['f=1','f=1']");
}
@Test
@@ -411,7 +411,7 @@ public class RestClientTest {
.get("/checkHeader")
.header("Foo", null)
.run()
- .getBody().assertValue("null");
+ .assertBody().equals("null");
}
@Test
@@ -425,7 +425,7 @@ public class RestClientTest {
.get("/checkHeader")
.header(new org.apache.http.message.BasicHeader("Foo",
"baz"))
.run()
- .getBody().assertValue("['bar','baz']");
+ .assertBody().equals("['bar','baz']");
}
@Test
@@ -439,7 +439,7 @@ public class RestClientTest {
.get("/checkHeader")
.header(new BasicNameValuePair("Foo", "baz"))
.run()
- .getBody().assertValue("['bar','baz']");
+ .assertBody().equals("['bar','baz']");
}
@Test
@@ -453,7 +453,7 @@ public class RestClientTest {
.get("/checkHeader")
.header(new BasicObjectHeader("Foo", "baz"))
.run()
- .getBody().assertValue("['bar','baz']");
+ .assertBody().equals("['bar','baz']");
}
@Test
@@ -467,7 +467,7 @@ public class RestClientTest {
.get("/checkHeader")
.headers(new org.apache.http.message.BasicHeader("Foo",
"baz"),new org.apache.http.message.BasicHeader("Baz", "quux"))
.run()
- .getBody().assertValue("['bar','baz']");
+ .assertBody().equals("['bar','baz']");
}
@Test
@@ -481,7 +481,7 @@ public class RestClientTest {
.get("/checkHeader")
.headers(OMap.of("Foo", "baz"))
.run()
- .getBody().assertValue("['bar','baz']");
+ .assertBody().equals("['bar','baz']");
}
@Test
@@ -495,7 +495,7 @@ public class RestClientTest {
.get("/checkHeader")
.headers(AMap.of("Foo", "baz"))
.run()
- .getBody().assertValue("['bar','baz']");
+ .assertBody().equals("['bar','baz']");
}
@Test
@@ -509,7 +509,7 @@ public class RestClientTest {
.get("/checkHeader")
.headers(NameValuePairs.of("Foo","baz"))
.run()
- .getBody().assertValue("['bar','baz']");
+ .assertBody().equals("['bar','baz']");
}
@Test
@@ -523,7 +523,7 @@ public class RestClientTest {
.get("/checkHeader")
.headers(new BasicNameValuePair("Foo","baz"))
.run()
- .getBody().assertValue("['bar','baz']");
+ .assertBody().equals("['bar','baz']");
}
@Test
@@ -537,7 +537,7 @@ public class RestClientTest {
.get("/checkHeader")
.headerPairs("Foo", "baz")
.run()
- .getBody().assertValue("['bar','baz']");
+ .assertBody().equals("['bar','baz']");
}
@Test
@@ -551,7 +551,7 @@ public class RestClientTest {
.get("/checkHeader")
.headers(new BasicObjectHeader("Foo", "baz"))
.run()
- .getBody().assertValue("['bar','baz']");
+ .assertBody().equals("['bar','baz']");
}
@Test
@@ -565,7 +565,7 @@ public class RestClientTest {
.get("/checkHeader")
.accept("text/plain")
.run()
- .getBody().assertValue("['text/foo','text/plain']");
+ .assertBody().equals("['text/foo','text/plain']");
}
@Test
@@ -578,7 +578,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['UTF-8']");
+ .assertBody().equals("['UTF-8']");
}
@Test
@@ -591,7 +591,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['identity']");
+ .assertBody().equals("['identity']");
}
@Test
@@ -604,7 +604,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['en']");
+ .assertBody().equals("['en']");
}
@Test
@@ -617,7 +617,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -630,7 +630,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['none']");
+ .assertBody().equals("['none']");
}
@Test
@@ -643,7 +643,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['1']");
+ .assertBody().equals("['1']");
}
@Test
@@ -656,7 +656,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -669,7 +669,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['123']");
+ .assertBody().equals("['123']");
}
@Test
@@ -682,7 +682,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -695,7 +695,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['123']");
+ .assertBody().equals("['123']");
}
@Test
@@ -708,7 +708,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -721,7 +721,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -734,7 +734,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -747,7 +747,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -760,7 +760,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -773,7 +773,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -786,7 +786,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -799,7 +799,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -812,7 +812,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -825,7 +825,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['10']");
+ .assertBody().equals("['10']");
}
@Test
@@ -838,7 +838,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['true']");
+ .assertBody().equals("['true']");
}
@Test
@@ -851,7 +851,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -864,7 +864,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -877,7 +877,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -890,7 +890,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -903,7 +903,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -916,7 +916,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -929,7 +929,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -942,7 +942,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -955,7 +955,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -968,7 +968,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
//------------------------------------------------------------------------------------------------------------------
@@ -986,7 +986,7 @@ public class RestClientTest {
.get("/checkHeader")
.header(new Accept("text/plain"))
.run()
- .getBody().assertValue("['text/foo','text/plain']");
+ .assertBody().equals("['text/foo','text/plain']");
}
@Test
@@ -999,7 +999,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['UTF-8']");
+ .assertBody().equals("['UTF-8']");
}
@Test
@@ -1012,7 +1012,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['identity']");
+ .assertBody().equals("['identity']");
}
@Test
@@ -1025,7 +1025,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['en']");
+ .assertBody().equals("['en']");
}
@Test
@@ -1038,7 +1038,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -1052,7 +1052,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['none']");
+ .assertBody().equals("['none']");
}
@Test
@@ -1065,7 +1065,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['1']");
+ .assertBody().equals("['1']");
}
@Test
@@ -1078,7 +1078,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -1091,7 +1091,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['123']");
+ .assertBody().equals("['123']");
}
@Test
@@ -1104,7 +1104,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -1117,7 +1117,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['Sun, 31 Dec 2000 12:34:56
GMT']");
+ .assertBody().equals("['Sun, 31 Dec 2000 12:34:56
GMT']");
}
@Test
@@ -1130,7 +1130,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['Sun, 31 Dec 2000 12:34:56
GMT']");
+ .assertBody().equals("['Sun, 31 Dec 2000 12:34:56
GMT']");
}
@Test
@@ -1143,7 +1143,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -1156,7 +1156,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -1169,7 +1169,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -1182,7 +1182,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -1195,7 +1195,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['\"foo\"']");
+ .assertBody().equals("['\"foo\"']");
}
@Test
@@ -1208,7 +1208,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['Sun, 31 Dec 2000 12:34:56
GMT']");
+ .assertBody().equals("['Sun, 31 Dec 2000 12:34:56
GMT']");
}
@Test
@@ -1221,7 +1221,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['Sun, 31 Dec 2000 12:34:56
GMT']");
+ .assertBody().equals("['Sun, 31 Dec 2000 12:34:56
GMT']");
}
@Test
@@ -1234,7 +1234,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['\"foo\"']");
+ .assertBody().equals("['\"foo\"']");
}
@Test
@@ -1247,7 +1247,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -1260,7 +1260,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['Sun, 31 Dec 2000 12:34:56
GMT']");
+ .assertBody().equals("['Sun, 31 Dec 2000 12:34:56
GMT']");
}
@Test
@@ -1273,7 +1273,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['Sun, 31 Dec 2000 12:34:56
GMT']");
+ .assertBody().equals("['Sun, 31 Dec 2000 12:34:56
GMT']");
}
@Test
@@ -1286,7 +1286,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['10']");
+ .assertBody().equals("['10']");
}
@Test
@@ -1299,7 +1299,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['true']");
+ .assertBody().equals("['true']");
}
@Test
@@ -1312,7 +1312,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -1325,7 +1325,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -1338,7 +1338,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -1351,7 +1351,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -1364,7 +1364,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -1377,7 +1377,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -1390,7 +1390,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -1403,7 +1403,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -1416,7 +1416,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
@Test
@@ -1429,7 +1429,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['foo']");
+ .assertBody().equals("['foo']");
}
//------------------------------------------------------------------------------------------------------------------
@@ -1448,7 +1448,7 @@ public class RestClientTest {
.get("/checkHeader")
.headerPairs("Foo","q1x","Foo","q2x")
.run()
-
.getBody().assertValue("['bar','baz','qux','q1x','q2x']");
+ .assertBody().equals("['bar','baz','qux','q1x','q2x']");
}
@Test
@@ -1462,7 +1462,7 @@ public class RestClientTest {
.get("/checkHeader")
.header("Foo","qux")
.run()
- .getBody().assertValue("['bar','baz','qux']");
+ .assertBody().equals("['bar','baz','qux']");
}
@Test
@@ -1475,7 +1475,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['text/plain']");
+ .assertBody().equals("['text/plain']");
}
@Test
@@ -1489,7 +1489,7 @@ public class RestClientTest {
.get("/checkHeader")
.header("Accept","text/plain")
.run()
- .getBody().assertValue("['text/foo','text/plain']");
+ .assertBody().equals("['text/foo','text/plain']");
}
@Test
@@ -1504,7 +1504,7 @@ public class RestClientTest {
req.setHeader("Accept","text/plain");
req
.run()
- .getBody().assertValue("['text/plain']");
+ .assertBody().equals("['text/plain']");
}
@Test
@@ -1517,7 +1517,7 @@ public class RestClientTest {
.build()
.get("/checkHeader")
.run()
- .getBody().assertValue("['text/plain']");
+ .assertBody().equals("['text/plain']");
}
@Test
@@ -1531,7 +1531,7 @@ public class RestClientTest {
.get("/checkHeader")
.header("Content-Type", "text/plain")
.run()
- .getBody().assertValue("['text/foo','text/plain']");
+ .assertBody().equals("['text/foo','text/plain']");
}
@Test
@@ -1545,7 +1545,7 @@ public class RestClientTest {
.get("/checkHeader")
.header(AddFlag.DEFAULT_FLAGS,"Foo",bean,new
XPartSerializer().createPartSession(null),null)
.run()
- .getBody().assertValue("['x{f:1}','x{f:1}']");
+ .assertBody().equals("['x{f:1}','x{f:1}']");
}
//-----------------------------------------------------------------------------------------------------------------
@@ -1562,7 +1562,7 @@ public class RestClientTest {
.build()
.get("/checkQuery")
.run()
- .getBody().assertValue("Foo=bar&Foo=baz");
+ .assertBody().equals("Foo=bar&Foo=baz");
}
@Test
@@ -1578,7 +1578,7 @@ public class RestClientTest {
.build()
.get("/checkQuery")
.run()
-
.getBody().assertValue("Foo=f1&Foo=f2&Foo=f3&Foo=f4&Foo=f5&Foo=f6&Foo=f7");
+
.assertBody().equals("Foo=f1&Foo=f2&Foo=f3&Foo=f4&Foo=f5&Foo=f6&Foo=f7");
}
//-----------------------------------------------------------------------------------------------------------------
@@ -1594,7 +1594,7 @@ public class RestClientTest {
.build()
.post("/checkFormData")
.run()
- .getBody().assertValue("Foo=bar&Foo=baz");
+ .assertBody().equals("Foo=bar&Foo=baz");
}
@Test
@@ -1610,7 +1610,7 @@ public class RestClientTest {
.build()
.post("/checkFormData")
.run()
-
.getBody().assertValue("Foo=f1&Foo=f2&Foo=f3&Foo=f4&Foo=f5&Foo=f6&Foo=f7");
+
.assertBody().equals("Foo=f1&Foo=f2&Foo=f3&Foo=f4&Foo=f5&Foo=f6&Foo=f7");
}
//-----------------------------------------------------------------------------------------------------------------
@@ -1648,7 +1648,7 @@ public class RestClientTest {
.get("/checkHeader")
.header("Foo","f2")
.run()
- .getBody().assertValue("['f1','f2','baz']");
+ .assertBody().equals("['f1','f2','baz']");
}
@Test
@@ -1680,8 +1680,8 @@ public class RestClientTest {
.get("/echo")
.runFuture()
.get()
- .assertStatusCode(200)
- .getBody().assertContains("HTTP GET /echo");
+ .assertStatusCode().equals(200)
+ .assertBody().contains("HTTP GET /echo");
}
@Test
@@ -1701,7 +1701,7 @@ public class RestClientTest {
.get("/ok")
.runFuture()
.get()
- .getBody().assertContains("OK");
+ .assertBody().contains("OK");
}
@Test
@@ -1721,7 +1721,7 @@ public class RestClientTest {
.get("/ok")
.runFuture()
.get()
- .getBody().assertContains("OK");
+ .assertBody().contains("OK");
}
public static class XRestCallInterceptor extends
BasicRestCallInterceptor {
@@ -1757,8 +1757,8 @@ public class RestClientTest {
.header("Check","foo")
.header("Foo","f3")
.run()
- .getBody().assertValue("['f1','f2','f3']")
- .getHeader("Bar").assertValue("b1");
+ .assertBody().equals("['f1','f2','f3']")
+ .assertHeader("Bar").equals("b1");
assertEquals(111, XRestCallInterceptor.x);
}
@@ -1774,8 +1774,8 @@ public class RestClientTest {
.header("Check","foo")
.header("Foo","f3")
.run()
- .getBody().assertValue("['f1','f2','f3']")
- .getHeader("Bar").assertValue("b1");
+ .assertBody().equals("['f1','f2','f3']")
+ .assertHeader("Bar").equals("b1");
assertEquals(111, XRestCallInterceptor.x);
}
@@ -1836,7 +1836,7 @@ public class RestClientTest {
.post("/echoBody", bean)
.run()
.cacheBody()
- .getBody().assertValue("<object><f>1</f></object>")
+ .assertBody().equals("<object><f>1</f></object>")
.getBody().as(Bean.class);
assertEqualObjects(b, bean);
@@ -1852,7 +1852,7 @@ public class RestClientTest {
rc
.post("/echoBody", bean)
.run()
- .getBody().assertValue("{f:1}");
+ .assertBody().equals("{f:1}");
Bean b = rc
.post("/echoBody", bean)
@@ -1860,7 +1860,7 @@ public class RestClientTest {
.contentType("text/xml")
.run()
.cacheBody()
- .getBody().assertValue("<object><f>1</f></object>")
+ .assertBody().equals("<object><f>1</f></object>")
.getBody().as(Bean.class);
assertEqualObjects(b, bean);
@@ -1870,7 +1870,7 @@ public class RestClientTest {
.contentType("text/json")
.run()
.cacheBody()
- .getBody().assertValue("{\"f\":1}")
+ .assertBody().equals("{\"f\":1}")
.getBody().as(Bean.class);
assertEqualObjects(b, bean);
}
@@ -1887,7 +1887,7 @@ public class RestClientTest {
.post("/echoBody", bean)
.run()
.cacheBody()
- .getBody().assertValue("<object><f>1</f></object>")
+ .assertBody().equals("<object><f>1</f></object>")
.getBody().as(Bean.class);
assertEqualObjects(b, bean);
@@ -1905,7 +1905,7 @@ public class RestClientTest {
.post("/echoBody", bean)
.run()
.cacheBody()
- .getBody().assertValue("<object><f>1</f></object>")
+ .assertBody().equals("<object><f>1</f></object>")
.getBody().as(Bean.class);
assertEqualObjects(b, bean);
@@ -1923,7 +1923,7 @@ public class RestClientTest {
rc
.post("/echoBody", bean)
.run()
- .getBody().assertValue("{f:1}");
+ .assertBody().equals("{f:1}");
Bean b = rc
.post("/echoBody", bean)
@@ -1931,7 +1931,7 @@ public class RestClientTest {
.contentType("text/xml")
.run()
.cacheBody()
- .getBody().assertValue("<object><f>1</f></object>")
+ .assertBody().equals("<object><f>1</f></object>")
.getBody().as(Bean.class);
assertEqualObjects(b, bean);
@@ -1941,7 +1941,7 @@ public class RestClientTest {
.contentType("text/json")
.run()
.cacheBody()
- .getBody().assertValue("{\"f\":1}")
+ .assertBody().equals("{\"f\":1}")
.getBody().as(Bean.class);
assertEqualObjects(b, bean);
}
@@ -1957,7 +1957,7 @@ public class RestClientTest {
rc
.post("/echoBody", bean)
.run()
- .getBody().assertValue("{f:1}");
+ .assertBody().equals("{f:1}");
Bean b = rc
.post("/echoBody", bean)
@@ -1965,7 +1965,7 @@ public class RestClientTest {
.contentType("text/xml")
.run()
.cacheBody()
- .getBody().assertValue("<object><f>1</f></object>")
+ .assertBody().equals("<object><f>1</f></object>")
.getBody().as(Bean.class);
assertEqualObjects(b, bean);
@@ -1975,7 +1975,7 @@ public class RestClientTest {
.contentType("text/json")
.run()
.cacheBody()
- .getBody().assertValue("{\"f\":1}")
+ .assertBody().equals("{\"f\":1}")
.getBody().as(Bean.class);
assertEqualObjects(b, bean);
}
@@ -2035,7 +2035,7 @@ public class RestClientTest {
.get("/")
.header("Foo",bean)
.run()
- .getHeader("Foo").assertValue("x{f:1}")
+ .assertHeader("Foo").equals("x{f:1}")
.getHeader("Foo").as(Bean.class);
assertEquals("{f:1}", b.toString());
}
@@ -2054,7 +2054,7 @@ public class RestClientTest {
.get("/")
.header("Foo",bean)
.run()
- .getHeader("Foo").assertValue("x{f:1}")
+ .assertHeader("Foo").equals("x{f:1}")
.getHeader("Foo").as(Bean.class);
assertEquals("{f:1}", b.toString());
}
@@ -2093,7 +2093,7 @@ public class RestClientTest {
.build()
.post("/echoBody", l1)
.run()
- .getBody().assertValue("{f1:{_type:'L',f2:1}}");
+ .assertBody().equals("{f1:{_type:'L',f2:1}}");
}
@Test
@@ -2108,7 +2108,7 @@ public class RestClientTest {
.build()
.post("/echoBody", l2)
.run()
- .getBody().assertValue("{_type:'L',f2:1}");
+ .assertBody().equals("{_type:'L',f2:1}");
}
@Test
@@ -2141,7 +2141,7 @@ public class RestClientTest {
.build()
.post("/echoBody", l1)
.run()
- .getBody().assertValue("{}");
+ .assertBody().equals("{}");
}
@Test
@@ -2154,7 +2154,7 @@ public class RestClientTest {
.build()
.post("/echoBody", bean)
.run()
- .getBody().assertValue("\t\t{\n\t\t\tf: 1\n\t\t}");
+ .assertBody().equals("\t\t{\n\t\t\tf: 1\n\t\t}");
}
public static class L10 extends SerializerListener {
@@ -2186,7 +2186,7 @@ public class RestClientTest {
.build()
.post("/echoBody", new L11().init())
.run()
- .getBody().assertValue("{}");
+ .assertBody().equals("{}");
}
@Test
@@ -2200,7 +2200,7 @@ public class RestClientTest {
.build()
.post("/echoBody", x)
.run()
- .getBody().assertValue("['a','b','c']");
+ .assertBody().equals("['a','b','c']");
}
@Test
@@ -2214,7 +2214,7 @@ public class RestClientTest {
.build()
.post("/echoBody", x)
.run()
- .getBody().assertValue("{a:1,b:2,c:3}");
+ .assertBody().equals("{a:1,b:2,c:3}");
}
public static class L16 {
@@ -2233,7 +2233,7 @@ public class RestClientTest {
.build()
.post("/echoBody", x)
.run()
- .getBody().assertValue("{}");
+ .assertBody().equals("{}");
}
public static class L18 {
@@ -2252,7 +2252,7 @@ public class RestClientTest {
.build()
.post("/echoBody", x)
.run()
- .getBody().assertValue("{}");
+ .assertBody().equals("{}");
}
public static class L20 {
@@ -2270,7 +2270,7 @@ public class RestClientTest {
.build()
.post("/echoBody", x)
.run()
- .getBody().assertValue("{f:null}");
+ .assertBody().equals("{f:null}");
}
public static class L21 {
@@ -2288,7 +2288,7 @@ public class RestClientTest {
.build()
.post("/echoBody", x)
.run()
- .getBody().assertValue("{f:'foo'}");
+ .assertBody().equals("{f:'foo'}");
}
public static class L23 {
@@ -2309,7 +2309,7 @@ public class RestClientTest {
.build()
.post("/echoBody", x)
.run()
-
.getBody().assertValue("{f:'http://localhost:80/context/resource/foo'}");
+
.assertBody().equals("{f:'http://localhost:80/context/resource/foo'}");
MockRestClient
.create(A.class)
@@ -2320,7 +2320,7 @@ public class RestClientTest {
.build()
.post("/echoBody", x)
.run()
- .getBody().assertValue("{f:'foo'}");
+ .assertBody().equals("{f:'foo'}");
}
public static class L26 {
@@ -2350,7 +2350,7 @@ public class RestClientTest {
.build()
.post("/echoBody", x)
.run()
- .getBody().assertValue("{\n\tf1: 1,\n\tf2: {\n\t\tf1:
2,\n\t\tf2: {f1:3}\n\t}\n}");
+ .assertBody().equals("{\n\tf1: 1,\n\tf2: {\n\t\tf1:
2,\n\t\tf2: {f1:3}\n\t}\n}");
}
public static class L27 {
@@ -2368,7 +2368,7 @@ public class RestClientTest {
.build()
.post("/echoBody", x)
.run()
- .getBody().assertValue("{'f1':'foo'}");
+ .assertBody().equals("{'f1':'foo'}");
MockRestClient
.create(A.class)
@@ -2377,7 +2377,7 @@ public class RestClientTest {
.build()
.post("/echoBody", x)
.run()
- .getBody().assertValue("{|f1|:|foo|}");
+ .assertBody().equals("{|f1|:|foo|}");
MockRestClient
.create(A.class)
@@ -2386,7 +2386,7 @@ public class RestClientTest {
.build()
.post("/echoBody", x)
.run()
- .getBody().assertValue("{f1:|foo|}");
+ .assertBody().equals("{f1:|foo|}");
}
@Test
@@ -2400,7 +2400,7 @@ public class RestClientTest {
.build()
.post("/echoBody", x)
.run()
- .getBody().assertValue("{'f1':'foo'}");
+ .assertBody().equals("{'f1':'foo'}");
MockRestClient
.create(A.class)
@@ -2409,7 +2409,7 @@ public class RestClientTest {
.build()
.post("/echoBody", x)
.run()
- .getBody().assertValue("{f1:'foo'}");
+ .assertBody().equals("{f1:'foo'}");
}
@Test
@@ -2423,7 +2423,7 @@ public class RestClientTest {
.build()
.post("/echoBody", x)
.run()
- .getBody().assertValue("{\n\tf1: 'foo'\n}");
+ .assertBody().equals("{\n\tf1: 'foo'\n}");
}
//-----------------------------------------------------------------------------------------------------------------
@@ -2506,7 +2506,7 @@ public class RestClientTest {
.get("/checkQuery")
.query("Foo", "bar baz")
.run()
- .getBody().assertValue("Foo=%27bar+baz%27");
+ .assertBody().equals("Foo=%27bar+baz%27");
}
@Test
@@ -2519,19 +2519,19 @@ public class RestClientTest {
rc.get("/checkQuery")
.query("Foo", new String[]{"bar","baz"})
.run()
- .getBody().assertValue("Foo=bar%7Cbaz");
+ .assertBody().equals("Foo=bar%7Cbaz");
rc.post("/checkFormData")
.formData("Foo", new String[]{"bar","baz"})
.run()
- .getBody().assertValue("Foo=bar%7Cbaz");
+ .assertBody().equals("Foo=bar%7Cbaz");
rc.get("/checkHeader")
.header("Check", "Foo")
.header("Foo", new String[]{"bar","baz"})
.accept("text/json+simple")
.run()
- .getBody().assertValue("['bar|baz']");
+ .assertBody().equals("['bar|baz']");
}
//-----------------------------------------------------------------------------------------------------------------
@@ -2562,39 +2562,39 @@ public class RestClientTest {
rc1.post("/echoBody", new O1())
.run()
- .getBody().assertValue("'O1'");
+ .assertBody().equals("'O1'");
rc2.post("/echoBody", new O1())
.run()
- .getBody().assertValue("{f:1}");
+ .assertBody().equals("{f:1}");
rc1.get("/checkQuery")
.query("foo", new O1())
.run()
- .getBody().assertValue("foo=O1");
+ .assertBody().equals("foo=O1");
rc2.get("/checkQuery")
.query("foo", new O1())
.run()
- .getBody().assertValue("foo=f%3D1");
+ .assertBody().equals("foo=f%3D1");
rc1.formPost("/checkFormData")
.formData("foo", new O1())
.run()
- .getBody().assertValue("foo=O1");
+ .assertBody().equals("foo=O1");
rc2.formPost("/checkFormData")
.formData("foo", new O1())
.run()
- .getBody().assertValue("foo=f%3D1");
+ .assertBody().equals("foo=f%3D1");
rc1.get("/checkHeader")
.header("foo", new O1())
.header("Check", "foo")
.run()
- .getBody().assertValue("['O1']");
+ .assertBody().equals("['O1']");
rc2.get("/checkHeader")
.header("foo", new O1())
.header("Check", "foo")
.run()
- .getBody().assertValue("['f=1']");
+ .assertBody().equals("['f=1']");
}
public static class O2 {
@@ -2629,8 +2629,8 @@ public class RestClientTest {
.header("X", new O2(1))
.run()
.cacheBody()
- .getBody().assertValue("1")
- .getHeader("X").assertValue("1")
+ .assertBody().equals("1")
+ .assertHeader("X").equals("1")
;
assertEquals(1, rr.getBody().as(O2.class).f);
assertEquals(1, rr.getHeader("X").as(O2.class).f);
@@ -2664,8 +2664,8 @@ public class RestClientTest {
.header("X", new O9().init())
.run()
.cacheBody()
- .getBody().assertValue("{f1:1,f2:2}")
- .getHeader("X").assertValue("f1=1,f2=2")
+ .assertBody().equals("{f1:1,f2:2}")
+ .assertHeader("X").equals("f1=1,f2=2")
;
assertEquals(2, rr.getBody().as(O9.class).f2);
assertEquals(2, rr.getHeader("X").as(O9.class).f2);
@@ -2714,8 +2714,8 @@ public class RestClientTest {
.header("X", new O10().init())
.run()
.cacheBody()
- .getBody().assertValue("{f1:1}")
- .getHeader("X").assertValue("f1=1")
+ .assertBody().equals("{f1:1}")
+ .assertHeader("X").equals("f1=1")
;
assertEquals(0, rr.getBody().as(O10.class).f2);
assertEquals(0, rr.getHeader("X").as(O10.class).f2);
@@ -2729,8 +2729,8 @@ public class RestClientTest {
.header("X", new O10().init())
.run()
.cacheBody()
- .getBody().assertValue("{f1:1}")
- .getHeader("X").assertValue("f1=1")
+ .assertBody().equals("{f1:1}")
+ .assertHeader("X").equals("f1=1")
;
assertEquals(0, rr.getBody().as(O10.class).f2);
assertEquals(0, rr.getHeader("X").as(O10.class).f2);
@@ -2744,8 +2744,8 @@ public class RestClientTest {
.header("X", new O10().init())
.run()
.cacheBody()
- .getBody().assertValue("{f1:1}")
- .getHeader("X").assertValue("f1=1")
+ .assertBody().equals("{f1:1}")
+ .assertHeader("X").equals("f1=1")
;
assertEquals(0, rr.getBody().as(O10.class).f2);
assertEquals(0, rr.getHeader("X").as(O10.class).f2);
@@ -2759,8 +2759,8 @@ public class RestClientTest {
.header("X", new O10().init())
.run()
.cacheBody()
- .getBody().assertValue("{f1:1}")
- .getHeader("X").assertValue("f1=1")
+ .assertBody().equals("{f1:1}")
+ .assertHeader("X").equals("f1=1")
;
assertEquals(0, rr.getBody().as(O10.class).f2);
assertEquals(0, rr.getHeader("X").as(O10.class).f2);
@@ -2774,8 +2774,8 @@ public class RestClientTest {
.header("X", new O10().init())
.run()
.cacheBody()
- .getBody().assertValue("{f3:3}")
- .getHeader("X").assertValue("f3=3")
+ .assertBody().equals("{f3:3}")
+ .assertHeader("X").equals("f3=3")
;
assertEquals(3, rr.getBody().as(O10.class).f3);
assertEquals(3, rr.getHeader("X").as(O10.class).f3);
@@ -2820,8 +2820,8 @@ public class RestClientTest {
.header("X", new O18().init())
.run()
.cacheBody()
- .getBody().assertValue("{f1:1,f2:2}")
- .getHeader("X").assertValue("f1=1,f2=2")
+ .assertBody().equals("{f1:1,f2:2}")
+ .assertHeader("X").equals("f1=1,f2=2")
;
assertEquals(2, rr.getBody().as(O18.class).f2);
assertEquals(2, rr.getHeader("X").as(O18.class).f2);
@@ -2849,8 +2849,8 @@ public class RestClientTest {
.post("/test", new O21("1"))
.header("X", new O21("1"))
.run()
- .getBody().assertValue("{f1:'1'}")
- .getHeader("X").assertValue("f1=1")
+ .assertBody().equals("{f1:'1'}")
+ .assertHeader("X").equals("f1=1")
;
MockRestClient
.create(O2R.class)
@@ -2860,8 +2860,8 @@ public class RestClientTest {
.post("/test", new O21("1"))
.header("X", new O21("1"))
.run()
- .getBody().assertValue("'1'")
- .getHeader("X").assertValue("1")
+ .assertBody().equals("'1'")
+ .assertHeader("X").equals("1")
;
}
@@ -2874,8 +2874,8 @@ public class RestClientTest {
.post("/test", new O21("1"))
.header("X", new O21("1"))
.run()
- .getBody().assertValue("{f1:'1'}")
- .getHeader("X").assertValue("f1=1")
+ .assertBody().equals("{f1:'1'}")
+ .assertHeader("X").equals("f1=1")
;
MockRestClient
.create(O2R.class)
@@ -2885,8 +2885,8 @@ public class RestClientTest {
.post("/test", new O21("1"))
.header("X", new O21("1"))
.run()
- .getBody().assertValue("'1'")
- .getHeader("X").assertValue("1")
+ .assertBody().equals("'1'")
+ .assertHeader("X").equals("1")
;
}
@@ -2924,8 +2924,8 @@ public class RestClientTest {
.post("/test", new O25().init())
.header("X", new O25().init())
.run()
- .getBody().assertValue("{f1:1,f2:2}")
- .getHeader("X").assertValue("f1=1,f2=2")
+ .assertBody().equals("{f1:1,f2:2}")
+ .assertHeader("X").equals("f1=1,f2=2")
;
MockRestClient
.create(O2R.class)
@@ -2935,8 +2935,8 @@ public class RestClientTest {
.post("/test", new O25().init())
.header("X", new O25().init())
.run()
- .getBody().assertValue("{f1:1}")
- .getHeader("X").assertValue("f1=1")
+ .assertBody().equals("{f1:1}")
+ .assertHeader("X").equals("f1=1")
;
}
@@ -2950,8 +2950,8 @@ public class RestClientTest {
.post("/test", new O25().init())
.header("X", new O25().init())
.run()
- .getBody().assertValue("{f2:2}")
- .getHeader("X").assertValue("f2=2")
+ .assertBody().equals("{f2:2}")
+ .assertHeader("X").equals("f2=2")
;
MockRestClient
.create(O2R.class)
@@ -2961,8 +2961,8 @@ public class RestClientTest {
.post("/test", new O25().init())
.header("X", new O25().init())
.run()
- .getBody().assertValue("{f2:2}")
- .getHeader("X").assertValue("f2=2")
+ .assertBody().equals("{f2:2}")
+ .assertHeader("X").equals("f2=2")
;
MockRestClient
.create(O2R.class)
@@ -2972,8 +2972,8 @@ public class RestClientTest {
.post("/test", new O25().init())
.header("X", new O25().init())
.run()
- .getBody().assertValue("{f2:2}")
- .getHeader("X").assertValue("f2=2")
+ .assertBody().equals("{f2:2}")
+ .assertHeader("X").equals("f2=2")
;
MockRestClient
.create(O2R.class)
@@ -2983,8 +2983,8 @@ public class RestClientTest {
.post("/test", new O25().init())
.header("X", new O25().init())
.run()
- .getBody().assertValue("{f2:2}")
- .getHeader("X").assertValue("f2=2")
+ .assertBody().equals("{f2:2}")
+ .assertHeader("X").equals("f2=2")
;
}
@@ -3001,8 +3001,8 @@ public class RestClientTest {
.header("X", new O25().init())
.run()
.cacheBody()
- .getBody().assertValue("{f1:1,f2:2}")
- .getHeader("X").assertValue("f1=1,f2=2")
+ .assertBody().equals("{f1:1,f2:2}")
+ .assertHeader("X").equals("f1=1,f2=2")
;
assertEquals("1/0", rr.getBody().as(O25.class).toString());
assertEquals("1/0", rr.getHeader("X").as(O25.class).toString());
@@ -3016,8 +3016,8 @@ public class RestClientTest {
.header("X", new O25().init())
.run()
.cacheBody()
- .getBody().assertValue("{f1:1,f2:2}")
- .getHeader("X").assertValue("f1=1,f2=2")
+ .assertBody().equals("{f1:1,f2:2}")
+ .assertHeader("X").equals("f1=1,f2=2")
;
assertEquals("1/0", rr.getBody().as(O25.class).toString());
assertEquals("1/0", rr.getHeader("X").as(O25.class).toString());
@@ -3031,8 +3031,8 @@ public class RestClientTest {
.header("X", new O25().init())
.run()
.cacheBody()
- .getBody().assertValue("{f1:1,f2:2}")
- .getHeader("X").assertValue("f1=1,f2=2")
+ .assertBody().equals("{f1:1,f2:2}")
+ .assertHeader("X").equals("f1=1,f2=2")
;
assertEquals("1/0", rr.getBody().as(O25.class).toString());
assertEquals("1/0", rr.getHeader("X").as(O25.class).toString());
@@ -3051,8 +3051,8 @@ public class RestClientTest {
.header("X", new O25().init())
.run()
.cacheBody()
- .getBody().assertValue("{f1:1}")
- .getHeader("X").assertValue("f1=1")
+ .assertBody().equals("{f1:1}")
+ .assertHeader("X").equals("f1=1")
;
assertEquals("1/0", rr.getBody().as(O25.class).toString());
assertEquals("1/0", rr.getHeader("X").as(O25.class).toString());
@@ -3066,8 +3066,8 @@ public class RestClientTest {
.header("X", new O25().init())
.run()
.cacheBody()
- .getBody().assertValue("{f1:1}")
- .getHeader("X").assertValue("f1=1")
+ .assertBody().equals("{f1:1}")
+ .assertHeader("X").equals("f1=1")
;
assertEquals("1/0", rr.getBody().as(O25.class).toString());
assertEquals("1/0", rr.getHeader("X").as(O25.class).toString());
@@ -3081,8 +3081,8 @@ public class RestClientTest {
.header("X", new O25().init())
.run()
.cacheBody()
- .getBody().assertValue("{f1:1}")
- .getHeader("X").assertValue("f1=1")
+ .assertBody().equals("{f1:1}")
+ .assertHeader("X").equals("f1=1")
;
assertEquals("1/0", rr.getBody().as(O25.class).toString());
assertEquals("1/0", rr.getHeader("X").as(O25.class).toString());
@@ -3098,8 +3098,8 @@ public class RestClientTest {
.post("/test", new O25().init())
.header("X", new O25().init())
.run()
- .getBody().assertValue("{f2:2}")
- .getHeader("X").assertValue("f2=2")
+ .assertBody().equals("{f2:2}")
+ .assertHeader("X").equals("f2=2")
;
MockRestClient
.create(O2R.class)
@@ -3109,8 +3109,8 @@ public class RestClientTest {
.post("/test", new O25().init())
.header("X", new O25().init())
.run()
- .getBody().assertValue("{f2:2}")
- .getHeader("X").assertValue("f2=2")
+ .assertBody().equals("{f2:2}")
+ .assertHeader("X").equals("f2=2")
;
MockRestClient
.create(O2R.class)
@@ -3120,8 +3120,8 @@ public class RestClientTest {
.post("/test", new O25().init())
.header("X", new O25().init())
.run()
- .getBody().assertValue("{f2:2}")
- .getHeader("X").assertValue("f2=2")
+ .assertBody().equals("{f2:2}")
+ .assertHeader("X").equals("f2=2")
;
MockRestClient
.create(O2R.class)
@@ -3131,8 +3131,8 @@ public class RestClientTest {
.post("/test", new O25().init())
.header("X", new O25().init())
.run()
- .getBody().assertValue("{f2:2}")
- .getHeader("X").assertValue("f2=2")
+ .assertBody().equals("{f2:2}")
+ .assertHeader("X").equals("f2=2")
;
}
@@ -3152,7 +3152,7 @@ public class RestClientTest {
.build()
.post("/echo", x)
.run()
- .getBody().assertContains("HTTP GET
/echo","Foo: bar");
+ .assertBody().contains("HTTP GET /echo","Foo:
bar");
;
} catch (RestCallException e) {
assertTrue(e.getCause(SerializeException.class).getMessage().startsWith("Recursion
occurred"));
@@ -3200,7 +3200,7 @@ public class RestClientTest {
.post("/echoBody", new O33a().init())
.run()
.cacheBody()
- .getBody().assertContains("{_type:'foo',foo:'1'}")
+ .assertBody().contains("{_type:'foo',foo:'1'}")
.getBody().as(Object.class);
;
assertTrue(o instanceof O33a);
@@ -3216,7 +3216,7 @@ public class RestClientTest {
.post("/echoBody", m)
.run()
.cacheBody()
-
.getBody().assertValue("{x:{_type:'foo',foo:'1'},y:{_type:'bar',foo:'2'}}")
+
.assertBody().equals("{x:{_type:'foo',foo:'1'},y:{_type:'bar',foo:'2'}}")
.getBody().as(OMap.class);
;
assertTrue(m.get("x") instanceof O33a);
@@ -3232,7 +3232,7 @@ public class RestClientTest {
.post("/echoBody", new O33c().init())
.run()
.cacheBody()
- .getBody().assertValue("{foo:{_type:'foo',foo:'1'}}")
+ .assertBody().equals("{foo:{_type:'foo',foo:'1'}}")
.getBody().as(O33c.class);
;
assertTrue(o33c.foo instanceof O33a);
@@ -3258,7 +3258,7 @@ public class RestClientTest {
.post("/echoBody", new O34().init())
.run()
.cacheBody()
- .getBody().assertContains("{foo:'foo'}")
+ .assertBody().contains("{foo:'foo'}")
.getBody().as(O34.class);
;
assertNull(x.foo);
@@ -3272,7 +3272,7 @@ public class RestClientTest {
.post("/echoBody", new O34().init())
.run()
.cacheBody()
- .getBody().assertContains("{foo:'foo'}")
+ .assertBody().contains("{foo:'foo'}")
.getBody().as(O34.class);
} catch (RestCallException e) {
assertTrue(e.getCause(BeanRuntimeException.class).getMessage().contains("Setter
or public field not defined"));
@@ -3299,7 +3299,7 @@ public class RestClientTest {
.post("/echoBody", new O35().init())
.run()
.cacheBody()
- .getBody().assertContains("{foo:'1'}")
+ .assertBody().contains("{foo:'1'}")
.getBody().as(O35.class);
;
assertNull(x.bar);
@@ -3312,7 +3312,7 @@ public class RestClientTest {
.post("/echoBody", new O35().init())
.run()
.cacheBody()
- .getBody().assertContains("{bar:'2',foo:'1'}")
+ .assertBody().contains("{bar:'2',foo:'1'}")
.getBody().as(O35.class);
assertEquals("2", x.bar);
}
@@ -3330,7 +3330,7 @@ public class RestClientTest {
.post("/echoBody", new
StringReader("{foo:'1',bar:null}"))
.run()
.cacheBody()
- .getBody().assertContains("{foo:'1',bar:null}")
+ .assertBody().contains("{foo:'1',bar:null}")
.getBody().as(O36.class);
;
@@ -3343,7 +3343,7 @@ public class RestClientTest {
.post("/echoBody", new
StringReader("{foo:'1',bar:null}"))
.run()
.cacheBody()
- .getBody().assertContains("{foo:'1',bar:null}")
+ .assertBody().contains("{foo:'1',bar:null}")
.getBody().as(O36.class);
} catch (RestCallException e) {
assertTrue(e.getCause(ParseException.class).getMessage().contains("Unknown
property 'bar'"));
@@ -3364,7 +3364,7 @@ public class RestClientTest {
.post("/echoBody", new StringReader("{foo:'1'}"))
.run()
.cacheBody()
- .getBody().assertContains("{foo:'1'}")
+ .assertBody().contains("{foo:'1'}")
.getBody().as(O37.class);
;
assertEquals("1", x.getFoo());
@@ -3378,7 +3378,7 @@ public class RestClientTest {
.post("/echoBody", new
StringReader("{foo:'1'}"))
.run()
.cacheBody()
- .getBody().assertContains("{foo:'1'}")
+ .assertBody().contains("{foo:'1'}")
.getBody().as(O37.class);
} catch (RestCallException e) {
assertTrue(e.getCause(ParseException.class).getMessage().contains("could not be
instantiated"));
@@ -3406,7 +3406,7 @@ public class RestClientTest {
.post("/echoBody", new StringReader("{foo:'1'}"))
.run()
.cacheBody()
- .getBody().assertContains("{foo:'1'}")
+ .assertBody().contains("{foo:'1'}")
.getBody().as(O38.class);
;
assertEquals("1", x.getFoo());
@@ -3419,7 +3419,7 @@ public class RestClientTest {
.post("/echoBody", new StringReader("{foo:'1'}"))
.run()
.cacheBody()
- .getBody().assertContains("{foo:'1'}")
+ .assertBody().contains("{foo:'1'}")
.getBody().as(O38.class);
;
assertEquals("1", x.getFoo());
@@ -3470,7 +3470,7 @@ public class RestClientTest {
.post("/echoBody", new O39().init())
.run()
.cacheBody()
- .getBody().assertContains("{foo:'1'}")
+ .assertBody().contains("{foo:'1'}")
.getBody().as(O39.class);
;
assertEquals("1", x.getFoo());
@@ -3568,13 +3568,13 @@ public class RestClientTest {
public static class O42 implements O42I {
private int foo;
@Override
- public void setFoo(int foo) {
- this.foo = foo;
- }
- @Override
public int getFoo() {
return foo;
}
+ @Override
+ public void setFoo(int foo) {
+ this.foo = foo;
+ }
}
@Test
@@ -3604,24 +3604,55 @@ public class RestClientTest {
assertTrue(x instanceof O42);
}
-// @Test
-// public void o0_beanContext_() throws Exception {
-// }
-// @Override /* GENERATED - BeanContextBuilder */
-// public MockRestClient interfaceClass(Class<?> on, Class<?> value) {
-// super.interfaceClass(on, value);
-// return this;
-// }
-//
-// @Test
-// public void o0_beanContext_() throws Exception {
-// }
-// @Override /* GENERATED - BeanContextBuilder */
-// public MockRestClient interfaces(java.lang.Class<?>...value) {
-// super.interfaces(value);
-// return this;
-// }
-//
+ public static interface O43I {
+ void setFoo(int foo);
+ int getFoo();
+ }
+
+ public static class O43 implements O43I {
+ private int foo,bar;
+ @Override
+ public int getFoo() { return foo; }
+ @Override
+ public void setFoo(int foo) { this.foo = foo; }
+ public int getBar() { return bar; }
+ public void setBar(int bar) { this.bar = bar; }
+
+ public O43 init() {
+ foo = 1;
+ bar = 2;
+ return this;
+ }
+ }
+
+ @Test
+ public void o043_beanContext_interfaceClass() throws Exception {
+ O43I x = MockRestClient
+ .create(A.class)
+ .simpleJson()
+ .interfaceClass(O43.class, O43I.class)
+ .build()
+ .post("/echoBody", new O43().init())
+ .run()
+ .cacheBody()
+ .assertBody().equals("{foo:1}")
+ .getBody().as(O43.class)
+ ;
+ assertEquals(1, x.getFoo());
+
+ x = MockRestClient
+ .create(A.class)
+ .simpleJson()
+ .interfaces(O43I.class)
+ .build()
+ .post("/echoBody", new O43().init())
+ .run()
+ .assertBody().equals("{foo:1}")
+ .getBody().as(O43.class)
+ ;
+ assertEquals(1, x.getFoo());
+ }
+
// @Test
// public void o0_beanContext_() throws Exception {
// }
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestClient.java
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestClient.java
index fee442d..9f88d0a 100644
---
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestClient.java
+++
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestClient.java
@@ -518,8 +518,7 @@ import org.apache.http.client.CookieStore;
* <li class='jm'><c>{@link RestResponse#getStatusCode(Mutable)
getStatusCode(Mutable<Integer>)} <jk>returns</jk> {@link RestResponse}</c>
* <li class='jm'><c>{@link RestResponse#getReasonPhrase()
getReasonPhrase()} <jk>returns</jk> String</c>
* <li class='jm'><c>{@link RestResponse#getReasonPhrase(Mutable)
getReasonPhrase(Mutable<String>)} <jk>returns</jk> {@link
RestResponse}</c>
- * <li class='jm'><c>{@link RestResponse#assertStatusCode(int...)
assertStatusCode(int...)} <jk>returns</jk> {@link RestResponse}</c>
- * <li class='jm'><c>{@link
RestResponse#assertStatusCode(Predicate)
assertStatusCode(Predicate<Integer>)} <jk>returns</jk> {@link
RestResponse}</c>
+ * <li class='jm'><c>{@link RestResponse#assertStatusCode()
assertStatusCode()} <jk>returns</jk> {@link RestResponseStatusCodeAssertion}</c>
* </ul>
* </ul>
*
@@ -618,13 +617,7 @@ import org.apache.http.client.CookieStore;
* <li class='jm'><c>{@link
RestResponseHeader#asMatcher(Mutable,String)
asMatcher(Mutable<Matcher>,String)} <jk>returns</jk> {@link
RestResponse}</c>
* <li class='jm'><c>{@link
RestResponseHeader#asMatcher(String,int) asMatcher(String,int)}
<jk>returns</jk> {@link Matcher}</c>
* <li class='jm'><c>{@link
RestResponseHeader#asMatcher(Mutable,String,int)
asMatcher(Mutable<Matcher>,String,int)} <jk>returns</jk> {@link
RestResponse}</c>
- * <li class='jm'><c>{@link RestResponseHeader#assertExists()
assertExists()} <jk>returns</jk> {@link RestResponse}</c>
- * <li class='jm'><c>{@link RestResponseHeader#assertValue(String)
assertValue(String)} <jk>returns</jk> {@link RestResponse}</c>
- * <li class='jm'><c>{@link
RestResponseHeader#assertValue(Predicate) assertValue(Predicate<String>)}
<jk>returns</jk> {@link RestResponse}</c>
- * <li class='jm'><c>{@link
RestResponseHeader#assertContains(String...) assertContains(String...)}
<jk>returns</jk> {@link RestResponse}</c>
- * <li class='jm'><c>{@link
RestResponseHeader#assertMatches(String) assertMatches(String)}
<jk>returns</jk> {@link RestResponse}</c>
- * <li class='jm'><c>{@link
RestResponseHeader#assertMatches(String,int) assertMatches(String,int)}
<jk>returns</jk> {@link RestResponse}</c>
- * <li class='jm'><c>{@link
RestResponseHeader#assertMatches(Pattern) assertMatches(Pattern)}
<jk>returns</jk> {@link RestResponse}</c>
+ * <li class='jm'><c>{@link RestResponseHeader#assertThat()
assertThat()} <jk>returns</jk> {@link RestResponseHeaderAssertion}</c>
* </ul>
* </ul>
*
@@ -684,12 +677,7 @@ import org.apache.http.client.CookieStore;
* <li class='jm'><c>{@link
RestResponseBody#asMatcher(Mutable,String)
asMatcher(Mutable<Matcher>,String)} <jk>returns</jk> {@link
RestResponse}</c>
* <li class='jm'><c>{@link RestResponseBody#asMatcher(String,int)
asMatcher(String,int)} <jk>returns</jk> {@link Matcher}</c>
* <li class='jm'><c>{@link
RestResponseBody#asMatcher(Mutable,String,int)
asMatcher(Mutable<Matcher>,String,int)} <jk>returns</jk> {@link
RestResponse}</c>
- * <li class='jm'><c>{@link RestResponseBody#assertValue(String)
assertValue(String)} <jk>returns</jk> {@link RestResponse}</c>
- * <li class='jm'><c>{@link
RestResponseBody#assertContains(String...) assertContains(String...)}
<jk>returns</jk> {@link RestResponse}</c>
- * <li class='jm'><c>{@link
RestResponseBody#assertValue(Predicate) assertValue(Predicate<String>)}
<jk>returns</jk> {@link RestResponse}</c>
- * <li class='jm'><c>{@link RestResponseBody#assertMatches(String)
assertMatches(String)} <jk>returns</jk> {@link RestResponse}</c>
- * <li class='jm'><c>{@link
RestResponseBody#assertMatches(String,int) assertMatches(String,int)}
<jk>returns</jk> {@link RestResponse}</c>
- * <li class='jm'><c>{@link
RestResponseBody#assertMatches(Pattern) assertMatches(Pattern)}
<jk>returns</jk> {@link RestResponse}</c>
+ * <li class='jm'><c>{@link RestResponseBody#assertThat()
assertThat()} <jk>returns</jk> {@link RestResponseBodyAssertion}</c>
* </ul>
* </ul>
*
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponse.java
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponse.java
index 9a3e720..0b06ce8 100644
---
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponse.java
+++
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponse.java
@@ -18,7 +18,6 @@ import static org.apache.juneau.httppart.HttpPartType.*;
import java.lang.reflect.*;
import java.util.*;
-import java.util.function.*;
import org.apache.http.*;
import org.apache.http.message.*;
@@ -150,34 +149,22 @@ public final class RestResponse implements HttpResponse {
//------------------------------------------------------------------------------------------------------------------
/**
- * Asserts that the status code on the response is one of the specified
values.
+ * Provides the ability to perform fluent-style assertions on the
response status code.
*
- * @param validCodes The list of valid codes.
- * @return This object (for method chaining).
- * @throws RestCallException If REST call failed.
- * @throws AssertionError If assertion failed.
- */
- public RestResponse assertStatusCode(int...validCodes) throws
RestCallException, AssertionError {
- int sc = getStatusCode();
- for (int c : validCodes)
- if (c == sc)
- return this;
- throw new BasicAssertionError("Response did not have the
expected status code.\n\tExpected=[{0}]\n\tActual=[{1}]", validCodes, sc);
- }
-
- /**
- * Asserts that the status code on the response passes the specified
predicate test.
+ * <h5 class='section'>Examples:</h5>
+ * <p class='bcode w800'>
+ * MyBean bean = client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ * .assertStatusCode().equals(200)
+ * .getBody().as(MyBean.<jk>class</jk>);
+ * </p>
*
- * @param test The test.
- * @return This object (for method chaining).
+ * @return A new fluent assertion object.
* @throws RestCallException If REST call failed.
- * @throws AssertionError If assertion failed.
*/
- public RestResponse assertStatusCode(Predicate<Integer> test) throws
RestCallException, AssertionError {
- int sc = getStatusCode();
- if (test.test(sc))
- return this;
- throw new BasicAssertionError("Response did not have the
expected status code.\n\tActual=[{0}]", sc);
+ public RestResponseStatusCodeAssertion assertStatusCode() throws
RestCallException {
+ return new RestResponseStatusCodeAssertion(getStatusCode(),
this);
}
//------------------------------------------------------------------------------------------------------------------
@@ -219,6 +206,69 @@ public final class RestResponse implements HttpResponse {
return new RestResponseHeader(request, this,
getLastHeader(name)).parser(partParser);
}
+ /**
+ /**
+ * Provides the ability to perform fluent-style assertions on this
response header.
+ *
+ * <h5 class='section'>Examples:</h5>
+ * <p class='bcode w800'>
+ * <jc>// Validates the content type header is provided.</jc>
+ * client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ * .assertHeader(<js>"Content-Type"</js>).exists();
+ *
+ * <jc>// Validates the content type is JSON.</jc>
+ * client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ *
.assertHeader(<js>"Content-Type"</js>).equals(<js>"application/json"</js>);
+ *
+ * <jc>// Validates the content type is JSON using test
predicate.</jc>
+ * client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ * .assertHeader(<js>"Content-Type"</js>).passes(x ->
x.equals(<js>"application/json"</js>));
+ *
+ * <jc>// Validates the content type is JSON by just checking for
substring.</jc>
+ * client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ *
.assertHeader(<js>"Content-Type"</js>).contains(<js>"json"</js>);
+ *
+ * <jc>// Validates the content type is JSON using regular
expression.</jc>
+ * client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ *
.assertHeader(<js>"Content-Type"</js>).matches(<js>".*json.*"</js>);
+ *
+ * <jc>// Validates the content type is JSON using
case-insensitive regular expression.</jc>
+ * client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ *
.assertHeader(<js>"Content-Type"</js>).matches(<js>".*json.*"</js>,
<jsf>CASE_INSENSITIVE</jsf>);
+ * </p>
+ *
+ * <p>
+ * The assertion test returns the original response object allowing you
to chain multiple requests like so:
+ * <p class='bcode w800'>
+ * <jc>// Validates the header and converts it to a bean.</jc>
+ * MediaType mediaType = client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ * .assertHeader(<js>"Content-Type"</js>).exists()
+ *
.assertHeader(<js>"Content-Type"</js>).matches(<js>".*json.*"</js>)
+ *
.getHeader(<js>"Content-Type"</js>).as(MediaType.<jk>class</jk>);
+ * </p>
+ *
+ * @param name The header name.
+ * @return A new fluent assertion object.
+ * @throws RestCallException If REST call failed.
+ */
+ public RestResponseHeaderAssertion assertHeader(String name) throws
RestCallException {
+ return getHeader(name).assertThat();
+ }
+
//------------------------------------------------------------------------------------------------------------------
// Body
//------------------------------------------------------------------------------------------------------------------
@@ -235,6 +285,77 @@ public final class RestResponse implements HttpResponse {
}
/**
+ * Provides the ability to perform fluent-style assertions on this
response body.
+ *
+ * <h5 class='section'>Examples:</h5>
+ * <p class='bcode w800'>
+ * <jc>// Validates the response body equals the text "OK".</jc>
+ * client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ * .assertBody().equals(<js>"OK"</js>);
+ *
+ * <jc>// Validates the response body contains the text "OK".</jc>
+ * client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ * .assertBody().contains(<js>"OK"</js>);
+ *
+ * <jc>// Validates the response body passes a predicate test.</jc>
+ * client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ * .assertBody().passes(x -> x.contains(<js>"OK"</js>));
+ *
+ * <jc>// Validates the response body matches a regular
expression.</jc>
+ * client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ * .assertBody().matches(<js>".*OK.*"</js>);
+ *
+ * <jc>// Validates the response body matches a regular expression
using regex flags.</jc>
+ * client
+ * .get(<jsf>URL</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 p = Pattern.<jsm>compile</jsm>(<js>".*OK.*"</js>);
+ * client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ * .assertBody().matches(p);
+ * </p>
+ *
+ * <p>
+ * The assertion test returns the original response object allowing you
to chain multiple requests like so:
+ * <p class='bcode w800'>
+ * <jc>// Validates the response body matches a regular
expression.</jc>
+ * MyBean bean = client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ * .assertBody().matches(<js>".*OK.*"</js>);
+ * .assertBody().doesNotMatch(<js>".*ERROR.*"</js>)
+ * .getBody().as(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.
+ * <li>
+ * When using this method, the body is automatically
cached by calling the {@link RestResponseBody#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 RestResponseBodyAssertion assertBody() throws RestCallException {
+ return responseBody.cache().assertThat();
+ }
+
+ /**
* Caches the response body so that it can be read as a stream multiple
times.
*
* This is equivalent to calling the following:
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponseBody.java
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponseBody.java
index 32177e7..53d578e 100644
---
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponseBody.java
+++
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponseBody.java
@@ -14,12 +14,10 @@ package org.apache.juneau.rest.client2;
import static org.apache.juneau.internal.IOUtils.*;
import static org.apache.juneau.internal.StringUtils.*;
-import static java.util.logging.Level.*;
import java.io.*;
import java.lang.reflect.*;
import java.util.concurrent.*;
-import java.util.function.*;
import java.util.regex.*;
import org.apache.http.*;
@@ -177,11 +175,7 @@ public class RestResponseBody implements HttpEntity {
* <li class='jm'>{@link #asPojoRest(Mutable) asPojoRest(Mutable)}
* <li class='jm'>{@link #asPojoRest(Class) asPojoRest(Class)}
* <li class='jm'>{@link #asPojoRest(Mutable,Class)
asPojoRest(Mutable,Class)}
- * <li class='jm'>{@link #assertValue(Predicate)
assertValue(Predicate)}
- * <li class='jm'>{@link #assertValue(String) assertValue(String)}
- * <li class='jm'>{@link #assertContains(String...)
assertContains(String...)}
- * <li class='jm'>{@link #assertMatches(Pattern)
assertMatches(Pattern)}
- * <li class='jm'>{@link #assertMatches(String)
assertMatches(String)}
+ * <li class='jm'>{@link #assertThat() assertThat()}
* <li class='jm'>{@link #asString() asString()}
* <li class='jm'>{@link #asString(Mutable) asString(Mutable)}
* <li class='jm'>{@link #asStringFuture() asStringFuture()}
@@ -1519,208 +1513,58 @@ public class RestResponseBody implements HttpEntity {
//------------------------------------------------------------------------------------------------------------------
/**
- * Asserts that the body equals the specified value.
+ * Provides the ability to perform fluent-style assertions on this
response body.
*
- * <h5 class='section'>Example:</h5>
+ * <h5 class='section'>Examples:</h5>
* <p class='bcode w800'>
- * <jc>// Validates the response body is the text "OK".</jc>
+ * <jc>// Validates the response body equals the text "OK".</jc>
* client
* .get(<jsf>URL</jsf>)
* .run()
- * .getBody().assertValue(<js>"OK"</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>
- * If {@link #cache()} or {@link RestResponse#cacheBody()}
has been called, this method can be can be called multiple times and/or
combined with
- * other methods that retrieve the content of the
response. Otherwise a {@link RestCallException}
- * with an inner {@link IllegalStateException} will be
thrown.
- * <li>
- * The input stream is automatically closed after this
call.
- * </ul>
+ * .assertBody().equals(<js>"OK"</js>);
*
- * @param value The value to check against.
- * @return The response object (for method chaining).
- * @throws RestCallException If REST call failed.
- * @throws AssertionError If assertion failed.
- */
- public RestResponse assertValue(String value) throws RestCallException,
AssertionError {
- String text = asString();
- if (! StringUtils.isEquals(value, text)) {
- if (value != null && value.startsWith("x")) {
- StringBuilder sb = new StringBuilder();
- sb.append("Response did not have the expected
value for body.");
- sb.append("\nExpected:
[").append(value.replaceAll("\\\\", "\\\\\\\\").replaceAll("\n",
"\\\\n").replaceAll("\t", "\\\\t")).append("]");
- sb.append("\nActual :
[").append(text.replaceAll("\\\\", "\\\\\\\\").replaceAll("\n",
"\\\\n").replaceAll("\t", "\\\\t")).append("]");
- client.log(WARNING, sb.toString());
- }
- throw new BasicAssertionError("Response did not have
the expected value for body.\n\tExpected=[{0}]\n\tActual=[{1}]", value, text);
- }
- return response;
- }
-
- /**
- * Asserts that the body contains all of the specified substrings.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
* <jc>// Validates the response body contains the text "OK".</jc>
* client
* .get(<jsf>URL</jsf>)
* .run()
- * .getBody().assertValueContains(<js>"OK"</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>
- * If {@link #cache()} or {@link RestResponse#cacheBody()}
has been called, this method can be can be called multiple times and/or
combined with
- * other methods that retrieve the content of the
response. Otherwise a {@link RestCallException}
- * with an inner {@link IllegalStateException} will be
thrown.
- * <li>
- * The input stream is automatically closed after this
call.
- * </ul>
+ * .assertBody().contains(<js>"OK"</js>);
*
- * @param values The values to check against.
- * @return The response object (for method chaining).
- * @throws AssertionError If assertion failed.
- * @throws RestCallException If REST call failed.
- */
- public RestResponse assertContains(String...values) throws
RestCallException, AssertionError {
- String text = asString();
- for (String substring : values)
- if (! StringUtils.contains(text, substring)) {
- if (substring.startsWith("x")) {
- StringBuilder sb = new StringBuilder();
- sb.append("Response did not have the
expected substring for body.");
- sb.append("\nExpected:
[").append(substring.replaceAll("\\\\", "\\\\\\\\").replaceAll("\n",
"\\\\n").replaceAll("\t", "\\\\t")).append("]");
- sb.append("\nActual :
[").append(text.replaceAll("\\\\", "\\\\\\\\").replaceAll("\n",
"\\\\n").replaceAll("\t", "\\\\t")).append("]");
- client.log(WARNING, sb.toString());
- }
- throw new BasicAssertionError("Response did not
have the expected substring for body.\n\tExpected=[{0}]\n\tBody=[{1}]",
substring, text);
-
- }
- return response;
- }
-
- /**
- * Asserts that the body passes the specified predicate test.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
- * <jc>// Validates the response body contains the text "OK".</jc>
+ * <jc>// Validates the response body passes a predicate test.</jc>
* client
* .get(<jsf>URL</jsf>)
* .run()
- * .getBody().assertValue(x ->
x.contains(<js>"OK"</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>
- * If {@link #cache()} or {@link RestResponse#cacheBody()}
has been called, this method can be can be called multiple times and/or
combined with
- * other methods that retrieve the content of the
response. Otherwise a {@link RestCallException}
- * with an inner {@link IllegalStateException} will be
thrown.
- * <li>
- * The input stream is automatically closed after this
call.
- * </ul>
- *
- * @param test The predicate to use to test the body context.
- * @return The response object (for method chaining).
- * @throws RestCallException If REST call failed.
- * @throws AssertionError If assertion failed.
- */
- public RestResponse assertValue(Predicate<String> test) throws
RestCallException, AssertionError {
- String text = asString();
- if (! test.test(text))
- throw new BasicAssertionError("Response did not have
the expected value for body.\n\tActual=[{0}]", text);
- return response;
- }
-
- /**
- * Asserts that the body matches the specified regular expression.
+ * .assertBody().passes(x -> x.contains(<js>"OK"</js>));
*
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
- * <jc>// Validates the response body contains the text "OK"
anywhere.</jc>
+ * <jc>// Validates the response body matches a regular
expression.</jc>
* client
* .get(<jsf>URL</jsf>)
* .run()
- * .getBody().assertValueMaches(<js>".*OK.*"</js>);
- * </p>
+ * .assertBody().matches(<js>".*OK.*"</js>);
*
- * <ul class='notes'>
- * <li>
- * If no charset was found on the
<code>Content-Type</code> response header, <js>"UTF-8"</js> is assumed.
- * <li>
- * If {@link #cache()} or {@link RestResponse#cacheBody()}
has been called, this method can be can be called multiple times and/or
combined with
- * other methods that retrieve the content of the
response. Otherwise a {@link RestCallException}
- * with an inner {@link IllegalStateException} will be
thrown.
- * <li>
- * The input stream is automatically closed after this
call.
- * </ul>
- *
- * @param regex The pattern to test for.
- * @return The response object (for method chaining).
- * @throws RestCallException If REST call failed.
- * @throws AssertionError If assertion failed.
- */
- public RestResponse assertMatches(String regex) throws
RestCallException, AssertionError {
- return assertMatches(regex, 0);
- }
-
- /**
- * Asserts that the body matches the specified regular expression.
+ * <jc>// Validates the response body matches a regular expression
using regex flags.</jc>
+ * client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ * .assertBody().matches(<js>".*OK.*"</js>,
<jsf>MULTILINE</jsf> & <jsf>CASE_INSENSITIVE</jsf>);
*
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
- * <jc>// Validates the response body contains the text "OK"
anywhere.</jc>
+ * <jc>// Validates the response body matches a regular expression
in the form of an existing Pattern.</jc>
+ * Pattern p = Pattern.<jsm>compile</jsm>(<js>".*OK.*"</js>);
* client
* .get(<jsf>URL</jsf>)
* .run()
- * .getBody().assertValueMaches(<js>".*OK.*"</js>,
<jsf>MULTILINE</jsf> & <jsf>CASE_INSENSITIVE</jsf>);
+ * .assertBody().matches(p);
* </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>
- * If {@link #cache()} or {@link RestResponse#cacheBody()}
has been called, this method can be can be called multiple times and/or
combined with
- * other methods that retrieve the content of the
response. Otherwise a {@link RestCallException}
- * with an inner {@link IllegalStateException} will be
thrown.
- * <li>
- * The input stream is automatically closed after this
call.
- * </ul>
- *
- * @param regex The pattern to test for.
- * @param flags Pattern match flags. See {@link
Pattern#compile(String, int)}.
- * @return The response object (for method chaining).
- * @throws RestCallException If REST call failed.
- * @throws AssertionError If assertion failed.
- */
- public RestResponse assertMatches(String regex, int flags) throws
RestCallException, AssertionError {
- String text = asString();
- Pattern p = Pattern.compile(regex, flags);
- if (! p.matcher(text).matches())
- throw new BasicAssertionError("Response did not match
expected pattern.\n\tpattern=[{0}]\n\tBody=[{1}]", regex, text);
- return response;
- }
-
- /**
- * Asserts that the body matches the specified regular expression
pattern.
- *
- * <h5 class='section'>Example:</h5>
+ * <p>
+ * The assertion test returns the original response object allowing you
to chain multiple requests like so:
* <p class='bcode w800'>
- * <jc>// Validates the response body contains the text "OK"
anywhere.</jc>
- * Pattern p = Pattern.<jsm>compile</jsm>(<js>".*OK.*"</js>);
- * client
+ * <jc>// Validates the response body matches a regular
expression.</jc>
+ * MyBean bean = client
* .get(<jsf>URL</jsf>)
* .run()
- * .getBody().assertValueMaches(p);
+ * .assertBody().matches(<js>".*OK.*"</js>);
+ * .assertBody().doesNotMatch(<js>".*ERROR.*"</js>)
+ * .getBody().as(MyBean.<jk>class</jk>);
* </p>
*
* <ul class='notes'>
@@ -1734,16 +1578,11 @@ public class RestResponseBody implements HttpEntity {
* The input stream is automatically closed after this
call.
* </ul>
*
- * @param pattern The pattern to test for.
- * @return The response object (for method chaining).
+ * @return A new fluent assertion object.
* @throws RestCallException If REST call failed.
- * @throws AssertionError If assertion failed.
*/
- public RestResponse assertMatches(Pattern pattern) throws
RestCallException, AssertionError {
- String text = asString();
- if (! pattern.matcher(text).matches())
- throw new BasicAssertionError("Response did not match
expected pattern.\n\tpattern=[{0}]\n\tBody=[{1}]", pattern.pattern(), text);
- return response;
+ public RestResponseBodyAssertion assertThat() throws RestCallException {
+ return new RestResponseBodyAssertion(asString(), response);
}
//------------------------------------------------------------------------------------------------------------------
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponseBodyAssertion.java
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponseBodyAssertion.java
new file mode 100644
index 0000000..645d681
--- /dev/null
+++
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponseBodyAssertion.java
@@ -0,0 +1,84 @@
+//
***************************************************************************************************************************
+// * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file *
+// * distributed with this work for additional information regarding copyright
ownership. The ASF licenses this file *
+// * to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance *
+// * with the License. You may obtain a copy of the License at
*
+// *
*
+// * http://www.apache.org/licenses/LICENSE-2.0
*
+// *
*
+// * Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an *
+// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the *
+// * specific language governing permissions and limitations under the
License. *
+//
***************************************************************************************************************************
+package org.apache.juneau.rest.client2;
+
+import org.apache.juneau.utils.*;
+
+/**
+ * Provides the ability to perform fluent-style assertions on the body of HTTP
responses.
+ *
+ * <h5 class='section'>Examples:</h5>
+ * <p class='bcode w800'>
+ * <jc>// Validates the response body equals the text "OK".</jc>
+ * client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ * .assertBody().equals(<js>"OK"</js>);
+ *
+ * <jc>// Validates the response body contains the text "OK".</jc>
+ * client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ * .assertBody().contains(<js>"OK"</js>);
+ *
+ * <jc>// Validates the response body passes a predicate test.</jc>
+ * client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ * .assertBody().passes(x -> x.contains(<js>"OK"</js>));
+ *
+ * <jc>// Validates the response body matches a regular expression.</jc>
+ * client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ * .assertBody().matches(<js>".*OK.*"</js>);
+ *
+ * <jc>// Validates the response body matches a regular expression using
regex flags.</jc>
+ * client
+ * .get(<jsf>URL</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 p = Pattern.<jsm>compile</jsm>(<js>".*OK.*"</js>);
+ * client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ * .assertBody().matches(p);
+ * </p>
+ *
+ * <p>
+ * The assertion test returns the original response object allowing you to
chain multiple requests like so:
+ * <p class='bcode w800'>
+ * <jc>// Validates the response body matches a regular expression.</jc>
+ * MyBean bean = client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ * .cacheBody() <jc>// Allows multiple calls to getBody() </jc>
+ * .assertBody().matches(<js>".*OK.*"</js>);
+ * .assertBody().doesNotMatch(<js>".*ERROR.*"</js>)
+ * .getBody().as(MyBean.<jk>class</jk>);
+ * </p>
+ */
+public class RestResponseBodyAssertion extends
FluentStringAssertion<RestResponse> {
+
+ /**
+ * Constructor
+ *
+ * @param text The HTTP body as text.
+ * @param returns The response object.
+ */
+ public RestResponseBodyAssertion(String text, RestResponse returns) {
+ super(text, returns);
+ }
+}
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponseHeader.java
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponseHeader.java
index deba94e..0a0620a 100644
---
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponseHeader.java
+++
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponseHeader.java
@@ -15,13 +15,11 @@ package org.apache.juneau.rest.client2;
import static org.apache.juneau.httppart.HttpPartType.*;
import java.lang.reflect.*;
import java.util.*;
-import java.util.function.*;
import java.util.regex.*;
import org.apache.http.*;
import org.apache.juneau.*;
import org.apache.juneau.httppart.*;
-import org.apache.juneau.internal.*;
import org.apache.juneau.oapi.*;
import org.apache.juneau.parser.ParseException;
import org.apache.juneau.utils.*;
@@ -504,171 +502,65 @@ public class RestResponseHeader implements Header {
//------------------------------------------------------------------------------------------------------------------
/**
- * Asserts that the header exists.
+ * Provides the ability to perform fluent-style assertions on this
response header.
*
- * <h5 class='section'>Example:</h5>
+ * <h5 class='section'>Examples:</h5>
* <p class='bcode w800'>
* <jc>// Validates the content type header is provided.</jc>
* client
* .get(<jsf>URL</jsf>)
* .run()
- * .getHeader(<js>"Content-Type"</js>).assertExists();
- * </p>
- *
- * @return The response object (for method chaining).
- * @throws RestCallException If REST call failed.
- * @throws AssertionError If assertion failed.
- */
- public RestResponse assertExists() throws RestCallException,
AssertionError {
- if (! exists())
- throw new BasicAssertionError("Response did not have
the expected header {0}.", getName());
- return response;
- }
-
- /**
- * Asserts that the header equals the specified value.
+ * .assertHeader(<js>"Content-Type"</js>).exists();
*
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
* <jc>// Validates the content type is JSON.</jc>
* client
* .get(<jsf>URL</jsf>)
* .run()
- *
.getHeader(<js>"Content-Type"</js>).assertValue(<js>"application/json"</js>);
- * </p>
- *
- * @param value The value to test for.
- * @return The response object (for method chaining).
- * @throws RestCallException If REST call failed.
- * @throws AssertionError If assertion failed.
- */
- public RestResponse assertValue(String value) throws RestCallException,
AssertionError {
- if (! StringUtils.isEquals(value, asString()))
- throw new BasicAssertionError("Response did not have
the expected value for header {0}.\n\tExpected=[{1}]\n\tActual=[{2}]",
getName(), value, asString());
- return response;
- }
-
- /**
- * Asserts that the header passes the specified predicate test.
+ *
.assertHeader(<js>"Content-Type"</js>).equals(<js>"application/json"</js>);
*
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
- * <jc>// Validates the content type is JSON.</jc>
+ * <jc>// Validates the content type is JSON using test
predicate.</jc>
* client
* .get(<jsf>URL</jsf>)
* .run()
- * .getHeader(<js>"Content-Type"</js>).assertValue(x ->
x.equals(<js>"application/json"</js>));
- * </p>
- *
- * @param test The predicate to test for.
- * @return The response object (for method chaining).
- * @throws RestCallException If REST call failed.
- * @throws AssertionError If assertion failed.
- */
- public RestResponse assertValue(Predicate<String> test) throws
RestCallException, AssertionError {
- String text = asString();
- if (! test.test(text))
- throw new BasicAssertionError("Response did not have
the expected value for header {0}.\n\tActual=[{1}]", getName(), text);
- return response;
- }
-
- /**
- * Asserts that the header contains all the specified substrings.
+ * .assertHeader(<js>"Content-Type"</js>).passes(x ->
x.equals(<js>"application/json"</js>));
*
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
- * <jc>// Validates the content type is JSON.</jc>
+ * <jc>// Validates the content type is JSON by just checking for
substring.</jc>
* client
* .get(<jsf>URL</jsf>)
* .run()
- *
.getHeader(<js>"Content-Type"</js>).assertValueContains(<js>"json"</js>);
- * </p>
+ *
.assertHeader(<js>"Content-Type"</js>).contains(<js>"json"</js>);
*
- * @param values The substrings to test for.
- * @return The response object (for method chaining).
- * @throws RestCallException If REST call failed.
- * @throws AssertionError If assertion failed.
- */
- public RestResponse assertContains(String...values) throws
RestCallException, AssertionError {
- String text = asString();
- for (String substring : values)
- if (! StringUtils.contains(text, substring))
- throw new BasicAssertionError("Response did not
have the expected substring in header {0}.\n\tExpected=[{1}]\n\tHeader=[{2}]",
getName(), substring, text);
- return response;
- }
-
- /**
- * Asserts that the header matches the specified regular expression.
- *
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
- * <jc>// Validates the content type is JSON.</jc>
+ * <jc>// Validates the content type is JSON using regular
expression.</jc>
* client
* .get(<jsf>URL</jsf>)
* .run()
- *
.getHeader(<js>"Content-Type"</js>).assertValueMatches(<js>".*json.*"</js>);
- * </p>
- *
- * @param regex The pattern to test for.
- * @return The response object (for method chaining).
- * @throws RestCallException If REST call failed.
- * @throws AssertionError If assertion failed.
- */
- public RestResponse assertMatches(String regex) throws
RestCallException, AssertionError {
- return assertMatches(regex, 0);
- }
-
- /**
- * Asserts that the header matches the specified regular expression.
+ *
.assertHeader(<js>"Content-Type"</js>).matches(<js>".*json.*"</js>);
*
- * <h5 class='section'>Example:</h5>
- * <p class='bcode w800'>
- * <jc>// Validates the content type is JSON.</jc>
+ * <jc>// Validates the content type is JSON using
case-insensitive regular expression.</jc>
* client
* .get(<jsf>URL</jsf>)
* .run()
- *
.getHeader(<js>"Content-Type"</js>).assertValueMatches(<js>".*json.*"</js>,
<jsf>CASE_INSENSITIVE</jsf>);
+ *
.assertHeader(<js>"Content-Type"</js>).matches(<js>".*json.*"</js>,
<jsf>CASE_INSENSITIVE</jsf>);
* </p>
*
- * @param regex The pattern to test for.
- * @param flags Pattern match flags. See {@link
Pattern#compile(String, int)}.
- * @return The response object (for method chaining).
- * @throws RestCallException If REST call failed.
- * @throws AssertionError If assertion failed.
- */
- public RestResponse assertMatches(String regex, int flags) throws
RestCallException, AssertionError {
- String text = asString();
- if (! Pattern.compile(regex, flags).matcher(text).matches())
- throw new BasicAssertionError("Response did not match
expected pattern in header {0}.\n\tpattern=[{1}]\n\tHeader=[{2}]", getName(),
regex, text);
- return response;
- }
-
- /**
- * Asserts that the header matches the specified pattern.
- *
* <p>
- * The pattern can contain <js>"*"</js> to represent zero or more
arbitrary characters.
- *
- * <h5 class='section'>Example:</h5>
+ * The assertion test returns the original response object allowing you
to chain multiple requests like so:
* <p class='bcode w800'>
- * <jc>// Validates the content type is JSON.</jc>
- * Pattern p =
Pattern.<jsm>compile</jsm>(<js>".*application\\/json.*"</js>);
- * client
+ * <jc>// Validates the header and converts it to a bean.</jc>
+ * MediaType mediaType = client
* .get(<jsf>URL</jsf>)
* .run()
- *
.getHeader(<js>"Content-Type"</js>).assertValueMatches(p);
+ * .assertHeader(<js>"Content-Type"</js>).exists()
+ *
.assertHeader(<js>"Content-Type"</js>).matches(<js>".*json.*"</js>)
+ *
.getHeader(<js>"Content-Type"</js>).as(MediaType.<jk>class</jk>);
* </p>
*
- * @param pattern The pattern to test for.
- * @return The response object (for method chaining).
+ * @return A new fluent assertion object.
* @throws RestCallException If REST call failed.
* @throws AssertionError If assertion failed.
*/
- public RestResponse assertMatches(Pattern pattern) throws
RestCallException, AssertionError {
- String text = asString();
- if (! pattern.matcher(text).matches())
- throw new BasicAssertionError("Response did not match
expected pattern in header {0}.\n\tpattern=[{1}]\n\tHeader=[{2}]", getName(),
pattern.pattern(), text);
- return response;
+ public RestResponseHeaderAssertion assertThat() throws
RestCallException {
+ return new RestResponseHeaderAssertion(asString(), response);
}
//------------------------------------------------------------------------------------------------------------------
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponseHeaderAssertion.java
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponseHeaderAssertion.java
new file mode 100644
index 0000000..a8baa37
--- /dev/null
+++
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponseHeaderAssertion.java
@@ -0,0 +1,82 @@
+//
***************************************************************************************************************************
+// * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file *
+// * distributed with this work for additional information regarding copyright
ownership. The ASF licenses this file *
+// * to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance *
+// * with the License. You may obtain a copy of the License at
*
+// *
*
+// * http://www.apache.org/licenses/LICENSE-2.0
*
+// *
*
+// * Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an *
+// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the *
+// * specific language governing permissions and limitations under the
License. *
+//
***************************************************************************************************************************
+package org.apache.juneau.rest.client2;
+
+import org.apache.juneau.utils.*;
+
+/**
+ * Provides the ability to perform fluent-style assertions on response headers.
+ *
+ * <h5 class='section'>Examples:</h5>
+ * <p class='bcode w800'>
+ * <jc>// Validates the content type header is provided.</jc>
+ * client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ * .assertHeader(<js>"Content-Type"</js>).exists();
+ *
+ * <jc>// Validates the content type is JSON.</jc>
+ * client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ *
.assertHeader(<js>"Content-Type"</js>).equals(<js>"application/json"</js>);
+ *
+ * <jc>// Validates the content type is JSON using test predicate.</jc>
+ * client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ * .assertHeader(<js>"Content-Type"</js>).passes(x ->
x.equals(<js>"application/json"</js>));
+ *
+ * <jc>// Validates the content type is JSON by just checking for
substring.</jc>
+ * client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ *
.assertHeader(<js>"Content-Type"</js>).contains(<js>"json"</js>);
+ *
+ * <jc>// Validates the content type is JSON using regular expression.</jc>
+ * client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ *
.assertHeader(<js>"Content-Type"</js>).matches(<js>".*json.*"</js>);
+ *
+ * <jc>// Validates the content type is JSON using case-insensitive
regular expression.</jc>
+ * client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ *
.assertHeader(<js>"Content-Type"</js>).matches(<js>".*json.*"</js>,
<jsf>CASE_INSENSITIVE</jsf>);
+ * </p>
+ *
+ * <p>
+ * The assertion test returns the original response object allowing you to
chain multiple requests like so:
+ * <p class='bcode w800'>
+ * <jc>// Validates the header and converts it to a bean.</jc>
+ * MediaType mediaType = client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ * .assertHeader(<js>"Content-Type"</js>).exists()
+ *
.assertHeader(<js>"Content-Type"</js>).matches(<js>".*json.*"</js>)
+ *
.getHeader(<js>"Content-Type"</js>).as(MediaType.<jk>class</jk>);
+ * </p>
+ */
+public class RestResponseHeaderAssertion extends
FluentStringAssertion<RestResponse> {
+
+ /**
+ * Constructor
+ *
+ * @param text The header value as text or <jk>null</jk> if it didn't
exist.
+ * @param returns The response object.
+ */
+ public RestResponseHeaderAssertion(String text, RestResponse returns) {
+ super(text, returns);
+ }
+}
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponseStatusCodeAssertion.java
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponseStatusCodeAssertion.java
new file mode 100644
index 0000000..c20a62a
--- /dev/null
+++
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponseStatusCodeAssertion.java
@@ -0,0 +1,40 @@
+//
***************************************************************************************************************************
+// * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file *
+// * distributed with this work for additional information regarding copyright
ownership. The ASF licenses this file *
+// * to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance *
+// * with the License. You may obtain a copy of the License at
*
+// *
*
+// * http://www.apache.org/licenses/LICENSE-2.0
*
+// *
*
+// * Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an *
+// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the *
+// * specific language governing permissions and limitations under the
License. *
+//
***************************************************************************************************************************
+package org.apache.juneau.rest.client2;
+
+import org.apache.juneau.utils.*;
+
+/**
+ * Provides the ability to perform fluent-style assertions on the response
status code.
+ *
+ * <h5 class='section'>Examples:</h5>
+ * <p class='bcode w800'>
+ * MyBean bean = client
+ * .get(<jsf>URL</jsf>)
+ * .run()
+ * .assertStatusCode().equals(200)
+ * .getBody().as(MyBean.<jk>class</jk>);
+ * </p>
+ */
+public class RestResponseStatusCodeAssertion extends
FluentIntAssertion<RestResponse> {
+
+ /**
+ * Constructor.
+ *
+ * @param value The status code.
+ * @param returns The response object.
+ */
+ public RestResponseStatusCodeAssertion(int value, RestResponse returns)
{
+ super(value, returns);
+ }
+}