You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by ja...@apache.org on 2016/09/15 21:25:30 UTC
[05/20] incubator-juneau git commit: Clean up Javadocs
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d45e1351/juneau-server-test/src/test/java/org/apache/juneau/server/test/DefaultContentTypesTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/test/DefaultContentTypesTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/test/DefaultContentTypesTest.java
new file mode 100755
index 0000000..28bb43c
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/test/DefaultContentTypesTest.java
@@ -0,0 +1,497 @@
+// ***************************************************************************************************************************
+// * 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.server.test;
+
+import static javax.servlet.http.HttpServletResponse.*;
+import static org.apache.juneau.server.test.TestUtils.*;
+import static org.junit.Assert.*;
+
+import org.apache.juneau.client.*;
+import org.apache.juneau.json.*;
+import org.junit.*;
+
+
+public class DefaultContentTypesTest {
+
+ private static String URL = "/testDefaultContentTypes";
+ private static boolean debug = false;
+
+ //====================================================================================================
+ // Test that default Accept and Content-Type headers on servlet annotation are picked up.
+ //====================================================================================================
+ @Test
+ public void testDefaultHeadersOnServletAnnotation() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ String r;
+
+ String url = URL + "/testDefaultHeadersOnServletAnnotation";
+
+ client.setAccept("").setContentType("");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s2/p2", r);
+
+ client.setAccept("text/s1").setContentType("");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s1/p2", r);
+
+ client.setAccept("").setContentType("text/p1");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s2/p1", r);
+
+ client.setAccept("text/s1").setContentType("text/p1");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s1/p1", r);
+
+ client.setAccept("text/s2").setContentType("");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s2/p2", r);
+
+ client.setAccept("").setContentType("text/p2");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s2/p2", r);
+
+ client.setAccept("text/s2").setContentType("text/p2");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s2/p2", r);
+
+ try {
+ client.setAccept("text/s3").setContentType("");
+ r = client.doPut(url+"?noTrace=true", "").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE,
+ "Unsupported media-type in request header 'Accept': 'text/s3'",
+ "Supported media-types: [text/s1, text/s2]"
+ );
+ }
+
+ try {
+ client.setAccept("").setContentType("text/p3");
+ r = client.doPut(url+"?noTrace=true", "").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
+ "Unsupported media-type in request header 'Content-Type': 'text/p3'",
+ "Supported media-types: [text/p1, text/p2]"
+ );
+ }
+
+ try {
+ client.setAccept("text/s3").setContentType("text/p3");
+ r = client.doPut(url+"?noTrace=true", "").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
+ "Unsupported media-type in request header 'Content-Type': 'text/p3'",
+ "Supported media-types: [text/p1, text/p2]"
+ );
+ }
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Test that default Accept and Content-Type headers on servlet annotation are picked up
+ // when @RestMethod.parsers/serializers annotations are used.
+ //====================================================================================================
+ @Test
+ public void testRestMethodParsersSerializers() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ String r;
+
+ String url = URL + "/testRestMethodParsersSerializers";
+
+ try {
+ client.setAccept("").setContentType("");
+ r = client.doPut(url+"?noTrace=true", "").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
+ "Unsupported media-type in request header 'Content-Type': 'text/p2'",
+ "Supported media-types: [text/p3]"
+ );
+ }
+
+ try {
+ client.setAccept("text/s1").setContentType("");
+ r = client.doPut(url+"?noTrace=true", "").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
+ "Unsupported media-type in request header 'Content-Type': 'text/p2'",
+ "Supported media-types: [text/p3]"
+ );
+ }
+
+ try {
+ client.setAccept("").setContentType("text/p1");
+ r = client.doPut(url+"?noTrace=true", "").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
+ "Unsupported media-type in request header 'Content-Type': 'text/p1'",
+ "Supported media-types: [text/p3]"
+ );
+ }
+
+ try {
+ client.setAccept("text/s1").setContentType("text/p1");
+ r = client.doPut(url+"?noTrace=true", "").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
+ "Unsupported media-type in request header 'Content-Type': 'text/p1'",
+ "Supported media-types: [text/p3]"
+ );
+ }
+
+ try {
+ client.setAccept("text/s2").setContentType("");
+ r = client.doPut(url+"?noTrace=true", "").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
+ "Unsupported media-type in request header 'Content-Type': 'text/p2'",
+ "Supported media-types: [text/p3]"
+ );
+ }
+
+ try {
+ client.setAccept("").setContentType("text/p2");
+ r = client.doPut(url+"?noTrace=true", "").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
+ "Unsupported media-type in request header 'Content-Type': 'text/p2'",
+ "Supported media-types: [text/p3]"
+ );
+ }
+
+ try {
+ client.setAccept("text/s2").setContentType("text/p2");
+ r = client.doPut(url+"?noTrace=true", "").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
+ "Unsupported media-type in request header 'Content-Type': 'text/p2'",
+ "Supported media-types: [text/p3]"
+ );
+ }
+
+ try {
+ client.setAccept("text/s3").setContentType("");
+ r = client.doPut(url+"?noTrace=true", "").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
+ "Unsupported media-type in request header 'Content-Type': 'text/p2'",
+ "Supported media-types: [text/p3]"
+ );
+ }
+
+ try {
+ client.setAccept("").setContentType("text/p3");
+ r = client.doPut(url+"?noTrace=true", "").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE,
+ "Unsupported media-type in request header 'Accept': 'text/s2'",
+ "Supported media-types: [text/s3]"
+ );
+ }
+
+ client.setAccept("text/s3").setContentType("text/p3");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s3/p3", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Test that default Accept and Content-Type headers on servlet annotation are picked up
+ // when @RestMethod.addParsers/addSerializers annotations are used.
+ //====================================================================================================
+ @Test
+ public void testRestMethodAddParsersSerializers() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ String r;
+
+ String url = URL + "/testRestMethodAddParsersSerializers";
+
+ client.setAccept("").setContentType("");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s2/p2", r);
+
+ client.setAccept("text/s1").setContentType("");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s1/p2", r);
+
+ client.setAccept("").setContentType("text/p1");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s2/p1", r);
+
+ client.setAccept("text/s1").setContentType("text/p1");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s1/p1", r);
+
+ client.setAccept("text/s2").setContentType("");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s2/p2", r);
+
+ client.setAccept("").setContentType("text/p2");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s2/p2", r);
+
+ client.setAccept("text/s2").setContentType("text/p2");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s2/p2", r);
+
+ client.setAccept("text/s3").setContentType("");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s3/p2", r);
+
+ client.setAccept("").setContentType("text/p3");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s2/p3", r);
+
+ client.setAccept("text/s3").setContentType("text/p3");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s3/p3", r);
+
+ try {
+ client.setAccept("").setContentType("text/p4");
+ r = client.doPut(url+"?noTrace=true", "").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ // Note that parsers defined on method are listed before parsers defined on class.
+ checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
+ "Unsupported media-type in request header 'Content-Type': 'text/p4'",
+ "Supported media-types: [text/p3, text/p1, text/p2]"
+ );
+ }
+
+ try {
+ client.setAccept("text/s4").setContentType("");
+ r = client.doPut(url+"?noTrace=true", "").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ // Note that serializers defined on method are listed before serializers defined on class.
+ checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE,
+ "Unsupported media-type in request header 'Accept': 'text/s4'",
+ "Supported media-types: [text/s3, text/s1, text/s2]"
+ );
+ }
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Various Accept incantations.
+ //====================================================================================================
+ @Test
+ public void testAccept() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT).setContentType("text/p1");
+ String r;
+
+ String url = URL + "/testAccept";
+
+ // "*/*" should match the first serializer, not the default serializer.
+ client.setAccept("*/*");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s1/p1", r);
+
+ // "text/*" should match the first serializer, not the default serializer.
+ client.setAccept("text/*");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s1/p1", r);
+
+ try {
+ client.setAccept("bad/*");
+ r = client.doPut(url+"?noTrace=true", "").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE,
+ "Unsupported media-type in request header 'Accept': 'bad/*'",
+ "Supported media-types: [text/s1, text/s2]"
+ );
+ }
+
+ client.setAccept("bad/*,text/*");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s1/p1", r);
+
+ client.setAccept("text/*,bad/*");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s1/p1", r);
+
+ client.setAccept("text/s1;q=0.5,text/s2");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s2/p1", r);
+
+ client.setAccept("text/s1,text/s2;q=0.5");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s1/p1", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Test that default Accept and Content-Type headers on method annotation are picked up
+ // when @RestMethod.parsers/serializers annotations are used.
+ //====================================================================================================
+ @Test
+ public void testRestMethodParserSerializerAnnotations() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ String r;
+
+ String url = URL + "/testRestMethodParserSerializerAnnotations";
+
+ client.setAccept("").setContentType("");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s3/p3", r);
+
+ try {
+ client.setAccept("text/s1").setContentType("");
+ r = client.doPut(url+"?noTrace=true", "").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE,
+ "Unsupported media-type in request header 'Accept': 'text/s1'",
+ "Supported media-types: [text/s3]"
+ );
+ }
+
+ try {
+ client.setAccept("").setContentType("text/p1");
+ r = client.doPut(url+"?noTrace=true", "").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
+ "Unsupported media-type in request header 'Content-Type': 'text/p1'",
+ "Supported media-types: [text/p3]"
+ );
+ }
+
+ try {
+ client.setAccept("text/s1").setContentType("text/p1");
+ r = client.doPut(url+"?noTrace=true", "").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
+ "Unsupported media-type in request header 'Content-Type': 'text/p1'",
+ "Supported media-types: [text/p3]"
+ );
+ }
+
+ try {
+ client.setAccept("text/s2").setContentType("");
+ r = client.doPut(url+"?noTrace=true", "").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE,
+ "Unsupported media-type in request header 'Accept': 'text/s2'",
+ "Supported media-types: [text/s3]"
+ );
+ }
+
+ try {
+ client.setAccept("").setContentType("text/p2");
+ r = client.doPut(url+"?noTrace=true", "").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
+ "Unsupported media-type in request header 'Content-Type': 'text/p2'",
+ "Supported media-types: [text/p3]"
+ );
+ }
+
+ try {
+ client.setAccept("text/s2").setContentType("text/p2");
+ r = client.doPut(url+"?noTrace=true", "").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
+ "Unsupported media-type in request header 'Content-Type': 'text/p2'",
+ "Supported media-types: [text/p3]"
+ );
+ }
+
+ client.setAccept("text/s3").setContentType("");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s3/p3", r);
+
+ client.setAccept("").setContentType("text/p3");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s3/p3", r);
+
+ client.setAccept("text/s3").setContentType("text/p3");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s3/p3", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Test that default Accept and Content-Type headers on method annotation are picked up
+ // when @RestMethod.addParsers/addSerializers annotations are used.
+ //====================================================================================================
+ @Test
+ public void testRestMethodAddParsersSerializersAnnotations() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ String r;
+
+ String url = URL + "/testRestMethodAddParsersSerializersAnnotations";
+
+ client.setAccept("").setContentType("");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s3/p3", r);
+
+ client.setAccept("text/s1").setContentType("");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s1/p3", r);
+
+ client.setAccept("").setContentType("text/p1");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s3/p1", r);
+
+ client.setAccept("text/s1").setContentType("text/p1");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s1/p1", r);
+
+ client.setAccept("text/s2").setContentType("");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s2/p3", r);
+
+ client.setAccept("").setContentType("text/p2");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s3/p2", r);
+
+ client.setAccept("text/s2").setContentType("text/p2");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s2/p2", r);
+
+ client.setAccept("text/s3").setContentType("");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s3/p3", r);
+
+ client.setAccept("").setContentType("text/p3");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s3/p3", r);
+
+ client.setAccept("text/s3").setContentType("text/p3");
+ r = client.doPut(url, "").getResponseAsString();
+ assertEquals("s3/p3", r);
+
+ client.closeQuietly();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d45e1351/juneau-server-test/src/test/java/org/apache/juneau/server/test/ErrorConditionsTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/test/ErrorConditionsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/test/ErrorConditionsTest.java
new file mode 100755
index 0000000..46364cc
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/test/ErrorConditionsTest.java
@@ -0,0 +1,220 @@
+// ***************************************************************************************************************************
+// * 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.server.test;
+
+import static javax.servlet.http.HttpServletResponse.*;
+import static org.apache.juneau.server.test.TestUtils.*;
+import static org.junit.Assert.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.client.*;
+import org.apache.juneau.json.*;
+import org.junit.*;
+
+
+public class ErrorConditionsTest {
+
+ private static String URL = "/testErrorConditions";
+ private static boolean debug = false;
+ private static RestClient client;
+
+ @BeforeClass
+ public static void beforeClass() {
+ client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ }
+
+ @AfterClass
+ public static void afterClass() {
+ client.closeQuietly();
+ }
+ //====================================================================================================
+ // Test non-existent properties
+ //====================================================================================================
+ @Test
+ public void testNonExistentBeanProperties() throws Exception {
+ String url = URL + "/testNonExistentBeanProperties";
+
+ try {
+ client.doPut(url + "?noTrace=true", new ObjectMap("{f2:'foo'}")).getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_BAD_REQUEST,
+ "Could not convert request body content to class type 'org.apache.juneau.server.test.ErrorConditionsResource$Test1' using parser 'org.apache.juneau.json.JsonParser'",
+ "Unknown property 'f2' encountered while trying to parse into class 'org.apache.juneau.server.test.ErrorConditionsResource$Test1'");
+ }
+
+ try {
+ client.doPut(url + "?noTrace=true", new ObjectMap("{f1:'foo', f2:'foo'}")).getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_BAD_REQUEST,
+ "Could not convert request body content to class type 'org.apache.juneau.server.test.ErrorConditionsResource$Test1' using parser 'org.apache.juneau.json.JsonParser'",
+ "Unknown property 'f2' encountered while trying to parse into class 'org.apache.juneau.server.test.ErrorConditionsResource$Test1'");
+ }
+ }
+
+ //====================================================================================================
+ // Test trying to set properties to wrong data type
+ //====================================================================================================
+ @Test
+ public void testWrongDataType() throws Exception {
+ String url = URL + "/testWrongDataType";
+ try {
+ client.doPut(url + "?noTrace=true", new ObjectMap("{f1:'foo'}")).getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_BAD_REQUEST,
+ "Could not convert request body content to class type 'org.apache.juneau.server.test.ErrorConditionsResource$Test2' using parser 'org.apache.juneau.json.JsonParser'.",
+ "Could not convert string 'foo' to class 'int'");
+ }
+ }
+
+ //====================================================================================================
+ // Test trying to parse into class with non-public no-arg constructor.
+ //====================================================================================================
+ @Test
+ public void testParseIntoNonConstructableBean() throws Exception {
+ String url = URL + "/testParseIntoNonConstructableBean";
+ try {
+ client.doPut(url + "?noTrace=true", new ObjectMap("{f1:1}")).getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_BAD_REQUEST,
+ "Class 'org.apache.juneau.server.test.ErrorConditionsResource$Test3a' could not be instantiated.");
+ }
+ }
+
+ //====================================================================================================
+ // Test trying to parse into non-static inner class
+ //====================================================================================================
+ @Test
+ public void testParseIntoNonStaticInnerClass() throws Exception {
+ String url = URL + "/testParseIntoNonStaticInnerClass";
+ try {
+ client.doPut(url + "?noTrace=true", new ObjectMap("{f1:1}")).getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_BAD_REQUEST,
+ "Class 'org.apache.juneau.server.test.ErrorConditionsResource$Test3b' could not be instantiated. Reason: 'No properties detected on bean class'");
+ }
+ }
+
+ //====================================================================================================
+ // Test trying to parse into non-public inner class
+ //====================================================================================================
+ @Test
+ public void testParseIntoNonPublicInnerClass() throws Exception {
+ String url = URL + "/testParseIntoNonPublicInnerClass";
+ try {
+ client.doPut(url + "?noTrace=true", new ObjectMap("{f1:1}")).getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_BAD_REQUEST,
+ "Class 'org.apache.juneau.server.test.ErrorConditionsResource$Test3b1' could not be instantiated",
+ "Class is not public");
+ }
+ }
+
+ //====================================================================================================
+ // Test exception thrown during bean construction.
+ //====================================================================================================
+ @Test
+ public void testThrownConstructorException() throws Exception {
+ String url = URL + "/testThrownConstructorException";
+ try {
+ client.doPut(url + "?noTrace=true", "'foo'").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_BAD_REQUEST,
+ "Could not convert request body content to class type 'org.apache.juneau.server.test.ErrorConditionsResource$Test3c' using parser 'org.apache.juneau.json.JsonParser'.",
+ "Caused by (RuntimeException): Test error");
+ }
+ }
+
+ //====================================================================================================
+ // Test trying to set parameters to invalid types.
+ //====================================================================================================
+ @Test
+ public void testSetParameterToInvalidTypes() throws Exception {
+ String url = URL + "/testSetParameterToInvalidTypes";
+ try {
+ client.doPut(url + "/1?noTrace=true&p1=foo", "").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_BAD_REQUEST,
+ "Could not convert PARAM 'p1' to type 'int' on method 'org.apache.juneau.server.test.ErrorConditionsResource.testSetParameterToInvalidTypes'");
+ }
+
+ try {
+ client.doPut(url + "/foo?noTrace=true&p1=1", "").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_BAD_REQUEST,
+ "Could not convert ATTR 'a1' to type 'int' on method 'org.apache.juneau.server.test.ErrorConditionsResource.testSetParameterToInvalidTypes'");
+ }
+
+ try {
+ client.doPut(url + "/1?noTrace=true&p1=1", "").setHeader("h1", "foo").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_BAD_REQUEST,
+ "Could not convert HEADER 'h1' to type 'int' on method 'org.apache.juneau.server.test.ErrorConditionsResource.testSetParameterToInvalidTypes'");
+ }
+ }
+
+ //====================================================================================================
+ // Test SC_NOT_FOUND & SC_METHOD_NOT_ALLOWED
+ //====================================================================================================
+ @Test
+ public void test404and405() throws Exception {
+ String url = URL + "/test404and405";
+ try {
+ client.doGet(URL + "/testNonExistent?noTrace=true").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_FOUND,
+ "Method 'GET' not found on resource with matching pattern on path '/testNonExistent'");
+ }
+
+ try {
+ client.doPut(url + "?noTrace=true", "").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_FOUND,
+ "Method 'PUT' not found on resource with matching pattern on path '/test404and405'");
+ }
+
+ try {
+ client.doPost(url + "?noTrace=true", "").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_METHOD_NOT_ALLOWED,
+ "Method 'POST' not found on resource.");
+ }
+ }
+
+ //====================================================================================================
+ // Test SC_PRECONDITION_FAILED
+ //====================================================================================================
+ @Test
+ public void test412() throws Exception {
+ String url = URL + "/test412";
+ try {
+ client.doGet(url + "?noTrace=true").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_PRECONDITION_FAILED,
+ "Method 'GET' not found on resource on path '/test412' with matching matcher.");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d45e1351/juneau-server-test/src/test/java/org/apache/juneau/server/test/GroupsTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/test/GroupsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/test/GroupsTest.java
new file mode 100755
index 0000000..9fc58b3
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/test/GroupsTest.java
@@ -0,0 +1,122 @@
+// ***************************************************************************************************************************
+// * 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.server.test;
+
+import static javax.servlet.http.HttpServletResponse.*;
+import static org.apache.juneau.server.test.TestUtils.*;
+import static org.junit.Assert.*;
+
+import java.io.*;
+
+import org.apache.juneau.client.*;
+import org.apache.juneau.json.*;
+import org.junit.*;
+
+
+public class GroupsTest {
+
+ private static String URL = "/testGroups";
+ private static boolean debug = false;
+
+ //====================================================================================================
+ // Serializer defined on class.
+ //====================================================================================================
+ @Test
+ public void testSerializerDefinedOnClass() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ String url = URL + "/testSerializerDefinedOnClass";
+ String r;
+
+ try {
+ client.setContentType("text/p1");
+ r = client.doGet(url+"?noTrace=true").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE,
+ "Unsupported media-type in request header 'Accept': 'application/json'",
+ "Supported media-types: [text/s1, text/s2]"
+ );
+ }
+
+ client.setAccept("text/s1").setContentType("");
+ r = client.doGet(url).getResponseAsString();
+ assertEquals("text/s,GET", r);
+
+ client.setAccept("text/s2").setContentType("");
+ r = client.doGet(url).getResponseAsString();
+ assertEquals("text/s,GET", r);
+
+ try {
+ client.setAccept("text/s3").setContentType("");
+ r = client.doGet(url+"?noTrace=true").getResponseAsString();
+ assertEquals("text/s,GET", r);
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE,
+ "Unsupported media-type in request header 'Accept': 'text/s3'",
+ "Supported media-types: [text/s1, text/s2]"
+ );
+ }
+
+ try {
+ client.setAccept("text/json").setContentType("text/p1");
+ r = client.doPut(url+"?noTrace=true", new StringReader("foo")).getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE,
+ "Unsupported media-type in request header 'Accept': 'text/json'",
+ "Supported media-types: [text/s1, text/s2]"
+ );
+ }
+
+ try {
+ client.setAccept("text/s1").setContentType("text/json");
+ r = client.doPut(url+"?noTrace=true", new StringReader("foo")).getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
+ "Unsupported media-type in request header 'Content-Type': 'text/json'",
+ "Supported media-types: [text/p1, text/p2]"
+ );
+ }
+
+ client.setContentType("text/p1").setAccept("text/s1");
+ r = client.doPut(url, new StringReader("foo")).getResponseAsString();
+ assertEquals("text/s,foo", r);
+
+ client.setContentType("text/p2").setAccept("text/s2");
+ r = client.doPut(url, new StringReader("foo")).getResponseAsString();
+ assertEquals("text/s,foo", r);
+
+ try {
+ client.setContentType("text/p1").setAccept("text/s3");
+ r = client.doPut(url+"?noTrace=true", new StringReader("foo")).getResponseAsString();
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE,
+ "Unsupported media-type in request header 'Accept': 'text/s3'",
+ "Supported media-types: [text/s1, text/s2]"
+ );
+ }
+
+ try {
+ client.setContentType("text/p3").setAccept("text/s1");
+ r = client.doPut(url+"?noTrace=true", new StringReader("foo")).getResponseAsString();
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
+ "Unsupported media-type in request header 'Content-Type': 'text/p3'",
+ "Supported media-types: [text/p1, text/p2]"
+ );
+ }
+
+ client.closeQuietly();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d45e1351/juneau-server-test/src/test/java/org/apache/juneau/server/test/GzipTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/test/GzipTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/test/GzipTest.java
new file mode 100755
index 0000000..513c90d
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/test/GzipTest.java
@@ -0,0 +1,344 @@
+// ***************************************************************************************************************************
+// * 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.server.test;
+
+import static javax.servlet.http.HttpServletResponse.*;
+import static org.apache.juneau.server.test.TestUtils.*;
+import static org.junit.Assert.*;
+
+import java.io.*;
+import java.util.zip.*;
+
+import org.apache.http.impl.client.*;
+import org.apache.juneau.client.*;
+import org.apache.juneau.internal.*;
+import org.junit.*;
+
+/**
+ * Test Accept-Encoding and Content-Encoding handling.
+ *
+ * Note: WAS does automatic gzip decompression on http request messages, so we have to invent
+ * our own 'mycoding' compression.
+ */
+public class GzipTest {
+
+ private static boolean debug = false;
+
+ private static String testGzipOff = "/testGzipOff";
+ private static String testGzipOn = "/testGzipOn";
+
+ // Converts string into a GZipped input stream.
+ private static InputStream compress(String contents) throws Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(contents.length()>>1);
+ GZIPOutputStream gos = new GZIPOutputStream(baos);
+ gos.write(contents.getBytes());
+ gos.finish();
+ gos.close();
+ return new ByteArrayInputStream(baos.toByteArray());
+ }
+
+ private static String decompress(InputStream is) throws Exception {
+ return IOUtils.read(new GZIPInputStream(is));
+ }
+
+ //====================================================================================================
+ // Test with no compression enabled.
+ //====================================================================================================
+ @Test
+ public void testGzipOff() throws Exception {
+ RestClient c = new TestRestClient().setAccept("text/plain").setContentType("text/plain");
+ RestCall r;
+ String url = testGzipOff;
+
+ // *** GET ***
+
+ r = c.doGet(url);
+ assertEquals("foo", r.getResponseAsString());
+
+ r = c.doGet(url).setHeader("Accept-Encoding", "");
+ assertEquals("foo", r.getResponseAsString());
+
+ r = c.doGet(url).setHeader("Accept-Encoding", "*");
+ assertEquals("foo", r.getResponseAsString());
+
+ r = c.doGet(url).setHeader("Accept-Encoding", "identity");
+ assertEquals("foo", r.getResponseAsString());
+
+ // Should match identity.
+ r = c.doGet(url).setHeader("Accept-Encoding", "mycoding");
+ assertEquals("foo", r.getResponseAsString());
+
+ // Shouldn't match.
+ try {
+ r = c.doGet(url+"?noTrace=true").setHeader("Accept-Encoding", "mycoding,identity;q=0").connect();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE,
+ "Unsupported encoding in request header 'Accept-Encoding': 'mycoding,identity;q=0'",
+ "Supported codings: [identity]"
+ );
+ }
+
+ // Shouldn't match.
+ try {
+ c.doGet(url+"?noTrace=true").setHeader("Accept-Encoding", "mycoding,*;q=0").connect();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE,
+ "Unsupported encoding in request header 'Accept-Encoding': 'mycoding,*;q=0'",
+ "Supported codings: [identity]"
+ );
+ }
+
+ // Should match identity
+ r = c.doGet(url).setHeader("Accept-Encoding", "identity;q=0.8,mycoding;q=0.6");
+ assertEquals("foo", r.getResponseAsString());
+
+ // Should match identity
+ r = c.doGet(url).setHeader("Accept-Encoding", "mycoding;q=0.8,identity;q=0.6");
+ assertEquals("foo", r.getResponseAsString());
+
+ // Should match identity
+ r = c.doGet(url).setHeader("Accept-Encoding", "mycoding;q=0.8,*;q=0.6");
+ assertEquals("foo", r.getResponseAsString());
+
+ // Should match identity
+ r = c.doGet(url).setHeader("Accept-Encoding", "*;q=0.8,myencoding;q=0.6");
+ assertEquals("foo", r.getResponseAsString());
+
+ // Shouldn't match
+ try {
+ c.doGet(url+"?noTrace=true").setHeader("Accept-Encoding", "identity;q=0").connect();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE,
+ "Unsupported encoding in request header 'Accept-Encoding': 'identity;q=0'",
+ "Supported codings: [identity]"
+ );
+ }
+
+ // Shouldn't match
+ try {
+ c.doGet(url+"?noTrace=true").setHeader("Accept-Encoding", "identity;q=0.0").connect();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE,
+ "Unsupported encoding in request header 'Accept-Encoding': 'identity;q=0.0'",
+ "Supported codings: [identity]"
+ );
+ }
+
+ // Shouldn't match
+ try {
+ c.doGet(url+"?noTrace=true").setHeader("Accept-Encoding", "*;q=0").connect();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE,
+ "Unsupported encoding in request header 'Accept-Encoding': '*;q=0'",
+ "Supported codings: [identity]"
+ );
+ }
+
+ // Shouldn't match
+ try {
+ c.doGet(url+"?noTrace=true").setHeader("Accept-Encoding", "*;q=0.0").connect();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE,
+ "Unsupported encoding in request header 'Accept-Encoding': '*;q=0.0'",
+ "Supported codings: [identity]"
+ );
+ }
+
+
+ // *** PUT ***
+
+ r = c.doPut(url, new StringReader("foo"));
+ assertEquals("foo", r.getResponseAsString());
+
+ r = c.doPut(url, new StringReader("foo")).setHeader("Content-Encoding", "");
+ assertEquals("foo", r.getResponseAsString());
+
+ r = c.doPut(url, new StringReader("foo")).setHeader("Content-Encoding", "identity");
+ assertEquals("foo", r.getResponseAsString());
+
+ try {
+ c.doPut(url+"?noTrace=true", compress("foo")).setHeader("Content-Encoding", "mycoding").connect();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
+ "Unsupported encoding in request header 'Content-Encoding': 'mycoding'",
+ "Supported codings: [identity]"
+ );
+ }
+
+ c.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Test with compression enabled.
+ //====================================================================================================
+ @Test
+ public void testGzipOn() throws Exception {
+
+ // Create a client that disables content compression support so that we can get the gzipped content directly.
+ CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(TestRestClient.getSSLSocketFactory()).disableContentCompression().build();
+
+ RestClient c = new TestRestClient(httpClient).setAccept("text/plain").setContentType("text/plain");
+ RestCall r;
+ String url = testGzipOn;
+
+ // *** GET ***
+
+ r = c.doGet(url);
+ assertEquals("foo", r.getResponseAsString());
+
+ r = c.doGet(url).setHeader("Accept-Encoding", "");
+ assertEquals("foo", r.getResponseAsString());
+
+ r = c.doGet(url).setHeader("Accept-Encoding", "*");
+ assertEquals("foo", decompress(r.getInputStream()));
+
+ r = c.doGet(url).setHeader("Accept-Encoding", "identity");
+ assertEquals("foo", r.getResponseAsString());
+
+ // Should match identity.
+ r = c.doGet(url).setHeader("Accept-Encoding", "mycoding");
+ assertEquals("foo", decompress(r.getInputStream()));
+
+ r = c.doGet(url).setHeader("Accept-Encoding", "mycoding,identity;q=0").connect();
+ assertEquals("foo", decompress(r.getInputStream()));
+
+ r = c.doGet(url).setHeader("Accept-Encoding", "mycoding,*;q=0").connect();
+ assertEquals("foo", decompress(r.getInputStream()));
+
+ // Should match identity
+ r = c.doGet(url).setHeader("Accept-Encoding", "identity;q=0.8,mycoding;q=0.6");
+ assertEquals("foo", r.getResponseAsString());
+
+ // Should match mycoding
+ r = c.doGet(url).setHeader("Accept-Encoding", "mycoding;q=0.8,identity;q=0.6");
+ assertEquals("foo", decompress(r.getInputStream()));
+
+ // Should match mycoding
+ r = c.doGet(url).setHeader("Accept-Encoding", "mycoding;q=0.8,*;q=0.6");
+ assertEquals("foo", decompress(r.getInputStream()));
+
+ // Should match identity
+ r = c.doGet(url).setHeader("Accept-Encoding", "*;q=0.8,myencoding;q=0.6");
+ assertEquals("foo", decompress(r.getInputStream()));
+
+ // Shouldn't match
+ try {
+ c.doGet(url+"?noTrace=true").setHeader("Accept-Encoding", "identity;q=0").connect();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE,
+ "Unsupported encoding in request header 'Accept-Encoding': 'identity;q=0'",
+ "Supported codings: [mycoding, identity]"
+ );
+ }
+
+ // Shouldn't match
+ try {
+ c.doGet(url+"?noTrace=true").setHeader("Accept-Encoding", "identity;q=0.0").connect();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE,
+ "Unsupported encoding in request header 'Accept-Encoding': 'identity;q=0.0'",
+ "Supported codings: [mycoding, identity]"
+ );
+ }
+
+ // Shouldn't match
+ try {
+ c.doGet(url+"?noTrace=true").setHeader("Accept-Encoding", "*;q=0").connect();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE,
+ "Unsupported encoding in request header 'Accept-Encoding': '*;q=0'",
+ "Supported codings: [mycoding, identity]"
+ );
+ }
+
+ // Shouldn't match
+ try {
+ c.doGet(url+"?noTrace=true").setHeader("Accept-Encoding", "*;q=0.0").connect();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE,
+ "Unsupported encoding in request header 'Accept-Encoding': '*;q=0.0'",
+ "Supported codings: [mycoding, identity]"
+ );
+ }
+
+
+ // *** PUT ***
+
+ r = c.doPut(url, new StringReader("foo"));
+ assertEquals("foo", r.getResponseAsString());
+
+ r = c.doPut(url, new StringReader("foo")).setHeader("Content-Encoding", "");
+ assertEquals("foo", r.getResponseAsString());
+
+ r = c.doPut(url, new StringReader("foo")).setHeader("Content-Encoding", "identity");
+ assertEquals("foo", r.getResponseAsString());
+
+ r = c.doPut(url, compress("foo")).setHeader("Content-Encoding", "mycoding");
+ assertEquals("foo", r.getResponseAsString());
+
+ c.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Test with compression enabled but with servlet using output stream directly.
+ //====================================================================================================
+ @Test
+ public void testGzipOnDirect() throws Exception {
+ // Create a client that disables content compression support so that we can get the gzipped content directly.
+ CloseableHttpClient httpClient = HttpClientBuilder.create().setSSLSocketFactory(TestRestClient.getSSLSocketFactory()).build();
+ RestClient c = new TestRestClient(httpClient).setAccept("text/plain").setContentType("text/plain");
+ RestCall r = null;
+ String s = null;
+
+ // res.getOutputStream() called....should bypass encoding.
+ r = c.doGet(testGzipOn + "/direct").setHeader("Accept-Encoding", "mycoding");
+ s = r.getResponseAsString();
+ assertEquals("test", s);
+ assertTrue(r.getResponse().getHeaders("Content-Type")[0].getValue().contains("text/direct")); // Should get header set manually.
+ assertEquals(0, r.getResponse().getHeaders("Content-Encoding").length); // Should not be set.
+
+ // res.getWriter() called....should bypass encoding.
+ r = c.doGet(testGzipOn + "/direct2").setHeader("Accept-Encoding", "mycoding");
+ s = r.getResponseAsString();
+ assertEquals("test", s);
+ assertEquals(0, r.getResponse().getHeaders("Content-Encoding").length); // Should not be set.
+
+ // res.getNegotiateWriter() called....should NOT bypass encoding.
+ r = c.doGet(testGzipOn + "/direct3").setHeader("Accept-Encoding", "mycoding");
+ try {
+ assertEquals("mycoding", r.getResponse().getHeaders("content-encoding")[0].getValue());
+ } catch (RestCallException e) {
+ // OK - HttpClient doesn't know what mycoding is.
+ // Newer versions of HttpClient ignore this condition.
+ }
+
+ // res.getNegotiateWriter() called but @RestMethod(encoders={})...should bypass encoding.
+ r = c.doGet(testGzipOn + "/direct4").setHeader("Accept-Encoding", "mycoding");
+ s = r.getResponseAsString();
+ assertEquals("test", s);
+ assertEquals(0, r.getResponse().getHeaders("Content-Encoding").length); // Should not be set.
+
+ c.closeQuietly();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d45e1351/juneau-server-test/src/test/java/org/apache/juneau/server/test/InheritanceTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/test/InheritanceTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/test/InheritanceTest.java
new file mode 100755
index 0000000..27f70f8
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/test/InheritanceTest.java
@@ -0,0 +1,126 @@
+// ***************************************************************************************************************************
+// * 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.server.test;
+
+import static org.junit.Assert.*;
+
+import org.apache.juneau.client.*;
+import org.apache.juneau.json.*;
+import org.junit.*;
+
+public class InheritanceTest {
+
+ private static RestClient client;
+
+ @BeforeClass
+ public static void beforeClass() {
+ client = new TestRestClient();
+ }
+
+ @AfterClass
+ public static void afterClass() {
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Test serializer inheritance.
+ //====================================================================================================
+ @Test
+ public void testSerializers() throws Exception {
+ String r;
+ String url = "/testInheritanceSerializers";
+ r = client.doGet(url + "/test1").getResponseAsString();
+ assertEquals("['text/s3','text/s4','text/s1','text/s2']", r);
+
+ r = client.doGet(url + "/test2").getResponseAsString();
+ assertEquals("['text/s5']", r);
+
+ r = client.doGet(url + "/test3").getResponseAsString();
+ assertEquals("['text/s5','text/s3','text/s4','text/s1','text/s2']", r);
+ }
+
+ //====================================================================================================
+ // Test parser inheritance.
+ //====================================================================================================
+ @Test
+ public void testParsers() throws Exception {
+ String r;
+ String url = "/testInheritanceParsers";
+ r = client.doGet(url + "/test1").getResponseAsString();
+ assertEquals("['text/p3','text/p4','text/p1','text/p2']", r);
+
+ r = client.doGet(url + "/test2").getResponseAsString();
+ assertEquals("['text/p5']", r);
+
+ r = client.doGet(url + "/test3").getResponseAsString();
+ assertEquals("['text/p5','text/p3','text/p4','text/p1','text/p2']", r);
+ }
+
+ //====================================================================================================
+ // Test encoder inheritance.
+ //====================================================================================================
+ @Test
+ public void testEncoders() throws Exception {
+ String url = "/testInheritanceEncoders";
+ String r = client.doGet(url + "/test").getResponseAsString();
+ assertEquals("['e3','e4','e1','e2','identity']", r);
+ }
+
+ //====================================================================================================
+ // Test filter inheritance.
+ //====================================================================================================
+ @Test
+ public void testTransforms() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.class, JsonParser.class).setAccept("text/json+simple");
+ String r;
+ String url = "/testInheritanceTransforms";
+
+ r = client.doGet(url + "/test1").getResponseAsString();
+ assertEquals("['F1','F2','Foo3']", r);
+
+ r = client.doGet(url + "/test2").getResponseAsString();
+ assertEquals("['F1','F2','F3']", r);
+
+ r = client.doGet(url + "/test3").getResponseAsString();
+ assertEquals("['F1','F2','F3']", r);
+
+ r = client.doGet(url + "/test4").getResponseAsString();
+ assertEquals("['Foo1','Foo2','F3']", r);
+
+ r = client.doGet(url + "/test5").getResponseAsString();
+ assertEquals("['F1','F2','F3']", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Test properties inheritance.
+ //====================================================================================================
+ @Test
+ public void testProperties() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.class, JsonParser.class).setAccept("text/json+simple");
+ String r;
+ String url = "/testInheritanceProperties";
+
+ r = client.doGet(url + "/test1").getResponseAsString();
+ assertEquals("{p1:'v1',p2:'v2a',p3:'v3',p4:'v4'}", r);
+
+ r = client.doGet(url + "/test2?override").getResponseAsString();
+ assertEquals("{p1:'x',p2:'x',p3:'x',p4:'x',p5:'x'}", r);
+
+ r = client.doGet(url + "/test2").getResponseAsString();
+ assertEquals("{p1:'v1',p2:'v2a',p3:'v3',p4:'v4a',p5:'v5'}", r);
+
+ client.closeQuietly();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d45e1351/juneau-server-test/src/test/java/org/apache/juneau/server/test/JacocoDummyTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/test/JacocoDummyTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/test/JacocoDummyTest.java
new file mode 100755
index 0000000..27c531a
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/test/JacocoDummyTest.java
@@ -0,0 +1,38 @@
+// ***************************************************************************************************************************
+// * 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.server.test;
+
+import java.lang.reflect.*;
+
+import org.apache.juneau.server.*;
+import org.junit.*;
+
+public class JacocoDummyTest {
+
+ //====================================================================================================
+ // Dummy code to add test coverage in Jacoco.
+ //====================================================================================================
+ @Test
+ public void accessPrivateConstructorsOnStaticUtilityClasses() throws Exception {
+
+ Class<?>[] classes = new Class[] {
+ RestUtils.class
+ };
+
+ for (Class<?> c : classes) {
+ Constructor<?> c1 = c.getDeclaredConstructor();
+ c1.setAccessible(true);
+ c1.newInstance();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d45e1351/juneau-server-test/src/test/java/org/apache/juneau/server/test/LargePojosTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/test/LargePojosTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/test/LargePojosTest.java
new file mode 100755
index 0000000..c06b18f
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/test/LargePojosTest.java
@@ -0,0 +1,83 @@
+// ***************************************************************************************************************************
+// * 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.server.test;
+
+import org.apache.juneau.client.*;
+import org.apache.juneau.html.*;
+import org.apache.juneau.json.*;
+import org.apache.juneau.urlencoding.*;
+import org.apache.juneau.xml.*;
+import org.junit.*;
+
+@Ignore
+public class LargePojosTest {
+
+ private static String URL = "/testLargePojos";
+ boolean debug = false;
+
+ //====================================================================================================
+ // Test how long it takes to serialize/parse various content types.
+ //====================================================================================================
+ @Test
+ public void test() throws Exception {
+ LargePojo p;
+ long t;
+ RestClient c;
+
+ System.err.println("\n---Testing JSON---");
+ c = new TestRestClient(JsonSerializer.class, JsonParser.class);
+ for (int i = 1; i <= 3; i++) {
+ t = System.currentTimeMillis();
+ p = c.doGet(URL).getResponse(LargePojo.class);
+ System.err.println("Download: ["+(System.currentTimeMillis() - t)+"] ms");
+ t = System.currentTimeMillis();
+ c.doPut(URL, p).run();
+ System.err.println("Upload: ["+(System.currentTimeMillis() - t)+"] ms");
+ }
+
+ System.err.println("\n---Testing XML---");
+ c = new TestRestClient(XmlSerializer.class, XmlParser.class);
+ for (int i = 1; i <= 3; i++) {
+ t = System.currentTimeMillis();
+ p = c.doGet(URL).getResponse(LargePojo.class);
+ System.err.println("Download: ["+(System.currentTimeMillis() - t)+"] ms");
+ t = System.currentTimeMillis();
+ c.doPut(URL, p).run();
+ System.err.println("Upload: ["+(System.currentTimeMillis() - t)+"] ms");
+ }
+
+ System.err.println("\n---Testing HTML---");
+ c = new TestRestClient(HtmlSerializer.class, HtmlParser.class).setAccept("text/html+stripped");
+ for (int i = 1; i <= 3; i++) {
+ t = System.currentTimeMillis();
+ p = c.doGet(URL).getResponse(LargePojo.class);
+ System.err.println("Download: ["+(System.currentTimeMillis() - t)+"] ms");
+ t = System.currentTimeMillis();
+ c.doPut(URL, p).run();
+ System.err.println("Upload: ["+(System.currentTimeMillis() - t)+"] ms");
+ }
+
+ System.err.println("\n---Testing UrlEncoding---");
+ c = new TestRestClient(UonSerializer.class, UonParser.class);
+ for (int i = 1; i <= 3; i++) {
+ t = System.currentTimeMillis();
+ p = c.doGet(URL).getResponse(LargePojo.class);
+ System.err.println("Download: ["+(System.currentTimeMillis() - t)+"] ms");
+ t = System.currentTimeMillis();
+ c.doPut(URL, p).run();
+ System.err.println("Upload: ["+(System.currentTimeMillis() - t)+"] ms");
+ }
+
+ c.closeQuietly();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d45e1351/juneau-server-test/src/test/java/org/apache/juneau/server/test/MessagesTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/test/MessagesTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/test/MessagesTest.java
new file mode 100755
index 0000000..8d86fee
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/test/MessagesTest.java
@@ -0,0 +1,47 @@
+// ***************************************************************************************************************************
+// * 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.server.test;
+
+import static org.apache.juneau.server.test.TestUtils.*;
+
+import java.util.*;
+
+import org.apache.juneau.client.*;
+import org.apache.juneau.json.*;
+import org.junit.*;
+
+/**
+ * Validates that resource bundles can be defined on both parent and child classes.
+ */
+public class MessagesTest {
+
+ //====================================================================================================
+ // Return contents of resource bundle.
+ //====================================================================================================
+ @SuppressWarnings("rawtypes")
+ @Test
+ public void test() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.class,JsonParser.class);
+
+ // Parent resource should just pick up values from its bundle.
+ TreeMap r = client.doGet("/testMessages/test").getResponse(TreeMap.class);
+ assertObjectEquals("{key1:'value1a',key2:'value2a'}", r);
+
+ // Child resource should pick up values from both parent and child,
+ // ordered child before parent.
+ r = client.doGet("/testMessages2/test").getResponse(TreeMap.class);
+ assertObjectEquals("{key1:'value1a',key2:'value2b',key3:'value3b'}", r);
+
+ client.closeQuietly();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d45e1351/juneau-server-test/src/test/java/org/apache/juneau/server/test/NlsPropertyTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/test/NlsPropertyTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/test/NlsPropertyTest.java
new file mode 100755
index 0000000..4c6c404
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/test/NlsPropertyTest.java
@@ -0,0 +1,48 @@
+// ***************************************************************************************************************************
+// * 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.server.test;
+
+import static org.junit.Assert.*;
+
+import org.apache.juneau.client.*;
+import org.apache.juneau.plaintext.*;
+import org.junit.*;
+
+public class NlsPropertyTest {
+
+ private static String URL = "/testNlsProperty";
+
+ //====================================================================================================
+ // Test getting an NLS property defined on a class.
+ //====================================================================================================
+ @Test
+ public void testInheritedFromClass() throws Exception {
+ RestClient client = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class);
+ String r = client.doGet(URL + "/testInheritedFromClass").getResponseAsString();
+ assertEquals("value1", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Test getting an NLS property defined on a method.
+ //====================================================================================================
+ @Test
+ public void testInheritedFromMethod() throws Exception {
+ RestClient client = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class);
+ String r = client.doGet(URL + "/testInheritedFromMethod").getResponseAsString();
+ assertEquals("value2", r);
+
+ client.closeQuietly();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/d45e1351/juneau-server-test/src/test/java/org/apache/juneau/server/test/NlsTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/test/NlsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/test/NlsTest.java
new file mode 100755
index 0000000..e106066
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/test/NlsTest.java
@@ -0,0 +1,170 @@
+// ***************************************************************************************************************************
+// * 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.server.test;
+
+import static org.junit.Assert.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.client.*;
+import org.apache.juneau.json.*;
+import org.junit.*;
+
+public class NlsTest {
+
+ private static String URL = "/testNls";
+
+ // ====================================================================================================
+ // test1 - Pull labels from annotations only.
+ // ====================================================================================================
+ @Test
+ public void test1() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ ObjectMap r = null;
+ String expected = null;
+
+ // Labels all pulled from annotations.
+ r = client.doOptions(URL + "/test1").getResponse(ObjectMap.class);
+ assertEquals("Test1.a", r.getString("label"));
+ assertEquals("Test1.b", r.getString("description"));
+ r = r.getObjectList("methods").getObjectMap(0);
+ assertEquals("test1", r.getString("javaMethod"));
+ assertEquals("POST", r.getString("httpMethod"));
+ expected = "[{category:'attr',name:'a',description:'Test1.d'},{category:'attr',name:'a2',description:'Test1.h'},{category:'attr',name:'e'},{category:'content',name:'',description:'Test1.f'},{category:'foo',name:'bar',description:'Test1.k'},{category:'header',name:'D',description:'Test1.g'},{category:'header',name:'D2',description:'Test1.j'},{category:'header',name:'g'},{category:'param',name:'b',description:'Test1.e'},{category:'param',name:'b2',description:'Test1.i'},{category:'param',name:'f'}]";
+ assertEquals(expected, r.getObjectList("input").toString());
+ expected = "[{status:200,description:'OK',output:[]},{status:201,description:'Test1.l',output:[{category:'foo',name:'bar',description:'Test1.m'}]}]";
+ assertEquals(expected, r.getObjectList("responses").toString());
+
+ client.closeQuietly();
+ }
+
+ // ====================================================================================================
+ // test2 - Pull labels from resource bundles only - simple keys.
+ // ====================================================================================================
+ @Test
+ public void test2() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ ObjectMap r = null;
+ String expected = null;
+
+ // Labels all pulled from annotations.
+ r = client.doOptions(URL + "/test2").getResponse(ObjectMap.class);
+ assertEquals("Test2.a", r.getString("label"));
+ assertEquals("Test2.b", r.getString("description"));
+ r = r.getObjectList("methods").getObjectMap(0);
+ assertEquals("test2", r.getString("javaMethod"));
+ assertEquals("POST", r.getString("httpMethod"));
+ expected = "[{category:'attr',name:'a',description:'Test2.d'},{category:'attr',name:'a2',description:'Test2.h'},{category:'attr',name:'e'},{category:'content',name:'',description:'Test2.f'},{category:'foo',name:'bar',description:'Test2.k'},{category:'header',name:'D',description:'Test2.g'},{category:'header',name:'D2',description:'Test2.j'},{category:'header',name:'g'},{category:'param',name:'b',description:'Test2.e'},{category:'param',name:'b2',description:'Test2.i'},{category:'param',name:'f'}]";
+ assertEquals(expected, r.getObjectList("input").toString());
+ expected = "[{status:200,description:'OK2',output:[]},{status:201,description:'Test2.l',output:[{category:'foo',name:'bar',description:'Test2.m'}]}]";
+ assertEquals(expected, r.getObjectList("responses").toString());
+
+ client.closeQuietly();
+ }
+
+ // ====================================================================================================
+ // test3 - Pull labels from resource bundles only - keys with class names.
+ // ====================================================================================================
+ @Test
+ public void test3() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ ObjectMap r = null;
+ String expected = null;
+
+ // Labels all pulled from annotations.
+ r = client.doOptions(URL + "/test3").getResponse(ObjectMap.class);
+ assertEquals("Test3.a", r.getString("label"));
+ assertEquals("Test3.b", r.getString("description"));
+ r = r.getObjectList("methods").getObjectMap(1);
+ assertEquals("test3", r.getString("javaMethod"));
+ assertEquals("POST", r.getString("httpMethod"));
+ expected = "[{category:'attr',name:'a',description:'Test3.d'},{category:'attr',name:'a2',description:'Test3.h'},{category:'attr',name:'e'},{category:'content',name:'',description:'Test3.f'},{category:'foo',name:'bar',description:'Test3.k'},{category:'header',name:'D',description:'Test3.g'},{category:'header',name:'D2',description:'Test3.j'},{category:'header',name:'g'},{category:'param',name:'b',description:'Test3.e'},{category:'param',name:'b2',description:'Test3.i'},{category:'param',name:'f'}]";
+ assertEquals(expected, r.getObjectList("input").toString());
+ expected = "[{status:200,description:'OK3',output:[]},{status:201,description:'Test3.l',output:[{category:'foo',name:'bar',description:'Test3.m'}]}]";
+ assertEquals(expected, r.getObjectList("responses").toString());
+
+ client.closeQuietly();
+ }
+
+ // ====================================================================================================
+ // test4 - Pull labels from resource bundles only. Values have localized variables to resolve.
+ // ====================================================================================================
+ @Test
+ public void test4() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ ObjectMap r = null;
+ String expected = null;
+
+ // Labels all pulled from annotations.
+ r = client.doOptions(URL + "/test4").getResponse(ObjectMap.class);
+ assertEquals("baz", r.getString("label"));
+ assertEquals("baz", r.getString("description"));
+ r = r.getObjectList("methods").getObjectMap(0);
+ assertEquals("test4", r.getString("javaMethod"));
+ assertEquals("POST", r.getString("httpMethod"));
+ expected = "[{category:'attr',name:'a',description:'baz'},{category:'attr',name:'a2',description:'baz'},{category:'attr',name:'e'},{category:'content',name:'',description:'baz'},{category:'foo',name:'bar',description:'baz'},{category:'header',name:'D',description:'baz'},{category:'header',name:'D2',description:'baz'},{category:'header',name:'g'},{category:'param',name:'b',description:'baz'},{category:'param',name:'b2',description:'baz'},{category:'param',name:'f'}]";
+ assertEquals(expected, r.getObjectList("input").toString());
+ expected = "[{status:200,description:'foobazfoobazfoo',output:[]},{status:201,description:'baz',output:[{category:'foo',name:'bar',description:'baz'}]}]";
+ assertEquals(expected, r.getObjectList("responses").toString());
+
+ client.closeQuietly();
+ }
+
+ // ====================================================================================================
+ // test5 - Pull labels from resource bundles only. Values have request variables to resolve.
+ // ====================================================================================================
+ @Test
+ public void test5() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ ObjectMap r = null;
+ String expected = null;
+
+ // Labels all pulled from annotations.
+ r = client.doOptions(URL + "/test5").getResponse(ObjectMap.class);
+ assertEquals("baz2", r.getString("label"));
+ assertEquals("baz2", r.getString("description"));
+ r = r.getObjectList("methods").getObjectMap(0);
+ assertEquals("test5", r.getString("javaMethod"));
+ assertEquals("POST", r.getString("httpMethod"));
+ expected = "[{category:'attr',name:'a',description:'baz2'},{category:'attr',name:'a2',description:'baz2'},{category:'attr',name:'e'},{category:'content',name:'',description:'baz2'},{category:'foo',name:'bar',description:'baz2'},{category:'header',name:'D',description:'baz2'},{category:'header',name:'D2',description:'baz2'},{category:'header',name:'g'},{category:'param',name:'b',description:'baz2'},{category:'param',name:'b2',description:'baz2'},{category:'param',name:'f'}]";
+ assertEquals(expected, r.getObjectList("input").toString());
+ expected = "[{status:200,description:'foobaz2foobaz2foo',output:[]},{status:201,description:'baz2',output:[{category:'foo',name:'bar',description:'baz2'}]}]";
+ assertEquals(expected, r.getObjectList("responses").toString());
+
+ client.closeQuietly();
+ }
+
+ // ====================================================================================================
+ // test6 - Pull labels from annotations only, but annotations contain variables.
+ // ====================================================================================================
+ @Test
+ public void test6() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ ObjectMap r = null;
+ String expected = null;
+
+ // Labels all pulled from annotations.
+ r = client.doOptions(URL + "/test6").getResponse(ObjectMap.class);
+ assertEquals("baz", r.getString("label"));
+ assertEquals("baz", r.getString("description"));
+ r = r.getObjectList("methods").getObjectMap(0);
+ assertEquals("test6", r.getString("javaMethod"));
+ assertEquals("POST", r.getString("httpMethod"));
+ expected = "[{category:'attr',name:'a',description:'baz'},{category:'attr',name:'a2',description:'baz'},{category:'attr',name:'e'},{category:'content',name:'',description:'baz'},{category:'foo',name:'bar',description:'baz'},{category:'header',name:'D',description:'baz'},{category:'header',name:'D2',description:'baz'},{category:'header',name:'g'},{category:'param',name:'b',description:'baz'},{category:'param',name:'b2',description:'baz'},{category:'param',name:'f'}]";
+ assertEquals(expected, r.getObjectList("input").toString());
+ expected = "[{status:200,description:'OK',output:[]},{status:201,description:'baz',output:[{category:'foo',name:'bar',description:'baz'}]}]";
+ assertEquals(expected, r.getObjectList("responses").toString());
+
+ client.closeQuietly();
+ }
+
+}