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/08/27 19:48:49 UTC
[01/14] incubator-juneau git commit: Clean up test and test resource
class names.
Repository: incubator-juneau
Updated Branches:
refs/heads/master 7b87347e0 -> bea31abd8
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/UrisTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/UrisTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/UrisTest.java
new file mode 100755
index 0000000..b1cb1a9
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/UrisTest.java
@@ -0,0 +1,918 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static org.junit.Assert.*;
+
+import java.util.regex.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.client.*;
+import org.apache.juneau.json.*;
+import org.junit.*;
+
+/**
+ * Verifies that all the RestRequest.getXXX() methods involving URIs work correctly.
+ */
+public class UrisTest {
+
+ private static String URL2 = Constants.getServerTestUrl() + "/testuris"; // /jazz/juneau/sample/testuris
+ private static int port = getPort(Constants.getServerTestUrl()); // 9443
+ private static String path = Constants.getServerTestUri().getPath(); // /jazz/juneau/sample
+
+ //====================================================================================================
+ // testRoot - http://localhost:8080/sample/testuris
+ //====================================================================================================
+ @Test
+ public void testRoot() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ ObjectMap r;
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris").getResponse(ObjectMap.class);
+ assertEquals("root.test1", r.getString("testMethod"));
+ assertNull(r.getString("pathInfo"));
+ assertNull(r.getString("pathRemainder"));
+ assertEquals(path + "/testuris", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris"));
+ // Same for servlet
+ assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2, r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/foo
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/foo").getResponse(ObjectMap.class);
+ assertEquals("root.test1", r.getString("testMethod"));
+ assertEquals("/foo", r.getString("pathInfo"));
+ assertEquals("foo", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/foo", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/foo"));
+ // Same for servlet
+ assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2, r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/foo/bar
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/foo/bar").getResponse(ObjectMap.class);
+ assertEquals("root.test1", r.getString("testMethod"));
+ assertEquals("/foo/bar", r.getString("pathInfo"));
+ assertEquals("foo/bar", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/foo", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/foo/bar", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/foo/bar"));
+ // Same for servlet
+ assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2, r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/foo/bar%2Fbaz
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/foo/bar%2Fbaz").getResponse(ObjectMap.class);
+ assertEquals("root.test1", r.getString("testMethod"));
+ assertEquals("/foo/bar/baz", r.getString("pathInfo"));
+ assertEquals("foo/bar/baz", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/foo", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/foo/bar%2Fbaz", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/foo/bar%2Fbaz"));
+ // Same for servlet
+ assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2, r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/test2
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/test2").getResponse(ObjectMap.class);
+ assertEquals("root.test2", r.getString("testMethod"));
+ assertEquals("/test2", r.getString("pathInfo"));
+ assertNull(r.getString("pathRemainder"));
+ assertEquals(path + "/testuris", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/test2", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/test2"));
+ // Same for servlet
+ assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2, r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/test2/foo
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/test2/foo").getResponse(ObjectMap.class);
+ assertEquals("root.test2", r.getString("testMethod"));
+ assertEquals("/test2/foo", r.getString("pathInfo"));
+ assertEquals("foo", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/test2", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/test2/foo", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/test2/foo"));
+ // Same for servlet
+ assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2, r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/test2/foo/bar
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/test2/foo/bar").getResponse(ObjectMap.class);
+ assertEquals("root.test2", r.getString("testMethod"));
+ assertEquals("/test2/foo/bar", r.getString("pathInfo"));
+ assertEquals("foo/bar", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/test2/foo", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/test2/foo/bar", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/test2/foo/bar"));
+ // Same for servlet
+ assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2, r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/test3%2Ftest3
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/test3%2Ftest3").getResponse(ObjectMap.class);
+ assertEquals("root.test3", r.getString("testMethod"));
+ assertEquals("/test3/test3", r.getString("pathInfo"));
+ assertNull(r.getString("pathRemainder"));
+ assertEquals(path + "/testuris", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/test3%2Ftest3", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/test3%2Ftest3"));
+ // Same for servlet
+ assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2, r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/test3%2Ftest3/foo
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/test3%2Ftest3/foo").getResponse(ObjectMap.class);
+ assertEquals("root.test3", r.getString("testMethod"));
+ assertEquals("/test3/test3/foo", r.getString("pathInfo"));
+ assertEquals("foo", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/test3%2Ftest3", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/test3%2Ftest3/foo", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/test3%2Ftest3/foo"));
+ // Same for servlet
+ assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2, r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/test3%2Ftest3/foo/bar
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/test3%2Ftest3/foo/bar").getResponse(ObjectMap.class);
+ assertEquals("root.test3", r.getString("testMethod"));
+ assertEquals("/test3/test3/foo/bar", r.getString("pathInfo"));
+ assertEquals("foo/bar", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/test3%2Ftest3/foo", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/test3%2Ftest3/foo/bar", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/test3%2Ftest3/foo/bar"));
+ // Same for servlet
+ assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2, r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/test3%2Ftest3/foo/bar%2Fbaz
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/test3%2Ftest3/foo/bar%2Fbaz").getResponse(ObjectMap.class);
+ assertEquals("root.test3", r.getString("testMethod"));
+ assertEquals("/test3/test3/foo/bar/baz", r.getString("pathInfo"));
+ assertEquals("foo/bar/baz", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/test3%2Ftest3/foo", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/test3%2Ftest3/foo/bar%2Fbaz", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/test3%2Ftest3/foo/bar%2Fbaz"));
+ // Same for servlet
+ assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2, r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/test4/test4
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/test4/test4").getResponse(ObjectMap.class);
+ assertEquals("root.test4", r.getString("testMethod"));
+ assertEquals("/test4/test4", r.getString("pathInfo"));
+ assertNull(r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/test4", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/test4/test4", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/test4/test4"));
+ // Same for servlet
+ assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2, r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/test4/test4/foo
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/test4/test4/foo").getResponse(ObjectMap.class);
+ assertEquals("root.test4", r.getString("testMethod"));
+ assertEquals("/test4/test4/foo", r.getString("pathInfo"));
+ assertEquals("foo", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/test4/test4", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/test4/test4/foo", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/test4/test4/foo"));
+ // Same for servlet
+ assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2, r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/test4/test4/foo/bar
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/test4/test4/foo/bar").getResponse(ObjectMap.class);
+ assertEquals("root.test4", r.getString("testMethod"));
+ assertEquals("/test4/test4/foo/bar", r.getString("pathInfo"));
+ assertEquals("foo/bar", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/test4/test4/foo", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/test4/test4/foo/bar", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/test4/test4/foo/bar"));
+ // Same for servlet
+ assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2, r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/test4/test4/foo/bar%2Fbaz
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/test4/test4/foo/bar%2Fbaz").getResponse(ObjectMap.class);
+ assertEquals("root.test4", r.getString("testMethod"));
+ assertEquals("/test4/test4/foo/bar/baz", r.getString("pathInfo"));
+ assertEquals("foo/bar/baz", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/test4/test4/foo", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/test4/test4/foo/bar%2Fbaz", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/test4/test4/foo/bar%2Fbaz"));
+ // Same for servlet
+ assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2, r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // testChild - http://localhost:8080/sample/testuris/child
+ //====================================================================================================
+ @Test
+ public void testChild() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ ObjectMap r;
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child").getResponse(ObjectMap.class);
+ assertEquals("child.test1", r.getString("testMethod"));
+ assertNull(r.getString("pathInfo"));
+ assertNull(r.getString("pathRemainder"));
+ assertEquals(path + "/testuris", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/foo
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/foo").getResponse(ObjectMap.class);
+ assertEquals("child.test1", r.getString("testMethod"));
+ assertEquals("/foo", r.getString("pathInfo"));
+ assertEquals("foo", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/foo", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/foo"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/foo/bar
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/foo/bar").getResponse(ObjectMap.class);
+ assertEquals("child.test1", r.getString("testMethod"));
+ assertEquals("/foo/bar", r.getString("pathInfo"));
+ assertEquals("foo/bar", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child/foo", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/foo/bar", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/foo/bar"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/foo/bar%2Fbaz
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/foo/bar%2Fbaz").getResponse(ObjectMap.class);
+ assertEquals("child.test1", r.getString("testMethod"));
+ assertEquals("/foo/bar/baz", r.getString("pathInfo"));
+ assertEquals("foo/bar/baz", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child/foo", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/foo/bar%2Fbaz", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/foo/bar%2Fbaz"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/test2
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/test2").getResponse(ObjectMap.class);
+ assertEquals("child.test2", r.getString("testMethod"));
+ assertEquals("/test2", r.getString("pathInfo"));
+ assertNull(r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/test2", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/test2"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/test2/foo
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/test2/foo").getResponse(ObjectMap.class);
+ assertEquals("child.test2", r.getString("testMethod"));
+ assertEquals("/test2/foo", r.getString("pathInfo"));
+ assertEquals("foo", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child/test2", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/test2/foo", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/test2/foo"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/test2/foo/bar
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/test2/foo/bar").getResponse(ObjectMap.class);
+ assertEquals("child.test2", r.getString("testMethod"));
+ assertEquals("/test2/foo/bar", r.getString("pathInfo"));
+ assertEquals("foo/bar", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child/test2/foo", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/test2/foo/bar", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/test2/foo/bar"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/test2/foo/bar%2Fbaz
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/test2/foo/bar%2Fbaz").getResponse(ObjectMap.class);
+ assertEquals("child.test2", r.getString("testMethod"));
+ assertEquals("/test2/foo/bar/baz", r.getString("pathInfo"));
+ assertEquals("foo/bar/baz", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child/test2/foo", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/test2/foo/bar%2Fbaz", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/test2/foo/bar%2Fbaz"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/test3%2Ftest3
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/test3%2Ftest3").getResponse(ObjectMap.class);
+ assertEquals("child.test3", r.getString("testMethod"));
+ assertEquals("/test3/test3", r.getString("pathInfo"));
+ assertNull(r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/test3%2Ftest3", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/test3%2Ftest3"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/test3%2Ftest3/foo
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/test3%2Ftest3/foo").getResponse(ObjectMap.class);
+ assertEquals("child.test3", r.getString("testMethod"));
+ assertEquals("/test3/test3/foo", r.getString("pathInfo"));
+ assertEquals("foo", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child/test3%2Ftest3", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/test3%2Ftest3/foo", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/test3%2Ftest3/foo"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/test3%2Ftest3/foo/bar
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/test3%2Ftest3/foo/bar").getResponse(ObjectMap.class);
+ assertEquals("child.test3", r.getString("testMethod"));
+ assertEquals("/test3/test3/foo/bar", r.getString("pathInfo"));
+ assertEquals("foo/bar", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child/test3%2Ftest3/foo", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/test3%2Ftest3/foo/bar", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/test3%2Ftest3/foo/bar"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/test3%2Ftest3/foo/bar%2Fbaz
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/test3%2Ftest3/foo/bar%2Fbaz").getResponse(ObjectMap.class);
+ assertEquals("child.test3", r.getString("testMethod"));
+ assertEquals("/test3/test3/foo/bar/baz", r.getString("pathInfo"));
+ assertEquals("foo/bar/baz", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child/test3%2Ftest3/foo", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/test3%2Ftest3/foo/bar%2Fbaz", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/test3%2Ftest3/foo/bar%2Fbaz"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/test4/test4
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/test4/test4").getResponse(ObjectMap.class);
+ assertEquals("child.test4", r.getString("testMethod"));
+ assertEquals("/test4/test4", r.getString("pathInfo"));
+ assertNull(r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child/test4", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/test4/test4", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/test4/test4"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/test4/test4/foo
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/test4/test4/foo").getResponse(ObjectMap.class);
+ assertEquals("child.test4", r.getString("testMethod"));
+ assertEquals("/test4/test4/foo", r.getString("pathInfo"));
+ assertEquals("foo", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child/test4/test4", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/test4/test4/foo", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/test4/test4/foo"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/test4/test4/foo/bar
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/test4/test4/foo/bar").getResponse(ObjectMap.class);
+ assertEquals("child.test4", r.getString("testMethod"));
+ assertEquals("/test4/test4/foo/bar", r.getString("pathInfo"));
+ assertEquals("foo/bar", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child/test4/test4/foo", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/test4/test4/foo/bar", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/test4/test4/foo/bar"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/test4/test4/foo/bar%2Fbaz
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/test4/test4/foo/bar%2Fbaz").getResponse(ObjectMap.class);
+ assertEquals("child.test4", r.getString("testMethod"));
+ assertEquals("/test4/test4/foo/bar/baz", r.getString("pathInfo"));
+ assertEquals("foo/bar/baz", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child/test4/test4/foo", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/test4/test4/foo/bar%2Fbaz", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/test4/test4/foo/bar%2Fbaz"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // testGrandChild - http://localhost:8080/sample/testuris/child/grandchild
+ //====================================================================================================
+ @Test
+ public void testGrandChild() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ ObjectMap r;
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/grandchild").getResponse(ObjectMap.class);
+ assertEquals("grandchild.test1", r.getString("testMethod"));
+ assertNull(r.getString("pathInfo"));
+ assertNull(r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/grandchild", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/foo
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/grandchild/foo").getResponse(ObjectMap.class);
+ assertEquals("grandchild.test1", r.getString("testMethod"));
+ assertEquals("/foo", r.getString("pathInfo"));
+ assertEquals("foo", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child/grandchild", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/grandchild/foo", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/foo"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/foo/bar
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/grandchild/foo/bar").getResponse(ObjectMap.class);
+ assertEquals("grandchild.test1", r.getString("testMethod"));
+ assertEquals("/foo/bar", r.getString("pathInfo"));
+ assertEquals("foo/bar", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child/grandchild/foo", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/grandchild/foo/bar", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/foo/bar"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/foo/bar%2Fbaz
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/grandchild/foo/bar%2Fbaz").getResponse(ObjectMap.class);
+ assertEquals("grandchild.test1", r.getString("testMethod"));
+ assertEquals("/foo/bar/baz", r.getString("pathInfo"));
+ assertEquals("foo/bar/baz", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child/grandchild/foo", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/grandchild/foo/bar%2Fbaz", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/foo/bar%2Fbaz"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/test2
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/grandchild/test2").getResponse(ObjectMap.class);
+ assertEquals("grandchild.test2", r.getString("testMethod"));
+ assertEquals("/test2", r.getString("pathInfo"));
+ assertNull(r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child/grandchild", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/grandchild/test2", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/test2"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/test2/foo
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/grandchild/test2/foo").getResponse(ObjectMap.class);
+ assertEquals("grandchild.test2", r.getString("testMethod"));
+ assertEquals("/test2/foo", r.getString("pathInfo"));
+ assertEquals("foo", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child/grandchild/test2", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/grandchild/test2/foo", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/test2/foo"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/test2/foo/bar
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/grandchild/test2/foo/bar").getResponse(ObjectMap.class);
+ assertEquals("grandchild.test2", r.getString("testMethod"));
+ assertEquals("/test2/foo/bar", r.getString("pathInfo"));
+ assertEquals("foo/bar", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child/grandchild/test2/foo", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/grandchild/test2/foo/bar", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/test2/foo/bar"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/test2/foo/bar%2Fbaz
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/grandchild/test2/foo/bar%2Fbaz").getResponse(ObjectMap.class);
+ assertEquals("grandchild.test2", r.getString("testMethod"));
+ assertEquals("/test2/foo/bar/baz", r.getString("pathInfo"));
+ assertEquals("foo/bar/baz", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child/grandchild/test2/foo", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/grandchild/test2/foo/bar%2Fbaz", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/test2/foo/bar%2Fbaz"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/test3%2Ftest3
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/grandchild/test3%2Ftest3").getResponse(ObjectMap.class);
+ assertEquals("grandchild.test3", r.getString("testMethod"));
+ assertEquals("/test3/test3", r.getString("pathInfo"));
+ assertNull(r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child/grandchild", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/grandchild/test3%2Ftest3", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/test3%2Ftest3"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/test3%2Ftest3/foo
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/grandchild/test3%2Ftest3/foo").getResponse(ObjectMap.class);
+ assertEquals("grandchild.test3", r.getString("testMethod"));
+ assertEquals("/test3/test3/foo", r.getString("pathInfo"));
+ assertEquals("foo", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child/grandchild/test3%2Ftest3", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/grandchild/test3%2Ftest3/foo", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/test3%2Ftest3/foo"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/test3%2Ftest3/foo/bar
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/grandchild/test3%2Ftest3/foo/bar").getResponse(ObjectMap.class);
+ assertEquals("grandchild.test3", r.getString("testMethod"));
+ assertEquals("/test3/test3/foo/bar", r.getString("pathInfo"));
+ assertEquals("foo/bar", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child/grandchild/test3%2Ftest3/foo", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/grandchild/test3%2Ftest3/foo/bar", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/test3%2Ftest3/foo/bar"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/test3%2Ftest3/foo/bar%2Fbaz
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/grandchild/test3%2Ftest3/foo/bar%2Fbaz").getResponse(ObjectMap.class);
+ assertEquals("grandchild.test3", r.getString("testMethod"));
+ assertEquals("/test3/test3/foo/bar/baz", r.getString("pathInfo"));
+ assertEquals("foo/bar/baz", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child/grandchild/test3%2Ftest3/foo", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/grandchild/test3%2Ftest3/foo/bar%2Fbaz", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/test3%2Ftest3/foo/bar%2Fbaz"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/test4/test4
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/grandchild/test4/test4").getResponse(ObjectMap.class);
+ assertEquals("grandchild.test4", r.getString("testMethod"));
+ assertEquals("/test4/test4", r.getString("pathInfo"));
+ assertNull(r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child/grandchild/test4", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/grandchild/test4/test4", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/test4/test4"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/test4/test4/foo
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/grandchild/test4/test4/foo").getResponse(ObjectMap.class);
+ assertEquals("grandchild.test4", r.getString("testMethod"));
+ assertEquals("/test4/test4/foo", r.getString("pathInfo"));
+ assertEquals("foo", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child/grandchild/test4/test4", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/grandchild/test4/test4/foo", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/test4/test4/foo"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/test4/test4/foo/bar
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/grandchild/test4/test4/foo/bar").getResponse(ObjectMap.class);
+ assertEquals("grandchild.test4", r.getString("testMethod"));
+ assertEquals("/test4/test4/foo/bar", r.getString("pathInfo"));
+ assertEquals("foo/bar", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child/grandchild/test4/test4/foo", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/grandchild/test4/test4/foo/bar", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/test4/test4/foo/bar"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ //--------------------------------------------------------------------------------
+ // http://localhost:8080/sample/testuris/child/test4/test4/foo/bar%2Fbaz
+ //--------------------------------------------------------------------------------
+ r = client.doGet("/testuris/child/grandchild/test4/test4/foo/bar%2Fbaz").getResponse(ObjectMap.class);
+ assertEquals("grandchild.test4", r.getString("testMethod"));
+ assertEquals("/test4/test4/foo/bar/baz", r.getString("pathInfo"));
+ assertEquals("foo/bar/baz", r.getString("pathRemainder"));
+ assertEquals(path + "/testuris/child/grandchild/test4/test4/foo", r.getString("requestParentURI"));
+ assertEquals(path + "/testuris/child/grandchild/test4/test4/foo/bar%2Fbaz", r.getString("requestURI"));
+ assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/test4/test4/foo/bar%2Fbaz"));
+ // Same for servlet
+ assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
+ assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
+ assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
+ // Always the same
+ assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
+ assertEquals("http://testURL", r.getString("testURL3"));
+
+ client.closeQuietly();
+ }
+
+ private static int getPort(String url) {
+ Pattern p = Pattern.compile("\\:(\\d{2,5})");
+ Matcher m = p.matcher(url);
+ if (m.find())
+ return Integer.parseInt(m.group(1));
+ return -1;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/UrlContentTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/UrlContentTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/UrlContentTest.java
new file mode 100755
index 0000000..fedfc26
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/UrlContentTest.java
@@ -0,0 +1,74 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static org.junit.Assert.*;
+
+import org.apache.juneau.client.*;
+import org.junit.*;
+
+public class UrlContentTest {
+
+ private static String URL = "/testUrlContent";
+ private static RestClient client;
+
+ @BeforeClass
+ public static void beforeClass() {
+ client = new TestRestClient().setHeader("Accept", "text/plain");
+ }
+
+ @AfterClass
+ public static void afterClass() {
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Test URL &Content parameter containing a String
+ //====================================================================================================
+ @Test
+ public void testString() throws Exception {
+ String r;
+ r = client.doGet(URL + "/testString?content=\'xxx\'&Content-Type=text/json").getResponseAsString();
+ assertEquals("class=java.lang.String, value=xxx", r);
+ }
+
+ //====================================================================================================
+ // Test URL &Content parameter containing an Enum
+ //====================================================================================================
+ @Test
+ public void testEnum() throws Exception {
+ String r;
+ r = client.doGet(URL + "/testEnum?content='X1'&Content-Type=text/json").getResponseAsString();
+ assertEquals("class=org.apache.juneau.server.UrlContentResource$TestEnum, value=X1", r);
+ }
+
+ //====================================================================================================
+ // Test URL &Content parameter containing a Bean
+ //====================================================================================================
+ @Test
+ public void testBean() throws Exception {
+ String r;
+ r = client.doGet(URL + "/testBean?content=%7Bf1:1,f2:'foobar'%7D&Content-Type=text/json").getResponseAsString();
+ assertEquals("class=org.apache.juneau.server.UrlContentResource$TestBean, value={f1:1,f2:'foobar'}", r);
+ }
+
+ //====================================================================================================
+ // Test URL &Content parameter containing an int
+ //====================================================================================================
+ @Test
+ public void testInt() throws Exception {
+ String r;
+ r = client.doGet(URL + "/testInt?content=123&Content-Type=text/json").getResponseAsString();
+ assertEquals("class=java.lang.Integer, value=123", r);
+ }
+}
\ No newline at end of file
[04/14] incubator-juneau git commit: Clean up test and test resource
class names.
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestParamsTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestParamsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestParamsTest.java
deleted file mode 100755
index 309e85f..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestParamsTest.java
+++ /dev/null
@@ -1,716 +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.server;
-
-import static javax.servlet.http.HttpServletResponse.*;
-import static org.apache.juneau.server.TestUtils.*;
-import static org.junit.Assert.*;
-
-import java.util.*;
-
-import org.apache.http.*;
-import org.apache.http.client.entity.*;
-import org.apache.http.entity.*;
-import org.apache.http.message.*;
-import org.apache.juneau.*;
-import org.apache.juneau.client.*;
-import org.apache.juneau.json.*;
-import org.junit.*;
-
-public class TestParamsTest {
-
- private static String URL = "/testParams";
- private static boolean debug = false;
-
- //====================================================================================================
- // Basic tests
- //====================================================================================================
- @Test
- public void testBasic() throws Exception {
- RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
- RestCall r;
-
- // @Override
- // @RestMethod(name="GET",pattern="/")
- // public void doGet(RestRequest req, RestResponse res) {
- // res.setOutput("No args");
- // }
- r = client.doGet(URL);
- assertEquals("GET", r.getResponse(String.class));
-
- r = client.doGet(URL + "/getx?noTrace=true");
- try {
- r.connect();
- fail("Connection should have failed.");
- } catch (RestCallException e) {
- checkErrorResponse(debug, e, SC_NOT_FOUND, "Method 'GET' not found on resource with matching pattern on path '/getx'");
- }
-
- // @RestMethod(name="GET",pattern="/get1")
- // public void doGet1(RestRequest req, RestResponse res) {
- // res.setOutput("/get1");
- // }
- r = client.doGet(URL + "/get1");
- assertEquals("GET /get1", r.getResponse(String.class));
-
- r = client.doGet(URL + "/get1a?noTrace=true");
- try {
- r.connect();
- fail("Connection should have failed.");
- } catch (RestCallException e) {
- checkErrorResponse(debug, e, SC_NOT_FOUND, "Method 'GET' not found on resource with matching pattern on path '/get1a'");
- }
-
- // @RestMethod(name="GET",pattern="/get1/{foo}")
- // public void doGet(RestRequest req, RestResponse res, String foo) {
- // res.setOutput("/get1/" + foo);
- // }
- r = client.doGet(URL + "/get1/foo");
- assertEquals("GET /get1a foo", r.getResponse(String.class));
-
- // URL-encoded part should not get decoded before finding method to invoke.
- // This should match /get1/{foo} and not /get1/{foo}/{bar}
- // NOTE: When testing on Tomcat, must specify the following system property:
- // -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true
- String x = "x%2Fy+z"; // [x/y z]
- r = client.doGet(URL + "/get1/"+x);
- assertEquals("GET /get1a x/y z", r.getResponse(String.class));
-
- r = client.doGet(URL + "/get1/"+x+"/"+x);
- assertEquals("GET /get1b x/y z,x/y z", r.getResponse(String.class));
-
- r = client.doGet(URL + "/get1/foo");
- assertEquals("GET /get1a foo", r.getResponse(String.class));
-
- r = client.doGet(URL + "/get1/foo/bar/baz?noTrace=true");
- try {
- r.connect();
- fail("Connection should have failed.");
- } catch (RestCallException e) {
- checkErrorResponse(debug, e, SC_NOT_FOUND, "Method 'GET' not found on resource with matching pattern on path '/get1/foo/bar/baz'");
- }
-
- // @RestMethod(name="GET",pattern="/get3/{foo}/{bar}/*")
- // public void doGet3(RestRequest req, RestResponse res, String foo, int bar) {
- // res.setOutput("/get3/"+foo+"/"+bar+", remainder="+req.getRemainder());
- // }
- r = client.doGet(URL + "/get3/foo/123");
- assertEquals("GET /get3/foo/123 remainder=null", r.getResponse(String.class));
-
- r = client.doGet(URL + "/get3/foo/123/xxx");
- assertEquals("GET /get3/foo/123 remainder=xxx", r.getResponse(String.class));
-
- // // Test method name with overlapping name, remainder allowed.
- // @RestMethod(name="GET2")
- // public void get2(RestRequest req, RestResponse res) {
- // res.setOutput("GET2, remainder="+req.getRemainder());
- // }
- r = client.doGet(URL + "?method=get2");
- assertEquals("GET2 remainder=null", r.getResponse(String.class));
- r = client.doGet(URL + "/foo/bar?method=get2");
- assertEquals("GET2 remainder=foo/bar", r.getResponse(String.class));
- r = client.doGet(URL + "/foo/bar?method=GET2");
- assertEquals("GET2 remainder=foo/bar", r.getResponse(String.class));
-
- // // Default POST
- // @Override
- // public void doPost(RestRequest req, RestResponse res) {
- // res.setOutput("POST, remainder="+req.getRemainder());
- // }
- r = client.doPost(URL, "");
- assertEquals("POST remainder=null", r.getResponse(String.class));
- r = client.doPost(URL + "/foo", "");
- assertEquals("POST remainder=foo", r.getResponse(String.class));
-
- // // Bunch of different argument types
- // @RestMethod(name="POST",pattern="/person/{person}")
- // public void doPost(RestRequest req, RestResponse res, Person p) {
- // res.setOutput("POST, /person, name="+p.name+", age="+p.age+" remainder="+req.getRemainder());
- // }
- r = client.doPost(URL + "/person/(name=John+Smith,birthDate=Jan+12~,+1952)", "");
- assertEquals("POST /person/{name=John Smith,birthDate.year=1952} remainder=null", r.getResponse(String.class));
-
- // Fall through to top-level POST
- r = client.doPost(URL + "/person/(name:'John+Smith',age:123)/foo", "");
- assertEquals("POST remainder=person/(name:'John Smith',age:123)/foo", r.getResponse(String.class));
-
- // // Various primitive types
- // @RestMethod(name="PUT",pattern="/primitives/{xInt}.{xShort},{xLong}/{xChar}/{xFloat}/{xDouble}/{xByte}/{xBoolean}")
- // public void doPut1(RestRequest req, RestResponse res, int xInt, short xShort, long xLong, char xChar, float xFloat, double xDouble, byte xByte, boolean xBoolean) {
- // res.setOutput("PUT, /primitives/"+xInt+"."+xShort+","+xLong+"/"+xChar+"/"+xFloat+"/"+xDouble+"/"+xByte+"/"+xBoolean);
- // }
- r = client.doPut(URL + "/primitives/1/2/3/x/4/5/6/true", "");
- assertEquals("PUT /primitives/1/2/3/x/4.0/5.0/6/true", r.getResponse(String.class));
-
- // // Various primitive objects
- // @RestMethod(name="PUT",pattern="/primitiveObjects/{xInt}/{xShort}/{xLong}/{xChar}/{xFloat}/{xDouble}/{xByte}/{xBoolean}")
- // public void doPut1(RestRequest req, RestResponse res, Integer xInt, Short xShort, Long xLong, Character xChar, Float xFloat, Double xDouble, Byte xByte, Boolean xBoolean) {
- // res.setOutput("PUT /primitives/"+xInt+"/"+xShort+"/"+xLong+"/"+xChar+"/"+xFloat+"/"+xDouble+"/"+xByte+"/"+xBoolean);
- // }
- r = client.doPut(URL + "/primitiveObjects/1/2/3/x/4/5/6/true", "");
- assertEquals("PUT /primitiveObjects/1/2/3/x/4.0/5.0/6/true", r.getResponse(String.class));
-
- // // Object with forString(String) method
- // @RestMethod(name="PUT",pattern="/uuid/{uuid}")
- // public void doPut1(RestRequest req, RestResponse res, UUID uuid) {
- // res.setOutput("PUT /uuid/"+uuid);
- // }
- UUID uuid = UUID.randomUUID();
- r = client.doPut(URL + "/uuid/"+uuid, "");
- assertEquals("PUT /uuid/"+uuid, r.getResponse(String.class));
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // @Param annotation - GET
- //====================================================================================================
- @Test
- public void testParamGet() throws Exception {
- RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
- String r;
- String url = URL + "/testParamGet";
-
- r = client.doGet(url + "?p1=p1&p2=2").getResponseAsString();
- assertEquals("p1=[p1,p1,p1],p2=[2,2,2]", r);
-
- r = client.doGet(url + "?p1&p2").getResponseAsString();
- assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
-
- r = client.doGet(url).getResponseAsString();
- assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
-
- r = client.doGet(url + "?p1").getResponseAsString();
- assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
-
- r = client.doGet(url + "?p2").getResponseAsString();
- assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
-
- r = client.doGet(url + "?p1=foo&p2").getResponseAsString();
- assertEquals("p1=[foo,foo,foo],p2=[0,null,0]", r);
-
- r = client.doGet(url + "?p1&p2=1").getResponseAsString();
- assertEquals("p1=[null,null,null],p2=[1,1,1]", r);
-
- String x = "a%2Fb%25c%3Dd+e"; // [x/y%z=a+b]
- r = client.doGet(url + "?p1="+x+"&p2=1").getResponseAsString();
- assertEquals("p1=[a/b%c=d e,a/b%c=d e,a/b%c=d e],p2=[1,1,1]", r);
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // @Param(format=PLAIN) annotation - GET
- //====================================================================================================
- @Test
- public void testPlainParamGet() throws Exception {
- RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
- String r;
- String url = URL + "/testPlainParamGet";
-
- r = client.doGet(url + "?p1=(p1)").getResponseAsString();
- assertEquals("p1=[(p1),(p1),p1]", r);
-
- r = client.doGet(url + "?p1=$s(p1)").getResponseAsString();
- assertEquals("p1=[$s(p1),$s(p1),p1]", r);
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // @Param annotation - POST
- //====================================================================================================
- @Test
- public void testParamPost() throws Exception {
- RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
- String r;
- String url = URL + "/testParamPost";
-
- r = client.doFormPost(url, new ObjectMap("{p1:'p1',p2:2}")).getResponseAsString();
- assertEquals("p1=[p1,p1,p1],p2=[2,$n(2),2]", r);
-
- r = client.doFormPost(url, new ObjectMap("{p1:null,p2:0}")).getResponseAsString();
- assertEquals("p1=[null,\u0000,null],p2=[0,$n(0),0]", r);
-
- r = client.doFormPost(url, new ObjectMap("{}")).getResponseAsString();
- assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
-
- r = client.doFormPost(url, new ObjectMap("{p1:null}")).getResponseAsString();
- assertEquals("p1=[null,\u0000,null],p2=[0,null,0]", r);
-
- r = client.doFormPost(url, new ObjectMap("{p2:0}")).getResponseAsString();
- assertEquals("p1=[null,null,null],p2=[0,$n(0),0]", r);
-
- r = client.doFormPost(url, new ObjectMap("{p1:'foo',p2:0}")).getResponseAsString();
- assertEquals("p1=[foo,foo,foo],p2=[0,$n(0),0]", r);
-
- r = client.doFormPost(url, new ObjectMap("{p1:null,p2:1}")).getResponseAsString();
- assertEquals("p1=[null,\u0000,null],p2=[1,$n(1),1]", r);
-
- r = client.doFormPost(url, new ObjectMap("{p1:'a/b%c=d e,f/g%h=i j',p2:1}")).getResponseAsString();
- assertEquals("p1=[a/b%c=d e,f/g%h=i j,a/b%c=d e,f/g%h=i j,a/b%c=d e,f/g%h=i j],p2=[1,$n(1),1]", r);
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // @Param(format=PLAIN) annotation - POST
- //====================================================================================================
- @Test
- public void testPlainParamPost() throws Exception {
- RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
- String r;
- String url = URL + "/testPlainParamPost";
-
- List<NameValuePair> nvps = new ArrayList<NameValuePair>();
- nvps.add(new BasicNameValuePair("p1", "(p1)"));
- HttpEntity he = new UrlEncodedFormEntity(nvps);
-
- r = client.doPost(url, he).getResponseAsString();
- assertEquals("p1=[(p1),(p1),p1]", r);
-
- nvps = new ArrayList<NameValuePair>();
- nvps.add(new BasicNameValuePair("p1", "$s(p1)"));
- he = new UrlEncodedFormEntity(nvps);
-
- r = client.doFormPost(url, he).getResponseAsString();
- assertEquals("p1=[$s(p1),$s(p1),p1]", r);
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // @QParam annotation - GET
- //====================================================================================================
- @Test
- public void testQParamGet() throws Exception {
- RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
- String r;
- String url = URL + "/testQParamGet";
-
- r = client.doGet(url + "?p1=p1&p2=2").getResponseAsString();
- assertEquals("p1=[p1,p1,p1],p2=[2,2,2]", r);
-
- r = client.doGet(url + "?p1&p2").getResponseAsString();
- assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
-
- r = client.doGet(url).getResponseAsString();
- assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
-
- r = client.doGet(url + "?p1").getResponseAsString();
- assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
-
- r = client.doGet(url + "?p2").getResponseAsString();
- assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
-
- r = client.doGet(url + "?p1=foo&p2").getResponseAsString();
- assertEquals("p1=[foo,foo,foo],p2=[0,null,0]", r);
-
- r = client.doGet(url + "?p1&p2=1").getResponseAsString();
- assertEquals("p1=[null,null,null],p2=[1,1,1]", r);
-
- String x = "a%2Fb%25c%3Dd+e"; // [x/y%z=a+b]
- r = client.doGet(url + "?p1="+x+"&p2=1").getResponseAsString();
- assertEquals("p1=[a/b%c=d e,a/b%c=d e,a/b%c=d e],p2=[1,1,1]", r);
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // @QParam(format=PLAIN) annotation - GET
- //====================================================================================================
- @Test
- public void testPlainQParamGet() throws Exception {
- RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
- String r;
- String url = URL + "/testPlainQParamGet";
-
- r = client.doGet(url + "?p1=(p1)").getResponseAsString();
- assertEquals("p1=[(p1),(p1),p1]", r);
-
- r = client.doGet(url + "?p1=$s(p1)").getResponseAsString();
- assertEquals("p1=[$s(p1),$s(p1),p1]", r);
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // @QParam annotation - POST
- //====================================================================================================
- @Test
- public void testQParamPost() throws Exception {
- RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
- String r;
- String url = URL + "/testQParamPost";
-
- r = client.doFormPost(url, new ObjectMap("{p1:'p1',p2:2}")).getResponseAsString();
- assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
-
- r = client.doFormPost(url, new ObjectMap("{p1:null,p2:0}")).getResponseAsString();
- assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
-
- r = client.doFormPost(url, new ObjectMap("{}")).getResponseAsString();
- assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
-
- r = client.doFormPost(url, new ObjectMap("{p1:null}")).getResponseAsString();
- assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
-
- r = client.doFormPost(url, new ObjectMap("{p2:0}")).getResponseAsString();
- assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
-
- r = client.doFormPost(url, new ObjectMap("{p1:'foo',p2:0}")).getResponseAsString();
- assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
-
- r = client.doFormPost(url, new ObjectMap("{p1:null,p2:1}")).getResponseAsString();
- assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
-
- r = client.doFormPost(url, new ObjectMap("{p1:'a/b%c=d e,f/g%h=i j',p2:1}")).getResponseAsString();
- assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // @HasParam annotation - GET
- //====================================================================================================
- @Test
- public void testHasParamGet() throws Exception {
- RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
- String r;
- String url = URL + "/testHasParamGet";
-
- r = client.doGet(url + "?p1=p1&p2=2").getResponseAsString();
- assertEquals("p1=[true,true],p2=[true,true]", r);
-
- r = client.doGet(url + "?p1&p2").getResponseAsString();
- assertEquals("p1=[true,true],p2=[true,true]", r);
-
- r = client.doGet(url).getResponseAsString();
- assertEquals("p1=[false,false],p2=[false,false]", r);
-
- r = client.doGet(url + "?p1").getResponseAsString();
- assertEquals("p1=[true,true],p2=[false,false]", r);
-
- r = client.doGet(url + "?p2").getResponseAsString();
- assertEquals("p1=[false,false],p2=[true,true]", r);
-
- r = client.doGet(url + "?p1=foo&p2").getResponseAsString();
- assertEquals("p1=[true,true],p2=[true,true]", r);
-
- r = client.doGet(url + "?p1&p2=1").getResponseAsString();
- assertEquals("p1=[true,true],p2=[true,true]", r);
-
- String x = "x%2Fy%25z%3Da+b"; // [x/y%z=a+b]
- r = client.doGet(url + "?p1="+x+"&p2=1").getResponseAsString();
- assertEquals("p1=[true,true],p2=[true,true]", r);
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // @HasParam annotation - POST
- //====================================================================================================
- @Test
- public void testHasParamPost() throws Exception {
- RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
- String r;
- String url = URL + "/testHasParamPost";
-
- r = client.doFormPost(url, new ObjectMap("{p1:'p1',p2:2}")).getResponseAsString();
- assertEquals("p1=[true,true],p2=[true,true]", r);
-
- r = client.doFormPost(url, new ObjectMap("{p1:null,p2:0}")).getResponseAsString();
- assertEquals("p1=[true,true],p2=[true,true]", r);
-
- r = client.doFormPost(url, new ObjectMap("{}")).getResponseAsString();
- assertEquals("p1=[false,false],p2=[false,false]", r);
-
- r = client.doFormPost(url, new ObjectMap("{p1:null}")).getResponseAsString();
- assertEquals("p1=[true,true],p2=[false,false]", r);
-
- r = client.doFormPost(url, new ObjectMap("{p2:0}")).getResponseAsString();
- assertEquals("p1=[false,false],p2=[true,true]", r);
-
- r = client.doFormPost(url, new ObjectMap("{p1:'foo',p2:0}")).getResponseAsString();
- assertEquals("p1=[true,true],p2=[true,true]", r);
-
- r = client.doFormPost(url, new ObjectMap("{p1:null,p2:1}")).getResponseAsString();
- assertEquals("p1=[true,true],p2=[true,true]", r);
-
- r = client.doFormPost(url, new ObjectMap("{p1:'a/b%c=d e,f/g%h=i j',p2:1}")).getResponseAsString();
- assertEquals("p1=[true,true],p2=[true,true]", r);
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // @HasQParam annotation - GET
- //====================================================================================================
- @Test
- public void testHasQParamGet() throws Exception {
- RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
- String r;
- String url = URL + "/testHasQParamGet";
-
- r = client.doGet(url + "?p1=p1&p2=2").getResponseAsString();
- assertEquals("p1=[true,true],p2=[true,true]", r);
-
- r = client.doGet(url + "?p1&p2").getResponseAsString();
- assertEquals("p1=[true,true],p2=[true,true]", r);
-
- r = client.doGet(url).getResponseAsString();
- assertEquals("p1=[false,false],p2=[false,false]", r);
-
- r = client.doGet(url + "?p1").getResponseAsString();
- assertEquals("p1=[true,true],p2=[false,false]", r);
-
- r = client.doGet(url + "?p2").getResponseAsString();
- assertEquals("p1=[false,false],p2=[true,true]", r);
-
- r = client.doGet(url + "?p1=foo&p2").getResponseAsString();
- assertEquals("p1=[true,true],p2=[true,true]", r);
-
- r = client.doGet(url + "?p1&p2=1").getResponseAsString();
- assertEquals("p1=[true,true],p2=[true,true]", r);
-
- String x = "x%2Fy%25z%3Da+b"; // [x/y%z=a+b]
- r = client.doGet(url + "?p1="+x+"&p2=1").getResponseAsString();
- assertEquals("p1=[true,true],p2=[true,true]", r);
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // @HasQParam annotation - POST
- //====================================================================================================
- @Test
- public void testHasQParamPost() throws Exception {
- RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
- String r;
- String url = URL + "/testHasQParamPost";
-
- r = client.doFormPost(url, new ObjectMap("{p1:'p1',p2:2}")).getResponseAsString();
- assertEquals("p1=[false,false],p2=[false,false]", r);
-
- r = client.doFormPost(url, new ObjectMap("{p1:null,p2:0}")).getResponseAsString();
- assertEquals("p1=[false,false],p2=[false,false]", r);
-
- r = client.doFormPost(url, new ObjectMap("{}")).getResponseAsString();
- assertEquals("p1=[false,false],p2=[false,false]", r);
-
- r = client.doFormPost(url, new ObjectMap("{p1:null}")).getResponseAsString();
- assertEquals("p1=[false,false],p2=[false,false]", r);
-
- r = client.doFormPost(url, new ObjectMap("{p2:0}")).getResponseAsString();
- assertEquals("p1=[false,false],p2=[false,false]", r);
-
- r = client.doFormPost(url, new ObjectMap("{p1:'foo',p2:0}")).getResponseAsString();
- assertEquals("p1=[false,false],p2=[false,false]", r);
-
- r = client.doFormPost(url, new ObjectMap("{p1:null,p2:1}")).getResponseAsString();
- assertEquals("p1=[false,false],p2=[false,false]", r);
-
- r = client.doFormPost(url, new ObjectMap("{p1:'a/b%c=d e,f/g%h=i j',p2:1}")).getResponseAsString();
- assertEquals("p1=[false,false],p2=[false,false]", r);
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // Form POSTS with @Content parameter
- //====================================================================================================
- @Test
- public void testFormPostAsContent() throws Exception {
- RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
- String r;
- String url = URL + "/testFormPostAsContent";
-
- r = client.doFormPost(url, new ObjectMap("{p1:'p1',p2:2}")).getResponseAsString();
- assertEquals("bean=[{p1:'p1',p2:2}],qp1=[null],qp2=[0],hqp1=[false],hqp2=[false]", r);
-
- r = client.doFormPost(url, new ObjectMap("{}")).getResponseAsString();
- assertEquals("bean=[{p2:0}],qp1=[null],qp2=[0],hqp1=[false],hqp2=[false]", r);
-
- r = client.doFormPost(url+"?p1=p3&p2=4", new ObjectMap("{p1:'p1',p2:2}")).getResponseAsString();
- assertEquals("bean=[{p1:'p1',p2:2}],qp1=[p3],qp2=[4],hqp1=[true],hqp2=[true]", r);
-
- r = client.doFormPost(url+"?p1=p3&p2=4", new ObjectMap("{}")).getResponseAsString();
- assertEquals("bean=[{p2:0}],qp1=[p3],qp2=[4],hqp1=[true],hqp2=[true]", r);
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // Test @Param and @QParam annotations when using multi-part parameters (e.g. &key=val1,&key=val2).
- //====================================================================================================
- @Test
- public void testMultiPartParams() throws Exception {
- RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
- String r;
- String url = URL + "/testMultiPartParams";
-
- String in = ""
- + "?p1=a&p1=b"
- + "&p2=1&p2=2"
- + "&p3=a&p3=b"
- + "&p4=1&p4=2"
- + "&p5=a&p5=b"
- + "&p6=1&p6=2"
- + "&p7=a&p7=b"
- + "&p8=1&p8=2"
- + "&p9=(a=1,b=2,c=false)&p9=(a=3,b=4,c=true)"
- + "&p10=(a=1,b=2,c=false)&p10=(a=3,b=4,c=true)"
- + "&p11=(a=1,b=2,c=false)&p11=(a=3,b=4,c=true)"
- + "&p12=(a=1,b=2,c=false)&p12=(a=3,b=4,c=true)";
- r = client.doGet(url + in).getResponseAsString();
- String e = "{"
- + "p1:['a','b'],"
- + "p2:[1,2],"
- + "p3:['a','b'],"
- + "p4:[1,2],"
- + "p5:['a','b'],"
- + "p6:[1,2],"
- + "p7:['a','b'],"
- + "p8:[1,2],"
- + "p9:[{a:'1',b:2,c:false},{a:'3',b:4,c:true}],"
- + "p10:[{a:'1',b:2,c:false},{a:'3',b:4,c:true}],"
- + "p11:[{a:'1',b:2,c:false},{a:'3',b:4,c:true}],"
- + "p12:[{a:'1',b:2,c:false},{a:'3',b:4,c:true}]"
- +"}";
- assertEquals(e, r);
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // Same as testMultiPartParams(), except make sure single values are still interpreted as collections.
- //====================================================================================================
- @Test
- public void testMultiPartParamsSingleValues() throws Exception {
- RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
- String r;
- String url = URL + "/testMultiPartParams";
-
- String in = ""
- + "?p1=a"
- + "&p2=1"
- + "&p3=a"
- + "&p4=1"
- + "&p5=a"
- + "&p6=1"
- + "&p7=a"
- + "&p8=1"
- + "&p9=(a=1,b=2,c=false)"
- + "&p10=(a=1,b=2,c=false)"
- + "&p11=(a=1,b=2,c=false)"
- + "&p12=(a=1,b=2,c=false)";
- r = client.doGet(url + in).getResponseAsString();
- String e = "{"
- + "p1:['a'],"
- + "p2:[1],"
- + "p3:['a'],"
- + "p4:[1],"
- + "p5:['a'],"
- + "p6:[1],"
- + "p7:['a'],"
- + "p8:[1],"
- + "p9:[{a:'1',b:2,c:false}],"
- + "p10:[{a:'1',b:2,c:false}],"
- + "p11:[{a:'1',b:2,c:false}],"
- + "p12:[{a:'1',b:2,c:false}]"
- +"}";
- assertEquals(e, r);
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // Test multi-part parameter keys on bean properties of type array/Collection (i.e. &key=val1,&key=val2)
- // using URLENC_expandedParams property.
- // A simple round-trip test to verify that both serializing and parsing works.
- //====================================================================================================
- @Test
- public void testFormPostsWithMultiParamsUsingProperty() throws Exception {
- RestClient client = new TestRestClient()
- .setHeader("Content-Type", "application/x-www-form-urlencoded")
- .setHeader("Accept", "application/x-www-form-urlencoded");
- String r;
- String url = URL + "/testFormPostsWithMultiParamsUsingProperty";
-
- String in = ""
- + "f1=a&f1=b"
- + "&f2=c&f2=d"
- + "&f3=1&f3=2"
- + "&f4=3&f4=4"
- + "&f5=(e,f)&f5=(g,h)"
- + "&f6=(i,j)&f6=(k,l)"
- + "&f7=(a=a,b=1,c=true)&f7=(a=b,b=2,c=false)"
- + "&f8=(a=a,b=1,c=true)&f8=(a=b,b=2,c=false)"
- + "&f9=((a=a,b=1,c=true))&f9=((a=b,b=2,c=false))"
- + "&f10=((a=a,b=1,c=true))&f10=((a=b,b=2,c=false))"
- + "&f11=a&f11=b"
- + "&f12=c&f12=d"
- + "&f13=1&f13=2"
- + "&f14=3&f14=4"
- + "&f15=(e,f)&f15=(g,h)"
- + "&f16=(i,j)&f16=(k,l)"
- + "&f17=(a=a,b=1,c=true)&f17=(a=b,b=2,c=false)"
- + "&f18=(a=a,b=1,c=true)&f18=(a=b,b=2,c=false)"
- + "&f19=((a=a,b=1,c=true))&f19=((a=b,b=2,c=false))"
- + "&f20=((a=a,b=1,c=true))&f20=((a=b,b=2,c=false))";
- r = client.doPost(url, new StringEntity(in)).getResponseAsString();
- assertEquals(in, r);
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // Test multi-part parameter keys on bean properties of type array/Collection (i.e. &key=val1,&key=val2)
- // using @UrlEncoding(expandedParams=true) annotation.
- // A simple round-trip test to verify that both serializing and parsing works.
- //====================================================================================================
- @Test
- public void testFormPostsWithMultiParamsUsingAnnotation() throws Exception {
- RestClient client = new TestRestClient()
- .setHeader("Content-Type", "application/x-www-form-urlencoded")
- .setHeader("Accept", "application/x-www-form-urlencoded");
- String r;
- String url = URL + "/testFormPostsWithMultiParamsUsingAnnotation";
-
- String in = ""
- + "f1=a&f1=b"
- + "&f2=c&f2=d"
- + "&f3=1&f3=2"
- + "&f4=3&f4=4"
- + "&f5=(e,f)&f5=(g,h)"
- + "&f6=(i,j)&f6=(k,l)"
- + "&f7=(a=a,b=1,c=true)&f7=(a=b,b=2,c=false)"
- + "&f8=(a=a,b=1,c=true)&f8=(a=b,b=2,c=false)"
- + "&f9=((a=a,b=1,c=true))&f9=((a=b,b=2,c=false))"
- + "&f10=((a=a,b=1,c=true))&f10=((a=b,b=2,c=false))"
- + "&f11=a&f11=b"
- + "&f12=c&f12=d"
- + "&f13=1&f13=2"
- + "&f14=3&f14=4"
- + "&f15=(e,f)&f15=(g,h)"
- + "&f16=(i,j)&f16=(k,l)"
- + "&f17=(a=a,b=1,c=true)&f17=(a=b,b=2,c=false)"
- + "&f18=(a=a,b=1,c=true)&f18=(a=b,b=2,c=false)"
- + "&f19=((a=a,b=1,c=true))&f19=((a=b,b=2,c=false))"
- + "&f20=((a=a,b=1,c=true))&f20=((a=b,b=2,c=false))";
- r = client.doPost(url, new StringEntity(in)).getResponseAsString();
- assertEquals(in, r);
-
- client.closeQuietly();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestParsersTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestParsersTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestParsersTest.java
deleted file mode 100755
index a3e4f76..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestParsersTest.java
+++ /dev/null
@@ -1,162 +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.server;
-
-import static javax.servlet.http.HttpServletResponse.*;
-import static org.apache.juneau.server.TestUtils.*;
-import static org.junit.Assert.*;
-
-import org.apache.juneau.client.*;
-import org.apache.juneau.plaintext.*;
-import org.junit.*;
-
-public class TestParsersTest {
-
- private static String URL = "/testParsers";
- private static boolean debug = false;
-
- //====================================================================================================
- // Parser defined on class.
- //====================================================================================================
- @Test
- public void testParserOnClass() throws Exception {
- RestClient client = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class);
- String url = URL + "/testParserOnClass";
-
- client.setContentType("text/a");
- String r = client.doPut(url, "test1").getResponseAsString();
- assertEquals("text/a - test1", r);
-
- try {
- client.setContentType("text/b");
- client.doPut(url + "?noTrace=true", "test1").getResponseAsString();
- fail("Exception expected");
- } catch (RestCallException e) {
- checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
- "Unsupported media-type in request header 'Content-Type': 'text/b'",
- "Supported media-types: [text/a"
- );
- }
-
- client.setContentType("text/json").setAccept("text/json");
- r = client.doPut(url, "'test1'").getResponseAsString();
- assertEquals("\"test1\"", r);
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // Parser defined on method.
- //====================================================================================================
- @Test
- public void testParserOnMethod() throws Exception {
- RestClient client = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class);
- String url = URL + "/testParserOnMethod";
-
- client.setContentType("text/b");
- String r = client.doPut(url, "test2").getResponseAsString();
- assertEquals("text/b - test2", r);
-
- try {
- client.setContentType("text/a");
- client.doPut(url + "?noTrace=true", "test2").getResponseAsString();
- fail("Exception expected");
- } catch (RestCallException e) {
- checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
- "Unsupported media-type in request header 'Content-Type': 'text/a'",
- "Supported media-types: [text/b]"
- );
- }
-
- try {
- client.setContentType("text/json");
- r = client.doPut(url + "?noTrace=true", "'test2'").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/b]"
- );
- }
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // Parser overridden on method.
- //====================================================================================================
- @Test
- public void testParserOverriddenOnMethod() throws Exception {
- RestClient client = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class);
- String url = URL + "/testParserOverriddenOnMethod";
-
- client.setContentType("text/a");
- String r = client.doPut(url, "test3").getResponseAsString();
- assertEquals("text/a - test3", r);
-
- client.setContentType("text/b");
- r = client.doPut(url, "test3").getResponseAsString();
- assertEquals("text/b - test3", r);
-
- client.setContentType("text/json");
- r = client.doPut(url, "'test3'").getResponseAsString();
- assertEquals("test3", r);
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // Parser with different Accept than Content-Type.
- //====================================================================================================
- @Test
- public void testParserWithDifferentMediaTypes() throws Exception {
- RestClient client = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class);
- String url = URL + "/testParserWithDifferentMediaTypes";
-
- client.setContentType("text/a");
- String r = client.doPut(url, "test4").getResponseAsString();
- assertEquals("text/d - test4", r);
-
- client.setContentType("text/d");
- r = client.doPut(url, "test4").getResponseAsString();
- assertEquals("text/d - test4", r);
-
- client.setContentType("text/json");
- r = client.doPut(url, "'test4'").getResponseAsString();
- assertEquals("test4", r);
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // Check for valid error response.
- //====================================================================================================
- @Test
- public void testValidErrorResponse() throws Exception {
- RestClient client = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class);
- String url = URL + "/testValidErrorResponse";
-
- try {
- client.setContentType("text/bad");
- client.doPut(url + "?noTrace=true", "test1").getResponseAsString();
- fail("Exception expected");
- } catch (RestCallException e) {
- checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
- "Unsupported media-type in request header 'Content-Type': 'text/bad'",
- "Supported media-types: [text/a"
- );
- }
-
- client.closeQuietly();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestPathTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestPathTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestPathTest.java
deleted file mode 100755
index 5ffd5b2..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestPathTest.java
+++ /dev/null
@@ -1,44 +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.server;
-
-import static org.junit.Assert.*;
-
-import org.apache.juneau.client.*;
-import org.apache.juneau.json.*;
-import org.junit.*;
-
-public class TestPathTest {
-
- private static String URL = "/testPath";
-
- //====================================================================================================
- // Basic tests
- //====================================================================================================
- @Test
- public void testBasic() throws Exception {
- RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
- String r = null;
-
- r = client.doGet(URL).getResponse(String.class);
- assertEquals("/testPath", r);
-
- r = client.doGet(URL + "/testPath2").getResponse(String.class);
- assertEquals("/testPath/testPath2", r);
-
- r = client.doGet(URL + "/testPath2/testPath3").getResponse(String.class);
- assertEquals("/testPath/testPath2/testPath3", r);
-
- client.closeQuietly();
- }
-}
[06/14] incubator-juneau git commit: Clean up test and test resource
class names.
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestAcceptCharsetTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestAcceptCharsetTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestAcceptCharsetTest.java
deleted file mode 100755
index 93a02b5..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestAcceptCharsetTest.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.server;
-
-import static javax.servlet.http.HttpServletResponse.*;
-import static org.apache.juneau.server.TestUtils.*;
-import static org.junit.Assert.*;
-
-import java.io.*;
-
-import org.apache.juneau.client.*;
-import org.apache.juneau.internal.*;
-import org.junit.*;
-
-public class TestAcceptCharsetTest {
-
- boolean debug = false;
-
- //====================================================================================================
- // Test that Q-values are being resolved correctly.
- //====================================================================================================
- @Test
- public void testQValues() throws Exception {
- RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
-
- 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");
-
- client.closeQuietly();
- }
-
- private void check1(RestClient client, String requestCharset, String responseCharset) throws Exception {
- RestCall r;
- InputStream is;
- String url = "/testAcceptCharset/testQValues";
- r = client.doGet(url).setHeader("Accept-Charset", requestCharset).connect();
- assertTrue(r.getResponse().getFirstHeader("Content-Type").getValue().toLowerCase().contains(responseCharset));
- is = r.getInputStream();
- assertEquals("foo", IOUtils.read(new InputStreamReader(is, responseCharset)));
- }
-
- //====================================================================================================
- // Validate various Accept-Charset variations.
- //====================================================================================================
- @Test
- public void testCharsetOnResponse() throws Exception {
- RestClient client = new TestRestClient().setAccept("text/plain").setContentType("text/plain");
- 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("")).setHeader("Accept-Charset", "Shift_JIS").getResponseAsString();
- assertEquals("utf-8/shift_jis", r.toLowerCase());
-
- try {
- r = client.doPut(url+"?noTrace=true", new StringReader("")).setHeader("Accept-Charset", "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("")).setHeader("Accept-Charset", "UTF-8").getResponseAsString();
- assertEquals("utf-8/utf-8", r.toLowerCase());
-
- r = client.doPut(url, new StringReader("")).setHeader("Accept-Charset", "bad,iso-8859-1").getResponseAsString();
- assertEquals("utf-8/iso-8859-1", r.toLowerCase());
-
- r = client.doPut(url, new StringReader("")).setHeader("Accept-Charset", "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("")).setHeader("Accept-Charset", "bad;q=0.1,iso-8859-1;q=0.9").getResponseAsString();
- assertEquals("utf-8/iso-8859-1", r.toLowerCase());
-
- client.setHeader("Accept-Charset", "utf-8");
-
- r = client.doPut(url, new StringReader("")).setHeader("Content-Type", "text/plain").getResponseAsString();
- assertEquals("utf-8/utf-8", r.toLowerCase());
-
- r = client.doPut(url, new StringReader("")).setHeader("Content-Type", "text/plain;charset=utf-8").getResponseAsString();
- assertEquals("utf-8/utf-8", r.toLowerCase());
-
- r = client.doPut(url, new StringReader("")).setHeader("Content-Type", "text/plain;charset=UTF-8").getResponseAsString();
- assertEquals("utf-8/utf-8", r.toLowerCase());
-
- r = client.doPut(url, new StringReader("")).setHeader("Content-Type", "text/plain;charset=iso-8859-1").getResponseAsString();
- assertEquals("iso-8859-1/utf-8", r.toLowerCase());
-
- r = client.doPut(url, new StringReader("")).setHeader("Content-Type", "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
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestBeanContextPropertiesTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestBeanContextPropertiesTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestBeanContextPropertiesTest.java
deleted file mode 100755
index 50ec9c6..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestBeanContextPropertiesTest.java
+++ /dev/null
@@ -1,37 +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.server;
-
-import static org.junit.Assert.*;
-
-import org.apache.juneau.client.*;
-import org.apache.juneau.json.*;
-import org.junit.*;
-
-public class TestBeanContextPropertiesTest {
-
- boolean debug = false;
-
- //====================================================================================================
- // Validate that filters defined on class filter to underlying bean context.
- //====================================================================================================
- @Test
- public void testClassTransforms() throws Exception {
- RestClient client = new TestRestClient(JsonSerializer.class, JsonParser.class);
- String r;
- r = client.doGet("/testBeanContext/testClassTransforms/2001-07-04T15:30:45Z?d2=2001-07-05T15:30:45Z").setHeader("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);
-
- client.closeQuietly();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestCallbackStringsTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestCallbackStringsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestCallbackStringsTest.java
deleted file mode 100755
index 2d8ccca..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestCallbackStringsTest.java
+++ /dev/null
@@ -1,50 +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.server;
-
-import static org.junit.Assert.*;
-
-import org.apache.juneau.client.*;
-import org.junit.*;
-
-public class TestCallbackStringsTest {
-
- //====================================================================================================
- // Basic tests using &Content parameter
- //====================================================================================================
- @Test
- public void test() throws Exception {
- RestClient c = new TestRestClient().setAccept("text/json+simple");
- String r;
-
- r = c.doCallback("GET /testCallback").getResponseAsString();
- assertEquals("{method:'GET',headers:{},content:''}", r);
-
- r = c.doCallback("GET /testCallback some sample content").getResponseAsString();
- assertEquals("{method:'GET',headers:{},content:'some sample content'}", r);
-
- r = c.doCallback("GET {Foo-X:123,Foo-Y:'abc'} /testCallback").getResponseAsString();
- assertEquals("{method:'GET',headers:{'Foo-X':'123','Foo-Y':'abc'},content:''}", r);
-
- r = c.doCallback("GET { Foo-X : 123, Foo-Y : 'abc' } /testCallback").getResponseAsString();
- assertEquals("{method:'GET',headers:{'Foo-X':'123','Foo-Y':'abc'},content:''}", r);
-
- r = c.doCallback("GET {Foo-X:123,Foo-Y:'abc'} /testCallback some sample content ").getResponseAsString();
- assertEquals("{method:'GET',headers:{'Foo-X':'123','Foo-Y':'abc'},content:'some sample content'}", r);
-
- r = c.doCallback("PUT {Foo-X:123,Foo-Y:'abc'} /testCallback some sample content ").getResponseAsString();
- assertEquals("{method:'PUT',headers:{'Foo-X':'123','Foo-Y':'abc'},content:'some sample content'}", r);
-
- c.closeQuietly();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestCharsetEncodingsTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestCharsetEncodingsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestCharsetEncodingsTest.java
deleted file mode 100755
index 996f283..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestCharsetEncodingsTest.java
+++ /dev/null
@@ -1,96 +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.server;
-
-import static javax.servlet.http.HttpServletResponse.*;
-import static org.apache.juneau.server.TestUtils.*;
-import static org.junit.Assert.*;
-
-import java.io.*;
-
-import org.apache.juneau.client.*;
-import org.apache.juneau.internal.*;
-import org.junit.*;
-
-
-public class TestCharsetEncodingsTest {
-
- private static boolean debug = false;
-
- /**
- * Basic tests to ensure that the correct charsets are found and used
- * under a variety of scenarios.
- */
- @Test
- public void test() throws Exception {
- String url = "/testCharsetEncodings";
- RestClient client = new TestRestClient().setAccept("text/s").setContentType("text/p");
- InputStream is;
- String r;
-
- r = client.doPut(url, new StringReader("foo")).getResponseAsString();
- if (debug) System.err.println(r);
- assertEquals("utf-8/foo/utf-8", r);
-
- is = client.doPut(url, new StringReader("foo")).getInputStream();
- r = IOUtils.read(new InputStreamReader(is, "utf-8"));
- if (debug) System.err.println(r);
- assertEquals("utf-8/foo/utf-8", r);
-
- client.setHeader("Accept-Charset", "utf-8").setContentType("text/p;charset=utf-8");
- is = client.doPut(url, new StringReader("foo")).getInputStream();
- r = IOUtils.read(new InputStreamReader(is, "utf-8"));
- if (debug) System.err.println(r);
- assertEquals("utf-8/foo/utf-8", r);
-
- client.setHeader("Accept-Charset", "Shift_JIS").setContentType("text/p;charset=shift_jis");
- is = client.doPut(url, new StringReader("foo")).getInputStream();
- r = IOUtils.read(new InputStreamReader(is, "Shift_JIS"));
- if (debug) System.err.println(r);
- assertEquals("shift_jis/foo/shift_jis", r);
-
- try {
- client.setHeader("Accept-Charset", "BAD").setContentType("text/p;charset=sjis");
- is = client.doPut(url + "?noTrace=true", new StringReader("foo")).getInputStream();
- r = IOUtils.read(new InputStreamReader(is, "sjis"));
- if (debug) System.err.println(r);
- fail("Exception expected");
- } catch (RestCallException e) {
- checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, "No supported charsets in header 'Accept-Charset': 'BAD'");
- }
-
- client.setAccept("text/s").setHeader("Accept-Charset", "utf-8").setContentType("text/p");
- is = client.doPut(url+"?Content-Type=text/p", new StringReader("foo")).getInputStream();
- r = IOUtils.read(new InputStreamReader(is, "utf-8"));
- if (debug) System.err.println(r);
- assertEquals("utf-8/foo/utf-8", r);
-
- client.setAccept("text/s").setContentType("text/bad").setHeader("Accept-Charset", "utf-8");
- is = client.doPut(url+"?Content-Type=text/p;charset=utf-8", new StringReader("foo")).getInputStream();
- r = IOUtils.read(new InputStreamReader(is, "utf-8"));
- if (debug) System.err.println(r);
- assertEquals("utf-8/foo/utf-8", r);
-
- try {
- client.setAccept("text/s").setContentType("text/p").setHeader("Accept-Charset", "utf-8");
- is = client.doPut(url+"?Content-Type=text/p;charset=BAD&noTrace=true", new StringReader("foo")).getInputStream();
- r = IOUtils.read(new InputStreamReader(is, "utf-8"));
- if (debug) System.err.println(r);
- assertEquals("utf-8/foo/utf-8", r);
- fail("Exception expected");
- } catch (RestCallException e) {
- checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE, "Unsupported charset in header 'Content-Type': 'text/p;charset=BAD'");
- }
- client.closeQuietly();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestClientVersionTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestClientVersionTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestClientVersionTest.java
deleted file mode 100644
index 7e78b73..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestClientVersionTest.java
+++ /dev/null
@@ -1,90 +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.server;
-
-import static org.junit.Assert.*;
-
-import org.apache.juneau.client.*;
-import org.apache.juneau.plaintext.*;
-import org.junit.*;
-
-public class TestClientVersionTest {
-
- private static String URL = "/testClientVersion";
-
- //====================================================================================================
- // Basic tests - default X-Client-Version header.
- //====================================================================================================
- @Test
- public void testDefaultHeader() throws Exception {
- RestClient c = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class);
- String url = URL + "/defaultHeader";
-
- assertEquals("no-version", c.doGet(url).getResponseAsString());
-
-// for (String s : "0, 0.0, 0.1, .1, .9, .99".split("\\s*,\\s*")) {
-// c.setClientVersion(s);
-// assertEquals(s, "[0.0,1.0)", c.doGet(url).getResponseAsString());
-// }
-
- for (String s : "1, 1.0, 1.0.0, 1.0.1".split("\\s*,\\s*")) {
- c.setClientVersion(s);
- assertEquals(s, "[1.0,1.0]", c.doGet(url).getResponseAsString());
- }
-
- for (String s : "1.1, 1.1.1, 1.2, 1.9.9".split("\\s*,\\s*")) {
- c.setClientVersion(s);
- assertEquals(s, "[1.1,2)", c.doGet(url).getResponseAsString());
- }
-
- for (String s : "2, 2.0, 2.1, 9, 9.9".split("\\s*,\\s*")) {
- c.setClientVersion(s);
- assertEquals(s, "2", c.doGet(url).getResponseAsString());
- }
-
- c.closeQuietly();
- }
-
- //====================================================================================================
- // Basic tests - Custom-Client-Version header.
- //====================================================================================================
- @Test
- public void testCustomHeader() throws Exception {
- RestClient c = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class);
- String url = URL + "/customHeader";
-
- assertEquals("no-version", c.doGet(url).getResponseAsString());
-
- for (String s : "0, 0.0, 0.1, .1, .9, .99".split("\\s*,\\s*")) {
- c.setHeader("Custom-Client-Version", s);
- assertEquals("[0.0,1.0)", c.doGet(url).getResponseAsString());
- }
-
- for (String s : "1, 1.0, 1.0.0, 1.0.1".split("\\s*,\\s*")) {
- c.setHeader("Custom-Client-Version", s);
- assertEquals("[1.0,1.0]", c.doGet(url).getResponseAsString());
- }
-
- for (String s : "1.1, 1.1.1, 1.2, 1.9.9".split("\\s*,\\s*")) {
- c.setHeader("Custom-Client-Version", s);
- assertEquals("[1.1,2)", c.doGet(url).getResponseAsString());
- }
-
- for (String s : "2, 2.0, 2.1, 9, 9.9".split("\\s*,\\s*")) {
- c.setHeader("Custom-Client-Version", s);
- assertEquals("2", c.doGet(url).getResponseAsString());
- }
-
- c.closeQuietly();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestConfigTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestConfigTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestConfigTest.java
deleted file mode 100755
index a417093..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestConfigTest.java
+++ /dev/null
@@ -1,58 +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.server;
-
-import static org.apache.juneau.server.TestUtils.*;
-import static org.junit.Assert.*;
-
-import org.apache.juneau.client.*;
-import org.apache.juneau.ini.*;
-import org.apache.juneau.json.*;
-import org.junit.*;
-
-public class TestConfigTest {
-
- private static String URL = "/testConfig";
-
- //====================================================================================================
- // Basic tests
- //====================================================================================================
- @Test
- public void test() throws Exception {
- RestClient c = new TestRestClient(JsonSerializer.class, JsonParser.class).setAccept("text/json+simple");
-
- ConfigFile cf = c.doGet(URL).getResponse(ConfigFileImpl.class);
-
- assertObjectEquals("{int1:'1',int2:'1,2,3',int3:'$C{Test/int1, -1}',int4:'$C{Test/int3, -1}',int5:'$C{XXX, -1}',boolean1:'true',boolean2:'true,true',path:'$E{PATH}',mainClass:'$MF{Main-Class}',importPackage:'$MF{Import-Package}'}", cf.get("Test"));
-
- assertEquals("'1'", c.doGet(URL + "/Test%2Fint1/" + getName(String.class)).getResponseAsString());
- assertEquals("['1']", c.doGet(URL + "/Test%2Fint1/" + getName(String[].class)).getResponseAsString());
- assertEquals("'1,2,3'", c.doGet(URL + "/Test%2Fint2/" + getName(String.class)).getResponseAsString());
- assertEquals("['1','2','3']", c.doGet(URL + "/Test%2Fint2/" + getName(String[].class)).getResponseAsString());
- assertEquals("[1,2,3]", c.doGet(URL + "/Test%2Fint2/" + getName(int[].class)).getResponseAsString());
- assertEquals("[1,2,3]", c.doGet(URL + "/Test%2Fint2/" + getName(Integer[].class)).getResponseAsString());
- assertEquals("[1]", c.doGet(URL + "/Test%2Fint3/" + getName(int[].class)).getResponseAsString());
- assertEquals("[1]", c.doGet(URL + "/Test%2Fint4/" + getName(int[].class)).getResponseAsString());
- assertEquals("[-1]", c.doGet(URL + "/Test%2Fint5/" + getName(int[].class)).getResponseAsString());
- assertEquals("true", c.doGet(URL + "/Test%2Fboolean1/" + getName(Boolean.class)).getResponseAsString());
- assertEquals("[true,true]", c.doGet(URL + "/Test%2Fboolean2/" + getName(Boolean[].class)).getResponseAsString());
- assertTrue(c.doGet(URL + "/Test%2Fpath/" + getName(String.class)).getResponseAsString().length() > 10);
- assertEquals("'org.apache.juneau.microservice.RestMicroservice'", c.doGet(URL + "/Test%2FmainClass/" + getName(String.class)).getResponseAsString());
-
- c.closeQuietly();
- }
-
- private String getName(Class<?> c) {
- return RestUtils.encode(c.getName());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestContentTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestContentTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestContentTest.java
deleted file mode 100755
index 84a6010..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestContentTest.java
+++ /dev/null
@@ -1,706 +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.server;
-
-import static org.junit.Assert.*;
-
-import java.io.*;
-import java.net.*;
-
-import org.apache.juneau.client.*;
-import org.apache.juneau.json.*;
-import org.apache.juneau.plaintext.*;
-import org.apache.juneau.urlencoding.*;
-import org.junit.*;
-
-public class TestContentTest {
-
- private static String URL = "/testContent";
-
- //====================================================================================================
- // Basic tests using &Content parameter
- //====================================================================================================
- @Test
- public void testUsingContentParam() throws Exception {
- RestClient c = new TestRestClient().setAccept("text/json+simple");
- String r;
-
- // @RestMethod(name="POST", path="/boolean")
- // public boolean testBool(@Content boolean b) {
- // return b;
- // }
- r = c.doPost(URL + "/boolean?content=true", null).getResponseAsString();
- assertEquals("true", r);
- r = c.doPost(URL + "/boolean?content=(true)", null).getResponseAsString();
- assertEquals("true", r);
- r = c.doPost(URL + "/boolean?content=$b(true)", null).getResponseAsString();
- assertEquals("true", r);
- r = c.doPost(URL + "/boolean?content=false", null).getResponseAsString();
- assertEquals("false", r);
- r = c.doPost(URL + "/boolean?content=(false)", null).getResponseAsString();
- assertEquals("false", r);
- r = c.doPost(URL + "/boolean?content=$b(false)", null).getResponseAsString();
- assertEquals("false", r);
- try {
- r = c.doPost(URL + "/boolean?content=%00&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
- try {
- r = c.doPost(URL + "/boolean?content=bad&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
-
- // @RestMethod(name="POST", path="/Boolean")
- // public Boolean testBoolean(@Content Boolean b) {
- // return b;
- // }
- r = c.doPost(URL + "/Boolean?content=true", null).getResponseAsString();
- assertEquals("true", r);
- r = c.doPost(URL + "/Boolean?content=(true)", null).getResponseAsString();
- assertEquals("true", r);
- r = c.doPost(URL + "/Boolean?content=$b(true)", null).getResponseAsString();
- assertEquals("true", r);
- r = c.doPost(URL + "/Boolean?content=false", null).getResponseAsString();
- assertEquals("false", r);
- r = c.doPost(URL + "/Boolean?content=(false)", null).getResponseAsString();
- assertEquals("false", r);
- r = c.doPost(URL + "/Boolean?content=$b(false)", null).getResponseAsString();
- assertEquals("false", r);
- r = c.doPost(URL + "/Boolean?content=%00", null).getResponseAsString();
- assertEquals("null", r);
- try {
- r = c.doPost(URL + "/Boolean?content=bad&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
- // @RestMethod(name="POST", path="/int")
- // public int testInt(@Content int i) {
- // return i;
- // }
- r = c.doPost(URL + "/int?content=-123", null).getResponseAsString();
- assertEquals("-123", r);
- r = c.doPost(URL + "/int?content=(-123)", null).getResponseAsString();
- assertEquals("-123", r);
- r = c.doPost(URL + "/int?content=$n(-123)", null).getResponseAsString();
- assertEquals("-123", r);
- try {
- r = c.doPost(URL + "/int?content=%00&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
- try {
- r = c.doPost(URL + "/int?content=bad&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
- // @RestMethod(name="POST", path="/Integer")
- // public Integer testInteger(@Content Integer i) {
- // return i;
- // }
- r = c.doPost(URL + "/Integer?content=-123", null).getResponseAsString();
- assertEquals("-123", r);
- r = c.doPost(URL + "/Integer?content=(-123)", null).getResponseAsString();
- assertEquals("-123", r);
- r = c.doPost(URL + "/Integer?content=$n(-123)", null).getResponseAsString();
- assertEquals("-123", r);
- r = c.doPost(URL + "/Integer?content=%00", null).getResponseAsString();
- assertEquals("null", r);
- try {
- r = c.doPost(URL + "/Integer?content=bad&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
- // @RestMethod(name="POST", path="/float")
- // public float testFloat(@Content float f) {
- // return f;
- // }
- r = c.doPost(URL + "/float?content=-1.23", null).getResponseAsString();
- assertEquals("-1.23", r);
- r = c.doPost(URL + "/float?content=(-1.23)", null).getResponseAsString();
- assertEquals("-1.23", r);
- r = c.doPost(URL + "/float?content=$n(-1.23)", null).getResponseAsString();
- assertEquals("-1.23", r);
- try {
- r = c.doPost(URL + "/float?content=%00&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
- try {
- r = c.doPost(URL + "/float?content=bad&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
- // @RestMethod(name="POST", path="/Float")
- // public Float testFloat2(@Content Float f) {
- // return f;
- // }
- r = c.doPost(URL + "/Float?content=-1.23", null).getResponseAsString();
- assertEquals("-1.23", r);
- r = c.doPost(URL + "/Float?content=(-1.23)", null).getResponseAsString();
- assertEquals("-1.23", r);
- r = c.doPost(URL + "/Float?content=$n(-1.23)", null).getResponseAsString();
- assertEquals("-1.23", r);
- r = c.doPost(URL + "/Float?content=%00", null).getResponseAsString();
- assertEquals("null", r);
- try {
- r = c.doPost(URL + "/Float?content=bad&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
- // @RestMethod(name="POST", path="/Map")
- // public TreeMap<String,String> testMap(@Content TreeMap<String,String> m) {
- // return m;
- // }
- r = c.doPost(URL + "/Map?content=(a=b,c=d)", null).getResponseAsString();
- assertEquals("{a:'b',c:'d'}", r);
- r = c.doPost(URL + "/Map?content=%00", null).getResponseAsString();
- assertEquals("null", r);
- try {
- r = c.doPost(URL + "/Map?content=bad&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
- // @RestMethod(name="POST", path="/B")
- // public DTO2s.B testPojo1(@Content DTO2s.B b) {
- // return b;
- // }
- DTOs.B b = DTOs.B.create();
- r = c.doPost(URL + "/B?content=" + UonSerializer.DEFAULT.serialize(b), null).getResponseAsString();
- assertEquals("{f1:['a','b'],f2:['c','d'],f3:[1,2],f4:[3,4],f5:[['e','f'],['g','h']],f6:[['i','j'],['k','l']],f7:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f8:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f9:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r);
- r = c.doPost(URL + "/B?content=" + UonSerializer.DEFAULT_SIMPLE.serialize(b), null).getResponseAsString();
- assertEquals("{f1:['a','b'],f2:['c','d'],f3:[1,2],f4:[3,4],f5:[['e','f'],['g','h']],f6:[['i','j'],['k','l']],f7:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f8:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f9:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r);
-
- // @RestMethod(name="POST", path="/C")
- // public DTO2s.C testPojo2(@Content DTO2s.C c) {
- // return c;
- // }
- DTOs.C x = DTOs.C.create();
- r = c.doPost(URL + "/C?content=" + UonSerializer.DEFAULT.serialize(x), null).getResponseAsString();
- assertEquals("{f1:['a','b'],f2:['c','d'],f3:[1,2],f4:[3,4],f5:[['e','f'],['g','h']],f6:[['i','j'],['k','l']],f7:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f8:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f9:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r);
- r = c.doPost(URL + "/C?content=" + UonSerializer.DEFAULT_SIMPLE.serialize(x), null).getResponseAsString();
- assertEquals("{f1:['a','b'],f2:['c','d'],f3:[1,2],f4:[3,4],f5:[['e','f'],['g','h']],f6:[['i','j'],['k','l']],f7:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f8:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f9:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r);
-
- c.closeQuietly();
- }
-
- //====================================================================================================
- // Basic tests using &Content parameter with &Accept=text/json
- //====================================================================================================
- @Test
- public void testUsingContentParamJsonHeader() throws Exception {
- RestClient c = new TestRestClient().setAccept("text/json+simple").setHeader("Content-Type", "text/json");
- String r;
-
- // @RestMethod(name="POST", path="/boolean")
- // public boolean testBool(@Content boolean b) {
- // return b;
- // }
- r = c.doPost(URL + "/boolean?content=true", null).getResponseAsString();
- assertEquals("true", r);
- r = c.doPost(URL + "/boolean?content=false", null).getResponseAsString();
- assertEquals("false", r);
- try {
- r = c.doPost(URL + "/boolean?content=null&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
- try {
- r = c.doPost(URL + "/boolean?content=bad&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
-
- // @RestMethod(name="POST", path="/Boolean")
- // public Boolean testBoolean(@Content Boolean b) {
- // return b;
- // }
- r = c.doPost(URL + "/Boolean?content=true", null).getResponseAsString();
- assertEquals("true", r);
- r = c.doPost(URL + "/Boolean?content=false", null).getResponseAsString();
- assertEquals("false", r);
- r = c.doPost(URL + "/Boolean?content=null", null).getResponseAsString();
- assertEquals("null", r);
- try {
- r = c.doPost(URL + "/Boolean?content=bad&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
- // @RestMethod(name="POST", path="/int")
- // public int testInt(@Content int i) {
- // return i;
- // }
- r = c.doPost(URL + "/int?content=-123", null).getResponseAsString();
- assertEquals("-123", r);
- try {
- r = c.doPost(URL + "/int?content=null&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
- try {
- r = c.doPost(URL + "/int?content=bad&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
- // @RestMethod(name="POST", path="/Integer")
- // public Integer testInteger(@Content Integer i) {
- // return i;
- // }
- r = c.doPost(URL + "/Integer?content=-123", null).getResponseAsString();
- assertEquals("-123", r);
- r = c.doPost(URL + "/Integer?content=null", null).getResponseAsString();
- assertEquals("null", r);
- try {
- r = c.doPost(URL + "/Integer?content=bad&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
- // @RestMethod(name="POST", path="/float")
- // public float testFloat(@Content float f) {
- // return f;
- // }
- r = c.doPost(URL + "/float?content=-1.23", null).getResponseAsString();
- assertEquals("-1.23", r);
- try {
- r = c.doPost(URL + "/float?content=null&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
- try {
- r = c.doPost(URL + "/float?content=bad&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
- // @RestMethod(name="POST", path="/Float")
- // public Float testFloat2(@Content Float f) {
- // return f;
- // }
- r = c.doPost(URL + "/Float?content=-1.23", null).getResponseAsString();
- assertEquals("-1.23", r);
- r = c.doPost(URL + "/Float?content=null", null).getResponseAsString();
- assertEquals("null", r);
- try {
- r = c.doPost(URL + "/Float?content=bad&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
- // @RestMethod(name="POST", path="/Map")
- // public TreeMap<String,String> testMap(@Content TreeMap<String,String> m) {
- // return m;
- // }
- r = c.doPost(URL + "/Map?content=" + encode("{a:'b',c:'d'}"), null).getResponseAsString();
- assertEquals("{a:'b',c:'d'}", r);
- r = c.doPost(URL + "/Map?content=null", null).getResponseAsString();
- assertEquals("null", r);
- try {
- r = c.doPost(URL + "/Map?content=bad&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
- // @RestMethod(name="POST", path="/B")
- // public DTO2s.B testPojo1(@Content DTO2s.B b) {
- // return b;
- // }
- DTOs.B b = DTOs.B.create();
- r = c.doPost(URL + "/B?content=" + encode(JsonSerializer.DEFAULT_LAX.serialize(b)), null).getResponseAsString();
- assertEquals("{f1:['a','b'],f2:['c','d'],f3:[1,2],f4:[3,4],f5:[['e','f'],['g','h']],f6:[['i','j'],['k','l']],f7:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f8:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f9:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r);
-
- // @RestMethod(name="POST", path="/C")
- // public DTO2s.C testPojo2(@Content DTO2s.C c) {
- // return c;
- // }
- DTOs.C x = DTOs.C.create();
- r = c.doPost(URL + "/C?content=" + encode(JsonSerializer.DEFAULT_LAX.serialize(x)), null).getResponseAsString();
- assertEquals("{f1:['a','b'],f2:['c','d'],f3:[1,2],f4:[3,4],f5:[['e','f'],['g','h']],f6:[['i','j'],['k','l']],f7:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f8:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f9:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r);
-
- c.closeQuietly();
- }
-
- //====================================================================================================
- // Basic tests using &Content parameter with &Accept=text/json
- //====================================================================================================
- @Test
- public void testUsingContentParamJsonParam() throws Exception {
- RestClient c = new TestRestClient().setAccept("text/json+simple");
- String r;
-
- // @RestMethod(name="POST", path="/boolean")
- // public boolean testBool(@Content boolean b) {
- // return b;
- // }
- r = c.doPost(URL + "/boolean?content=true&Content-Type=text/json", null).getResponseAsString();
- assertEquals("true", r);
- r = c.doPost(URL + "/boolean?content=false&Content-Type=text/json", null).getResponseAsString();
- assertEquals("false", r);
- try {
- r = c.doPost(URL + "/boolean?content=null&Content-Type=text/json&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
- try {
- r = c.doPost(URL + "/boolean?content=bad&Content-Type=text/json&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
-
- // @RestMethod(name="POST", path="/Boolean")
- // public Boolean testBoolean(@Content Boolean b) {
- // return b;
- // }
- r = c.doPost(URL + "/Boolean?content=true&Content-Type=text/json", null).getResponseAsString();
- assertEquals("true", r);
- r = c.doPost(URL + "/Boolean?content=false&Content-Type=text/json", null).getResponseAsString();
- assertEquals("false", r);
- r = c.doPost(URL + "/Boolean?content=null&Content-Type=text/json", null).getResponseAsString();
- assertEquals("null", r);
- try {
- r = c.doPost(URL + "/Boolean?content=bad&Content-Type=text/json&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
- // @RestMethod(name="POST", path="/int")
- // public int testInt(@Content int i) {
- // return i;
- // }
- r = c.doPost(URL + "/int?content=-123&Content-Type=text/json", null).getResponseAsString();
- assertEquals("-123", r);
- try {
- r = c.doPost(URL + "/int?content=null&Content-Type=text/json&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
- try {
- r = c.doPost(URL + "/int?content=bad&Content-Type=text/json&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
- // @RestMethod(name="POST", path="/Integer")
- // public Integer testInteger(@Content Integer i) {
- // return i;
- // }
- r = c.doPost(URL + "/Integer?content=-123&Content-Type=text/json", null).getResponseAsString();
- assertEquals("-123", r);
- r = c.doPost(URL + "/Integer?content=null&Content-Type=text/json", null).getResponseAsString();
- assertEquals("null", r);
- try {
- r = c.doPost(URL + "/Integer?content=bad&Content-Type=text/json&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
- // @RestMethod(name="POST", path="/float")
- // public float testFloat(@Content float f) {
- // return f;
- // }
- r = c.doPost(URL + "/float?content=-1.23&Content-Type=text/json", null).getResponseAsString();
- assertEquals("-1.23", r);
- try {
- r = c.doPost(URL + "/float?content=null&Content-Type=text/json&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
- try {
- r = c.doPost(URL + "/float?content=bad&Content-Type=text/json&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
- // @RestMethod(name="POST", path="/Float")
- // public Float testFloat2(@Content Float f) {
- // return f;
- // }
- r = c.doPost(URL + "/Float?content=-1.23&Content-Type=text/json", null).getResponseAsString();
- assertEquals("-1.23", r);
- r = c.doPost(URL + "/Float?content=null&Content-Type=text/json", null).getResponseAsString();
- assertEquals("null", r);
- try {
- r = c.doPost(URL + "/Float?content=bad&Content-Type=text/json&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
- // @RestMethod(name="POST", path="/Map")
- // public TreeMap<String,String> testMap(@Content TreeMap<String,String> m) {
- // return m;
- // }
- r = c.doPost(URL + "/Map?content=" + encode("{a:'b',c:'d'}") + "&Content-Type=text/json", null).getResponseAsString();
- assertEquals("{a:'b',c:'d'}", r);
- r = c.doPost(URL + "/Map?content=null&Content-Type=text/json", null).getResponseAsString();
- assertEquals("null", r);
- try {
- r = c.doPost(URL + "/Map?content=bad&Content-Type=text/json&noTrace=true", null).getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
- // @RestMethod(name="POST", path="/B")
- // public DTO2s.B testPojo1(@Content DTO2s.B b) {
- // return b;
- // }
- DTOs.B b = DTOs.B.create();
- r = c.doPost(URL + "/B?content=" + encode(JsonSerializer.DEFAULT_LAX.serialize(b)) + "&Content-Type=text/json", null).getResponseAsString();
- assertEquals("{f1:['a','b'],f2:['c','d'],f3:[1,2],f4:[3,4],f5:[['e','f'],['g','h']],f6:[['i','j'],['k','l']],f7:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f8:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f9:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r);
-
- // @RestMethod(name="POST", path="/C")
- // public DTO2s.C testPojo2(@Content DTO2s.C c) {
- // return c;
- // }
- DTOs.C x = DTOs.C.create();
- r = c.doPost(URL + "/C?content=" + encode(JsonSerializer.DEFAULT_LAX.serialize(x)) + "&Content-Type=text/json", null).getResponseAsString();
- assertEquals("{f1:['a','b'],f2:['c','d'],f3:[1,2],f4:[3,4],f5:[['e','f'],['g','h']],f6:[['i','j'],['k','l']],f7:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f8:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f9:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r);
-
- c.closeQuietly();
- }
-
- //====================================================================================================
- // Basic tests using HTTP body content
- //====================================================================================================
- @Test
- public void testUsingContent() throws Exception {
- RestClient c = new TestRestClient().setAccept("text/json+simple").setHeader("Content-Type", "text/uon").setSerializer(PlainTextSerializer.class);
- String r;
-
- // @RestMethod(name="POST", path="/boolean")
- // public boolean testBool(@Content boolean b) {
- // return b;
- // }
- r = c.doPost(URL + "/boolean", "true").getResponseAsString();
- assertEquals("true", r);
- r = c.doPost(URL + "/boolean", "(true)").getResponseAsString();
- assertEquals("true", r);
- r = c.doPost(URL + "/boolean", "$b(true)").getResponseAsString();
- assertEquals("true", r);
- r = c.doPost(URL + "/boolean", "false").getResponseAsString();
- assertEquals("false", r);
- r = c.doPost(URL + "/boolean", "(false)").getResponseAsString();
- assertEquals("false", r);
- r = c.doPost(URL + "/boolean", "$b(false)").getResponseAsString();
- assertEquals("false", r);
- try {
- r = c.doPost(URL + "/boolean?noTrace=true", "%00").getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
- try {
- r = c.doPost(URL + "/boolean?noTrace=true", "bad").getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
-
- // @RestMethod(name="POST", path="/Boolean")
- // public Boolean testBoolean(@Content Boolean b) {
- // return b;
- // }
- r = c.doPost(URL + "/Boolean", "true").getResponseAsString();
- assertEquals("true", r);
- r = c.doPost(URL + "/Boolean", "(true)").getResponseAsString();
- assertEquals("true", r);
- r = c.doPost(URL + "/Boolean", "$b(true)").getResponseAsString();
- assertEquals("true", r);
- r = c.doPost(URL + "/Boolean", "false").getResponseAsString();
- assertEquals("false", r);
- r = c.doPost(URL + "/Boolean", "(false)").getResponseAsString();
- assertEquals("false", r);
- r = c.doPost(URL + "/Boolean", "$b(false)").getResponseAsString();
- assertEquals("false", r);
- r = c.doPost(URL + "/Boolean", "\u0000").getResponseAsString();
- assertEquals("null", r);
- try {
- r = c.doPost(URL + "/Boolean?noTrace=true", "bad").getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
- // @RestMethod(name="POST", path="/int")
- // public int testInt(@Content int i) {
- // return i;
- // }
- r = c.doPost(URL + "/int", "-123").getResponseAsString();
- assertEquals("-123", r);
- r = c.doPost(URL + "/int", "(-123)").getResponseAsString();
- assertEquals("-123", r);
- r = c.doPost(URL + "/int", "$n(-123)").getResponseAsString();
- assertEquals("-123", r);
- try {
- r = c.doPost(URL + "/int?noTrace=true", "%00").getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
- try {
- r = c.doPost(URL + "/int?noTrace=true", "bad").getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
- // @RestMethod(name="POST", path="/Integer")
- // public Integer testInteger(@Content Integer i) {
- // return i;
- // }
- r = c.doPost(URL + "/Integer", "-123").getResponseAsString();
- assertEquals("-123", r);
- r = c.doPost(URL + "/Integer", "(-123)").getResponseAsString();
- assertEquals("-123", r);
- r = c.doPost(URL + "/Integer", "$n(-123)").getResponseAsString();
- assertEquals("-123", r);
- r = c.doPost(URL + "/Integer", "\u0000").getResponseAsString();
- assertEquals("null", r);
- try {
- r = c.doPost(URL + "/Integer?noTrace=true", "bad").getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
- // @RestMethod(name="POST", path="/float")
- // public float testFloat(@Content float f) {
- // return f;
- // }
- r = c.doPost(URL + "/float", "-1.23").getResponseAsString();
- assertEquals("-1.23", r);
- r = c.doPost(URL + "/float", "(-1.23)").getResponseAsString();
- assertEquals("-1.23", r);
- r = c.doPost(URL + "/float", "$n(-1.23)").getResponseAsString();
- assertEquals("-1.23", r);
- try {
- r = c.doPost(URL + "/float?noTrace=true", "\u0000").getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
- try {
- r = c.doPost(URL + "/float?noTrace=true", "bad").getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
- // @RestMethod(name="POST", path="/Float")
- // public Float testFloat2(@Content Float f) {
- // return f;
- // }
- r = c.doPost(URL + "/Float", "-1.23").getResponseAsString();
- assertEquals("-1.23", r);
- r = c.doPost(URL + "/Float", "(-1.23)").getResponseAsString();
- assertEquals("-1.23", r);
- r = c.doPost(URL + "/Float", "$n(-1.23)").getResponseAsString();
- assertEquals("-1.23", r);
- r = c.doPost(URL + "/Float", "\u0000").getResponseAsString();
- assertEquals("null", r);
- try {
- r = c.doPost(URL + "/Float?noTrace=true", "bad").getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
- // @RestMethod(name="POST", path="/Map")
- // public TreeMap<String,String> testMap(@Content TreeMap<String,String> m) {
- // return m;
- // }
- r = c.doPost(URL + "/Map", "(a=b,c=d)").getResponseAsString();
- assertEquals("{a:'b',c:'d'}", r);
- r = c.doPost(URL + "/Map", "\u0000").getResponseAsString();
- assertEquals("null", r);
- try {
- r = c.doPost(URL + "/Map?noTrace=true", "bad").getResponseAsString();
- fail("Exception expected!");
- } catch (RestCallException e) {
- assertEquals(400, e.getResponseCode());
- }
-
- // @RestMethod(name="POST", path="/B")
- // public DTO2s.B testPojo1(@Content DTO2s.B b) {
- // return b;
- // }
- DTOs.B b = DTOs.B.create();
- r = c.doPost(URL + "/B", "" + UonSerializer.DEFAULT.serialize(b)).getResponseAsString();
- assertEquals("{f1:['a','b'],f2:['c','d'],f3:[1,2],f4:[3,4],f5:[['e','f'],['g','h']],f6:[['i','j'],['k','l']],f7:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f8:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f9:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r);
- r = c.doPost(URL + "/B", "" + UonSerializer.DEFAULT_SIMPLE.serialize(b)).getResponseAsString();
- assertEquals("{f1:['a','b'],f2:['c','d'],f3:[1,2],f4:[3,4],f5:[['e','f'],['g','h']],f6:[['i','j'],['k','l']],f7:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f8:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f9:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r);
-
- // @RestMethod(name="POST", path="/C")
- // public DTO2s.C testPojo2(@Content DTO2s.C c) {
- // return c;
- // }
- DTOs.C x = DTOs.C.create();
- r = c.doPost(URL + "/C", "" + UonSerializer.DEFAULT.serialize(x)).getResponseAsString();
- assertEquals("{f1:['a','b'],f2:['c','d'],f3:[1,2],f4:[3,4],f5:[['e','f'],['g','h']],f6:[['i','j'],['k','l']],f7:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f8:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f9:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r);
- r = c.doPost(URL + "/C", "" + UonSerializer.DEFAULT_SIMPLE.serialize(x)).getResponseAsString();
- assertEquals("{f1:['a','b'],f2:['c','d'],f3:[1,2],f4:[3,4],f5:[['e','f'],['g','h']],f6:[['i','j'],['k','l']],f7:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f8:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f9:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r);
-
- c.closeQuietly();
- }
-
-
- private String encode(String s) {
- try {
- return URLEncoder.encode(s, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestDefaultContentTypesTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestDefaultContentTypesTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestDefaultContentTypesTest.java
deleted file mode 100755
index 613619f..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestDefaultContentTypesTest.java
+++ /dev/null
@@ -1,497 +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.server;
-
-import static javax.servlet.http.HttpServletResponse.*;
-import static org.apache.juneau.server.TestUtils.*;
-import static org.junit.Assert.*;
-
-import org.apache.juneau.client.*;
-import org.apache.juneau.json.*;
-import org.junit.*;
-
-
-public class TestDefaultContentTypesTest {
-
- 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();
- }
-}
[07/14] incubator-juneau git commit: Clean up test and test resource
class names.
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/PathsTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/PathsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/PathsTest.java
new file mode 100755
index 0000000..9a01e93
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/PathsTest.java
@@ -0,0 +1,1368 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static org.junit.Assert.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.client.*;
+import org.apache.juneau.json.*;
+import org.junit.*;
+
+public class PathsTest {
+
+ private static String URL = "/testPaths";
+
+ //====================================================================================================
+ // Basic tests
+ //====================================================================================================
+ @Test
+ public void testBasic() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ ObjectMap r;
+ String url;
+
+ // [/test/testPaths]
+ // {
+ // pathInfo:null,
+ // pathInfoUndecoded:null,
+ // pathInfoParts:[],
+ // pathRemainder:null,
+ // pathRemainderUndecoded:null,
+ // requestURI:'/jazz/juneau/test/testPaths',
+ // requestParentURI:'/jazz/juneau/test',
+ // requestURL:'https://localhost:9443/jazz/juneau/test/testPaths',
+ // servletPath:'/juneau/test/testPaths',
+ // relativeServletURI:'/jazz/juneau/test/testPaths',
+ // pathRemainder2:null
+ // }
+ url = URL;
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertNull(r.getString("pathInfo"));
+ assertNull(r.getString("pathInfoUndecoded"));
+ assertEquals("[]", r.getObjectList("pathInfoParts").toString());
+ assertNull(r.getString("pathRemainder"));
+ assertNull(r.getString("pathRemainderUndecoded"));
+ assertNull(r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths"));
+ assertTrue(r.getString("requestParentURI").endsWith("/"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
+ assertEquals(1, (int)r.getInt("method"));
+
+
+ // [/test/testPaths/]
+ // {
+ // pathInfo: '/',
+ // pathInfoUndecoded: '/',
+ // pathInfoParts: [
+ // ],
+ // pathRemainder: '',
+ // pathRemainderUndecoded: '',
+ // requestURI: '/jazz/juneau/test/testPaths/',
+ // requestParentURI: '/jazz/juneau/test',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/',
+ // servletPath: '/juneau/test/testPaths',
+ // relativeServletURI: '/jazz/juneau/test/testPaths',
+ // pathRemainder2: ''
+ // }
+ url = URL + '/';
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/", r.getString("pathInfo"));
+ assertEquals("/", r.getString("pathInfoUndecoded"));
+ assertEquals("[]", r.getObjectList("pathInfoParts").toString());
+ assertEquals("", r.getString("pathRemainder"));
+ assertEquals("", r.getString("pathRemainderUndecoded"));
+ assertEquals("", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/"));
+ assertTrue(r.getString("requestParentURI").endsWith("/"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
+ assertEquals(1, (int)r.getInt("method"));
+
+ // [/test/testPaths//]
+ // {
+ // pathInfo: '//',
+ // pathInfoParts: [''],
+ // pathRemainder: '/',
+ // requestURI: '/jazz/juneau/test/testPaths//',
+ // requestParentURI: '/jazz/juneau/test',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths//',
+ // servletPath: '/juneau/test/testPaths',
+ // relativeServletURI: '/jazz/juneau/test/testPaths',
+ // pathRemainder2: '/'
+ // }
+ url = URL + "//";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("//", r.getString("pathInfo"));
+ assertEquals("['']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("/", r.getString("pathRemainder"));
+ assertEquals("/", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths//"));
+ assertTrue(r.getString("requestParentURI").endsWith("/"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths//"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
+ assertEquals(1, (int)r.getInt("method"));
+
+ // [/test/testPaths///]
+ // {
+ // pathInfo: '///',
+ // pathInfoParts: ['',''],
+ // pathRemainder: '//',
+ // requestURI: '/jazz/juneau/test/testPaths///',
+ // requestParentURI: '/jazz/juneau/test',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths///',
+ // servletPath: '/juneau/test/testPaths',
+ // relativeServletURI: '/jazz/juneau/test/testPaths',
+ // pathRemainder2: '//'
+ // }
+ url = URL + "///";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("///", r.getString("pathInfo"));
+ assertEquals("['','']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("//", r.getString("pathRemainder"));
+ assertEquals("//", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths///"));
+ assertTrue(r.getString("requestParentURI").endsWith("/"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths///"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
+ assertEquals(1, (int)r.getInt("method"));
+
+ // [/test/testPaths/foo/bar]
+ // {
+ // pathInfo: '/foo/bar',
+ // pathInfoParts: [
+ // 'foo',
+ // 'bar'
+ // ],
+ // pathRemainder: 'foo/bar',
+ // requestURI: '/jazz/juneau/test/testPaths/foo/bar',
+ // requestParentURI: '/jazz/juneau/test/testPaths/foo',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/foo/bar',
+ // servletPath: '/juneau/test/testPaths',
+ // relativeServletURI: '/jazz/juneau/test/testPaths',
+ // pathRemainder2: 'foo/bar'
+ // }
+ url = URL + "/foo/bar";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/foo/bar", r.getString("pathInfo"));
+ assertEquals("['foo','bar']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("foo/bar", r.getString("pathRemainder"));
+ assertEquals("foo/bar", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/foo/bar"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/foo"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/foo/bar"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
+ assertEquals(1, (int)r.getInt("method"));
+
+ // [/test/testPaths/foo/bar/]
+ // {
+ // pathInfo: '/foo/bar/',
+ // pathInfoParts: [
+ // 'foo',
+ // 'bar'
+ // ],
+ // pathRemainder: 'foo/bar/',
+ // requestURI: '/jazz/juneau/test/testPaths/foo/bar/',
+ // requestParentURI: '/jazz/juneau/test/testPaths/foo',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/foo/bar/',
+ // servletPath: '/juneau/test/testPaths',
+ // relativeServletURI: '/jazz/juneau/test/testPaths',
+ // pathRemainder2: 'foo/bar/'
+ // }
+ url = URL + "/foo/bar/";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/foo/bar/", r.getString("pathInfo"));
+ assertEquals("['foo','bar']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("foo/bar/", r.getString("pathRemainder"));
+ assertEquals("foo/bar/", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/foo/bar/"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/foo"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/foo/bar/"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
+ assertEquals(1, (int)r.getInt("method"));
+
+ // [/test/testPaths//foo//bar//]
+ // {
+ // pathInfo: '//foo//bar//',
+ // pathInfoParts: [
+ // '',
+ // 'foo',
+ // '',
+ // 'bar',
+ // ''
+ // ],
+ // pathRemainder: '/foo//bar//',
+ // requestURI: '/jazz/juneau/test/testPaths//foo//bar//',
+ // requestParentURI: '/jazz/juneau/test/testPaths//foo',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths//foo//bar//',
+ // servletPath: '/juneau/test/testPaths',
+ // relativeServletURI: '/jazz/juneau/test/testPaths',
+ // pathRemainder2: '/foo//bar//'
+ // }
+ url = URL + "//foo//bar//";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("//foo//bar//", r.getString("pathInfo"));
+ assertEquals("['','foo','','bar','']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("/foo//bar//", r.getString("pathRemainder"));
+ assertEquals("/foo//bar//", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths//foo//bar//"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths//foo/"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths//foo//bar//"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
+ assertEquals(1, (int)r.getInt("method"));
+
+ // [/test/testPaths/foo%2Fbar]
+ // {
+ // pathInfo: '/foo//bar',
+ // pathInfoUndecoded: '/foo%2F%2Fbar',
+ // pathInfoParts: [
+ // 'foo//bar'
+ // ],
+ // pathRemainder: 'foo//bar',
+ // pathRemainderUndecoded: 'foo%2F%2Fbar',
+ // requestURI: '/jazz/juneau/test/testPaths/foo%2F%2Fbar',
+ // requestParentURI: '/jazz/juneau/test/testPaths',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/foo%2F%2Fbar',
+ // servletPath: '/juneau/test/testPaths',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test',
+ // relativeServletURI: '/jazz/juneau/test/testPaths',
+ // pathRemainder2: 'foo//bar',
+ // method: 1
+ // }
+ url = URL + "/foo%2F%2Fbar";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/foo//bar", r.getString("pathInfo"));
+ assertEquals("/foo%2F%2Fbar", r.getString("pathInfoUndecoded"));
+ assertEquals("['foo//bar']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("foo//bar", r.getString("pathRemainder"));
+ assertEquals("foo%2F%2Fbar", r.getString("pathRemainderUndecoded"));
+ assertEquals("foo//bar", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/foo%2F%2Fbar"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/foo%2F%2Fbar"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
+ assertEquals(1, (int)r.getInt("method"));
+
+ // [/test/testPaths//foo%2Fbar//]
+ // {
+ // pathInfo: '//foo//bar//',
+ // pathInfoUndecoded: '//foo%2F%2Fbar//',
+ // pathInfoParts: [
+ // '',
+ // 'foo//bar',
+ // ''
+ // ],
+ // pathRemainder: '/foo//bar//',
+ // pathRemainderUndecoded: '/foo%2F%2Fbar//',
+ // requestURI: '/jazz/juneau/test/testPaths//foo%2F%2Fbar//',
+ // requestParentURI: '/jazz/juneau/test/testPaths/',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths//foo%2F%2Fbar//',
+ // servletPath: '/juneau/test/testPaths',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test',
+ // relativeServletURI: '/jazz/juneau/test/testPaths',
+ // pathRemainder2: '/foo//bar//',
+ // method: 1
+ // }
+ url = URL + "//foo%2F%2Fbar//";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("//foo//bar//", r.getString("pathInfo"));
+ assertEquals("//foo%2F%2Fbar//", r.getString("pathInfoUndecoded"));
+ assertEquals("['','foo//bar','']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("/foo//bar//", r.getString("pathRemainder"));
+ assertEquals("/foo%2F%2Fbar//", r.getString("pathRemainderUndecoded"));
+ assertEquals("/foo//bar//", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths//foo%2F%2Fbar//"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths//foo%2F%2Fbar//"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
+ assertEquals(1, (int)r.getInt("method"));
+
+ // [/test/testPaths/test2]
+ // {
+ // pathInfo: '/test2',
+ // pathInfoParts: [
+ // 'test2'
+ // ],
+ // pathRemainder: null,
+ // requestURI: '/jazz/juneau/test/testPaths/test2',
+ // requestParentURI: '/jazz/juneau/test/testPaths',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/test2',
+ // servletPath: '/juneau/test/testPaths',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test',
+ // relativeServletURI: '/jazz/juneau/test/testPaths',
+ // pathRemainder2: null,
+ // method: 2
+ // }
+ url = URL + "/test2";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/test2", r.getString("pathInfo"));
+ assertEquals("['test2']", r.getObjectList("pathInfoParts").toString());
+ assertNull(r.getString("pathRemainder"));
+ assertNull(r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/test2"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/test2"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
+ assertEquals(2, (int)r.getInt("method"));
+
+
+ // [/test/testPaths/test2/]
+ // {
+ // pathInfo: '/test2/',
+ // pathInfoParts: [
+ // 'test2'
+ // ],
+ // pathRemainder: '',
+ // requestURI: '/jazz/juneau/test/testPaths/test2/',
+ // requestParentURI: '/jazz/juneau/test/testPaths',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/test2/',
+ // servletPath: '/juneau/test/testPaths',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test',
+ // relativeServletURI: '/jazz/juneau/test/testPaths',
+ // pathRemainder2: '',
+ // method: 2
+ // }
+ url = URL + "/test2/";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/test2/", r.getString("pathInfo"));
+ assertEquals("['test2']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("", r.getString("pathRemainder"));
+ assertEquals("", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/test2/"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/test2/"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
+ assertEquals(2, (int)r.getInt("method"));
+
+ // [/test/testPaths/test2//]
+ // {
+ // pathInfo: '/test2//',
+ // pathInfoParts: [
+ // 'test2',
+ // ''
+ // ],
+ // pathRemainder: '/',
+ // requestURI: '/jazz/juneau/test/testPaths/test2//',
+ // requestParentURI: '/jazz/juneau/test/testPaths',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/test2//',
+ // servletPath: '/juneau/test/testPaths',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test',
+ // relativeServletURI: '/jazz/juneau/test/testPaths',
+ // pathRemainder2: '/',
+ // method: 2
+ // }
+ url = URL + "/test2//";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/test2//", r.getString("pathInfo"));
+ assertEquals("['test2','']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("/", r.getString("pathRemainder"));
+ assertEquals("/", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/test2//"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/test2//"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
+ assertEquals(2, (int)r.getInt("method"));
+
+ // [/test/testPaths/test2///]
+ // {
+ // pathInfo: '/test2///',
+ // pathInfoParts: [
+ // 'test2',
+ // '',
+ // ''
+ // ],
+ // pathRemainder: '//',
+ // requestURI: '/jazz/juneau/test/testPaths/test2///',
+ // requestParentURI: '/jazz/juneau/test/testPaths',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/test2///',
+ // servletPath: '/juneau/test/testPaths',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test',
+ // relativeServletURI: '/jazz/juneau/test/testPaths',
+ // pathRemainder2: '//',
+ // method: 2
+ // }
+ url = URL + "/test2///";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/test2///", r.getString("pathInfo"));
+ assertEquals("['test2','','']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("//", r.getString("pathRemainder"));
+ assertEquals("//", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/test2///"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/test2///"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
+ assertEquals(2, (int)r.getInt("method"));
+
+ // [/test/testPaths/test2/foo/bar]
+ // {
+ // pathInfo: '/test2/foo/bar',
+ // pathInfoParts: [
+ // 'test2',
+ // 'foo',
+ // 'bar'
+ // ],
+ // pathRemainder: 'foo/bar',
+ // requestURI: '/jazz/juneau/test/testPaths/test2/foo/bar',
+ // requestParentURI: '/jazz/juneau/test/testPaths/test2/foo',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/test2/foo/bar',
+ // servletPath: '/juneau/test/testPaths',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test',
+ // relativeServletURI: '/jazz/juneau/test/testPaths',
+ // pathRemainder2: 'foo/bar',
+ // method: 2
+ // }
+ url = URL + "/test2/foo/bar";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/test2/foo/bar", r.getString("pathInfo"));
+ assertEquals("['test2','foo','bar']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("foo/bar", r.getString("pathRemainder"));
+ assertEquals("foo/bar", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/test2/foo/bar"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/test2/foo"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/test2/foo/bar"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
+ assertEquals(2, (int)r.getInt("method"));
+
+ // [/test/testPaths/test2/foo/bar/]
+ // {
+ // pathInfo: '/test2/foo/bar/',
+ // pathInfoParts: [
+ // 'test2',
+ // 'foo',
+ // 'bar'
+ // ],
+ // pathRemainder: 'foo/bar/',
+ // requestURI: '/jazz/juneau/test/testPaths/test2/foo/bar/',
+ // requestParentURI: '/jazz/juneau/test/testPaths/test2/foo',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/test2/foo/bar/',
+ // servletPath: '/juneau/test/testPaths',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test',
+ // relativeServletURI: '/jazz/juneau/test/testPaths',
+ // pathRemainder2: 'foo/bar/',
+ // method: 2
+ // }
+ url = URL + "/test2/foo/bar/";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/test2/foo/bar/", r.getString("pathInfo"));
+ assertEquals("['test2','foo','bar']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("foo/bar/", r.getString("pathRemainder"));
+ assertEquals("foo/bar/", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/test2/foo/bar/"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/test2/foo"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/test2/foo/bar/"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
+ assertEquals(2, (int)r.getInt("method"));
+
+ // [/test/testPaths/test2//foo//bar//]
+ // {
+ // pathInfo: '/test2//foo//bar//',
+ // pathInfoParts: [
+ // 'test2',
+ // '',
+ // 'foo',
+ // '',
+ // 'bar',
+ // ''
+ // ],
+ // pathRemainder: '/foo//bar//',
+ // requestURI: '/jazz/juneau/test/testPaths/test2//foo//bar//',
+ // requestParentURI: '/jazz/juneau/test/testPaths/test2//foo/',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/test2//foo//bar//',
+ // servletPath: '/juneau/test/testPaths',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test',
+ // relativeServletURI: '/jazz/juneau/test/testPaths',
+ // pathRemainder2: '/foo//bar//',
+ // method: 2
+ // }
+ url = URL + "/test2//foo//bar//";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/test2//foo//bar//", r.getString("pathInfo"));
+ assertEquals("['test2','','foo','','bar','']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("/foo//bar//", r.getString("pathRemainder"));
+ assertEquals("/foo//bar//", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/test2//foo//bar//"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/test2//foo/"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/test2//foo//bar//"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
+ assertEquals(2, (int)r.getInt("method"));
+
+ // [/test/testPaths/test2/foo%2Fbar]
+ // {
+ // pathInfo: '/test2/foo//bar',
+ // pathInfoUndecoded: '/test2/foo%2F%2Fbar',
+ // pathInfoParts: [
+ // 'test2',
+ // 'foo//bar'
+ // ],
+ // pathRemainder: 'foo//bar',
+ // pathRemainderUndecoded: 'foo%2F%2Fbar',
+ // requestURI: '/jazz/juneau/test/testPaths/test2/foo%2F%2Fbar',
+ // requestParentURI: '/jazz/juneau/test/testPaths/test2',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/test2/foo%2F%2Fbar',
+ // servletPath: '/juneau/test/testPaths',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test',
+ // relativeServletURI: '/jazz/juneau/test/testPaths',
+ // pathRemainder2: 'foo//bar',
+ // method: 2
+ // }
+ url = URL + "/test2/foo%2F%2Fbar";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/test2/foo//bar", r.getString("pathInfo"));
+ assertEquals("/test2/foo%2F%2Fbar", r.getString("pathInfoUndecoded"));
+ assertEquals("['test2','foo//bar']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("foo//bar", r.getString("pathRemainder"));
+ assertEquals("foo%2F%2Fbar", r.getString("pathRemainderUndecoded"));
+ assertEquals("foo//bar", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/test2/foo%2F%2Fbar"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/test2"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/test2/foo%2F%2Fbar"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
+ assertEquals(2, (int)r.getInt("method"));
+
+ // [/test/testPaths/test2//foo%2Fbar//]
+ // {
+ // pathInfo: '/test2//foo//bar//',
+ // pathInfoUndecoded: '/test2//foo%2F%2Fbar//',
+ // pathInfoParts: [
+ // 'test2',
+ // '',
+ // 'foo//bar',
+ // ''
+ // ],
+ // pathRemainder: '/foo//bar//',
+ // pathRemainderUndecoded: '/foo%2F%2Fbar//',
+ // requestURI: '/jazz/juneau/test/testPaths/test2//foo%2F%2Fbar//',
+ // requestParentURI: '/jazz/juneau/test/testPaths/test2/',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/test2//foo%2F%2Fbar//',
+ // servletPath: '/juneau/test/testPaths',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test',
+ // relativeServletURI: '/jazz/juneau/test/testPaths',
+ // pathRemainder2: '/foo//bar//',
+ // method: 2
+ // }
+ url = URL + "/test2//foo%2F%2Fbar//";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/test2//foo//bar//", r.getString("pathInfo"));
+ assertEquals("/test2//foo%2F%2Fbar//", r.getString("pathInfoUndecoded"));
+ assertEquals("['test2','','foo//bar','']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("/foo//bar//", r.getString("pathRemainder"));
+ assertEquals("/foo%2F%2Fbar//", r.getString("pathRemainderUndecoded"));
+ assertEquals("/foo//bar//", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/test2//foo%2F%2Fbar//"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/test2/"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/test2//foo%2F%2Fbar//"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
+ assertEquals(2, (int)r.getInt("method"));
+
+ // [/test/testPaths/a]
+ // {
+ // pathInfo: null,
+ // pathInfoParts: [
+ // ],
+ // pathRemainder: null,
+ // requestURI: '/jazz/juneau/test/testPaths/a',
+ // requestParentURI: '/jazz/juneau/test/testPaths',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
+ // servletPath: '/juneau/test/testPaths/a',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // relativeServletURI: '/jazz/juneau/test/testPaths/a',
+ // pathRemainder2: null,
+ // method: 3
+ // }
+ url = URL + "/a";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertNull(r.getString("pathInfo"));
+ assertEquals("[]", r.getObjectList("pathInfoParts").toString());
+ assertNull(r.getString("pathRemainder"));
+ assertNull(r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
+ assertEquals(3, (int)r.getInt("method"));
+
+ // [/test/testPaths/a/]
+ // {
+ // pathInfo: '/',
+ // pathInfoParts: [
+ // ],
+ // pathRemainder: '',
+ // requestURI: '/jazz/juneau/test/testPaths/a/',
+ // requestParentURI: '/jazz/juneau/test/testPaths',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a/',
+ // servletPath: '/juneau/test/testPaths/a',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // relativeServletURI: '/jazz/juneau/test/testPaths/a',
+ // pathRemainder2: '',
+ // method: 3
+ // }
+ url = URL + "/a/";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/", r.getString("pathInfo"));
+ assertEquals("[]", r.getObjectList("pathInfoParts").toString());
+ assertEquals("", r.getString("pathRemainder"));
+ assertEquals("", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/a/"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/a/"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
+ assertEquals(3, (int)r.getInt("method"));
+
+ // [/test/testPaths/a//]
+ // {
+ // pathInfo: '//',
+ // pathInfoParts: [
+ // ''
+ // ],
+ // pathRemainder: '/',
+ // requestURI: '/jazz/juneau/test/testPaths/a//',
+ // requestParentURI: '/jazz/juneau/test/testPaths',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a//',
+ // servletPath: '/juneau/test/testPaths/a',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // relativeServletURI: '/jazz/juneau/test/testPaths/a',
+ // pathRemainder2: '/',
+ // method: 3
+ // }
+ url = URL + "/a//";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("//", r.getString("pathInfo"));
+ assertEquals("['']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("/", r.getString("pathRemainder"));
+ assertEquals("/", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/a//"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/a//"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
+ assertEquals(3, (int)r.getInt("method"));
+
+ // [/test/testPaths/a///]
+ // {
+ // pathInfo: '///',
+ // pathInfoParts: [
+ // '',
+ // ''
+ // ],
+ // pathRemainder: '//',
+ // requestURI: '/jazz/juneau/test/testPaths/a///',
+ // requestParentURI: '/jazz/juneau/test/testPaths',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a///',
+ // servletPath: '/juneau/test/testPaths/a',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // relativeServletURI: '/jazz/juneau/test/testPaths/a',
+ // pathRemainder2: '//',
+ // method: 3
+ // }
+ url = URL + "/a///";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("///", r.getString("pathInfo"));
+ assertEquals("['','']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("//", r.getString("pathRemainder"));
+ assertEquals("//", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/a///"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/a///"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
+ assertEquals(3, (int)r.getInt("method"));
+
+ // [/test/testPaths/a/foo/bar]
+ // {
+ // pathInfo: '/foo/bar',
+ // pathInfoParts: [
+ // 'foo',
+ // 'bar'
+ // ],
+ // pathRemainder: 'foo/bar',
+ // requestURI: '/jazz/juneau/test/testPaths/a/foo/bar',
+ // requestParentURI: '/jazz/juneau/test/testPaths/a/foo',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a/foo/bar',
+ // servletPath: '/juneau/test/testPaths/a',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // relativeServletURI: '/jazz/juneau/test/testPaths/a',
+ // pathRemainder2: 'foo/bar',
+ // method: 3
+ // }
+ url = URL + "/a/foo/bar";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/foo/bar", r.getString("pathInfo"));
+ assertEquals("['foo','bar']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("foo/bar", r.getString("pathRemainder"));
+ assertEquals("foo/bar", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/a/foo/bar"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a/foo"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/a/foo/bar"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
+ assertEquals(3, (int)r.getInt("method"));
+
+ // [/test/testPaths/a/foo/bar/]
+ // {
+ // pathInfo: '/foo/bar/',
+ // pathInfoParts: [
+ // 'foo',
+ // 'bar'
+ // ],
+ // pathRemainder: 'foo/bar/',
+ // requestURI: '/jazz/juneau/test/testPaths/a/foo/bar/',
+ // requestParentURI: '/jazz/juneau/test/testPaths/a/foo',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a/foo/bar/',
+ // servletPath: '/juneau/test/testPaths/a',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // relativeServletURI: '/jazz/juneau/test/testPaths/a',
+ // pathRemainder2: 'foo/bar/',
+ // method: 3
+ // }
+ url = URL + "/a/foo/bar/";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/foo/bar/", r.getString("pathInfo"));
+ assertEquals("['foo','bar']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("foo/bar/", r.getString("pathRemainder"));
+ assertEquals("foo/bar/", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/a/foo/bar/"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a/foo"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/a/foo/bar/"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
+ assertEquals(3, (int)r.getInt("method"));
+
+ // [/test/testPaths/a//foo//bar//]
+ // {
+ // pathInfo: '//foo//bar//',
+ // pathInfoParts: [
+ // '',
+ // 'foo',
+ // '',
+ // 'bar',
+ // ''
+ // ],
+ // pathRemainder: '/foo//bar//',
+ // requestURI: '/jazz/juneau/test/testPaths/a//foo//bar//',
+ // requestParentURI: '/jazz/juneau/test/testPaths/a//foo/',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a//foo//bar//',
+ // servletPath: '/juneau/test/testPaths/a',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // relativeServletURI: '/jazz/juneau/test/testPaths/a',
+ // pathRemainder2: '/foo//bar//',
+ // method: 3
+ // }
+ url = URL + "/a//foo//bar//";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("//foo//bar//", r.getString("pathInfo"));
+ assertEquals("['','foo','','bar','']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("/foo//bar//", r.getString("pathRemainder"));
+ assertEquals("/foo//bar//", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/a//foo//bar//"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a//foo/"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/a//foo//bar//"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
+ assertEquals(3, (int)r.getInt("method"));
+
+ // [/test/testPaths/a/foo%2Fbar]
+ // {
+ // pathInfo: '/foo//bar',
+ // pathInfoUndecoded: '/foo%2F%2Fbar',
+ // pathInfoParts: [
+ // 'foo//bar'
+ // ],
+ // pathRemainder: 'foo//bar',
+ // pathRemainderUndecoded: 'foo%2F%2Fbar',
+ // requestURI: '/jazz/juneau/test/testPaths/a/foo%2F%2Fbar',
+ // requestParentURI: '/jazz/juneau/test/testPaths/a',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a/foo%2F%2Fbar',
+ // servletPath: '/juneau/test/testPaths/a',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // relativeServletURI: '/jazz/juneau/test/testPaths/a',
+ // pathRemainder2: 'foo//bar',
+ // method: 3
+ // }
+ url = URL + "/a/foo%2F%2Fbar";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/foo//bar", r.getString("pathInfo"));
+ assertEquals("/foo%2F%2Fbar", r.getString("pathInfoUndecoded"));
+ assertEquals("['foo//bar']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("foo//bar", r.getString("pathRemainder"));
+ assertEquals("foo%2F%2Fbar", r.getString("pathRemainderUndecoded"));
+ assertEquals("foo//bar", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/a/foo%2F%2Fbar"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/a/foo%2F%2Fbar"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
+ assertEquals(3, (int)r.getInt("method"));
+
+ // [/test/testPaths/a//foo%2Fbar//]
+ // {
+ // pathInfo: '//foo//bar//',
+ // pathInfoUndecoded: '//foo%2F%2Fbar//',
+ // pathInfoParts: [
+ // '',
+ // 'foo//bar',
+ // ''
+ // ],
+ // pathRemainder: '/foo//bar//',
+ // pathRemainderUndecoded: '/foo%2F%2Fbar//',
+ // requestURI: '/jazz/juneau/test/testPaths/a//foo%2F%2Fbar//',
+ // requestParentURI: '/jazz/juneau/test/testPaths/a/',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a//foo%2F%2Fbar//',
+ // servletPath: '/juneau/test/testPaths/a',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // relativeServletURI: '/jazz/juneau/test/testPaths/a',
+ // pathRemainder2: '/foo//bar//',
+ // method: 3
+ // }
+ url = URL + "/a//foo%2F%2Fbar//";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("//foo//bar//", r.getString("pathInfo"));
+ assertEquals("//foo%2F%2Fbar//", r.getString("pathInfoUndecoded"));
+ assertEquals("['','foo//bar','']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("/foo//bar//", r.getString("pathRemainder"));
+ assertEquals("/foo%2F%2Fbar//", r.getString("pathRemainderUndecoded"));
+ assertEquals("/foo//bar//", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/a//foo%2F%2Fbar//"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a/"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/a//foo%2F%2Fbar//"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
+ assertEquals(3, (int)r.getInt("method"));
+
+
+ // [/test/testPaths/a/test2]
+ // {
+ // pathInfo: '/test2',
+ // pathInfoParts: [
+ // 'test2'
+ // ],
+ // pathRemainder: null,
+ // requestURI: '/jazz/juneau/test/testPaths/a/test2',
+ // requestParentURI: '/jazz/juneau/test/testPaths/a',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a/test2',
+ // servletPath: '/juneau/test/testPaths/a',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // relativeServletURI: '/jazz/juneau/test/testPaths/a',
+ // pathRemainder2: null,
+ // method: 4
+ // }
+ url = URL + "/a/test2";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/test2", r.getString("pathInfo"));
+ assertEquals("['test2']", r.getObjectList("pathInfoParts").toString());
+ assertNull(r.getString("pathRemainder"));
+ assertNull(r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/a/test2"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/a/test2"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
+ assertEquals(4, (int)r.getInt("method"));
+
+ // [/test/testPaths/a/test2/]
+ // {
+ // pathInfo: '/test2/',
+ // pathInfoParts: [
+ // 'test2'
+ // ],
+ // pathRemainder: '',
+ // requestURI: '/jazz/juneau/test/testPaths/a/test2/',
+ // requestParentURI: '/jazz/juneau/test/testPaths/a',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a/test2/',
+ // servletPath: '/juneau/test/testPaths/a',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // relativeServletURI: '/jazz/juneau/test/testPaths/a',
+ // pathRemainder2: '',
+ // method: 4
+ // }
+ url = URL + "/a/test2/";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/test2/", r.getString("pathInfo"));
+ assertEquals("['test2']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("", r.getString("pathRemainder"));
+ assertEquals("", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/a/test2/"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/a/test2/"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
+ assertEquals(4, (int)r.getInt("method"));
+
+ // [/test/testPaths/a/test2//]
+ // {
+ // pathInfo: '/test2//',
+ // pathInfoParts: [
+ // 'test2',
+ // ''
+ // ],
+ // pathRemainder: '/',
+ // requestURI: '/jazz/juneau/test/testPaths/a/test2//',
+ // requestParentURI: '/jazz/juneau/test/testPaths/a',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a/test2//',
+ // servletPath: '/juneau/test/testPaths/a',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // relativeServletURI: '/jazz/juneau/test/testPaths/a',
+ // pathRemainder2: '/',
+ // method: 4
+ // }
+ url = URL + "/a/test2//";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/test2//", r.getString("pathInfo"));
+ assertEquals("['test2','']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("/", r.getString("pathRemainder"));
+ assertEquals("/", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/a/test2//"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/a/test2//"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
+ assertEquals(4, (int)r.getInt("method"));
+
+ // [/test/testPaths/a/test2///]
+ // {
+ // pathInfo: '/test2///',
+ // pathInfoParts: [
+ // 'test2',
+ // '',
+ // ''
+ // ],
+ // pathRemainder: '//',
+ // requestURI: '/jazz/juneau/test/testPaths/a/test2///',
+ // requestParentURI: '/jazz/juneau/test/testPaths/a',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a/test2///',
+ // servletPath: '/juneau/test/testPaths/a',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // relativeServletURI: '/jazz/juneau/test/testPaths/a',
+ // pathRemainder2: '//',
+ // method: 4
+ // }
+ url = URL + "/a/test2///";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/test2///", r.getString("pathInfo"));
+ assertEquals("['test2','','']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("//", r.getString("pathRemainder"));
+ assertEquals("//", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/a/test2///"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/a/test2///"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
+ assertEquals(4, (int)r.getInt("method"));
+
+ // [/test/testPaths/a/test2/foo/bar]
+ // {
+ // pathInfo: '/test2/foo/bar',
+ // pathInfoParts: [
+ // 'test2',
+ // 'foo',
+ // 'bar'
+ // ],
+ // pathRemainder: 'foo/bar',
+ // requestURI: '/jazz/juneau/test/testPaths/a/test2/foo/bar',
+ // requestParentURI: '/jazz/juneau/test/testPaths/a/test2/foo',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a/test2/foo/bar',
+ // servletPath: '/juneau/test/testPaths/a',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // relativeServletURI: '/jazz/juneau/test/testPaths/a',
+ // pathRemainder2: 'foo/bar',
+ // method: 4
+ // }
+ url = URL + "/a/test2/foo/bar";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/test2/foo/bar", r.getString("pathInfo"));
+ assertEquals("['test2','foo','bar']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("foo/bar", r.getString("pathRemainder"));
+ assertEquals("foo/bar", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/a/test2/foo/bar"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a/test2/foo"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/a/test2/foo/bar"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
+ assertEquals(4, (int)r.getInt("method"));
+
+ // [/test/testPaths/a/test2/foo/bar/]
+ // {
+ // pathInfo: '/test2/foo/bar/',
+ // pathInfoParts: [
+ // 'test2',
+ // 'foo',
+ // 'bar'
+ // ],
+ // pathRemainder: 'foo/bar/',
+ // requestURI: '/jazz/juneau/test/testPaths/a/test2/foo/bar/',
+ // requestParentURI: '/jazz/juneau/test/testPaths/a/test2/foo',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a/test2/foo/bar/',
+ // servletPath: '/juneau/test/testPaths/a',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // relativeServletURI: '/jazz/juneau/test/testPaths/a',
+ // pathRemainder2: 'foo/bar/',
+ // method: 4
+ // }
+ url = URL + "/a/test2/foo/bar/";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/test2/foo/bar/", r.getString("pathInfo"));
+ assertEquals("['test2','foo','bar']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("foo/bar/", r.getString("pathRemainder"));
+ assertEquals("foo/bar/", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/a/test2/foo/bar/"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a/test2/foo"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/a/test2/foo/bar/"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
+ assertEquals(4, (int)r.getInt("method"));
+
+ // [/test/testPaths/a/test2//foo//bar//]
+ // {
+ // pathInfo: '/test2//foo//bar//',
+ // pathInfoParts: [
+ // 'test2',
+ // '',
+ // 'foo',
+ // '',
+ // 'bar',
+ // ''
+ // ],
+ // pathRemainder: '/foo//bar//',
+ // requestURI: '/jazz/juneau/test/testPaths/a/test2//foo//bar//',
+ // requestParentURI: '/jazz/juneau/test/testPaths/a/test2//foo/',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a/test2//foo//bar//',
+ // servletPath: '/juneau/test/testPaths/a',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // relativeServletURI: '/jazz/juneau/test/testPaths/a',
+ // pathRemainder2: '/foo//bar//',
+ // method: 4
+ // }
+ url = URL + "/a/test2//foo//bar//";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/test2//foo//bar//", r.getString("pathInfo"));
+ assertEquals("['test2','','foo','','bar','']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("/foo//bar//", r.getString("pathRemainder"));
+ assertEquals("/foo//bar//", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/a/test2//foo//bar//"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a/test2//foo/"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/a/test2//foo//bar//"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
+ assertEquals(4, (int)r.getInt("method"));
+
+ // [/test/testPaths/a/test2/foo%2Fbar]
+ // {
+ // pathInfo: '/test2/foo//bar',
+ // pathInfoUndecoded: '/test2/foo%2F%2Fbar',
+ // pathInfoParts: [
+ // 'test2',
+ // 'foo//bar'
+ // ],
+ // pathRemainder: 'foo//bar',
+ // pathRemainderUndecoded: 'foo%2F%2Fbar',
+ // requestURI: '/jazz/juneau/test/testPaths/a/test2/foo%2F%2Fbar',
+ // requestParentURI: '/jazz/juneau/test/testPaths/a/test2',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a/test2/foo%2F%2Fbar',
+ // servletPath: '/juneau/test/testPaths/a',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // relativeServletURI: '/jazz/juneau/test/testPaths/a',
+ // pathRemainder2: 'foo//bar',
+ // method: 4
+ // }
+ url = URL + "/a/test2/foo%2F%2Fbar";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/test2/foo//bar", r.getString("pathInfo"));
+ assertEquals("/test2/foo%2F%2Fbar", r.getString("pathInfoUndecoded"));
+ assertEquals("['test2','foo//bar']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("foo//bar", r.getString("pathRemainder"));
+ assertEquals("foo%2F%2Fbar", r.getString("pathRemainderUndecoded"));
+ assertEquals("foo//bar", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/a/test2/foo%2F%2Fbar"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a/test2"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/a/test2/foo%2F%2Fbar"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
+ assertEquals(4, (int)r.getInt("method"));
+
+ // [/test/testPaths/a/test2//foo%2Fbar//]
+ // {
+ // pathInfo: '/test2//foo//bar//',
+ // pathInfoUndecoded: '/test2//foo%2F%2Fbar//',
+ // pathInfoParts: [
+ // 'test2',
+ // '',
+ // 'foo//bar',
+ // ''
+ // ],
+ // pathRemainder: '/foo//bar//',
+ // pathRemainderUndecoded: '/foo%2F%2Fbar//',
+ // requestURI: '/jazz/juneau/test/testPaths/a/test2//foo%2F%2Fbar//',
+ // requestParentURI: '/jazz/juneau/test/testPaths/a/test2/',
+ // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a/test2//foo%2F%2Fbar//',
+ // servletPath: '/juneau/test/testPaths/a',
+ // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
+ // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
+ // relativeServletURI: '/jazz/juneau/test/testPaths/a',
+ // pathRemainder2: '/foo//bar//',
+ // method: 4
+ // }
+ url = URL + "/a/test2//foo%2F%2Fbar//";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/test2//foo//bar//", r.getString("pathInfo"));
+ assertEquals("/test2//foo%2F%2Fbar//", r.getString("pathInfoUndecoded"));
+ assertEquals("['test2','','foo//bar','']", r.getObjectList("pathInfoParts").toString());
+ assertEquals("/foo//bar//", r.getString("pathRemainder"));
+ assertEquals("/foo%2F%2Fbar//", r.getString("pathRemainderUndecoded"));
+ assertEquals("/foo//bar//", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/a/test2//foo%2F%2Fbar//"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a/test2/"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/a/test2//foo%2F%2Fbar//"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
+ assertEquals(4, (int)r.getInt("method"));
+
+ //--------------------------------------------------------------------------------
+ // Spaces
+ //--------------------------------------------------------------------------------
+ url = URL + "/%20";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/ ", r.getString("pathInfo"));
+ assertEquals("/%20", r.getString("pathInfoUndecoded"));
+ assertEquals("[' ']", r.getObjectList("pathInfoParts").toString());
+ assertEquals(" ", r.getString("pathRemainder"));
+ assertEquals("%20", r.getString("pathRemainderUndecoded"));
+ assertEquals(" ", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/%20"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/%20"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
+ assertEquals(1, (int)r.getInt("method"));
+
+ url = URL + "/test2/%20";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/test2/ ", r.getString("pathInfo"));
+ assertEquals("/test2/%20", r.getString("pathInfoUndecoded"));
+ assertEquals("['test2',' ']", r.getObjectList("pathInfoParts").toString());
+ assertEquals(" ", r.getString("pathRemainder"));
+ assertEquals("%20", r.getString("pathRemainderUndecoded"));
+ assertEquals(" ", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/test2/%20"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/test2"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/test2/%20"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
+ assertEquals(2, (int)r.getInt("method"));
+
+ url = URL + "/a/%20";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/ ", r.getString("pathInfo"));
+ assertEquals("/%20", r.getString("pathInfoUndecoded"));
+ assertEquals("[' ']", r.getObjectList("pathInfoParts").toString());
+ assertEquals(" ", r.getString("pathRemainder"));
+ assertEquals("%20", r.getString("pathRemainderUndecoded"));
+ assertEquals(" ", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/a/%20"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/a/%20"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
+ assertEquals(3, (int)r.getInt("method"));
+
+ url = URL + "/a/test2/%20";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/test2/ ", r.getString("pathInfo"));
+ assertEquals("/test2/%20", r.getString("pathInfoUndecoded"));
+ assertEquals("['test2',' ']", r.getObjectList("pathInfoParts").toString());
+ assertEquals(" ", r.getString("pathRemainder"));
+ assertEquals("%20", r.getString("pathRemainderUndecoded"));
+ assertEquals(" ", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/a/test2/%20"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a/test2"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/a/test2/%20"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
+ assertEquals(4, (int)r.getInt("method"));
+
+ url = URL + "/+";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/ ", r.getString("pathInfo"));
+ assertEquals("/+", r.getString("pathInfoUndecoded"));
+ assertEquals("[' ']", r.getObjectList("pathInfoParts").toString());
+ assertEquals(" ", r.getString("pathRemainder"));
+ assertEquals("+", r.getString("pathRemainderUndecoded"));
+ assertEquals(" ", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/+"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/+"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
+ assertEquals(1, (int)r.getInt("method"));
+
+ url = URL + "/test2/+";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/test2/ ", r.getString("pathInfo"));
+ assertEquals("/test2/+", r.getString("pathInfoUndecoded"));
+ assertEquals("['test2',' ']", r.getObjectList("pathInfoParts").toString());
+ assertEquals(" ", r.getString("pathRemainder"));
+ assertEquals("+", r.getString("pathRemainderUndecoded"));
+ assertEquals(" ", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/test2/+"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/test2"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/test2/+"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
+ assertEquals(2, (int)r.getInt("method"));
+
+ url = URL + "/a/+";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/ ", r.getString("pathInfo"));
+ assertEquals("/+", r.getString("pathInfoUndecoded"));
+ assertEquals("[' ']", r.getObjectList("pathInfoParts").toString());
+ assertEquals(" ", r.getString("pathRemainder"));
+ assertEquals("+", r.getString("pathRemainderUndecoded"));
+ assertEquals(" ", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/a/+"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/a/+"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
+ assertEquals(3, (int)r.getInt("method"));
+
+ url = URL + "/a/test2/+";
+ r = client.doGet(url).getResponse(ObjectMap.class);
+ assertEquals("/test2/ ", r.getString("pathInfo"));
+ assertEquals("/test2/+", r.getString("pathInfoUndecoded"));
+ assertEquals("['test2',' ']", r.getObjectList("pathInfoParts").toString());
+ assertEquals(" ", r.getString("pathRemainder"));
+ assertEquals("+", r.getString("pathRemainderUndecoded"));
+ assertEquals(" ", r.getString("pathRemainder2"));
+ assertTrue(r.getString("requestURI").endsWith("/testPaths/a/test2/+"));
+ assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a/test2"));
+ assertTrue(r.getString("requestURL").endsWith("/testPaths/a/test2/+"));
+ assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
+ assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
+ assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
+ assertEquals(4, (int)r.getInt("method"));
+
+ client.closeQuietly();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/PropertiesTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/PropertiesTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/PropertiesTest.java
new file mode 100755
index 0000000..388367c
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/PropertiesTest.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;
+
+import static org.junit.Assert.*;
+
+import org.apache.juneau.client.*;
+import org.apache.juneau.json.*;
+import org.junit.*;
+
+public class PropertiesTest {
+
+ private static String URL = "/testProperties";
+
+ //====================================================================================================
+ // Properties defined on method.
+ //====================================================================================================
+ @Test
+ public void testPropertiesDefinedOnMethod() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ String r = client.doGet(URL + "/testPropertiesDefinedOnMethod").getResponseAsString();
+ assertTrue(r.matches("A1=a1,A2=c,B1=b1,B2=c,C=c,R1a=.*/testProperties/testPropertiesDefinedOnMethod,R1b=.*/testProperties,R2=bar,R3=baz,R4=a1,R5=c,R6=c"));
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Make sure attributes/parameters/headers are available through ctx.getProperties().
+ //====================================================================================================
+ @Test
+ public void testProperties() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ String r = client.doGet(URL + "/testProperties/a1?P=p1").setHeader("H", "h1").getResponseAsString();
+ assertEquals("A=a1,P=p1,H=h1", r);
+
+ client.closeQuietly();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/RestClientTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/RestClientTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/RestClientTest.java
new file mode 100755
index 0000000..d801033
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/RestClientTest.java
@@ -0,0 +1,199 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static org.apache.juneau.server.TestUtils.*;
+import static org.junit.Assert.*;
+
+import java.util.*;
+import java.util.regex.*;
+
+import org.apache.http.entity.*;
+import org.apache.juneau.client.*;
+import org.apache.juneau.json.*;
+import org.junit.*;
+
+public class RestClientTest {
+
+ private static String URL = "/testRestClient";
+
+ //====================================================================================================
+ // successPattern()
+ //====================================================================================================
+ @Test
+ public void testSuccessPattern() throws Exception {
+ RestClient c = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ String r;
+ int rc;
+
+ r = c.doPost(URL, new StringEntity("xxxSUCCESSxxx")).successPattern("SUCCESS").getResponseAsString();
+ assertEquals("xxxSUCCESSxxx", r);
+ rc = c.doPost(URL, new StringEntity("xxxSUCCESSxxx")).successPattern("SUCCESS").run();
+ assertEquals(200, rc);
+
+ try {
+ r = c.doPost(URL, new StringEntity("xxxFAILURExxx")).successPattern("SUCCESS").getResponseAsString();
+ fail();
+ } catch (RestCallException e) {
+ assertEquals("Success pattern not detected.", e.getLocalizedMessage());
+ }
+
+ c.closeQuietly();
+ }
+
+ //====================================================================================================
+ // failurePattern()
+ //====================================================================================================
+ @Test
+ public void testFailurePattern() throws Exception {
+ RestClient c = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ String r;
+ int rc;
+
+ r = c.doPost(URL, new StringEntity("xxxSUCCESSxxx")).failurePattern("FAILURE").getResponseAsString();
+ assertEquals("xxxSUCCESSxxx", r);
+ rc = c.doPost(URL, new StringEntity("xxxSUCCESSxxx")).failurePattern("FAILURE").run();
+ assertEquals(200, rc);
+
+ try {
+ r = c.doPost(URL, new StringEntity("xxxFAILURExxx")).failurePattern("FAILURE").getResponseAsString();
+ fail();
+ } catch (RestCallException e) {
+ assertEquals("Failure pattern detected.", e.getLocalizedMessage());
+ }
+
+ try {
+ r = c.doPost(URL, new StringEntity("xxxERRORxxx")).failurePattern("FAILURE|ERROR").getResponseAsString();
+ fail();
+ } catch (RestCallException e) {
+ assertEquals("Failure pattern detected.", e.getLocalizedMessage());
+ }
+
+ c.closeQuietly();
+ }
+
+ //====================================================================================================
+ // captureResponse()/getCapturedResponse()
+ //====================================================================================================
+ @Test
+ public void testCaptureResponse() throws Exception {
+ RestClient c = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ RestCall rc = c.doPost(URL, new StringEntity("xxx")).captureResponse();
+
+ try {
+ rc.getCapturedResponse();
+ fail();
+ } catch (IllegalStateException e) {
+ assertEquals("This method cannot be called until the response has been consumed.", e.getLocalizedMessage());
+ }
+ rc.run();
+ assertEquals("xxx", rc.getCapturedResponse());
+ assertEquals("xxx", rc.getCapturedResponse());
+
+ rc = c.doPost(URL, new StringEntity("xxx")).captureResponse();
+ assertEquals("xxx", rc.getResponseAsString());
+ assertEquals("xxx", rc.getCapturedResponse());
+ assertEquals("xxx", rc.getCapturedResponse());
+
+ try {
+ rc.getResponseAsString();
+ fail();
+ } catch (IllegalStateException e) {
+ assertEquals("Method cannot be called. Response has already been consumed.", e.getLocalizedMessage());
+ }
+
+ c.closeQuietly();
+ }
+
+ //====================================================================================================
+ // addResponsePattern()
+ //====================================================================================================
+ @Test
+ public void testAddResponsePattern() throws Exception {
+ RestClient c = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ String r;
+
+ final List<String> l = new ArrayList<String>();
+ ResponsePattern p = new ResponsePattern("x=(\\d+),y=(\\S+)") {
+ @Override
+ public void onMatch(RestCall restCall, Matcher m) throws RestCallException {
+ l.add(m.group(1)+'/'+m.group(2));
+ }
+ @Override
+ public void onNoMatch(RestCall restCall) throws RestCallException {
+ throw new RestCallException("Pattern not found!");
+ }
+ };
+
+ r = c.doPost(URL, new StringEntity("x=1,y=2")).addResponsePattern(p).getResponseAsString();
+ assertEquals("x=1,y=2", r);
+ assertObjectEquals("['1/2']", l);
+
+ l.clear();
+
+ r = c.doPost(URL, new StringEntity("x=1,y=2\nx=3,y=4")).addResponsePattern(p).getResponseAsString();
+ assertEquals("x=1,y=2\nx=3,y=4", r);
+ assertObjectEquals("['1/2','3/4']", l);
+
+ try {
+ c.doPost(URL, new StringEntity("x=1")).addResponsePattern(p).run();
+ fail();
+ } catch (RestCallException e) {
+ assertEquals("Pattern not found!", e.getLocalizedMessage());
+ assertEquals(0, e.getResponseCode());
+ }
+
+ // Two patterns!
+ ResponsePattern p1 = new ResponsePattern("x=(\\d+)") {
+ @Override
+ public void onMatch(RestCall restCall, Matcher m) throws RestCallException {
+ l.add("x="+m.group(1));
+ }
+ @Override
+ public void onNoMatch(RestCall restCall) throws RestCallException {
+ throw new RestCallException("Pattern x not found!");
+ }
+ };
+ ResponsePattern p2 = new ResponsePattern("y=(\\S+)") {
+ @Override
+ public void onMatch(RestCall restCall, Matcher m) throws RestCallException {
+ l.add("y="+m.group(1));
+ }
+ @Override
+ public void onNoMatch(RestCall restCall) throws RestCallException {
+ throw new RestCallException("Pattern y not found!");
+ }
+ };
+
+ l.clear();
+ r = c.doPost(URL, new StringEntity("x=1,y=2\nx=3,y=4")).addResponsePattern(p1).addResponsePattern(p2).getResponseAsString();
+ assertEquals("x=1,y=2\nx=3,y=4", r);
+ assertObjectEquals("['x=1','x=3','y=2','y=4']", l);
+
+ try {
+ c.doPost(URL, new StringEntity("x=1\nx=3")).addResponsePattern(p1).addResponsePattern(p2).getResponseAsString();
+ } catch (RestCallException e) {
+ assertEquals("Pattern y not found!", e.getLocalizedMessage());
+ assertEquals(0, e.getResponseCode());
+ }
+
+ try {
+ c.doPost(URL, new StringEntity("y=1\ny=3")).addResponsePattern(p1).addResponsePattern(p2).getResponseAsString();
+ } catch (RestCallException e) {
+ assertEquals("Pattern x not found!", e.getLocalizedMessage());
+ assertEquals(0, e.getResponseCode());
+ }
+
+ c.closeQuietly();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/SerializersTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/SerializersTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/SerializersTest.java
new file mode 100755
index 0000000..95ecf68
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/SerializersTest.java
@@ -0,0 +1,152 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static javax.servlet.http.HttpServletResponse.*;
+import static org.apache.juneau.server.TestUtils.*;
+import static org.junit.Assert.*;
+
+import org.apache.juneau.client.*;
+import org.apache.juneau.json.*;
+import org.junit.*;
+
+public class SerializersTest {
+
+ private static String URL = "/testSerializers";
+ 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();
+ }
+
+ //====================================================================================================
+ // Serializer defined on class.
+ //====================================================================================================
+ @Test
+ public void testSerializerOnClass() throws Exception {
+ String url = URL + "/testSerializerOnClass";
+
+ client.setAccept("text/a");
+ String r = client.doGet(url).getResponseAsString();
+ assertEquals("text/a - test1", r);
+
+ try {
+ client.setAccept("text/b");
+ 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': 'text/b'",
+ "Supported media-types: [text/a, ");
+ }
+
+ client.setAccept("text/json");
+ r = client.doGet(url).getResponseAsString();
+ assertEquals("\"test1\"", r);
+ }
+
+ //====================================================================================================
+ // Serializer defined on method.
+ //====================================================================================================
+ @Test
+ public void testSerializerOnMethod() throws Exception {
+ String url = URL + "/testSerializerOnMethod";
+
+ try {
+ client.setAccept("text/a");
+ 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': 'text/a'",
+ "Supported media-types: [text/b]"
+ );
+ }
+
+ try {
+ client.setAccept("text/json");
+ 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': 'text/json'",
+ "Supported media-types: [text/b]"
+ );
+ }
+ }
+
+ //====================================================================================================
+ // Serializer overridden on method.
+ //====================================================================================================
+ @Test
+ public void testSerializerOverriddenOnMethod() throws Exception {
+ String url = URL + "/testSerializerOverriddenOnMethod";
+
+ client.setAccept("text/a");
+ String r = client.doGet(url).getResponseAsString();
+ assertEquals("text/c - test3", r);
+
+ client.setAccept("text/b");
+ r = client.doGet(url).getResponseAsString();
+ assertEquals("text/b - test3", r);
+
+ client.setAccept("text/json");
+ r = client.doGet(url).getResponseAsString();
+ assertEquals("\"test3\"", r);
+ }
+
+ //====================================================================================================
+ // Serializer with different Accept than Content-Type.
+ //====================================================================================================
+ @Test
+ public void testSerializerWithDifferentMediaTypes() throws Exception {
+ String url = URL + "/testSerializerWithDifferentMediaTypes";
+
+ client.setAccept("text/a");
+ String r = client.doGet(url).getResponseAsString();
+ assertEquals("text/d - test4", r);
+
+ client.setAccept("text/d");
+ r = client.doGet(url).getResponseAsString();
+ assertEquals("text/d - test4", r);
+
+ client.setAccept("text/json");
+ r = client.doGet(url).getResponseAsString();
+ assertEquals("\"test4\"", r);
+ }
+
+ //====================================================================================================
+ // Check for valid 406 error response.
+ //====================================================================================================
+ @Test
+ public void test406() throws Exception {
+ String url = URL + "/test406";
+
+ try {
+ client.setAccept("text/bad");
+ 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': 'text/bad'",
+ "Supported media-types: [text/a");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/StaticFilesTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/StaticFilesTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/StaticFilesTest.java
new file mode 100755
index 0000000..8ec05ae
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/StaticFilesTest.java
@@ -0,0 +1,56 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static org.junit.Assert.*;
+
+import org.apache.juneau.client.*;
+import org.apache.juneau.plaintext.*;
+import org.junit.*;
+
+public class StaticFilesTest {
+
+ private static String URL = "/testStaticFiles";
+
+ //====================================================================================================
+ // Tests the @RestResource(staticFiles) annotation.
+ //====================================================================================================
+ @Test
+ public void testXdocs() throws Exception {
+ RestClient client = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class);
+ String r;
+ String url = URL + "/xdocs";
+
+ r = client.doGet(url + "/test.txt").getResponseAsString();
+ assertEquals("OK-1", r);
+ r = client.doGet(url + "/xdocs/test.txt").getResponseAsString();
+ assertEquals("OK-2", r);
+
+ // For security reasons, paths containing ".." should always return 404.
+ try {
+ client.doGet(url + "/xdocs/../test.txt?noTrace=true").connect();
+ fail("404 exception expected");
+ } catch (RestCallException e) {
+ assertEquals(404, e.getResponseCode());
+ }
+
+ try {
+ client.doGet(url + "/xdocs/%2E%2E/test.txt?noTrace=true").connect();
+ fail("404 exception expected");
+ } catch (RestCallException e) {
+ assertEquals(404, e.getResponseCode());
+ }
+
+ client.closeQuietly();
+ }
+}
[11/14] incubator-juneau git commit: Clean up test and test resource
class names.
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestParsers.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestParsers.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestParsers.java
deleted file mode 100755
index 2b3e55a..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestParsers.java
+++ /dev/null
@@ -1,111 +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.server;
-
-import static org.apache.juneau.server.annotation.Inherit.*;
-
-import org.apache.juneau.*;
-import org.apache.juneau.annotation.*;
-import org.apache.juneau.internal.*;
-import org.apache.juneau.parser.*;
-import org.apache.juneau.plaintext.*;
-import org.apache.juneau.server.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- * Validates correct parser is used.
- */
-@RestResource(
- path="/testParsers",
- parsers=TestParsers.TestParserA.class,
- serializers=PlainTextSerializer.class
-)
-public class TestParsers extends RestServletDefault {
- private static final long serialVersionUID = 1L;
-
- @Consumes("text/a")
- public static class TestParserA extends ReaderParser {
- @SuppressWarnings("unchecked")
- @Override /* Parser */
- protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception {
- return (T)("text/a - " + IOUtils.read(session.getReader()).trim());
- }
- }
-
- //====================================================================================================
- // Parser defined on class.
- //====================================================================================================
- @RestMethod(name="PUT", path="/testParserOnClass")
- public String testParserOnClass(@Content String in) {
- return in;
- }
-
- //====================================================================================================
- // Parser defined on method.
- //====================================================================================================
- @RestMethod(name="PUT", path="/testParserOnMethod", parsers=TestParserB.class)
- public String testParserOnMethod(@Content String in) {
- return in;
- }
-
- @Consumes("text/b")
- public static class TestParserB extends ReaderParser {
- @SuppressWarnings("unchecked")
- @Override /* Parser */
- protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception {
- return (T)("text/b - " + IOUtils.read(session.getReader()).trim());
- }
- }
-
- //====================================================================================================
- // Parser overridden on method.
- //====================================================================================================
- @RestMethod(name="PUT", path="/testParserOverriddenOnMethod", parsers={TestParserB.class,TestParserC.class}, parsersInherit=PARSERS)
- public String testParserOverriddenOnMethod(@Content String in) {
- return in;
- }
-
- @Consumes("text/c")
- public static class TestParserC extends ReaderParser {
- @SuppressWarnings("unchecked")
- @Override /* Parser */
- protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception {
- return (T)("text/c - " + IOUtils.read(session.getReader()).trim());
- }
- }
-
- //====================================================================================================
- // Parser with different Accept than Content-Type.
- //====================================================================================================
- @RestMethod(name="PUT", path="/testParserWithDifferentMediaTypes", parsers={TestParserD.class}, parsersInherit=PARSERS)
- public String testParserWithDifferentMediaTypes(@Content String in) {
- return in;
- }
-
- @Consumes({"text/a","text/d"})
- public static class TestParserD extends ReaderParser {
- @SuppressWarnings("unchecked")
- @Override /* Parser */
- protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception {
- return (T)("text/d - " + IOUtils.read(session.getReader()).trim());
- }
- }
-
- //====================================================================================================
- // Check for valid error response.
- //====================================================================================================
- @RestMethod(name="PUT", path="/testValidErrorResponse")
- public String testValidErrorResponse(@Content String in) {
- return in;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestPath.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestPath.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestPath.java
deleted file mode 100755
index a4e1315..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestPath.java
+++ /dev/null
@@ -1,68 +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.server;
-
-import org.apache.juneau.server.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- * Tests the RestServlet.getPath() method.
- */
-@RestResource(
- path="/testPath",
- children={
- TestPath.TestPath2.class
- }
-)
-public class TestPath extends RestServletDefault {
- private static final long serialVersionUID = 1L;
-
- //====================================================================================================
- // Basic tests
- //====================================================================================================
- @RestMethod(name="GET", path="/")
- public String doGet() {
- return getPath();
- }
-
- @RestResource(
- path="/testPath2",
- children={
- TestPath.TestPath3.class
- }
- )
- public static class TestPath2 extends RestServletDefault {
- private static final long serialVersionUID = 1L;
- // Basic tests
- @RestMethod(name="GET", path="/")
- public String doGet() {
- return getPath();
- }
- }
-
- @RestResource(
- path="/testPath3"
- )
- public static class TestPath3a extends RestServletDefault {
- private static final long serialVersionUID = 1L;
- // Basic tests
- @RestMethod(name="GET", path="/")
- public String doGet() {
- return getPath();
- }
- }
-
- public static class TestPath3 extends TestPath3a {
- private static final long serialVersionUID = 1L;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestPaths.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestPaths.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestPaths.java
deleted file mode 100755
index 453f864..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestPaths.java
+++ /dev/null
@@ -1,72 +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.server;
-
-import org.apache.juneau.*;
-import org.apache.juneau.server.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- * Tests the URL-related methods on RestRequest.
- */
-@RestResource(
- path="/testPaths",
- children={
- TestPaths.A.class
- }
-)
-public class TestPaths extends RestServletDefault {
- private static final long serialVersionUID = 1L;
-
- @RestMethod(name="GET", path="/*")
- public ObjectMap doGet1(RestRequest req, @PathRemainder String r) {
- return getPaths(req).append("pathRemainder2", r).append("method",1);
- }
-
- @RestMethod(name="GET", path="/test2/*")
- public ObjectMap doGet2(RestRequest req, @PathRemainder String r) {
- return getPaths(req).append("pathRemainder2", r).append("method",2);
- }
-
- @RestResource(
- path="/a"
- )
- public static class A extends RestServletDefault {
- private static final long serialVersionUID = 1L;
- @RestMethod(name="GET", path="/*")
- public ObjectMap doGet1(RestRequest req, @PathRemainder String r) {
- return getPaths(req).append("pathRemainder2", r).append("method",3);
- }
- @RestMethod(name="GET", path="/test2/*")
- public ObjectMap doGet2(RestRequest req, @PathRemainder String r) {
- return getPaths(req).append("pathRemainder2", r).append("method",4);
- }
- }
-
- private static ObjectMap getPaths(RestRequest req) {
- return new ObjectMap()
- .append("pathInfo", req.getPathInfo())
- .append("pathInfoUndecoded", req.getPathInfoUndecoded())
- .append("pathInfoParts", req.getPathInfoParts())
- .append("pathRemainder", req.getPathRemainder())
- .append("pathRemainderUndecoded", req.getPathRemainderUndecoded())
- .append("requestURI", req.getRequestURI())
- .append("requestParentURI", req.getRequestParentURI())
- .append("requestURL", req.getRequestURL())
- .append("servletPath", req.getServletPath())
- .append("servletURI", req.getServletURI())
- .append("servletParentURI", req.getServletParentURI())
- .append("relativeServletURI", req.getRelativeServletURI());
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestProperties.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestProperties.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestProperties.java
deleted file mode 100755
index baccafa..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestProperties.java
+++ /dev/null
@@ -1,89 +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.server;
-
-import static java.lang.String.*;
-
-import org.apache.juneau.*;
-import org.apache.juneau.annotation.*;
-import org.apache.juneau.serializer.*;
-import org.apache.juneau.server.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testProperties",
- properties={
- @Property(name="A1",value="a1"),
- @Property(name="A2",value="a2"),
- @Property(name="foo",value="bar"),
- @Property(name="bar",value="baz"),
- @Property(name="R1a",value="$R{requestURI}"),
- @Property(name="R1b",value="$R{requestParentURI}"),
- @Property(name="R2",value="$R{foo}"),
- @Property(name="R3",value="$R{$R{foo}}"),
- @Property(name="R4",value="$R{A1}"),
- @Property(name="R5",value="$R{A2}"),
- @Property(name="R6",value="$R{C}"),
- }
-)
-public class TestProperties extends RestServletDefault {
- private static final long serialVersionUID = 1L;
-
- //====================================================================================================
- // Properties defined on method.
- //====================================================================================================
- @RestMethod(name="GET", path="/testPropertiesDefinedOnMethod",
- properties={
- @Property(name="B1",value="b1"),
- @Property(name="B2",value="b2")
- },
- serializers=PropertySerializer1.class
- )
- public void testPropertiesDefinedOnMethod(RestResponse res) {
- res.setProperty("A2", "c");
- res.setProperty("B2", "c");
- res.setProperty("C", "c");
- res.setOutput(null);
- }
-
- @Produces({"application/json","text/json"})
- public static class PropertySerializer1 extends WriterSerializer {
- @Override /* Serializer */
- protected void doSerialize(SerializerSession session, Object output) throws Exception {
- ObjectMap p = session.getProperties();
- session.getWriter().write(format("A1=%s,A2=%s,B1=%s,B2=%s,C=%s,R1a=%s,R1b=%s,R2=%s,R3=%s,R4=%s,R5=%s,R6=%s",
- p.get("A1"), p.get("A2"), p.get("B1"), p.get("B2"), p.get("C"),
- p.get("R1a"), p.get("R1b"), p.get("R2"), p.get("R3"), p.get("R4"), p.get("R5"), p.get("R6")));
- }
- }
-
- //====================================================================================================
- // Make sure attributes/parameters/headers are available through ctx.getProperties().
- //====================================================================================================
- @RestMethod(name="GET", path="/testProperties/{A}", serializers=PropertySerializer2.class)
- public void testProperties(RestResponse res) {
- res.setOutput(null);
- }
-
- @Produces({"application/json","text/json"})
- public static class PropertySerializer2 extends WriterSerializer {
- @Override /* Serializer */
- protected void doSerialize(SerializerSession session, Object output) throws Exception {
- ObjectMap p = session.getProperties();
- session.getWriter().write(format("A=%s,P=%s,H=%s", p.get("A"), p.get("P"), p.get("h")));
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestRestClient2.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestRestClient2.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestRestClient2.java
deleted file mode 100755
index e476263..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestRestClient2.java
+++ /dev/null
@@ -1,35 +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.server;
-
-import java.io.*;
-
-import org.apache.juneau.server.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testRestClient"
-)
-public class TestRestClient2 extends RestServletDefault {
- private static final long serialVersionUID = 1L;
-
- //====================================================================================================
- // Echo response
- //====================================================================================================
- @RestMethod(name="POST", path="/")
- public Reader test1(RestRequest req) throws Exception {
- return new StringReader(req.getInputAsString());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestSerializers.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestSerializers.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestSerializers.java
deleted file mode 100755
index cef0362..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestSerializers.java
+++ /dev/null
@@ -1,102 +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.server;
-
-import static org.apache.juneau.server.annotation.Inherit.*;
-
-import org.apache.juneau.annotation.*;
-import org.apache.juneau.serializer.*;
-import org.apache.juneau.server.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testSerializers",
- serializers=TestSerializers.TestSerializerA.class
-)
-public class TestSerializers extends RestServletDefault {
- private static final long serialVersionUID = 1L;
-
- @Produces("text/a")
- public static class TestSerializerA extends WriterSerializer {
- @Override /* Serializer */
- protected void doSerialize(SerializerSession session, Object o) throws Exception {
- session.getWriter().write("text/a - " + o);
- }
- }
-
- @Produces("text/b")
- public static class TestSerializerB extends WriterSerializer {
- @Override /* Serializer */
- protected void doSerialize(SerializerSession session, Object o) throws Exception {
- session.getWriter().write("text/b - " + o);
- }
- }
-
- //====================================================================================================
- // Serializer defined on class.
- //====================================================================================================
- @RestMethod(name="GET", path="/testSerializerOnClass")
- public String testSerializerOnClass() {
- return "test1";
- }
-
- //====================================================================================================
- // Serializer defined on method.
- //====================================================================================================
- @RestMethod(name="GET", path="/testSerializerOnMethod", serializers=TestSerializerB.class)
- public String testSerializerOnMethod() {
- return "test2";
- }
-
- //====================================================================================================
- // Serializer overridden on method.
- //====================================================================================================
- @RestMethod(name="GET", path="/testSerializerOverriddenOnMethod", serializers={TestSerializerB.class,TestSerializerC.class}, serializersInherit=SERIALIZERS)
- public String testSerializerOverriddenOnMethod() {
- return "test3";
- }
-
- @Produces("text/a")
- public static class TestSerializerC extends WriterSerializer {
- @Override /* Serializer */
- protected void doSerialize(SerializerSession session, Object o) throws Exception {
- session.getWriter().write("text/c - " + o);
- }
- }
-
- //====================================================================================================
- // Serializer with different Accept than Content-Type.
- //====================================================================================================
- @RestMethod(name="GET", path="/testSerializerWithDifferentMediaTypes", serializers={TestSerializerD.class}, serializersInherit=SERIALIZERS)
- public String testSerializerWithDifferentMediaTypes() {
- return "test4";
- }
-
- @Produces(value={"text/a","text/d"},contentType="text/d")
- public static class TestSerializerD extends WriterSerializer {
- @Override /* Serializer */
- protected void doSerialize(SerializerSession session, Object o) throws Exception {
- session.getWriter().write("text/d - " + o);
- }
- }
-
- //====================================================================================================
- // Check for valid 406 error response.
- //====================================================================================================
- @RestMethod(name="GET", path="/test406")
- public String test406() {
- return "test406";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestStaticFiles.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestStaticFiles.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestStaticFiles.java
deleted file mode 100755
index 253e814..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestStaticFiles.java
+++ /dev/null
@@ -1,35 +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.server;
-
-import org.apache.juneau.server.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testStaticFiles",
- staticFiles="{xdocs:'xdocs'}"
-)
-public class TestStaticFiles extends RestServlet {
- private static final long serialVersionUID = 1L;
-
- //====================================================================================================
- // Tests the @RestResource(staticFiles) annotation.
- //====================================================================================================
- @RestMethod(name="GET", path="/*")
- public String testXdocs() {
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestTransforms.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestTransforms.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestTransforms.java
deleted file mode 100755
index 5918f06..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestTransforms.java
+++ /dev/null
@@ -1,114 +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.server;
-
-
-import org.apache.juneau.parser.*;
-import org.apache.juneau.serializer.*;
-import org.apache.juneau.server.annotation.*;
-import org.apache.juneau.transform.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testTransforms",
- transforms={TestTransforms.SwapA2.class}
-)
-public class TestTransforms extends TestTransformsParent {
- private static final long serialVersionUID = 1L;
-
- //====================================================================================================
- // Test class transform overrides parent class transform
- // Should return "A2-1".
- //====================================================================================================
- @RestMethod(name="GET", path="/testClassTransformOverridesParentClassTransform")
- public A testClassTransformOverridesParentClassTransform() {
- return new A();
- }
- @RestMethod(name="PUT", path="/testClassTransformOverridesParentClassTransform")
- public A test1b(@Content A a) {
- return a;
- }
- @RestMethod(name="PUT", path="/testClassTransformOverridesParentClassTransform/{a}")
- public A test1c(@Attr A a) {
- return a;
- }
-
- //====================================================================================================
- // Test method transform overrides class transform
- // Should return "A3-1".
- //====================================================================================================
- @RestMethod(name="GET", path="/testMethodTransformOverridesClassTransform", transforms={SwapA3.class})
- public A test2a() {
- return new A();
- }
- @RestMethod(name="PUT", path="/testMethodTransformOverridesClassTransform", transforms={SwapA3.class})
- public A test2b(@Content A a) {
- return a;
- }
- @RestMethod(name="PUT", path="/testMethodTransformOverridesClassTransform/{a}", transforms={SwapA3.class})
- public A test2c(@Attr A a) {
- return a;
- }
-
-
- public static class A {
- public int f1;
- }
-
- public static class SwapA1 extends PojoSwap<A,String> {
- @Override /* PojoSwap */
- public String swap(A a) throws SerializeException {
- return "A1-" + a.f1;
- }
- @Override /* PojoSwap */
- public A unswap(String in) throws ParseException {
- if (! in.startsWith("A1"))
- throw new RuntimeException("Invalid input for SwapA1!");
- A a = new A();
- a.f1 = Integer.parseInt(in.substring(3));
- return a;
- }
- }
-
- public static class SwapA2 extends PojoSwap<A,String> {
- @Override /* PojoSwap */
- public String swap(A a) throws SerializeException {
- return "A2-" + a.f1;
- }
- @Override /* PojoSwap */
- public A unswap(String in) throws ParseException {
- if (! in.startsWith("A2"))
- throw new RuntimeException("Invalid input for SwapA2!");
- A a = new A();
- a.f1 = Integer.parseInt(in.substring(3));
- return a;
- }
- }
-
- public static class SwapA3 extends PojoSwap<A,String> {
- @Override /* PojoSwap */
- public String swap(A a) throws SerializeException {
- return "A3-" + a.f1;
- }
- @Override /* PojoSwap */
- public A unswap(String in) throws ParseException {
- if (! in.startsWith("A3"))
- throw new RuntimeException("Invalid input for SwapA3!");
- A a = new A();
- a.f1 = Integer.parseInt(in.substring(3));
- return a;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestTransformsParent.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestTransformsParent.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestTransformsParent.java
deleted file mode 100755
index 4e8ddb8..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestTransformsParent.java
+++ /dev/null
@@ -1,25 +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.server;
-
-import org.apache.juneau.server.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- transforms={TestTransforms.SwapA1.class}
-)
-public class TestTransformsParent extends RestServletDefault {
- private static final long serialVersionUID = 1L;
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestUris.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestUris.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestUris.java
deleted file mode 100755
index b2db727..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestUris.java
+++ /dev/null
@@ -1,120 +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.server;
-
-import org.apache.juneau.*;
-import org.apache.juneau.server.annotation.*;
-
-@RestResource(
- path="/testuris",
- children={
- TestUris.Child.class
- }
-)
-public class TestUris extends RestServletDefault {
- private static final long serialVersionUID = 1L;
-
- @RestMethod(name="GET", path="/*")
- public ObjectMap test1(RestRequest req) throws Exception {
- return getPathInfoObject(req).append("testMethod", "root.test1");
- }
-
- @RestMethod(name="GET", path="/test2/*")
- public ObjectMap test2(RestRequest req) throws Exception {
- return getPathInfoObject(req).append("testMethod", "root.test2");
- }
-
- @RestMethod(name="GET", path="/test3%2Ftest3/*")
- public ObjectMap test3(RestRequest req) throws Exception {
- return getPathInfoObject(req).append("testMethod", "root.test3");
- }
-
- @RestMethod(name="GET", path="/test4/test4/*")
- public ObjectMap test4(RestRequest req) throws Exception {
- return getPathInfoObject(req).append("testMethod", "root.test4");
- }
-
- @RestResource(
- path="/child",
- children={
- GrandChild.class
- }
- )
- public static class Child extends RestServletDefault {
- private static final long serialVersionUID = 1L;
-
- @RestMethod(name="GET", path="/*")
- public ObjectMap test1(RestRequest req) throws Exception {
- return getPathInfoObject(req).append("testMethod", "child.test1");
- }
-
- @RestMethod(name="GET", path="/test2/*")
- public ObjectMap test2(RestRequest req) throws Exception {
- return getPathInfoObject(req).append("testMethod", "child.test2");
- }
-
- @RestMethod(name="GET", path="/test3%2Ftest3/*")
- public ObjectMap test3(RestRequest req) throws Exception {
- return getPathInfoObject(req).append("testMethod", "child.test3");
- }
-
- @RestMethod(name="GET", path="/test4/test4/*")
- public ObjectMap test4(RestRequest req) throws Exception {
- return getPathInfoObject(req).append("testMethod", "child.test4");
- }
- }
-
- @RestResource(
- path="/grandchild"
- )
- public static class GrandChild extends RestServletDefault {
- private static final long serialVersionUID = 1L;
-
- @RestMethod(name="GET", path="/*")
- public ObjectMap test1(RestRequest req) throws Exception {
- return getPathInfoObject(req).append("testMethod", "grandchild.test1");
- }
-
- @RestMethod(name="GET", path="/test2/*")
- public ObjectMap test2(RestRequest req) throws Exception {
- return getPathInfoObject(req).append("testMethod", "grandchild.test2");
- }
-
- @RestMethod(name="GET", path="/test3%2Ftest3/*")
- public ObjectMap test3(RestRequest req) throws Exception {
- return getPathInfoObject(req).append("testMethod", "grandchild.test3");
- }
-
- @RestMethod(name="GET", path="/test4/test4/*")
- public ObjectMap test4(RestRequest req) throws Exception {
- return getPathInfoObject(req).append("testMethod", "grandchild.test4");
- }
- }
-
- static ObjectMap getPathInfoObject(RestRequest req) throws Exception {
- ObjectMap m = new ObjectMap();
- m.put("contextPath", req.getContextPath());
- m.put("pathInfo", req.getPathInfo());
- m.put("pathRemainder", req.getPathRemainder());
- m.put("pathTranslated", req.getPathTranslated());
- m.put("requestParentURI", req.getRequestParentURI());
- m.put("requestURI", req.getRequestURI());
- m.put("requestURL", req.getRequestURL());
- m.put("servletPath", req.getServletPath());
- m.put("servletURI", req.getServletURI());
- m.put("testURL1", req.getURL("testURL"));
- m.put("testURL2", req.getURL("/testURL"));
- m.put("testURL3", req.getURL("http://testURL"));
- return m;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestUrlContent.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestUrlContent.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestUrlContent.java
deleted file mode 100755
index ad0c64d..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestUrlContent.java
+++ /dev/null
@@ -1,58 +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.server;
-
-import org.apache.juneau.json.*;
-import org.apache.juneau.plaintext.*;
-import org.apache.juneau.server.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testUrlContent",
- serializers={PlainTextSerializer.class},
- parsers={JsonParser.class}
-)
-public class TestUrlContent extends RestServlet {
- private static final long serialVersionUID = 1L;
-
- @RestMethod(name="GET", path="/testString")
- public String testString(@Content String content) {
- return String.format("class=%s, value=%s", content.getClass().getName(), content.toString());
- }
-
- @RestMethod(name="GET", path="/testEnum")
- public String testEnum(@Content TestEnum content) {
- return String.format("class=%s, value=%s", content.getClass().getName(), content.toString());
- }
-
- public static enum TestEnum {
- X1
- }
-
- @RestMethod(name="GET", path="/testBean")
- public String testBean(@Content TestBean content) throws Exception {
- return String.format("class=%s, value=%s", content.getClass().getName(), JsonSerializer.DEFAULT_LAX.serialize(content));
- }
-
- public static class TestBean {
- public int f1;
- public String f2;
- }
-
- @RestMethod(name="GET", path="/testInt")
- public String testString(@Content Integer content) {
- return String.format("class=%s, value=%s", content.getClass().getName(), content.toString());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TransformsParentResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TransformsParentResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TransformsParentResource.java
new file mode 100755
index 0000000..f7db4d3
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/TransformsParentResource.java
@@ -0,0 +1,25 @@
+/***************************************************************************************************************************
+ * 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;
+
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ transforms={TransformsResource.SwapA1.class}
+)
+public class TransformsParentResource extends RestServletDefault {
+ private static final long serialVersionUID = 1L;
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TransformsResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TransformsResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TransformsResource.java
new file mode 100755
index 0000000..4301411
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/TransformsResource.java
@@ -0,0 +1,114 @@
+/***************************************************************************************************************************
+ * 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;
+
+
+import org.apache.juneau.parser.*;
+import org.apache.juneau.serializer.*;
+import org.apache.juneau.server.annotation.*;
+import org.apache.juneau.transform.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testTransforms",
+ transforms={TransformsResource.SwapA2.class}
+)
+public class TransformsResource extends TransformsParentResource {
+ private static final long serialVersionUID = 1L;
+
+ //====================================================================================================
+ // Test class transform overrides parent class transform
+ // Should return "A2-1".
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testClassTransformOverridesParentClassTransform")
+ public A testClassTransformOverridesParentClassTransform() {
+ return new A();
+ }
+ @RestMethod(name="PUT", path="/testClassTransformOverridesParentClassTransform")
+ public A test1b(@Content A a) {
+ return a;
+ }
+ @RestMethod(name="PUT", path="/testClassTransformOverridesParentClassTransform/{a}")
+ public A test1c(@Attr A a) {
+ return a;
+ }
+
+ //====================================================================================================
+ // Test method transform overrides class transform
+ // Should return "A3-1".
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testMethodTransformOverridesClassTransform", transforms={SwapA3.class})
+ public A test2a() {
+ return new A();
+ }
+ @RestMethod(name="PUT", path="/testMethodTransformOverridesClassTransform", transforms={SwapA3.class})
+ public A test2b(@Content A a) {
+ return a;
+ }
+ @RestMethod(name="PUT", path="/testMethodTransformOverridesClassTransform/{a}", transforms={SwapA3.class})
+ public A test2c(@Attr A a) {
+ return a;
+ }
+
+
+ public static class A {
+ public int f1;
+ }
+
+ public static class SwapA1 extends PojoSwap<A,String> {
+ @Override /* PojoSwap */
+ public String swap(A a) throws SerializeException {
+ return "A1-" + a.f1;
+ }
+ @Override /* PojoSwap */
+ public A unswap(String in) throws ParseException {
+ if (! in.startsWith("A1"))
+ throw new RuntimeException("Invalid input for SwapA1!");
+ A a = new A();
+ a.f1 = Integer.parseInt(in.substring(3));
+ return a;
+ }
+ }
+
+ public static class SwapA2 extends PojoSwap<A,String> {
+ @Override /* PojoSwap */
+ public String swap(A a) throws SerializeException {
+ return "A2-" + a.f1;
+ }
+ @Override /* PojoSwap */
+ public A unswap(String in) throws ParseException {
+ if (! in.startsWith("A2"))
+ throw new RuntimeException("Invalid input for SwapA2!");
+ A a = new A();
+ a.f1 = Integer.parseInt(in.substring(3));
+ return a;
+ }
+ }
+
+ public static class SwapA3 extends PojoSwap<A,String> {
+ @Override /* PojoSwap */
+ public String swap(A a) throws SerializeException {
+ return "A3-" + a.f1;
+ }
+ @Override /* PojoSwap */
+ public A unswap(String in) throws ParseException {
+ if (! in.startsWith("A3"))
+ throw new RuntimeException("Invalid input for SwapA3!");
+ A a = new A();
+ a.f1 = Integer.parseInt(in.substring(3));
+ return a;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/UrisResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/UrisResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/UrisResource.java
new file mode 100755
index 0000000..46c0445
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/UrisResource.java
@@ -0,0 +1,120 @@
+/***************************************************************************************************************************
+ * 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;
+
+import org.apache.juneau.*;
+import org.apache.juneau.server.annotation.*;
+
+@RestResource(
+ path="/testuris",
+ children={
+ UrisResource.Child.class
+ }
+)
+public class UrisResource extends RestServletDefault {
+ private static final long serialVersionUID = 1L;
+
+ @RestMethod(name="GET", path="/*")
+ public ObjectMap test1(RestRequest req) throws Exception {
+ return getPathInfoObject(req).append("testMethod", "root.test1");
+ }
+
+ @RestMethod(name="GET", path="/test2/*")
+ public ObjectMap test2(RestRequest req) throws Exception {
+ return getPathInfoObject(req).append("testMethod", "root.test2");
+ }
+
+ @RestMethod(name="GET", path="/test3%2Ftest3/*")
+ public ObjectMap test3(RestRequest req) throws Exception {
+ return getPathInfoObject(req).append("testMethod", "root.test3");
+ }
+
+ @RestMethod(name="GET", path="/test4/test4/*")
+ public ObjectMap test4(RestRequest req) throws Exception {
+ return getPathInfoObject(req).append("testMethod", "root.test4");
+ }
+
+ @RestResource(
+ path="/child",
+ children={
+ GrandChild.class
+ }
+ )
+ public static class Child extends RestServletDefault {
+ private static final long serialVersionUID = 1L;
+
+ @RestMethod(name="GET", path="/*")
+ public ObjectMap test1(RestRequest req) throws Exception {
+ return getPathInfoObject(req).append("testMethod", "child.test1");
+ }
+
+ @RestMethod(name="GET", path="/test2/*")
+ public ObjectMap test2(RestRequest req) throws Exception {
+ return getPathInfoObject(req).append("testMethod", "child.test2");
+ }
+
+ @RestMethod(name="GET", path="/test3%2Ftest3/*")
+ public ObjectMap test3(RestRequest req) throws Exception {
+ return getPathInfoObject(req).append("testMethod", "child.test3");
+ }
+
+ @RestMethod(name="GET", path="/test4/test4/*")
+ public ObjectMap test4(RestRequest req) throws Exception {
+ return getPathInfoObject(req).append("testMethod", "child.test4");
+ }
+ }
+
+ @RestResource(
+ path="/grandchild"
+ )
+ public static class GrandChild extends RestServletDefault {
+ private static final long serialVersionUID = 1L;
+
+ @RestMethod(name="GET", path="/*")
+ public ObjectMap test1(RestRequest req) throws Exception {
+ return getPathInfoObject(req).append("testMethod", "grandchild.test1");
+ }
+
+ @RestMethod(name="GET", path="/test2/*")
+ public ObjectMap test2(RestRequest req) throws Exception {
+ return getPathInfoObject(req).append("testMethod", "grandchild.test2");
+ }
+
+ @RestMethod(name="GET", path="/test3%2Ftest3/*")
+ public ObjectMap test3(RestRequest req) throws Exception {
+ return getPathInfoObject(req).append("testMethod", "grandchild.test3");
+ }
+
+ @RestMethod(name="GET", path="/test4/test4/*")
+ public ObjectMap test4(RestRequest req) throws Exception {
+ return getPathInfoObject(req).append("testMethod", "grandchild.test4");
+ }
+ }
+
+ static ObjectMap getPathInfoObject(RestRequest req) throws Exception {
+ ObjectMap m = new ObjectMap();
+ m.put("contextPath", req.getContextPath());
+ m.put("pathInfo", req.getPathInfo());
+ m.put("pathRemainder", req.getPathRemainder());
+ m.put("pathTranslated", req.getPathTranslated());
+ m.put("requestParentURI", req.getRequestParentURI());
+ m.put("requestURI", req.getRequestURI());
+ m.put("requestURL", req.getRequestURL());
+ m.put("servletPath", req.getServletPath());
+ m.put("servletURI", req.getServletURI());
+ m.put("testURL1", req.getURL("testURL"));
+ m.put("testURL2", req.getURL("/testURL"));
+ m.put("testURL3", req.getURL("http://testURL"));
+ return m;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/UrlContentResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/UrlContentResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/UrlContentResource.java
new file mode 100755
index 0000000..a1b4726
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/UrlContentResource.java
@@ -0,0 +1,58 @@
+/***************************************************************************************************************************
+ * 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;
+
+import org.apache.juneau.json.*;
+import org.apache.juneau.plaintext.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testUrlContent",
+ serializers={PlainTextSerializer.class},
+ parsers={JsonParser.class}
+)
+public class UrlContentResource extends RestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @RestMethod(name="GET", path="/testString")
+ public String testString(@Content String content) {
+ return String.format("class=%s, value=%s", content.getClass().getName(), content.toString());
+ }
+
+ @RestMethod(name="GET", path="/testEnum")
+ public String testEnum(@Content TestEnum content) {
+ return String.format("class=%s, value=%s", content.getClass().getName(), content.toString());
+ }
+
+ public static enum TestEnum {
+ X1
+ }
+
+ @RestMethod(name="GET", path="/testBean")
+ public String testBean(@Content TestBean content) throws Exception {
+ return String.format("class=%s, value=%s", content.getClass().getName(), JsonSerializer.DEFAULT_LAX.serialize(content));
+ }
+
+ public static class TestBean {
+ public int f1;
+ public String f2;
+ }
+
+ @RestMethod(name="GET", path="/testInt")
+ public String testString(@Content Integer content) {
+ return String.format("class=%s, value=%s", content.getClass().getName(), content.toString());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/resources/org/apache/juneau/server/Messages2Resource.properties
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/resources/org/apache/juneau/server/Messages2Resource.properties b/juneau-server-test/src/main/resources/org/apache/juneau/server/Messages2Resource.properties
new file mode 100755
index 0000000..9a5fe73
--- /dev/null
+++ b/juneau-server-test/src/main/resources/org/apache/juneau/server/Messages2Resource.properties
@@ -0,0 +1,16 @@
+# ***************************************************************************************************************************
+# * 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. *
+# * *
+# ***************************************************************************************************************************
+
+key2 = value2b
+key3 = value3b
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/resources/org/apache/juneau/server/MessagesResource.properties
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/resources/org/apache/juneau/server/MessagesResource.properties b/juneau-server-test/src/main/resources/org/apache/juneau/server/MessagesResource.properties
new file mode 100755
index 0000000..d107ee8
--- /dev/null
+++ b/juneau-server-test/src/main/resources/org/apache/juneau/server/MessagesResource.properties
@@ -0,0 +1,16 @@
+# ***************************************************************************************************************************
+# * 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. *
+# * *
+# ***************************************************************************************************************************
+
+key1 = value1a
+key2 = value2a
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/resources/org/apache/juneau/server/NlsPropertyResource.properties
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/resources/org/apache/juneau/server/NlsPropertyResource.properties b/juneau-server-test/src/main/resources/org/apache/juneau/server/NlsPropertyResource.properties
new file mode 100755
index 0000000..a833256
--- /dev/null
+++ b/juneau-server-test/src/main/resources/org/apache/juneau/server/NlsPropertyResource.properties
@@ -0,0 +1,16 @@
+# ***************************************************************************************************************************
+# * 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. *
+# * *
+# ***************************************************************************************************************************
+
+key1 = value1
+key2 = value2
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/resources/org/apache/juneau/server/NlsResource.properties
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/resources/org/apache/juneau/server/NlsResource.properties b/juneau-server-test/src/main/resources/org/apache/juneau/server/NlsResource.properties
new file mode 100755
index 0000000..9833d00
--- /dev/null
+++ b/juneau-server-test/src/main/resources/org/apache/juneau/server/NlsResource.properties
@@ -0,0 +1,79 @@
+# ***************************************************************************************************************************
+# * 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. *
+# * *
+# ***************************************************************************************************************************
+
+label = Test2.a
+description = Test2.b
+test2 = Test2.c
+test2.req.attr.a = Test2.d
+test2.req.param.b = Test2.e
+test2.req.content = Test2.f
+test2.req.header.D = Test2.g
+test2.req.attr.a2 = Test2.h
+test2.req.param.b2 = Test2.i
+test2.req.header.D2 = Test2.j
+test2.req.foo.bar = Test2.k
+test2.res.200 = OK2
+test2.res.201 = Test2.l
+test2.res.201.foo.bar = Test2.m
+
+Test3.label = Test3.a
+Test3.description = Test3.b
+Test3.test3 = Test3.c
+Test3.test3.req.attr.a = Test3.d
+Test3.test3.req.param.b = Test3.e
+Test3.test3.req.content = Test3.f
+Test3.test3.req.header.D = Test3.g
+Test3.test3.req.attr.a2 = Test3.h
+Test3.test3.req.param.b2 = Test3.i
+Test3.test3.req.header.D2 = Test3.j
+Test3.test3.req.foo.bar = Test3.k
+Test3.test3.res.200 = OK3
+Test3.test3.res.201 = Test3.l
+Test3.test3.res.201.foo.bar = Test3.m
+
+Test4.label = $L{foo}
+Test4.description = $L{foo}
+Test4.test4 = $L{foo}
+Test4.test4.req.attr.a = $L{foo}
+Test4.test4.req.param.b = $L{foo}
+Test4.test4.req.content = $L{foo}
+Test4.test4.req.header.D = $L{foo}
+Test4.test4.req.attr.a2 = $L{foo}
+Test4.test4.req.param.b2 = $L{foo}
+Test4.test4.req.header.D2 = $L{foo}
+Test4.test4.req.foo.bar = $L{foo}
+Test4.test4.res.200 = foo$L{foo}foo$L{foo}foo
+Test4.test4.res.201 = $L{foo}
+Test4.test4.res.201.foo.bar = $L{foo}
+
+foo = $L{bar}
+bar = baz
+
+Test5.label = $L{foo2}
+Test5.description = $R{servletLabel}
+Test5.test5 = $R{servletLabel}
+Test5.test5.req.attr.a = $R{servletLabel}
+Test5.test5.req.param.b = $R{servletLabel}
+Test5.test5.req.content = $R{servletLabel}
+Test5.test5.req.header.D = $R{servletLabel}
+Test5.test5.req.attr.a2 = $R{servletLabel}
+Test5.test5.req.param.b2 = $R{servletLabel}
+Test5.test5.req.header.D2 = $R{servletLabel}
+Test5.test5.req.foo.bar = $R{servletLabel}
+Test5.test5.res.200 = foo$R{servletLabel}foo$R{servletLabel}foo
+Test5.test5.res.201 = $R{servletLabel}
+Test5.test5.res.201.foo.bar = $R{servletLabel}
+Test5.foo2 = $L{bar2}
+Test5.bar2 = baz2
+
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/resources/org/apache/juneau/server/TestMessages.properties
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/resources/org/apache/juneau/server/TestMessages.properties b/juneau-server-test/src/main/resources/org/apache/juneau/server/TestMessages.properties
deleted file mode 100755
index d107ee8..0000000
--- a/juneau-server-test/src/main/resources/org/apache/juneau/server/TestMessages.properties
+++ /dev/null
@@ -1,16 +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. *
-# * *
-# ***************************************************************************************************************************
-
-key1 = value1a
-key2 = value2a
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/resources/org/apache/juneau/server/TestMessages2.properties
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/resources/org/apache/juneau/server/TestMessages2.properties b/juneau-server-test/src/main/resources/org/apache/juneau/server/TestMessages2.properties
deleted file mode 100755
index 9a5fe73..0000000
--- a/juneau-server-test/src/main/resources/org/apache/juneau/server/TestMessages2.properties
+++ /dev/null
@@ -1,16 +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. *
-# * *
-# ***************************************************************************************************************************
-
-key2 = value2b
-key3 = value3b
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/resources/org/apache/juneau/server/TestNls.properties
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/resources/org/apache/juneau/server/TestNls.properties b/juneau-server-test/src/main/resources/org/apache/juneau/server/TestNls.properties
deleted file mode 100755
index 9833d00..0000000
--- a/juneau-server-test/src/main/resources/org/apache/juneau/server/TestNls.properties
+++ /dev/null
@@ -1,79 +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. *
-# * *
-# ***************************************************************************************************************************
-
-label = Test2.a
-description = Test2.b
-test2 = Test2.c
-test2.req.attr.a = Test2.d
-test2.req.param.b = Test2.e
-test2.req.content = Test2.f
-test2.req.header.D = Test2.g
-test2.req.attr.a2 = Test2.h
-test2.req.param.b2 = Test2.i
-test2.req.header.D2 = Test2.j
-test2.req.foo.bar = Test2.k
-test2.res.200 = OK2
-test2.res.201 = Test2.l
-test2.res.201.foo.bar = Test2.m
-
-Test3.label = Test3.a
-Test3.description = Test3.b
-Test3.test3 = Test3.c
-Test3.test3.req.attr.a = Test3.d
-Test3.test3.req.param.b = Test3.e
-Test3.test3.req.content = Test3.f
-Test3.test3.req.header.D = Test3.g
-Test3.test3.req.attr.a2 = Test3.h
-Test3.test3.req.param.b2 = Test3.i
-Test3.test3.req.header.D2 = Test3.j
-Test3.test3.req.foo.bar = Test3.k
-Test3.test3.res.200 = OK3
-Test3.test3.res.201 = Test3.l
-Test3.test3.res.201.foo.bar = Test3.m
-
-Test4.label = $L{foo}
-Test4.description = $L{foo}
-Test4.test4 = $L{foo}
-Test4.test4.req.attr.a = $L{foo}
-Test4.test4.req.param.b = $L{foo}
-Test4.test4.req.content = $L{foo}
-Test4.test4.req.header.D = $L{foo}
-Test4.test4.req.attr.a2 = $L{foo}
-Test4.test4.req.param.b2 = $L{foo}
-Test4.test4.req.header.D2 = $L{foo}
-Test4.test4.req.foo.bar = $L{foo}
-Test4.test4.res.200 = foo$L{foo}foo$L{foo}foo
-Test4.test4.res.201 = $L{foo}
-Test4.test4.res.201.foo.bar = $L{foo}
-
-foo = $L{bar}
-bar = baz
-
-Test5.label = $L{foo2}
-Test5.description = $R{servletLabel}
-Test5.test5 = $R{servletLabel}
-Test5.test5.req.attr.a = $R{servletLabel}
-Test5.test5.req.param.b = $R{servletLabel}
-Test5.test5.req.content = $R{servletLabel}
-Test5.test5.req.header.D = $R{servletLabel}
-Test5.test5.req.attr.a2 = $R{servletLabel}
-Test5.test5.req.param.b2 = $R{servletLabel}
-Test5.test5.req.header.D2 = $R{servletLabel}
-Test5.test5.req.foo.bar = $R{servletLabel}
-Test5.test5.res.200 = foo$R{servletLabel}foo$R{servletLabel}foo
-Test5.test5.res.201 = $R{servletLabel}
-Test5.test5.res.201.foo.bar = $R{servletLabel}
-Test5.foo2 = $L{bar2}
-Test5.bar2 = baz2
-
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/resources/org/apache/juneau/server/TestNlsProperty.properties
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/resources/org/apache/juneau/server/TestNlsProperty.properties b/juneau-server-test/src/main/resources/org/apache/juneau/server/TestNlsProperty.properties
deleted file mode 100755
index a833256..0000000
--- a/juneau-server-test/src/main/resources/org/apache/juneau/server/TestNlsProperty.properties
+++ /dev/null
@@ -1,16 +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. *
-# * *
-# ***************************************************************************************************************************
-
-key1 = value1
-key2 = value2
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/AcceptCharsetTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/AcceptCharsetTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/AcceptCharsetTest.java
new file mode 100755
index 0000000..6a6e9b6
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/AcceptCharsetTest.java
@@ -0,0 +1,123 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static javax.servlet.http.HttpServletResponse.*;
+import static org.apache.juneau.server.TestUtils.*;
+import static org.junit.Assert.*;
+
+import java.io.*;
+
+import org.apache.juneau.client.*;
+import org.apache.juneau.internal.*;
+import org.junit.*;
+
+public class AcceptCharsetTest {
+
+ boolean debug = false;
+
+ //====================================================================================================
+ // Test that Q-values are being resolved correctly.
+ //====================================================================================================
+ @Test
+ public void testQValues() throws Exception {
+ RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
+
+ 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");
+
+ client.closeQuietly();
+ }
+
+ private void check1(RestClient client, String requestCharset, String responseCharset) throws Exception {
+ RestCall r;
+ InputStream is;
+ String url = "/testAcceptCharset/testQValues";
+ r = client.doGet(url).setHeader("Accept-Charset", requestCharset).connect();
+ assertTrue(r.getResponse().getFirstHeader("Content-Type").getValue().toLowerCase().contains(responseCharset));
+ is = r.getInputStream();
+ assertEquals("foo", IOUtils.read(new InputStreamReader(is, responseCharset)));
+ }
+
+ //====================================================================================================
+ // Validate various Accept-Charset variations.
+ //====================================================================================================
+ @Test
+ public void testCharsetOnResponse() throws Exception {
+ RestClient client = new TestRestClient().setAccept("text/plain").setContentType("text/plain");
+ 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("")).setHeader("Accept-Charset", "Shift_JIS").getResponseAsString();
+ assertEquals("utf-8/shift_jis", r.toLowerCase());
+
+ try {
+ r = client.doPut(url+"?noTrace=true", new StringReader("")).setHeader("Accept-Charset", "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("")).setHeader("Accept-Charset", "UTF-8").getResponseAsString();
+ assertEquals("utf-8/utf-8", r.toLowerCase());
+
+ r = client.doPut(url, new StringReader("")).setHeader("Accept-Charset", "bad,iso-8859-1").getResponseAsString();
+ assertEquals("utf-8/iso-8859-1", r.toLowerCase());
+
+ r = client.doPut(url, new StringReader("")).setHeader("Accept-Charset", "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("")).setHeader("Accept-Charset", "bad;q=0.1,iso-8859-1;q=0.9").getResponseAsString();
+ assertEquals("utf-8/iso-8859-1", r.toLowerCase());
+
+ client.setHeader("Accept-Charset", "utf-8");
+
+ r = client.doPut(url, new StringReader("")).setHeader("Content-Type", "text/plain").getResponseAsString();
+ assertEquals("utf-8/utf-8", r.toLowerCase());
+
+ r = client.doPut(url, new StringReader("")).setHeader("Content-Type", "text/plain;charset=utf-8").getResponseAsString();
+ assertEquals("utf-8/utf-8", r.toLowerCase());
+
+ r = client.doPut(url, new StringReader("")).setHeader("Content-Type", "text/plain;charset=UTF-8").getResponseAsString();
+ assertEquals("utf-8/utf-8", r.toLowerCase());
+
+ r = client.doPut(url, new StringReader("")).setHeader("Content-Type", "text/plain;charset=iso-8859-1").getResponseAsString();
+ assertEquals("iso-8859-1/utf-8", r.toLowerCase());
+
+ r = client.doPut(url, new StringReader("")).setHeader("Content-Type", "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
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/BeanContextPropertiesTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/BeanContextPropertiesTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/BeanContextPropertiesTest.java
new file mode 100755
index 0000000..a5ffd65
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/BeanContextPropertiesTest.java
@@ -0,0 +1,37 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static org.junit.Assert.*;
+
+import org.apache.juneau.client.*;
+import org.apache.juneau.json.*;
+import org.junit.*;
+
+public class BeanContextPropertiesTest {
+
+ boolean debug = false;
+
+ //====================================================================================================
+ // Validate that filters defined on class filter to underlying bean context.
+ //====================================================================================================
+ @Test
+ public void testClassTransforms() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.class, JsonParser.class);
+ String r;
+ r = client.doGet("/testBeanContext/testClassTransforms/2001-07-04T15:30:45Z?d2=2001-07-05T15:30:45Z").setHeader("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);
+
+ client.closeQuietly();
+ }
+}
\ No newline at end of file
[12/14] incubator-juneau git commit: Clean up test and test resource
class names.
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestDefaultContentTypes.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestDefaultContentTypes.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestDefaultContentTypes.java
deleted file mode 100755
index b17c974..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestDefaultContentTypes.java
+++ /dev/null
@@ -1,127 +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.server;
-
-import static org.apache.juneau.server.annotation.Inherit.*;
-
-import org.apache.juneau.*;
-import org.apache.juneau.annotation.*;
-import org.apache.juneau.parser.*;
-import org.apache.juneau.serializer.*;
-import org.apache.juneau.server.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testDefaultContentTypes",
- defaultRequestHeaders={" Accept : text/s2 "," Content-Type : text/p2 "},
- parsers={TestDefaultContentTypes.P1.class,TestDefaultContentTypes.P2.class}, serializers={TestDefaultContentTypes.S1.class,TestDefaultContentTypes.S2.class}
-)
-@SuppressWarnings("synthetic-access")
-public class TestDefaultContentTypes extends RestServlet {
- private static final long serialVersionUID = 1L;
-
- @Consumes("text/p1")
- public static class P1 extends DummyParser { public P1() {super("p1");}}
-
- @Consumes("text/p2")
- public static class P2 extends DummyParser { public P2() {super("p2");}}
-
- @Consumes("text/p3")
- public static class P3 extends DummyParser { public P3() {super("p3");}}
-
- @Produces("text/s1")
- public static class S1 extends DummySerializer { public S1() {super("s1");}}
-
- @Produces("text/s2")
- public static class S2 extends DummySerializer { public S2() {super("s2");}}
-
- @Produces("text/s3")
- public static class S3 extends DummySerializer { public S3() {super("s3");}}
-
- /**
- * Test that default Accept and Content-Type headers on servlet annotation are picked up.
- */
- @RestMethod(name="PUT", path="/testDefaultHeadersOnServletAnnotation")
- public String testDefaultHeadersOnServletAnnotation(@Content String in) {
- return in;
- }
-
- //====================================================================================================
- // Test that default Accept and Content-Type headers on servlet annotation are picked up
- // when @RestMethod.parsers/serializers annotations are used.
- //====================================================================================================
- @RestMethod(name="PUT", path="/testRestMethodParsersSerializers", parsers=P3.class, serializers=S3.class)
- public String testRestMethodParsersSerializers(@Content String in) {
- return in;
- }
-
- //====================================================================================================
- // Test that default Accept and Content-Type headers on servlet annotation are picked up
- // when @RestMethod.addParsers/addSerializers annotations are used.
- //====================================================================================================
- @RestMethod(name="PUT", path="/testRestMethodAddParsersSerializers", parsers=P3.class, parsersInherit=PARSERS, serializers=S3.class, serializersInherit=SERIALIZERS)
- public String testRestMethodAddParsersSerializers(@Content String in) {
- return in;
- }
-
- //====================================================================================================
- // Various Accept incantations.
- //====================================================================================================
- @RestMethod(name="PUT", path="/testAccept")
- public String testAccept(@Content String in) {
- return in;
- }
-
- //====================================================================================================
- // Test that default Accept and Content-Type headers on method annotation are picked up
- // when @RestMethod.parsers/serializers annotations are used.
- //====================================================================================================
- @RestMethod(name="PUT", path="/testRestMethodParserSerializerAnnotations", defaultRequestHeaders={"Accept: text/s3","Content-Type: text/p3"}, parsers=P3.class, serializers=S3.class)
- public String testRestMethodParserSerializerAnnotations(@Content String in) {
- return in;
- }
-
- //====================================================================================================
- // Test that default Accept and Content-Type headers on method annotation are picked up
- // when @RestMethod.addParsers/addSerializers annotations are used.
- //====================================================================================================
- @RestMethod(name="PUT", path="/testRestMethodAddParsersSerializersAnnotations", defaultRequestHeaders={"Accept: text/s3","Content-Type: text/p3"}, parsers=P3.class, parsersInherit=PARSERS, serializers=S3.class, serializersInherit=SERIALIZERS)
- public String testRestMethodAddParsersSerializersAnnotations(@Content String in) {
- return in;
- }
-
- public static class DummyParser extends ReaderParser {
- private String name;
- private DummyParser(String name) {
- this.name = name;
- }
- @SuppressWarnings("unchecked")
- @Override /* Parser */
- protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception {
- return (T)name;
- }
- }
-
- public static class DummySerializer extends WriterSerializer {
- private String name;
- private DummySerializer(String name) {
- this.name = name;
- }
- @Override /* Serializer */
- protected void doSerialize(SerializerSession session, Object output) throws Exception {
- session.getWriter().write(name + "/" + output);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestErrorConditions.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestErrorConditions.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestErrorConditions.java
deleted file mode 100755
index 3926d82..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestErrorConditions.java
+++ /dev/null
@@ -1,134 +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.server;
-
-import org.apache.juneau.server.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- * Validates correct parser is used.
- */
-@RestResource(
- path="/testErrorConditions"
-)
-public class TestErrorConditions extends RestServletDefault {
- private static final long serialVersionUID = 1L;
-
- //====================================================================================================
- // Test non-existent properties
- //====================================================================================================
- @RestMethod(name="PUT", path="/testNonExistentBeanProperties")
- public String testNonExistentBeanProperties(@Content Test1 in) {
- return "OK";
- }
-
- public static class Test1 {
- public String f1;
- }
-
- //====================================================================================================
- // Test trying to set properties to wrong data type
- //====================================================================================================
- @RestMethod(name="PUT", path="/testWrongDataType")
- public String testWrongDataType(@Content Test2 in) {
- return "OK";
- }
-
- public static class Test2 {
- public int f1;
- }
-
- //====================================================================================================
- // Test trying to parse into class with non-public no-arg constructor.
- //====================================================================================================
- @RestMethod(name="PUT", path="/testParseIntoNonConstructableBean")
- public String testParseIntoNonConstructableBean(@Content Test3a in) {
- return "OK";
- }
-
- public static class Test3a {
- public int f1;
- private Test3a(){}
- }
-
- //====================================================================================================
- // Test trying to parse into non-static inner class
- //====================================================================================================
- @RestMethod(name="PUT", path="/testParseIntoNonStaticInnerClass")
- public String testParseIntoNonStaticInnerClass(@Content Test3b in) {
- return "OK";
- }
-
- public class Test3b {
- public Test3b(){}
- }
-
- //====================================================================================================
- // Test trying to parse into non-public inner class
- //====================================================================================================
- @RestMethod(name="PUT", path="/testParseIntoNonPublicInnerClass")
- public String testParseIntoNonPublicInnerClass(@Content Test3b1 in) {
- return "OK";
- }
-
- static class Test3b1 {
- public Test3b1(){}
- }
-
- //====================================================================================================
- // Test exception thrown during bean construction.
- //====================================================================================================
- @RestMethod(name="PUT", path="/testThrownConstructorException")
- public String testThrownConstructorException(@Content Test3c in) {
- return "OK";
- }
-
- public static class Test3c {
- public int f1;
- private Test3c(){}
- public static Test3c valueOf(String s) {
- throw new RuntimeException("Test error");
- }
- }
-
- //====================================================================================================
- // Test trying to set parameters to invalid types.
- //====================================================================================================
- @RestMethod(name="PUT", path="/testSetParameterToInvalidTypes/{a1}")
- public String testSetParameterToInvalidTypes(@Param("p1") int t1, @Attr int a1, @Header("h1") int h1) {
- return "OK";
- }
-
- //====================================================================================================
- // Test SC_NOT_FOUND & SC_METHOD_NOT_ALLOWED
- //====================================================================================================
- @RestMethod(name="GET", path="/test404and405")
- public String test404and405() {
- return "OK";
- }
-
- //====================================================================================================
- // Test SC_PRECONDITION_FAILED
- //====================================================================================================
- @RestMethod(name="GET", path="/test412", matchers=NeverMatcher.class)
- public String test412() {
- return "OK";
- }
-
- public static class NeverMatcher extends RestMatcher {
- @Override /* RestMatcher */
- public boolean matches(RestRequest req) {
- return false;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestGroups.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestGroups.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestGroups.java
deleted file mode 100755
index d105918..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestGroups.java
+++ /dev/null
@@ -1,71 +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.server;
-
-import org.apache.juneau.*;
-import org.apache.juneau.annotation.*;
-import org.apache.juneau.internal.*;
-import org.apache.juneau.parser.*;
-import org.apache.juneau.serializer.*;
-import org.apache.juneau.server.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testGroups"
-)
-public class TestGroups extends RestServlet {
- private static final long serialVersionUID = 1L;
-
- @Produces({"text/s1","text/s2"})
- public static class SSerializer extends WriterSerializer {
- @Override /* Serializer */
- protected void doSerialize(SerializerSession session, Object output) throws Exception {
- session.getWriter().write("text/s," + output);
- }
- }
-
- @Consumes({"text/p1","text/p2"})
- public static class PParser extends ReaderParser {
- @SuppressWarnings("unchecked")
- @Override /* Parser */
- protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception {
- return (T)IOUtils.read(session.getReader());
- }
- }
-
-
- @Override /* RestServlet */
- public SerializerGroup createSerializers(ObjectMap properties, Class<?>[] filters) throws Exception {
- return new SerializerGroup().append(SSerializer.class).setProperties(properties).addTransforms(filters);
- }
-
- @Override /* RestServlet */
- public ParserGroup createParsers(ObjectMap properties, Class<?>[] filters) throws Exception {
- return new ParserGroup().append(PParser.class).setProperties(properties).addTransforms(filters);
- }
-
- //====================================================================================================
- // Serializer defined on class.
- //====================================================================================================
- @RestMethod(name="GET", path="/testSerializerDefinedOnClass")
- public String testSerializerDefinedOnClass_get() {
- return "GET";
- }
-
- @RestMethod(name="PUT", path="/testSerializerDefinedOnClass")
- public String testSerializerDefinedOnClass_put(@Content String in) {
- return in;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestGzip.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestGzip.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestGzip.java
deleted file mode 100755
index 787488b..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestGzip.java
+++ /dev/null
@@ -1,110 +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.server;
-
-import java.io.*;
-
-import org.apache.juneau.encoders.*;
-import org.apache.juneau.plaintext.*;
-import org.apache.juneau.server.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- */
-public class TestGzip {
-
- //================================================================================
- // Encoder for "myencoding" encoding
- //================================================================================
- public static class MyEncoder extends GzipEncoder {
- @Override /* Encoder */
- public String[] getCodings() {
- return new String[]{"mycoding"};
- }
- }
-
- //====================================================================================================
- // Test with no compression enabled.
- //====================================================================================================
- @RestResource(
- path="/testGzipOff",
- serializers=PlainTextSerializer.class,
- parsers=PlainTextParser.class
- )
- public static class TestGzipOff extends RestServlet {
- private static final long serialVersionUID = 1L;
- @RestMethod(name="GET", path="/")
- public String test1get() {
- return "foo";
- }
- @RestMethod(name="PUT", path="/")
- public String test1put(@Content String in) {
- return in;
- }
- }
-
- //====================================================================================================
- // Test with compression enabled.
- //====================================================================================================
- @RestResource(
- path="/testGzipOn",
- serializers=PlainTextSerializer.class,
- parsers=PlainTextParser.class,
- encoders=MyEncoder.class
- )
- public static class TestGzipOn extends RestServlet {
- private static final long serialVersionUID = 1L;
- @RestMethod(name="GET", path="/")
- public String test1() {
- return "foo";
- }
- @RestMethod(name="PUT", path="/")
- public String test1put(@Content String in) {
- return in;
- }
- // This method bypasses the content type and encoding from
- // the serializers and encoders when calling getOutputStream() directly.
- @RestMethod(name="GET", path="/direct")
- public void direct(RestResponse res) throws Exception {
- res.setContentType("text/direct");
- OutputStream os = res.getOutputStream();
- os.write("test".getBytes());
- os.flush();
- }
-
- // This method bypasses the content type and encoding from
- // the serializers and encoders when calling getWriter() directly.
- @RestMethod(name="GET", path="/direct2")
- public void direct2(RestResponse res) throws Exception {
- Writer w = res.getWriter();
- w.append("test");
- w.flush();
- }
-
- // This method uses getNegotiatedWriter() which should use GZip encoding.
- @RestMethod(name="GET", path="/direct3")
- public void direct3(RestResponse res) throws Exception {
- Writer w = res.getNegotiatedWriter();
- w.append("test");
- w.flush();
- }
-
- // This method overrides the set of encoders at the method level and so shouldn't use GZip encoding.
- @RestMethod(name="GET", path="/direct4", inheritEncoders=false)
- public void direct4(RestResponse res) throws Exception {
- Writer w = res.getNegotiatedWriter();
- w.append("test");
- w.flush();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestInheritance.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestInheritance.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestInheritance.java
deleted file mode 100755
index 4f6dfbd..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestInheritance.java
+++ /dev/null
@@ -1,316 +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.server;
-
-import static org.apache.juneau.server.annotation.Inherit.*;
-
-import java.io.*;
-import java.util.*;
-
-import org.apache.juneau.*;
-import org.apache.juneau.annotation.*;
-import org.apache.juneau.encoders.*;
-import org.apache.juneau.json.*;
-import org.apache.juneau.parser.*;
-import org.apache.juneau.serializer.*;
-import org.apache.juneau.server.annotation.*;
-import org.apache.juneau.server.annotation.Properties;
-import org.apache.juneau.transform.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testInheritance",
- serializers={TestInheritance.S1.class,TestInheritance.S2.class},
- parsers={TestInheritance.P1.class,TestInheritance.P2.class},
- encoders={TestInheritance.E1.class,TestInheritance.E2.class},
- transforms={TestInheritance.F1.class},
- properties={@Property(name="p1",value="v1"), @Property(name="p2",value="v2")}
-)
-public class TestInheritance extends RestServlet {
- private static final long serialVersionUID = 1L;
-
- @RestResource(
- serializers={S3.class,S4.class},
- parsers={P3.class,P4.class},
- encoders={E3.class,E4.class},
- transforms={F2.class},
- properties={@Property(name="p2",value="v2a"), @Property(name="p3",value="v3"), @Property(name="p4",value="v4")}
- )
- public static class Sub extends TestInheritance {
- private static final long serialVersionUID = 1L;
- }
-
- //====================================================================================================
- // Test serializer inheritance.
- //====================================================================================================
- @RestResource(path="/testInheritanceSerializers")
- public static class TestSerializers extends Sub {
- private static final long serialVersionUID = 1L;
-
- // Should show ['text/s3','text/s4','text/s1','text/s2']
- @RestMethod(
- name="GET",
- path="/test1"
- )
- public Reader test1(RestResponse res) {
- return new StringReader(new ObjectList(res.getSupportedMediaTypes()).toString());
- }
-
- // Should show ['text/s5']
- @RestMethod(
- name="GET",
- path="/test2",
- serializers=S5.class
- )
- public Reader test2(RestResponse res) {
- return new StringReader(new ObjectList(res.getSupportedMediaTypes()).toString());
- }
-
- // Should show ['text/s5','text/s3','text/s4','text/s1','text/s2']
- @RestMethod(
- name="GET",
- path="/test3",
- serializers=S5.class,
- serializersInherit=SERIALIZERS
- )
- public Reader test3(RestResponse res) {
- return new StringReader(new ObjectList(res.getSupportedMediaTypes()).toString());
- }
- }
-
- //====================================================================================================
- // Test parser inheritance.
- //====================================================================================================
- @RestResource(path="/testInheritanceParsers")
- public static class TestParsers extends Sub {
- private static final long serialVersionUID = 1L;
-
- // Should show ['text/p3','text/p4','text/p1','text/p2']
- @RestMethod(
- name="GET",
- path="/test1"
- )
- public Reader test1(RestRequest req) {
- return new StringReader(new ObjectList(req.getSupportedMediaTypes()).toString());
- }
-
- // Should show ['text/p5']
- @RestMethod(
- name="GET",
- path="/test2",
- parsers=P5.class
- )
- public Reader test2(RestRequest req) {
- return new StringReader(new ObjectList(req.getSupportedMediaTypes()).toString());
- }
-
- // Should show ['text/p5','text/p3','text/p4','text/p1','text/p2']
- @RestMethod(
- name="GET",
- path="/test3",
- parsers=P5.class,
- parsersInherit=PARSERS
- )
- public Reader test3(RestRequest req) {
- return new StringReader(new ObjectList(req.getSupportedMediaTypes()).toString());
- }
- }
-
- //====================================================================================================
- // Test encoder inheritance.
- //====================================================================================================
- @RestResource(path="/testInheritanceEncoders")
- public static class TestEncoders extends Sub {
- private static final long serialVersionUID = 1L;
-
- // Should show ['e3','e4','e1','e2','identity']
- @RestMethod(name="GET", path="/test")
- public Reader test(RestResponse res) throws RestServletException {
- return new StringReader(new ObjectList(res.getSupportedEncodings()).toString());
- }
- }
-
- //====================================================================================================
- // Test filter inheritance.
- //====================================================================================================
- @RestResource(path="/testInheritanceTransforms", serializers=JsonSerializer.Simple.class)
- public static class TestTransforms extends Sub {
- private static final long serialVersionUID = 1L;
-
- // Should show ['F1','F2','Foo3']
- @RestMethod(name="GET", path="/test1")
- public Object[] test1() {
- return new Object[]{new Foo1(), new Foo2(), new Foo3()};
- }
-
- // Should show ['F1','F2','F3']
- // Inherited serializer already has parent filters applied.
- @RestMethod(name="GET", path="/test2", transforms=F3.class)
- public Object[] test2() {
- return new Object[]{new Foo1(), new Foo2(), new Foo3()};
- }
-
- // Should show ['F1','F2','F3']
- @RestMethod(name="GET", path="/test3", transforms=F3.class, serializersInherit=TRANSFORMS)
- public Object[] test3() {
- return new Object[]{new Foo1(), new Foo2(), new Foo3()};
- }
-
- // Should show ['Foo1','Foo2','F3']
- // Overriding serializer does not have parent filters applied.
- @RestMethod(name="GET", path="/test4", serializers=JsonSerializer.Simple.class, transforms=F3.class)
- public Object[] test4() {
- return new Object[]{new Foo1(), new Foo2(), new Foo3()};
- }
-
- // Should show ['F1','F2','F3']
- // Overriding serializer does have parent filters applied.
- @RestMethod(name="GET", path="/test5", serializers=JsonSerializer.Simple.class, transforms=F3.class, serializersInherit=TRANSFORMS)
- public Object[] test5() {
- return new Object[]{new Foo1(), new Foo2(), new Foo3()};
- }
- }
-
- //====================================================================================================
- // Test properties inheritance.
- //====================================================================================================
- @RestResource(path="/testInheritanceProperties", serializers=JsonSerializer.Simple.class)
- public static class TestProperties extends Sub {
- private static final long serialVersionUID = 1L;
-
- // Should show {p1:'v1',p2:'v2a',p3:'v3',p4:'v4'}
- @RestMethod(name="GET", path="/test1")
- public ObjectMap test1(@Properties ObjectMap properties) {
- return transform(properties);
- }
-
- // Should show {p1:'v1',p2:'v2a',p3:'v3',p4:'v4a',p5:'v5'} when override is false.
- // Should show {p1:'x',p2:'x',p3:'x',p4:'x',p5:'x'} when override is true.
- @RestMethod(name="GET", path="/test2",
- properties={@Property(name="p4",value="v4a"), @Property(name="p5", value="v5")})
- public ObjectMap test2(@Properties ObjectMap properties, @HasParam("override") boolean override) {
- if (override) {
- properties.put("p1", "x");
- properties.put("p2", "x");
- properties.put("p3", "x");
- properties.put("p4", "x");
- properties.put("p5", "x");
- }
- return transform(properties);
- }
-
- private ObjectMap transform(ObjectMap properties) {
- ObjectMap m = new ObjectMap();
- for (Map.Entry<String,Object> e : properties.entrySet()) {
- if (e.getKey().startsWith("p"))
- m.put(e.getKey(), e.getValue());
- }
- return m;
- }
- }
-
- public static class DummyParser extends ReaderParser {
- @Override /* Parser */
- protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception {
- return null;
- }
- }
-
- public static class DummySerializer extends WriterSerializer {
- @Override /* Serializer */
- protected void doSerialize(SerializerSession session, Object o) throws Exception {
- session.getWriter().write(o.toString());
- }
- }
-
- @Consumes("text/p1")
- public static class P1 extends DummyParser{}
-
- @Consumes("text/p2")
- public static class P2 extends DummyParser{}
-
- @Consumes("text/p3")
- public static class P3 extends DummyParser{}
-
- @Consumes("text/p4")
- public static class P4 extends DummyParser{}
-
- @Consumes("text/p5")
- public static class P5 extends DummyParser{}
-
- @Produces("text/s1")
- public static class S1 extends DummySerializer{}
-
- @Produces("text/s2")
- public static class S2 extends DummySerializer{}
-
- @Produces("text/s3")
- public static class S3 extends DummySerializer{}
-
- @Produces("text/s4")
- public static class S4 extends DummySerializer{}
-
- @Produces("text/s5")
- public static class S5 extends DummySerializer{}
-
- public static class E1 extends IdentityEncoder {
- @Override public String[] getCodings() {
- return new String[]{"e1"};
- }
- }
-
- public static class E2 extends IdentityEncoder {
- @Override public String[] getCodings() {
- return new String[]{"e2"};
- }
- }
-
- public static class E3 extends IdentityEncoder {
- @Override public String[] getCodings() {
- return new String[]{"e3"};
- }
- }
-
- public static class E4 extends IdentityEncoder {
- @Override public String[] getCodings() {
- return new String[]{"e4"};
- }
- }
-
- public static class Foo1 {@Override public String toString(){return "Foo1";}}
- public static class Foo2 {@Override public String toString(){return "Foo2";}}
- public static class Foo3 {@Override public String toString(){return "Foo3";}}
-
- public static class F1 extends PojoSwap<Foo1,String> {
- @Override /* PojoSwap */
- public String swap(Foo1 o) throws SerializeException {
- return "F1";
- }
- }
-
- public static class F2 extends PojoSwap<Foo2,String> {
- @Override /* PojoSwap */
- public String swap(Foo2 o) throws SerializeException {
- return "F2";
- }
- }
-
- public static class F3 extends PojoSwap<Foo3,String> {
- @Override /* PojoSwap */
- public String swap(Foo3 o) throws SerializeException {
- return "F3";
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestLargePojos.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestLargePojos.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestLargePojos.java
deleted file mode 100755
index 011e73f..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestLargePojos.java
+++ /dev/null
@@ -1,40 +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.server;
-
-
-import org.apache.juneau.server.annotation.*;
-import org.apache.juneau.server.jena.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testLargePojos"
-)
-public class TestLargePojos extends RestServletJenaDefault {
- private static final long serialVersionUID = 1L;
-
- //====================================================================================================
- // Test how long it takes to serialize/parse various content types.
- //====================================================================================================
- @RestMethod(name="GET", path="/")
- public LargePojo testGet() {
- return LargePojo.create();
- }
-
- @RestMethod(name="PUT", path="/")
- public String testPut(@Content LargePojo in) {
- return "ok";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestMessages.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestMessages.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestMessages.java
deleted file mode 100755
index adfe2b6..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestMessages.java
+++ /dev/null
@@ -1,61 +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.server;
-
-import java.util.*;
-
-import org.apache.juneau.*;
-import org.apache.juneau.serializer.*;
-import org.apache.juneau.server.annotation.*;
-import org.apache.juneau.transform.*;
-
-/**
- * JUnit automated testcase resource.
- * Validates that resource bundles can be defined on both parent and child classes.
- */
-@RestResource(
- path="/testMessages",
- messages="TestMessages",
- transforms={
- TestMessages.ResourceBundleSwap.class
- }
-)
-public class TestMessages extends RestServletDefault {
- private static final long serialVersionUID = 1L;
-
- //====================================================================================================
- // Return contents of resource bundle.
- //====================================================================================================
- @RestMethod(name="GET", path="/test")
- public Object test(@Messages ResourceBundle nls) {
- return nls;
- }
-
-
- @SuppressWarnings("serial")
- @RestResource(
- path="/testMessages2",
- messages="TestMessages2"
- )
- public static class TestMessages2 extends TestMessages {}
-
- public static class ResourceBundleSwap extends PojoSwap<ResourceBundle,ObjectMap> {
- @Override /* Transform */
- public ObjectMap swap(ResourceBundle o) throws SerializeException {
- ObjectMap m = new ObjectMap();
- for (String k : o.keySet())
- m.put(k, o.getString(k));
- return m;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestNls.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestNls.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestNls.java
deleted file mode 100755
index 1ad654b..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestNls.java
+++ /dev/null
@@ -1,194 +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.server;
-
-import org.apache.juneau.server.annotation.*;
-import org.apache.juneau.utils.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testNls",
- children={
- TestNls.Test1.class,
- TestNls.Test2.class,
- TestNls.Test3.class,
- TestNls.Test4.class,
- TestNls.Test5.class,
- TestNls.Test6.class
- }
-)
-@SuppressWarnings({"serial"})
-public class TestNls extends RestServletGroupDefault {
- private static final long serialVersionUID = 1L;
-
- //====================================================================================================
- // test1 - Pull labels from annotations only.
- //====================================================================================================
- @RestResource(
- path="/test1",
- messages="TestNls",
- label="Test1.a",
- description="Test1.b"
- )
- public static class Test1 extends RestServletDefault {
-
- @RestMethod(
- name="POST", path="/{a}",
- description="Test1.c",
- input={
- @Var(category="attr", name="a", description="Test1.d"),
- @Var(category="param", name="b", description="Test1.e"),
- @Var(category="content", description="Test1.f"),
- @Var(category="header", name="D", description="Test1.g"),
- @Var(category="attr", name="a2", description="Test1.h"),
- @Var(category="param", name="b2", description="Test1.i"),
- @Var(category="header", name="D2", description="Test1.j"),
- @Var(category="foo", name="bar", description="Test1.k"),
- },
- responses={
- @Response(200),
- @Response(value=201,
- description="Test1.l",
- output={
- @Var(category="foo", name="bar", description="Test1.m"),
- }
- )
- }
- )
- public String test1(@Attr("a") String a, @Param("b") String b, @Content String c, @Header("D") String d,
- @Attr("e") String e, @Param("f") String f, @Header("g") String g) {
- return null;
- }
- }
-
- //====================================================================================================
- // test2 - Pull labels from resource bundles only - simple keys.
- //====================================================================================================
- @RestResource(
- path="/test2",
- messages="TestNls"
- )
- public static class Test2 extends RestServletDefault {
-
- @RestMethod(
- name="POST", path="/{a}"
- )
- public String test2(@Attr("a") String a, @Param("b") String b, @Content String c, @Header("D") String d,
- @Attr("e") String e, @Param("f") String f, @Header("g") String g) {
- return null;
- }
- }
-
- //====================================================================================================
- // test3 - Pull labels from resource bundles only - keys with class names.
- //====================================================================================================
- @RestResource(
- path="/test3",
- messages="TestNls"
- )
- public static class Test3 extends RestServletDefault {
-
- @RestMethod(
- name="POST", path="/{a}"
- )
- public String test3(@Attr("a") String a, @Param("b") String b, @Content String c, @Header("D") String d,
- @Attr("e") String e, @Param("f") String f, @Header("g") String g) {
- return null;
- }
-
- @RestMethod(
- name="GET", path="/"
- )
- public Object test3a(@Messages MessageBundle mb) {
- return mb;
- }
- }
-
- //====================================================================================================
- // test4 - Pull labels from resource bundles only. Values have localized variables to resolve.
- //====================================================================================================
- @RestResource(
- path="/test4",
- messages="TestNls"
- )
- public static class Test4 extends RestServletDefault {
-
- @RestMethod(
- name="POST", path="/{a}"
- )
- public String test4(@Attr("a") String a, @Param("b") String b, @Content String c, @Header("D") String d,
- @Attr("e") String e, @Param("f") String f, @Header("g") String g) {
- return null;
- }
- }
-
- //====================================================================================================
- // test5 - Pull labels from resource bundles only. Values have request variables to resolve.
- //====================================================================================================
- @RestResource(
- path="/test5",
- messages="TestNls"
- )
- public static class Test5 extends RestServletDefault {
-
- @RestMethod(
- name="POST", path="/{a}"
- )
- public String test5(@Attr("a") String a, @Param("b") String b, @Content String c, @Header("D") String d,
- @Attr("e") String e, @Param("f") String f, @Header("g") String g) {
- return null;
- }
- }
-
- //====================================================================================================
- // test6 - Pull labels from annotations only, but annotations contain variables.
- //====================================================================================================
- @RestResource(
- path="/test6",
- messages="TestNls",
- label="$L{foo}",
- description="$L{foo}"
- )
- public static class Test6 extends RestServletDefault {
-
- @RestMethod(
- name="POST", path="/{a}",
- description="$L{foo}",
- input={
- @Var(category="attr", name="a", description="$L{foo}"),
- @Var(category="param", name="b", description="$L{foo}"),
- @Var(category="content", description="$L{foo}"),
- @Var(category="header", name="D", description="$L{foo}"),
- @Var(category="attr", name="a2", description="$L{foo}"),
- @Var(category="param", name="b2", description="$L{foo}"),
- @Var(category="header", name="D2", description="$L{foo}"),
- @Var(category="foo", name="bar", description="$L{foo}"),
- },
- responses={
- @Response(200),
- @Response(value=201,
- description="$L{foo}",
- output={
- @Var(category="foo", name="bar", description="$L{foo}"),
- }
- )
- }
- )
- public String test6(@Attr("a") String a, @Param("b") String b, @Content String c, @Header("D") String d,
- @Attr("e") String e, @Param("f") String f, @Header("g") String g) {
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestNlsProperty.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestNlsProperty.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestNlsProperty.java
deleted file mode 100755
index 3f49566..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestNlsProperty.java
+++ /dev/null
@@ -1,60 +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.server;
-
-import org.apache.juneau.annotation.*;
-import org.apache.juneau.serializer.*;
-import org.apache.juneau.server.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testNlsProperty",
- serializers={TestNlsProperty.TestSerializer.class},
- properties={
- @Property(name="TestProperty",value="$L{key1}")
- },
- messages="TestNlsProperty"
-)
-public class TestNlsProperty extends RestServlet {
- private static final long serialVersionUID = 1L;
-
- //====================================================================================================
- // Test getting an NLS property defined on a class.
- //====================================================================================================
- @RestMethod(name="GET", path="/testInheritedFromClass")
- public String testInheritedFromClass() {
- return null;
- }
-
- //====================================================================================================
- // Test getting an NLS property defined on a method.
- //====================================================================================================
- @RestMethod(name="GET", path="/testInheritedFromMethod",
- properties={
- @Property(name="TestProperty",value="$L{key2}")
- }
- )
- public String testInheritedFromMethod() {
- return null;
- }
-
- @Produces("text/plain")
- public static class TestSerializer extends WriterSerializer {
- @Override /* Serializer */
- protected void doSerialize(SerializerSession session, Object o) throws Exception {
- session.getWriter().write(session.getProperties().getString("TestProperty"));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestNoParserInput.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestNoParserInput.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestNoParserInput.java
deleted file mode 100755
index 81f7bcd..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestNoParserInput.java
+++ /dev/null
@@ -1,55 +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.server;
-
-import java.io.*;
-
-import org.apache.juneau.internal.*;
-import org.apache.juneau.plaintext.*;
-import org.apache.juneau.server.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testNoParserInput",
- serializers=PlainTextSerializer.class
-)
-public class TestNoParserInput extends RestServlet {
- private static final long serialVersionUID = 1L;
-
- //====================================================================================================
- // @Content annotated InputStream.
- //====================================================================================================
- @RestMethod(name="PUT", path="/testInputStream")
- public String testInputStream(@Content InputStream in) throws Exception {
- return IOUtils.read(in);
- }
-
- //====================================================================================================
- // @Content annotated Reader.
- //====================================================================================================
- @RestMethod(name="PUT", path="/testReader")
- public String testReader(@Content Reader in) throws Exception {
- return IOUtils.read(in);
- }
-
- //====================================================================================================
- // @Content annotated PushbackReader.
- // This should always fail since the servlet reader is not a pushback reader.
- //====================================================================================================
- @RestMethod(name="PUT", path="/testPushbackReader")
- public String testPushbackReader(@Content PushbackReader in) throws Exception {
- return IOUtils.read(in);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestOnPostCall.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestOnPostCall.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestOnPostCall.java
deleted file mode 100755
index ffac262..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestOnPostCall.java
+++ /dev/null
@@ -1,93 +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.server;
-
-import org.apache.juneau.*;
-import org.apache.juneau.annotation.*;
-import org.apache.juneau.serializer.*;
-import org.apache.juneau.server.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- * Validates that headers
- */
-@RestResource(
- path="/testOnPostCall",
- serializers=TestOnPostCall.TestSerializer.class,
- properties={
- @Property(name="p1",value="sp1"), // Unchanged servlet-level property.
- @Property(name="p2",value="sp2"), // Servlet-level property overridden by onPostCall.
- @Property(name="p3",value="sp3"), // Servlet-level property overridded by method.
- @Property(name="p4",value="sp4") // Servlet-level property overridden by method then onPostCall.
- }
-)
-public class TestOnPostCall extends RestServlet {
- private static final long serialVersionUID = 1L;
-
- @Produces({"text/s1","text/s2","text/s3"})
- public static class TestSerializer extends WriterSerializer {
- @Override /* Serializer */
- protected void doSerialize(SerializerSession session, Object o) throws Exception {
- ObjectMap p = session.getProperties();
- session.getWriter().write("p1="+p.get("p1")+",p2="+p.get("p2")+",p3="+p.get("p3")+",p4="+p.get("p4")+",p5="+p.get("p5")+",contentType="+session.getProperties().getString("mediaType"));
- }
- @Override /* Serializer */
- public ObjectMap getResponseHeaders(ObjectMap properties) {
- if (properties.containsKey("Override-Content-Type"))
- return new ObjectMap().append("Content-Type", properties.get("Override-Content-Type"));
- return null;
- }
- }
-
- @Override /* RestServlet */
- protected void onPostCall(RestRequest req, RestResponse res) {
- ObjectMap properties = req.getProperties();
- properties.put("p2", "xp2");
- properties.put("p4", "xp4");
- properties.put("p5", "xp5"); // New property
- String overrideAccept = req.getHeader("Override-Accept");
- if (overrideAccept != null)
- req.setHeader("Accept", overrideAccept);
- String overrideContentType = req.getHeader("Override-Content-Type");
- if (overrideContentType != null)
- properties.put("Override-Content-Type", overrideContentType);
- }
-
-
- //====================================================================================================
- // Test1 - Properties overridden via properties annotation.
- //====================================================================================================
- @RestMethod(name="PUT", path="/testPropertiesOverridenByAnnotation",
- properties={
- @Property(name="p3",value="mp3"),
- @Property(name="p4",value="mp4")
- },
- defaultRequestHeaders="Accept: text/s2"
- )
- public String testPropertiesOverridenByAnnotation() {
- return "";
- }
-
- //====================================================================================================
- // Test2 - Properties overridden programmatically.
- //====================================================================================================
- @RestMethod(name="PUT", path="/testPropertiesOverriddenProgramatically")
- public String testPropertiesOverriddenProgramatically(RestRequest req, @Properties ObjectMap properties) throws Exception {
- properties.put("p3", "pp3");
- properties.put("p4", "pp4");
- String accept = req.getHeader("Accept");
- if (accept == null || accept.isEmpty())
- req.setHeader("Accept", "text/s2");
- return "";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestOnPreCall.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestOnPreCall.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestOnPreCall.java
deleted file mode 100755
index 6c802ba..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestOnPreCall.java
+++ /dev/null
@@ -1,84 +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.server;
-
-import org.apache.juneau.*;
-import org.apache.juneau.annotation.*;
-import org.apache.juneau.parser.*;
-import org.apache.juneau.plaintext.*;
-import org.apache.juneau.server.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- * Validates that headers
- */
-@RestResource(
- path="/testOnPreCall",
- parsers=TestOnPreCall.TestParserA.class,
- serializers=PlainTextSerializer.class,
- properties={
- @Property(name="p1",value="sp1"), // Unchanged servlet-level property.
- @Property(name="p2",value="sp2"), // Servlet-level property overridden by onPreCall.
- @Property(name="p3",value="sp3"), // Servlet-level property overridded by method.
- @Property(name="p4",value="sp4") // Servlet-level property overridden by method then onPreCall.
- }
-)
-public class TestOnPreCall extends RestServlet {
- private static final long serialVersionUID = 1L;
-
- @Consumes({"text/a1","text/a2","text/a3"})
- public static class TestParserA extends ReaderParser {
- @SuppressWarnings("unchecked")
- @Override /* Parser */
- protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception {
- ObjectMap p = session.getProperties();
- String matchingContentType = session.getProperties().getString("mediaType");
- return (T)("p1="+p.get("p1")+",p2="+p.get("p2")+",p3="+p.get("p3")+",p4="+p.get("p4")+",p5="+p.get("p5")+",contentType="+matchingContentType);
- }
- }
-
- @Override /* RestServlet */
- protected void onPreCall(RestRequest req) {
- ObjectMap properties = req.getProperties();
- properties.put("p2", "xp2");
- properties.put("p4", "xp4");
- properties.put("p5", "xp5"); // New property
- String overrideContentType = req.getHeader("Override-Content-Type");
- if (overrideContentType != null)
- req.setHeader("Content-Type", overrideContentType);
- }
-
-
- //====================================================================================================
- // Properties overridden via properties annotation.
- //====================================================================================================
- @RestMethod(name="PUT", path="/testPropertiesOverriddenByAnnotation",
- properties={
- @Property(name="p3",value="mp3"),
- @Property(name="p4",value="mp4")
- }
- )
- public String testPropertiesOverriddenByAnnotation(@Content String in) {
- return in;
- }
-
- //====================================================================================================
- // Properties overridden programmatically.
- //====================================================================================================
- @RestMethod(name="PUT", path="/testPropertiesOverriddenProgrammatically")
- public String testPropertiesOverriddenProgrammatically(RestRequest req, @Properties ObjectMap properties) throws Exception {
- properties.put("p3", "pp3");
- properties.put("p4", "pp4");
- return req.getInput(String.class);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestOptionsWithoutNls.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestOptionsWithoutNls.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestOptionsWithoutNls.java
deleted file mode 100755
index f85f8c1..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestOptionsWithoutNls.java
+++ /dev/null
@@ -1,43 +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.server;
-
-import org.apache.juneau.server.annotation.*;
-import org.apache.juneau.server.labels.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testOptionsWithoutNls"
-)
-public class TestOptionsWithoutNls extends RestServletDefault {
- private static final long serialVersionUID = 1L;
-
- //====================================================================================================
- // Should get to the options page without errors
- //====================================================================================================
- @RestMethod(name="OPTIONS", path="/testOptions/*")
- public ResourceOptions testOptions(RestRequest req) {
- return new ResourceOptions(this, req);
- }
-
- //====================================================================================================
- // Missing resource bundle should cause {!!x} string.
- //====================================================================================================
- @RestMethod(name="GET", path="/testMissingResourceBundle")
- public String test(RestRequest req) {
- return req.getMessage("bad", 1, 2, 3);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestOverlappingMethods.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestOverlappingMethods.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestOverlappingMethods.java
deleted file mode 100755
index 12d10fc..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestOverlappingMethods.java
+++ /dev/null
@@ -1,145 +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.server;
-
-import org.apache.juneau.plaintext.*;
-import org.apache.juneau.server.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testOverlappingMethods",
- serializers=PlainTextSerializer.class
-)
-public class TestOverlappingMethods extends RestServletDefault {
- private static final long serialVersionUID = 1L;
-
- //====================================================================================================
- // Overlapping guards
- //====================================================================================================
- @RestMethod(name="GET", path="/testOverlappingGuards1", guards=Test1Guard.class)
- public String testOverlappingGuards1() {
- return "test1_doGet";
- }
-
- //====================================================================================================
- // Overlapping guards
- //====================================================================================================
- @RestMethod(name="GET", path="/testOverlappingGuards2", guards={Test1Guard.class, Test2Guard.class})
- public String testOverlappingGuards2() {
- return "test2_doGet";
- }
-
- public static class Test1Guard extends RestGuard {
- @Override /* RestGuard */
- public boolean isRequestAllowed(RestRequest req) {
- return req.getParameter("t1","").equals("1");
- }
- }
-
- public static class Test2Guard extends RestGuard {
- @Override /* RestGuard */
- public boolean isRequestAllowed(RestRequest req) {
- return req.getParameter("t2","").equals("2");
- }
- }
-
- //====================================================================================================
- // Overlapping matchers
- //====================================================================================================
- @RestMethod(name="GET", path="/testOverlappingMatchers1", matchers=Test3aMatcher.class)
- public String testOverlappingMatchers1() {
- return "test3a";
- }
-
- @RestMethod(name="GET", path="/testOverlappingMatchers1", matchers=Test3bMatcher.class)
- public String test3b_doGet() {
- return "test3b";
- }
-
- @RestMethod(name="GET", path="/testOverlappingMatchers1")
- public String test3c_doGet() {
- return "test3c";
- }
-
- public static class Test3aMatcher extends RestMatcher {
- @Override /* RestMatcher */
- public boolean matches(RestRequest req) {
- return req.getParameter("t1","").equals("1");
- }
- }
-
- public static class Test3bMatcher extends RestMatcher {
- @Override /* RestMatcher */
- public boolean matches(RestRequest req) {
- return req.getParameter("t2","").equals("2");
- }
- }
-
- //====================================================================================================
- // Overlapping matchers
- //====================================================================================================
- @RestMethod(name="GET", path="/testOverlappingMatchers2")
- public String test4a_doGet() {
- return "test4a";
- }
-
- @RestMethod(name="GET", path="/testOverlappingMatchers2", matchers={Test3aMatcher.class, Test3bMatcher.class})
- public String test4b_doGet() {
- return "test4b";
- }
-
- //====================================================================================================
- // Overlapping URL patterns
- //====================================================================================================
- @RestMethod(name="GET", path="/testOverlappingUrlPatterns")
- public String testOverlappingUrlPatterns1() {
- return "test5a";
- }
-
- @RestMethod(name="GET", path="/testOverlappingUrlPatterns/*")
- public String testOverlappingUrlPatterns2() {
- return "test5b";
- }
-
- @RestMethod(name="GET", path="/testOverlappingUrlPatterns/foo")
- public String testOverlappingUrlPatterns3() {
- return "test5c";
- }
-
- @RestMethod(name="GET", path="/testOverlappingUrlPatterns/foo/*")
- public String testOverlappingUrlPatterns4() {
- return "test5d";
- }
-
- @RestMethod(name="GET", path="/testOverlappingUrlPatterns/{id}")
- public String testOverlappingUrlPatterns5() {
- return "test5e";
- }
-
- @RestMethod(name="GET", path="/testOverlappingUrlPatterns/{id}/*")
- public String testOverlappingUrlPatterns6() {
- return "test5f";
- }
-
- @RestMethod(name="GET", path="/testOverlappingUrlPatterns/{id}/foo")
- public String testOverlappingUrlPatterns7() {
- return "test5g";
- }
-
- @RestMethod(name="GET", path="/testOverlappingUrlPatterns/{id}/foo/*")
- public String testOverlappingUrlPatterns8() {
- return "test5h";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestParams.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestParams.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestParams.java
deleted file mode 100755
index a448b23..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestParams.java
+++ /dev/null
@@ -1,292 +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.server;
-
-import static org.apache.juneau.server.RestServletContext.*;
-import static org.apache.juneau.urlencoding.UrlEncodingContext.*;
-
-import java.util.*;
-
-import javax.servlet.http.*;
-
-import org.apache.juneau.*;
-import org.apache.juneau.json.*;
-import org.apache.juneau.plaintext.*;
-import org.apache.juneau.samples.addressbook.*;
-import org.apache.juneau.server.annotation.*;
-import org.apache.juneau.transforms.*;
-import org.apache.juneau.urlencoding.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testParams",
- serializers=PlainTextSerializer.class,
- properties={
- @Property(name=REST_allowMethodParam, value="*")
- }
-)
-public class TestParams extends RestServletDefault {
- private static final long serialVersionUID = 1L;
-
- //====================================================================================================
- // Basic tests
- //====================================================================================================
- @RestMethod(name="GET", path="/")
- public void doGet(RestResponse res) {
- res.setOutput("GET");
- }
-
- @RestMethod(name="GET", path="/get1")
- public String doGet1() {
- return "GET /get1";
- }
-
- @RestMethod(name="GET", path="/get1/{foo}")
- public void doGet1a(RestResponse res, String foo) {
- res.setOutput("GET /get1a " + foo);
- }
-
- @RestMethod(name="GET", path="/get1/{foo}/{bar}")
- public void doGet1b(RestResponse res, String foo, String bar) {
- res.setOutput("GET /get1b " + foo + "," + bar);
- }
-
- @RestMethod(name="GET", path="/get3/{foo}/{bar}/*")
- public void doGet3(HttpServletRequest reqx, HttpServletResponse resx, String foo, int bar) {
- RestRequest req = (RestRequest)reqx;
- RestResponse res = (RestResponse)resx;
- res.setOutput("GET /get3/"+foo+"/"+bar+" remainder="+req.getPathRemainder());
- }
-
- // Test method name with overlapping name, remainder allowed.
- @RestMethod(name="GET2")
- public void get2(RestRequest req, RestResponse res) {
- res.setOutput("GET2 remainder="+req.getPathRemainder());
- }
-
- // Default POST
- @RestMethod(name="POST")
- public void doPost(RestRequest req, RestResponse res) {
- res.setOutput("POST remainder="+req.getPathRemainder());
- }
-
- // Bean parameter
- @RestMethod(name="POST", path="/person/{person}")
- public void doPost(RestRequest req, RestResponse res, Person p) {
- res.setOutput("POST /person/{name="+p.name+",birthDate.year="+p.birthDate.get(Calendar.YEAR)+"} remainder="+req.getPathRemainder());
- }
-
- // Various primitive types
- @RestMethod(name="PUT", path="/primitives/{xInt}/{xShort}/{xLong}/{xChar}/{xFloat}/{xDouble}/{xByte}/{xBoolean}")
- public void doPut1(RestResponse res, int xInt, short xShort, long xLong, char xChar, float xFloat, double xDouble, byte xByte, boolean xBoolean) {
- res.setOutput("PUT /primitives/"+xInt+"/"+xShort+"/"+xLong+"/"+xChar+"/"+xFloat+"/"+xDouble+"/"+xByte+"/"+xBoolean);
- }
-
- // Various primitive objects
- @RestMethod(name="PUT", path="/primitiveObjects/{xInt}/{xShort}/{xLong}/{xChar}/{xFloat}/{xDouble}/{xByte}/{xBoolean}")
- public void doPut2(RestResponse res, Integer xInt, Short xShort, Long xLong, Character xChar, Float xFloat, Double xDouble, Byte xByte, Boolean xBoolean) {
- res.setOutput("PUT /primitiveObjects/"+xInt+"/"+xShort+"/"+xLong+"/"+xChar+"/"+xFloat+"/"+xDouble+"/"+xByte+"/"+xBoolean);
- }
-
- // Object with forString(String) method
- @RestMethod(name="PUT", path="/uuid/{uuid}")
- public void doPut1(RestResponse res, UUID uuid) {
- res.setOutput("PUT /uuid/"+uuid);
- }
-
- @Override /* RestServlet */
- public Class<?>[] createTransforms() {
- return new Class[]{CalendarSwap.Medium.class};
- }
-
- //====================================================================================================
- // @Param annotation - GET
- //====================================================================================================
- @RestMethod(name="GET", path="/testParamGet/*")
- public String testParamGet(RestRequest req, @Param("p1") String p1, @Param("p2") int p2) throws Exception {
- return "p1=["+p1+","+req.getParameter("p1")+","+req.getParameter("p1", String.class)+"],p2=["+p2+","+req.getParameter("p2")+","+req.getParameter("p2", int.class)+"]";
- }
-
- //====================================================================================================
- // @Param annotation - POST
- //====================================================================================================
- @RestMethod(name="POST", path="/testParamPost/*")
- public String testParamPost(RestRequest req, @Param("p1") String p1, @Param("p2") int p2) throws Exception {
- return "p1=["+p1+","+req.getParameter("p1")+","+req.getParameter("p1", String.class)+"],p2=["+p2+","+req.getParameter("p2")+","+req.getParameter("p2", int.class)+"]";
- }
-
- //====================================================================================================
- // @QParam annotation - GET
- //====================================================================================================
- @RestMethod(name="GET", path="/testQParamGet/*")
- public String testQParamGet(RestRequest req, @QParam("p1") String p1, @QParam("p2") int p2) throws Exception {
- return "p1=["+p1+","+req.getQueryParameter("p1")+","+req.getQueryParameter("p1", String.class)+"],p2=["+p2+","+req.getQueryParameter("p2")+","+req.getQueryParameter("p2", int.class)+"]";
- }
-
- //====================================================================================================
- // @QParam annotation - POST
- //====================================================================================================
- @RestMethod(name="POST", path="/testQParamPost/*")
- public String testQParamPost(RestRequest req, @QParam("p1") String p1, @QParam("p2") int p2) throws Exception {
- return "p1=["+p1+","+req.getQueryParameter("p1")+","+req.getQueryParameter("p1", String.class)+"],p2=["+p2+","+req.getQueryParameter("p2")+","+req.getQueryParameter("p2", int.class)+"]";
- }
-
- //====================================================================================================
- // @Param(format=PLAIN) annotation - GET
- //====================================================================================================
- @RestMethod(name="GET", path="/testPlainParamGet/*")
- public String testPlainParamGet(RestRequest req, @Param(value="p1",format="PLAIN") String p1) throws Exception {
- return "p1=["+p1+","+req.getParameter("p1")+","+req.getParameter("p1", String.class)+"]";
- }
-
- //====================================================================================================
- // @Param(format=PLAIN) annotation - POST
- //====================================================================================================
- @RestMethod(name="POST", path="/testPlainParamPost/*")
- public String testPlainParamPost(RestRequest req, @Param(value="p1",format="PLAIN") String p1) throws Exception {
- return "p1=["+p1+","+req.getParameter("p1")+","+req.getParameter("p1", String.class)+"]";
- }
-
- //====================================================================================================
- // @QParam(format=PLAIN) annotation - GET
- //====================================================================================================
- @RestMethod(name="GET", path="/testPlainQParamGet/*")
- public String testPlainQParamGet(RestRequest req, @QParam(value="p1",format="PLAIN") String p1) throws Exception {
- return "p1=["+p1+","+req.getQueryParameter("p1")+","+req.getQueryParameter("p1", String.class)+"]";
- }
-
- //====================================================================================================
- // @QParam(format=PLAIN) annotation - POST
- //====================================================================================================
- @RestMethod(name="POST", path="/testPlainQParamPost/*")
- public String testPlainQParamPost(RestRequest req, @QParam(value="p1",format="PLAIN") String p1) throws Exception {
- return "p1=["+p1+","+req.getQueryParameter("p1")+","+req.getQueryParameter("p1", String.class)+"]";
- }
-
- //====================================================================================================
- // @HasParam annotation - GET
- //====================================================================================================
- @RestMethod(name="GET", path="/testHasParamGet/*")
- public String testHasParamGet(RestRequest req, @HasParam("p1") boolean p1, @HasParam("p2") Boolean p2) throws Exception {
- return "p1=["+p1+","+req.hasParameter("p1")+"],p2=["+p2+","+req.hasParameter("p2")+"]";
- }
-
- //====================================================================================================
- // @HasParam annotation - POST
- //====================================================================================================
- @RestMethod(name="POST", path="/testHasParamPost/*")
- public String testHasParamPost(RestRequest req, @HasParam("p1") boolean p1, @HasParam("p2") Boolean p2) throws Exception {
- return "p1=["+p1+","+req.hasParameter("p1")+"],p2=["+p2+","+req.hasParameter("p2")+"]";
- }
-
- //====================================================================================================
- // @HasQParam annotation - GET
- //====================================================================================================
- @RestMethod(name="GET", path="/testHasQParamGet/*")
- public String testHasQParamGet(RestRequest req, @HasQParam("p1") boolean p1, @HasQParam("p2") Boolean p2) throws Exception {
- return "p1=["+p1+","+req.hasQueryParameter("p1")+"],p2=["+p2+","+req.hasQueryParameter("p2")+"]";
- }
-
- //====================================================================================================
- // @HasQParam annotation - POST
- //====================================================================================================
- @RestMethod(name="POST", path="/testHasQParamPost/*")
- public String testHasQParamPost_post(RestRequest req, @HasQParam("p1") boolean p1, @HasQParam("p2") Boolean p2) throws Exception {
- return "p1=["+p1+","+req.hasQueryParameter("p1")+"],p2=["+p2+","+req.hasQueryParameter("p2")+"]";
- }
-
- //====================================================================================================
- // Form POSTS with @Content parameter
- //====================================================================================================
- @RestMethod(name="POST", path="/testFormPostAsContent/*")
- public String testFormPostAsContent(@Content Test6Bean bean,
- @HasQParam("p1") boolean hqp1, @HasQParam("p2") boolean hqp2,
- @QParam("p1") String qp1, @QParam("p2") int qp2) throws Exception {
- return "bean=["+JsonSerializer.DEFAULT_LAX.toString(bean)+"],qp1=["+qp1+"],qp2=["+qp2+"],hqp1=["+hqp1+"],hqp2=["+hqp2+"]";
- }
-
- public static class Test6Bean {
- public String p1;
- public int p2;
- }
-
- //====================================================================================================
- // Test @Param and @QParam annotations when using multi-part parameters (e.g. &key=val1,&key=val2).
- //====================================================================================================
- @RestMethod(name="GET", path="/testMultiPartParams")
- public String testMultiPartParams(
- @QParam(value="p1",multipart=true) String[] p1,
- @QParam(value="p2",multipart=true) int[] p2,
- @QParam(value="p3",multipart=true) List<String> p3,
- @QParam(value="p4",multipart=true) List<Integer> p4,
- @Param(value="p5",multipart=true) String[] p5,
- @Param(value="p6",multipart=true) int[] p6,
- @Param(value="p7",multipart=true) List<String> p7,
- @Param(value="p8",multipart=true) List<Integer> p8,
- @QParam(value="p9",multipart=true) A[] p9,
- @QParam(value="p10",multipart=true) List<A> p10,
- @Param(value="p11",multipart=true) A[] p11,
- @Param(value="p12",multipart=true) List<A> p12) throws Exception {
- ObjectMap m = new ObjectMap()
- .append("p1", p1)
- .append("p2", p2)
- .append("p3", p3)
- .append("p4", p4)
- .append("p5", p5)
- .append("p6", p6)
- .append("p7", p7)
- .append("p8", p8)
- .append("p9", p9)
- .append("p10", p10)
- .append("p11", p11)
- .append("p12", p12);
- return JsonSerializer.DEFAULT_LAX.toString(m);
- }
-
- public static class A {
- public String a;
- public int b;
- public boolean c;
- }
-
- //====================================================================================================
- // Test multi-part parameter keys on bean properties of type array/Collection (i.e. &key=val1,&key=val2)
- // using URLENC_expandedParams property.
- // A simple round-trip test to verify that both serializing and parsing works.
- //====================================================================================================
- @RestMethod(name="POST", path="/testFormPostsWithMultiParamsUsingProperty",
- properties={
- @Property(name=URLENC_expandedParams, value="true"),
- @Property(name=UonSerializerContext.UON_simpleMode, value="true")
- }
- )
- public DTO2s.B testFormPostsWithMultiParamsViaProperty(@Content DTO2s.B content) throws Exception {
- return content;
- }
-
- //====================================================================================================
- // Test multi-part parameter keys on bean properties of type array/Collection (i.e. &key=val1,&key=val2)
- // using @UrlEncoding(expandedParams=true) annotation.
- // A simple round-trip test to verify that both serializing and parsing works.
- //====================================================================================================
- @RestMethod(name="POST", path="/testFormPostsWithMultiParamsUsingAnnotation",
- properties={
- @Property(name=UonSerializerContext.UON_simpleMode, value="true")
- }
- )
- public DTO2s.C testFormPostsWithMultiParamsUsingAnnotation(@Content DTO2s.C content) throws Exception {
- return content;
- }
-}
[05/14] incubator-juneau git commit: Clean up test and test resource
class names.
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestErrorConditionsTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestErrorConditionsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestErrorConditionsTest.java
deleted file mode 100755
index 5b7c1fa..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestErrorConditionsTest.java
+++ /dev/null
@@ -1,220 +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.server;
-
-import static javax.servlet.http.HttpServletResponse.*;
-import static org.apache.juneau.server.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 TestErrorConditionsTest {
-
- 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.TestErrorConditions$Test1' using parser 'org.apache.juneau.json.JsonParser'",
- "Unknown property 'f2' encountered while trying to parse into class 'org.apache.juneau.server.TestErrorConditions$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.TestErrorConditions$Test1' using parser 'org.apache.juneau.json.JsonParser'",
- "Unknown property 'f2' encountered while trying to parse into class 'org.apache.juneau.server.TestErrorConditions$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.TestErrorConditions$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.TestErrorConditions$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.TestErrorConditions$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.TestErrorConditions$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.TestErrorConditions$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.TestErrorConditions.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.TestErrorConditions.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.TestErrorConditions.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/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestGroupsTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestGroupsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestGroupsTest.java
deleted file mode 100755
index 4b57cc7..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestGroupsTest.java
+++ /dev/null
@@ -1,122 +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.server;
-
-import static javax.servlet.http.HttpServletResponse.*;
-import static org.apache.juneau.server.TestUtils.*;
-import static org.junit.Assert.*;
-
-import java.io.*;
-
-import org.apache.juneau.client.*;
-import org.apache.juneau.json.*;
-import org.junit.*;
-
-
-public class TestGroupsTest {
-
- 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/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestGzipTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestGzipTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestGzipTest.java
deleted file mode 100755
index 37b84d3..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestGzipTest.java
+++ /dev/null
@@ -1,344 +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.server;
-
-import static javax.servlet.http.HttpServletResponse.*;
-import static org.apache.juneau.server.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 TestGzipTest {
-
- 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/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestInheritanceTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestInheritanceTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestInheritanceTest.java
deleted file mode 100755
index 428ac60..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestInheritanceTest.java
+++ /dev/null
@@ -1,126 +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.server;
-
-import static org.junit.Assert.*;
-
-import org.apache.juneau.client.*;
-import org.apache.juneau.json.*;
-import org.junit.*;
-
-public class TestInheritanceTest {
-
- 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/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestLargePojosTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestLargePojosTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestLargePojosTest.java
deleted file mode 100755
index fc5863f..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestLargePojosTest.java
+++ /dev/null
@@ -1,83 +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.server;
-
-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 TestLargePojosTest {
-
- 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/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestMessagesTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestMessagesTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestMessagesTest.java
deleted file mode 100755
index 0ba1bcb..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestMessagesTest.java
+++ /dev/null
@@ -1,47 +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.server;
-
-import static org.apache.juneau.server.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 TestMessagesTest {
-
- //====================================================================================================
- // 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/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestNlsPropertyTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestNlsPropertyTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestNlsPropertyTest.java
deleted file mode 100755
index 4a3c225..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestNlsPropertyTest.java
+++ /dev/null
@@ -1,48 +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.server;
-
-import static org.junit.Assert.*;
-
-import org.apache.juneau.client.*;
-import org.apache.juneau.plaintext.*;
-import org.junit.*;
-
-public class TestNlsPropertyTest {
-
- 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/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestNlsTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestNlsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestNlsTest.java
deleted file mode 100755
index 82d55c1..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestNlsTest.java
+++ /dev/null
@@ -1,170 +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.server;
-
-import static org.junit.Assert.*;
-
-import org.apache.juneau.*;
-import org.apache.juneau.client.*;
-import org.apache.juneau.json.*;
-import org.junit.*;
-
-public class TestNlsTest {
-
- 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();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestNoParserInputTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestNoParserInputTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestNoParserInputTest.java
deleted file mode 100755
index 6a42c93..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestNoParserInputTest.java
+++ /dev/null
@@ -1,70 +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.server;
-
-import static javax.servlet.http.HttpServletResponse.*;
-import static org.apache.juneau.server.TestUtils.*;
-import static org.junit.Assert.*;
-
-import org.apache.juneau.client.*;
-import org.apache.juneau.plaintext.*;
-import org.junit.*;
-
-public class TestNoParserInputTest {
-
- private static String URL = "/testNoParserInput";
- private static boolean debug = false;
-
- //====================================================================================================
- // @Content annotated InputStream.
- //====================================================================================================
- @Test
- public void testInputStream() throws Exception {
- RestClient client = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class);
- String r = client.doPut(URL + "/testInputStream", "foo").getResponseAsString();
- assertEquals("foo", r);
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // @Content annotated Reader.
- //====================================================================================================
- @Test
- public void testReader() throws Exception {
- RestClient client = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class);
- String r = client.doPut(URL + "/testReader", "foo").getResponseAsString();
- assertEquals("foo", r);
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // @Content annotated PushbackReader.
- // This should always fail since the servlet reader is not a pushback reader.
- //====================================================================================================
- @Test
- public void testPushbackReader() throws Exception {
- RestClient client = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class);
- try {
- client.doPut(URL + "/testPushbackReader?noTrace=true", "foo").getResponseAsString();
- fail("Exception expected");
- } catch (RestCallException e) {
- checkErrorResponse(debug, e, SC_BAD_REQUEST,
- "Invalid argument type passed to the following method:",
- "'public java.lang.String org.apache.juneau.server.TestNoParserInput.testPushbackReader(java.io.PushbackReader) throws java.lang.Exception'");
- }
-
- client.closeQuietly();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestOnPostCallTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestOnPostCallTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestOnPostCallTest.java
deleted file mode 100755
index 9ad422c..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestOnPostCallTest.java
+++ /dev/null
@@ -1,121 +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.server;
-
-import static org.junit.Assert.*;
-
-import java.io.*;
-
-import org.apache.juneau.client.*;
-import org.junit.*;
-
-public class TestOnPostCallTest {
-
- private static String URL = "/testOnPostCall";
-
- //====================================================================================================
- // Properties overridden via properties annotation.
- //====================================================================================================
- @Test
- public void testPropertiesOverridenByAnnotation() throws Exception {
- RestClient client = new TestRestClient().setAccept("text/s1");
- String url = URL + "/testPropertiesOverridenByAnnotation";
- String r;
- RestCall rc;
-
- r = client.doPut(url, new StringReader("")).getResponseAsString();
- assertEquals("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/s1", r);
-
- r = client.doPut(url, new StringReader("")).setHeader("Override-Accept", "text/s2").getResponseAsString();
- assertEquals("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/s2", r);
-
- rc = client.doPut(url, new StringReader("")).setHeader("Override-Content-Type", "text/s3").connect();
- r = rc.getResponseAsString();
- assertEquals("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/s1", r);
- assertTrue(rc.getResponse().getFirstHeader("Content-Type").getValue().startsWith("text/s3"));
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // Properties overridden via properties annotation. Default Accept header.
- //====================================================================================================
- @Test
- public void testPropertiesOverridenByAnnotationDefaultAccept() throws Exception {
- RestClient client = new TestRestClient().setAccept("");
- String url = URL + "/testPropertiesOverridenByAnnotation";
- String r;
- RestCall rc;
-
- r = client.doPut(url, new StringReader("")).getResponseAsString();
- assertEquals("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/s2", r);
-
- r = client.doPut(url, new StringReader("")).setHeader("Override-Accept", "text/s3").getResponseAsString();
- assertEquals("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/s3", r);
-
- rc = client.doPut(url, new StringReader("")).setHeader("Override-Content-Type", "text/s3").connect();
- r = rc.getResponseAsString();
- assertEquals("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/s2", r);
- assertTrue(rc.getResponse().getFirstHeader("Content-Type").getValue().startsWith("text/s3"));
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // Properties overridden programmatically.
- //====================================================================================================
- @Test
- public void testPropertiesOverriddenProgramatically() throws Exception {
- RestClient client = new TestRestClient().setAccept("text/s1");
- String url = URL + "/testPropertiesOverriddenProgramatically";
- String r;
- RestCall rc;
-
- r = client.doPut(url, new StringReader("")).getResponseAsString();
- assertEquals("p1=sp1,p2=xp2,p3=pp3,p4=xp4,p5=xp5,contentType=text/s1", r);
-
- r = client.doPut(url, new StringReader("")).setHeader("Override-Accept", "text/s2").getResponseAsString();
- assertEquals("p1=sp1,p2=xp2,p3=pp3,p4=xp4,p5=xp5,contentType=text/s2", r);
-
- rc = client.doPut(url, new StringReader("")).setHeader("Override-Content-Type", "text/s3").connect();
- r = rc.getResponseAsString();
- assertEquals("p1=sp1,p2=xp2,p3=pp3,p4=xp4,p5=xp5,contentType=text/s1", r);
- assertTrue(rc.getResponse().getFirstHeader("Content-Type").getValue().startsWith("text/s3"));
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // Properties overridden programmatically. Default Accept header.
- //====================================================================================================
- @Test
- public void testPropertiesOverriddenProgramaticallyDefaultAccept() throws Exception {
- RestClient client = new TestRestClient().setAccept("");
- String url = URL + "/testPropertiesOverriddenProgramatically";
- String r;
- RestCall rc;
-
- r = client.doPut(url, new StringReader("")).getResponseAsString();
- assertEquals("p1=sp1,p2=xp2,p3=pp3,p4=xp4,p5=xp5,contentType=text/s2", r);
-
- r = client.doPut(url, new StringReader("")).setHeader("Override-Accept", "text/s3").getResponseAsString();
- assertEquals("p1=sp1,p2=xp2,p3=pp3,p4=xp4,p5=xp5,contentType=text/s3", r);
-
- rc = client.doPut(url, new StringReader("")).setHeader("Override-Content-Type", "text/s3").connect();
- r = rc.getResponseAsString();
- assertEquals("p1=sp1,p2=xp2,p3=pp3,p4=xp4,p5=xp5,contentType=text/s2", r);
- assertTrue(rc.getResponse().getFirstHeader("Content-Type").getValue().startsWith("text/s3"));
-
- client.closeQuietly();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestOnPreCallTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestOnPreCallTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestOnPreCallTest.java
deleted file mode 100755
index bda13b0..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestOnPreCallTest.java
+++ /dev/null
@@ -1,61 +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.server;
-
-import static org.junit.Assert.*;
-
-import java.io.*;
-
-import org.apache.juneau.client.*;
-import org.junit.*;
-
-public class TestOnPreCallTest {
-
- private static String URL = "/testOnPreCall";
-
- //====================================================================================================
- // Properties overridden via properties annotation.
- //====================================================================================================
- @Test
- public void testPropertiesOverriddenByAnnotation() throws Exception {
- RestClient client = new TestRestClient().setContentType("text/a1").setAccept("text/plain");
- String url = URL + "/testPropertiesOverriddenByAnnotation";
- String r;
-
- r = client.doPut(url, new StringReader("")).getResponseAsString();
- assertEquals("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/a1", r);
-
- r = client.doPut(url, new StringReader("")).setHeader("Override-Content-Type", "text/a2").getResponseAsString();
- assertEquals("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/a2", r);
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // Properties overridden programmatically.
- //====================================================================================================
- @Test
- public void testPropertiesOverriddenProgrammatically() throws Exception {
- RestClient client = new TestRestClient().setContentType("text/a1").setAccept("text/plain");
- String url = URL + "/testPropertiesOverriddenProgrammatically";
- String r;
-
- r = client.doPut(url, new StringReader("")).getResponseAsString();
- assertEquals("p1=sp1,p2=xp2,p3=pp3,p4=pp4,p5=xp5,contentType=text/a1", r);
-
- r = client.doPut(url, new StringReader("")).setHeader("Override-Content-Type", "text/a2").getResponseAsString();
- assertEquals("p1=sp1,p2=xp2,p3=pp3,p4=pp4,p5=xp5,contentType=text/a2", r);
-
- client.closeQuietly();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestOptionsWithoutNlsTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestOptionsWithoutNlsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestOptionsWithoutNlsTest.java
deleted file mode 100755
index b4f7431..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestOptionsWithoutNlsTest.java
+++ /dev/null
@@ -1,51 +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.server;
-
-import static org.junit.Assert.*;
-
-import org.apache.juneau.client.*;
-import org.apache.juneau.json.*;
-import org.apache.juneau.server.labels.*;
-import org.junit.*;
-
-public class TestOptionsWithoutNlsTest {
-
- private static String URL = "/testOptionsWithoutNls";
-
- //====================================================================================================
- // Should get to the options page without errors
- //====================================================================================================
- @Test
- public void testOptions() throws Exception {
- RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
- RestCall r = client.doOptions(URL + "/testOptions");
- ResourceOptions o = r.getResponse(ResourceOptions.class);
- assertEquals("", o.getDescription());
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // Missing resource bundle should cause {!!x} string.
- //====================================================================================================
- @Test
- public void testMissingResourceBundle() throws Exception {
- RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
- RestCall r = client.doGet(URL + "/testMissingResourceBundle");
- String o = r.getResponse(String.class);
- assertEquals("{!!bad}", o);
-
- client.closeQuietly();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestOverlappingMethodsTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestOverlappingMethodsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestOverlappingMethodsTest.java
deleted file mode 100755
index 54e4c76..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestOverlappingMethodsTest.java
+++ /dev/null
@@ -1,170 +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.server;
-
-import static javax.servlet.http.HttpServletResponse.*;
-import static org.apache.juneau.server.TestUtils.*;
-import static org.junit.Assert.*;
-
-import org.apache.juneau.client.*;
-import org.junit.*;
-
-public class TestOverlappingMethodsTest {
-
- private static String URL = "/testOverlappingMethods";
- private static boolean debug = false;
-
- //====================================================================================================
- // Overlapping guards
- //====================================================================================================
- @Test
- public void testOverlappingGuards1() throws Exception {
- RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
- String r;
- String url = URL + "/testOverlappingGuards1";
-
- r = client.doGet(url + "?t1=1").getResponseAsString();
- assertEquals("test1_doGet", r);
-
- try {
- client.doGet(url + "?noTrace=true").connect();
- fail("Exception expected");
- } catch (RestCallException e) {
- checkErrorResponse(debug, e, SC_FORBIDDEN, "Access denied by guard");
- }
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // Overlapping guards
- //====================================================================================================
- @Test
- public void testOverlappingGuards2() throws Exception {
- RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
- String r;
- String url = URL + "/testOverlappingGuards2";
- try {
- client.doGet(url + "?noTrace=true").connect();
- fail("Exception expected");
- } catch (RestCallException e) {
- checkErrorResponse(debug, e, SC_FORBIDDEN, "Access denied by guard");
- }
-
- try {
- client.doGet(url + "?t1=1&noTrace=true").connect();
- fail("Exception expected");
- } catch (RestCallException e) {
- checkErrorResponse(debug, e, SC_FORBIDDEN, "Access denied by guard");
- }
-
- try {
- client.doGet(url + "?t2=2&noTrace=true").connect();
- fail("Exception expected");
- } catch (RestCallException e) {
- checkErrorResponse(debug, e, SC_FORBIDDEN, "Access denied by guard");
- }
-
- r = client.doGet(url + "?t1=1&t2=2").getResponseAsString();
- assertEquals("test2_doGet", r);
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // Overlapping matchers
- //====================================================================================================
- @Test
- public void testOverlappingMatchers1() throws Exception {
- RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
- String r;
- String url = URL + "/testOverlappingMatchers1";
-
- r = client.doGet(url + "?t1=1").getResponseAsString();
- assertEquals("test3a", r);
-
- r = client.doGet(url + "?t2=2").getResponseAsString();
- assertEquals("test3b", r);
-
- r = client.doGet(url).getResponseAsString();
- assertEquals("test3c", r);
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // Overlapping matchers
- //====================================================================================================
- @Test
- public void testOverlappingMatchers2() throws Exception {
- RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
- String r;
- String url = URL + "/testOverlappingMatchers2";
-
- r = client.doGet(url + "?t1=1").getResponseAsString();
- assertEquals("test4b", r);
-
- r = client.doGet(url + "?t2=2").getResponseAsString();
- assertEquals("test4b", r);
-
- r = client.doGet(url + "?t1=1&t2=2").getResponseAsString();
- assertEquals("test4b", r);
-
- r = client.doGet(url + "?tx=x").getResponseAsString();
- assertEquals("test4a", r);
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // Overlapping URL patterns
- //====================================================================================================
- @Test
- public void testOverlappingUrlPatterns() throws Exception {
- RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
- String r;
- String url = URL + "/testOverlappingUrlPatterns";
-
- // [/test5] = [test5a]
- // [/test5/*] = [test5b] -- Cannot get called.
- // [/test5/foo] = [test5c]
- // [/test5/foo/*] = [test5d]
- // [/test5/{id}] = [test5e]
- // [/test5/{id}/*] = [test5f]
- // [/test5/{id}/foo] = [test5g]
- // [/test5/{id}/foo/*] = [test5h]
-
- r = client.doGet(url).getResponseAsString();
- assertEquals("test5a", r);
-
- r = client.doGet(url + "/foo").getResponseAsString();
- assertEquals("test5c", r);
-
- r = client.doGet(url + "/foo/x").getResponseAsString();
- assertEquals("test5d", r);
-
- r = client.doGet(url + "/x").getResponseAsString();
- assertEquals("test5e", r);
-
- r = client.doGet(url + "/x/x").getResponseAsString();
- assertEquals("test5f", r);
-
- r = client.doGet(url + "/x/foo").getResponseAsString();
- assertEquals("test5g", r);
-
- r = client.doGet(url + "/x/foo/x").getResponseAsString();
- assertEquals("test5h", r);
-
- client.closeQuietly();
- }
-}
[03/14] incubator-juneau git commit: Clean up test and test resource
class names.
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestPathsTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestPathsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestPathsTest.java
deleted file mode 100755
index 01f0eef..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestPathsTest.java
+++ /dev/null
@@ -1,1368 +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.server;
-
-import static org.junit.Assert.*;
-
-import org.apache.juneau.*;
-import org.apache.juneau.client.*;
-import org.apache.juneau.json.*;
-import org.junit.*;
-
-public class TestPathsTest {
-
- private static String URL = "/testPaths";
-
- //====================================================================================================
- // Basic tests
- //====================================================================================================
- @Test
- public void testBasic() throws Exception {
- RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
- ObjectMap r;
- String url;
-
- // [/test/testPaths]
- // {
- // pathInfo:null,
- // pathInfoUndecoded:null,
- // pathInfoParts:[],
- // pathRemainder:null,
- // pathRemainderUndecoded:null,
- // requestURI:'/jazz/juneau/test/testPaths',
- // requestParentURI:'/jazz/juneau/test',
- // requestURL:'https://localhost:9443/jazz/juneau/test/testPaths',
- // servletPath:'/juneau/test/testPaths',
- // relativeServletURI:'/jazz/juneau/test/testPaths',
- // pathRemainder2:null
- // }
- url = URL;
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertNull(r.getString("pathInfo"));
- assertNull(r.getString("pathInfoUndecoded"));
- assertEquals("[]", r.getObjectList("pathInfoParts").toString());
- assertNull(r.getString("pathRemainder"));
- assertNull(r.getString("pathRemainderUndecoded"));
- assertNull(r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths"));
- assertTrue(r.getString("requestParentURI").endsWith("/"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
- assertEquals(1, (int)r.getInt("method"));
-
-
- // [/test/testPaths/]
- // {
- // pathInfo: '/',
- // pathInfoUndecoded: '/',
- // pathInfoParts: [
- // ],
- // pathRemainder: '',
- // pathRemainderUndecoded: '',
- // requestURI: '/jazz/juneau/test/testPaths/',
- // requestParentURI: '/jazz/juneau/test',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/',
- // servletPath: '/juneau/test/testPaths',
- // relativeServletURI: '/jazz/juneau/test/testPaths',
- // pathRemainder2: ''
- // }
- url = URL + '/';
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/", r.getString("pathInfo"));
- assertEquals("/", r.getString("pathInfoUndecoded"));
- assertEquals("[]", r.getObjectList("pathInfoParts").toString());
- assertEquals("", r.getString("pathRemainder"));
- assertEquals("", r.getString("pathRemainderUndecoded"));
- assertEquals("", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/"));
- assertTrue(r.getString("requestParentURI").endsWith("/"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
- assertEquals(1, (int)r.getInt("method"));
-
- // [/test/testPaths//]
- // {
- // pathInfo: '//',
- // pathInfoParts: [''],
- // pathRemainder: '/',
- // requestURI: '/jazz/juneau/test/testPaths//',
- // requestParentURI: '/jazz/juneau/test',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths//',
- // servletPath: '/juneau/test/testPaths',
- // relativeServletURI: '/jazz/juneau/test/testPaths',
- // pathRemainder2: '/'
- // }
- url = URL + "//";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("//", r.getString("pathInfo"));
- assertEquals("['']", r.getObjectList("pathInfoParts").toString());
- assertEquals("/", r.getString("pathRemainder"));
- assertEquals("/", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths//"));
- assertTrue(r.getString("requestParentURI").endsWith("/"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths//"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
- assertEquals(1, (int)r.getInt("method"));
-
- // [/test/testPaths///]
- // {
- // pathInfo: '///',
- // pathInfoParts: ['',''],
- // pathRemainder: '//',
- // requestURI: '/jazz/juneau/test/testPaths///',
- // requestParentURI: '/jazz/juneau/test',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths///',
- // servletPath: '/juneau/test/testPaths',
- // relativeServletURI: '/jazz/juneau/test/testPaths',
- // pathRemainder2: '//'
- // }
- url = URL + "///";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("///", r.getString("pathInfo"));
- assertEquals("['','']", r.getObjectList("pathInfoParts").toString());
- assertEquals("//", r.getString("pathRemainder"));
- assertEquals("//", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths///"));
- assertTrue(r.getString("requestParentURI").endsWith("/"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths///"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
- assertEquals(1, (int)r.getInt("method"));
-
- // [/test/testPaths/foo/bar]
- // {
- // pathInfo: '/foo/bar',
- // pathInfoParts: [
- // 'foo',
- // 'bar'
- // ],
- // pathRemainder: 'foo/bar',
- // requestURI: '/jazz/juneau/test/testPaths/foo/bar',
- // requestParentURI: '/jazz/juneau/test/testPaths/foo',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/foo/bar',
- // servletPath: '/juneau/test/testPaths',
- // relativeServletURI: '/jazz/juneau/test/testPaths',
- // pathRemainder2: 'foo/bar'
- // }
- url = URL + "/foo/bar";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/foo/bar", r.getString("pathInfo"));
- assertEquals("['foo','bar']", r.getObjectList("pathInfoParts").toString());
- assertEquals("foo/bar", r.getString("pathRemainder"));
- assertEquals("foo/bar", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/foo/bar"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/foo"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/foo/bar"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
- assertEquals(1, (int)r.getInt("method"));
-
- // [/test/testPaths/foo/bar/]
- // {
- // pathInfo: '/foo/bar/',
- // pathInfoParts: [
- // 'foo',
- // 'bar'
- // ],
- // pathRemainder: 'foo/bar/',
- // requestURI: '/jazz/juneau/test/testPaths/foo/bar/',
- // requestParentURI: '/jazz/juneau/test/testPaths/foo',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/foo/bar/',
- // servletPath: '/juneau/test/testPaths',
- // relativeServletURI: '/jazz/juneau/test/testPaths',
- // pathRemainder2: 'foo/bar/'
- // }
- url = URL + "/foo/bar/";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/foo/bar/", r.getString("pathInfo"));
- assertEquals("['foo','bar']", r.getObjectList("pathInfoParts").toString());
- assertEquals("foo/bar/", r.getString("pathRemainder"));
- assertEquals("foo/bar/", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/foo/bar/"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/foo"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/foo/bar/"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
- assertEquals(1, (int)r.getInt("method"));
-
- // [/test/testPaths//foo//bar//]
- // {
- // pathInfo: '//foo//bar//',
- // pathInfoParts: [
- // '',
- // 'foo',
- // '',
- // 'bar',
- // ''
- // ],
- // pathRemainder: '/foo//bar//',
- // requestURI: '/jazz/juneau/test/testPaths//foo//bar//',
- // requestParentURI: '/jazz/juneau/test/testPaths//foo',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths//foo//bar//',
- // servletPath: '/juneau/test/testPaths',
- // relativeServletURI: '/jazz/juneau/test/testPaths',
- // pathRemainder2: '/foo//bar//'
- // }
- url = URL + "//foo//bar//";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("//foo//bar//", r.getString("pathInfo"));
- assertEquals("['','foo','','bar','']", r.getObjectList("pathInfoParts").toString());
- assertEquals("/foo//bar//", r.getString("pathRemainder"));
- assertEquals("/foo//bar//", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths//foo//bar//"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths//foo/"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths//foo//bar//"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
- assertEquals(1, (int)r.getInt("method"));
-
- // [/test/testPaths/foo%2Fbar]
- // {
- // pathInfo: '/foo//bar',
- // pathInfoUndecoded: '/foo%2F%2Fbar',
- // pathInfoParts: [
- // 'foo//bar'
- // ],
- // pathRemainder: 'foo//bar',
- // pathRemainderUndecoded: 'foo%2F%2Fbar',
- // requestURI: '/jazz/juneau/test/testPaths/foo%2F%2Fbar',
- // requestParentURI: '/jazz/juneau/test/testPaths',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/foo%2F%2Fbar',
- // servletPath: '/juneau/test/testPaths',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test',
- // relativeServletURI: '/jazz/juneau/test/testPaths',
- // pathRemainder2: 'foo//bar',
- // method: 1
- // }
- url = URL + "/foo%2F%2Fbar";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/foo//bar", r.getString("pathInfo"));
- assertEquals("/foo%2F%2Fbar", r.getString("pathInfoUndecoded"));
- assertEquals("['foo//bar']", r.getObjectList("pathInfoParts").toString());
- assertEquals("foo//bar", r.getString("pathRemainder"));
- assertEquals("foo%2F%2Fbar", r.getString("pathRemainderUndecoded"));
- assertEquals("foo//bar", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/foo%2F%2Fbar"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/foo%2F%2Fbar"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
- assertEquals(1, (int)r.getInt("method"));
-
- // [/test/testPaths//foo%2Fbar//]
- // {
- // pathInfo: '//foo//bar//',
- // pathInfoUndecoded: '//foo%2F%2Fbar//',
- // pathInfoParts: [
- // '',
- // 'foo//bar',
- // ''
- // ],
- // pathRemainder: '/foo//bar//',
- // pathRemainderUndecoded: '/foo%2F%2Fbar//',
- // requestURI: '/jazz/juneau/test/testPaths//foo%2F%2Fbar//',
- // requestParentURI: '/jazz/juneau/test/testPaths/',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths//foo%2F%2Fbar//',
- // servletPath: '/juneau/test/testPaths',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test',
- // relativeServletURI: '/jazz/juneau/test/testPaths',
- // pathRemainder2: '/foo//bar//',
- // method: 1
- // }
- url = URL + "//foo%2F%2Fbar//";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("//foo//bar//", r.getString("pathInfo"));
- assertEquals("//foo%2F%2Fbar//", r.getString("pathInfoUndecoded"));
- assertEquals("['','foo//bar','']", r.getObjectList("pathInfoParts").toString());
- assertEquals("/foo//bar//", r.getString("pathRemainder"));
- assertEquals("/foo%2F%2Fbar//", r.getString("pathRemainderUndecoded"));
- assertEquals("/foo//bar//", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths//foo%2F%2Fbar//"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths//foo%2F%2Fbar//"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
- assertEquals(1, (int)r.getInt("method"));
-
- // [/test/testPaths/test2]
- // {
- // pathInfo: '/test2',
- // pathInfoParts: [
- // 'test2'
- // ],
- // pathRemainder: null,
- // requestURI: '/jazz/juneau/test/testPaths/test2',
- // requestParentURI: '/jazz/juneau/test/testPaths',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/test2',
- // servletPath: '/juneau/test/testPaths',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test',
- // relativeServletURI: '/jazz/juneau/test/testPaths',
- // pathRemainder2: null,
- // method: 2
- // }
- url = URL + "/test2";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/test2", r.getString("pathInfo"));
- assertEquals("['test2']", r.getObjectList("pathInfoParts").toString());
- assertNull(r.getString("pathRemainder"));
- assertNull(r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/test2"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/test2"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
- assertEquals(2, (int)r.getInt("method"));
-
-
- // [/test/testPaths/test2/]
- // {
- // pathInfo: '/test2/',
- // pathInfoParts: [
- // 'test2'
- // ],
- // pathRemainder: '',
- // requestURI: '/jazz/juneau/test/testPaths/test2/',
- // requestParentURI: '/jazz/juneau/test/testPaths',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/test2/',
- // servletPath: '/juneau/test/testPaths',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test',
- // relativeServletURI: '/jazz/juneau/test/testPaths',
- // pathRemainder2: '',
- // method: 2
- // }
- url = URL + "/test2/";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/test2/", r.getString("pathInfo"));
- assertEquals("['test2']", r.getObjectList("pathInfoParts").toString());
- assertEquals("", r.getString("pathRemainder"));
- assertEquals("", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/test2/"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/test2/"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
- assertEquals(2, (int)r.getInt("method"));
-
- // [/test/testPaths/test2//]
- // {
- // pathInfo: '/test2//',
- // pathInfoParts: [
- // 'test2',
- // ''
- // ],
- // pathRemainder: '/',
- // requestURI: '/jazz/juneau/test/testPaths/test2//',
- // requestParentURI: '/jazz/juneau/test/testPaths',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/test2//',
- // servletPath: '/juneau/test/testPaths',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test',
- // relativeServletURI: '/jazz/juneau/test/testPaths',
- // pathRemainder2: '/',
- // method: 2
- // }
- url = URL + "/test2//";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/test2//", r.getString("pathInfo"));
- assertEquals("['test2','']", r.getObjectList("pathInfoParts").toString());
- assertEquals("/", r.getString("pathRemainder"));
- assertEquals("/", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/test2//"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/test2//"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
- assertEquals(2, (int)r.getInt("method"));
-
- // [/test/testPaths/test2///]
- // {
- // pathInfo: '/test2///',
- // pathInfoParts: [
- // 'test2',
- // '',
- // ''
- // ],
- // pathRemainder: '//',
- // requestURI: '/jazz/juneau/test/testPaths/test2///',
- // requestParentURI: '/jazz/juneau/test/testPaths',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/test2///',
- // servletPath: '/juneau/test/testPaths',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test',
- // relativeServletURI: '/jazz/juneau/test/testPaths',
- // pathRemainder2: '//',
- // method: 2
- // }
- url = URL + "/test2///";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/test2///", r.getString("pathInfo"));
- assertEquals("['test2','','']", r.getObjectList("pathInfoParts").toString());
- assertEquals("//", r.getString("pathRemainder"));
- assertEquals("//", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/test2///"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/test2///"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
- assertEquals(2, (int)r.getInt("method"));
-
- // [/test/testPaths/test2/foo/bar]
- // {
- // pathInfo: '/test2/foo/bar',
- // pathInfoParts: [
- // 'test2',
- // 'foo',
- // 'bar'
- // ],
- // pathRemainder: 'foo/bar',
- // requestURI: '/jazz/juneau/test/testPaths/test2/foo/bar',
- // requestParentURI: '/jazz/juneau/test/testPaths/test2/foo',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/test2/foo/bar',
- // servletPath: '/juneau/test/testPaths',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test',
- // relativeServletURI: '/jazz/juneau/test/testPaths',
- // pathRemainder2: 'foo/bar',
- // method: 2
- // }
- url = URL + "/test2/foo/bar";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/test2/foo/bar", r.getString("pathInfo"));
- assertEquals("['test2','foo','bar']", r.getObjectList("pathInfoParts").toString());
- assertEquals("foo/bar", r.getString("pathRemainder"));
- assertEquals("foo/bar", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/test2/foo/bar"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/test2/foo"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/test2/foo/bar"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
- assertEquals(2, (int)r.getInt("method"));
-
- // [/test/testPaths/test2/foo/bar/]
- // {
- // pathInfo: '/test2/foo/bar/',
- // pathInfoParts: [
- // 'test2',
- // 'foo',
- // 'bar'
- // ],
- // pathRemainder: 'foo/bar/',
- // requestURI: '/jazz/juneau/test/testPaths/test2/foo/bar/',
- // requestParentURI: '/jazz/juneau/test/testPaths/test2/foo',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/test2/foo/bar/',
- // servletPath: '/juneau/test/testPaths',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test',
- // relativeServletURI: '/jazz/juneau/test/testPaths',
- // pathRemainder2: 'foo/bar/',
- // method: 2
- // }
- url = URL + "/test2/foo/bar/";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/test2/foo/bar/", r.getString("pathInfo"));
- assertEquals("['test2','foo','bar']", r.getObjectList("pathInfoParts").toString());
- assertEquals("foo/bar/", r.getString("pathRemainder"));
- assertEquals("foo/bar/", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/test2/foo/bar/"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/test2/foo"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/test2/foo/bar/"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
- assertEquals(2, (int)r.getInt("method"));
-
- // [/test/testPaths/test2//foo//bar//]
- // {
- // pathInfo: '/test2//foo//bar//',
- // pathInfoParts: [
- // 'test2',
- // '',
- // 'foo',
- // '',
- // 'bar',
- // ''
- // ],
- // pathRemainder: '/foo//bar//',
- // requestURI: '/jazz/juneau/test/testPaths/test2//foo//bar//',
- // requestParentURI: '/jazz/juneau/test/testPaths/test2//foo/',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/test2//foo//bar//',
- // servletPath: '/juneau/test/testPaths',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test',
- // relativeServletURI: '/jazz/juneau/test/testPaths',
- // pathRemainder2: '/foo//bar//',
- // method: 2
- // }
- url = URL + "/test2//foo//bar//";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/test2//foo//bar//", r.getString("pathInfo"));
- assertEquals("['test2','','foo','','bar','']", r.getObjectList("pathInfoParts").toString());
- assertEquals("/foo//bar//", r.getString("pathRemainder"));
- assertEquals("/foo//bar//", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/test2//foo//bar//"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/test2//foo/"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/test2//foo//bar//"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
- assertEquals(2, (int)r.getInt("method"));
-
- // [/test/testPaths/test2/foo%2Fbar]
- // {
- // pathInfo: '/test2/foo//bar',
- // pathInfoUndecoded: '/test2/foo%2F%2Fbar',
- // pathInfoParts: [
- // 'test2',
- // 'foo//bar'
- // ],
- // pathRemainder: 'foo//bar',
- // pathRemainderUndecoded: 'foo%2F%2Fbar',
- // requestURI: '/jazz/juneau/test/testPaths/test2/foo%2F%2Fbar',
- // requestParentURI: '/jazz/juneau/test/testPaths/test2',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/test2/foo%2F%2Fbar',
- // servletPath: '/juneau/test/testPaths',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test',
- // relativeServletURI: '/jazz/juneau/test/testPaths',
- // pathRemainder2: 'foo//bar',
- // method: 2
- // }
- url = URL + "/test2/foo%2F%2Fbar";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/test2/foo//bar", r.getString("pathInfo"));
- assertEquals("/test2/foo%2F%2Fbar", r.getString("pathInfoUndecoded"));
- assertEquals("['test2','foo//bar']", r.getObjectList("pathInfoParts").toString());
- assertEquals("foo//bar", r.getString("pathRemainder"));
- assertEquals("foo%2F%2Fbar", r.getString("pathRemainderUndecoded"));
- assertEquals("foo//bar", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/test2/foo%2F%2Fbar"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/test2"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/test2/foo%2F%2Fbar"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
- assertEquals(2, (int)r.getInt("method"));
-
- // [/test/testPaths/test2//foo%2Fbar//]
- // {
- // pathInfo: '/test2//foo//bar//',
- // pathInfoUndecoded: '/test2//foo%2F%2Fbar//',
- // pathInfoParts: [
- // 'test2',
- // '',
- // 'foo//bar',
- // ''
- // ],
- // pathRemainder: '/foo//bar//',
- // pathRemainderUndecoded: '/foo%2F%2Fbar//',
- // requestURI: '/jazz/juneau/test/testPaths/test2//foo%2F%2Fbar//',
- // requestParentURI: '/jazz/juneau/test/testPaths/test2/',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/test2//foo%2F%2Fbar//',
- // servletPath: '/juneau/test/testPaths',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test',
- // relativeServletURI: '/jazz/juneau/test/testPaths',
- // pathRemainder2: '/foo//bar//',
- // method: 2
- // }
- url = URL + "/test2//foo%2F%2Fbar//";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/test2//foo//bar//", r.getString("pathInfo"));
- assertEquals("/test2//foo%2F%2Fbar//", r.getString("pathInfoUndecoded"));
- assertEquals("['test2','','foo//bar','']", r.getObjectList("pathInfoParts").toString());
- assertEquals("/foo//bar//", r.getString("pathRemainder"));
- assertEquals("/foo%2F%2Fbar//", r.getString("pathRemainderUndecoded"));
- assertEquals("/foo//bar//", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/test2//foo%2F%2Fbar//"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/test2/"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/test2//foo%2F%2Fbar//"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
- assertEquals(2, (int)r.getInt("method"));
-
- // [/test/testPaths/a]
- // {
- // pathInfo: null,
- // pathInfoParts: [
- // ],
- // pathRemainder: null,
- // requestURI: '/jazz/juneau/test/testPaths/a',
- // requestParentURI: '/jazz/juneau/test/testPaths',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
- // servletPath: '/juneau/test/testPaths/a',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // relativeServletURI: '/jazz/juneau/test/testPaths/a',
- // pathRemainder2: null,
- // method: 3
- // }
- url = URL + "/a";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertNull(r.getString("pathInfo"));
- assertEquals("[]", r.getObjectList("pathInfoParts").toString());
- assertNull(r.getString("pathRemainder"));
- assertNull(r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
- assertEquals(3, (int)r.getInt("method"));
-
- // [/test/testPaths/a/]
- // {
- // pathInfo: '/',
- // pathInfoParts: [
- // ],
- // pathRemainder: '',
- // requestURI: '/jazz/juneau/test/testPaths/a/',
- // requestParentURI: '/jazz/juneau/test/testPaths',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a/',
- // servletPath: '/juneau/test/testPaths/a',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // relativeServletURI: '/jazz/juneau/test/testPaths/a',
- // pathRemainder2: '',
- // method: 3
- // }
- url = URL + "/a/";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/", r.getString("pathInfo"));
- assertEquals("[]", r.getObjectList("pathInfoParts").toString());
- assertEquals("", r.getString("pathRemainder"));
- assertEquals("", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/a/"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/a/"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
- assertEquals(3, (int)r.getInt("method"));
-
- // [/test/testPaths/a//]
- // {
- // pathInfo: '//',
- // pathInfoParts: [
- // ''
- // ],
- // pathRemainder: '/',
- // requestURI: '/jazz/juneau/test/testPaths/a//',
- // requestParentURI: '/jazz/juneau/test/testPaths',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a//',
- // servletPath: '/juneau/test/testPaths/a',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // relativeServletURI: '/jazz/juneau/test/testPaths/a',
- // pathRemainder2: '/',
- // method: 3
- // }
- url = URL + "/a//";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("//", r.getString("pathInfo"));
- assertEquals("['']", r.getObjectList("pathInfoParts").toString());
- assertEquals("/", r.getString("pathRemainder"));
- assertEquals("/", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/a//"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/a//"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
- assertEquals(3, (int)r.getInt("method"));
-
- // [/test/testPaths/a///]
- // {
- // pathInfo: '///',
- // pathInfoParts: [
- // '',
- // ''
- // ],
- // pathRemainder: '//',
- // requestURI: '/jazz/juneau/test/testPaths/a///',
- // requestParentURI: '/jazz/juneau/test/testPaths',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a///',
- // servletPath: '/juneau/test/testPaths/a',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // relativeServletURI: '/jazz/juneau/test/testPaths/a',
- // pathRemainder2: '//',
- // method: 3
- // }
- url = URL + "/a///";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("///", r.getString("pathInfo"));
- assertEquals("['','']", r.getObjectList("pathInfoParts").toString());
- assertEquals("//", r.getString("pathRemainder"));
- assertEquals("//", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/a///"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/a///"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
- assertEquals(3, (int)r.getInt("method"));
-
- // [/test/testPaths/a/foo/bar]
- // {
- // pathInfo: '/foo/bar',
- // pathInfoParts: [
- // 'foo',
- // 'bar'
- // ],
- // pathRemainder: 'foo/bar',
- // requestURI: '/jazz/juneau/test/testPaths/a/foo/bar',
- // requestParentURI: '/jazz/juneau/test/testPaths/a/foo',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a/foo/bar',
- // servletPath: '/juneau/test/testPaths/a',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // relativeServletURI: '/jazz/juneau/test/testPaths/a',
- // pathRemainder2: 'foo/bar',
- // method: 3
- // }
- url = URL + "/a/foo/bar";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/foo/bar", r.getString("pathInfo"));
- assertEquals("['foo','bar']", r.getObjectList("pathInfoParts").toString());
- assertEquals("foo/bar", r.getString("pathRemainder"));
- assertEquals("foo/bar", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/a/foo/bar"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a/foo"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/a/foo/bar"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
- assertEquals(3, (int)r.getInt("method"));
-
- // [/test/testPaths/a/foo/bar/]
- // {
- // pathInfo: '/foo/bar/',
- // pathInfoParts: [
- // 'foo',
- // 'bar'
- // ],
- // pathRemainder: 'foo/bar/',
- // requestURI: '/jazz/juneau/test/testPaths/a/foo/bar/',
- // requestParentURI: '/jazz/juneau/test/testPaths/a/foo',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a/foo/bar/',
- // servletPath: '/juneau/test/testPaths/a',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // relativeServletURI: '/jazz/juneau/test/testPaths/a',
- // pathRemainder2: 'foo/bar/',
- // method: 3
- // }
- url = URL + "/a/foo/bar/";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/foo/bar/", r.getString("pathInfo"));
- assertEquals("['foo','bar']", r.getObjectList("pathInfoParts").toString());
- assertEquals("foo/bar/", r.getString("pathRemainder"));
- assertEquals("foo/bar/", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/a/foo/bar/"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a/foo"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/a/foo/bar/"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
- assertEquals(3, (int)r.getInt("method"));
-
- // [/test/testPaths/a//foo//bar//]
- // {
- // pathInfo: '//foo//bar//',
- // pathInfoParts: [
- // '',
- // 'foo',
- // '',
- // 'bar',
- // ''
- // ],
- // pathRemainder: '/foo//bar//',
- // requestURI: '/jazz/juneau/test/testPaths/a//foo//bar//',
- // requestParentURI: '/jazz/juneau/test/testPaths/a//foo/',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a//foo//bar//',
- // servletPath: '/juneau/test/testPaths/a',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // relativeServletURI: '/jazz/juneau/test/testPaths/a',
- // pathRemainder2: '/foo//bar//',
- // method: 3
- // }
- url = URL + "/a//foo//bar//";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("//foo//bar//", r.getString("pathInfo"));
- assertEquals("['','foo','','bar','']", r.getObjectList("pathInfoParts").toString());
- assertEquals("/foo//bar//", r.getString("pathRemainder"));
- assertEquals("/foo//bar//", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/a//foo//bar//"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a//foo/"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/a//foo//bar//"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
- assertEquals(3, (int)r.getInt("method"));
-
- // [/test/testPaths/a/foo%2Fbar]
- // {
- // pathInfo: '/foo//bar',
- // pathInfoUndecoded: '/foo%2F%2Fbar',
- // pathInfoParts: [
- // 'foo//bar'
- // ],
- // pathRemainder: 'foo//bar',
- // pathRemainderUndecoded: 'foo%2F%2Fbar',
- // requestURI: '/jazz/juneau/test/testPaths/a/foo%2F%2Fbar',
- // requestParentURI: '/jazz/juneau/test/testPaths/a',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a/foo%2F%2Fbar',
- // servletPath: '/juneau/test/testPaths/a',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // relativeServletURI: '/jazz/juneau/test/testPaths/a',
- // pathRemainder2: 'foo//bar',
- // method: 3
- // }
- url = URL + "/a/foo%2F%2Fbar";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/foo//bar", r.getString("pathInfo"));
- assertEquals("/foo%2F%2Fbar", r.getString("pathInfoUndecoded"));
- assertEquals("['foo//bar']", r.getObjectList("pathInfoParts").toString());
- assertEquals("foo//bar", r.getString("pathRemainder"));
- assertEquals("foo%2F%2Fbar", r.getString("pathRemainderUndecoded"));
- assertEquals("foo//bar", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/a/foo%2F%2Fbar"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/a/foo%2F%2Fbar"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
- assertEquals(3, (int)r.getInt("method"));
-
- // [/test/testPaths/a//foo%2Fbar//]
- // {
- // pathInfo: '//foo//bar//',
- // pathInfoUndecoded: '//foo%2F%2Fbar//',
- // pathInfoParts: [
- // '',
- // 'foo//bar',
- // ''
- // ],
- // pathRemainder: '/foo//bar//',
- // pathRemainderUndecoded: '/foo%2F%2Fbar//',
- // requestURI: '/jazz/juneau/test/testPaths/a//foo%2F%2Fbar//',
- // requestParentURI: '/jazz/juneau/test/testPaths/a/',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a//foo%2F%2Fbar//',
- // servletPath: '/juneau/test/testPaths/a',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // relativeServletURI: '/jazz/juneau/test/testPaths/a',
- // pathRemainder2: '/foo//bar//',
- // method: 3
- // }
- url = URL + "/a//foo%2F%2Fbar//";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("//foo//bar//", r.getString("pathInfo"));
- assertEquals("//foo%2F%2Fbar//", r.getString("pathInfoUndecoded"));
- assertEquals("['','foo//bar','']", r.getObjectList("pathInfoParts").toString());
- assertEquals("/foo//bar//", r.getString("pathRemainder"));
- assertEquals("/foo%2F%2Fbar//", r.getString("pathRemainderUndecoded"));
- assertEquals("/foo//bar//", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/a//foo%2F%2Fbar//"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a/"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/a//foo%2F%2Fbar//"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
- assertEquals(3, (int)r.getInt("method"));
-
-
- // [/test/testPaths/a/test2]
- // {
- // pathInfo: '/test2',
- // pathInfoParts: [
- // 'test2'
- // ],
- // pathRemainder: null,
- // requestURI: '/jazz/juneau/test/testPaths/a/test2',
- // requestParentURI: '/jazz/juneau/test/testPaths/a',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a/test2',
- // servletPath: '/juneau/test/testPaths/a',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // relativeServletURI: '/jazz/juneau/test/testPaths/a',
- // pathRemainder2: null,
- // method: 4
- // }
- url = URL + "/a/test2";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/test2", r.getString("pathInfo"));
- assertEquals("['test2']", r.getObjectList("pathInfoParts").toString());
- assertNull(r.getString("pathRemainder"));
- assertNull(r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/a/test2"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/a/test2"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
- assertEquals(4, (int)r.getInt("method"));
-
- // [/test/testPaths/a/test2/]
- // {
- // pathInfo: '/test2/',
- // pathInfoParts: [
- // 'test2'
- // ],
- // pathRemainder: '',
- // requestURI: '/jazz/juneau/test/testPaths/a/test2/',
- // requestParentURI: '/jazz/juneau/test/testPaths/a',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a/test2/',
- // servletPath: '/juneau/test/testPaths/a',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // relativeServletURI: '/jazz/juneau/test/testPaths/a',
- // pathRemainder2: '',
- // method: 4
- // }
- url = URL + "/a/test2/";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/test2/", r.getString("pathInfo"));
- assertEquals("['test2']", r.getObjectList("pathInfoParts").toString());
- assertEquals("", r.getString("pathRemainder"));
- assertEquals("", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/a/test2/"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/a/test2/"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
- assertEquals(4, (int)r.getInt("method"));
-
- // [/test/testPaths/a/test2//]
- // {
- // pathInfo: '/test2//',
- // pathInfoParts: [
- // 'test2',
- // ''
- // ],
- // pathRemainder: '/',
- // requestURI: '/jazz/juneau/test/testPaths/a/test2//',
- // requestParentURI: '/jazz/juneau/test/testPaths/a',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a/test2//',
- // servletPath: '/juneau/test/testPaths/a',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // relativeServletURI: '/jazz/juneau/test/testPaths/a',
- // pathRemainder2: '/',
- // method: 4
- // }
- url = URL + "/a/test2//";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/test2//", r.getString("pathInfo"));
- assertEquals("['test2','']", r.getObjectList("pathInfoParts").toString());
- assertEquals("/", r.getString("pathRemainder"));
- assertEquals("/", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/a/test2//"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/a/test2//"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
- assertEquals(4, (int)r.getInt("method"));
-
- // [/test/testPaths/a/test2///]
- // {
- // pathInfo: '/test2///',
- // pathInfoParts: [
- // 'test2',
- // '',
- // ''
- // ],
- // pathRemainder: '//',
- // requestURI: '/jazz/juneau/test/testPaths/a/test2///',
- // requestParentURI: '/jazz/juneau/test/testPaths/a',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a/test2///',
- // servletPath: '/juneau/test/testPaths/a',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // relativeServletURI: '/jazz/juneau/test/testPaths/a',
- // pathRemainder2: '//',
- // method: 4
- // }
- url = URL + "/a/test2///";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/test2///", r.getString("pathInfo"));
- assertEquals("['test2','','']", r.getObjectList("pathInfoParts").toString());
- assertEquals("//", r.getString("pathRemainder"));
- assertEquals("//", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/a/test2///"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/a/test2///"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
- assertEquals(4, (int)r.getInt("method"));
-
- // [/test/testPaths/a/test2/foo/bar]
- // {
- // pathInfo: '/test2/foo/bar',
- // pathInfoParts: [
- // 'test2',
- // 'foo',
- // 'bar'
- // ],
- // pathRemainder: 'foo/bar',
- // requestURI: '/jazz/juneau/test/testPaths/a/test2/foo/bar',
- // requestParentURI: '/jazz/juneau/test/testPaths/a/test2/foo',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a/test2/foo/bar',
- // servletPath: '/juneau/test/testPaths/a',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // relativeServletURI: '/jazz/juneau/test/testPaths/a',
- // pathRemainder2: 'foo/bar',
- // method: 4
- // }
- url = URL + "/a/test2/foo/bar";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/test2/foo/bar", r.getString("pathInfo"));
- assertEquals("['test2','foo','bar']", r.getObjectList("pathInfoParts").toString());
- assertEquals("foo/bar", r.getString("pathRemainder"));
- assertEquals("foo/bar", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/a/test2/foo/bar"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a/test2/foo"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/a/test2/foo/bar"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
- assertEquals(4, (int)r.getInt("method"));
-
- // [/test/testPaths/a/test2/foo/bar/]
- // {
- // pathInfo: '/test2/foo/bar/',
- // pathInfoParts: [
- // 'test2',
- // 'foo',
- // 'bar'
- // ],
- // pathRemainder: 'foo/bar/',
- // requestURI: '/jazz/juneau/test/testPaths/a/test2/foo/bar/',
- // requestParentURI: '/jazz/juneau/test/testPaths/a/test2/foo',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a/test2/foo/bar/',
- // servletPath: '/juneau/test/testPaths/a',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // relativeServletURI: '/jazz/juneau/test/testPaths/a',
- // pathRemainder2: 'foo/bar/',
- // method: 4
- // }
- url = URL + "/a/test2/foo/bar/";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/test2/foo/bar/", r.getString("pathInfo"));
- assertEquals("['test2','foo','bar']", r.getObjectList("pathInfoParts").toString());
- assertEquals("foo/bar/", r.getString("pathRemainder"));
- assertEquals("foo/bar/", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/a/test2/foo/bar/"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a/test2/foo"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/a/test2/foo/bar/"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
- assertEquals(4, (int)r.getInt("method"));
-
- // [/test/testPaths/a/test2//foo//bar//]
- // {
- // pathInfo: '/test2//foo//bar//',
- // pathInfoParts: [
- // 'test2',
- // '',
- // 'foo',
- // '',
- // 'bar',
- // ''
- // ],
- // pathRemainder: '/foo//bar//',
- // requestURI: '/jazz/juneau/test/testPaths/a/test2//foo//bar//',
- // requestParentURI: '/jazz/juneau/test/testPaths/a/test2//foo/',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a/test2//foo//bar//',
- // servletPath: '/juneau/test/testPaths/a',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // relativeServletURI: '/jazz/juneau/test/testPaths/a',
- // pathRemainder2: '/foo//bar//',
- // method: 4
- // }
- url = URL + "/a/test2//foo//bar//";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/test2//foo//bar//", r.getString("pathInfo"));
- assertEquals("['test2','','foo','','bar','']", r.getObjectList("pathInfoParts").toString());
- assertEquals("/foo//bar//", r.getString("pathRemainder"));
- assertEquals("/foo//bar//", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/a/test2//foo//bar//"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a/test2//foo/"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/a/test2//foo//bar//"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
- assertEquals(4, (int)r.getInt("method"));
-
- // [/test/testPaths/a/test2/foo%2Fbar]
- // {
- // pathInfo: '/test2/foo//bar',
- // pathInfoUndecoded: '/test2/foo%2F%2Fbar',
- // pathInfoParts: [
- // 'test2',
- // 'foo//bar'
- // ],
- // pathRemainder: 'foo//bar',
- // pathRemainderUndecoded: 'foo%2F%2Fbar',
- // requestURI: '/jazz/juneau/test/testPaths/a/test2/foo%2F%2Fbar',
- // requestParentURI: '/jazz/juneau/test/testPaths/a/test2',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a/test2/foo%2F%2Fbar',
- // servletPath: '/juneau/test/testPaths/a',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // relativeServletURI: '/jazz/juneau/test/testPaths/a',
- // pathRemainder2: 'foo//bar',
- // method: 4
- // }
- url = URL + "/a/test2/foo%2F%2Fbar";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/test2/foo//bar", r.getString("pathInfo"));
- assertEquals("/test2/foo%2F%2Fbar", r.getString("pathInfoUndecoded"));
- assertEquals("['test2','foo//bar']", r.getObjectList("pathInfoParts").toString());
- assertEquals("foo//bar", r.getString("pathRemainder"));
- assertEquals("foo%2F%2Fbar", r.getString("pathRemainderUndecoded"));
- assertEquals("foo//bar", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/a/test2/foo%2F%2Fbar"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a/test2"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/a/test2/foo%2F%2Fbar"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
- assertEquals(4, (int)r.getInt("method"));
-
- // [/test/testPaths/a/test2//foo%2Fbar//]
- // {
- // pathInfo: '/test2//foo//bar//',
- // pathInfoUndecoded: '/test2//foo%2F%2Fbar//',
- // pathInfoParts: [
- // 'test2',
- // '',
- // 'foo//bar',
- // ''
- // ],
- // pathRemainder: '/foo//bar//',
- // pathRemainderUndecoded: '/foo%2F%2Fbar//',
- // requestURI: '/jazz/juneau/test/testPaths/a/test2//foo%2F%2Fbar//',
- // requestParentURI: '/jazz/juneau/test/testPaths/a/test2/',
- // requestURL: 'https://localhost:9443/jazz/juneau/test/testPaths/a/test2//foo%2F%2Fbar//',
- // servletPath: '/juneau/test/testPaths/a',
- // servletURI: 'https://localhost:9443/jazz/juneau/test/testPaths/a',
- // servletParentURI: 'https://localhost:9443/jazz/juneau/test/testPaths',
- // relativeServletURI: '/jazz/juneau/test/testPaths/a',
- // pathRemainder2: '/foo//bar//',
- // method: 4
- // }
- url = URL + "/a/test2//foo%2F%2Fbar//";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/test2//foo//bar//", r.getString("pathInfo"));
- assertEquals("/test2//foo%2F%2Fbar//", r.getString("pathInfoUndecoded"));
- assertEquals("['test2','','foo//bar','']", r.getObjectList("pathInfoParts").toString());
- assertEquals("/foo//bar//", r.getString("pathRemainder"));
- assertEquals("/foo%2F%2Fbar//", r.getString("pathRemainderUndecoded"));
- assertEquals("/foo//bar//", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/a/test2//foo%2F%2Fbar//"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a/test2/"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/a/test2//foo%2F%2Fbar//"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
- assertEquals(4, (int)r.getInt("method"));
-
- //--------------------------------------------------------------------------------
- // Spaces
- //--------------------------------------------------------------------------------
- url = URL + "/%20";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/ ", r.getString("pathInfo"));
- assertEquals("/%20", r.getString("pathInfoUndecoded"));
- assertEquals("[' ']", r.getObjectList("pathInfoParts").toString());
- assertEquals(" ", r.getString("pathRemainder"));
- assertEquals("%20", r.getString("pathRemainderUndecoded"));
- assertEquals(" ", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/%20"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/%20"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
- assertEquals(1, (int)r.getInt("method"));
-
- url = URL + "/test2/%20";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/test2/ ", r.getString("pathInfo"));
- assertEquals("/test2/%20", r.getString("pathInfoUndecoded"));
- assertEquals("['test2',' ']", r.getObjectList("pathInfoParts").toString());
- assertEquals(" ", r.getString("pathRemainder"));
- assertEquals("%20", r.getString("pathRemainderUndecoded"));
- assertEquals(" ", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/test2/%20"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/test2"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/test2/%20"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
- assertEquals(2, (int)r.getInt("method"));
-
- url = URL + "/a/%20";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/ ", r.getString("pathInfo"));
- assertEquals("/%20", r.getString("pathInfoUndecoded"));
- assertEquals("[' ']", r.getObjectList("pathInfoParts").toString());
- assertEquals(" ", r.getString("pathRemainder"));
- assertEquals("%20", r.getString("pathRemainderUndecoded"));
- assertEquals(" ", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/a/%20"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/a/%20"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
- assertEquals(3, (int)r.getInt("method"));
-
- url = URL + "/a/test2/%20";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/test2/ ", r.getString("pathInfo"));
- assertEquals("/test2/%20", r.getString("pathInfoUndecoded"));
- assertEquals("['test2',' ']", r.getObjectList("pathInfoParts").toString());
- assertEquals(" ", r.getString("pathRemainder"));
- assertEquals("%20", r.getString("pathRemainderUndecoded"));
- assertEquals(" ", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/a/test2/%20"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a/test2"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/a/test2/%20"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
- assertEquals(4, (int)r.getInt("method"));
-
- url = URL + "/+";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/ ", r.getString("pathInfo"));
- assertEquals("/+", r.getString("pathInfoUndecoded"));
- assertEquals("[' ']", r.getObjectList("pathInfoParts").toString());
- assertEquals(" ", r.getString("pathRemainder"));
- assertEquals("+", r.getString("pathRemainderUndecoded"));
- assertEquals(" ", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/+"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/+"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
- assertEquals(1, (int)r.getInt("method"));
-
- url = URL + "/test2/+";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/test2/ ", r.getString("pathInfo"));
- assertEquals("/test2/+", r.getString("pathInfoUndecoded"));
- assertEquals("['test2',' ']", r.getObjectList("pathInfoParts").toString());
- assertEquals(" ", r.getString("pathRemainder"));
- assertEquals("+", r.getString("pathRemainderUndecoded"));
- assertEquals(" ", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/test2/+"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/test2"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/test2/+"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths"));
- assertEquals(2, (int)r.getInt("method"));
-
- url = URL + "/a/+";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/ ", r.getString("pathInfo"));
- assertEquals("/+", r.getString("pathInfoUndecoded"));
- assertEquals("[' ']", r.getObjectList("pathInfoParts").toString());
- assertEquals(" ", r.getString("pathRemainder"));
- assertEquals("+", r.getString("pathRemainderUndecoded"));
- assertEquals(" ", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/a/+"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/a/+"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
- assertEquals(3, (int)r.getInt("method"));
-
- url = URL + "/a/test2/+";
- r = client.doGet(url).getResponse(ObjectMap.class);
- assertEquals("/test2/ ", r.getString("pathInfo"));
- assertEquals("/test2/+", r.getString("pathInfoUndecoded"));
- assertEquals("['test2',' ']", r.getObjectList("pathInfoParts").toString());
- assertEquals(" ", r.getString("pathRemainder"));
- assertEquals("+", r.getString("pathRemainderUndecoded"));
- assertEquals(" ", r.getString("pathRemainder2"));
- assertTrue(r.getString("requestURI").endsWith("/testPaths/a/test2/+"));
- assertTrue(r.getString("requestParentURI").endsWith("/testPaths/a/test2"));
- assertTrue(r.getString("requestURL").endsWith("/testPaths/a/test2/+"));
- assertTrue(r.getString("servletPath").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletURI").endsWith("/testPaths/a"));
- assertTrue(r.getString("servletParentURI").endsWith("/testPaths"));
- assertTrue(r.getString("relativeServletURI").endsWith("/testPaths/a"));
- assertEquals(4, (int)r.getInt("method"));
-
- client.closeQuietly();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestPropertiesTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestPropertiesTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestPropertiesTest.java
deleted file mode 100755
index 4ed0a7b..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestPropertiesTest.java
+++ /dev/null
@@ -1,48 +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.server;
-
-import static org.junit.Assert.*;
-
-import org.apache.juneau.client.*;
-import org.apache.juneau.json.*;
-import org.junit.*;
-
-public class TestPropertiesTest {
-
- private static String URL = "/testProperties";
-
- //====================================================================================================
- // Properties defined on method.
- //====================================================================================================
- @Test
- public void testPropertiesDefinedOnMethod() throws Exception {
- RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
- String r = client.doGet(URL + "/testPropertiesDefinedOnMethod").getResponseAsString();
- assertTrue(r.matches("A1=a1,A2=c,B1=b1,B2=c,C=c,R1a=.*/testProperties/testPropertiesDefinedOnMethod,R1b=.*/testProperties,R2=bar,R3=baz,R4=a1,R5=c,R6=c"));
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // Make sure attributes/parameters/headers are available through ctx.getProperties().
- //====================================================================================================
- @Test
- public void testProperties() throws Exception {
- RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
- String r = client.doGet(URL + "/testProperties/a1?P=p1").setHeader("H", "h1").getResponseAsString();
- assertEquals("A=a1,P=p1,H=h1", r);
-
- client.closeQuietly();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestRestClientTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestRestClientTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestRestClientTest.java
deleted file mode 100755
index ed53dbb..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestRestClientTest.java
+++ /dev/null
@@ -1,199 +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.server;
-
-import static org.apache.juneau.server.TestUtils.*;
-import static org.junit.Assert.*;
-
-import java.util.*;
-import java.util.regex.*;
-
-import org.apache.http.entity.*;
-import org.apache.juneau.client.*;
-import org.apache.juneau.json.*;
-import org.junit.*;
-
-public class TestRestClientTest {
-
- private static String URL = "/testRestClient";
-
- //====================================================================================================
- // successPattern()
- //====================================================================================================
- @Test
- public void testSuccessPattern() throws Exception {
- RestClient c = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
- String r;
- int rc;
-
- r = c.doPost(URL, new StringEntity("xxxSUCCESSxxx")).successPattern("SUCCESS").getResponseAsString();
- assertEquals("xxxSUCCESSxxx", r);
- rc = c.doPost(URL, new StringEntity("xxxSUCCESSxxx")).successPattern("SUCCESS").run();
- assertEquals(200, rc);
-
- try {
- r = c.doPost(URL, new StringEntity("xxxFAILURExxx")).successPattern("SUCCESS").getResponseAsString();
- fail();
- } catch (RestCallException e) {
- assertEquals("Success pattern not detected.", e.getLocalizedMessage());
- }
-
- c.closeQuietly();
- }
-
- //====================================================================================================
- // failurePattern()
- //====================================================================================================
- @Test
- public void testFailurePattern() throws Exception {
- RestClient c = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
- String r;
- int rc;
-
- r = c.doPost(URL, new StringEntity("xxxSUCCESSxxx")).failurePattern("FAILURE").getResponseAsString();
- assertEquals("xxxSUCCESSxxx", r);
- rc = c.doPost(URL, new StringEntity("xxxSUCCESSxxx")).failurePattern("FAILURE").run();
- assertEquals(200, rc);
-
- try {
- r = c.doPost(URL, new StringEntity("xxxFAILURExxx")).failurePattern("FAILURE").getResponseAsString();
- fail();
- } catch (RestCallException e) {
- assertEquals("Failure pattern detected.", e.getLocalizedMessage());
- }
-
- try {
- r = c.doPost(URL, new StringEntity("xxxERRORxxx")).failurePattern("FAILURE|ERROR").getResponseAsString();
- fail();
- } catch (RestCallException e) {
- assertEquals("Failure pattern detected.", e.getLocalizedMessage());
- }
-
- c.closeQuietly();
- }
-
- //====================================================================================================
- // captureResponse()/getCapturedResponse()
- //====================================================================================================
- @Test
- public void testCaptureResponse() throws Exception {
- RestClient c = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
- RestCall rc = c.doPost(URL, new StringEntity("xxx")).captureResponse();
-
- try {
- rc.getCapturedResponse();
- fail();
- } catch (IllegalStateException e) {
- assertEquals("This method cannot be called until the response has been consumed.", e.getLocalizedMessage());
- }
- rc.run();
- assertEquals("xxx", rc.getCapturedResponse());
- assertEquals("xxx", rc.getCapturedResponse());
-
- rc = c.doPost(URL, new StringEntity("xxx")).captureResponse();
- assertEquals("xxx", rc.getResponseAsString());
- assertEquals("xxx", rc.getCapturedResponse());
- assertEquals("xxx", rc.getCapturedResponse());
-
- try {
- rc.getResponseAsString();
- fail();
- } catch (IllegalStateException e) {
- assertEquals("Method cannot be called. Response has already been consumed.", e.getLocalizedMessage());
- }
-
- c.closeQuietly();
- }
-
- //====================================================================================================
- // addResponsePattern()
- //====================================================================================================
- @Test
- public void testAddResponsePattern() throws Exception {
- RestClient c = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
- String r;
-
- final List<String> l = new ArrayList<String>();
- ResponsePattern p = new ResponsePattern("x=(\\d+),y=(\\S+)") {
- @Override
- public void onMatch(RestCall restCall, Matcher m) throws RestCallException {
- l.add(m.group(1)+'/'+m.group(2));
- }
- @Override
- public void onNoMatch(RestCall restCall) throws RestCallException {
- throw new RestCallException("Pattern not found!");
- }
- };
-
- r = c.doPost(URL, new StringEntity("x=1,y=2")).addResponsePattern(p).getResponseAsString();
- assertEquals("x=1,y=2", r);
- assertObjectEquals("['1/2']", l);
-
- l.clear();
-
- r = c.doPost(URL, new StringEntity("x=1,y=2\nx=3,y=4")).addResponsePattern(p).getResponseAsString();
- assertEquals("x=1,y=2\nx=3,y=4", r);
- assertObjectEquals("['1/2','3/4']", l);
-
- try {
- c.doPost(URL, new StringEntity("x=1")).addResponsePattern(p).run();
- fail();
- } catch (RestCallException e) {
- assertEquals("Pattern not found!", e.getLocalizedMessage());
- assertEquals(0, e.getResponseCode());
- }
-
- // Two patterns!
- ResponsePattern p1 = new ResponsePattern("x=(\\d+)") {
- @Override
- public void onMatch(RestCall restCall, Matcher m) throws RestCallException {
- l.add("x="+m.group(1));
- }
- @Override
- public void onNoMatch(RestCall restCall) throws RestCallException {
- throw new RestCallException("Pattern x not found!");
- }
- };
- ResponsePattern p2 = new ResponsePattern("y=(\\S+)") {
- @Override
- public void onMatch(RestCall restCall, Matcher m) throws RestCallException {
- l.add("y="+m.group(1));
- }
- @Override
- public void onNoMatch(RestCall restCall) throws RestCallException {
- throw new RestCallException("Pattern y not found!");
- }
- };
-
- l.clear();
- r = c.doPost(URL, new StringEntity("x=1,y=2\nx=3,y=4")).addResponsePattern(p1).addResponsePattern(p2).getResponseAsString();
- assertEquals("x=1,y=2\nx=3,y=4", r);
- assertObjectEquals("['x=1','x=3','y=2','y=4']", l);
-
- try {
- c.doPost(URL, new StringEntity("x=1\nx=3")).addResponsePattern(p1).addResponsePattern(p2).getResponseAsString();
- } catch (RestCallException e) {
- assertEquals("Pattern y not found!", e.getLocalizedMessage());
- assertEquals(0, e.getResponseCode());
- }
-
- try {
- c.doPost(URL, new StringEntity("y=1\ny=3")).addResponsePattern(p1).addResponsePattern(p2).getResponseAsString();
- } catch (RestCallException e) {
- assertEquals("Pattern x not found!", e.getLocalizedMessage());
- assertEquals(0, e.getResponseCode());
- }
-
- c.closeQuietly();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestSerializersTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestSerializersTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestSerializersTest.java
deleted file mode 100755
index 5a478b9..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestSerializersTest.java
+++ /dev/null
@@ -1,152 +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.server;
-
-import static javax.servlet.http.HttpServletResponse.*;
-import static org.apache.juneau.server.TestUtils.*;
-import static org.junit.Assert.*;
-
-import org.apache.juneau.client.*;
-import org.apache.juneau.json.*;
-import org.junit.*;
-
-public class TestSerializersTest {
-
- private static String URL = "/testSerializers";
- 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();
- }
-
- //====================================================================================================
- // Serializer defined on class.
- //====================================================================================================
- @Test
- public void testSerializerOnClass() throws Exception {
- String url = URL + "/testSerializerOnClass";
-
- client.setAccept("text/a");
- String r = client.doGet(url).getResponseAsString();
- assertEquals("text/a - test1", r);
-
- try {
- client.setAccept("text/b");
- 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': 'text/b'",
- "Supported media-types: [text/a, ");
- }
-
- client.setAccept("text/json");
- r = client.doGet(url).getResponseAsString();
- assertEquals("\"test1\"", r);
- }
-
- //====================================================================================================
- // Serializer defined on method.
- //====================================================================================================
- @Test
- public void testSerializerOnMethod() throws Exception {
- String url = URL + "/testSerializerOnMethod";
-
- try {
- client.setAccept("text/a");
- 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': 'text/a'",
- "Supported media-types: [text/b]"
- );
- }
-
- try {
- client.setAccept("text/json");
- 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': 'text/json'",
- "Supported media-types: [text/b]"
- );
- }
- }
-
- //====================================================================================================
- // Serializer overridden on method.
- //====================================================================================================
- @Test
- public void testSerializerOverriddenOnMethod() throws Exception {
- String url = URL + "/testSerializerOverriddenOnMethod";
-
- client.setAccept("text/a");
- String r = client.doGet(url).getResponseAsString();
- assertEquals("text/c - test3", r);
-
- client.setAccept("text/b");
- r = client.doGet(url).getResponseAsString();
- assertEquals("text/b - test3", r);
-
- client.setAccept("text/json");
- r = client.doGet(url).getResponseAsString();
- assertEquals("\"test3\"", r);
- }
-
- //====================================================================================================
- // Serializer with different Accept than Content-Type.
- //====================================================================================================
- @Test
- public void testSerializerWithDifferentMediaTypes() throws Exception {
- String url = URL + "/testSerializerWithDifferentMediaTypes";
-
- client.setAccept("text/a");
- String r = client.doGet(url).getResponseAsString();
- assertEquals("text/d - test4", r);
-
- client.setAccept("text/d");
- r = client.doGet(url).getResponseAsString();
- assertEquals("text/d - test4", r);
-
- client.setAccept("text/json");
- r = client.doGet(url).getResponseAsString();
- assertEquals("\"test4\"", r);
- }
-
- //====================================================================================================
- // Check for valid 406 error response.
- //====================================================================================================
- @Test
- public void test406() throws Exception {
- String url = URL + "/test406";
-
- try {
- client.setAccept("text/bad");
- 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': 'text/bad'",
- "Supported media-types: [text/a");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestStaticFilesTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestStaticFilesTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestStaticFilesTest.java
deleted file mode 100755
index c605122..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestStaticFilesTest.java
+++ /dev/null
@@ -1,56 +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.server;
-
-import static org.junit.Assert.*;
-
-import org.apache.juneau.client.*;
-import org.apache.juneau.plaintext.*;
-import org.junit.*;
-
-public class TestStaticFilesTest {
-
- private static String URL = "/testStaticFiles";
-
- //====================================================================================================
- // Tests the @RestResource(staticFiles) annotation.
- //====================================================================================================
- @Test
- public void testXdocs() throws Exception {
- RestClient client = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class);
- String r;
- String url = URL + "/xdocs";
-
- r = client.doGet(url + "/test.txt").getResponseAsString();
- assertEquals("OK-1", r);
- r = client.doGet(url + "/xdocs/test.txt").getResponseAsString();
- assertEquals("OK-2", r);
-
- // For security reasons, paths containing ".." should always return 404.
- try {
- client.doGet(url + "/xdocs/../test.txt?noTrace=true").connect();
- fail("404 exception expected");
- } catch (RestCallException e) {
- assertEquals(404, e.getResponseCode());
- }
-
- try {
- client.doGet(url + "/xdocs/%2E%2E/test.txt?noTrace=true").connect();
- fail("404 exception expected");
- } catch (RestCallException e) {
- assertEquals(404, e.getResponseCode());
- }
-
- client.closeQuietly();
- }
-}
[14/14] incubator-juneau git commit: Clean up test and test resource
class names.
Posted by ja...@apache.org.
Clean up test and test resource class names.
Project: http://git-wip-us.apache.org/repos/asf/incubator-juneau/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-juneau/commit/bea31abd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-juneau/tree/bea31abd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-juneau/diff/bea31abd
Branch: refs/heads/master
Commit: bea31abd8960a3f3d6574084228279921be1688b
Parents: 7b87347
Author: jamesbognar <ja...@gmail.com>
Authored: Sat Aug 27 15:48:43 2016 -0400
Committer: jamesbognar <ja...@gmail.com>
Committed: Sat Aug 27 15:48:43 2016 -0400
----------------------------------------------------------------------
.../juneau/server/AcceptCharsetResource.java | 75 +
.../server/BeanContextPropertiesResource.java | 41 +
.../juneau/server/CallbackStringsResource.java | 52 +
.../juneau/server/CharsetEncodingsResource.java | 54 +
.../juneau/server/ClientVersionResource.java | 93 ++
.../apache/juneau/server/ConfigResource.java | 37 +
.../apache/juneau/server/ContentResource.java | 80 +
.../server/DefaultContentTypesResource.java | 127 ++
.../juneau/server/ErrorConditionsResource.java | 134 ++
.../apache/juneau/server/GroupsResource.java | 71 +
.../org/apache/juneau/server/GzipResource.java | 110 ++
.../juneau/server/InheritanceResource.java | 316 ++++
.../juneau/server/LargePojosResource.java | 40 +
.../apache/juneau/server/MessagesResource.java | 61 +
.../juneau/server/NlsPropertyResource.java | 60 +
.../org/apache/juneau/server/NlsResource.java | 194 +++
.../juneau/server/NoParserInputResource.java | 55 +
.../juneau/server/OnPostCallResource.java | 93 ++
.../apache/juneau/server/OnPreCallResource.java | 84 ++
.../server/OptionsWithoutNlsResource.java | 43 +
.../server/OverlappingMethodsResource.java | 145 ++
.../apache/juneau/server/ParamsResource.java | 292 ++++
.../apache/juneau/server/ParsersResource.java | 111 ++
.../org/apache/juneau/server/PathResource.java | 68 +
.../org/apache/juneau/server/PathsResource.java | 72 +
.../juneau/server/PropertiesResource.java | 89 ++
.../juneau/server/RestClient2Resource.java | 35 +
.../java/org/apache/juneau/server/Root.java | 76 +-
.../juneau/server/SerializersResource.java | 102 ++
.../juneau/server/StaticFilesResource.java | 35 +
.../apache/juneau/server/TestAcceptCharset.java | 75 -
.../server/TestBeanContextProperties.java | 41 -
.../juneau/server/TestCallbackStrings.java | 52 -
.../juneau/server/TestCharsetEncodings.java | 54 -
.../apache/juneau/server/TestClientVersion.java | 93 --
.../org/apache/juneau/server/TestConfig.java | 37 -
.../org/apache/juneau/server/TestContent.java | 80 -
.../juneau/server/TestDefaultContentTypes.java | 127 --
.../juneau/server/TestErrorConditions.java | 134 --
.../org/apache/juneau/server/TestGroups.java | 71 -
.../java/org/apache/juneau/server/TestGzip.java | 110 --
.../apache/juneau/server/TestInheritance.java | 316 ----
.../apache/juneau/server/TestLargePojos.java | 40 -
.../org/apache/juneau/server/TestMessages.java | 61 -
.../java/org/apache/juneau/server/TestNls.java | 194 ---
.../apache/juneau/server/TestNlsProperty.java | 60 -
.../apache/juneau/server/TestNoParserInput.java | 55 -
.../apache/juneau/server/TestOnPostCall.java | 93 --
.../org/apache/juneau/server/TestOnPreCall.java | 84 --
.../juneau/server/TestOptionsWithoutNls.java | 43 -
.../juneau/server/TestOverlappingMethods.java | 145 --
.../org/apache/juneau/server/TestParams.java | 292 ----
.../org/apache/juneau/server/TestParsers.java | 111 --
.../java/org/apache/juneau/server/TestPath.java | 68 -
.../org/apache/juneau/server/TestPaths.java | 72 -
.../apache/juneau/server/TestProperties.java | 89 --
.../apache/juneau/server/TestRestClient2.java | 35 -
.../apache/juneau/server/TestSerializers.java | 102 --
.../apache/juneau/server/TestStaticFiles.java | 35 -
.../apache/juneau/server/TestTransforms.java | 114 --
.../juneau/server/TestTransformsParent.java | 25 -
.../java/org/apache/juneau/server/TestUris.java | 120 --
.../apache/juneau/server/TestUrlContent.java | 58 -
.../juneau/server/TransformsParentResource.java | 25 +
.../juneau/server/TransformsResource.java | 114 ++
.../org/apache/juneau/server/UrisResource.java | 120 ++
.../juneau/server/UrlContentResource.java | 58 +
.../juneau/server/Messages2Resource.properties | 16 +
.../juneau/server/MessagesResource.properties | 16 +
.../server/NlsPropertyResource.properties | 16 +
.../apache/juneau/server/NlsResource.properties | 79 +
.../juneau/server/TestMessages.properties | 16 -
.../juneau/server/TestMessages2.properties | 16 -
.../org/apache/juneau/server/TestNls.properties | 79 -
.../juneau/server/TestNlsProperty.properties | 16 -
.../apache/juneau/server/AcceptCharsetTest.java | 123 ++
.../server/BeanContextPropertiesTest.java | 37 +
.../juneau/server/CallbackStringsTest.java | 50 +
.../juneau/server/CharsetEncodingsTest.java | 96 ++
.../apache/juneau/server/ClientVersionTest.java | 90 ++
.../org/apache/juneau/server/ConfigTest.java | 58 +
.../org/apache/juneau/server/ContentTest.java | 706 +++++++++
.../juneau/server/DefaultContentTypesTest.java | 497 +++++++
.../juneau/server/ErrorConditionsTest.java | 220 +++
.../org/apache/juneau/server/GroupsTest.java | 122 ++
.../java/org/apache/juneau/server/GzipTest.java | 344 +++++
.../apache/juneau/server/InheritanceTest.java | 126 ++
.../apache/juneau/server/LargePojosTest.java | 83 ++
.../org/apache/juneau/server/MessagesTest.java | 47 +
.../apache/juneau/server/NlsPropertyTest.java | 48 +
.../java/org/apache/juneau/server/NlsTest.java | 170 +++
.../apache/juneau/server/NoParserInputTest.java | 70 +
.../apache/juneau/server/OnPostCallTest.java | 121 ++
.../org/apache/juneau/server/OnPreCallTest.java | 61 +
.../juneau/server/OptionsWithoutNlsTest.java | 51 +
.../juneau/server/OverlappingMethodsTest.java | 170 +++
.../org/apache/juneau/server/ParamsTest.java | 716 +++++++++
.../org/apache/juneau/server/ParsersTest.java | 162 +++
.../java/org/apache/juneau/server/PathTest.java | 44 +
.../org/apache/juneau/server/PathsTest.java | 1368 ++++++++++++++++++
.../apache/juneau/server/PropertiesTest.java | 48 +
.../apache/juneau/server/RestClientTest.java | 199 +++
.../apache/juneau/server/SerializersTest.java | 152 ++
.../apache/juneau/server/StaticFilesTest.java | 56 +
.../juneau/server/TestAcceptCharsetTest.java | 123 --
.../server/TestBeanContextPropertiesTest.java | 37 -
.../juneau/server/TestCallbackStringsTest.java | 50 -
.../juneau/server/TestCharsetEncodingsTest.java | 96 --
.../juneau/server/TestClientVersionTest.java | 90 --
.../apache/juneau/server/TestConfigTest.java | 58 -
.../apache/juneau/server/TestContentTest.java | 706 ---------
.../server/TestDefaultContentTypesTest.java | 497 -------
.../juneau/server/TestErrorConditionsTest.java | 220 ---
.../apache/juneau/server/TestGroupsTest.java | 122 --
.../org/apache/juneau/server/TestGzipTest.java | 344 -----
.../juneau/server/TestInheritanceTest.java | 126 --
.../juneau/server/TestLargePojosTest.java | 83 --
.../apache/juneau/server/TestMessagesTest.java | 47 -
.../juneau/server/TestNlsPropertyTest.java | 48 -
.../org/apache/juneau/server/TestNlsTest.java | 170 ---
.../juneau/server/TestNoParserInputTest.java | 70 -
.../juneau/server/TestOnPostCallTest.java | 121 --
.../apache/juneau/server/TestOnPreCallTest.java | 61 -
.../server/TestOptionsWithoutNlsTest.java | 51 -
.../server/TestOverlappingMethodsTest.java | 170 ---
.../apache/juneau/server/TestParamsTest.java | 716 ---------
.../apache/juneau/server/TestParsersTest.java | 162 ---
.../org/apache/juneau/server/TestPathTest.java | 44 -
.../org/apache/juneau/server/TestPathsTest.java | 1368 ------------------
.../juneau/server/TestPropertiesTest.java | 48 -
.../juneau/server/TestRestClientTest.java | 199 ---
.../juneau/server/TestSerializersTest.java | 152 --
.../juneau/server/TestStaticFilesTest.java | 56 -
.../juneau/server/TestTransformsTest.java | 68 -
.../org/apache/juneau/server/TestUrisTest.java | 918 ------------
.../juneau/server/TestUrlContentTest.java | 74 -
.../apache/juneau/server/TransformsTest.java | 68 +
.../java/org/apache/juneau/server/UrisTest.java | 918 ++++++++++++
.../apache/juneau/server/UrlContentTest.java | 74 +
139 files changed, 10346 insertions(+), 10346 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/AcceptCharsetResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/AcceptCharsetResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/AcceptCharsetResource.java
new file mode 100755
index 0000000..3533353
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/AcceptCharsetResource.java
@@ -0,0 +1,75 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static org.apache.juneau.server.RestServletContext.*;
+
+import java.io.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.annotation.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.plaintext.*;
+import org.apache.juneau.serializer.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testAcceptCharset",
+ serializers={PlainTextSerializer.class},
+ properties={
+ // Some versions of Jetty default to ISO8601, so specify UTF-8 for test consistency.
+ @Property(name=REST_defaultCharset,value="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(@Content String in) {
+ return in;
+ }
+
+ @Consumes("text/plain")
+ public static class TestParser extends InputStreamParser {
+ @SuppressWarnings("unchecked")
+ @Override /* Parser */
+ protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception {
+ return (T)session.getProperties().getString("characterEncoding");
+ }
+ }
+
+ @Produces("text/plain")
+ public static class TestSerializer extends OutputStreamSerializer {
+ @Override /* Serializer */
+ protected void doSerialize(SerializerSession session, Object o) throws Exception {
+ Writer w = new OutputStreamWriter(session.getOutputStream());
+ w.append(o.toString()).append('/').append(session.getProperties().getString("characterEncoding"));
+ w.flush();
+ w.close();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/BeanContextPropertiesResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/BeanContextPropertiesResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/BeanContextPropertiesResource.java
new file mode 100755
index 0000000..519715a
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/BeanContextPropertiesResource.java
@@ -0,0 +1,41 @@
+/***************************************************************************************************************************
+ * 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;
+
+import java.io.*;
+import java.util.*;
+
+import org.apache.juneau.server.annotation.*;
+import org.apache.juneau.transforms.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testBeanContext",
+ transforms=DateSwap.ISO8601DTZ.class
+)
+public class BeanContextPropertiesResource extends RestServletDefault {
+ private static final long serialVersionUID = 1L;
+
+ //====================================================================================================
+ // Validate that transforms defined on class transform to underlying bean context.
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testClassTransforms/{d1}")
+ public Reader testClassTransforms(@Attr("d1") Date d1, @Param("d2") Date d2, @Header("X-D3") Date d3) throws Exception {
+ DateSwap df = DateSwap.ISO8601DTZ.class.newInstance();
+ return new StringReader(
+ "d1="+df.swap(d1)+",d2="+df.swap(d2)+",d3="+df.swap(d3)+""
+ );
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/CallbackStringsResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/CallbackStringsResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/CallbackStringsResource.java
new file mode 100755
index 0000000..04eaf2d
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/CallbackStringsResource.java
@@ -0,0 +1,52 @@
+/***************************************************************************************************************************
+ * 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;
+
+import java.util.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testCallback"
+)
+public class CallbackStringsResource extends RestServletDefault {
+ private static final long serialVersionUID = 1L;
+
+ //====================================================================================================
+ // Test GET
+ //====================================================================================================
+ @RestMethod(name="GET", path="/")
+ public ObjectMap test1(RestRequest req) throws Exception {
+ return new ObjectMap().append("method","GET").append("headers", getFooHeaders(req)).append("content", req.getInputAsString());
+ }
+
+ //====================================================================================================
+ // Test PUT
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/")
+ public ObjectMap testCharsetOnResponse(RestRequest req) throws Exception {
+ return new ObjectMap().append("method","PUT").append("headers", getFooHeaders(req)).append("content", req.getInputAsString());
+ }
+
+ private Map<String,Object> getFooHeaders(RestRequest req) {
+ Map<String,Object> m = new TreeMap<String,Object>();
+ for (Map.Entry<String,Object> e : req.getHeaders().entrySet())
+ if (e.getKey().startsWith("Foo-"))
+ m.put(e.getKey(), e.getValue());
+ return m;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/CharsetEncodingsResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/CharsetEncodingsResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/CharsetEncodingsResource.java
new file mode 100755
index 0000000..0f6e55e
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/CharsetEncodingsResource.java
@@ -0,0 +1,54 @@
+/***************************************************************************************************************************
+ * 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;
+
+import org.apache.juneau.*;
+import org.apache.juneau.annotation.*;
+import org.apache.juneau.internal.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.serializer.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testCharsetEncodings",
+ defaultRequestHeaders={"Accept: text/s", "Content-Type: text/p"},
+ parsers={CharsetEncodingsResource.CtParser.class}, serializers={CharsetEncodingsResource.ASerializer.class}
+)
+public class CharsetEncodingsResource extends RestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Consumes("text/p")
+ public static class CtParser extends ReaderParser {
+ @SuppressWarnings("unchecked")
+ @Override /* Parser */
+ protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception {
+ return (T)IOUtils.read(session.getReader());
+ }
+ }
+
+ @Produces("text/s")
+ public static class ASerializer extends WriterSerializer {
+ @Override /* Serializer */
+ protected void doSerialize(SerializerSession session, Object o) throws Exception {
+ session.getWriter().write(o.toString());
+ }
+ }
+
+ @RestMethod(name="PUT", path="/")
+ public String test1(RestRequest req, @Content String in) {
+ return req.getCharacterEncoding() + "/" + in + "/" + req.getCharacterEncoding();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/ClientVersionResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/ClientVersionResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/ClientVersionResource.java
new file mode 100644
index 0000000..93c2528
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/ClientVersionResource.java
@@ -0,0 +1,93 @@
+/***************************************************************************************************************************
+ * 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;
+
+import org.apache.juneau.microservice.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testClientVersion",
+ children={
+ ClientVersionResource.DefaultHeader.class,
+ ClientVersionResource.CustomHeader.class
+ }
+)
+@SuppressWarnings("serial")
+public class ClientVersionResource extends Resource {
+
+ @RestResource(
+ path="/defaultHeader"
+ )
+ public static class DefaultHeader extends Resource {
+
+ @RestMethod(name="GET", path="/")
+ public String test0() {
+ return "no-version";
+ }
+
+ @RestMethod(name="GET", path="/", clientVersion="[0.0,1.0)")
+ public String test1() {
+ return "[0.0,1.0)";
+ }
+
+ @RestMethod(name="GET", path="/", clientVersion="[1.0,1.0]")
+ public String test2() {
+ return "[1.0,1.0]";
+ }
+
+ @RestMethod(name="GET", path="/", clientVersion="[1.1,2)")
+ public String test3() {
+ return "[1.1,2)";
+ }
+
+ @RestMethod(name="GET", path="/", clientVersion="2")
+ public String test4() {
+ return "2";
+ }
+ }
+
+ @RestResource(
+ path="/customHeader",
+ clientVersionHeader="Custom-Client-Version"
+ )
+ public static class CustomHeader extends Resource {
+
+ @RestMethod(name="GET", path="/")
+ public String test0() {
+ return "no-version";
+ }
+
+ @RestMethod(name="GET", path="/", clientVersion="[0.0,1.0)")
+ public String test1() {
+ return "[0.0,1.0)";
+ }
+
+ @RestMethod(name="GET", path="/", clientVersion="[1.0,1.0]")
+ public String test2() {
+ return "[1.0,1.0]";
+ }
+
+ @RestMethod(name="GET", path="/", clientVersion="[1.1,2)")
+ public String test3() {
+ return "[1.1,2)";
+ }
+
+ @RestMethod(name="GET", path="/", clientVersion="2")
+ public String test4() {
+ return "2";
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/ConfigResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/ConfigResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/ConfigResource.java
new file mode 100755
index 0000000..df8b31f
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/ConfigResource.java
@@ -0,0 +1,37 @@
+/***************************************************************************************************************************
+ * 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;
+
+import org.apache.juneau.ini.*;
+import org.apache.juneau.microservice.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testConfig"
+)
+@SuppressWarnings("serial")
+public class ConfigResource extends Resource {
+
+ @RestMethod(name="GET", path="/")
+ public ConfigFile test1(RestRequest req) {
+ return req.getConfig();
+ }
+
+ @RestMethod(name="GET", path="/{key}/{class}")
+ public Object test2(RestRequest req, @Attr("key") String key, @Attr("class") Class<?> c) throws Exception {
+ return req.getConfig().getObject(c, key);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/ContentResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/ContentResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/ContentResource.java
new file mode 100755
index 0000000..efe4326
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/ContentResource.java
@@ -0,0 +1,80 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static org.apache.juneau.server.RestServletContext.*;
+
+import java.util.*;
+
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testContent",
+ properties={
+ @Property(name=REST_allowMethodParam, value="*")
+ }
+)
+public class ContentResource extends RestServletDefault {
+ private static final long serialVersionUID = 1L;
+
+ //====================================================================================================
+ // Basic tests
+ //====================================================================================================
+ @RestMethod(name="POST", path="/boolean")
+ public boolean testBool(@Content boolean b) {
+ return b;
+ }
+
+ @RestMethod(name="POST", path="/Boolean")
+ public Boolean testBoolean(@Content Boolean b) {
+ return b;
+ }
+
+ @RestMethod(name="POST", path="/int")
+ public int testInt(@Content int i) {
+ return i;
+ }
+
+ @RestMethod(name="POST", path="/Integer")
+ public Integer testInteger(@Content Integer i) {
+ return i;
+ }
+
+ @RestMethod(name="POST", path="/float")
+ public float testFloat(@Content float f) {
+ return f;
+ }
+
+ @RestMethod(name="POST", path="/Float")
+ public Float testFloat2(@Content Float f) {
+ return f;
+ }
+
+ @RestMethod(name="POST", path="/Map")
+ public TreeMap<String,String> testMap(@Content TreeMap<String,String> m) {
+ return m;
+ }
+
+ @RestMethod(name="POST", path="/B")
+ public DTO2s.B testPojo1(@Content DTO2s.B b) {
+ return b;
+ }
+
+ @RestMethod(name="POST", path="/C")
+ public DTO2s.C testPojo2(@Content DTO2s.C c) {
+ return c;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/DefaultContentTypesResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/DefaultContentTypesResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/DefaultContentTypesResource.java
new file mode 100755
index 0000000..0cf5649
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/DefaultContentTypesResource.java
@@ -0,0 +1,127 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static org.apache.juneau.server.annotation.Inherit.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.annotation.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.serializer.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testDefaultContentTypes",
+ defaultRequestHeaders={" Accept : text/s2 "," Content-Type : text/p2 "},
+ parsers={DefaultContentTypesResource.P1.class,DefaultContentTypesResource.P2.class}, serializers={DefaultContentTypesResource.S1.class,DefaultContentTypesResource.S2.class}
+)
+@SuppressWarnings("synthetic-access")
+public class DefaultContentTypesResource extends RestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Consumes("text/p1")
+ public static class P1 extends DummyParser { public P1() {super("p1");}}
+
+ @Consumes("text/p2")
+ public static class P2 extends DummyParser { public P2() {super("p2");}}
+
+ @Consumes("text/p3")
+ public static class P3 extends DummyParser { public P3() {super("p3");}}
+
+ @Produces("text/s1")
+ public static class S1 extends DummySerializer { public S1() {super("s1");}}
+
+ @Produces("text/s2")
+ public static class S2 extends DummySerializer { public S2() {super("s2");}}
+
+ @Produces("text/s3")
+ public static class S3 extends DummySerializer { public S3() {super("s3");}}
+
+ /**
+ * Test that default Accept and Content-Type headers on servlet annotation are picked up.
+ */
+ @RestMethod(name="PUT", path="/testDefaultHeadersOnServletAnnotation")
+ public String testDefaultHeadersOnServletAnnotation(@Content String in) {
+ return in;
+ }
+
+ //====================================================================================================
+ // Test that default Accept and Content-Type headers on servlet annotation are picked up
+ // when @RestMethod.parsers/serializers annotations are used.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testRestMethodParsersSerializers", parsers=P3.class, serializers=S3.class)
+ public String testRestMethodParsersSerializers(@Content String in) {
+ return in;
+ }
+
+ //====================================================================================================
+ // Test that default Accept and Content-Type headers on servlet annotation are picked up
+ // when @RestMethod.addParsers/addSerializers annotations are used.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testRestMethodAddParsersSerializers", parsers=P3.class, parsersInherit=PARSERS, serializers=S3.class, serializersInherit=SERIALIZERS)
+ public String testRestMethodAddParsersSerializers(@Content String in) {
+ return in;
+ }
+
+ //====================================================================================================
+ // Various Accept incantations.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testAccept")
+ public String testAccept(@Content String in) {
+ return in;
+ }
+
+ //====================================================================================================
+ // Test that default Accept and Content-Type headers on method annotation are picked up
+ // when @RestMethod.parsers/serializers annotations are used.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testRestMethodParserSerializerAnnotations", defaultRequestHeaders={"Accept: text/s3","Content-Type: text/p3"}, parsers=P3.class, serializers=S3.class)
+ public String testRestMethodParserSerializerAnnotations(@Content String in) {
+ return in;
+ }
+
+ //====================================================================================================
+ // Test that default Accept and Content-Type headers on method annotation are picked up
+ // when @RestMethod.addParsers/addSerializers annotations are used.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testRestMethodAddParsersSerializersAnnotations", defaultRequestHeaders={"Accept: text/s3","Content-Type: text/p3"}, parsers=P3.class, parsersInherit=PARSERS, serializers=S3.class, serializersInherit=SERIALIZERS)
+ public String testRestMethodAddParsersSerializersAnnotations(@Content String in) {
+ return in;
+ }
+
+ public static class DummyParser extends ReaderParser {
+ private String name;
+ private DummyParser(String name) {
+ this.name = name;
+ }
+ @SuppressWarnings("unchecked")
+ @Override /* Parser */
+ protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception {
+ return (T)name;
+ }
+ }
+
+ public static class DummySerializer extends WriterSerializer {
+ private String name;
+ private DummySerializer(String name) {
+ this.name = name;
+ }
+ @Override /* Serializer */
+ protected void doSerialize(SerializerSession session, Object output) throws Exception {
+ session.getWriter().write(name + "/" + output);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/ErrorConditionsResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/ErrorConditionsResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/ErrorConditionsResource.java
new file mode 100755
index 0000000..80649f2
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/ErrorConditionsResource.java
@@ -0,0 +1,134 @@
+/***************************************************************************************************************************
+ * 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;
+
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ * Validates correct parser is used.
+ */
+@RestResource(
+ path="/testErrorConditions"
+)
+public class ErrorConditionsResource extends RestServletDefault {
+ private static final long serialVersionUID = 1L;
+
+ //====================================================================================================
+ // Test non-existent properties
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testNonExistentBeanProperties")
+ public String testNonExistentBeanProperties(@Content Test1 in) {
+ return "OK";
+ }
+
+ public static class Test1 {
+ public String f1;
+ }
+
+ //====================================================================================================
+ // Test trying to set properties to wrong data type
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testWrongDataType")
+ public String testWrongDataType(@Content Test2 in) {
+ return "OK";
+ }
+
+ public static class Test2 {
+ public int f1;
+ }
+
+ //====================================================================================================
+ // Test trying to parse into class with non-public no-arg constructor.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testParseIntoNonConstructableBean")
+ public String testParseIntoNonConstructableBean(@Content Test3a in) {
+ return "OK";
+ }
+
+ public static class Test3a {
+ public int f1;
+ private Test3a(){}
+ }
+
+ //====================================================================================================
+ // Test trying to parse into non-static inner class
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testParseIntoNonStaticInnerClass")
+ public String testParseIntoNonStaticInnerClass(@Content Test3b in) {
+ return "OK";
+ }
+
+ public class Test3b {
+ public Test3b(){}
+ }
+
+ //====================================================================================================
+ // Test trying to parse into non-public inner class
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testParseIntoNonPublicInnerClass")
+ public String testParseIntoNonPublicInnerClass(@Content Test3b1 in) {
+ return "OK";
+ }
+
+ static class Test3b1 {
+ public Test3b1(){}
+ }
+
+ //====================================================================================================
+ // Test exception thrown during bean construction.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testThrownConstructorException")
+ public String testThrownConstructorException(@Content Test3c in) {
+ return "OK";
+ }
+
+ public static class Test3c {
+ public int f1;
+ private Test3c(){}
+ public static Test3c valueOf(String s) {
+ throw new RuntimeException("Test error");
+ }
+ }
+
+ //====================================================================================================
+ // Test trying to set parameters to invalid types.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testSetParameterToInvalidTypes/{a1}")
+ public String testSetParameterToInvalidTypes(@Param("p1") int t1, @Attr int a1, @Header("h1") int h1) {
+ return "OK";
+ }
+
+ //====================================================================================================
+ // Test SC_NOT_FOUND & SC_METHOD_NOT_ALLOWED
+ //====================================================================================================
+ @RestMethod(name="GET", path="/test404and405")
+ public String test404and405() {
+ return "OK";
+ }
+
+ //====================================================================================================
+ // Test SC_PRECONDITION_FAILED
+ //====================================================================================================
+ @RestMethod(name="GET", path="/test412", matchers=NeverMatcher.class)
+ public String test412() {
+ return "OK";
+ }
+
+ public static class NeverMatcher extends RestMatcher {
+ @Override /* RestMatcher */
+ public boolean matches(RestRequest req) {
+ return false;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/GroupsResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/GroupsResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/GroupsResource.java
new file mode 100755
index 0000000..be2df77
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/GroupsResource.java
@@ -0,0 +1,71 @@
+/***************************************************************************************************************************
+ * 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;
+
+import org.apache.juneau.*;
+import org.apache.juneau.annotation.*;
+import org.apache.juneau.internal.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.serializer.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testGroups"
+)
+public class GroupsResource extends RestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Produces({"text/s1","text/s2"})
+ public static class SSerializer extends WriterSerializer {
+ @Override /* Serializer */
+ protected void doSerialize(SerializerSession session, Object output) throws Exception {
+ session.getWriter().write("text/s," + output);
+ }
+ }
+
+ @Consumes({"text/p1","text/p2"})
+ public static class PParser extends ReaderParser {
+ @SuppressWarnings("unchecked")
+ @Override /* Parser */
+ protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception {
+ return (T)IOUtils.read(session.getReader());
+ }
+ }
+
+
+ @Override /* RestServlet */
+ public SerializerGroup createSerializers(ObjectMap properties, Class<?>[] filters) throws Exception {
+ return new SerializerGroup().append(SSerializer.class).setProperties(properties).addTransforms(filters);
+ }
+
+ @Override /* RestServlet */
+ public ParserGroup createParsers(ObjectMap properties, Class<?>[] filters) throws Exception {
+ return new ParserGroup().append(PParser.class).setProperties(properties).addTransforms(filters);
+ }
+
+ //====================================================================================================
+ // Serializer defined on class.
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testSerializerDefinedOnClass")
+ public String testSerializerDefinedOnClass_get() {
+ return "GET";
+ }
+
+ @RestMethod(name="PUT", path="/testSerializerDefinedOnClass")
+ public String testSerializerDefinedOnClass_put(@Content String in) {
+ return in;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/GzipResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/GzipResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/GzipResource.java
new file mode 100755
index 0000000..d095c8d
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/GzipResource.java
@@ -0,0 +1,110 @@
+/***************************************************************************************************************************
+ * 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;
+
+import java.io.*;
+
+import org.apache.juneau.encoders.*;
+import org.apache.juneau.plaintext.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+public class GzipResource {
+
+ //================================================================================
+ // Encoder for "myencoding" encoding
+ //================================================================================
+ public static class MyEncoder extends GzipEncoder {
+ @Override /* Encoder */
+ public String[] getCodings() {
+ return new String[]{"mycoding"};
+ }
+ }
+
+ //====================================================================================================
+ // Test with no compression enabled.
+ //====================================================================================================
+ @RestResource(
+ path="/testGzipOff",
+ serializers=PlainTextSerializer.class,
+ parsers=PlainTextParser.class
+ )
+ public static class TestGzipOff extends RestServlet {
+ private static final long serialVersionUID = 1L;
+ @RestMethod(name="GET", path="/")
+ public String test1get() {
+ return "foo";
+ }
+ @RestMethod(name="PUT", path="/")
+ public String test1put(@Content String in) {
+ return in;
+ }
+ }
+
+ //====================================================================================================
+ // Test with compression enabled.
+ //====================================================================================================
+ @RestResource(
+ path="/testGzipOn",
+ serializers=PlainTextSerializer.class,
+ parsers=PlainTextParser.class,
+ encoders=MyEncoder.class
+ )
+ public static class TestGzipOn extends RestServlet {
+ private static final long serialVersionUID = 1L;
+ @RestMethod(name="GET", path="/")
+ public String test1() {
+ return "foo";
+ }
+ @RestMethod(name="PUT", path="/")
+ public String test1put(@Content String in) {
+ return in;
+ }
+ // This method bypasses the content type and encoding from
+ // the serializers and encoders when calling getOutputStream() directly.
+ @RestMethod(name="GET", path="/direct")
+ public void direct(RestResponse res) throws Exception {
+ res.setContentType("text/direct");
+ OutputStream os = res.getOutputStream();
+ os.write("test".getBytes());
+ os.flush();
+ }
+
+ // This method bypasses the content type and encoding from
+ // the serializers and encoders when calling getWriter() directly.
+ @RestMethod(name="GET", path="/direct2")
+ public void direct2(RestResponse res) throws Exception {
+ Writer w = res.getWriter();
+ w.append("test");
+ w.flush();
+ }
+
+ // This method uses getNegotiatedWriter() which should use GZip encoding.
+ @RestMethod(name="GET", path="/direct3")
+ public void direct3(RestResponse res) throws Exception {
+ Writer w = res.getNegotiatedWriter();
+ w.append("test");
+ w.flush();
+ }
+
+ // This method overrides the set of encoders at the method level and so shouldn't use GZip encoding.
+ @RestMethod(name="GET", path="/direct4", inheritEncoders=false)
+ public void direct4(RestResponse res) throws Exception {
+ Writer w = res.getNegotiatedWriter();
+ w.append("test");
+ w.flush();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/InheritanceResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/InheritanceResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/InheritanceResource.java
new file mode 100755
index 0000000..4c25acc
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/InheritanceResource.java
@@ -0,0 +1,316 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static org.apache.juneau.server.annotation.Inherit.*;
+
+import java.io.*;
+import java.util.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.annotation.*;
+import org.apache.juneau.encoders.*;
+import org.apache.juneau.json.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.serializer.*;
+import org.apache.juneau.server.annotation.*;
+import org.apache.juneau.server.annotation.Properties;
+import org.apache.juneau.transform.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testInheritance",
+ serializers={InheritanceResource.S1.class,InheritanceResource.S2.class},
+ parsers={InheritanceResource.P1.class,InheritanceResource.P2.class},
+ encoders={InheritanceResource.E1.class,InheritanceResource.E2.class},
+ transforms={InheritanceResource.F1.class},
+ properties={@Property(name="p1",value="v1"), @Property(name="p2",value="v2")}
+)
+public class InheritanceResource extends RestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @RestResource(
+ serializers={S3.class,S4.class},
+ parsers={P3.class,P4.class},
+ encoders={E3.class,E4.class},
+ transforms={F2.class},
+ properties={@Property(name="p2",value="v2a"), @Property(name="p3",value="v3"), @Property(name="p4",value="v4")}
+ )
+ public static class Sub extends InheritanceResource {
+ private static final long serialVersionUID = 1L;
+ }
+
+ //====================================================================================================
+ // Test serializer inheritance.
+ //====================================================================================================
+ @RestResource(path="/testInheritanceSerializers")
+ public static class TestSerializers extends Sub {
+ private static final long serialVersionUID = 1L;
+
+ // Should show ['text/s3','text/s4','text/s1','text/s2']
+ @RestMethod(
+ name="GET",
+ path="/test1"
+ )
+ public Reader test1(RestResponse res) {
+ return new StringReader(new ObjectList(res.getSupportedMediaTypes()).toString());
+ }
+
+ // Should show ['text/s5']
+ @RestMethod(
+ name="GET",
+ path="/test2",
+ serializers=S5.class
+ )
+ public Reader test2(RestResponse res) {
+ return new StringReader(new ObjectList(res.getSupportedMediaTypes()).toString());
+ }
+
+ // Should show ['text/s5','text/s3','text/s4','text/s1','text/s2']
+ @RestMethod(
+ name="GET",
+ path="/test3",
+ serializers=S5.class,
+ serializersInherit=SERIALIZERS
+ )
+ public Reader test3(RestResponse res) {
+ return new StringReader(new ObjectList(res.getSupportedMediaTypes()).toString());
+ }
+ }
+
+ //====================================================================================================
+ // Test parser inheritance.
+ //====================================================================================================
+ @RestResource(path="/testInheritanceParsers")
+ public static class TestParsers extends Sub {
+ private static final long serialVersionUID = 1L;
+
+ // Should show ['text/p3','text/p4','text/p1','text/p2']
+ @RestMethod(
+ name="GET",
+ path="/test1"
+ )
+ public Reader test1(RestRequest req) {
+ return new StringReader(new ObjectList(req.getSupportedMediaTypes()).toString());
+ }
+
+ // Should show ['text/p5']
+ @RestMethod(
+ name="GET",
+ path="/test2",
+ parsers=P5.class
+ )
+ public Reader test2(RestRequest req) {
+ return new StringReader(new ObjectList(req.getSupportedMediaTypes()).toString());
+ }
+
+ // Should show ['text/p5','text/p3','text/p4','text/p1','text/p2']
+ @RestMethod(
+ name="GET",
+ path="/test3",
+ parsers=P5.class,
+ parsersInherit=PARSERS
+ )
+ public Reader test3(RestRequest req) {
+ return new StringReader(new ObjectList(req.getSupportedMediaTypes()).toString());
+ }
+ }
+
+ //====================================================================================================
+ // Test encoder inheritance.
+ //====================================================================================================
+ @RestResource(path="/testInheritanceEncoders")
+ public static class TestEncoders extends Sub {
+ private static final long serialVersionUID = 1L;
+
+ // Should show ['e3','e4','e1','e2','identity']
+ @RestMethod(name="GET", path="/test")
+ public Reader test(RestResponse res) throws RestServletException {
+ return new StringReader(new ObjectList(res.getSupportedEncodings()).toString());
+ }
+ }
+
+ //====================================================================================================
+ // Test filter inheritance.
+ //====================================================================================================
+ @RestResource(path="/testInheritanceTransforms", serializers=JsonSerializer.Simple.class)
+ public static class TestTransforms extends Sub {
+ private static final long serialVersionUID = 1L;
+
+ // Should show ['F1','F2','Foo3']
+ @RestMethod(name="GET", path="/test1")
+ public Object[] test1() {
+ return new Object[]{new Foo1(), new Foo2(), new Foo3()};
+ }
+
+ // Should show ['F1','F2','F3']
+ // Inherited serializer already has parent filters applied.
+ @RestMethod(name="GET", path="/test2", transforms=F3.class)
+ public Object[] test2() {
+ return new Object[]{new Foo1(), new Foo2(), new Foo3()};
+ }
+
+ // Should show ['F1','F2','F3']
+ @RestMethod(name="GET", path="/test3", transforms=F3.class, serializersInherit=TRANSFORMS)
+ public Object[] test3() {
+ return new Object[]{new Foo1(), new Foo2(), new Foo3()};
+ }
+
+ // Should show ['Foo1','Foo2','F3']
+ // Overriding serializer does not have parent filters applied.
+ @RestMethod(name="GET", path="/test4", serializers=JsonSerializer.Simple.class, transforms=F3.class)
+ public Object[] test4() {
+ return new Object[]{new Foo1(), new Foo2(), new Foo3()};
+ }
+
+ // Should show ['F1','F2','F3']
+ // Overriding serializer does have parent filters applied.
+ @RestMethod(name="GET", path="/test5", serializers=JsonSerializer.Simple.class, transforms=F3.class, serializersInherit=TRANSFORMS)
+ public Object[] test5() {
+ return new Object[]{new Foo1(), new Foo2(), new Foo3()};
+ }
+ }
+
+ //====================================================================================================
+ // Test properties inheritance.
+ //====================================================================================================
+ @RestResource(path="/testInheritanceProperties", serializers=JsonSerializer.Simple.class)
+ public static class TestProperties extends Sub {
+ private static final long serialVersionUID = 1L;
+
+ // Should show {p1:'v1',p2:'v2a',p3:'v3',p4:'v4'}
+ @RestMethod(name="GET", path="/test1")
+ public ObjectMap test1(@Properties ObjectMap properties) {
+ return transform(properties);
+ }
+
+ // Should show {p1:'v1',p2:'v2a',p3:'v3',p4:'v4a',p5:'v5'} when override is false.
+ // Should show {p1:'x',p2:'x',p3:'x',p4:'x',p5:'x'} when override is true.
+ @RestMethod(name="GET", path="/test2",
+ properties={@Property(name="p4",value="v4a"), @Property(name="p5", value="v5")})
+ public ObjectMap test2(@Properties ObjectMap properties, @HasParam("override") boolean override) {
+ if (override) {
+ properties.put("p1", "x");
+ properties.put("p2", "x");
+ properties.put("p3", "x");
+ properties.put("p4", "x");
+ properties.put("p5", "x");
+ }
+ return transform(properties);
+ }
+
+ private ObjectMap transform(ObjectMap properties) {
+ ObjectMap m = new ObjectMap();
+ for (Map.Entry<String,Object> e : properties.entrySet()) {
+ if (e.getKey().startsWith("p"))
+ m.put(e.getKey(), e.getValue());
+ }
+ return m;
+ }
+ }
+
+ public static class DummyParser extends ReaderParser {
+ @Override /* Parser */
+ protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception {
+ return null;
+ }
+ }
+
+ public static class DummySerializer extends WriterSerializer {
+ @Override /* Serializer */
+ protected void doSerialize(SerializerSession session, Object o) throws Exception {
+ session.getWriter().write(o.toString());
+ }
+ }
+
+ @Consumes("text/p1")
+ public static class P1 extends DummyParser{}
+
+ @Consumes("text/p2")
+ public static class P2 extends DummyParser{}
+
+ @Consumes("text/p3")
+ public static class P3 extends DummyParser{}
+
+ @Consumes("text/p4")
+ public static class P4 extends DummyParser{}
+
+ @Consumes("text/p5")
+ public static class P5 extends DummyParser{}
+
+ @Produces("text/s1")
+ public static class S1 extends DummySerializer{}
+
+ @Produces("text/s2")
+ public static class S2 extends DummySerializer{}
+
+ @Produces("text/s3")
+ public static class S3 extends DummySerializer{}
+
+ @Produces("text/s4")
+ public static class S4 extends DummySerializer{}
+
+ @Produces("text/s5")
+ public static class S5 extends DummySerializer{}
+
+ public static class E1 extends IdentityEncoder {
+ @Override public String[] getCodings() {
+ return new String[]{"e1"};
+ }
+ }
+
+ public static class E2 extends IdentityEncoder {
+ @Override public String[] getCodings() {
+ return new String[]{"e2"};
+ }
+ }
+
+ public static class E3 extends IdentityEncoder {
+ @Override public String[] getCodings() {
+ return new String[]{"e3"};
+ }
+ }
+
+ public static class E4 extends IdentityEncoder {
+ @Override public String[] getCodings() {
+ return new String[]{"e4"};
+ }
+ }
+
+ public static class Foo1 {@Override public String toString(){return "Foo1";}}
+ public static class Foo2 {@Override public String toString(){return "Foo2";}}
+ public static class Foo3 {@Override public String toString(){return "Foo3";}}
+
+ public static class F1 extends PojoSwap<Foo1,String> {
+ @Override /* PojoSwap */
+ public String swap(Foo1 o) throws SerializeException {
+ return "F1";
+ }
+ }
+
+ public static class F2 extends PojoSwap<Foo2,String> {
+ @Override /* PojoSwap */
+ public String swap(Foo2 o) throws SerializeException {
+ return "F2";
+ }
+ }
+
+ public static class F3 extends PojoSwap<Foo3,String> {
+ @Override /* PojoSwap */
+ public String swap(Foo3 o) throws SerializeException {
+ return "F3";
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/LargePojosResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/LargePojosResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/LargePojosResource.java
new file mode 100755
index 0000000..c4921d5
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/LargePojosResource.java
@@ -0,0 +1,40 @@
+/***************************************************************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ ***************************************************************************************************************************/
+package org.apache.juneau.server;
+
+
+import org.apache.juneau.server.annotation.*;
+import org.apache.juneau.server.jena.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testLargePojos"
+)
+public class LargePojosResource extends RestServletJenaDefault {
+ private static final long serialVersionUID = 1L;
+
+ //====================================================================================================
+ // Test how long it takes to serialize/parse various content types.
+ //====================================================================================================
+ @RestMethod(name="GET", path="/")
+ public LargePojo testGet() {
+ return LargePojo.create();
+ }
+
+ @RestMethod(name="PUT", path="/")
+ public String testPut(@Content LargePojo in) {
+ return "ok";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/MessagesResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/MessagesResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/MessagesResource.java
new file mode 100755
index 0000000..28a85bf
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/MessagesResource.java
@@ -0,0 +1,61 @@
+/***************************************************************************************************************************
+ * 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;
+
+import java.util.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.serializer.*;
+import org.apache.juneau.server.annotation.*;
+import org.apache.juneau.transform.*;
+
+/**
+ * JUnit automated testcase resource.
+ * Validates that resource bundles can be defined on both parent and child classes.
+ */
+@RestResource(
+ path="/testMessages",
+ messages="MessagesResource",
+ transforms={
+ MessagesResource.ResourceBundleSwap.class
+ }
+)
+public class MessagesResource extends RestServletDefault {
+ private static final long serialVersionUID = 1L;
+
+ //====================================================================================================
+ // Return contents of resource bundle.
+ //====================================================================================================
+ @RestMethod(name="GET", path="/test")
+ public Object test(@Messages ResourceBundle nls) {
+ return nls;
+ }
+
+
+ @SuppressWarnings("serial")
+ @RestResource(
+ path="/testMessages2",
+ messages="Messages2Resource"
+ )
+ public static class Messages2Resource extends MessagesResource {}
+
+ public static class ResourceBundleSwap extends PojoSwap<ResourceBundle,ObjectMap> {
+ @Override /* Transform */
+ public ObjectMap swap(ResourceBundle o) throws SerializeException {
+ ObjectMap m = new ObjectMap();
+ for (String k : o.keySet())
+ m.put(k, o.getString(k));
+ return m;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/NlsPropertyResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/NlsPropertyResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/NlsPropertyResource.java
new file mode 100755
index 0000000..d943ab6
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/NlsPropertyResource.java
@@ -0,0 +1,60 @@
+/***************************************************************************************************************************
+ * 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;
+
+import org.apache.juneau.annotation.*;
+import org.apache.juneau.serializer.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testNlsProperty",
+ serializers={NlsPropertyResource.TestSerializer.class},
+ properties={
+ @Property(name="TestProperty",value="$L{key1}")
+ },
+ messages="NlsPropertyResource"
+)
+public class NlsPropertyResource extends RestServlet {
+ private static final long serialVersionUID = 1L;
+
+ //====================================================================================================
+ // Test getting an NLS property defined on a class.
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testInheritedFromClass")
+ public String testInheritedFromClass() {
+ return null;
+ }
+
+ //====================================================================================================
+ // Test getting an NLS property defined on a method.
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testInheritedFromMethod",
+ properties={
+ @Property(name="TestProperty",value="$L{key2}")
+ }
+ )
+ public String testInheritedFromMethod() {
+ return null;
+ }
+
+ @Produces("text/plain")
+ public static class TestSerializer extends WriterSerializer {
+ @Override /* Serializer */
+ protected void doSerialize(SerializerSession session, Object o) throws Exception {
+ session.getWriter().write(session.getProperties().getString("TestProperty"));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/NlsResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/NlsResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/NlsResource.java
new file mode 100755
index 0000000..1dafcb5
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/NlsResource.java
@@ -0,0 +1,194 @@
+/***************************************************************************************************************************
+ * 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;
+
+import org.apache.juneau.server.annotation.*;
+import org.apache.juneau.utils.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testNls",
+ children={
+ NlsResource.Test1.class,
+ NlsResource.Test2.class,
+ NlsResource.Test3.class,
+ NlsResource.Test4.class,
+ NlsResource.Test5.class,
+ NlsResource.Test6.class
+ }
+)
+@SuppressWarnings({"serial"})
+public class NlsResource extends RestServletGroupDefault {
+ private static final long serialVersionUID = 1L;
+
+ //====================================================================================================
+ // test1 - Pull labels from annotations only.
+ //====================================================================================================
+ @RestResource(
+ path="/test1",
+ messages="NlsResource",
+ label="Test1.a",
+ description="Test1.b"
+ )
+ public static class Test1 extends RestServletDefault {
+
+ @RestMethod(
+ name="POST", path="/{a}",
+ description="Test1.c",
+ input={
+ @Var(category="attr", name="a", description="Test1.d"),
+ @Var(category="param", name="b", description="Test1.e"),
+ @Var(category="content", description="Test1.f"),
+ @Var(category="header", name="D", description="Test1.g"),
+ @Var(category="attr", name="a2", description="Test1.h"),
+ @Var(category="param", name="b2", description="Test1.i"),
+ @Var(category="header", name="D2", description="Test1.j"),
+ @Var(category="foo", name="bar", description="Test1.k"),
+ },
+ responses={
+ @Response(200),
+ @Response(value=201,
+ description="Test1.l",
+ output={
+ @Var(category="foo", name="bar", description="Test1.m"),
+ }
+ )
+ }
+ )
+ public String test1(@Attr("a") String a, @Param("b") String b, @Content String c, @Header("D") String d,
+ @Attr("e") String e, @Param("f") String f, @Header("g") String g) {
+ return null;
+ }
+ }
+
+ //====================================================================================================
+ // test2 - Pull labels from resource bundles only - simple keys.
+ //====================================================================================================
+ @RestResource(
+ path="/test2",
+ messages="NlsResource"
+ )
+ public static class Test2 extends RestServletDefault {
+
+ @RestMethod(
+ name="POST", path="/{a}"
+ )
+ public String test2(@Attr("a") String a, @Param("b") String b, @Content String c, @Header("D") String d,
+ @Attr("e") String e, @Param("f") String f, @Header("g") String g) {
+ return null;
+ }
+ }
+
+ //====================================================================================================
+ // test3 - Pull labels from resource bundles only - keys with class names.
+ //====================================================================================================
+ @RestResource(
+ path="/test3",
+ messages="NlsResource"
+ )
+ public static class Test3 extends RestServletDefault {
+
+ @RestMethod(
+ name="POST", path="/{a}"
+ )
+ public String test3(@Attr("a") String a, @Param("b") String b, @Content String c, @Header("D") String d,
+ @Attr("e") String e, @Param("f") String f, @Header("g") String g) {
+ return null;
+ }
+
+ @RestMethod(
+ name="GET", path="/"
+ )
+ public Object test3a(@Messages MessageBundle mb) {
+ return mb;
+ }
+ }
+
+ //====================================================================================================
+ // test4 - Pull labels from resource bundles only. Values have localized variables to resolve.
+ //====================================================================================================
+ @RestResource(
+ path="/test4",
+ messages="NlsResource"
+ )
+ public static class Test4 extends RestServletDefault {
+
+ @RestMethod(
+ name="POST", path="/{a}"
+ )
+ public String test4(@Attr("a") String a, @Param("b") String b, @Content String c, @Header("D") String d,
+ @Attr("e") String e, @Param("f") String f, @Header("g") String g) {
+ return null;
+ }
+ }
+
+ //====================================================================================================
+ // test5 - Pull labels from resource bundles only. Values have request variables to resolve.
+ //====================================================================================================
+ @RestResource(
+ path="/test5",
+ messages="NlsResource"
+ )
+ public static class Test5 extends RestServletDefault {
+
+ @RestMethod(
+ name="POST", path="/{a}"
+ )
+ public String test5(@Attr("a") String a, @Param("b") String b, @Content String c, @Header("D") String d,
+ @Attr("e") String e, @Param("f") String f, @Header("g") String g) {
+ return null;
+ }
+ }
+
+ //====================================================================================================
+ // test6 - Pull labels from annotations only, but annotations contain variables.
+ //====================================================================================================
+ @RestResource(
+ path="/test6",
+ messages="NlsResource",
+ label="$L{foo}",
+ description="$L{foo}"
+ )
+ public static class Test6 extends RestServletDefault {
+
+ @RestMethod(
+ name="POST", path="/{a}",
+ description="$L{foo}",
+ input={
+ @Var(category="attr", name="a", description="$L{foo}"),
+ @Var(category="param", name="b", description="$L{foo}"),
+ @Var(category="content", description="$L{foo}"),
+ @Var(category="header", name="D", description="$L{foo}"),
+ @Var(category="attr", name="a2", description="$L{foo}"),
+ @Var(category="param", name="b2", description="$L{foo}"),
+ @Var(category="header", name="D2", description="$L{foo}"),
+ @Var(category="foo", name="bar", description="$L{foo}"),
+ },
+ responses={
+ @Response(200),
+ @Response(value=201,
+ description="$L{foo}",
+ output={
+ @Var(category="foo", name="bar", description="$L{foo}"),
+ }
+ )
+ }
+ )
+ public String test6(@Attr("a") String a, @Param("b") String b, @Content String c, @Header("D") String d,
+ @Attr("e") String e, @Param("f") String f, @Header("g") String g) {
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/NoParserInputResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/NoParserInputResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/NoParserInputResource.java
new file mode 100755
index 0000000..5399196
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/NoParserInputResource.java
@@ -0,0 +1,55 @@
+/***************************************************************************************************************************
+ * 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;
+
+import java.io.*;
+
+import org.apache.juneau.internal.*;
+import org.apache.juneau.plaintext.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testNoParserInput",
+ serializers=PlainTextSerializer.class
+)
+public class NoParserInputResource extends RestServlet {
+ private static final long serialVersionUID = 1L;
+
+ //====================================================================================================
+ // @Content annotated InputStream.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testInputStream")
+ public String testInputStream(@Content InputStream in) throws Exception {
+ return IOUtils.read(in);
+ }
+
+ //====================================================================================================
+ // @Content annotated Reader.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testReader")
+ public String testReader(@Content Reader in) throws Exception {
+ return IOUtils.read(in);
+ }
+
+ //====================================================================================================
+ // @Content annotated PushbackReader.
+ // This should always fail since the servlet reader is not a pushback reader.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testPushbackReader")
+ public String testPushbackReader(@Content PushbackReader in) throws Exception {
+ return IOUtils.read(in);
+ }
+}
[13/14] incubator-juneau git commit: Clean up test and test resource
class names.
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/OnPostCallResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/OnPostCallResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/OnPostCallResource.java
new file mode 100755
index 0000000..c09dbee
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/OnPostCallResource.java
@@ -0,0 +1,93 @@
+/***************************************************************************************************************************
+ * 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;
+
+import org.apache.juneau.*;
+import org.apache.juneau.annotation.*;
+import org.apache.juneau.serializer.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ * Validates that headers
+ */
+@RestResource(
+ path="/testOnPostCall",
+ serializers=OnPostCallResource.TestSerializer.class,
+ properties={
+ @Property(name="p1",value="sp1"), // Unchanged servlet-level property.
+ @Property(name="p2",value="sp2"), // Servlet-level property overridden by onPostCall.
+ @Property(name="p3",value="sp3"), // Servlet-level property overridded by method.
+ @Property(name="p4",value="sp4") // Servlet-level property overridden by method then onPostCall.
+ }
+)
+public class OnPostCallResource extends RestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Produces({"text/s1","text/s2","text/s3"})
+ public static class TestSerializer extends WriterSerializer {
+ @Override /* Serializer */
+ protected void doSerialize(SerializerSession session, Object o) throws Exception {
+ ObjectMap p = session.getProperties();
+ session.getWriter().write("p1="+p.get("p1")+",p2="+p.get("p2")+",p3="+p.get("p3")+",p4="+p.get("p4")+",p5="+p.get("p5")+",contentType="+session.getProperties().getString("mediaType"));
+ }
+ @Override /* Serializer */
+ public ObjectMap getResponseHeaders(ObjectMap properties) {
+ if (properties.containsKey("Override-Content-Type"))
+ return new ObjectMap().append("Content-Type", properties.get("Override-Content-Type"));
+ return null;
+ }
+ }
+
+ @Override /* RestServlet */
+ protected void onPostCall(RestRequest req, RestResponse res) {
+ ObjectMap properties = req.getProperties();
+ properties.put("p2", "xp2");
+ properties.put("p4", "xp4");
+ properties.put("p5", "xp5"); // New property
+ String overrideAccept = req.getHeader("Override-Accept");
+ if (overrideAccept != null)
+ req.setHeader("Accept", overrideAccept);
+ String overrideContentType = req.getHeader("Override-Content-Type");
+ if (overrideContentType != null)
+ properties.put("Override-Content-Type", overrideContentType);
+ }
+
+
+ //====================================================================================================
+ // Test1 - Properties overridden via properties annotation.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testPropertiesOverridenByAnnotation",
+ properties={
+ @Property(name="p3",value="mp3"),
+ @Property(name="p4",value="mp4")
+ },
+ defaultRequestHeaders="Accept: text/s2"
+ )
+ public String testPropertiesOverridenByAnnotation() {
+ return "";
+ }
+
+ //====================================================================================================
+ // Test2 - Properties overridden programmatically.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testPropertiesOverriddenProgramatically")
+ public String testPropertiesOverriddenProgramatically(RestRequest req, @Properties ObjectMap properties) throws Exception {
+ properties.put("p3", "pp3");
+ properties.put("p4", "pp4");
+ String accept = req.getHeader("Accept");
+ if (accept == null || accept.isEmpty())
+ req.setHeader("Accept", "text/s2");
+ return "";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/OnPreCallResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/OnPreCallResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/OnPreCallResource.java
new file mode 100755
index 0000000..62a0bdc
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/OnPreCallResource.java
@@ -0,0 +1,84 @@
+/***************************************************************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ ***************************************************************************************************************************/
+package org.apache.juneau.server;
+
+import org.apache.juneau.*;
+import org.apache.juneau.annotation.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.plaintext.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ * Validates that headers
+ */
+@RestResource(
+ path="/testOnPreCall",
+ parsers=OnPreCallResource.TestParserA.class,
+ serializers=PlainTextSerializer.class,
+ properties={
+ @Property(name="p1",value="sp1"), // Unchanged servlet-level property.
+ @Property(name="p2",value="sp2"), // Servlet-level property overridden by onPreCall.
+ @Property(name="p3",value="sp3"), // Servlet-level property overridded by method.
+ @Property(name="p4",value="sp4") // Servlet-level property overridden by method then onPreCall.
+ }
+)
+public class OnPreCallResource extends RestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Consumes({"text/a1","text/a2","text/a3"})
+ public static class TestParserA extends ReaderParser {
+ @SuppressWarnings("unchecked")
+ @Override /* Parser */
+ protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception {
+ ObjectMap p = session.getProperties();
+ String matchingContentType = session.getProperties().getString("mediaType");
+ return (T)("p1="+p.get("p1")+",p2="+p.get("p2")+",p3="+p.get("p3")+",p4="+p.get("p4")+",p5="+p.get("p5")+",contentType="+matchingContentType);
+ }
+ }
+
+ @Override /* RestServlet */
+ protected void onPreCall(RestRequest req) {
+ ObjectMap properties = req.getProperties();
+ properties.put("p2", "xp2");
+ properties.put("p4", "xp4");
+ properties.put("p5", "xp5"); // New property
+ String overrideContentType = req.getHeader("Override-Content-Type");
+ if (overrideContentType != null)
+ req.setHeader("Content-Type", overrideContentType);
+ }
+
+
+ //====================================================================================================
+ // Properties overridden via properties annotation.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testPropertiesOverriddenByAnnotation",
+ properties={
+ @Property(name="p3",value="mp3"),
+ @Property(name="p4",value="mp4")
+ }
+ )
+ public String testPropertiesOverriddenByAnnotation(@Content String in) {
+ return in;
+ }
+
+ //====================================================================================================
+ // Properties overridden programmatically.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testPropertiesOverriddenProgrammatically")
+ public String testPropertiesOverriddenProgrammatically(RestRequest req, @Properties ObjectMap properties) throws Exception {
+ properties.put("p3", "pp3");
+ properties.put("p4", "pp4");
+ return req.getInput(String.class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/OptionsWithoutNlsResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/OptionsWithoutNlsResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/OptionsWithoutNlsResource.java
new file mode 100755
index 0000000..8cff70c
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/OptionsWithoutNlsResource.java
@@ -0,0 +1,43 @@
+/***************************************************************************************************************************
+ * 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;
+
+import org.apache.juneau.server.annotation.*;
+import org.apache.juneau.server.labels.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testOptionsWithoutNls"
+)
+public class OptionsWithoutNlsResource extends RestServletDefault {
+ private static final long serialVersionUID = 1L;
+
+ //====================================================================================================
+ // Should get to the options page without errors
+ //====================================================================================================
+ @RestMethod(name="OPTIONS", path="/testOptions/*")
+ public ResourceOptions testOptions(RestRequest req) {
+ return new ResourceOptions(this, req);
+ }
+
+ //====================================================================================================
+ // Missing resource bundle should cause {!!x} string.
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testMissingResourceBundle")
+ public String test(RestRequest req) {
+ return req.getMessage("bad", 1, 2, 3);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/OverlappingMethodsResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/OverlappingMethodsResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/OverlappingMethodsResource.java
new file mode 100755
index 0000000..1da85c4
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/OverlappingMethodsResource.java
@@ -0,0 +1,145 @@
+/***************************************************************************************************************************
+ * 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;
+
+import org.apache.juneau.plaintext.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testOverlappingMethods",
+ serializers=PlainTextSerializer.class
+)
+public class OverlappingMethodsResource extends RestServletDefault {
+ private static final long serialVersionUID = 1L;
+
+ //====================================================================================================
+ // Overlapping guards
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testOverlappingGuards1", guards=Test1Guard.class)
+ public String testOverlappingGuards1() {
+ return "test1_doGet";
+ }
+
+ //====================================================================================================
+ // Overlapping guards
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testOverlappingGuards2", guards={Test1Guard.class, Test2Guard.class})
+ public String testOverlappingGuards2() {
+ return "test2_doGet";
+ }
+
+ public static class Test1Guard extends RestGuard {
+ @Override /* RestGuard */
+ public boolean isRequestAllowed(RestRequest req) {
+ return req.getParameter("t1","").equals("1");
+ }
+ }
+
+ public static class Test2Guard extends RestGuard {
+ @Override /* RestGuard */
+ public boolean isRequestAllowed(RestRequest req) {
+ return req.getParameter("t2","").equals("2");
+ }
+ }
+
+ //====================================================================================================
+ // Overlapping matchers
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testOverlappingMatchers1", matchers=Test3aMatcher.class)
+ public String testOverlappingMatchers1() {
+ return "test3a";
+ }
+
+ @RestMethod(name="GET", path="/testOverlappingMatchers1", matchers=Test3bMatcher.class)
+ public String test3b_doGet() {
+ return "test3b";
+ }
+
+ @RestMethod(name="GET", path="/testOverlappingMatchers1")
+ public String test3c_doGet() {
+ return "test3c";
+ }
+
+ public static class Test3aMatcher extends RestMatcher {
+ @Override /* RestMatcher */
+ public boolean matches(RestRequest req) {
+ return req.getParameter("t1","").equals("1");
+ }
+ }
+
+ public static class Test3bMatcher extends RestMatcher {
+ @Override /* RestMatcher */
+ public boolean matches(RestRequest req) {
+ return req.getParameter("t2","").equals("2");
+ }
+ }
+
+ //====================================================================================================
+ // Overlapping matchers
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testOverlappingMatchers2")
+ public String test4a_doGet() {
+ return "test4a";
+ }
+
+ @RestMethod(name="GET", path="/testOverlappingMatchers2", matchers={Test3aMatcher.class, Test3bMatcher.class})
+ public String test4b_doGet() {
+ return "test4b";
+ }
+
+ //====================================================================================================
+ // Overlapping URL patterns
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testOverlappingUrlPatterns")
+ public String testOverlappingUrlPatterns1() {
+ return "test5a";
+ }
+
+ @RestMethod(name="GET", path="/testOverlappingUrlPatterns/*")
+ public String testOverlappingUrlPatterns2() {
+ return "test5b";
+ }
+
+ @RestMethod(name="GET", path="/testOverlappingUrlPatterns/foo")
+ public String testOverlappingUrlPatterns3() {
+ return "test5c";
+ }
+
+ @RestMethod(name="GET", path="/testOverlappingUrlPatterns/foo/*")
+ public String testOverlappingUrlPatterns4() {
+ return "test5d";
+ }
+
+ @RestMethod(name="GET", path="/testOverlappingUrlPatterns/{id}")
+ public String testOverlappingUrlPatterns5() {
+ return "test5e";
+ }
+
+ @RestMethod(name="GET", path="/testOverlappingUrlPatterns/{id}/*")
+ public String testOverlappingUrlPatterns6() {
+ return "test5f";
+ }
+
+ @RestMethod(name="GET", path="/testOverlappingUrlPatterns/{id}/foo")
+ public String testOverlappingUrlPatterns7() {
+ return "test5g";
+ }
+
+ @RestMethod(name="GET", path="/testOverlappingUrlPatterns/{id}/foo/*")
+ public String testOverlappingUrlPatterns8() {
+ return "test5h";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/ParamsResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/ParamsResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/ParamsResource.java
new file mode 100755
index 0000000..d195704
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/ParamsResource.java
@@ -0,0 +1,292 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static org.apache.juneau.server.RestServletContext.*;
+import static org.apache.juneau.urlencoding.UrlEncodingContext.*;
+
+import java.util.*;
+
+import javax.servlet.http.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.json.*;
+import org.apache.juneau.plaintext.*;
+import org.apache.juneau.samples.addressbook.*;
+import org.apache.juneau.server.annotation.*;
+import org.apache.juneau.transforms.*;
+import org.apache.juneau.urlencoding.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testParams",
+ serializers=PlainTextSerializer.class,
+ properties={
+ @Property(name=REST_allowMethodParam, value="*")
+ }
+)
+public class ParamsResource extends RestServletDefault {
+ private static final long serialVersionUID = 1L;
+
+ //====================================================================================================
+ // Basic tests
+ //====================================================================================================
+ @RestMethod(name="GET", path="/")
+ public void doGet(RestResponse res) {
+ res.setOutput("GET");
+ }
+
+ @RestMethod(name="GET", path="/get1")
+ public String doGet1() {
+ return "GET /get1";
+ }
+
+ @RestMethod(name="GET", path="/get1/{foo}")
+ public void doGet1a(RestResponse res, String foo) {
+ res.setOutput("GET /get1a " + foo);
+ }
+
+ @RestMethod(name="GET", path="/get1/{foo}/{bar}")
+ public void doGet1b(RestResponse res, String foo, String bar) {
+ res.setOutput("GET /get1b " + foo + "," + bar);
+ }
+
+ @RestMethod(name="GET", path="/get3/{foo}/{bar}/*")
+ public void doGet3(HttpServletRequest reqx, HttpServletResponse resx, String foo, int bar) {
+ RestRequest req = (RestRequest)reqx;
+ RestResponse res = (RestResponse)resx;
+ res.setOutput("GET /get3/"+foo+"/"+bar+" remainder="+req.getPathRemainder());
+ }
+
+ // Test method name with overlapping name, remainder allowed.
+ @RestMethod(name="GET2")
+ public void get2(RestRequest req, RestResponse res) {
+ res.setOutput("GET2 remainder="+req.getPathRemainder());
+ }
+
+ // Default POST
+ @RestMethod(name="POST")
+ public void doPost(RestRequest req, RestResponse res) {
+ res.setOutput("POST remainder="+req.getPathRemainder());
+ }
+
+ // Bean parameter
+ @RestMethod(name="POST", path="/person/{person}")
+ public void doPost(RestRequest req, RestResponse res, Person p) {
+ res.setOutput("POST /person/{name="+p.name+",birthDate.year="+p.birthDate.get(Calendar.YEAR)+"} remainder="+req.getPathRemainder());
+ }
+
+ // Various primitive types
+ @RestMethod(name="PUT", path="/primitives/{xInt}/{xShort}/{xLong}/{xChar}/{xFloat}/{xDouble}/{xByte}/{xBoolean}")
+ public void doPut1(RestResponse res, int xInt, short xShort, long xLong, char xChar, float xFloat, double xDouble, byte xByte, boolean xBoolean) {
+ res.setOutput("PUT /primitives/"+xInt+"/"+xShort+"/"+xLong+"/"+xChar+"/"+xFloat+"/"+xDouble+"/"+xByte+"/"+xBoolean);
+ }
+
+ // Various primitive objects
+ @RestMethod(name="PUT", path="/primitiveObjects/{xInt}/{xShort}/{xLong}/{xChar}/{xFloat}/{xDouble}/{xByte}/{xBoolean}")
+ public void doPut2(RestResponse res, Integer xInt, Short xShort, Long xLong, Character xChar, Float xFloat, Double xDouble, Byte xByte, Boolean xBoolean) {
+ res.setOutput("PUT /primitiveObjects/"+xInt+"/"+xShort+"/"+xLong+"/"+xChar+"/"+xFloat+"/"+xDouble+"/"+xByte+"/"+xBoolean);
+ }
+
+ // Object with forString(String) method
+ @RestMethod(name="PUT", path="/uuid/{uuid}")
+ public void doPut1(RestResponse res, UUID uuid) {
+ res.setOutput("PUT /uuid/"+uuid);
+ }
+
+ @Override /* RestServlet */
+ public Class<?>[] createTransforms() {
+ return new Class[]{CalendarSwap.Medium.class};
+ }
+
+ //====================================================================================================
+ // @Param annotation - GET
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testParamGet/*")
+ public String testParamGet(RestRequest req, @Param("p1") String p1, @Param("p2") int p2) throws Exception {
+ return "p1=["+p1+","+req.getParameter("p1")+","+req.getParameter("p1", String.class)+"],p2=["+p2+","+req.getParameter("p2")+","+req.getParameter("p2", int.class)+"]";
+ }
+
+ //====================================================================================================
+ // @Param annotation - POST
+ //====================================================================================================
+ @RestMethod(name="POST", path="/testParamPost/*")
+ public String testParamPost(RestRequest req, @Param("p1") String p1, @Param("p2") int p2) throws Exception {
+ return "p1=["+p1+","+req.getParameter("p1")+","+req.getParameter("p1", String.class)+"],p2=["+p2+","+req.getParameter("p2")+","+req.getParameter("p2", int.class)+"]";
+ }
+
+ //====================================================================================================
+ // @QParam annotation - GET
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testQParamGet/*")
+ public String testQParamGet(RestRequest req, @QParam("p1") String p1, @QParam("p2") int p2) throws Exception {
+ return "p1=["+p1+","+req.getQueryParameter("p1")+","+req.getQueryParameter("p1", String.class)+"],p2=["+p2+","+req.getQueryParameter("p2")+","+req.getQueryParameter("p2", int.class)+"]";
+ }
+
+ //====================================================================================================
+ // @QParam annotation - POST
+ //====================================================================================================
+ @RestMethod(name="POST", path="/testQParamPost/*")
+ public String testQParamPost(RestRequest req, @QParam("p1") String p1, @QParam("p2") int p2) throws Exception {
+ return "p1=["+p1+","+req.getQueryParameter("p1")+","+req.getQueryParameter("p1", String.class)+"],p2=["+p2+","+req.getQueryParameter("p2")+","+req.getQueryParameter("p2", int.class)+"]";
+ }
+
+ //====================================================================================================
+ // @Param(format=PLAIN) annotation - GET
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testPlainParamGet/*")
+ public String testPlainParamGet(RestRequest req, @Param(value="p1",format="PLAIN") String p1) throws Exception {
+ return "p1=["+p1+","+req.getParameter("p1")+","+req.getParameter("p1", String.class)+"]";
+ }
+
+ //====================================================================================================
+ // @Param(format=PLAIN) annotation - POST
+ //====================================================================================================
+ @RestMethod(name="POST", path="/testPlainParamPost/*")
+ public String testPlainParamPost(RestRequest req, @Param(value="p1",format="PLAIN") String p1) throws Exception {
+ return "p1=["+p1+","+req.getParameter("p1")+","+req.getParameter("p1", String.class)+"]";
+ }
+
+ //====================================================================================================
+ // @QParam(format=PLAIN) annotation - GET
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testPlainQParamGet/*")
+ public String testPlainQParamGet(RestRequest req, @QParam(value="p1",format="PLAIN") String p1) throws Exception {
+ return "p1=["+p1+","+req.getQueryParameter("p1")+","+req.getQueryParameter("p1", String.class)+"]";
+ }
+
+ //====================================================================================================
+ // @QParam(format=PLAIN) annotation - POST
+ //====================================================================================================
+ @RestMethod(name="POST", path="/testPlainQParamPost/*")
+ public String testPlainQParamPost(RestRequest req, @QParam(value="p1",format="PLAIN") String p1) throws Exception {
+ return "p1=["+p1+","+req.getQueryParameter("p1")+","+req.getQueryParameter("p1", String.class)+"]";
+ }
+
+ //====================================================================================================
+ // @HasParam annotation - GET
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testHasParamGet/*")
+ public String testHasParamGet(RestRequest req, @HasParam("p1") boolean p1, @HasParam("p2") Boolean p2) throws Exception {
+ return "p1=["+p1+","+req.hasParameter("p1")+"],p2=["+p2+","+req.hasParameter("p2")+"]";
+ }
+
+ //====================================================================================================
+ // @HasParam annotation - POST
+ //====================================================================================================
+ @RestMethod(name="POST", path="/testHasParamPost/*")
+ public String testHasParamPost(RestRequest req, @HasParam("p1") boolean p1, @HasParam("p2") Boolean p2) throws Exception {
+ return "p1=["+p1+","+req.hasParameter("p1")+"],p2=["+p2+","+req.hasParameter("p2")+"]";
+ }
+
+ //====================================================================================================
+ // @HasQParam annotation - GET
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testHasQParamGet/*")
+ public String testHasQParamGet(RestRequest req, @HasQParam("p1") boolean p1, @HasQParam("p2") Boolean p2) throws Exception {
+ return "p1=["+p1+","+req.hasQueryParameter("p1")+"],p2=["+p2+","+req.hasQueryParameter("p2")+"]";
+ }
+
+ //====================================================================================================
+ // @HasQParam annotation - POST
+ //====================================================================================================
+ @RestMethod(name="POST", path="/testHasQParamPost/*")
+ public String testHasQParamPost_post(RestRequest req, @HasQParam("p1") boolean p1, @HasQParam("p2") Boolean p2) throws Exception {
+ return "p1=["+p1+","+req.hasQueryParameter("p1")+"],p2=["+p2+","+req.hasQueryParameter("p2")+"]";
+ }
+
+ //====================================================================================================
+ // Form POSTS with @Content parameter
+ //====================================================================================================
+ @RestMethod(name="POST", path="/testFormPostAsContent/*")
+ public String testFormPostAsContent(@Content Test6Bean bean,
+ @HasQParam("p1") boolean hqp1, @HasQParam("p2") boolean hqp2,
+ @QParam("p1") String qp1, @QParam("p2") int qp2) throws Exception {
+ return "bean=["+JsonSerializer.DEFAULT_LAX.toString(bean)+"],qp1=["+qp1+"],qp2=["+qp2+"],hqp1=["+hqp1+"],hqp2=["+hqp2+"]";
+ }
+
+ public static class Test6Bean {
+ public String p1;
+ public int p2;
+ }
+
+ //====================================================================================================
+ // Test @Param and @QParam annotations when using multi-part parameters (e.g. &key=val1,&key=val2).
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testMultiPartParams")
+ public String testMultiPartParams(
+ @QParam(value="p1",multipart=true) String[] p1,
+ @QParam(value="p2",multipart=true) int[] p2,
+ @QParam(value="p3",multipart=true) List<String> p3,
+ @QParam(value="p4",multipart=true) List<Integer> p4,
+ @Param(value="p5",multipart=true) String[] p5,
+ @Param(value="p6",multipart=true) int[] p6,
+ @Param(value="p7",multipart=true) List<String> p7,
+ @Param(value="p8",multipart=true) List<Integer> p8,
+ @QParam(value="p9",multipart=true) A[] p9,
+ @QParam(value="p10",multipart=true) List<A> p10,
+ @Param(value="p11",multipart=true) A[] p11,
+ @Param(value="p12",multipart=true) List<A> p12) throws Exception {
+ ObjectMap m = new ObjectMap()
+ .append("p1", p1)
+ .append("p2", p2)
+ .append("p3", p3)
+ .append("p4", p4)
+ .append("p5", p5)
+ .append("p6", p6)
+ .append("p7", p7)
+ .append("p8", p8)
+ .append("p9", p9)
+ .append("p10", p10)
+ .append("p11", p11)
+ .append("p12", p12);
+ return JsonSerializer.DEFAULT_LAX.toString(m);
+ }
+
+ public static class A {
+ public String a;
+ public int b;
+ public boolean c;
+ }
+
+ //====================================================================================================
+ // Test multi-part parameter keys on bean properties of type array/Collection (i.e. &key=val1,&key=val2)
+ // using URLENC_expandedParams property.
+ // A simple round-trip test to verify that both serializing and parsing works.
+ //====================================================================================================
+ @RestMethod(name="POST", path="/testFormPostsWithMultiParamsUsingProperty",
+ properties={
+ @Property(name=URLENC_expandedParams, value="true"),
+ @Property(name=UonSerializerContext.UON_simpleMode, value="true")
+ }
+ )
+ public DTO2s.B testFormPostsWithMultiParamsViaProperty(@Content DTO2s.B content) throws Exception {
+ return content;
+ }
+
+ //====================================================================================================
+ // Test multi-part parameter keys on bean properties of type array/Collection (i.e. &key=val1,&key=val2)
+ // using @UrlEncoding(expandedParams=true) annotation.
+ // A simple round-trip test to verify that both serializing and parsing works.
+ //====================================================================================================
+ @RestMethod(name="POST", path="/testFormPostsWithMultiParamsUsingAnnotation",
+ properties={
+ @Property(name=UonSerializerContext.UON_simpleMode, value="true")
+ }
+ )
+ public DTO2s.C testFormPostsWithMultiParamsUsingAnnotation(@Content DTO2s.C content) throws Exception {
+ return content;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/ParsersResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/ParsersResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/ParsersResource.java
new file mode 100755
index 0000000..1584ece
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/ParsersResource.java
@@ -0,0 +1,111 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static org.apache.juneau.server.annotation.Inherit.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.annotation.*;
+import org.apache.juneau.internal.*;
+import org.apache.juneau.parser.*;
+import org.apache.juneau.plaintext.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ * Validates correct parser is used.
+ */
+@RestResource(
+ path="/testParsers",
+ parsers=ParsersResource.TestParserA.class,
+ serializers=PlainTextSerializer.class
+)
+public class ParsersResource extends RestServletDefault {
+ private static final long serialVersionUID = 1L;
+
+ @Consumes("text/a")
+ public static class TestParserA extends ReaderParser {
+ @SuppressWarnings("unchecked")
+ @Override /* Parser */
+ protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception {
+ return (T)("text/a - " + IOUtils.read(session.getReader()).trim());
+ }
+ }
+
+ //====================================================================================================
+ // Parser defined on class.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testParserOnClass")
+ public String testParserOnClass(@Content String in) {
+ return in;
+ }
+
+ //====================================================================================================
+ // Parser defined on method.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testParserOnMethod", parsers=TestParserB.class)
+ public String testParserOnMethod(@Content String in) {
+ return in;
+ }
+
+ @Consumes("text/b")
+ public static class TestParserB extends ReaderParser {
+ @SuppressWarnings("unchecked")
+ @Override /* Parser */
+ protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception {
+ return (T)("text/b - " + IOUtils.read(session.getReader()).trim());
+ }
+ }
+
+ //====================================================================================================
+ // Parser overridden on method.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testParserOverriddenOnMethod", parsers={TestParserB.class,TestParserC.class}, parsersInherit=PARSERS)
+ public String testParserOverriddenOnMethod(@Content String in) {
+ return in;
+ }
+
+ @Consumes("text/c")
+ public static class TestParserC extends ReaderParser {
+ @SuppressWarnings("unchecked")
+ @Override /* Parser */
+ protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception {
+ return (T)("text/c - " + IOUtils.read(session.getReader()).trim());
+ }
+ }
+
+ //====================================================================================================
+ // Parser with different Accept than Content-Type.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testParserWithDifferentMediaTypes", parsers={TestParserD.class}, parsersInherit=PARSERS)
+ public String testParserWithDifferentMediaTypes(@Content String in) {
+ return in;
+ }
+
+ @Consumes({"text/a","text/d"})
+ public static class TestParserD extends ReaderParser {
+ @SuppressWarnings("unchecked")
+ @Override /* Parser */
+ protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception {
+ return (T)("text/d - " + IOUtils.read(session.getReader()).trim());
+ }
+ }
+
+ //====================================================================================================
+ // Check for valid error response.
+ //====================================================================================================
+ @RestMethod(name="PUT", path="/testValidErrorResponse")
+ public String testValidErrorResponse(@Content String in) {
+ return in;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/PathResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/PathResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/PathResource.java
new file mode 100755
index 0000000..f7170e5
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/PathResource.java
@@ -0,0 +1,68 @@
+/***************************************************************************************************************************
+ * 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;
+
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ * Tests the RestServlet.getPath() method.
+ */
+@RestResource(
+ path="/testPath",
+ children={
+ PathResource.TestPath2.class
+ }
+)
+public class PathResource extends RestServletDefault {
+ private static final long serialVersionUID = 1L;
+
+ //====================================================================================================
+ // Basic tests
+ //====================================================================================================
+ @RestMethod(name="GET", path="/")
+ public String doGet() {
+ return getPath();
+ }
+
+ @RestResource(
+ path="/testPath2",
+ children={
+ PathResource.TestPath3.class
+ }
+ )
+ public static class TestPath2 extends RestServletDefault {
+ private static final long serialVersionUID = 1L;
+ // Basic tests
+ @RestMethod(name="GET", path="/")
+ public String doGet() {
+ return getPath();
+ }
+ }
+
+ @RestResource(
+ path="/testPath3"
+ )
+ public static class TestPath3a extends RestServletDefault {
+ private static final long serialVersionUID = 1L;
+ // Basic tests
+ @RestMethod(name="GET", path="/")
+ public String doGet() {
+ return getPath();
+ }
+ }
+
+ public static class TestPath3 extends TestPath3a {
+ private static final long serialVersionUID = 1L;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/PathsResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/PathsResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/PathsResource.java
new file mode 100755
index 0000000..ec4ebf4
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/PathsResource.java
@@ -0,0 +1,72 @@
+/***************************************************************************************************************************
+ * 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;
+
+import org.apache.juneau.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ * Tests the URL-related methods on RestRequest.
+ */
+@RestResource(
+ path="/testPaths",
+ children={
+ PathsResource.A.class
+ }
+)
+public class PathsResource extends RestServletDefault {
+ private static final long serialVersionUID = 1L;
+
+ @RestMethod(name="GET", path="/*")
+ public ObjectMap doGet1(RestRequest req, @PathRemainder String r) {
+ return getPaths(req).append("pathRemainder2", r).append("method",1);
+ }
+
+ @RestMethod(name="GET", path="/test2/*")
+ public ObjectMap doGet2(RestRequest req, @PathRemainder String r) {
+ return getPaths(req).append("pathRemainder2", r).append("method",2);
+ }
+
+ @RestResource(
+ path="/a"
+ )
+ public static class A extends RestServletDefault {
+ private static final long serialVersionUID = 1L;
+ @RestMethod(name="GET", path="/*")
+ public ObjectMap doGet1(RestRequest req, @PathRemainder String r) {
+ return getPaths(req).append("pathRemainder2", r).append("method",3);
+ }
+ @RestMethod(name="GET", path="/test2/*")
+ public ObjectMap doGet2(RestRequest req, @PathRemainder String r) {
+ return getPaths(req).append("pathRemainder2", r).append("method",4);
+ }
+ }
+
+ private static ObjectMap getPaths(RestRequest req) {
+ return new ObjectMap()
+ .append("pathInfo", req.getPathInfo())
+ .append("pathInfoUndecoded", req.getPathInfoUndecoded())
+ .append("pathInfoParts", req.getPathInfoParts())
+ .append("pathRemainder", req.getPathRemainder())
+ .append("pathRemainderUndecoded", req.getPathRemainderUndecoded())
+ .append("requestURI", req.getRequestURI())
+ .append("requestParentURI", req.getRequestParentURI())
+ .append("requestURL", req.getRequestURL())
+ .append("servletPath", req.getServletPath())
+ .append("servletURI", req.getServletURI())
+ .append("servletParentURI", req.getServletParentURI())
+ .append("relativeServletURI", req.getRelativeServletURI());
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/PropertiesResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/PropertiesResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/PropertiesResource.java
new file mode 100755
index 0000000..8cf5154
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/PropertiesResource.java
@@ -0,0 +1,89 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static java.lang.String.*;
+
+import org.apache.juneau.*;
+import org.apache.juneau.annotation.*;
+import org.apache.juneau.serializer.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testProperties",
+ properties={
+ @Property(name="A1",value="a1"),
+ @Property(name="A2",value="a2"),
+ @Property(name="foo",value="bar"),
+ @Property(name="bar",value="baz"),
+ @Property(name="R1a",value="$R{requestURI}"),
+ @Property(name="R1b",value="$R{requestParentURI}"),
+ @Property(name="R2",value="$R{foo}"),
+ @Property(name="R3",value="$R{$R{foo}}"),
+ @Property(name="R4",value="$R{A1}"),
+ @Property(name="R5",value="$R{A2}"),
+ @Property(name="R6",value="$R{C}"),
+ }
+)
+public class PropertiesResource extends RestServletDefault {
+ private static final long serialVersionUID = 1L;
+
+ //====================================================================================================
+ // Properties defined on method.
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testPropertiesDefinedOnMethod",
+ properties={
+ @Property(name="B1",value="b1"),
+ @Property(name="B2",value="b2")
+ },
+ serializers=PropertySerializer1.class
+ )
+ public void testPropertiesDefinedOnMethod(RestResponse res) {
+ res.setProperty("A2", "c");
+ res.setProperty("B2", "c");
+ res.setProperty("C", "c");
+ res.setOutput(null);
+ }
+
+ @Produces({"application/json","text/json"})
+ public static class PropertySerializer1 extends WriterSerializer {
+ @Override /* Serializer */
+ protected void doSerialize(SerializerSession session, Object output) throws Exception {
+ ObjectMap p = session.getProperties();
+ session.getWriter().write(format("A1=%s,A2=%s,B1=%s,B2=%s,C=%s,R1a=%s,R1b=%s,R2=%s,R3=%s,R4=%s,R5=%s,R6=%s",
+ p.get("A1"), p.get("A2"), p.get("B1"), p.get("B2"), p.get("C"),
+ p.get("R1a"), p.get("R1b"), p.get("R2"), p.get("R3"), p.get("R4"), p.get("R5"), p.get("R6")));
+ }
+ }
+
+ //====================================================================================================
+ // Make sure attributes/parameters/headers are available through ctx.getProperties().
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testProperties/{A}", serializers=PropertySerializer2.class)
+ public void testProperties(RestResponse res) {
+ res.setOutput(null);
+ }
+
+ @Produces({"application/json","text/json"})
+ public static class PropertySerializer2 extends WriterSerializer {
+ @Override /* Serializer */
+ protected void doSerialize(SerializerSession session, Object output) throws Exception {
+ ObjectMap p = session.getProperties();
+ session.getWriter().write(format("A=%s,P=%s,H=%s", p.get("A"), p.get("P"), p.get("h")));
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/RestClient2Resource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/RestClient2Resource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/RestClient2Resource.java
new file mode 100755
index 0000000..d1c3761
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/RestClient2Resource.java
@@ -0,0 +1,35 @@
+/***************************************************************************************************************************
+ * 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;
+
+import java.io.*;
+
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testRestClient"
+)
+public class RestClient2Resource extends RestServletDefault {
+ private static final long serialVersionUID = 1L;
+
+ //====================================================================================================
+ // Echo response
+ //====================================================================================================
+ @RestMethod(name="POST", path="/")
+ public Reader test1(RestRequest req) throws Exception {
+ return new StringReader(req.getInputAsString());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/Root.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/Root.java b/juneau-server-test/src/main/java/org/apache/juneau/server/Root.java
index 29d1fc2..46a3596 100755
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/Root.java
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/Root.java
@@ -19,44 +19,44 @@ import org.apache.juneau.server.labels.*;
@RestResource(
path="/",
children={
- TestAcceptCharset.class,
- TestBeanContextProperties.class,
- TestCallbackStrings.class,
- TestCharsetEncodings.class,
- TestClientVersion.class,
- TestConfig.class,
- TestContent.class,
- TestDefaultContentTypes.class,
- TestErrorConditions.class,
- TestTransforms.class,
- TestGroups.class,
- TestGzip.TestGzipOff.class,
- TestGzip.TestGzipOn.class,
- TestInheritance.TestEncoders.class,
- TestInheritance.TestTransforms.class,
- TestInheritance.TestParsers.class,
- TestInheritance.TestProperties.class,
- TestInheritance.TestSerializers.class,
- TestLargePojos.class,
- TestMessages.TestMessages2.class,
- TestMessages.class,
- TestNls.class,
- TestNlsProperty.class,
- TestNoParserInput.class,
- TestOnPostCall.class,
- TestOnPreCall.class,
- TestOptionsWithoutNls.class,
- TestOverlappingMethods.class,
- TestParams.class,
- TestParsers.class,
- TestPath.class,
- TestPaths.class,
- TestProperties.class,
- TestRestClient2.class,
- TestSerializers.class,
- TestStaticFiles.class,
- TestUris.class,
- TestUrlContent.class,
+ AcceptCharsetResource.class,
+ BeanContextPropertiesResource.class,
+ CallbackStringsResource.class,
+ CharsetEncodingsResource.class,
+ ClientVersionResource.class,
+ ConfigResource.class,
+ ContentResource.class,
+ DefaultContentTypesResource.class,
+ ErrorConditionsResource.class,
+ TransformsResource.class,
+ GroupsResource.class,
+ GzipResource.TestGzipOff.class,
+ GzipResource.TestGzipOn.class,
+ InheritanceResource.TestEncoders.class,
+ InheritanceResource.TestTransforms.class,
+ InheritanceResource.TestParsers.class,
+ InheritanceResource.TestProperties.class,
+ InheritanceResource.TestSerializers.class,
+ LargePojosResource.class,
+ MessagesResource.Messages2Resource.class,
+ MessagesResource.class,
+ NlsResource.class,
+ NlsPropertyResource.class,
+ NoParserInputResource.class,
+ OnPostCallResource.class,
+ OnPreCallResource.class,
+ OptionsWithoutNlsResource.class,
+ OverlappingMethodsResource.class,
+ ParamsResource.class,
+ ParsersResource.class,
+ PathResource.class,
+ PathsResource.class,
+ PropertiesResource.class,
+ RestClient2Resource.class,
+ SerializersResource.class,
+ StaticFilesResource.class,
+ UrisResource.class,
+ UrlContentResource.class,
ShutdownResource.class
}
)
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/SerializersResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/SerializersResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/SerializersResource.java
new file mode 100755
index 0000000..61e9ae6
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/SerializersResource.java
@@ -0,0 +1,102 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static org.apache.juneau.server.annotation.Inherit.*;
+
+import org.apache.juneau.annotation.*;
+import org.apache.juneau.serializer.*;
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testSerializers",
+ serializers=SerializersResource.TestSerializerA.class
+)
+public class SerializersResource extends RestServletDefault {
+ private static final long serialVersionUID = 1L;
+
+ @Produces("text/a")
+ public static class TestSerializerA extends WriterSerializer {
+ @Override /* Serializer */
+ protected void doSerialize(SerializerSession session, Object o) throws Exception {
+ session.getWriter().write("text/a - " + o);
+ }
+ }
+
+ @Produces("text/b")
+ public static class TestSerializerB extends WriterSerializer {
+ @Override /* Serializer */
+ protected void doSerialize(SerializerSession session, Object o) throws Exception {
+ session.getWriter().write("text/b - " + o);
+ }
+ }
+
+ //====================================================================================================
+ // Serializer defined on class.
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testSerializerOnClass")
+ public String testSerializerOnClass() {
+ return "test1";
+ }
+
+ //====================================================================================================
+ // Serializer defined on method.
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testSerializerOnMethod", serializers=TestSerializerB.class)
+ public String testSerializerOnMethod() {
+ return "test2";
+ }
+
+ //====================================================================================================
+ // Serializer overridden on method.
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testSerializerOverriddenOnMethod", serializers={TestSerializerB.class,TestSerializerC.class}, serializersInherit=SERIALIZERS)
+ public String testSerializerOverriddenOnMethod() {
+ return "test3";
+ }
+
+ @Produces("text/a")
+ public static class TestSerializerC extends WriterSerializer {
+ @Override /* Serializer */
+ protected void doSerialize(SerializerSession session, Object o) throws Exception {
+ session.getWriter().write("text/c - " + o);
+ }
+ }
+
+ //====================================================================================================
+ // Serializer with different Accept than Content-Type.
+ //====================================================================================================
+ @RestMethod(name="GET", path="/testSerializerWithDifferentMediaTypes", serializers={TestSerializerD.class}, serializersInherit=SERIALIZERS)
+ public String testSerializerWithDifferentMediaTypes() {
+ return "test4";
+ }
+
+ @Produces(value={"text/a","text/d"},contentType="text/d")
+ public static class TestSerializerD extends WriterSerializer {
+ @Override /* Serializer */
+ protected void doSerialize(SerializerSession session, Object o) throws Exception {
+ session.getWriter().write("text/d - " + o);
+ }
+ }
+
+ //====================================================================================================
+ // Check for valid 406 error response.
+ //====================================================================================================
+ @RestMethod(name="GET", path="/test406")
+ public String test406() {
+ return "test406";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/StaticFilesResource.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/StaticFilesResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/StaticFilesResource.java
new file mode 100755
index 0000000..8ef1d8f
--- /dev/null
+++ b/juneau-server-test/src/main/java/org/apache/juneau/server/StaticFilesResource.java
@@ -0,0 +1,35 @@
+/***************************************************************************************************************************
+ * 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;
+
+import org.apache.juneau.server.annotation.*;
+
+/**
+ * JUnit automated testcase resource.
+ */
+@RestResource(
+ path="/testStaticFiles",
+ staticFiles="{xdocs:'xdocs'}"
+)
+public class StaticFilesResource extends RestServlet {
+ private static final long serialVersionUID = 1L;
+
+ //====================================================================================================
+ // Tests the @RestResource(staticFiles) annotation.
+ //====================================================================================================
+ @RestMethod(name="GET", path="/*")
+ public String testXdocs() {
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestAcceptCharset.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestAcceptCharset.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestAcceptCharset.java
deleted file mode 100755
index 9efa109..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestAcceptCharset.java
+++ /dev/null
@@ -1,75 +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.server;
-
-import static org.apache.juneau.server.RestServletContext.*;
-
-import java.io.*;
-
-import org.apache.juneau.*;
-import org.apache.juneau.annotation.*;
-import org.apache.juneau.parser.*;
-import org.apache.juneau.plaintext.*;
-import org.apache.juneau.serializer.*;
-import org.apache.juneau.server.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testAcceptCharset",
- serializers={PlainTextSerializer.class},
- properties={
- // Some versions of Jetty default to ISO8601, so specify UTF-8 for test consistency.
- @Property(name=REST_defaultCharset,value="utf-8")
- }
-)
-public class TestAcceptCharset 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(@Content String in) {
- return in;
- }
-
- @Consumes("text/plain")
- public static class TestParser extends InputStreamParser {
- @SuppressWarnings("unchecked")
- @Override /* Parser */
- protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception {
- return (T)session.getProperties().getString("characterEncoding");
- }
- }
-
- @Produces("text/plain")
- public static class TestSerializer extends OutputStreamSerializer {
- @Override /* Serializer */
- protected void doSerialize(SerializerSession session, Object o) throws Exception {
- Writer w = new OutputStreamWriter(session.getOutputStream());
- w.append(o.toString()).append('/').append(session.getProperties().getString("characterEncoding"));
- w.flush();
- w.close();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestBeanContextProperties.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestBeanContextProperties.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestBeanContextProperties.java
deleted file mode 100755
index da7abe2..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestBeanContextProperties.java
+++ /dev/null
@@ -1,41 +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.server;
-
-import java.io.*;
-import java.util.*;
-
-import org.apache.juneau.server.annotation.*;
-import org.apache.juneau.transforms.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testBeanContext",
- transforms=DateSwap.ISO8601DTZ.class
-)
-public class TestBeanContextProperties extends RestServletDefault {
- private static final long serialVersionUID = 1L;
-
- //====================================================================================================
- // Validate that transforms defined on class transform to underlying bean context.
- //====================================================================================================
- @RestMethod(name="GET", path="/testClassTransforms/{d1}")
- public Reader testClassTransforms(@Attr("d1") Date d1, @Param("d2") Date d2, @Header("X-D3") Date d3) throws Exception {
- DateSwap df = DateSwap.ISO8601DTZ.class.newInstance();
- return new StringReader(
- "d1="+df.swap(d1)+",d2="+df.swap(d2)+",d3="+df.swap(d3)+""
- );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestCallbackStrings.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestCallbackStrings.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestCallbackStrings.java
deleted file mode 100755
index 4527f26..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestCallbackStrings.java
+++ /dev/null
@@ -1,52 +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.server;
-
-import java.util.*;
-
-import org.apache.juneau.*;
-import org.apache.juneau.server.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testCallback"
-)
-public class TestCallbackStrings extends RestServletDefault {
- private static final long serialVersionUID = 1L;
-
- //====================================================================================================
- // Test GET
- //====================================================================================================
- @RestMethod(name="GET", path="/")
- public ObjectMap test1(RestRequest req) throws Exception {
- return new ObjectMap().append("method","GET").append("headers", getFooHeaders(req)).append("content", req.getInputAsString());
- }
-
- //====================================================================================================
- // Test PUT
- //====================================================================================================
- @RestMethod(name="PUT", path="/")
- public ObjectMap testCharsetOnResponse(RestRequest req) throws Exception {
- return new ObjectMap().append("method","PUT").append("headers", getFooHeaders(req)).append("content", req.getInputAsString());
- }
-
- private Map<String,Object> getFooHeaders(RestRequest req) {
- Map<String,Object> m = new TreeMap<String,Object>();
- for (Map.Entry<String,Object> e : req.getHeaders().entrySet())
- if (e.getKey().startsWith("Foo-"))
- m.put(e.getKey(), e.getValue());
- return m;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestCharsetEncodings.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestCharsetEncodings.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestCharsetEncodings.java
deleted file mode 100755
index f95b368..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestCharsetEncodings.java
+++ /dev/null
@@ -1,54 +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.server;
-
-import org.apache.juneau.*;
-import org.apache.juneau.annotation.*;
-import org.apache.juneau.internal.*;
-import org.apache.juneau.parser.*;
-import org.apache.juneau.serializer.*;
-import org.apache.juneau.server.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testCharsetEncodings",
- defaultRequestHeaders={"Accept: text/s", "Content-Type: text/p"},
- parsers={TestCharsetEncodings.CtParser.class}, serializers={TestCharsetEncodings.ASerializer.class}
-)
-public class TestCharsetEncodings extends RestServlet {
- private static final long serialVersionUID = 1L;
-
- @Consumes("text/p")
- public static class CtParser extends ReaderParser {
- @SuppressWarnings("unchecked")
- @Override /* Parser */
- protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception {
- return (T)IOUtils.read(session.getReader());
- }
- }
-
- @Produces("text/s")
- public static class ASerializer extends WriterSerializer {
- @Override /* Serializer */
- protected void doSerialize(SerializerSession session, Object o) throws Exception {
- session.getWriter().write(o.toString());
- }
- }
-
- @RestMethod(name="PUT", path="/")
- public String test1(RestRequest req, @Content String in) {
- return req.getCharacterEncoding() + "/" + in + "/" + req.getCharacterEncoding();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestClientVersion.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestClientVersion.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestClientVersion.java
deleted file mode 100644
index 65fec38..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestClientVersion.java
+++ /dev/null
@@ -1,93 +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.server;
-
-import org.apache.juneau.microservice.*;
-import org.apache.juneau.server.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testClientVersion",
- children={
- TestClientVersion.DefaultHeader.class,
- TestClientVersion.CustomHeader.class
- }
-)
-@SuppressWarnings("serial")
-public class TestClientVersion extends Resource {
-
- @RestResource(
- path="/defaultHeader"
- )
- public static class DefaultHeader extends Resource {
-
- @RestMethod(name="GET", path="/")
- public String test0() {
- return "no-version";
- }
-
- @RestMethod(name="GET", path="/", clientVersion="[0.0,1.0)")
- public String test1() {
- return "[0.0,1.0)";
- }
-
- @RestMethod(name="GET", path="/", clientVersion="[1.0,1.0]")
- public String test2() {
- return "[1.0,1.0]";
- }
-
- @RestMethod(name="GET", path="/", clientVersion="[1.1,2)")
- public String test3() {
- return "[1.1,2)";
- }
-
- @RestMethod(name="GET", path="/", clientVersion="2")
- public String test4() {
- return "2";
- }
- }
-
- @RestResource(
- path="/customHeader",
- clientVersionHeader="Custom-Client-Version"
- )
- public static class CustomHeader extends Resource {
-
- @RestMethod(name="GET", path="/")
- public String test0() {
- return "no-version";
- }
-
- @RestMethod(name="GET", path="/", clientVersion="[0.0,1.0)")
- public String test1() {
- return "[0.0,1.0)";
- }
-
- @RestMethod(name="GET", path="/", clientVersion="[1.0,1.0]")
- public String test2() {
- return "[1.0,1.0]";
- }
-
- @RestMethod(name="GET", path="/", clientVersion="[1.1,2)")
- public String test3() {
- return "[1.1,2)";
- }
-
- @RestMethod(name="GET", path="/", clientVersion="2")
- public String test4() {
- return "2";
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestConfig.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestConfig.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestConfig.java
deleted file mode 100755
index ceafea0..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestConfig.java
+++ /dev/null
@@ -1,37 +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.server;
-
-import org.apache.juneau.ini.*;
-import org.apache.juneau.microservice.*;
-import org.apache.juneau.server.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testConfig"
-)
-@SuppressWarnings("serial")
-public class TestConfig extends Resource {
-
- @RestMethod(name="GET", path="/")
- public ConfigFile test1(RestRequest req) {
- return req.getConfig();
- }
-
- @RestMethod(name="GET", path="/{key}/{class}")
- public Object test2(RestRequest req, @Attr("key") String key, @Attr("class") Class<?> c) throws Exception {
- return req.getConfig().getObject(c, key);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestContent.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestContent.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestContent.java
deleted file mode 100755
index 036fb5b..0000000
--- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestContent.java
+++ /dev/null
@@ -1,80 +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.server;
-
-import static org.apache.juneau.server.RestServletContext.*;
-
-import java.util.*;
-
-import org.apache.juneau.server.annotation.*;
-
-/**
- * JUnit automated testcase resource.
- */
-@RestResource(
- path="/testContent",
- properties={
- @Property(name=REST_allowMethodParam, value="*")
- }
-)
-public class TestContent extends RestServletDefault {
- private static final long serialVersionUID = 1L;
-
- //====================================================================================================
- // Basic tests
- //====================================================================================================
- @RestMethod(name="POST", path="/boolean")
- public boolean testBool(@Content boolean b) {
- return b;
- }
-
- @RestMethod(name="POST", path="/Boolean")
- public Boolean testBoolean(@Content Boolean b) {
- return b;
- }
-
- @RestMethod(name="POST", path="/int")
- public int testInt(@Content int i) {
- return i;
- }
-
- @RestMethod(name="POST", path="/Integer")
- public Integer testInteger(@Content Integer i) {
- return i;
- }
-
- @RestMethod(name="POST", path="/float")
- public float testFloat(@Content float f) {
- return f;
- }
-
- @RestMethod(name="POST", path="/Float")
- public Float testFloat2(@Content Float f) {
- return f;
- }
-
- @RestMethod(name="POST", path="/Map")
- public TreeMap<String,String> testMap(@Content TreeMap<String,String> m) {
- return m;
- }
-
- @RestMethod(name="POST", path="/B")
- public DTO2s.B testPojo1(@Content DTO2s.B b) {
- return b;
- }
-
- @RestMethod(name="POST", path="/C")
- public DTO2s.C testPojo2(@Content DTO2s.C c) {
- return c;
- }
-}
[02/14] incubator-juneau git commit: Clean up test and test resource
class names.
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestTransformsTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestTransformsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestTransformsTest.java
deleted file mode 100755
index 85be1e2..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestTransformsTest.java
+++ /dev/null
@@ -1,68 +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.server;
-
-import static org.junit.Assert.*;
-
-import org.apache.juneau.client.*;
-import org.apache.juneau.json.*;
-import org.junit.*;
-
-public class TestTransformsTest {
-
- private static String URL = "/testTransforms";
-
- //====================================================================================================
- // test1 - Test class transform overrides parent class transform
- // Should return "A2-1".
- //====================================================================================================
- @Test
- public void testClassTransformOverridesParentClassTransform() throws Exception {
- RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
- String r;
- String url = URL + "/testClassTransformOverridesParentClassTransform";
-
- r = client.doGet(url).getResponse(String.class);
- assertEquals("A2-0", r);
-
- r = client.doPut(url, "A2-1").getResponse(String.class);
- assertEquals("A2-1", r);
-
- r = client.doPut(url + "/A2-2", "").getResponse(String.class);
- assertEquals("A2-2", r);
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // Test method transform overrides class transform
- // Should return "A3-1".
- //====================================================================================================
- @Test
- public void testMethodTransformOverridesClassTransform() throws Exception {
- RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
- String r;
- String url = URL + "/testMethodTransformOverridesClassTransform";
-
- r = client.doGet(url).getResponse(String.class);
- assertEquals("A3-0", r);
-
- r = client.doPut(url, "A3-1").getResponse(String.class);
- assertEquals("A3-1", r);
-
- r = client.doPut(url + "/A3-2", "").getResponse(String.class);
- assertEquals("A3-2", r);
-
- client.closeQuietly();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestUrisTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestUrisTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestUrisTest.java
deleted file mode 100755
index 4cf147e..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestUrisTest.java
+++ /dev/null
@@ -1,918 +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.server;
-
-import static org.junit.Assert.*;
-
-import java.util.regex.*;
-
-import org.apache.juneau.*;
-import org.apache.juneau.client.*;
-import org.apache.juneau.json.*;
-import org.junit.*;
-
-/**
- * Verifies that all the RestRequest.getXXX() methods involving URIs work correctly.
- */
-public class TestUrisTest {
-
- private static String URL2 = Constants.getServerTestUrl() + "/testuris"; // /jazz/juneau/sample/testuris
- private static int port = getPort(Constants.getServerTestUrl()); // 9443
- private static String path = Constants.getServerTestUri().getPath(); // /jazz/juneau/sample
-
- //====================================================================================================
- // testRoot - http://localhost:8080/sample/testuris
- //====================================================================================================
- @Test
- public void testRoot() throws Exception {
- RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
- ObjectMap r;
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris").getResponse(ObjectMap.class);
- assertEquals("root.test1", r.getString("testMethod"));
- assertNull(r.getString("pathInfo"));
- assertNull(r.getString("pathRemainder"));
- assertEquals(path + "/testuris", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris"));
- // Same for servlet
- assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2, r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/foo
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/foo").getResponse(ObjectMap.class);
- assertEquals("root.test1", r.getString("testMethod"));
- assertEquals("/foo", r.getString("pathInfo"));
- assertEquals("foo", r.getString("pathRemainder"));
- assertEquals(path + "/testuris", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/foo", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/foo"));
- // Same for servlet
- assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2, r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/foo/bar
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/foo/bar").getResponse(ObjectMap.class);
- assertEquals("root.test1", r.getString("testMethod"));
- assertEquals("/foo/bar", r.getString("pathInfo"));
- assertEquals("foo/bar", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/foo", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/foo/bar", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/foo/bar"));
- // Same for servlet
- assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2, r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/foo/bar%2Fbaz
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/foo/bar%2Fbaz").getResponse(ObjectMap.class);
- assertEquals("root.test1", r.getString("testMethod"));
- assertEquals("/foo/bar/baz", r.getString("pathInfo"));
- assertEquals("foo/bar/baz", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/foo", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/foo/bar%2Fbaz", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/foo/bar%2Fbaz"));
- // Same for servlet
- assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2, r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/test2
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/test2").getResponse(ObjectMap.class);
- assertEquals("root.test2", r.getString("testMethod"));
- assertEquals("/test2", r.getString("pathInfo"));
- assertNull(r.getString("pathRemainder"));
- assertEquals(path + "/testuris", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/test2", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/test2"));
- // Same for servlet
- assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2, r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/test2/foo
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/test2/foo").getResponse(ObjectMap.class);
- assertEquals("root.test2", r.getString("testMethod"));
- assertEquals("/test2/foo", r.getString("pathInfo"));
- assertEquals("foo", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/test2", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/test2/foo", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/test2/foo"));
- // Same for servlet
- assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2, r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/test2/foo/bar
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/test2/foo/bar").getResponse(ObjectMap.class);
- assertEquals("root.test2", r.getString("testMethod"));
- assertEquals("/test2/foo/bar", r.getString("pathInfo"));
- assertEquals("foo/bar", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/test2/foo", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/test2/foo/bar", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/test2/foo/bar"));
- // Same for servlet
- assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2, r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/test3%2Ftest3
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/test3%2Ftest3").getResponse(ObjectMap.class);
- assertEquals("root.test3", r.getString("testMethod"));
- assertEquals("/test3/test3", r.getString("pathInfo"));
- assertNull(r.getString("pathRemainder"));
- assertEquals(path + "/testuris", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/test3%2Ftest3", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/test3%2Ftest3"));
- // Same for servlet
- assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2, r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/test3%2Ftest3/foo
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/test3%2Ftest3/foo").getResponse(ObjectMap.class);
- assertEquals("root.test3", r.getString("testMethod"));
- assertEquals("/test3/test3/foo", r.getString("pathInfo"));
- assertEquals("foo", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/test3%2Ftest3", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/test3%2Ftest3/foo", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/test3%2Ftest3/foo"));
- // Same for servlet
- assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2, r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/test3%2Ftest3/foo/bar
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/test3%2Ftest3/foo/bar").getResponse(ObjectMap.class);
- assertEquals("root.test3", r.getString("testMethod"));
- assertEquals("/test3/test3/foo/bar", r.getString("pathInfo"));
- assertEquals("foo/bar", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/test3%2Ftest3/foo", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/test3%2Ftest3/foo/bar", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/test3%2Ftest3/foo/bar"));
- // Same for servlet
- assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2, r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/test3%2Ftest3/foo/bar%2Fbaz
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/test3%2Ftest3/foo/bar%2Fbaz").getResponse(ObjectMap.class);
- assertEquals("root.test3", r.getString("testMethod"));
- assertEquals("/test3/test3/foo/bar/baz", r.getString("pathInfo"));
- assertEquals("foo/bar/baz", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/test3%2Ftest3/foo", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/test3%2Ftest3/foo/bar%2Fbaz", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/test3%2Ftest3/foo/bar%2Fbaz"));
- // Same for servlet
- assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2, r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/test4/test4
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/test4/test4").getResponse(ObjectMap.class);
- assertEquals("root.test4", r.getString("testMethod"));
- assertEquals("/test4/test4", r.getString("pathInfo"));
- assertNull(r.getString("pathRemainder"));
- assertEquals(path + "/testuris/test4", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/test4/test4", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/test4/test4"));
- // Same for servlet
- assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2, r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/test4/test4/foo
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/test4/test4/foo").getResponse(ObjectMap.class);
- assertEquals("root.test4", r.getString("testMethod"));
- assertEquals("/test4/test4/foo", r.getString("pathInfo"));
- assertEquals("foo", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/test4/test4", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/test4/test4/foo", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/test4/test4/foo"));
- // Same for servlet
- assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2, r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/test4/test4/foo/bar
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/test4/test4/foo/bar").getResponse(ObjectMap.class);
- assertEquals("root.test4", r.getString("testMethod"));
- assertEquals("/test4/test4/foo/bar", r.getString("pathInfo"));
- assertEquals("foo/bar", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/test4/test4/foo", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/test4/test4/foo/bar", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/test4/test4/foo/bar"));
- // Same for servlet
- assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2, r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/test4/test4/foo/bar%2Fbaz
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/test4/test4/foo/bar%2Fbaz").getResponse(ObjectMap.class);
- assertEquals("root.test4", r.getString("testMethod"));
- assertEquals("/test4/test4/foo/bar/baz", r.getString("pathInfo"));
- assertEquals("foo/bar/baz", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/test4/test4/foo", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/test4/test4/foo/bar%2Fbaz", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/test4/test4/foo/bar%2Fbaz"));
- // Same for servlet
- assertEquals(path + "/testuris", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2, r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // testChild - http://localhost:8080/sample/testuris/child
- //====================================================================================================
- @Test
- public void testChild() throws Exception {
- RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
- ObjectMap r;
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child").getResponse(ObjectMap.class);
- assertEquals("child.test1", r.getString("testMethod"));
- assertNull(r.getString("pathInfo"));
- assertNull(r.getString("pathRemainder"));
- assertEquals(path + "/testuris", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child"));
- // Same for servlet
- assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/foo
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/foo").getResponse(ObjectMap.class);
- assertEquals("child.test1", r.getString("testMethod"));
- assertEquals("/foo", r.getString("pathInfo"));
- assertEquals("foo", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/foo", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/foo"));
- // Same for servlet
- assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/foo/bar
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/foo/bar").getResponse(ObjectMap.class);
- assertEquals("child.test1", r.getString("testMethod"));
- assertEquals("/foo/bar", r.getString("pathInfo"));
- assertEquals("foo/bar", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child/foo", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/foo/bar", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/foo/bar"));
- // Same for servlet
- assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/foo/bar%2Fbaz
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/foo/bar%2Fbaz").getResponse(ObjectMap.class);
- assertEquals("child.test1", r.getString("testMethod"));
- assertEquals("/foo/bar/baz", r.getString("pathInfo"));
- assertEquals("foo/bar/baz", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child/foo", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/foo/bar%2Fbaz", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/foo/bar%2Fbaz"));
- // Same for servlet
- assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/test2
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/test2").getResponse(ObjectMap.class);
- assertEquals("child.test2", r.getString("testMethod"));
- assertEquals("/test2", r.getString("pathInfo"));
- assertNull(r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/test2", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/test2"));
- // Same for servlet
- assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/test2/foo
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/test2/foo").getResponse(ObjectMap.class);
- assertEquals("child.test2", r.getString("testMethod"));
- assertEquals("/test2/foo", r.getString("pathInfo"));
- assertEquals("foo", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child/test2", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/test2/foo", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/test2/foo"));
- // Same for servlet
- assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/test2/foo/bar
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/test2/foo/bar").getResponse(ObjectMap.class);
- assertEquals("child.test2", r.getString("testMethod"));
- assertEquals("/test2/foo/bar", r.getString("pathInfo"));
- assertEquals("foo/bar", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child/test2/foo", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/test2/foo/bar", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/test2/foo/bar"));
- // Same for servlet
- assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/test2/foo/bar%2Fbaz
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/test2/foo/bar%2Fbaz").getResponse(ObjectMap.class);
- assertEquals("child.test2", r.getString("testMethod"));
- assertEquals("/test2/foo/bar/baz", r.getString("pathInfo"));
- assertEquals("foo/bar/baz", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child/test2/foo", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/test2/foo/bar%2Fbaz", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/test2/foo/bar%2Fbaz"));
- // Same for servlet
- assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/test3%2Ftest3
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/test3%2Ftest3").getResponse(ObjectMap.class);
- assertEquals("child.test3", r.getString("testMethod"));
- assertEquals("/test3/test3", r.getString("pathInfo"));
- assertNull(r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/test3%2Ftest3", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/test3%2Ftest3"));
- // Same for servlet
- assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/test3%2Ftest3/foo
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/test3%2Ftest3/foo").getResponse(ObjectMap.class);
- assertEquals("child.test3", r.getString("testMethod"));
- assertEquals("/test3/test3/foo", r.getString("pathInfo"));
- assertEquals("foo", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child/test3%2Ftest3", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/test3%2Ftest3/foo", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/test3%2Ftest3/foo"));
- // Same for servlet
- assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/test3%2Ftest3/foo/bar
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/test3%2Ftest3/foo/bar").getResponse(ObjectMap.class);
- assertEquals("child.test3", r.getString("testMethod"));
- assertEquals("/test3/test3/foo/bar", r.getString("pathInfo"));
- assertEquals("foo/bar", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child/test3%2Ftest3/foo", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/test3%2Ftest3/foo/bar", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/test3%2Ftest3/foo/bar"));
- // Same for servlet
- assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/test3%2Ftest3/foo/bar%2Fbaz
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/test3%2Ftest3/foo/bar%2Fbaz").getResponse(ObjectMap.class);
- assertEquals("child.test3", r.getString("testMethod"));
- assertEquals("/test3/test3/foo/bar/baz", r.getString("pathInfo"));
- assertEquals("foo/bar/baz", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child/test3%2Ftest3/foo", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/test3%2Ftest3/foo/bar%2Fbaz", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/test3%2Ftest3/foo/bar%2Fbaz"));
- // Same for servlet
- assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/test4/test4
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/test4/test4").getResponse(ObjectMap.class);
- assertEquals("child.test4", r.getString("testMethod"));
- assertEquals("/test4/test4", r.getString("pathInfo"));
- assertNull(r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child/test4", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/test4/test4", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/test4/test4"));
- // Same for servlet
- assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/test4/test4/foo
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/test4/test4/foo").getResponse(ObjectMap.class);
- assertEquals("child.test4", r.getString("testMethod"));
- assertEquals("/test4/test4/foo", r.getString("pathInfo"));
- assertEquals("foo", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child/test4/test4", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/test4/test4/foo", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/test4/test4/foo"));
- // Same for servlet
- assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/test4/test4/foo/bar
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/test4/test4/foo/bar").getResponse(ObjectMap.class);
- assertEquals("child.test4", r.getString("testMethod"));
- assertEquals("/test4/test4/foo/bar", r.getString("pathInfo"));
- assertEquals("foo/bar", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child/test4/test4/foo", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/test4/test4/foo/bar", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/test4/test4/foo/bar"));
- // Same for servlet
- assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/test4/test4/foo/bar%2Fbaz
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/test4/test4/foo/bar%2Fbaz").getResponse(ObjectMap.class);
- assertEquals("child.test4", r.getString("testMethod"));
- assertEquals("/test4/test4/foo/bar/baz", r.getString("pathInfo"));
- assertEquals("foo/bar/baz", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child/test4/test4/foo", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/test4/test4/foo/bar%2Fbaz", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/test4/test4/foo/bar%2Fbaz"));
- // Same for servlet
- assertEquals(path + "/testuris/child", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- client.closeQuietly();
- }
-
- //====================================================================================================
- // testGrandChild - http://localhost:8080/sample/testuris/child/grandchild
- //====================================================================================================
- @Test
- public void testGrandChild() throws Exception {
- RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
- ObjectMap r;
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/grandchild").getResponse(ObjectMap.class);
- assertEquals("grandchild.test1", r.getString("testMethod"));
- assertNull(r.getString("pathInfo"));
- assertNull(r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/grandchild", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild"));
- // Same for servlet
- assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/foo
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/grandchild/foo").getResponse(ObjectMap.class);
- assertEquals("grandchild.test1", r.getString("testMethod"));
- assertEquals("/foo", r.getString("pathInfo"));
- assertEquals("foo", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child/grandchild", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/grandchild/foo", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/foo"));
- // Same for servlet
- assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/foo/bar
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/grandchild/foo/bar").getResponse(ObjectMap.class);
- assertEquals("grandchild.test1", r.getString("testMethod"));
- assertEquals("/foo/bar", r.getString("pathInfo"));
- assertEquals("foo/bar", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child/grandchild/foo", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/grandchild/foo/bar", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/foo/bar"));
- // Same for servlet
- assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/foo/bar%2Fbaz
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/grandchild/foo/bar%2Fbaz").getResponse(ObjectMap.class);
- assertEquals("grandchild.test1", r.getString("testMethod"));
- assertEquals("/foo/bar/baz", r.getString("pathInfo"));
- assertEquals("foo/bar/baz", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child/grandchild/foo", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/grandchild/foo/bar%2Fbaz", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/foo/bar%2Fbaz"));
- // Same for servlet
- assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/test2
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/grandchild/test2").getResponse(ObjectMap.class);
- assertEquals("grandchild.test2", r.getString("testMethod"));
- assertEquals("/test2", r.getString("pathInfo"));
- assertNull(r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child/grandchild", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/grandchild/test2", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/test2"));
- // Same for servlet
- assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/test2/foo
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/grandchild/test2/foo").getResponse(ObjectMap.class);
- assertEquals("grandchild.test2", r.getString("testMethod"));
- assertEquals("/test2/foo", r.getString("pathInfo"));
- assertEquals("foo", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child/grandchild/test2", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/grandchild/test2/foo", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/test2/foo"));
- // Same for servlet
- assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/test2/foo/bar
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/grandchild/test2/foo/bar").getResponse(ObjectMap.class);
- assertEquals("grandchild.test2", r.getString("testMethod"));
- assertEquals("/test2/foo/bar", r.getString("pathInfo"));
- assertEquals("foo/bar", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child/grandchild/test2/foo", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/grandchild/test2/foo/bar", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/test2/foo/bar"));
- // Same for servlet
- assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/test2/foo/bar%2Fbaz
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/grandchild/test2/foo/bar%2Fbaz").getResponse(ObjectMap.class);
- assertEquals("grandchild.test2", r.getString("testMethod"));
- assertEquals("/test2/foo/bar/baz", r.getString("pathInfo"));
- assertEquals("foo/bar/baz", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child/grandchild/test2/foo", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/grandchild/test2/foo/bar%2Fbaz", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/test2/foo/bar%2Fbaz"));
- // Same for servlet
- assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/test3%2Ftest3
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/grandchild/test3%2Ftest3").getResponse(ObjectMap.class);
- assertEquals("grandchild.test3", r.getString("testMethod"));
- assertEquals("/test3/test3", r.getString("pathInfo"));
- assertNull(r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child/grandchild", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/grandchild/test3%2Ftest3", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/test3%2Ftest3"));
- // Same for servlet
- assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/test3%2Ftest3/foo
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/grandchild/test3%2Ftest3/foo").getResponse(ObjectMap.class);
- assertEquals("grandchild.test3", r.getString("testMethod"));
- assertEquals("/test3/test3/foo", r.getString("pathInfo"));
- assertEquals("foo", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child/grandchild/test3%2Ftest3", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/grandchild/test3%2Ftest3/foo", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/test3%2Ftest3/foo"));
- // Same for servlet
- assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/test3%2Ftest3/foo/bar
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/grandchild/test3%2Ftest3/foo/bar").getResponse(ObjectMap.class);
- assertEquals("grandchild.test3", r.getString("testMethod"));
- assertEquals("/test3/test3/foo/bar", r.getString("pathInfo"));
- assertEquals("foo/bar", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child/grandchild/test3%2Ftest3/foo", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/grandchild/test3%2Ftest3/foo/bar", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/test3%2Ftest3/foo/bar"));
- // Same for servlet
- assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/test3%2Ftest3/foo/bar%2Fbaz
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/grandchild/test3%2Ftest3/foo/bar%2Fbaz").getResponse(ObjectMap.class);
- assertEquals("grandchild.test3", r.getString("testMethod"));
- assertEquals("/test3/test3/foo/bar/baz", r.getString("pathInfo"));
- assertEquals("foo/bar/baz", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child/grandchild/test3%2Ftest3/foo", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/grandchild/test3%2Ftest3/foo/bar%2Fbaz", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/test3%2Ftest3/foo/bar%2Fbaz"));
- // Same for servlet
- assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/test4/test4
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/grandchild/test4/test4").getResponse(ObjectMap.class);
- assertEquals("grandchild.test4", r.getString("testMethod"));
- assertEquals("/test4/test4", r.getString("pathInfo"));
- assertNull(r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child/grandchild/test4", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/grandchild/test4/test4", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/test4/test4"));
- // Same for servlet
- assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/test4/test4/foo
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/grandchild/test4/test4/foo").getResponse(ObjectMap.class);
- assertEquals("grandchild.test4", r.getString("testMethod"));
- assertEquals("/test4/test4/foo", r.getString("pathInfo"));
- assertEquals("foo", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child/grandchild/test4/test4", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/grandchild/test4/test4/foo", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/test4/test4/foo"));
- // Same for servlet
- assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/test4/test4/foo/bar
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/grandchild/test4/test4/foo/bar").getResponse(ObjectMap.class);
- assertEquals("grandchild.test4", r.getString("testMethod"));
- assertEquals("/test4/test4/foo/bar", r.getString("pathInfo"));
- assertEquals("foo/bar", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child/grandchild/test4/test4/foo", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/grandchild/test4/test4/foo/bar", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/test4/test4/foo/bar"));
- // Same for servlet
- assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- //--------------------------------------------------------------------------------
- // http://localhost:8080/sample/testuris/child/test4/test4/foo/bar%2Fbaz
- //--------------------------------------------------------------------------------
- r = client.doGet("/testuris/child/grandchild/test4/test4/foo/bar%2Fbaz").getResponse(ObjectMap.class);
- assertEquals("grandchild.test4", r.getString("testMethod"));
- assertEquals("/test4/test4/foo/bar/baz", r.getString("pathInfo"));
- assertEquals("foo/bar/baz", r.getString("pathRemainder"));
- assertEquals(path + "/testuris/child/grandchild/test4/test4/foo", r.getString("requestParentURI"));
- assertEquals(path + "/testuris/child/grandchild/test4/test4/foo/bar%2Fbaz", r.getString("requestURI"));
- assertTrue(r.getString("requestURL").endsWith(port + path + "/testuris/child/grandchild/test4/test4/foo/bar%2Fbaz"));
- // Same for servlet
- assertEquals(path + "/testuris/child/grandchild", r.getString("contextPath") + r.getString("servletPath")); // App may not have context path, but combination should always equal path.
- assertEquals(URL2 + "/child/grandchild", r.getString("servletURI"));
- assertTrue(r.getString("testURL1").endsWith(port + path + "/testuris/child/grandchild/testURL"));
- // Always the same
- assertTrue(r.getString("testURL2").endsWith(port + "/testURL"));
- assertEquals("http://testURL", r.getString("testURL3"));
-
- client.closeQuietly();
- }
-
- private static int getPort(String url) {
- Pattern p = Pattern.compile("\\:(\\d{2,5})");
- Matcher m = p.matcher(url);
- if (m.find())
- return Integer.parseInt(m.group(1));
- return -1;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TestUrlContentTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TestUrlContentTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TestUrlContentTest.java
deleted file mode 100755
index fab63a6..0000000
--- a/juneau-server-test/src/test/java/org/apache/juneau/server/TestUrlContentTest.java
+++ /dev/null
@@ -1,74 +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.server;
-
-import static org.junit.Assert.*;
-
-import org.apache.juneau.client.*;
-import org.junit.*;
-
-public class TestUrlContentTest {
-
- private static String URL = "/testUrlContent";
- private static RestClient client;
-
- @BeforeClass
- public static void beforeClass() {
- client = new TestRestClient().setHeader("Accept", "text/plain");
- }
-
- @AfterClass
- public static void afterClass() {
- client.closeQuietly();
- }
-
- //====================================================================================================
- // Test URL &Content parameter containing a String
- //====================================================================================================
- @Test
- public void testString() throws Exception {
- String r;
- r = client.doGet(URL + "/testString?content=\'xxx\'&Content-Type=text/json").getResponseAsString();
- assertEquals("class=java.lang.String, value=xxx", r);
- }
-
- //====================================================================================================
- // Test URL &Content parameter containing an Enum
- //====================================================================================================
- @Test
- public void testEnum() throws Exception {
- String r;
- r = client.doGet(URL + "/testEnum?content='X1'&Content-Type=text/json").getResponseAsString();
- assertEquals("class=org.apache.juneau.server.TestUrlContent$TestEnum, value=X1", r);
- }
-
- //====================================================================================================
- // Test URL &Content parameter containing a Bean
- //====================================================================================================
- @Test
- public void testBean() throws Exception {
- String r;
- r = client.doGet(URL + "/testBean?content=%7Bf1:1,f2:'foobar'%7D&Content-Type=text/json").getResponseAsString();
- assertEquals("class=org.apache.juneau.server.TestUrlContent$TestBean, value={f1:1,f2:'foobar'}", r);
- }
-
- //====================================================================================================
- // Test URL &Content parameter containing an int
- //====================================================================================================
- @Test
- public void testInt() throws Exception {
- String r;
- r = client.doGet(URL + "/testInt?content=123&Content-Type=text/json").getResponseAsString();
- assertEquals("class=java.lang.Integer, value=123", r);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/TransformsTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/TransformsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/TransformsTest.java
new file mode 100755
index 0000000..c0c0390
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/TransformsTest.java
@@ -0,0 +1,68 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static org.junit.Assert.*;
+
+import org.apache.juneau.client.*;
+import org.apache.juneau.json.*;
+import org.junit.*;
+
+public class TransformsTest {
+
+ private static String URL = "/testTransforms";
+
+ //====================================================================================================
+ // test1 - Test class transform overrides parent class transform
+ // Should return "A2-1".
+ //====================================================================================================
+ @Test
+ public void testClassTransformOverridesParentClassTransform() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ String r;
+ String url = URL + "/testClassTransformOverridesParentClassTransform";
+
+ r = client.doGet(url).getResponse(String.class);
+ assertEquals("A2-0", r);
+
+ r = client.doPut(url, "A2-1").getResponse(String.class);
+ assertEquals("A2-1", r);
+
+ r = client.doPut(url + "/A2-2", "").getResponse(String.class);
+ assertEquals("A2-2", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Test method transform overrides class transform
+ // Should return "A3-1".
+ //====================================================================================================
+ @Test
+ public void testMethodTransformOverridesClassTransform() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ String r;
+ String url = URL + "/testMethodTransformOverridesClassTransform";
+
+ r = client.doGet(url).getResponse(String.class);
+ assertEquals("A3-0", r);
+
+ r = client.doPut(url, "A3-1").getResponse(String.class);
+ assertEquals("A3-1", r);
+
+ r = client.doPut(url + "/A3-2", "").getResponse(String.class);
+ assertEquals("A3-2", r);
+
+ client.closeQuietly();
+ }
+}
[10/14] incubator-juneau git commit: Clean up test and test resource
class names.
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/CallbackStringsTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/CallbackStringsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/CallbackStringsTest.java
new file mode 100755
index 0000000..8f240c5
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/CallbackStringsTest.java
@@ -0,0 +1,50 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static org.junit.Assert.*;
+
+import org.apache.juneau.client.*;
+import org.junit.*;
+
+public class CallbackStringsTest {
+
+ //====================================================================================================
+ // Basic tests using &Content parameter
+ //====================================================================================================
+ @Test
+ public void test() throws Exception {
+ RestClient c = new TestRestClient().setAccept("text/json+simple");
+ String r;
+
+ r = c.doCallback("GET /testCallback").getResponseAsString();
+ assertEquals("{method:'GET',headers:{},content:''}", r);
+
+ r = c.doCallback("GET /testCallback some sample content").getResponseAsString();
+ assertEquals("{method:'GET',headers:{},content:'some sample content'}", r);
+
+ r = c.doCallback("GET {Foo-X:123,Foo-Y:'abc'} /testCallback").getResponseAsString();
+ assertEquals("{method:'GET',headers:{'Foo-X':'123','Foo-Y':'abc'},content:''}", r);
+
+ r = c.doCallback("GET { Foo-X : 123, Foo-Y : 'abc' } /testCallback").getResponseAsString();
+ assertEquals("{method:'GET',headers:{'Foo-X':'123','Foo-Y':'abc'},content:''}", r);
+
+ r = c.doCallback("GET {Foo-X:123,Foo-Y:'abc'} /testCallback some sample content ").getResponseAsString();
+ assertEquals("{method:'GET',headers:{'Foo-X':'123','Foo-Y':'abc'},content:'some sample content'}", r);
+
+ r = c.doCallback("PUT {Foo-X:123,Foo-Y:'abc'} /testCallback some sample content ").getResponseAsString();
+ assertEquals("{method:'PUT',headers:{'Foo-X':'123','Foo-Y':'abc'},content:'some sample content'}", r);
+
+ c.closeQuietly();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/CharsetEncodingsTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/CharsetEncodingsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/CharsetEncodingsTest.java
new file mode 100755
index 0000000..0744637
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/CharsetEncodingsTest.java
@@ -0,0 +1,96 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static javax.servlet.http.HttpServletResponse.*;
+import static org.apache.juneau.server.TestUtils.*;
+import static org.junit.Assert.*;
+
+import java.io.*;
+
+import org.apache.juneau.client.*;
+import org.apache.juneau.internal.*;
+import org.junit.*;
+
+
+public class CharsetEncodingsTest {
+
+ private static boolean debug = false;
+
+ /**
+ * Basic tests to ensure that the correct charsets are found and used
+ * under a variety of scenarios.
+ */
+ @Test
+ public void test() throws Exception {
+ String url = "/testCharsetEncodings";
+ RestClient client = new TestRestClient().setAccept("text/s").setContentType("text/p");
+ InputStream is;
+ String r;
+
+ r = client.doPut(url, new StringReader("foo")).getResponseAsString();
+ if (debug) System.err.println(r);
+ assertEquals("utf-8/foo/utf-8", r);
+
+ is = client.doPut(url, new StringReader("foo")).getInputStream();
+ r = IOUtils.read(new InputStreamReader(is, "utf-8"));
+ if (debug) System.err.println(r);
+ assertEquals("utf-8/foo/utf-8", r);
+
+ client.setHeader("Accept-Charset", "utf-8").setContentType("text/p;charset=utf-8");
+ is = client.doPut(url, new StringReader("foo")).getInputStream();
+ r = IOUtils.read(new InputStreamReader(is, "utf-8"));
+ if (debug) System.err.println(r);
+ assertEquals("utf-8/foo/utf-8", r);
+
+ client.setHeader("Accept-Charset", "Shift_JIS").setContentType("text/p;charset=shift_jis");
+ is = client.doPut(url, new StringReader("foo")).getInputStream();
+ r = IOUtils.read(new InputStreamReader(is, "Shift_JIS"));
+ if (debug) System.err.println(r);
+ assertEquals("shift_jis/foo/shift_jis", r);
+
+ try {
+ client.setHeader("Accept-Charset", "BAD").setContentType("text/p;charset=sjis");
+ is = client.doPut(url + "?noTrace=true", new StringReader("foo")).getInputStream();
+ r = IOUtils.read(new InputStreamReader(is, "sjis"));
+ if (debug) System.err.println(r);
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, "No supported charsets in header 'Accept-Charset': 'BAD'");
+ }
+
+ client.setAccept("text/s").setHeader("Accept-Charset", "utf-8").setContentType("text/p");
+ is = client.doPut(url+"?Content-Type=text/p", new StringReader("foo")).getInputStream();
+ r = IOUtils.read(new InputStreamReader(is, "utf-8"));
+ if (debug) System.err.println(r);
+ assertEquals("utf-8/foo/utf-8", r);
+
+ client.setAccept("text/s").setContentType("text/bad").setHeader("Accept-Charset", "utf-8");
+ is = client.doPut(url+"?Content-Type=text/p;charset=utf-8", new StringReader("foo")).getInputStream();
+ r = IOUtils.read(new InputStreamReader(is, "utf-8"));
+ if (debug) System.err.println(r);
+ assertEquals("utf-8/foo/utf-8", r);
+
+ try {
+ client.setAccept("text/s").setContentType("text/p").setHeader("Accept-Charset", "utf-8");
+ is = client.doPut(url+"?Content-Type=text/p;charset=BAD&noTrace=true", new StringReader("foo")).getInputStream();
+ r = IOUtils.read(new InputStreamReader(is, "utf-8"));
+ if (debug) System.err.println(r);
+ assertEquals("utf-8/foo/utf-8", r);
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE, "Unsupported charset in header 'Content-Type': 'text/p;charset=BAD'");
+ }
+ client.closeQuietly();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/ClientVersionTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/ClientVersionTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/ClientVersionTest.java
new file mode 100644
index 0000000..9867c7e
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/ClientVersionTest.java
@@ -0,0 +1,90 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static org.junit.Assert.*;
+
+import org.apache.juneau.client.*;
+import org.apache.juneau.plaintext.*;
+import org.junit.*;
+
+public class ClientVersionTest {
+
+ private static String URL = "/testClientVersion";
+
+ //====================================================================================================
+ // Basic tests - default X-Client-Version header.
+ //====================================================================================================
+ @Test
+ public void testDefaultHeader() throws Exception {
+ RestClient c = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class);
+ String url = URL + "/defaultHeader";
+
+ assertEquals("no-version", c.doGet(url).getResponseAsString());
+
+// for (String s : "0, 0.0, 0.1, .1, .9, .99".split("\\s*,\\s*")) {
+// c.setClientVersion(s);
+// assertEquals(s, "[0.0,1.0)", c.doGet(url).getResponseAsString());
+// }
+
+ for (String s : "1, 1.0, 1.0.0, 1.0.1".split("\\s*,\\s*")) {
+ c.setClientVersion(s);
+ assertEquals(s, "[1.0,1.0]", c.doGet(url).getResponseAsString());
+ }
+
+ for (String s : "1.1, 1.1.1, 1.2, 1.9.9".split("\\s*,\\s*")) {
+ c.setClientVersion(s);
+ assertEquals(s, "[1.1,2)", c.doGet(url).getResponseAsString());
+ }
+
+ for (String s : "2, 2.0, 2.1, 9, 9.9".split("\\s*,\\s*")) {
+ c.setClientVersion(s);
+ assertEquals(s, "2", c.doGet(url).getResponseAsString());
+ }
+
+ c.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Basic tests - Custom-Client-Version header.
+ //====================================================================================================
+ @Test
+ public void testCustomHeader() throws Exception {
+ RestClient c = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class);
+ String url = URL + "/customHeader";
+
+ assertEquals("no-version", c.doGet(url).getResponseAsString());
+
+ for (String s : "0, 0.0, 0.1, .1, .9, .99".split("\\s*,\\s*")) {
+ c.setHeader("Custom-Client-Version", s);
+ assertEquals("[0.0,1.0)", c.doGet(url).getResponseAsString());
+ }
+
+ for (String s : "1, 1.0, 1.0.0, 1.0.1".split("\\s*,\\s*")) {
+ c.setHeader("Custom-Client-Version", s);
+ assertEquals("[1.0,1.0]", c.doGet(url).getResponseAsString());
+ }
+
+ for (String s : "1.1, 1.1.1, 1.2, 1.9.9".split("\\s*,\\s*")) {
+ c.setHeader("Custom-Client-Version", s);
+ assertEquals("[1.1,2)", c.doGet(url).getResponseAsString());
+ }
+
+ for (String s : "2, 2.0, 2.1, 9, 9.9".split("\\s*,\\s*")) {
+ c.setHeader("Custom-Client-Version", s);
+ assertEquals("2", c.doGet(url).getResponseAsString());
+ }
+
+ c.closeQuietly();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/ConfigTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/ConfigTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/ConfigTest.java
new file mode 100755
index 0000000..aefa47d
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/ConfigTest.java
@@ -0,0 +1,58 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static org.apache.juneau.server.TestUtils.*;
+import static org.junit.Assert.*;
+
+import org.apache.juneau.client.*;
+import org.apache.juneau.ini.*;
+import org.apache.juneau.json.*;
+import org.junit.*;
+
+public class ConfigTest {
+
+ private static String URL = "/testConfig";
+
+ //====================================================================================================
+ // Basic tests
+ //====================================================================================================
+ @Test
+ public void test() throws Exception {
+ RestClient c = new TestRestClient(JsonSerializer.class, JsonParser.class).setAccept("text/json+simple");
+
+ ConfigFile cf = c.doGet(URL).getResponse(ConfigFileImpl.class);
+
+ assertObjectEquals("{int1:'1',int2:'1,2,3',int3:'$C{Test/int1, -1}',int4:'$C{Test/int3, -1}',int5:'$C{XXX, -1}',boolean1:'true',boolean2:'true,true',path:'$E{PATH}',mainClass:'$MF{Main-Class}',importPackage:'$MF{Import-Package}'}", cf.get("Test"));
+
+ assertEquals("'1'", c.doGet(URL + "/Test%2Fint1/" + getName(String.class)).getResponseAsString());
+ assertEquals("['1']", c.doGet(URL + "/Test%2Fint1/" + getName(String[].class)).getResponseAsString());
+ assertEquals("'1,2,3'", c.doGet(URL + "/Test%2Fint2/" + getName(String.class)).getResponseAsString());
+ assertEquals("['1','2','3']", c.doGet(URL + "/Test%2Fint2/" + getName(String[].class)).getResponseAsString());
+ assertEquals("[1,2,3]", c.doGet(URL + "/Test%2Fint2/" + getName(int[].class)).getResponseAsString());
+ assertEquals("[1,2,3]", c.doGet(URL + "/Test%2Fint2/" + getName(Integer[].class)).getResponseAsString());
+ assertEquals("[1]", c.doGet(URL + "/Test%2Fint3/" + getName(int[].class)).getResponseAsString());
+ assertEquals("[1]", c.doGet(URL + "/Test%2Fint4/" + getName(int[].class)).getResponseAsString());
+ assertEquals("[-1]", c.doGet(URL + "/Test%2Fint5/" + getName(int[].class)).getResponseAsString());
+ assertEquals("true", c.doGet(URL + "/Test%2Fboolean1/" + getName(Boolean.class)).getResponseAsString());
+ assertEquals("[true,true]", c.doGet(URL + "/Test%2Fboolean2/" + getName(Boolean[].class)).getResponseAsString());
+ assertTrue(c.doGet(URL + "/Test%2Fpath/" + getName(String.class)).getResponseAsString().length() > 10);
+ assertEquals("'org.apache.juneau.microservice.RestMicroservice'", c.doGet(URL + "/Test%2FmainClass/" + getName(String.class)).getResponseAsString());
+
+ c.closeQuietly();
+ }
+
+ private String getName(Class<?> c) {
+ return RestUtils.encode(c.getName());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/ContentTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/ContentTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/ContentTest.java
new file mode 100755
index 0000000..0db6c73
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/ContentTest.java
@@ -0,0 +1,706 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static org.junit.Assert.*;
+
+import java.io.*;
+import java.net.*;
+
+import org.apache.juneau.client.*;
+import org.apache.juneau.json.*;
+import org.apache.juneau.plaintext.*;
+import org.apache.juneau.urlencoding.*;
+import org.junit.*;
+
+public class ContentTest {
+
+ private static String URL = "/testContent";
+
+ //====================================================================================================
+ // Basic tests using &Content parameter
+ //====================================================================================================
+ @Test
+ public void testUsingContentParam() throws Exception {
+ RestClient c = new TestRestClient().setAccept("text/json+simple");
+ String r;
+
+ // @RestMethod(name="POST", path="/boolean")
+ // public boolean testBool(@Content boolean b) {
+ // return b;
+ // }
+ r = c.doPost(URL + "/boolean?content=true", null).getResponseAsString();
+ assertEquals("true", r);
+ r = c.doPost(URL + "/boolean?content=(true)", null).getResponseAsString();
+ assertEquals("true", r);
+ r = c.doPost(URL + "/boolean?content=$b(true)", null).getResponseAsString();
+ assertEquals("true", r);
+ r = c.doPost(URL + "/boolean?content=false", null).getResponseAsString();
+ assertEquals("false", r);
+ r = c.doPost(URL + "/boolean?content=(false)", null).getResponseAsString();
+ assertEquals("false", r);
+ r = c.doPost(URL + "/boolean?content=$b(false)", null).getResponseAsString();
+ assertEquals("false", r);
+ try {
+ r = c.doPost(URL + "/boolean?content=%00&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+ try {
+ r = c.doPost(URL + "/boolean?content=bad&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+
+ // @RestMethod(name="POST", path="/Boolean")
+ // public Boolean testBoolean(@Content Boolean b) {
+ // return b;
+ // }
+ r = c.doPost(URL + "/Boolean?content=true", null).getResponseAsString();
+ assertEquals("true", r);
+ r = c.doPost(URL + "/Boolean?content=(true)", null).getResponseAsString();
+ assertEquals("true", r);
+ r = c.doPost(URL + "/Boolean?content=$b(true)", null).getResponseAsString();
+ assertEquals("true", r);
+ r = c.doPost(URL + "/Boolean?content=false", null).getResponseAsString();
+ assertEquals("false", r);
+ r = c.doPost(URL + "/Boolean?content=(false)", null).getResponseAsString();
+ assertEquals("false", r);
+ r = c.doPost(URL + "/Boolean?content=$b(false)", null).getResponseAsString();
+ assertEquals("false", r);
+ r = c.doPost(URL + "/Boolean?content=%00", null).getResponseAsString();
+ assertEquals("null", r);
+ try {
+ r = c.doPost(URL + "/Boolean?content=bad&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+ // @RestMethod(name="POST", path="/int")
+ // public int testInt(@Content int i) {
+ // return i;
+ // }
+ r = c.doPost(URL + "/int?content=-123", null).getResponseAsString();
+ assertEquals("-123", r);
+ r = c.doPost(URL + "/int?content=(-123)", null).getResponseAsString();
+ assertEquals("-123", r);
+ r = c.doPost(URL + "/int?content=$n(-123)", null).getResponseAsString();
+ assertEquals("-123", r);
+ try {
+ r = c.doPost(URL + "/int?content=%00&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+ try {
+ r = c.doPost(URL + "/int?content=bad&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+ // @RestMethod(name="POST", path="/Integer")
+ // public Integer testInteger(@Content Integer i) {
+ // return i;
+ // }
+ r = c.doPost(URL + "/Integer?content=-123", null).getResponseAsString();
+ assertEquals("-123", r);
+ r = c.doPost(URL + "/Integer?content=(-123)", null).getResponseAsString();
+ assertEquals("-123", r);
+ r = c.doPost(URL + "/Integer?content=$n(-123)", null).getResponseAsString();
+ assertEquals("-123", r);
+ r = c.doPost(URL + "/Integer?content=%00", null).getResponseAsString();
+ assertEquals("null", r);
+ try {
+ r = c.doPost(URL + "/Integer?content=bad&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+ // @RestMethod(name="POST", path="/float")
+ // public float testFloat(@Content float f) {
+ // return f;
+ // }
+ r = c.doPost(URL + "/float?content=-1.23", null).getResponseAsString();
+ assertEquals("-1.23", r);
+ r = c.doPost(URL + "/float?content=(-1.23)", null).getResponseAsString();
+ assertEquals("-1.23", r);
+ r = c.doPost(URL + "/float?content=$n(-1.23)", null).getResponseAsString();
+ assertEquals("-1.23", r);
+ try {
+ r = c.doPost(URL + "/float?content=%00&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+ try {
+ r = c.doPost(URL + "/float?content=bad&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+ // @RestMethod(name="POST", path="/Float")
+ // public Float testFloat2(@Content Float f) {
+ // return f;
+ // }
+ r = c.doPost(URL + "/Float?content=-1.23", null).getResponseAsString();
+ assertEquals("-1.23", r);
+ r = c.doPost(URL + "/Float?content=(-1.23)", null).getResponseAsString();
+ assertEquals("-1.23", r);
+ r = c.doPost(URL + "/Float?content=$n(-1.23)", null).getResponseAsString();
+ assertEquals("-1.23", r);
+ r = c.doPost(URL + "/Float?content=%00", null).getResponseAsString();
+ assertEquals("null", r);
+ try {
+ r = c.doPost(URL + "/Float?content=bad&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+ // @RestMethod(name="POST", path="/Map")
+ // public TreeMap<String,String> testMap(@Content TreeMap<String,String> m) {
+ // return m;
+ // }
+ r = c.doPost(URL + "/Map?content=(a=b,c=d)", null).getResponseAsString();
+ assertEquals("{a:'b',c:'d'}", r);
+ r = c.doPost(URL + "/Map?content=%00", null).getResponseAsString();
+ assertEquals("null", r);
+ try {
+ r = c.doPost(URL + "/Map?content=bad&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+ // @RestMethod(name="POST", path="/B")
+ // public DTO2s.B testPojo1(@Content DTO2s.B b) {
+ // return b;
+ // }
+ DTOs.B b = DTOs.B.create();
+ r = c.doPost(URL + "/B?content=" + UonSerializer.DEFAULT.serialize(b), null).getResponseAsString();
+ assertEquals("{f1:['a','b'],f2:['c','d'],f3:[1,2],f4:[3,4],f5:[['e','f'],['g','h']],f6:[['i','j'],['k','l']],f7:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f8:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f9:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r);
+ r = c.doPost(URL + "/B?content=" + UonSerializer.DEFAULT_SIMPLE.serialize(b), null).getResponseAsString();
+ assertEquals("{f1:['a','b'],f2:['c','d'],f3:[1,2],f4:[3,4],f5:[['e','f'],['g','h']],f6:[['i','j'],['k','l']],f7:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f8:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f9:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r);
+
+ // @RestMethod(name="POST", path="/C")
+ // public DTO2s.C testPojo2(@Content DTO2s.C c) {
+ // return c;
+ // }
+ DTOs.C x = DTOs.C.create();
+ r = c.doPost(URL + "/C?content=" + UonSerializer.DEFAULT.serialize(x), null).getResponseAsString();
+ assertEquals("{f1:['a','b'],f2:['c','d'],f3:[1,2],f4:[3,4],f5:[['e','f'],['g','h']],f6:[['i','j'],['k','l']],f7:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f8:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f9:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r);
+ r = c.doPost(URL + "/C?content=" + UonSerializer.DEFAULT_SIMPLE.serialize(x), null).getResponseAsString();
+ assertEquals("{f1:['a','b'],f2:['c','d'],f3:[1,2],f4:[3,4],f5:[['e','f'],['g','h']],f6:[['i','j'],['k','l']],f7:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f8:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f9:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r);
+
+ c.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Basic tests using &Content parameter with &Accept=text/json
+ //====================================================================================================
+ @Test
+ public void testUsingContentParamJsonHeader() throws Exception {
+ RestClient c = new TestRestClient().setAccept("text/json+simple").setHeader("Content-Type", "text/json");
+ String r;
+
+ // @RestMethod(name="POST", path="/boolean")
+ // public boolean testBool(@Content boolean b) {
+ // return b;
+ // }
+ r = c.doPost(URL + "/boolean?content=true", null).getResponseAsString();
+ assertEquals("true", r);
+ r = c.doPost(URL + "/boolean?content=false", null).getResponseAsString();
+ assertEquals("false", r);
+ try {
+ r = c.doPost(URL + "/boolean?content=null&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+ try {
+ r = c.doPost(URL + "/boolean?content=bad&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+
+ // @RestMethod(name="POST", path="/Boolean")
+ // public Boolean testBoolean(@Content Boolean b) {
+ // return b;
+ // }
+ r = c.doPost(URL + "/Boolean?content=true", null).getResponseAsString();
+ assertEquals("true", r);
+ r = c.doPost(URL + "/Boolean?content=false", null).getResponseAsString();
+ assertEquals("false", r);
+ r = c.doPost(URL + "/Boolean?content=null", null).getResponseAsString();
+ assertEquals("null", r);
+ try {
+ r = c.doPost(URL + "/Boolean?content=bad&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+ // @RestMethod(name="POST", path="/int")
+ // public int testInt(@Content int i) {
+ // return i;
+ // }
+ r = c.doPost(URL + "/int?content=-123", null).getResponseAsString();
+ assertEquals("-123", r);
+ try {
+ r = c.doPost(URL + "/int?content=null&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+ try {
+ r = c.doPost(URL + "/int?content=bad&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+ // @RestMethod(name="POST", path="/Integer")
+ // public Integer testInteger(@Content Integer i) {
+ // return i;
+ // }
+ r = c.doPost(URL + "/Integer?content=-123", null).getResponseAsString();
+ assertEquals("-123", r);
+ r = c.doPost(URL + "/Integer?content=null", null).getResponseAsString();
+ assertEquals("null", r);
+ try {
+ r = c.doPost(URL + "/Integer?content=bad&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+ // @RestMethod(name="POST", path="/float")
+ // public float testFloat(@Content float f) {
+ // return f;
+ // }
+ r = c.doPost(URL + "/float?content=-1.23", null).getResponseAsString();
+ assertEquals("-1.23", r);
+ try {
+ r = c.doPost(URL + "/float?content=null&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+ try {
+ r = c.doPost(URL + "/float?content=bad&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+ // @RestMethod(name="POST", path="/Float")
+ // public Float testFloat2(@Content Float f) {
+ // return f;
+ // }
+ r = c.doPost(URL + "/Float?content=-1.23", null).getResponseAsString();
+ assertEquals("-1.23", r);
+ r = c.doPost(URL + "/Float?content=null", null).getResponseAsString();
+ assertEquals("null", r);
+ try {
+ r = c.doPost(URL + "/Float?content=bad&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+ // @RestMethod(name="POST", path="/Map")
+ // public TreeMap<String,String> testMap(@Content TreeMap<String,String> m) {
+ // return m;
+ // }
+ r = c.doPost(URL + "/Map?content=" + encode("{a:'b',c:'d'}"), null).getResponseAsString();
+ assertEquals("{a:'b',c:'d'}", r);
+ r = c.doPost(URL + "/Map?content=null", null).getResponseAsString();
+ assertEquals("null", r);
+ try {
+ r = c.doPost(URL + "/Map?content=bad&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+ // @RestMethod(name="POST", path="/B")
+ // public DTO2s.B testPojo1(@Content DTO2s.B b) {
+ // return b;
+ // }
+ DTOs.B b = DTOs.B.create();
+ r = c.doPost(URL + "/B?content=" + encode(JsonSerializer.DEFAULT_LAX.serialize(b)), null).getResponseAsString();
+ assertEquals("{f1:['a','b'],f2:['c','d'],f3:[1,2],f4:[3,4],f5:[['e','f'],['g','h']],f6:[['i','j'],['k','l']],f7:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f8:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f9:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r);
+
+ // @RestMethod(name="POST", path="/C")
+ // public DTO2s.C testPojo2(@Content DTO2s.C c) {
+ // return c;
+ // }
+ DTOs.C x = DTOs.C.create();
+ r = c.doPost(URL + "/C?content=" + encode(JsonSerializer.DEFAULT_LAX.serialize(x)), null).getResponseAsString();
+ assertEquals("{f1:['a','b'],f2:['c','d'],f3:[1,2],f4:[3,4],f5:[['e','f'],['g','h']],f6:[['i','j'],['k','l']],f7:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f8:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f9:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r);
+
+ c.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Basic tests using &Content parameter with &Accept=text/json
+ //====================================================================================================
+ @Test
+ public void testUsingContentParamJsonParam() throws Exception {
+ RestClient c = new TestRestClient().setAccept("text/json+simple");
+ String r;
+
+ // @RestMethod(name="POST", path="/boolean")
+ // public boolean testBool(@Content boolean b) {
+ // return b;
+ // }
+ r = c.doPost(URL + "/boolean?content=true&Content-Type=text/json", null).getResponseAsString();
+ assertEquals("true", r);
+ r = c.doPost(URL + "/boolean?content=false&Content-Type=text/json", null).getResponseAsString();
+ assertEquals("false", r);
+ try {
+ r = c.doPost(URL + "/boolean?content=null&Content-Type=text/json&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+ try {
+ r = c.doPost(URL + "/boolean?content=bad&Content-Type=text/json&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+
+ // @RestMethod(name="POST", path="/Boolean")
+ // public Boolean testBoolean(@Content Boolean b) {
+ // return b;
+ // }
+ r = c.doPost(URL + "/Boolean?content=true&Content-Type=text/json", null).getResponseAsString();
+ assertEquals("true", r);
+ r = c.doPost(URL + "/Boolean?content=false&Content-Type=text/json", null).getResponseAsString();
+ assertEquals("false", r);
+ r = c.doPost(URL + "/Boolean?content=null&Content-Type=text/json", null).getResponseAsString();
+ assertEquals("null", r);
+ try {
+ r = c.doPost(URL + "/Boolean?content=bad&Content-Type=text/json&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+ // @RestMethod(name="POST", path="/int")
+ // public int testInt(@Content int i) {
+ // return i;
+ // }
+ r = c.doPost(URL + "/int?content=-123&Content-Type=text/json", null).getResponseAsString();
+ assertEquals("-123", r);
+ try {
+ r = c.doPost(URL + "/int?content=null&Content-Type=text/json&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+ try {
+ r = c.doPost(URL + "/int?content=bad&Content-Type=text/json&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+ // @RestMethod(name="POST", path="/Integer")
+ // public Integer testInteger(@Content Integer i) {
+ // return i;
+ // }
+ r = c.doPost(URL + "/Integer?content=-123&Content-Type=text/json", null).getResponseAsString();
+ assertEquals("-123", r);
+ r = c.doPost(URL + "/Integer?content=null&Content-Type=text/json", null).getResponseAsString();
+ assertEquals("null", r);
+ try {
+ r = c.doPost(URL + "/Integer?content=bad&Content-Type=text/json&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+ // @RestMethod(name="POST", path="/float")
+ // public float testFloat(@Content float f) {
+ // return f;
+ // }
+ r = c.doPost(URL + "/float?content=-1.23&Content-Type=text/json", null).getResponseAsString();
+ assertEquals("-1.23", r);
+ try {
+ r = c.doPost(URL + "/float?content=null&Content-Type=text/json&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+ try {
+ r = c.doPost(URL + "/float?content=bad&Content-Type=text/json&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+ // @RestMethod(name="POST", path="/Float")
+ // public Float testFloat2(@Content Float f) {
+ // return f;
+ // }
+ r = c.doPost(URL + "/Float?content=-1.23&Content-Type=text/json", null).getResponseAsString();
+ assertEquals("-1.23", r);
+ r = c.doPost(URL + "/Float?content=null&Content-Type=text/json", null).getResponseAsString();
+ assertEquals("null", r);
+ try {
+ r = c.doPost(URL + "/Float?content=bad&Content-Type=text/json&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+ // @RestMethod(name="POST", path="/Map")
+ // public TreeMap<String,String> testMap(@Content TreeMap<String,String> m) {
+ // return m;
+ // }
+ r = c.doPost(URL + "/Map?content=" + encode("{a:'b',c:'d'}") + "&Content-Type=text/json", null).getResponseAsString();
+ assertEquals("{a:'b',c:'d'}", r);
+ r = c.doPost(URL + "/Map?content=null&Content-Type=text/json", null).getResponseAsString();
+ assertEquals("null", r);
+ try {
+ r = c.doPost(URL + "/Map?content=bad&Content-Type=text/json&noTrace=true", null).getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+ // @RestMethod(name="POST", path="/B")
+ // public DTO2s.B testPojo1(@Content DTO2s.B b) {
+ // return b;
+ // }
+ DTOs.B b = DTOs.B.create();
+ r = c.doPost(URL + "/B?content=" + encode(JsonSerializer.DEFAULT_LAX.serialize(b)) + "&Content-Type=text/json", null).getResponseAsString();
+ assertEquals("{f1:['a','b'],f2:['c','d'],f3:[1,2],f4:[3,4],f5:[['e','f'],['g','h']],f6:[['i','j'],['k','l']],f7:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f8:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f9:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r);
+
+ // @RestMethod(name="POST", path="/C")
+ // public DTO2s.C testPojo2(@Content DTO2s.C c) {
+ // return c;
+ // }
+ DTOs.C x = DTOs.C.create();
+ r = c.doPost(URL + "/C?content=" + encode(JsonSerializer.DEFAULT_LAX.serialize(x)) + "&Content-Type=text/json", null).getResponseAsString();
+ assertEquals("{f1:['a','b'],f2:['c','d'],f3:[1,2],f4:[3,4],f5:[['e','f'],['g','h']],f6:[['i','j'],['k','l']],f7:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f8:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f9:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r);
+
+ c.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Basic tests using HTTP body content
+ //====================================================================================================
+ @Test
+ public void testUsingContent() throws Exception {
+ RestClient c = new TestRestClient().setAccept("text/json+simple").setHeader("Content-Type", "text/uon").setSerializer(PlainTextSerializer.class);
+ String r;
+
+ // @RestMethod(name="POST", path="/boolean")
+ // public boolean testBool(@Content boolean b) {
+ // return b;
+ // }
+ r = c.doPost(URL + "/boolean", "true").getResponseAsString();
+ assertEquals("true", r);
+ r = c.doPost(URL + "/boolean", "(true)").getResponseAsString();
+ assertEquals("true", r);
+ r = c.doPost(URL + "/boolean", "$b(true)").getResponseAsString();
+ assertEquals("true", r);
+ r = c.doPost(URL + "/boolean", "false").getResponseAsString();
+ assertEquals("false", r);
+ r = c.doPost(URL + "/boolean", "(false)").getResponseAsString();
+ assertEquals("false", r);
+ r = c.doPost(URL + "/boolean", "$b(false)").getResponseAsString();
+ assertEquals("false", r);
+ try {
+ r = c.doPost(URL + "/boolean?noTrace=true", "%00").getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+ try {
+ r = c.doPost(URL + "/boolean?noTrace=true", "bad").getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+
+ // @RestMethod(name="POST", path="/Boolean")
+ // public Boolean testBoolean(@Content Boolean b) {
+ // return b;
+ // }
+ r = c.doPost(URL + "/Boolean", "true").getResponseAsString();
+ assertEquals("true", r);
+ r = c.doPost(URL + "/Boolean", "(true)").getResponseAsString();
+ assertEquals("true", r);
+ r = c.doPost(URL + "/Boolean", "$b(true)").getResponseAsString();
+ assertEquals("true", r);
+ r = c.doPost(URL + "/Boolean", "false").getResponseAsString();
+ assertEquals("false", r);
+ r = c.doPost(URL + "/Boolean", "(false)").getResponseAsString();
+ assertEquals("false", r);
+ r = c.doPost(URL + "/Boolean", "$b(false)").getResponseAsString();
+ assertEquals("false", r);
+ r = c.doPost(URL + "/Boolean", "\u0000").getResponseAsString();
+ assertEquals("null", r);
+ try {
+ r = c.doPost(URL + "/Boolean?noTrace=true", "bad").getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+ // @RestMethod(name="POST", path="/int")
+ // public int testInt(@Content int i) {
+ // return i;
+ // }
+ r = c.doPost(URL + "/int", "-123").getResponseAsString();
+ assertEquals("-123", r);
+ r = c.doPost(URL + "/int", "(-123)").getResponseAsString();
+ assertEquals("-123", r);
+ r = c.doPost(URL + "/int", "$n(-123)").getResponseAsString();
+ assertEquals("-123", r);
+ try {
+ r = c.doPost(URL + "/int?noTrace=true", "%00").getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+ try {
+ r = c.doPost(URL + "/int?noTrace=true", "bad").getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+ // @RestMethod(name="POST", path="/Integer")
+ // public Integer testInteger(@Content Integer i) {
+ // return i;
+ // }
+ r = c.doPost(URL + "/Integer", "-123").getResponseAsString();
+ assertEquals("-123", r);
+ r = c.doPost(URL + "/Integer", "(-123)").getResponseAsString();
+ assertEquals("-123", r);
+ r = c.doPost(URL + "/Integer", "$n(-123)").getResponseAsString();
+ assertEquals("-123", r);
+ r = c.doPost(URL + "/Integer", "\u0000").getResponseAsString();
+ assertEquals("null", r);
+ try {
+ r = c.doPost(URL + "/Integer?noTrace=true", "bad").getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+ // @RestMethod(name="POST", path="/float")
+ // public float testFloat(@Content float f) {
+ // return f;
+ // }
+ r = c.doPost(URL + "/float", "-1.23").getResponseAsString();
+ assertEquals("-1.23", r);
+ r = c.doPost(URL + "/float", "(-1.23)").getResponseAsString();
+ assertEquals("-1.23", r);
+ r = c.doPost(URL + "/float", "$n(-1.23)").getResponseAsString();
+ assertEquals("-1.23", r);
+ try {
+ r = c.doPost(URL + "/float?noTrace=true", "\u0000").getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+ try {
+ r = c.doPost(URL + "/float?noTrace=true", "bad").getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+ // @RestMethod(name="POST", path="/Float")
+ // public Float testFloat2(@Content Float f) {
+ // return f;
+ // }
+ r = c.doPost(URL + "/Float", "-1.23").getResponseAsString();
+ assertEquals("-1.23", r);
+ r = c.doPost(URL + "/Float", "(-1.23)").getResponseAsString();
+ assertEquals("-1.23", r);
+ r = c.doPost(URL + "/Float", "$n(-1.23)").getResponseAsString();
+ assertEquals("-1.23", r);
+ r = c.doPost(URL + "/Float", "\u0000").getResponseAsString();
+ assertEquals("null", r);
+ try {
+ r = c.doPost(URL + "/Float?noTrace=true", "bad").getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+ // @RestMethod(name="POST", path="/Map")
+ // public TreeMap<String,String> testMap(@Content TreeMap<String,String> m) {
+ // return m;
+ // }
+ r = c.doPost(URL + "/Map", "(a=b,c=d)").getResponseAsString();
+ assertEquals("{a:'b',c:'d'}", r);
+ r = c.doPost(URL + "/Map", "\u0000").getResponseAsString();
+ assertEquals("null", r);
+ try {
+ r = c.doPost(URL + "/Map?noTrace=true", "bad").getResponseAsString();
+ fail("Exception expected!");
+ } catch (RestCallException e) {
+ assertEquals(400, e.getResponseCode());
+ }
+
+ // @RestMethod(name="POST", path="/B")
+ // public DTO2s.B testPojo1(@Content DTO2s.B b) {
+ // return b;
+ // }
+ DTOs.B b = DTOs.B.create();
+ r = c.doPost(URL + "/B", "" + UonSerializer.DEFAULT.serialize(b)).getResponseAsString();
+ assertEquals("{f1:['a','b'],f2:['c','d'],f3:[1,2],f4:[3,4],f5:[['e','f'],['g','h']],f6:[['i','j'],['k','l']],f7:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f8:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f9:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r);
+ r = c.doPost(URL + "/B", "" + UonSerializer.DEFAULT_SIMPLE.serialize(b)).getResponseAsString();
+ assertEquals("{f1:['a','b'],f2:['c','d'],f3:[1,2],f4:[3,4],f5:[['e','f'],['g','h']],f6:[['i','j'],['k','l']],f7:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f8:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f9:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r);
+
+ // @RestMethod(name="POST", path="/C")
+ // public DTO2s.C testPojo2(@Content DTO2s.C c) {
+ // return c;
+ // }
+ DTOs.C x = DTOs.C.create();
+ r = c.doPost(URL + "/C", "" + UonSerializer.DEFAULT.serialize(x)).getResponseAsString();
+ assertEquals("{f1:['a','b'],f2:['c','d'],f3:[1,2],f4:[3,4],f5:[['e','f'],['g','h']],f6:[['i','j'],['k','l']],f7:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f8:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f9:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r);
+ r = c.doPost(URL + "/C", "" + UonSerializer.DEFAULT_SIMPLE.serialize(x)).getResponseAsString();
+ assertEquals("{f1:['a','b'],f2:['c','d'],f3:[1,2],f4:[3,4],f5:[['e','f'],['g','h']],f6:[['i','j'],['k','l']],f7:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f8:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f9:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f10:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f11:['a','b'],f12:['c','d'],f13:[1,2],f14:[3,4],f15:[['e','f'],['g','h']],f16:[['i','j'],['k','l']],f17:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f18:[{a:'a',b:1,c:true},{a:'a',b:1,c:true}],f19:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]],f20:[[{a:'a',b:1,c:true}],[{a:'a',b:1,c:true}]]}", r);
+
+ c.closeQuietly();
+ }
+
+
+ private String encode(String s) {
+ try {
+ return URLEncoder.encode(s, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/DefaultContentTypesTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/DefaultContentTypesTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/DefaultContentTypesTest.java
new file mode 100755
index 0000000..695a41b
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/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;
+
+import static javax.servlet.http.HttpServletResponse.*;
+import static org.apache.juneau.server.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/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/ErrorConditionsTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/ErrorConditionsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/ErrorConditionsTest.java
new file mode 100755
index 0000000..2123fa5
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/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;
+
+import static javax.servlet.http.HttpServletResponse.*;
+import static org.apache.juneau.server.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.ErrorConditionsResource$Test1' using parser 'org.apache.juneau.json.JsonParser'",
+ "Unknown property 'f2' encountered while trying to parse into class 'org.apache.juneau.server.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.ErrorConditionsResource$Test1' using parser 'org.apache.juneau.json.JsonParser'",
+ "Unknown property 'f2' encountered while trying to parse into class 'org.apache.juneau.server.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.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.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.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.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.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.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.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.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/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/GroupsTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/GroupsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/GroupsTest.java
new file mode 100755
index 0000000..fd865f9
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/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;
+
+import static javax.servlet.http.HttpServletResponse.*;
+import static org.apache.juneau.server.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();
+ }
+}
[09/14] incubator-juneau git commit: Clean up test and test resource
class names.
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/GzipTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/GzipTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/GzipTest.java
new file mode 100755
index 0000000..927363d
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/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;
+
+import static javax.servlet.http.HttpServletResponse.*;
+import static org.apache.juneau.server.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/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/InheritanceTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/InheritanceTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/InheritanceTest.java
new file mode 100755
index 0000000..3594d11
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/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;
+
+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/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/LargePojosTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/LargePojosTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/LargePojosTest.java
new file mode 100755
index 0000000..7c139d5
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/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;
+
+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/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/MessagesTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/MessagesTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/MessagesTest.java
new file mode 100755
index 0000000..d6eb29e
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/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;
+
+import static org.apache.juneau.server.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/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/NlsPropertyTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/NlsPropertyTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/NlsPropertyTest.java
new file mode 100755
index 0000000..0157540
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/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;
+
+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/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/NlsTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/NlsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/NlsTest.java
new file mode 100755
index 0000000..09789b6
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/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;
+
+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();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/NoParserInputTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/NoParserInputTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/NoParserInputTest.java
new file mode 100755
index 0000000..04704ef
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/NoParserInputTest.java
@@ -0,0 +1,70 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static javax.servlet.http.HttpServletResponse.*;
+import static org.apache.juneau.server.TestUtils.*;
+import static org.junit.Assert.*;
+
+import org.apache.juneau.client.*;
+import org.apache.juneau.plaintext.*;
+import org.junit.*;
+
+public class NoParserInputTest {
+
+ private static String URL = "/testNoParserInput";
+ private static boolean debug = false;
+
+ //====================================================================================================
+ // @Content annotated InputStream.
+ //====================================================================================================
+ @Test
+ public void testInputStream() throws Exception {
+ RestClient client = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class);
+ String r = client.doPut(URL + "/testInputStream", "foo").getResponseAsString();
+ assertEquals("foo", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // @Content annotated Reader.
+ //====================================================================================================
+ @Test
+ public void testReader() throws Exception {
+ RestClient client = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class);
+ String r = client.doPut(URL + "/testReader", "foo").getResponseAsString();
+ assertEquals("foo", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // @Content annotated PushbackReader.
+ // This should always fail since the servlet reader is not a pushback reader.
+ //====================================================================================================
+ @Test
+ public void testPushbackReader() throws Exception {
+ RestClient client = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class);
+ try {
+ client.doPut(URL + "/testPushbackReader?noTrace=true", "foo").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_BAD_REQUEST,
+ "Invalid argument type passed to the following method:",
+ "'public java.lang.String org.apache.juneau.server.NoParserInputResource.testPushbackReader(java.io.PushbackReader) throws java.lang.Exception'");
+ }
+
+ client.closeQuietly();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/OnPostCallTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/OnPostCallTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/OnPostCallTest.java
new file mode 100755
index 0000000..edcc1d8
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/OnPostCallTest.java
@@ -0,0 +1,121 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static org.junit.Assert.*;
+
+import java.io.*;
+
+import org.apache.juneau.client.*;
+import org.junit.*;
+
+public class OnPostCallTest {
+
+ private static String URL = "/testOnPostCall";
+
+ //====================================================================================================
+ // Properties overridden via properties annotation.
+ //====================================================================================================
+ @Test
+ public void testPropertiesOverridenByAnnotation() throws Exception {
+ RestClient client = new TestRestClient().setAccept("text/s1");
+ String url = URL + "/testPropertiesOverridenByAnnotation";
+ String r;
+ RestCall rc;
+
+ r = client.doPut(url, new StringReader("")).getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/s1", r);
+
+ r = client.doPut(url, new StringReader("")).setHeader("Override-Accept", "text/s2").getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/s2", r);
+
+ rc = client.doPut(url, new StringReader("")).setHeader("Override-Content-Type", "text/s3").connect();
+ r = rc.getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/s1", r);
+ assertTrue(rc.getResponse().getFirstHeader("Content-Type").getValue().startsWith("text/s3"));
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Properties overridden via properties annotation. Default Accept header.
+ //====================================================================================================
+ @Test
+ public void testPropertiesOverridenByAnnotationDefaultAccept() throws Exception {
+ RestClient client = new TestRestClient().setAccept("");
+ String url = URL + "/testPropertiesOverridenByAnnotation";
+ String r;
+ RestCall rc;
+
+ r = client.doPut(url, new StringReader("")).getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/s2", r);
+
+ r = client.doPut(url, new StringReader("")).setHeader("Override-Accept", "text/s3").getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/s3", r);
+
+ rc = client.doPut(url, new StringReader("")).setHeader("Override-Content-Type", "text/s3").connect();
+ r = rc.getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/s2", r);
+ assertTrue(rc.getResponse().getFirstHeader("Content-Type").getValue().startsWith("text/s3"));
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Properties overridden programmatically.
+ //====================================================================================================
+ @Test
+ public void testPropertiesOverriddenProgramatically() throws Exception {
+ RestClient client = new TestRestClient().setAccept("text/s1");
+ String url = URL + "/testPropertiesOverriddenProgramatically";
+ String r;
+ RestCall rc;
+
+ r = client.doPut(url, new StringReader("")).getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=pp3,p4=xp4,p5=xp5,contentType=text/s1", r);
+
+ r = client.doPut(url, new StringReader("")).setHeader("Override-Accept", "text/s2").getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=pp3,p4=xp4,p5=xp5,contentType=text/s2", r);
+
+ rc = client.doPut(url, new StringReader("")).setHeader("Override-Content-Type", "text/s3").connect();
+ r = rc.getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=pp3,p4=xp4,p5=xp5,contentType=text/s1", r);
+ assertTrue(rc.getResponse().getFirstHeader("Content-Type").getValue().startsWith("text/s3"));
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Properties overridden programmatically. Default Accept header.
+ //====================================================================================================
+ @Test
+ public void testPropertiesOverriddenProgramaticallyDefaultAccept() throws Exception {
+ RestClient client = new TestRestClient().setAccept("");
+ String url = URL + "/testPropertiesOverriddenProgramatically";
+ String r;
+ RestCall rc;
+
+ r = client.doPut(url, new StringReader("")).getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=pp3,p4=xp4,p5=xp5,contentType=text/s2", r);
+
+ r = client.doPut(url, new StringReader("")).setHeader("Override-Accept", "text/s3").getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=pp3,p4=xp4,p5=xp5,contentType=text/s3", r);
+
+ rc = client.doPut(url, new StringReader("")).setHeader("Override-Content-Type", "text/s3").connect();
+ r = rc.getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=pp3,p4=xp4,p5=xp5,contentType=text/s2", r);
+ assertTrue(rc.getResponse().getFirstHeader("Content-Type").getValue().startsWith("text/s3"));
+
+ client.closeQuietly();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/OnPreCallTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/OnPreCallTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/OnPreCallTest.java
new file mode 100755
index 0000000..f11ef24
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/OnPreCallTest.java
@@ -0,0 +1,61 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static org.junit.Assert.*;
+
+import java.io.*;
+
+import org.apache.juneau.client.*;
+import org.junit.*;
+
+public class OnPreCallTest {
+
+ private static String URL = "/testOnPreCall";
+
+ //====================================================================================================
+ // Properties overridden via properties annotation.
+ //====================================================================================================
+ @Test
+ public void testPropertiesOverriddenByAnnotation() throws Exception {
+ RestClient client = new TestRestClient().setContentType("text/a1").setAccept("text/plain");
+ String url = URL + "/testPropertiesOverriddenByAnnotation";
+ String r;
+
+ r = client.doPut(url, new StringReader("")).getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/a1", r);
+
+ r = client.doPut(url, new StringReader("")).setHeader("Override-Content-Type", "text/a2").getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=mp3,p4=xp4,p5=xp5,contentType=text/a2", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Properties overridden programmatically.
+ //====================================================================================================
+ @Test
+ public void testPropertiesOverriddenProgrammatically() throws Exception {
+ RestClient client = new TestRestClient().setContentType("text/a1").setAccept("text/plain");
+ String url = URL + "/testPropertiesOverriddenProgrammatically";
+ String r;
+
+ r = client.doPut(url, new StringReader("")).getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=pp3,p4=pp4,p5=xp5,contentType=text/a1", r);
+
+ r = client.doPut(url, new StringReader("")).setHeader("Override-Content-Type", "text/a2").getResponseAsString();
+ assertEquals("p1=sp1,p2=xp2,p3=pp3,p4=pp4,p5=xp5,contentType=text/a2", r);
+
+ client.closeQuietly();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/OptionsWithoutNlsTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/OptionsWithoutNlsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/OptionsWithoutNlsTest.java
new file mode 100755
index 0000000..ccd242e
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/OptionsWithoutNlsTest.java
@@ -0,0 +1,51 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static org.junit.Assert.*;
+
+import org.apache.juneau.client.*;
+import org.apache.juneau.json.*;
+import org.apache.juneau.server.labels.*;
+import org.junit.*;
+
+public class OptionsWithoutNlsTest {
+
+ private static String URL = "/testOptionsWithoutNls";
+
+ //====================================================================================================
+ // Should get to the options page without errors
+ //====================================================================================================
+ @Test
+ public void testOptions() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ RestCall r = client.doOptions(URL + "/testOptions");
+ ResourceOptions o = r.getResponse(ResourceOptions.class);
+ assertEquals("", o.getDescription());
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Missing resource bundle should cause {!!x} string.
+ //====================================================================================================
+ @Test
+ public void testMissingResourceBundle() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ RestCall r = client.doGet(URL + "/testMissingResourceBundle");
+ String o = r.getResponse(String.class);
+ assertEquals("{!!bad}", o);
+
+ client.closeQuietly();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/OverlappingMethodsTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/OverlappingMethodsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/OverlappingMethodsTest.java
new file mode 100755
index 0000000..caa79d7
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/OverlappingMethodsTest.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;
+
+import static javax.servlet.http.HttpServletResponse.*;
+import static org.apache.juneau.server.TestUtils.*;
+import static org.junit.Assert.*;
+
+import org.apache.juneau.client.*;
+import org.junit.*;
+
+public class OverlappingMethodsTest {
+
+ private static String URL = "/testOverlappingMethods";
+ private static boolean debug = false;
+
+ //====================================================================================================
+ // Overlapping guards
+ //====================================================================================================
+ @Test
+ public void testOverlappingGuards1() throws Exception {
+ RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
+ String r;
+ String url = URL + "/testOverlappingGuards1";
+
+ r = client.doGet(url + "?t1=1").getResponseAsString();
+ assertEquals("test1_doGet", r);
+
+ try {
+ client.doGet(url + "?noTrace=true").connect();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_FORBIDDEN, "Access denied by guard");
+ }
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Overlapping guards
+ //====================================================================================================
+ @Test
+ public void testOverlappingGuards2() throws Exception {
+ RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
+ String r;
+ String url = URL + "/testOverlappingGuards2";
+ try {
+ client.doGet(url + "?noTrace=true").connect();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_FORBIDDEN, "Access denied by guard");
+ }
+
+ try {
+ client.doGet(url + "?t1=1&noTrace=true").connect();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_FORBIDDEN, "Access denied by guard");
+ }
+
+ try {
+ client.doGet(url + "?t2=2&noTrace=true").connect();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_FORBIDDEN, "Access denied by guard");
+ }
+
+ r = client.doGet(url + "?t1=1&t2=2").getResponseAsString();
+ assertEquals("test2_doGet", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Overlapping matchers
+ //====================================================================================================
+ @Test
+ public void testOverlappingMatchers1() throws Exception {
+ RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
+ String r;
+ String url = URL + "/testOverlappingMatchers1";
+
+ r = client.doGet(url + "?t1=1").getResponseAsString();
+ assertEquals("test3a", r);
+
+ r = client.doGet(url + "?t2=2").getResponseAsString();
+ assertEquals("test3b", r);
+
+ r = client.doGet(url).getResponseAsString();
+ assertEquals("test3c", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Overlapping matchers
+ //====================================================================================================
+ @Test
+ public void testOverlappingMatchers2() throws Exception {
+ RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
+ String r;
+ String url = URL + "/testOverlappingMatchers2";
+
+ r = client.doGet(url + "?t1=1").getResponseAsString();
+ assertEquals("test4b", r);
+
+ r = client.doGet(url + "?t2=2").getResponseAsString();
+ assertEquals("test4b", r);
+
+ r = client.doGet(url + "?t1=1&t2=2").getResponseAsString();
+ assertEquals("test4b", r);
+
+ r = client.doGet(url + "?tx=x").getResponseAsString();
+ assertEquals("test4a", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Overlapping URL patterns
+ //====================================================================================================
+ @Test
+ public void testOverlappingUrlPatterns() throws Exception {
+ RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
+ String r;
+ String url = URL + "/testOverlappingUrlPatterns";
+
+ // [/test5] = [test5a]
+ // [/test5/*] = [test5b] -- Cannot get called.
+ // [/test5/foo] = [test5c]
+ // [/test5/foo/*] = [test5d]
+ // [/test5/{id}] = [test5e]
+ // [/test5/{id}/*] = [test5f]
+ // [/test5/{id}/foo] = [test5g]
+ // [/test5/{id}/foo/*] = [test5h]
+
+ r = client.doGet(url).getResponseAsString();
+ assertEquals("test5a", r);
+
+ r = client.doGet(url + "/foo").getResponseAsString();
+ assertEquals("test5c", r);
+
+ r = client.doGet(url + "/foo/x").getResponseAsString();
+ assertEquals("test5d", r);
+
+ r = client.doGet(url + "/x").getResponseAsString();
+ assertEquals("test5e", r);
+
+ r = client.doGet(url + "/x/x").getResponseAsString();
+ assertEquals("test5f", r);
+
+ r = client.doGet(url + "/x/foo").getResponseAsString();
+ assertEquals("test5g", r);
+
+ r = client.doGet(url + "/x/foo/x").getResponseAsString();
+ assertEquals("test5h", r);
+
+ client.closeQuietly();
+ }
+}
[08/14] incubator-juneau git commit: Clean up test and test resource
class names.
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/ParamsTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/ParamsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/ParamsTest.java
new file mode 100755
index 0000000..a6d7e61
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/ParamsTest.java
@@ -0,0 +1,716 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static javax.servlet.http.HttpServletResponse.*;
+import static org.apache.juneau.server.TestUtils.*;
+import static org.junit.Assert.*;
+
+import java.util.*;
+
+import org.apache.http.*;
+import org.apache.http.client.entity.*;
+import org.apache.http.entity.*;
+import org.apache.http.message.*;
+import org.apache.juneau.*;
+import org.apache.juneau.client.*;
+import org.apache.juneau.json.*;
+import org.junit.*;
+
+public class ParamsTest {
+
+ private static String URL = "/testParams";
+ private static boolean debug = false;
+
+ //====================================================================================================
+ // Basic tests
+ //====================================================================================================
+ @Test
+ public void testBasic() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ RestCall r;
+
+ // @Override
+ // @RestMethod(name="GET",pattern="/")
+ // public void doGet(RestRequest req, RestResponse res) {
+ // res.setOutput("No args");
+ // }
+ r = client.doGet(URL);
+ assertEquals("GET", r.getResponse(String.class));
+
+ r = client.doGet(URL + "/getx?noTrace=true");
+ try {
+ r.connect();
+ fail("Connection should have failed.");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_FOUND, "Method 'GET' not found on resource with matching pattern on path '/getx'");
+ }
+
+ // @RestMethod(name="GET",pattern="/get1")
+ // public void doGet1(RestRequest req, RestResponse res) {
+ // res.setOutput("/get1");
+ // }
+ r = client.doGet(URL + "/get1");
+ assertEquals("GET /get1", r.getResponse(String.class));
+
+ r = client.doGet(URL + "/get1a?noTrace=true");
+ try {
+ r.connect();
+ fail("Connection should have failed.");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_FOUND, "Method 'GET' not found on resource with matching pattern on path '/get1a'");
+ }
+
+ // @RestMethod(name="GET",pattern="/get1/{foo}")
+ // public void doGet(RestRequest req, RestResponse res, String foo) {
+ // res.setOutput("/get1/" + foo);
+ // }
+ r = client.doGet(URL + "/get1/foo");
+ assertEquals("GET /get1a foo", r.getResponse(String.class));
+
+ // URL-encoded part should not get decoded before finding method to invoke.
+ // This should match /get1/{foo} and not /get1/{foo}/{bar}
+ // NOTE: When testing on Tomcat, must specify the following system property:
+ // -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true
+ String x = "x%2Fy+z"; // [x/y z]
+ r = client.doGet(URL + "/get1/"+x);
+ assertEquals("GET /get1a x/y z", r.getResponse(String.class));
+
+ r = client.doGet(URL + "/get1/"+x+"/"+x);
+ assertEquals("GET /get1b x/y z,x/y z", r.getResponse(String.class));
+
+ r = client.doGet(URL + "/get1/foo");
+ assertEquals("GET /get1a foo", r.getResponse(String.class));
+
+ r = client.doGet(URL + "/get1/foo/bar/baz?noTrace=true");
+ try {
+ r.connect();
+ fail("Connection should have failed.");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_NOT_FOUND, "Method 'GET' not found on resource with matching pattern on path '/get1/foo/bar/baz'");
+ }
+
+ // @RestMethod(name="GET",pattern="/get3/{foo}/{bar}/*")
+ // public void doGet3(RestRequest req, RestResponse res, String foo, int bar) {
+ // res.setOutput("/get3/"+foo+"/"+bar+", remainder="+req.getRemainder());
+ // }
+ r = client.doGet(URL + "/get3/foo/123");
+ assertEquals("GET /get3/foo/123 remainder=null", r.getResponse(String.class));
+
+ r = client.doGet(URL + "/get3/foo/123/xxx");
+ assertEquals("GET /get3/foo/123 remainder=xxx", r.getResponse(String.class));
+
+ // // Test method name with overlapping name, remainder allowed.
+ // @RestMethod(name="GET2")
+ // public void get2(RestRequest req, RestResponse res) {
+ // res.setOutput("GET2, remainder="+req.getRemainder());
+ // }
+ r = client.doGet(URL + "?method=get2");
+ assertEquals("GET2 remainder=null", r.getResponse(String.class));
+ r = client.doGet(URL + "/foo/bar?method=get2");
+ assertEquals("GET2 remainder=foo/bar", r.getResponse(String.class));
+ r = client.doGet(URL + "/foo/bar?method=GET2");
+ assertEquals("GET2 remainder=foo/bar", r.getResponse(String.class));
+
+ // // Default POST
+ // @Override
+ // public void doPost(RestRequest req, RestResponse res) {
+ // res.setOutput("POST, remainder="+req.getRemainder());
+ // }
+ r = client.doPost(URL, "");
+ assertEquals("POST remainder=null", r.getResponse(String.class));
+ r = client.doPost(URL + "/foo", "");
+ assertEquals("POST remainder=foo", r.getResponse(String.class));
+
+ // // Bunch of different argument types
+ // @RestMethod(name="POST",pattern="/person/{person}")
+ // public void doPost(RestRequest req, RestResponse res, Person p) {
+ // res.setOutput("POST, /person, name="+p.name+", age="+p.age+" remainder="+req.getRemainder());
+ // }
+ r = client.doPost(URL + "/person/(name=John+Smith,birthDate=Jan+12~,+1952)", "");
+ assertEquals("POST /person/{name=John Smith,birthDate.year=1952} remainder=null", r.getResponse(String.class));
+
+ // Fall through to top-level POST
+ r = client.doPost(URL + "/person/(name:'John+Smith',age:123)/foo", "");
+ assertEquals("POST remainder=person/(name:'John Smith',age:123)/foo", r.getResponse(String.class));
+
+ // // Various primitive types
+ // @RestMethod(name="PUT",pattern="/primitives/{xInt}.{xShort},{xLong}/{xChar}/{xFloat}/{xDouble}/{xByte}/{xBoolean}")
+ // public void doPut1(RestRequest req, RestResponse res, int xInt, short xShort, long xLong, char xChar, float xFloat, double xDouble, byte xByte, boolean xBoolean) {
+ // res.setOutput("PUT, /primitives/"+xInt+"."+xShort+","+xLong+"/"+xChar+"/"+xFloat+"/"+xDouble+"/"+xByte+"/"+xBoolean);
+ // }
+ r = client.doPut(URL + "/primitives/1/2/3/x/4/5/6/true", "");
+ assertEquals("PUT /primitives/1/2/3/x/4.0/5.0/6/true", r.getResponse(String.class));
+
+ // // Various primitive objects
+ // @RestMethod(name="PUT",pattern="/primitiveObjects/{xInt}/{xShort}/{xLong}/{xChar}/{xFloat}/{xDouble}/{xByte}/{xBoolean}")
+ // public void doPut1(RestRequest req, RestResponse res, Integer xInt, Short xShort, Long xLong, Character xChar, Float xFloat, Double xDouble, Byte xByte, Boolean xBoolean) {
+ // res.setOutput("PUT /primitives/"+xInt+"/"+xShort+"/"+xLong+"/"+xChar+"/"+xFloat+"/"+xDouble+"/"+xByte+"/"+xBoolean);
+ // }
+ r = client.doPut(URL + "/primitiveObjects/1/2/3/x/4/5/6/true", "");
+ assertEquals("PUT /primitiveObjects/1/2/3/x/4.0/5.0/6/true", r.getResponse(String.class));
+
+ // // Object with forString(String) method
+ // @RestMethod(name="PUT",pattern="/uuid/{uuid}")
+ // public void doPut1(RestRequest req, RestResponse res, UUID uuid) {
+ // res.setOutput("PUT /uuid/"+uuid);
+ // }
+ UUID uuid = UUID.randomUUID();
+ r = client.doPut(URL + "/uuid/"+uuid, "");
+ assertEquals("PUT /uuid/"+uuid, r.getResponse(String.class));
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // @Param annotation - GET
+ //====================================================================================================
+ @Test
+ public void testParamGet() throws Exception {
+ RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
+ String r;
+ String url = URL + "/testParamGet";
+
+ r = client.doGet(url + "?p1=p1&p2=2").getResponseAsString();
+ assertEquals("p1=[p1,p1,p1],p2=[2,2,2]", r);
+
+ r = client.doGet(url + "?p1&p2").getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ r = client.doGet(url).getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ r = client.doGet(url + "?p1").getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ r = client.doGet(url + "?p2").getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ r = client.doGet(url + "?p1=foo&p2").getResponseAsString();
+ assertEquals("p1=[foo,foo,foo],p2=[0,null,0]", r);
+
+ r = client.doGet(url + "?p1&p2=1").getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[1,1,1]", r);
+
+ String x = "a%2Fb%25c%3Dd+e"; // [x/y%z=a+b]
+ r = client.doGet(url + "?p1="+x+"&p2=1").getResponseAsString();
+ assertEquals("p1=[a/b%c=d e,a/b%c=d e,a/b%c=d e],p2=[1,1,1]", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // @Param(format=PLAIN) annotation - GET
+ //====================================================================================================
+ @Test
+ public void testPlainParamGet() throws Exception {
+ RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
+ String r;
+ String url = URL + "/testPlainParamGet";
+
+ r = client.doGet(url + "?p1=(p1)").getResponseAsString();
+ assertEquals("p1=[(p1),(p1),p1]", r);
+
+ r = client.doGet(url + "?p1=$s(p1)").getResponseAsString();
+ assertEquals("p1=[$s(p1),$s(p1),p1]", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // @Param annotation - POST
+ //====================================================================================================
+ @Test
+ public void testParamPost() throws Exception {
+ RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
+ String r;
+ String url = URL + "/testParamPost";
+
+ r = client.doFormPost(url, new ObjectMap("{p1:'p1',p2:2}")).getResponseAsString();
+ assertEquals("p1=[p1,p1,p1],p2=[2,$n(2),2]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:null,p2:0}")).getResponseAsString();
+ assertEquals("p1=[null,\u0000,null],p2=[0,$n(0),0]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{}")).getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:null}")).getResponseAsString();
+ assertEquals("p1=[null,\u0000,null],p2=[0,null,0]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p2:0}")).getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,$n(0),0]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:'foo',p2:0}")).getResponseAsString();
+ assertEquals("p1=[foo,foo,foo],p2=[0,$n(0),0]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:null,p2:1}")).getResponseAsString();
+ assertEquals("p1=[null,\u0000,null],p2=[1,$n(1),1]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:'a/b%c=d e,f/g%h=i j',p2:1}")).getResponseAsString();
+ assertEquals("p1=[a/b%c=d e,f/g%h=i j,a/b%c=d e,f/g%h=i j,a/b%c=d e,f/g%h=i j],p2=[1,$n(1),1]", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // @Param(format=PLAIN) annotation - POST
+ //====================================================================================================
+ @Test
+ public void testPlainParamPost() throws Exception {
+ RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
+ String r;
+ String url = URL + "/testPlainParamPost";
+
+ List<NameValuePair> nvps = new ArrayList<NameValuePair>();
+ nvps.add(new BasicNameValuePair("p1", "(p1)"));
+ HttpEntity he = new UrlEncodedFormEntity(nvps);
+
+ r = client.doPost(url, he).getResponseAsString();
+ assertEquals("p1=[(p1),(p1),p1]", r);
+
+ nvps = new ArrayList<NameValuePair>();
+ nvps.add(new BasicNameValuePair("p1", "$s(p1)"));
+ he = new UrlEncodedFormEntity(nvps);
+
+ r = client.doFormPost(url, he).getResponseAsString();
+ assertEquals("p1=[$s(p1),$s(p1),p1]", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // @QParam annotation - GET
+ //====================================================================================================
+ @Test
+ public void testQParamGet() throws Exception {
+ RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
+ String r;
+ String url = URL + "/testQParamGet";
+
+ r = client.doGet(url + "?p1=p1&p2=2").getResponseAsString();
+ assertEquals("p1=[p1,p1,p1],p2=[2,2,2]", r);
+
+ r = client.doGet(url + "?p1&p2").getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ r = client.doGet(url).getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ r = client.doGet(url + "?p1").getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ r = client.doGet(url + "?p2").getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ r = client.doGet(url + "?p1=foo&p2").getResponseAsString();
+ assertEquals("p1=[foo,foo,foo],p2=[0,null,0]", r);
+
+ r = client.doGet(url + "?p1&p2=1").getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[1,1,1]", r);
+
+ String x = "a%2Fb%25c%3Dd+e"; // [x/y%z=a+b]
+ r = client.doGet(url + "?p1="+x+"&p2=1").getResponseAsString();
+ assertEquals("p1=[a/b%c=d e,a/b%c=d e,a/b%c=d e],p2=[1,1,1]", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // @QParam(format=PLAIN) annotation - GET
+ //====================================================================================================
+ @Test
+ public void testPlainQParamGet() throws Exception {
+ RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
+ String r;
+ String url = URL + "/testPlainQParamGet";
+
+ r = client.doGet(url + "?p1=(p1)").getResponseAsString();
+ assertEquals("p1=[(p1),(p1),p1]", r);
+
+ r = client.doGet(url + "?p1=$s(p1)").getResponseAsString();
+ assertEquals("p1=[$s(p1),$s(p1),p1]", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // @QParam annotation - POST
+ //====================================================================================================
+ @Test
+ public void testQParamPost() throws Exception {
+ RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
+ String r;
+ String url = URL + "/testQParamPost";
+
+ r = client.doFormPost(url, new ObjectMap("{p1:'p1',p2:2}")).getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:null,p2:0}")).getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{}")).getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:null}")).getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p2:0}")).getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:'foo',p2:0}")).getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:null,p2:1}")).getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:'a/b%c=d e,f/g%h=i j',p2:1}")).getResponseAsString();
+ assertEquals("p1=[null,null,null],p2=[0,null,0]", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // @HasParam annotation - GET
+ //====================================================================================================
+ @Test
+ public void testHasParamGet() throws Exception {
+ RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
+ String r;
+ String url = URL + "/testHasParamGet";
+
+ r = client.doGet(url + "?p1=p1&p2=2").getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ r = client.doGet(url + "?p1&p2").getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ r = client.doGet(url).getResponseAsString();
+ assertEquals("p1=[false,false],p2=[false,false]", r);
+
+ r = client.doGet(url + "?p1").getResponseAsString();
+ assertEquals("p1=[true,true],p2=[false,false]", r);
+
+ r = client.doGet(url + "?p2").getResponseAsString();
+ assertEquals("p1=[false,false],p2=[true,true]", r);
+
+ r = client.doGet(url + "?p1=foo&p2").getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ r = client.doGet(url + "?p1&p2=1").getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ String x = "x%2Fy%25z%3Da+b"; // [x/y%z=a+b]
+ r = client.doGet(url + "?p1="+x+"&p2=1").getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // @HasParam annotation - POST
+ //====================================================================================================
+ @Test
+ public void testHasParamPost() throws Exception {
+ RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
+ String r;
+ String url = URL + "/testHasParamPost";
+
+ r = client.doFormPost(url, new ObjectMap("{p1:'p1',p2:2}")).getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:null,p2:0}")).getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{}")).getResponseAsString();
+ assertEquals("p1=[false,false],p2=[false,false]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:null}")).getResponseAsString();
+ assertEquals("p1=[true,true],p2=[false,false]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p2:0}")).getResponseAsString();
+ assertEquals("p1=[false,false],p2=[true,true]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:'foo',p2:0}")).getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:null,p2:1}")).getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:'a/b%c=d e,f/g%h=i j',p2:1}")).getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // @HasQParam annotation - GET
+ //====================================================================================================
+ @Test
+ public void testHasQParamGet() throws Exception {
+ RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
+ String r;
+ String url = URL + "/testHasQParamGet";
+
+ r = client.doGet(url + "?p1=p1&p2=2").getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ r = client.doGet(url + "?p1&p2").getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ r = client.doGet(url).getResponseAsString();
+ assertEquals("p1=[false,false],p2=[false,false]", r);
+
+ r = client.doGet(url + "?p1").getResponseAsString();
+ assertEquals("p1=[true,true],p2=[false,false]", r);
+
+ r = client.doGet(url + "?p2").getResponseAsString();
+ assertEquals("p1=[false,false],p2=[true,true]", r);
+
+ r = client.doGet(url + "?p1=foo&p2").getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ r = client.doGet(url + "?p1&p2=1").getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ String x = "x%2Fy%25z%3Da+b"; // [x/y%z=a+b]
+ r = client.doGet(url + "?p1="+x+"&p2=1").getResponseAsString();
+ assertEquals("p1=[true,true],p2=[true,true]", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // @HasQParam annotation - POST
+ //====================================================================================================
+ @Test
+ public void testHasQParamPost() throws Exception {
+ RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
+ String r;
+ String url = URL + "/testHasQParamPost";
+
+ r = client.doFormPost(url, new ObjectMap("{p1:'p1',p2:2}")).getResponseAsString();
+ assertEquals("p1=[false,false],p2=[false,false]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:null,p2:0}")).getResponseAsString();
+ assertEquals("p1=[false,false],p2=[false,false]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{}")).getResponseAsString();
+ assertEquals("p1=[false,false],p2=[false,false]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:null}")).getResponseAsString();
+ assertEquals("p1=[false,false],p2=[false,false]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p2:0}")).getResponseAsString();
+ assertEquals("p1=[false,false],p2=[false,false]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:'foo',p2:0}")).getResponseAsString();
+ assertEquals("p1=[false,false],p2=[false,false]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:null,p2:1}")).getResponseAsString();
+ assertEquals("p1=[false,false],p2=[false,false]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{p1:'a/b%c=d e,f/g%h=i j',p2:1}")).getResponseAsString();
+ assertEquals("p1=[false,false],p2=[false,false]", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Form POSTS with @Content parameter
+ //====================================================================================================
+ @Test
+ public void testFormPostAsContent() throws Exception {
+ RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
+ String r;
+ String url = URL + "/testFormPostAsContent";
+
+ r = client.doFormPost(url, new ObjectMap("{p1:'p1',p2:2}")).getResponseAsString();
+ assertEquals("bean=[{p1:'p1',p2:2}],qp1=[null],qp2=[0],hqp1=[false],hqp2=[false]", r);
+
+ r = client.doFormPost(url, new ObjectMap("{}")).getResponseAsString();
+ assertEquals("bean=[{p2:0}],qp1=[null],qp2=[0],hqp1=[false],hqp2=[false]", r);
+
+ r = client.doFormPost(url+"?p1=p3&p2=4", new ObjectMap("{p1:'p1',p2:2}")).getResponseAsString();
+ assertEquals("bean=[{p1:'p1',p2:2}],qp1=[p3],qp2=[4],hqp1=[true],hqp2=[true]", r);
+
+ r = client.doFormPost(url+"?p1=p3&p2=4", new ObjectMap("{}")).getResponseAsString();
+ assertEquals("bean=[{p2:0}],qp1=[p3],qp2=[4],hqp1=[true],hqp2=[true]", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Test @Param and @QParam annotations when using multi-part parameters (e.g. &key=val1,&key=val2).
+ //====================================================================================================
+ @Test
+ public void testMultiPartParams() throws Exception {
+ RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
+ String r;
+ String url = URL + "/testMultiPartParams";
+
+ String in = ""
+ + "?p1=a&p1=b"
+ + "&p2=1&p2=2"
+ + "&p3=a&p3=b"
+ + "&p4=1&p4=2"
+ + "&p5=a&p5=b"
+ + "&p6=1&p6=2"
+ + "&p7=a&p7=b"
+ + "&p8=1&p8=2"
+ + "&p9=(a=1,b=2,c=false)&p9=(a=3,b=4,c=true)"
+ + "&p10=(a=1,b=2,c=false)&p10=(a=3,b=4,c=true)"
+ + "&p11=(a=1,b=2,c=false)&p11=(a=3,b=4,c=true)"
+ + "&p12=(a=1,b=2,c=false)&p12=(a=3,b=4,c=true)";
+ r = client.doGet(url + in).getResponseAsString();
+ String e = "{"
+ + "p1:['a','b'],"
+ + "p2:[1,2],"
+ + "p3:['a','b'],"
+ + "p4:[1,2],"
+ + "p5:['a','b'],"
+ + "p6:[1,2],"
+ + "p7:['a','b'],"
+ + "p8:[1,2],"
+ + "p9:[{a:'1',b:2,c:false},{a:'3',b:4,c:true}],"
+ + "p10:[{a:'1',b:2,c:false},{a:'3',b:4,c:true}],"
+ + "p11:[{a:'1',b:2,c:false},{a:'3',b:4,c:true}],"
+ + "p12:[{a:'1',b:2,c:false},{a:'3',b:4,c:true}]"
+ +"}";
+ assertEquals(e, r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Same as testMultiPartParams(), except make sure single values are still interpreted as collections.
+ //====================================================================================================
+ @Test
+ public void testMultiPartParamsSingleValues() throws Exception {
+ RestClient client = new TestRestClient().setHeader("Accept", "text/plain");
+ String r;
+ String url = URL + "/testMultiPartParams";
+
+ String in = ""
+ + "?p1=a"
+ + "&p2=1"
+ + "&p3=a"
+ + "&p4=1"
+ + "&p5=a"
+ + "&p6=1"
+ + "&p7=a"
+ + "&p8=1"
+ + "&p9=(a=1,b=2,c=false)"
+ + "&p10=(a=1,b=2,c=false)"
+ + "&p11=(a=1,b=2,c=false)"
+ + "&p12=(a=1,b=2,c=false)";
+ r = client.doGet(url + in).getResponseAsString();
+ String e = "{"
+ + "p1:['a'],"
+ + "p2:[1],"
+ + "p3:['a'],"
+ + "p4:[1],"
+ + "p5:['a'],"
+ + "p6:[1],"
+ + "p7:['a'],"
+ + "p8:[1],"
+ + "p9:[{a:'1',b:2,c:false}],"
+ + "p10:[{a:'1',b:2,c:false}],"
+ + "p11:[{a:'1',b:2,c:false}],"
+ + "p12:[{a:'1',b:2,c:false}]"
+ +"}";
+ assertEquals(e, r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Test multi-part parameter keys on bean properties of type array/Collection (i.e. &key=val1,&key=val2)
+ // using URLENC_expandedParams property.
+ // A simple round-trip test to verify that both serializing and parsing works.
+ //====================================================================================================
+ @Test
+ public void testFormPostsWithMultiParamsUsingProperty() throws Exception {
+ RestClient client = new TestRestClient()
+ .setHeader("Content-Type", "application/x-www-form-urlencoded")
+ .setHeader("Accept", "application/x-www-form-urlencoded");
+ String r;
+ String url = URL + "/testFormPostsWithMultiParamsUsingProperty";
+
+ String in = ""
+ + "f1=a&f1=b"
+ + "&f2=c&f2=d"
+ + "&f3=1&f3=2"
+ + "&f4=3&f4=4"
+ + "&f5=(e,f)&f5=(g,h)"
+ + "&f6=(i,j)&f6=(k,l)"
+ + "&f7=(a=a,b=1,c=true)&f7=(a=b,b=2,c=false)"
+ + "&f8=(a=a,b=1,c=true)&f8=(a=b,b=2,c=false)"
+ + "&f9=((a=a,b=1,c=true))&f9=((a=b,b=2,c=false))"
+ + "&f10=((a=a,b=1,c=true))&f10=((a=b,b=2,c=false))"
+ + "&f11=a&f11=b"
+ + "&f12=c&f12=d"
+ + "&f13=1&f13=2"
+ + "&f14=3&f14=4"
+ + "&f15=(e,f)&f15=(g,h)"
+ + "&f16=(i,j)&f16=(k,l)"
+ + "&f17=(a=a,b=1,c=true)&f17=(a=b,b=2,c=false)"
+ + "&f18=(a=a,b=1,c=true)&f18=(a=b,b=2,c=false)"
+ + "&f19=((a=a,b=1,c=true))&f19=((a=b,b=2,c=false))"
+ + "&f20=((a=a,b=1,c=true))&f20=((a=b,b=2,c=false))";
+ r = client.doPost(url, new StringEntity(in)).getResponseAsString();
+ assertEquals(in, r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Test multi-part parameter keys on bean properties of type array/Collection (i.e. &key=val1,&key=val2)
+ // using @UrlEncoding(expandedParams=true) annotation.
+ // A simple round-trip test to verify that both serializing and parsing works.
+ //====================================================================================================
+ @Test
+ public void testFormPostsWithMultiParamsUsingAnnotation() throws Exception {
+ RestClient client = new TestRestClient()
+ .setHeader("Content-Type", "application/x-www-form-urlencoded")
+ .setHeader("Accept", "application/x-www-form-urlencoded");
+ String r;
+ String url = URL + "/testFormPostsWithMultiParamsUsingAnnotation";
+
+ String in = ""
+ + "f1=a&f1=b"
+ + "&f2=c&f2=d"
+ + "&f3=1&f3=2"
+ + "&f4=3&f4=4"
+ + "&f5=(e,f)&f5=(g,h)"
+ + "&f6=(i,j)&f6=(k,l)"
+ + "&f7=(a=a,b=1,c=true)&f7=(a=b,b=2,c=false)"
+ + "&f8=(a=a,b=1,c=true)&f8=(a=b,b=2,c=false)"
+ + "&f9=((a=a,b=1,c=true))&f9=((a=b,b=2,c=false))"
+ + "&f10=((a=a,b=1,c=true))&f10=((a=b,b=2,c=false))"
+ + "&f11=a&f11=b"
+ + "&f12=c&f12=d"
+ + "&f13=1&f13=2"
+ + "&f14=3&f14=4"
+ + "&f15=(e,f)&f15=(g,h)"
+ + "&f16=(i,j)&f16=(k,l)"
+ + "&f17=(a=a,b=1,c=true)&f17=(a=b,b=2,c=false)"
+ + "&f18=(a=a,b=1,c=true)&f18=(a=b,b=2,c=false)"
+ + "&f19=((a=a,b=1,c=true))&f19=((a=b,b=2,c=false))"
+ + "&f20=((a=a,b=1,c=true))&f20=((a=b,b=2,c=false))";
+ r = client.doPost(url, new StringEntity(in)).getResponseAsString();
+ assertEquals(in, r);
+
+ client.closeQuietly();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/ParsersTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/ParsersTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/ParsersTest.java
new file mode 100755
index 0000000..2e4890c
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/ParsersTest.java
@@ -0,0 +1,162 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static javax.servlet.http.HttpServletResponse.*;
+import static org.apache.juneau.server.TestUtils.*;
+import static org.junit.Assert.*;
+
+import org.apache.juneau.client.*;
+import org.apache.juneau.plaintext.*;
+import org.junit.*;
+
+public class ParsersTest {
+
+ private static String URL = "/testParsers";
+ private static boolean debug = false;
+
+ //====================================================================================================
+ // Parser defined on class.
+ //====================================================================================================
+ @Test
+ public void testParserOnClass() throws Exception {
+ RestClient client = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class);
+ String url = URL + "/testParserOnClass";
+
+ client.setContentType("text/a");
+ String r = client.doPut(url, "test1").getResponseAsString();
+ assertEquals("text/a - test1", r);
+
+ try {
+ client.setContentType("text/b");
+ client.doPut(url + "?noTrace=true", "test1").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
+ "Unsupported media-type in request header 'Content-Type': 'text/b'",
+ "Supported media-types: [text/a"
+ );
+ }
+
+ client.setContentType("text/json").setAccept("text/json");
+ r = client.doPut(url, "'test1'").getResponseAsString();
+ assertEquals("\"test1\"", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Parser defined on method.
+ //====================================================================================================
+ @Test
+ public void testParserOnMethod() throws Exception {
+ RestClient client = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class);
+ String url = URL + "/testParserOnMethod";
+
+ client.setContentType("text/b");
+ String r = client.doPut(url, "test2").getResponseAsString();
+ assertEquals("text/b - test2", r);
+
+ try {
+ client.setContentType("text/a");
+ client.doPut(url + "?noTrace=true", "test2").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
+ "Unsupported media-type in request header 'Content-Type': 'text/a'",
+ "Supported media-types: [text/b]"
+ );
+ }
+
+ try {
+ client.setContentType("text/json");
+ r = client.doPut(url + "?noTrace=true", "'test2'").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/b]"
+ );
+ }
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Parser overridden on method.
+ //====================================================================================================
+ @Test
+ public void testParserOverriddenOnMethod() throws Exception {
+ RestClient client = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class);
+ String url = URL + "/testParserOverriddenOnMethod";
+
+ client.setContentType("text/a");
+ String r = client.doPut(url, "test3").getResponseAsString();
+ assertEquals("text/a - test3", r);
+
+ client.setContentType("text/b");
+ r = client.doPut(url, "test3").getResponseAsString();
+ assertEquals("text/b - test3", r);
+
+ client.setContentType("text/json");
+ r = client.doPut(url, "'test3'").getResponseAsString();
+ assertEquals("test3", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Parser with different Accept than Content-Type.
+ //====================================================================================================
+ @Test
+ public void testParserWithDifferentMediaTypes() throws Exception {
+ RestClient client = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class);
+ String url = URL + "/testParserWithDifferentMediaTypes";
+
+ client.setContentType("text/a");
+ String r = client.doPut(url, "test4").getResponseAsString();
+ assertEquals("text/d - test4", r);
+
+ client.setContentType("text/d");
+ r = client.doPut(url, "test4").getResponseAsString();
+ assertEquals("text/d - test4", r);
+
+ client.setContentType("text/json");
+ r = client.doPut(url, "'test4'").getResponseAsString();
+ assertEquals("test4", r);
+
+ client.closeQuietly();
+ }
+
+ //====================================================================================================
+ // Check for valid error response.
+ //====================================================================================================
+ @Test
+ public void testValidErrorResponse() throws Exception {
+ RestClient client = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class);
+ String url = URL + "/testValidErrorResponse";
+
+ try {
+ client.setContentType("text/bad");
+ client.doPut(url + "?noTrace=true", "test1").getResponseAsString();
+ fail("Exception expected");
+ } catch (RestCallException e) {
+ checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE,
+ "Unsupported media-type in request header 'Content-Type': 'text/bad'",
+ "Supported media-types: [text/a"
+ );
+ }
+
+ client.closeQuietly();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/PathTest.java
----------------------------------------------------------------------
diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/PathTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/PathTest.java
new file mode 100755
index 0000000..2870661
--- /dev/null
+++ b/juneau-server-test/src/test/java/org/apache/juneau/server/PathTest.java
@@ -0,0 +1,44 @@
+/***************************************************************************************************************************
+ * 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;
+
+import static org.junit.Assert.*;
+
+import org.apache.juneau.client.*;
+import org.apache.juneau.json.*;
+import org.junit.*;
+
+public class PathTest {
+
+ private static String URL = "/testPath";
+
+ //====================================================================================================
+ // Basic tests
+ //====================================================================================================
+ @Test
+ public void testBasic() throws Exception {
+ RestClient client = new TestRestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT);
+ String r = null;
+
+ r = client.doGet(URL).getResponse(String.class);
+ assertEquals("/testPath", r);
+
+ r = client.doGet(URL + "/testPath2").getResponse(String.class);
+ assertEquals("/testPath/testPath2", r);
+
+ r = client.doGet(URL + "/testPath2/testPath3").getResponse(String.class);
+ assertEquals("/testPath/testPath2/testPath3", r);
+
+ client.closeQuietly();
+ }
+}