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(); - } -}
