http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-server-test/src/test/java/org/apache/juneau/server/test/GzipTest.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/test/GzipTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/test/GzipTest.java deleted file mode 100755 index 513c90d..0000000 --- a/juneau-server-test/src/test/java/org/apache/juneau/server/test/GzipTest.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.test; - -import static javax.servlet.http.HttpServletResponse.*; -import static org.apache.juneau.server.test.TestUtils.*; -import static org.junit.Assert.*; - -import java.io.*; -import java.util.zip.*; - -import org.apache.http.impl.client.*; -import org.apache.juneau.client.*; -import org.apache.juneau.internal.*; -import org.junit.*; - -/** - * Test Accept-Encoding and Content-Encoding handling. - * - * Note: WAS does automatic gzip decompression on http request messages, so we have to invent - * our own 'mycoding' compression. - */ -public class GzipTest { - - private static boolean debug = false; - - private static String testGzipOff = "/testGzipOff"; - private static String testGzipOn = "/testGzipOn"; - - // Converts string into a GZipped input stream. - private static InputStream compress(String contents) throws Exception { - ByteArrayOutputStream baos = new ByteArrayOutputStream(contents.length()>>1); - GZIPOutputStream gos = new GZIPOutputStream(baos); - gos.write(contents.getBytes()); - gos.finish(); - gos.close(); - return new ByteArrayInputStream(baos.toByteArray()); - } - - private static String decompress(InputStream is) throws Exception { - return IOUtils.read(new GZIPInputStream(is)); - } - - //==================================================================================================== - // Test with no compression enabled. - //==================================================================================================== - @Test - public void testGzipOff() throws Exception { - RestClient c = new TestRestClient().setAccept("text/plain").setContentType("text/plain"); - RestCall r; - String url = testGzipOff; - - // *** GET *** - - r = c.doGet(url); - assertEquals("foo", r.getResponseAsString()); - - r = c.doGet(url).setHeader("Accept-Encoding", ""); - assertEquals("foo", r.getResponseAsString()); - - r = c.doGet(url).setHeader("Accept-Encoding", "*"); - assertEquals("foo", r.getResponseAsString()); - - r = c.doGet(url).setHeader("Accept-Encoding", "identity"); - assertEquals("foo", r.getResponseAsString()); - - // Should match identity. - r = c.doGet(url).setHeader("Accept-Encoding", "mycoding"); - assertEquals("foo", r.getResponseAsString()); - - // Shouldn't match. - try { - r = c.doGet(url+"?noTrace=true").setHeader("Accept-Encoding", "mycoding,identity;q=0").connect(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, - "Unsupported encoding in request header 'Accept-Encoding': 'mycoding,identity;q=0'", - "Supported codings: [identity]" - ); - } - - // Shouldn't match. - try { - c.doGet(url+"?noTrace=true").setHeader("Accept-Encoding", "mycoding,*;q=0").connect(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, - "Unsupported encoding in request header 'Accept-Encoding': 'mycoding,*;q=0'", - "Supported codings: [identity]" - ); - } - - // Should match identity - r = c.doGet(url).setHeader("Accept-Encoding", "identity;q=0.8,mycoding;q=0.6"); - assertEquals("foo", r.getResponseAsString()); - - // Should match identity - r = c.doGet(url).setHeader("Accept-Encoding", "mycoding;q=0.8,identity;q=0.6"); - assertEquals("foo", r.getResponseAsString()); - - // Should match identity - r = c.doGet(url).setHeader("Accept-Encoding", "mycoding;q=0.8,*;q=0.6"); - assertEquals("foo", r.getResponseAsString()); - - // Should match identity - r = c.doGet(url).setHeader("Accept-Encoding", "*;q=0.8,myencoding;q=0.6"); - assertEquals("foo", r.getResponseAsString()); - - // Shouldn't match - try { - c.doGet(url+"?noTrace=true").setHeader("Accept-Encoding", "identity;q=0").connect(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, - "Unsupported encoding in request header 'Accept-Encoding': 'identity;q=0'", - "Supported codings: [identity]" - ); - } - - // Shouldn't match - try { - c.doGet(url+"?noTrace=true").setHeader("Accept-Encoding", "identity;q=0.0").connect(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, - "Unsupported encoding in request header 'Accept-Encoding': 'identity;q=0.0'", - "Supported codings: [identity]" - ); - } - - // Shouldn't match - try { - c.doGet(url+"?noTrace=true").setHeader("Accept-Encoding", "*;q=0").connect(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, - "Unsupported encoding in request header 'Accept-Encoding': '*;q=0'", - "Supported codings: [identity]" - ); - } - - // Shouldn't match - try { - c.doGet(url+"?noTrace=true").setHeader("Accept-Encoding", "*;q=0.0").connect(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, - "Unsupported encoding in request header 'Accept-Encoding': '*;q=0.0'", - "Supported codings: [identity]" - ); - } - - - // *** PUT *** - - r = c.doPut(url, new StringReader("foo")); - assertEquals("foo", r.getResponseAsString()); - - r = c.doPut(url, new StringReader("foo")).setHeader("Content-Encoding", ""); - assertEquals("foo", r.getResponseAsString()); - - r = c.doPut(url, new StringReader("foo")).setHeader("Content-Encoding", "identity"); - assertEquals("foo", r.getResponseAsString()); - - try { - c.doPut(url+"?noTrace=true", compress("foo")).setHeader("Content-Encoding", "mycoding").connect(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE, - "Unsupported encoding in request header 'Content-Encoding': 'mycoding'", - "Supported codings: [identity]" - ); - } - - c.closeQuietly(); - } - - //==================================================================================================== - // Test with compression enabled. - //==================================================================================================== - @Test - public void testGzipOn() throws Exception { - - // Create a client that disables content compression support so that we can get the gzipped content directly. - CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(TestRestClient.getSSLSocketFactory()).disableContentCompression().build(); - - RestClient c = new TestRestClient(httpClient).setAccept("text/plain").setContentType("text/plain"); - RestCall r; - String url = testGzipOn; - - // *** GET *** - - r = c.doGet(url); - assertEquals("foo", r.getResponseAsString()); - - r = c.doGet(url).setHeader("Accept-Encoding", ""); - assertEquals("foo", r.getResponseAsString()); - - r = c.doGet(url).setHeader("Accept-Encoding", "*"); - assertEquals("foo", decompress(r.getInputStream())); - - r = c.doGet(url).setHeader("Accept-Encoding", "identity"); - assertEquals("foo", r.getResponseAsString()); - - // Should match identity. - r = c.doGet(url).setHeader("Accept-Encoding", "mycoding"); - assertEquals("foo", decompress(r.getInputStream())); - - r = c.doGet(url).setHeader("Accept-Encoding", "mycoding,identity;q=0").connect(); - assertEquals("foo", decompress(r.getInputStream())); - - r = c.doGet(url).setHeader("Accept-Encoding", "mycoding,*;q=0").connect(); - assertEquals("foo", decompress(r.getInputStream())); - - // Should match identity - r = c.doGet(url).setHeader("Accept-Encoding", "identity;q=0.8,mycoding;q=0.6"); - assertEquals("foo", r.getResponseAsString()); - - // Should match mycoding - r = c.doGet(url).setHeader("Accept-Encoding", "mycoding;q=0.8,identity;q=0.6"); - assertEquals("foo", decompress(r.getInputStream())); - - // Should match mycoding - r = c.doGet(url).setHeader("Accept-Encoding", "mycoding;q=0.8,*;q=0.6"); - assertEquals("foo", decompress(r.getInputStream())); - - // Should match identity - r = c.doGet(url).setHeader("Accept-Encoding", "*;q=0.8,myencoding;q=0.6"); - assertEquals("foo", decompress(r.getInputStream())); - - // Shouldn't match - try { - c.doGet(url+"?noTrace=true").setHeader("Accept-Encoding", "identity;q=0").connect(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, - "Unsupported encoding in request header 'Accept-Encoding': 'identity;q=0'", - "Supported codings: [mycoding, identity]" - ); - } - - // Shouldn't match - try { - c.doGet(url+"?noTrace=true").setHeader("Accept-Encoding", "identity;q=0.0").connect(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, - "Unsupported encoding in request header 'Accept-Encoding': 'identity;q=0.0'", - "Supported codings: [mycoding, identity]" - ); - } - - // Shouldn't match - try { - c.doGet(url+"?noTrace=true").setHeader("Accept-Encoding", "*;q=0").connect(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, - "Unsupported encoding in request header 'Accept-Encoding': '*;q=0'", - "Supported codings: [mycoding, identity]" - ); - } - - // Shouldn't match - try { - c.doGet(url+"?noTrace=true").setHeader("Accept-Encoding", "*;q=0.0").connect(); - fail("Exception expected"); - } catch (RestCallException e) { - checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, - "Unsupported encoding in request header 'Accept-Encoding': '*;q=0.0'", - "Supported codings: [mycoding, identity]" - ); - } - - - // *** PUT *** - - r = c.doPut(url, new StringReader("foo")); - assertEquals("foo", r.getResponseAsString()); - - r = c.doPut(url, new StringReader("foo")).setHeader("Content-Encoding", ""); - assertEquals("foo", r.getResponseAsString()); - - r = c.doPut(url, new StringReader("foo")).setHeader("Content-Encoding", "identity"); - assertEquals("foo", r.getResponseAsString()); - - r = c.doPut(url, compress("foo")).setHeader("Content-Encoding", "mycoding"); - assertEquals("foo", r.getResponseAsString()); - - c.closeQuietly(); - } - - //==================================================================================================== - // Test with compression enabled but with servlet using output stream directly. - //==================================================================================================== - @Test - public void testGzipOnDirect() throws Exception { - // Create a client that disables content compression support so that we can get the gzipped content directly. - CloseableHttpClient httpClient = HttpClientBuilder.create().setSSLSocketFactory(TestRestClient.getSSLSocketFactory()).build(); - RestClient c = new TestRestClient(httpClient).setAccept("text/plain").setContentType("text/plain"); - RestCall r = null; - String s = null; - - // res.getOutputStream() called....should bypass encoding. - r = c.doGet(testGzipOn + "/direct").setHeader("Accept-Encoding", "mycoding"); - s = r.getResponseAsString(); - assertEquals("test", s); - assertTrue(r.getResponse().getHeaders("Content-Type")[0].getValue().contains("text/direct")); // Should get header set manually. - assertEquals(0, r.getResponse().getHeaders("Content-Encoding").length); // Should not be set. - - // res.getWriter() called....should bypass encoding. - r = c.doGet(testGzipOn + "/direct2").setHeader("Accept-Encoding", "mycoding"); - s = r.getResponseAsString(); - assertEquals("test", s); - assertEquals(0, r.getResponse().getHeaders("Content-Encoding").length); // Should not be set. - - // res.getNegotiateWriter() called....should NOT bypass encoding. - r = c.doGet(testGzipOn + "/direct3").setHeader("Accept-Encoding", "mycoding"); - try { - assertEquals("mycoding", r.getResponse().getHeaders("content-encoding")[0].getValue()); - } catch (RestCallException e) { - // OK - HttpClient doesn't know what mycoding is. - // Newer versions of HttpClient ignore this condition. - } - - // res.getNegotiateWriter() called but @RestMethod(encoders={})...should bypass encoding. - r = c.doGet(testGzipOn + "/direct4").setHeader("Accept-Encoding", "mycoding"); - s = r.getResponseAsString(); - assertEquals("test", s); - assertEquals(0, r.getResponse().getHeaders("Content-Encoding").length); // Should not be set. - - c.closeQuietly(); - } -}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-server-test/src/test/java/org/apache/juneau/server/test/InheritanceTest.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/test/InheritanceTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/test/InheritanceTest.java deleted file mode 100755 index 27f70f8..0000000 --- a/juneau-server-test/src/test/java/org/apache/juneau/server/test/InheritanceTest.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.test; - -import static org.junit.Assert.*; - -import org.apache.juneau.client.*; -import org.apache.juneau.json.*; -import org.junit.*; - -public class InheritanceTest { - - private static RestClient client; - - @BeforeClass - public static void beforeClass() { - client = new TestRestClient(); - } - - @AfterClass - public static void afterClass() { - client.closeQuietly(); - } - - //==================================================================================================== - // Test serializer inheritance. - //==================================================================================================== - @Test - public void testSerializers() throws Exception { - String r; - String url = "/testInheritanceSerializers"; - r = client.doGet(url + "/test1").getResponseAsString(); - assertEquals("['text/s3','text/s4','text/s1','text/s2']", r); - - r = client.doGet(url + "/test2").getResponseAsString(); - assertEquals("['text/s5']", r); - - r = client.doGet(url + "/test3").getResponseAsString(); - assertEquals("['text/s5','text/s3','text/s4','text/s1','text/s2']", r); - } - - //==================================================================================================== - // Test parser inheritance. - //==================================================================================================== - @Test - public void testParsers() throws Exception { - String r; - String url = "/testInheritanceParsers"; - r = client.doGet(url + "/test1").getResponseAsString(); - assertEquals("['text/p3','text/p4','text/p1','text/p2']", r); - - r = client.doGet(url + "/test2").getResponseAsString(); - assertEquals("['text/p5']", r); - - r = client.doGet(url + "/test3").getResponseAsString(); - assertEquals("['text/p5','text/p3','text/p4','text/p1','text/p2']", r); - } - - //==================================================================================================== - // Test encoder inheritance. - //==================================================================================================== - @Test - public void testEncoders() throws Exception { - String url = "/testInheritanceEncoders"; - String r = client.doGet(url + "/test").getResponseAsString(); - assertEquals("['e3','e4','e1','e2','identity']", r); - } - - //==================================================================================================== - // Test filter inheritance. - //==================================================================================================== - @Test - public void testTransforms() throws Exception { - RestClient client = new TestRestClient(JsonSerializer.class, JsonParser.class).setAccept("text/json+simple"); - String r; - String url = "/testInheritanceTransforms"; - - r = client.doGet(url + "/test1").getResponseAsString(); - assertEquals("['F1','F2','Foo3']", r); - - r = client.doGet(url + "/test2").getResponseAsString(); - assertEquals("['F1','F2','F3']", r); - - r = client.doGet(url + "/test3").getResponseAsString(); - assertEquals("['F1','F2','F3']", r); - - r = client.doGet(url + "/test4").getResponseAsString(); - assertEquals("['Foo1','Foo2','F3']", r); - - r = client.doGet(url + "/test5").getResponseAsString(); - assertEquals("['F1','F2','F3']", r); - - client.closeQuietly(); - } - - //==================================================================================================== - // Test properties inheritance. - //==================================================================================================== - @Test - public void testProperties() throws Exception { - RestClient client = new TestRestClient(JsonSerializer.class, JsonParser.class).setAccept("text/json+simple"); - String r; - String url = "/testInheritanceProperties"; - - r = client.doGet(url + "/test1").getResponseAsString(); - assertEquals("{p1:'v1',p2:'v2a',p3:'v3',p4:'v4'}", r); - - r = client.doGet(url + "/test2?override").getResponseAsString(); - assertEquals("{p1:'x',p2:'x',p3:'x',p4:'x',p5:'x'}", r); - - r = client.doGet(url + "/test2").getResponseAsString(); - assertEquals("{p1:'v1',p2:'v2a',p3:'v3',p4:'v4a',p5:'v5'}", r); - - client.closeQuietly(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-server-test/src/test/java/org/apache/juneau/server/test/JacocoDummyTest.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/test/JacocoDummyTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/test/JacocoDummyTest.java deleted file mode 100755 index 27c531a..0000000 --- a/juneau-server-test/src/test/java/org/apache/juneau/server/test/JacocoDummyTest.java +++ /dev/null @@ -1,38 +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.test; - -import java.lang.reflect.*; - -import org.apache.juneau.server.*; -import org.junit.*; - -public class JacocoDummyTest { - - //==================================================================================================== - // Dummy code to add test coverage in Jacoco. - //==================================================================================================== - @Test - public void accessPrivateConstructorsOnStaticUtilityClasses() throws Exception { - - Class<?>[] classes = new Class[] { - RestUtils.class - }; - - for (Class<?> c : classes) { - Constructor<?> c1 = c.getDeclaredConstructor(); - c1.setAccessible(true); - c1.newInstance(); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-server-test/src/test/java/org/apache/juneau/server/test/LargePojosTest.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/test/LargePojosTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/test/LargePojosTest.java deleted file mode 100755 index c06b18f..0000000 --- a/juneau-server-test/src/test/java/org/apache/juneau/server/test/LargePojosTest.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.test; - -import org.apache.juneau.client.*; -import org.apache.juneau.html.*; -import org.apache.juneau.json.*; -import org.apache.juneau.urlencoding.*; -import org.apache.juneau.xml.*; -import org.junit.*; - -@Ignore -public class LargePojosTest { - - private static String URL = "/testLargePojos"; - boolean debug = false; - - //==================================================================================================== - // Test how long it takes to serialize/parse various content types. - //==================================================================================================== - @Test - public void test() throws Exception { - LargePojo p; - long t; - RestClient c; - - System.err.println("\n---Testing JSON---"); - c = new TestRestClient(JsonSerializer.class, JsonParser.class); - for (int i = 1; i <= 3; i++) { - t = System.currentTimeMillis(); - p = c.doGet(URL).getResponse(LargePojo.class); - System.err.println("Download: ["+(System.currentTimeMillis() - t)+"] ms"); - t = System.currentTimeMillis(); - c.doPut(URL, p).run(); - System.err.println("Upload: ["+(System.currentTimeMillis() - t)+"] ms"); - } - - System.err.println("\n---Testing XML---"); - c = new TestRestClient(XmlSerializer.class, XmlParser.class); - for (int i = 1; i <= 3; i++) { - t = System.currentTimeMillis(); - p = c.doGet(URL).getResponse(LargePojo.class); - System.err.println("Download: ["+(System.currentTimeMillis() - t)+"] ms"); - t = System.currentTimeMillis(); - c.doPut(URL, p).run(); - System.err.println("Upload: ["+(System.currentTimeMillis() - t)+"] ms"); - } - - System.err.println("\n---Testing HTML---"); - c = new TestRestClient(HtmlSerializer.class, HtmlParser.class).setAccept("text/html+stripped"); - for (int i = 1; i <= 3; i++) { - t = System.currentTimeMillis(); - p = c.doGet(URL).getResponse(LargePojo.class); - System.err.println("Download: ["+(System.currentTimeMillis() - t)+"] ms"); - t = System.currentTimeMillis(); - c.doPut(URL, p).run(); - System.err.println("Upload: ["+(System.currentTimeMillis() - t)+"] ms"); - } - - System.err.println("\n---Testing UrlEncoding---"); - c = new TestRestClient(UonSerializer.class, UonParser.class); - for (int i = 1; i <= 3; i++) { - t = System.currentTimeMillis(); - p = c.doGet(URL).getResponse(LargePojo.class); - System.err.println("Download: ["+(System.currentTimeMillis() - t)+"] ms"); - t = System.currentTimeMillis(); - c.doPut(URL, p).run(); - System.err.println("Upload: ["+(System.currentTimeMillis() - t)+"] ms"); - } - - c.closeQuietly(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-server-test/src/test/java/org/apache/juneau/server/test/MessagesTest.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/test/MessagesTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/test/MessagesTest.java deleted file mode 100755 index 8d86fee..0000000 --- a/juneau-server-test/src/test/java/org/apache/juneau/server/test/MessagesTest.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.test; - -import static org.apache.juneau.server.test.TestUtils.*; - -import java.util.*; - -import org.apache.juneau.client.*; -import org.apache.juneau.json.*; -import org.junit.*; - -/** - * Validates that resource bundles can be defined on both parent and child classes. - */ -public class MessagesTest { - - //==================================================================================================== - // Return contents of resource bundle. - //==================================================================================================== - @SuppressWarnings("rawtypes") - @Test - public void test() throws Exception { - RestClient client = new TestRestClient(JsonSerializer.class,JsonParser.class); - - // Parent resource should just pick up values from its bundle. - TreeMap r = client.doGet("/testMessages/test").getResponse(TreeMap.class); - assertObjectEquals("{key1:'value1a',key2:'value2a'}", r); - - // Child resource should pick up values from both parent and child, - // ordered child before parent. - r = client.doGet("/testMessages2/test").getResponse(TreeMap.class); - assertObjectEquals("{key1:'value1a',key2:'value2b',key3:'value3b'}", r); - - client.closeQuietly(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-server-test/src/test/java/org/apache/juneau/server/test/NlsPropertyTest.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/test/NlsPropertyTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/test/NlsPropertyTest.java deleted file mode 100755 index 4c6c404..0000000 --- a/juneau-server-test/src/test/java/org/apache/juneau/server/test/NlsPropertyTest.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.test; - -import static org.junit.Assert.*; - -import org.apache.juneau.client.*; -import org.apache.juneau.plaintext.*; -import org.junit.*; - -public class NlsPropertyTest { - - private static String URL = "/testNlsProperty"; - - //==================================================================================================== - // Test getting an NLS property defined on a class. - //==================================================================================================== - @Test - public void testInheritedFromClass() throws Exception { - RestClient client = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class); - String r = client.doGet(URL + "/testInheritedFromClass").getResponseAsString(); - assertEquals("value1", r); - - client.closeQuietly(); - } - - //==================================================================================================== - // Test getting an NLS property defined on a method. - //==================================================================================================== - @Test - public void testInheritedFromMethod() throws Exception { - RestClient client = new TestRestClient(PlainTextSerializer.class, PlainTextParser.class); - String r = client.doGet(URL + "/testInheritedFromMethod").getResponseAsString(); - assertEquals("value2", r); - - client.closeQuietly(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-server-test/src/test/java/org/apache/juneau/server/test/NlsTest.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/test/NlsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/test/NlsTest.java deleted file mode 100755 index 798ecee..0000000 --- a/juneau-server-test/src/test/java/org/apache/juneau/server/test/NlsTest.java +++ /dev/null @@ -1,115 +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.test; - -import static org.apache.juneau.server.test.TestUtils.*; - -import org.apache.juneau.client.*; -import org.apache.juneau.dto.swagger.*; -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); - - Swagger s = client.doOptions(URL + "/test1").getResponse(Swagger.class); - assertObjectEquals("{title:'Test1.a',description:'Test1.b'}", s.getInfo()); - assertObjectEquals("[{'in':'body',description:'Test1.f'},{'in':'header',name:'D',type:'string',description:'Test1.g'},{'in':'header',name:'D2',type:'string',description:'Test1.j'},{'in':'header',name:'g'},{'in':'path',name:'a',type:'string',description:'Test1.d',required:true},{'in':'path',name:'a2',type:'string',description:'Test1.h',required:true},{'in':'path',name:'e',required:true},{'in':'query',name:'b',type:'string',description:'Test1.e'},{'in':'query',name:'b2',type:'string',description:'Test1.i'},{'in':'query',name:'f'}]", s.getPaths().get("/{a}").get("post").getParameters()); - assertObjectEquals("{'200':{description:'OK'},'201':{description:'Test1.l',headers:{bar:{description:'Test1.m',type:'string'}}}}", s.getPaths().get("/{a}").get("post").getResponses()); - - 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); - - Swagger s = client.doOptions(URL + "/test2").getResponse(Swagger.class); - assertObjectEquals("{title:'Test2.a',description:'Test2.b'}", s.getInfo()); - assertObjectEquals("[{'in':'body',description:'Test2.f'},{'in':'header',name:'D',description:'Test2.g'},{'in':'header',name:'D2',description:'Test2.j'},{'in':'header',name:'g'},{'in':'path',name:'a',description:'Test2.d',required:true},{'in':'path',name:'a2',description:'Test2.h',required:true},{'in':'path',name:'e',required:true},{'in':'query',name:'b',description:'Test2.e'},{'in':'query',name:'b2',description:'Test2.i'},{'in':'query',name:'f'}]", s.getPaths().get("/{a}").get("post").getParameters()); - assertObjectEquals("{'200':{description:'OK2'},'201':{description:'Test2.l'}}", s.getPaths().get("/{a}").get("post").getResponses()); - - 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); - - Swagger s = client.doOptions(URL + "/test3").getResponse(Swagger.class); - assertObjectEquals("{title:'Test3.a',description:'Test3.b'}", s.getInfo()); - assertObjectEquals("[{'in':'body',description:'Test3.f'},{'in':'header',name:'D',description:'Test3.g'},{'in':'header',name:'D2',description:'Test3.j'},{'in':'header',name:'g'},{'in':'path',name:'a',description:'Test3.d',required:true},{'in':'path',name:'a2',description:'Test3.h',required:true},{'in':'path',name:'e',required:true},{'in':'query',name:'b',description:'Test3.e'},{'in':'query',name:'b2',description:'Test3.i'},{'in':'query',name:'f'}]", s.getPaths().get("/{a}").get("post").getParameters()); - assertObjectEquals("{'200':{description:'OK3'},'201':{description:'Test3.l'}}", s.getPaths().get("/{a}").get("post").getResponses()); - - 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); - - Swagger s = client.doOptions(URL + "/test4").getResponse(Swagger.class); - assertObjectEquals("{title:'baz',description:'baz'}", s.getInfo()); - assertObjectEquals("[{'in':'body',description:'baz'},{'in':'header',name:'D',description:'baz'},{'in':'header',name:'D2',description:'baz'},{'in':'header',name:'g'},{'in':'path',name:'a',description:'baz',required:true},{'in':'path',name:'a2',description:'baz',required:true},{'in':'path',name:'e',required:true},{'in':'query',name:'b',description:'baz'},{'in':'query',name:'b2',description:'baz'},{'in':'query',name:'f'}]", s.getPaths().get("/{a}").get("post").getParameters()); - assertObjectEquals("{'200':{description:'foobazfoobazfoo'},'201':{description:'baz'}}", s.getPaths().get("/{a}").get("post").getResponses()); - - 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); - - Swagger s = client.doOptions(URL + "/test5").getResponse(Swagger.class); - assertObjectEquals("{title:'baz2',description:'baz2'}", s.getInfo()); - assertObjectEquals("[{'in':'body',description:'baz2'},{'in':'header',name:'D',description:'baz2'},{'in':'header',name:'D2',description:'baz2'},{'in':'header',name:'g'},{'in':'path',name:'a',description:'baz2',required:true},{'in':'path',name:'a2',description:'baz2',required:true},{'in':'path',name:'e',required:true},{'in':'query',name:'b',description:'baz2'},{'in':'query',name:'b2',description:'baz2'},{'in':'query',name:'f'}]", s.getPaths().get("/{a}").get("post").getParameters()); - assertObjectEquals("{'200':{description:'foobaz2foobaz2foo'},'201':{description:'baz2'}}", s.getPaths().get("/{a}").get("post").getResponses()); - - 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); - - Swagger s = client.doOptions(URL + "/test6").getResponse(Swagger.class); - assertObjectEquals("{title:'baz',description:'baz'}", s.getInfo()); - assertObjectEquals("[{'in':'body',description:'baz'},{'in':'header',name:'D',type:'string',description:'baz'},{'in':'header',name:'D2',type:'string',description:'baz'},{'in':'header',name:'g'},{'in':'path',name:'a',type:'string',description:'baz',required:true},{'in':'path',name:'a2',type:'string',description:'baz',required:true},{'in':'path',name:'e',required:true},{'in':'query',name:'b',type:'string',description:'baz'},{'in':'query',name:'b2',type:'string',description:'baz'},{'in':'query',name:'f'}]", s.getPaths().get("/{a}").get("post").getParameters()); - assertObjectEquals("{'200':{description:'OK'},'201':{description:'baz',headers:{bar:{description:'baz',type:'string'}}}}", s.getPaths().get("/{a}").get("post").getResponses()); - - client.closeQuietly(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-server-test/src/test/java/org/apache/juneau/server/test/NoParserInputTest.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/test/NoParserInputTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/test/NoParserInputTest.java deleted file mode 100755 index 8d5b4ab..0000000 --- a/juneau-server-test/src/test/java/org/apache/juneau/server/test/NoParserInputTest.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.test; - -import static javax.servlet.http.HttpServletResponse.*; -import static org.apache.juneau.server.test.TestUtils.*; -import static org.junit.Assert.*; - -import org.apache.juneau.client.*; -import org.apache.juneau.plaintext.*; -import org.junit.*; - -public class NoParserInputTest { - - private static String URL = "/testNoParserInput"; - private static boolean debug = false; - - //==================================================================================================== - // @Body 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(); - } - - //==================================================================================================== - // @Body 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(); - } - - //==================================================================================================== - // @Body 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.test.NoParserInputResource.testPushbackReader(java.io.PushbackReader) throws java.lang.Exception'"); - } - - client.closeQuietly(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/91a388d0/juneau-server-test/src/test/java/org/apache/juneau/server/test/OnPostCallTest.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/test/OnPostCallTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/test/OnPostCallTest.java deleted file mode 100755 index ae64011..0000000 --- a/juneau-server-test/src/test/java/org/apache/juneau/server/test/OnPostCallTest.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.test; - -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/91a388d0/juneau-server-test/src/test/java/org/apache/juneau/server/test/OnPreCallTest.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/test/OnPreCallTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/test/OnPreCallTest.java deleted file mode 100755 index 173a472..0000000 --- a/juneau-server-test/src/test/java/org/apache/juneau/server/test/OnPreCallTest.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.test; - -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/91a388d0/juneau-server-test/src/test/java/org/apache/juneau/server/test/OptionsWithoutNlsTest.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/test/OptionsWithoutNlsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/test/OptionsWithoutNlsTest.java deleted file mode 100755 index 27862dc..0000000 --- a/juneau-server-test/src/test/java/org/apache/juneau/server/test/OptionsWithoutNlsTest.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.test; - -import static org.junit.Assert.*; - -import org.apache.juneau.client.*; -import org.apache.juneau.dto.swagger.*; -import org.apache.juneau.json.*; -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"); - Swagger o = r.getResponse(Swagger.class); - assertNotNull(o.getInfo()); - - 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/91a388d0/juneau-server-test/src/test/java/org/apache/juneau/server/test/OverlappingMethodsTest.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/test/OverlappingMethodsTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/test/OverlappingMethodsTest.java deleted file mode 100755 index 0573eda..0000000 --- a/juneau-server-test/src/test/java/org/apache/juneau/server/test/OverlappingMethodsTest.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.test; - -import static javax.servlet.http.HttpServletResponse.*; -import static org.apache.juneau.server.test.TestUtils.*; -import static org.junit.Assert.*; - -import org.apache.juneau.client.*; -import org.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(); - } -}