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 37ed58a Tests.
37ed58a is described below
commit 37ed58a3aae3003fbc3e412d57c27a8746b502bd
Author: JamesBognar <[email protected]>
AuthorDate: Sat May 12 21:06:08 2018 -0400
Tests.
---
.../juneau/rest/test/AcceptCharsetResource.java | 92 ---------------
.../java/org/apache/juneau/rest/test/Root.java | 2 -
.../apache/juneau/rest/test/AcceptCharsetTest.java | 123 ---------------------
.../rest/test/BeanContextPropertiesTest.java | 34 ------
.../org/apache/juneau/rest/test/_TestSuite.java | 2 -
.../juneau/rest/mock/MockServletRequest.java | 10 ++
.../juneau/rest/mock/MockServletResponse.java | 13 +++
.../org/apache/juneau/rest/AcceptCharsetTest.java | 118 ++++++++++++++++++++
.../juneau/rest/BeanContextPropertiesTest.java | 43 ++++---
.../org/apache/juneau/rest/StatusCodesTest.java | 4 +-
10 files changed, 169 insertions(+), 272 deletions(-)
diff --git
a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/AcceptCharsetResource.java
b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/AcceptCharsetResource.java
deleted file mode 100644
index 9f474fa..0000000
---
a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/AcceptCharsetResource.java
+++ /dev/null
@@ -1,92 +0,0 @@
-//
***************************************************************************************************************************
-// * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file *
-// * distributed with this work for additional information regarding copyright
ownership. The ASF licenses this file *
-// * to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance *
-// * with the License. You may obtain a copy of the License at
*
-// *
*
-// * http://www.apache.org/licenses/LICENSE-2.0
*
-// *
*
-// * Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an *
-// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the *
-// * specific language governing permissions and limitations under the
License. *
-//
***************************************************************************************************************************
-package org.apache.juneau.rest.test;
-
-import static org.apache.juneau.http.HttpMethodName.*;
-
-import java.io.*;
-
-import org.apache.juneau.*;
-import org.apache.juneau.parser.*;
-import org.apache.juneau.plaintext.*;
-import org.apache.juneau.rest.*;
-import org.apache.juneau.rest.annotation.*;
-import org.apache.juneau.serializer.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testAcceptCharset",
- serializers={PlainTextSerializer.class},
- // Some versions of Jetty default to ISO8601, so specify UTF-8 for test
consistency.
- defaultCharset="utf-8"
-)
-public class AcceptCharsetResource extends RestServlet {
- private static final long serialVersionUID = 1L;
-
-
//====================================================================================================
- // Test that Q-values are being resolved correctly.
-
//====================================================================================================
- @RestMethod(name=GET, path="/testQValues")
- public String testQValues() {
- return "foo";
- }
-
-
//====================================================================================================
- // Validate various Accept-Charset variations.
-
//====================================================================================================
- @RestMethod(name=PUT, path="/testCharsetOnResponse",
parsers=TestParser.class, serializers=TestSerializer.class)
- public String testCharsetOnResponse(@Body String in) {
- return in;
- }
-
- public static class TestParser extends InputStreamParser {
-
- public TestParser(PropertyStore ps) {
- super(ps, "text/plain");
- }
-
- @Override /* Parser */
- public InputStreamParserSession createSession(ParserSessionArgs
args) {
- return new InputStreamParserSession(args) {
-
- @Override /* ParserSession */
- @SuppressWarnings("unchecked")
- protected <T> T doParse(ParserPipe pipe,
ClassMeta<T> type) throws Exception {
- return
(T)getProperty("characterEncoding", String.class);
- }
- };
- }
- }
-
- public static class TestSerializer extends OutputStreamSerializer {
-
- public TestSerializer(PropertyStore ps) {
- super(ps, "text/plain", null);
- }
-
- @Override /* Serializer */
- public OutputStreamSerializerSession
createSession(SerializerSessionArgs args) {
- return new OutputStreamSerializerSession(args) {
-
- @Override /* SerializerSession */
- protected void doSerialize(SerializerPipe out,
Object o) throws Exception {
- try (Writer w = new
OutputStreamWriter(out.getOutputStream())) {
-
w.append(o.toString()).append('/').append(getProperty("characterEncoding",
String.class));
- }
- }
- };
- }
- }
-}
diff --git
a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/Root.java
b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/Root.java
index d78303f..4e8d6e4 100644
---
a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/Root.java
+++
b/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/Root.java
@@ -24,8 +24,6 @@ import org.apache.juneau.rest.helper.*;
children={
DebugResource.class,
LogsResource.class,
- AcceptCharsetResource.class,
- BeanContextPropertiesResource.class,
BpiResource.class,
CallbackStringsResource.class,
CharsetEncodingsResource.class,
diff --git
a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/AcceptCharsetTest.java
b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/AcceptCharsetTest.java
deleted file mode 100644
index dcd54d1..0000000
---
a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/AcceptCharsetTest.java
+++ /dev/null
@@ -1,123 +0,0 @@
-//
***************************************************************************************************************************
-// * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file *
-// * distributed with this work for additional information regarding copyright
ownership. The ASF licenses this file *
-// * to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance *
-// * with the License. You may obtain a copy of the License at
*
-// *
*
-// * http://www.apache.org/licenses/LICENSE-2.0
*
-// *
*
-// * Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an *
-// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the *
-// * specific language governing permissions and limitations under the
License. *
-//
***************************************************************************************************************************
-package org.apache.juneau.rest.test;
-
-import static javax.servlet.http.HttpServletResponse.*;
-import static org.apache.juneau.internal.IOUtils.*;
-import static org.apache.juneau.microservice.testutils.TestUtils.*;
-import static org.junit.Assert.*;
-
-import java.io.*;
-
-import org.apache.juneau.rest.client.*;
-import org.junit.*;
-
-public class AcceptCharsetTest extends RestTestcase {
-
- boolean debug = false;
-
-
//====================================================================================================
- // Test that Q-values are being resolved correctly.
-
//====================================================================================================
- @Test
- public void testQValues() throws Exception {
- RestClient client = TestMicroservice.DEFAULT_CLIENT_PLAINTEXT;
-
- check1(client, "utf-8", "utf-8");
- check1(client, "iso-8859-1", "iso-8859-1");
- check1(client, "bad,utf-8", "utf-8");
- check1(client, "utf-8,bad", "utf-8");
- check1(client, "bad;q=0.9,utf-8;q=0.1", "utf-8");
- check1(client, "bad;q=0.1,utf-8;q=0.9", "utf-8");
-// check1(client, "utf-8,iso-8859-1", "utf-8");
-// check1(client, "iso-8859-1,utf-8", "utf-8");
- check1(client, "utf-8;q=0.9,iso-8859-1;q=0.1", "utf-8");
- check1(client, "utf-8;q=0.1,iso-8859-1;q=0.9", "iso-8859-1");
- check1(client, "*", "utf-8");
- check1(client, "bad,iso-8859-1;q=0.5,*;q=0.1", "iso-8859-1");
- check1(client, "bad,iso-8859-1;q=0.1,*;q=0.5", "utf-8");
- }
-
- private void check1(RestClient client, String requestCharset, String
responseCharset) throws Exception {
- RestCall r;
- debug=true;
- InputStream is;
- String url = "/testAcceptCharset/testQValues";
- r = client.doGet(url).acceptCharset(requestCharset).connect();
-
-
assertTrue(r.getResponse().getFirstHeader("Content-Type").getValue().toLowerCase().contains(responseCharset));
- is = r.getInputStream();
- assertEquals("foo", read(new InputStreamReader(is,
responseCharset)));
- }
-
-
//====================================================================================================
- // Validate various Accept-Charset variations.
-
//====================================================================================================
- @Test
- public void testCharsetOnResponse() throws Exception {
- RestClient client = TestMicroservice.DEFAULT_CLIENT_PLAINTEXT;
- String url = "/testAcceptCharset/testCharsetOnResponse";
- String r;
-
- r = client.doPut(url, new
StringReader("")).getResponseAsString();
- assertEquals("utf-8/utf-8", r.toLowerCase());
-
- r = client.doPut(url, new
StringReader("")).acceptCharset("Shift_JIS").getResponseAsString();
- assertEquals("utf-8/shift_jis", r.toLowerCase());
-
- try {
- r = client.doPut(url+"?noTrace=true", new
StringReader("")).acceptCharset("BAD").getResponseAsString();
- fail("Exception expected");
- } catch (RestCallException e) {
- checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, "No
supported charsets in header 'Accept-Charset': 'BAD'");
- }
-
- r = client.doPut(url, new
StringReader("")).acceptCharset("UTF-8").getResponseAsString();
- assertEquals("utf-8/utf-8", r.toLowerCase());
-
- r = client.doPut(url, new
StringReader("")).acceptCharset("bad,iso-8859-1").getResponseAsString();
- assertEquals("utf-8/iso-8859-1", r.toLowerCase());
-
- r = client.doPut(url, new
StringReader("")).acceptCharset("bad;q=0.9,iso-8859-1;q=0.1").getResponseAsString();
- assertEquals("utf-8/iso-8859-1", r.toLowerCase());
-
- r = client.doPut(url, new
StringReader("")).acceptCharset("bad;q=0.1,iso-8859-1;q=0.9").getResponseAsString();
- assertEquals("utf-8/iso-8859-1", r.toLowerCase());
-
- client =
TestMicroservice.client().accept("text/plain").contentType("text/plain").acceptCharset("utf-8").build();
-
- r = client.doPut(url, new
StringReader("")).contentType("text/plain").getResponseAsString();
- assertEquals("utf-8/utf-8", r.toLowerCase());
-
- r = client.doPut(url, new
StringReader("")).contentType("text/plain;charset=utf-8").getResponseAsString();
- assertEquals("utf-8/utf-8", r.toLowerCase());
-
- r = client.doPut(url, new
StringReader("")).contentType("text/plain;charset=UTF-8").getResponseAsString();
- assertEquals("utf-8/utf-8", r.toLowerCase());
-
- r = client.doPut(url, new
StringReader("")).contentType("text/plain;charset=iso-8859-1").getResponseAsString();
- assertEquals("iso-8859-1/utf-8", r.toLowerCase());
-
- r = client.doPut(url, new
StringReader("")).contentType("text/plain;charset=Shift_JIS").getResponseAsString();
- assertEquals("shift_jis/utf-8", r.toLowerCase());
-
- try {
- r = client.doPut(url +
"?noTrace=true&Content-Type=text/plain;charset=BAD", new
StringReader("")).getResponseAsString();
- fail("Exception expected");
- } catch (RestCallException e) {
- checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
"Unsupported charset in header 'Content-Type': 'text/plain;charset=BAD'");
- }
-
- client.closeQuietly();
- }
-}
\ No newline at end of file
diff --git
a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/BeanContextPropertiesTest.java
b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/BeanContextPropertiesTest.java
deleted file mode 100644
index 1e583a5..0000000
---
a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/BeanContextPropertiesTest.java
+++ /dev/null
@@ -1,34 +0,0 @@
-//
***************************************************************************************************************************
-// * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file *
-// * distributed with this work for additional information regarding copyright
ownership. The ASF licenses this file *
-// * to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance *
-// * with the License. You may obtain a copy of the License at
*
-// *
*
-// * http://www.apache.org/licenses/LICENSE-2.0
*
-// *
*
-// * Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an *
-// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the *
-// * specific language governing permissions and limitations under the
License. *
-//
***************************************************************************************************************************
-package org.apache.juneau.rest.test;
-
-import static org.junit.Assert.*;
-
-import org.apache.juneau.rest.client.*;
-import org.junit.*;
-
-public class BeanContextPropertiesTest extends RestTestcase {
-
- boolean debug = false;
-
-
//====================================================================================================
- // Validate that filters defined on class filter to underlying bean
context.
-
//====================================================================================================
- @Test
- public void testClassTransforms() throws Exception {
- RestClient client = TestMicroservice.DEFAULT_CLIENT;
- String r;
- r =
client.doGet("/testBeanContext/testClassTransforms/2001-07-04T15:30:45Z?d2=2001-07-05T15:30:45Z").header("X-D3",
"2001-07-06T15:30:45Z").getResponseAsString();
-
assertEquals("d1=2001-07-04T15:30:45Z,d2=2001-07-05T15:30:45Z,d3=2001-07-06T15:30:45Z",
r);
- }
-}
\ No newline at end of file
diff --git
a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/_TestSuite.java
b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/_TestSuite.java
index 589f004..04d902a 100644
---
a/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/_TestSuite.java
+++
b/juneau-microservice/juneau-microservice-test/src/test/java/org/apache/juneau/rest/test/_TestSuite.java
@@ -24,8 +24,6 @@ import org.junit.runners.Suite.*;
*/
@RunWith(Suite.class)
@SuiteClasses({
- AcceptCharsetTest.class,
- BeanContextPropertiesTest.class,
CallbackStringsTest.class,
CharsetEncodingsTest.class,
ClientFuturesTest.class,
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/mock/MockServletRequest.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/mock/MockServletRequest.java
index 5be2550..3f4de59 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/mock/MockServletRequest.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/mock/MockServletRequest.java
@@ -1017,4 +1017,14 @@ public class MockServletRequest implements
HttpServletRequest {
public MockServletRequest acceptLanguage(String value) {
return header("Accept-Language", value);
}
+
+ /**
+ * Specifies the <code>Accept-Charset</code> header value on the
request.
+ *
+ * @param value The new value.
+ * @return This object (for method chaining).
+ */
+ public MockServletRequest acceptCharset(String value) {
+ return header("Accept-Charset", value);
+ }
}
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/mock/MockServletResponse.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/mock/MockServletResponse.java
index f9845c6..d85c7d1 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/mock/MockServletResponse.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/mock/MockServletResponse.java
@@ -310,4 +310,17 @@ public class MockServletResponse implements
HttpServletResponse {
throw new AssertionError(MessageFormat.format("Response
did not have the expected text. expected=[{0}], actual=[{1}]", text,
getBodyAsString()));
return this;
}
+
+ /**
+ * Throws an {@link AssertionError} if the response does not contain
the expected character encoding.
+ *
+ * @param value The expected character encoding.
+ * @return This object (for method chaining).
+ * @throws AssertionError Thrown if the response does not contain the
expected character encoding.
+ */
+ public MockServletResponse assertCharset(String value) {
+ if (! StringUtils.isEquals(value, getCharacterEncoding()))
+ throw new AssertionError(MessageFormat.format("Response
did not have the expected character encoding. expected=[{0}], actual=[{1}]",
value, getBodyAsString()));
+ return this;
+ }
}
diff --git
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/AcceptCharsetTest.java
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/AcceptCharsetTest.java
new file mode 100644
index 0000000..4bbee68
--- /dev/null
+++
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/AcceptCharsetTest.java
@@ -0,0 +1,118 @@
+//
***************************************************************************************************************************
+// * 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;
+
+import static org.apache.juneau.http.HttpMethodName.*;
+
+import java.io.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.plaintext.*;
+import org.apache.juneau.rest.annotation.*;
+import org.apache.juneau.rest.mock.*;
+import org.apache.juneau.serializer.*;
+import org.junit.*;
+
+/**
+ * Validates the handling of the Accept-Charset header.
+ */
+@SuppressWarnings("javadoc")
+public class AcceptCharsetTest {
+
+
//====================================================================================================
+ // Test that Q-values are being resolved correctly.
+
//====================================================================================================
+
+
@RestResource(defaultCharset="utf-8",serializers=PlainTextSerializer.class)
+ public static class A {
+ @RestMethod(name=GET)
+ public String qValues() {
+ return "foo";
+ }
+ }
+ static MockRest a = MockRest.create(A.class);
+
+ @Test
+ public void a01_qValues() throws Exception {
+ a.request("GET",
"/").accept("text/plain").acceptCharset("utf-8").execute().assertCharset("utf-8");
+ a.request("GET",
"/").accept("text/plain").acceptCharset("iso-8859-1").execute().assertCharset("iso-8859-1");
+ a.request("GET",
"/").accept("text/plain").acceptCharset("bad,utf-8").execute().assertCharset("utf-8");
+ a.request("GET",
"/").accept("text/plain").acceptCharset("utf-8,bad").execute().assertCharset("utf-8");
+ a.request("GET",
"/").accept("text/plain").acceptCharset("bad;q=0.9,utf-8;q=0.1").execute().assertCharset("utf-8");
+ a.request("GET",
"/").accept("text/plain").acceptCharset("bad;q=0.1,utf-8;q=0.9").execute().assertCharset("utf-8");
+ a.request("GET",
"/").accept("text/plain").acceptCharset("utf-8;q=0.9,iso-8859-1;q=0.1").execute().assertCharset("utf-8");
+ a.request("GET",
"/").accept("text/plain").acceptCharset("utf-8;q=0.1,iso-8859-1;q=0.9").execute().assertCharset("iso-8859-1");
+ a.request("GET",
"/").accept("text/plain").acceptCharset("*").execute().assertCharset("utf-8");
+ a.request("GET",
"/").accept("text/plain").acceptCharset("bad,iso-8859-1;q=0.5,*;q=0.1").execute().assertCharset("iso-8859-1");
+ a.request("GET",
"/").accept("text/plain").acceptCharset("bad,iso-8859-1;q=0.1,*;q=0.5").execute().assertCharset("utf-8");
+ }
+
+
//====================================================================================================
+ // Validate various Accept-Charset variations.
+
//====================================================================================================
+
+ @RestResource(defaultCharset="utf-8")
+ public static class B {
+
+ @RestMethod(name=PUT, parsers=TestParser.class,
serializers=TestSerializer.class)
+ public String charsetOnResponse(@Body String in) {
+ return in;
+ }
+
+ public static class TestParser extends InputStreamParser {
+ public TestParser(PropertyStore ps) {
+ super(ps, "text/plain");
+ }
+ @Override /* Parser */
+ public InputStreamParserSession
createSession(ParserSessionArgs args) {
+ return new InputStreamParserSession(args) {
+ @Override /* ParserSession */
+ @SuppressWarnings("unchecked")
+ protected <T> T doParse(ParserPipe
pipe, ClassMeta<T> type) throws Exception {
+ return
(T)getProperty("characterEncoding", String.class);
+ }
+ };
+ }
+ }
+
+ public static class TestSerializer extends
OutputStreamSerializer {
+ public TestSerializer(PropertyStore ps) {
+ super(ps, "text/plain", null);
+ }
+ @Override /* Serializer */
+ public OutputStreamSerializerSession
createSession(SerializerSessionArgs args) {
+ return new OutputStreamSerializerSession(args) {
+ @Override /* SerializerSession */
+ protected void
doSerialize(SerializerPipe out, Object o) throws Exception {
+ try (Writer w = new
OutputStreamWriter(out.getOutputStream())) {
+
w.append(o.toString()).append('/').append(getProperty("characterEncoding",
String.class));
+ }
+ }
+ };
+ }
+ }
+ }
+ static MockRest b = MockRest.create(B.class);
+
+ @Test
+ public void b01_testCharsetOnResponse() throws Exception {
+ b.request("PUT",
"/").plainText().execute().assertBody("utf-8/utf-8");
+ b.request("PUT",
"/").plainText().acceptCharset("Shift_JIS").execute().assertBody("utf-8/Shift_JIS");
+ b.request("PUT",
"?noTrace=true").plainText().acceptCharset("BAD").execute().assertStatus(406).assertBodyContains("No
supported charsets in header 'Accept-Charset': 'BAD'");
+ b.request("PUT",
"/").plainText().acceptCharset("UTF-8").execute().assertBody("utf-8/UTF-8");
+ b.request("PUT",
"/").plainText().acceptCharset("bad,iso-8859-1").execute().assertBody("utf-8/iso-8859-1");
+ b.request("PUT",
"/").plainText().acceptCharset("bad;q=0.9,iso-8859-1;q=0.1").execute().assertBody("utf-8/iso-8859-1");
+ b.request("PUT",
"/").plainText().acceptCharset("bad;q=0.1,iso-8859-1;q=0.9").execute().assertBody("utf-8/iso-8859-1");
+ }
+}
diff --git
a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/BeanContextPropertiesResource.java
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/BeanContextPropertiesTest.java
similarity index 63%
rename from
juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/BeanContextPropertiesResource.java
rename to
juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/BeanContextPropertiesTest.java
index 910ae99..32ababb 100644
---
a/juneau-microservice/juneau-microservice-test/src/main/java/org/apache/juneau/rest/test/BeanContextPropertiesResource.java
+++
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/BeanContextPropertiesTest.java
@@ -10,37 +10,44 @@
// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the *
// * specific language governing permissions and limitations under the
License. *
//
***************************************************************************************************************************
-package org.apache.juneau.rest.test;
+package org.apache.juneau.rest;
import static org.apache.juneau.http.HttpMethodName.*;
-import java.io.*;
import java.util.*;
import org.apache.juneau.*;
-import org.apache.juneau.rest.*;
import org.apache.juneau.rest.annotation.*;
+import org.apache.juneau.rest.mock.*;
import org.apache.juneau.transforms.*;
+import org.junit.*;
+import org.junit.runners.*;
/**
- * JUnit automated testcase resource.
+ * Tests related bean context properties in REST resources.
*/
-@RestResource(
- path="/testBeanContext",
- pojoSwaps=DateSwap.ISO8601DTZ.class
-)
-public class BeanContextPropertiesResource extends BasicRestServlet {
- private static final long serialVersionUID = 1L;
+@SuppressWarnings({"javadoc"})
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class BeanContextPropertiesTest {
//====================================================================================================
// Validate that transforms defined on class transform to underlying
bean context.
//====================================================================================================
- @RestMethod(name=GET, path="/testClassTransforms/{d1}")
- public Reader testClassTransforms(@Path("d1") Date d1, @Query("d2")
Date d2, @Header("X-D3") Date d3) throws Exception {
- DateSwap df = DateSwap.ISO8601DTZ.class.newInstance();
- BeanSession session = BeanContext.DEFAULT.createSession();
- return new StringReader(
- "d1="+df.swap(session, d1)+",d2="+df.swap(session,
d2)+",d3="+df.swap(session, d3)+""
- );
+
+ @RestResource(pojoSwaps=DateSwap.ISO8601DTZ.class)
+ public static class A {
+ @RestMethod(name=GET, path="/{d1}")
+ public String testClassTransforms(@Path("d1") Date d1,
@Query("d2") Date d2, @Header("X-D3") Date d3) throws Exception {
+ DateSwap df = DateSwap.ISO8601DTZ.class.newInstance();
+ BeanSession session =
BeanContext.DEFAULT.createSession();
+ return "d1="+df.swap(session,
d1)+",d2="+df.swap(session, d2)+",d3="+df.swap(session, d3)+"";
+ }
+ }
+ static MockRest a = MockRest.create(A.class);
+
+ @Test
+ public void a01_testClassTransforms() throws Exception {
+ a.request("GET",
"/2001-07-04T15:30:45Z?d2=2001-07-05T15:30:45Z").header("X-D3",
"2001-07-06T15:30:45Z").execute()
+
.assertBody("d1=2001-07-04T15:30:45Z,d2=2001-07-05T15:30:45Z,d3=2001-07-06T15:30:45Z");
}
-}
+}
\ No newline at end of file
diff --git
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/StatusCodesTest.java
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/StatusCodesTest.java
index d4fac10..7ff36d7 100644
---
a/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/StatusCodesTest.java
+++
b/juneau-rest/juneau-rest-server/src/test/java/org/apache/juneau/rest/StatusCodesTest.java
@@ -20,11 +20,13 @@ import org.apache.juneau.json.*;
import org.apache.juneau.rest.annotation.*;
import org.apache.juneau.rest.mock.*;
import org.junit.*;
+import org.junit.runners.*;
/**
* Validates that the correct status codes are returned on REST requests.
*/
-@SuppressWarnings("javadoc")
+@SuppressWarnings({"javadoc"})
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class StatusCodesTest {
//=================================================================================================================
--
To stop receiving notification emails like this one, please contact
[email protected].