http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestParsers.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestParsers.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestParsers.java deleted file mode 100755 index 2b3e55a..0000000 --- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestParsers.java +++ /dev/null @@ -1,111 +0,0 @@ -/*************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - ***************************************************************************************************************************/ -package org.apache.juneau.server; - -import static org.apache.juneau.server.annotation.Inherit.*; - -import org.apache.juneau.*; -import org.apache.juneau.annotation.*; -import org.apache.juneau.internal.*; -import org.apache.juneau.parser.*; -import org.apache.juneau.plaintext.*; -import org.apache.juneau.server.annotation.*; - -/** - * JUnit automated testcase resource. - * Validates correct parser is used. - */ -@RestResource( - path="/testParsers", - parsers=TestParsers.TestParserA.class, - serializers=PlainTextSerializer.class -) -public class TestParsers extends RestServletDefault { - private static final long serialVersionUID = 1L; - - @Consumes("text/a") - public static class TestParserA extends ReaderParser { - @SuppressWarnings("unchecked") - @Override /* Parser */ - protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception { - return (T)("text/a - " + IOUtils.read(session.getReader()).trim()); - } - } - - //==================================================================================================== - // Parser defined on class. - //==================================================================================================== - @RestMethod(name="PUT", path="/testParserOnClass") - public String testParserOnClass(@Content String in) { - return in; - } - - //==================================================================================================== - // Parser defined on method. - //==================================================================================================== - @RestMethod(name="PUT", path="/testParserOnMethod", parsers=TestParserB.class) - public String testParserOnMethod(@Content String in) { - return in; - } - - @Consumes("text/b") - public static class TestParserB extends ReaderParser { - @SuppressWarnings("unchecked") - @Override /* Parser */ - protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception { - return (T)("text/b - " + IOUtils.read(session.getReader()).trim()); - } - } - - //==================================================================================================== - // Parser overridden on method. - //==================================================================================================== - @RestMethod(name="PUT", path="/testParserOverriddenOnMethod", parsers={TestParserB.class,TestParserC.class}, parsersInherit=PARSERS) - public String testParserOverriddenOnMethod(@Content String in) { - return in; - } - - @Consumes("text/c") - public static class TestParserC extends ReaderParser { - @SuppressWarnings("unchecked") - @Override /* Parser */ - protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception { - return (T)("text/c - " + IOUtils.read(session.getReader()).trim()); - } - } - - //==================================================================================================== - // Parser with different Accept than Content-Type. - //==================================================================================================== - @RestMethod(name="PUT", path="/testParserWithDifferentMediaTypes", parsers={TestParserD.class}, parsersInherit=PARSERS) - public String testParserWithDifferentMediaTypes(@Content String in) { - return in; - } - - @Consumes({"text/a","text/d"}) - public static class TestParserD extends ReaderParser { - @SuppressWarnings("unchecked") - @Override /* Parser */ - protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception { - return (T)("text/d - " + IOUtils.read(session.getReader()).trim()); - } - } - - //==================================================================================================== - // Check for valid error response. - //==================================================================================================== - @RestMethod(name="PUT", path="/testValidErrorResponse") - public String testValidErrorResponse(@Content String in) { - return in; - } -}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestPath.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestPath.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestPath.java deleted file mode 100755 index a4e1315..0000000 --- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestPath.java +++ /dev/null @@ -1,68 +0,0 @@ -/*************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - ***************************************************************************************************************************/ -package org.apache.juneau.server; - -import org.apache.juneau.server.annotation.*; - -/** - * JUnit automated testcase resource. - * Tests the RestServlet.getPath() method. - */ -@RestResource( - path="/testPath", - children={ - TestPath.TestPath2.class - } -) -public class TestPath extends RestServletDefault { - private static final long serialVersionUID = 1L; - - //==================================================================================================== - // Basic tests - //==================================================================================================== - @RestMethod(name="GET", path="/") - public String doGet() { - return getPath(); - } - - @RestResource( - path="/testPath2", - children={ - TestPath.TestPath3.class - } - ) - public static class TestPath2 extends RestServletDefault { - private static final long serialVersionUID = 1L; - // Basic tests - @RestMethod(name="GET", path="/") - public String doGet() { - return getPath(); - } - } - - @RestResource( - path="/testPath3" - ) - public static class TestPath3a extends RestServletDefault { - private static final long serialVersionUID = 1L; - // Basic tests - @RestMethod(name="GET", path="/") - public String doGet() { - return getPath(); - } - } - - public static class TestPath3 extends TestPath3a { - private static final long serialVersionUID = 1L; - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestPaths.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestPaths.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestPaths.java deleted file mode 100755 index 453f864..0000000 --- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestPaths.java +++ /dev/null @@ -1,72 +0,0 @@ -/*************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - ***************************************************************************************************************************/ -package org.apache.juneau.server; - -import org.apache.juneau.*; -import org.apache.juneau.server.annotation.*; - -/** - * JUnit automated testcase resource. - * Tests the URL-related methods on RestRequest. - */ -@RestResource( - path="/testPaths", - children={ - TestPaths.A.class - } -) -public class TestPaths extends RestServletDefault { - private static final long serialVersionUID = 1L; - - @RestMethod(name="GET", path="/*") - public ObjectMap doGet1(RestRequest req, @PathRemainder String r) { - return getPaths(req).append("pathRemainder2", r).append("method",1); - } - - @RestMethod(name="GET", path="/test2/*") - public ObjectMap doGet2(RestRequest req, @PathRemainder String r) { - return getPaths(req).append("pathRemainder2", r).append("method",2); - } - - @RestResource( - path="/a" - ) - public static class A extends RestServletDefault { - private static final long serialVersionUID = 1L; - @RestMethod(name="GET", path="/*") - public ObjectMap doGet1(RestRequest req, @PathRemainder String r) { - return getPaths(req).append("pathRemainder2", r).append("method",3); - } - @RestMethod(name="GET", path="/test2/*") - public ObjectMap doGet2(RestRequest req, @PathRemainder String r) { - return getPaths(req).append("pathRemainder2", r).append("method",4); - } - } - - private static ObjectMap getPaths(RestRequest req) { - return new ObjectMap() - .append("pathInfo", req.getPathInfo()) - .append("pathInfoUndecoded", req.getPathInfoUndecoded()) - .append("pathInfoParts", req.getPathInfoParts()) - .append("pathRemainder", req.getPathRemainder()) - .append("pathRemainderUndecoded", req.getPathRemainderUndecoded()) - .append("requestURI", req.getRequestURI()) - .append("requestParentURI", req.getRequestParentURI()) - .append("requestURL", req.getRequestURL()) - .append("servletPath", req.getServletPath()) - .append("servletURI", req.getServletURI()) - .append("servletParentURI", req.getServletParentURI()) - .append("relativeServletURI", req.getRelativeServletURI()); - - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestProperties.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestProperties.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestProperties.java deleted file mode 100755 index baccafa..0000000 --- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestProperties.java +++ /dev/null @@ -1,89 +0,0 @@ -/*************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - ***************************************************************************************************************************/ -package org.apache.juneau.server; - -import static java.lang.String.*; - -import org.apache.juneau.*; -import org.apache.juneau.annotation.*; -import org.apache.juneau.serializer.*; -import org.apache.juneau.server.annotation.*; - -/** - * JUnit automated testcase resource. - */ -@RestResource( - path="/testProperties", - properties={ - @Property(name="A1",value="a1"), - @Property(name="A2",value="a2"), - @Property(name="foo",value="bar"), - @Property(name="bar",value="baz"), - @Property(name="R1a",value="$R{requestURI}"), - @Property(name="R1b",value="$R{requestParentURI}"), - @Property(name="R2",value="$R{foo}"), - @Property(name="R3",value="$R{$R{foo}}"), - @Property(name="R4",value="$R{A1}"), - @Property(name="R5",value="$R{A2}"), - @Property(name="R6",value="$R{C}"), - } -) -public class TestProperties extends RestServletDefault { - private static final long serialVersionUID = 1L; - - //==================================================================================================== - // Properties defined on method. - //==================================================================================================== - @RestMethod(name="GET", path="/testPropertiesDefinedOnMethod", - properties={ - @Property(name="B1",value="b1"), - @Property(name="B2",value="b2") - }, - serializers=PropertySerializer1.class - ) - public void testPropertiesDefinedOnMethod(RestResponse res) { - res.setProperty("A2", "c"); - res.setProperty("B2", "c"); - res.setProperty("C", "c"); - res.setOutput(null); - } - - @Produces({"application/json","text/json"}) - public static class PropertySerializer1 extends WriterSerializer { - @Override /* Serializer */ - protected void doSerialize(SerializerSession session, Object output) throws Exception { - ObjectMap p = session.getProperties(); - session.getWriter().write(format("A1=%s,A2=%s,B1=%s,B2=%s,C=%s,R1a=%s,R1b=%s,R2=%s,R3=%s,R4=%s,R5=%s,R6=%s", - p.get("A1"), p.get("A2"), p.get("B1"), p.get("B2"), p.get("C"), - p.get("R1a"), p.get("R1b"), p.get("R2"), p.get("R3"), p.get("R4"), p.get("R5"), p.get("R6"))); - } - } - - //==================================================================================================== - // Make sure attributes/parameters/headers are available through ctx.getProperties(). - //==================================================================================================== - @RestMethod(name="GET", path="/testProperties/{A}", serializers=PropertySerializer2.class) - public void testProperties(RestResponse res) { - res.setOutput(null); - } - - @Produces({"application/json","text/json"}) - public static class PropertySerializer2 extends WriterSerializer { - @Override /* Serializer */ - protected void doSerialize(SerializerSession session, Object output) throws Exception { - ObjectMap p = session.getProperties(); - session.getWriter().write(format("A=%s,P=%s,H=%s", p.get("A"), p.get("P"), p.get("h"))); - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestRestClient2.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestRestClient2.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestRestClient2.java deleted file mode 100755 index e476263..0000000 --- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestRestClient2.java +++ /dev/null @@ -1,35 +0,0 @@ -/*************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - ***************************************************************************************************************************/ -package org.apache.juneau.server; - -import java.io.*; - -import org.apache.juneau.server.annotation.*; - -/** - * JUnit automated testcase resource. - */ -@RestResource( - path="/testRestClient" -) -public class TestRestClient2 extends RestServletDefault { - private static final long serialVersionUID = 1L; - - //==================================================================================================== - // Echo response - //==================================================================================================== - @RestMethod(name="POST", path="/") - public Reader test1(RestRequest req) throws Exception { - return new StringReader(req.getInputAsString()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestSerializers.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestSerializers.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestSerializers.java deleted file mode 100755 index cef0362..0000000 --- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestSerializers.java +++ /dev/null @@ -1,102 +0,0 @@ -/*************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - ***************************************************************************************************************************/ -package org.apache.juneau.server; - -import static org.apache.juneau.server.annotation.Inherit.*; - -import org.apache.juneau.annotation.*; -import org.apache.juneau.serializer.*; -import org.apache.juneau.server.annotation.*; - -/** - * JUnit automated testcase resource. - */ -@RestResource( - path="/testSerializers", - serializers=TestSerializers.TestSerializerA.class -) -public class TestSerializers extends RestServletDefault { - private static final long serialVersionUID = 1L; - - @Produces("text/a") - public static class TestSerializerA extends WriterSerializer { - @Override /* Serializer */ - protected void doSerialize(SerializerSession session, Object o) throws Exception { - session.getWriter().write("text/a - " + o); - } - } - - @Produces("text/b") - public static class TestSerializerB extends WriterSerializer { - @Override /* Serializer */ - protected void doSerialize(SerializerSession session, Object o) throws Exception { - session.getWriter().write("text/b - " + o); - } - } - - //==================================================================================================== - // Serializer defined on class. - //==================================================================================================== - @RestMethod(name="GET", path="/testSerializerOnClass") - public String testSerializerOnClass() { - return "test1"; - } - - //==================================================================================================== - // Serializer defined on method. - //==================================================================================================== - @RestMethod(name="GET", path="/testSerializerOnMethod", serializers=TestSerializerB.class) - public String testSerializerOnMethod() { - return "test2"; - } - - //==================================================================================================== - // Serializer overridden on method. - //==================================================================================================== - @RestMethod(name="GET", path="/testSerializerOverriddenOnMethod", serializers={TestSerializerB.class,TestSerializerC.class}, serializersInherit=SERIALIZERS) - public String testSerializerOverriddenOnMethod() { - return "test3"; - } - - @Produces("text/a") - public static class TestSerializerC extends WriterSerializer { - @Override /* Serializer */ - protected void doSerialize(SerializerSession session, Object o) throws Exception { - session.getWriter().write("text/c - " + o); - } - } - - //==================================================================================================== - // Serializer with different Accept than Content-Type. - //==================================================================================================== - @RestMethod(name="GET", path="/testSerializerWithDifferentMediaTypes", serializers={TestSerializerD.class}, serializersInherit=SERIALIZERS) - public String testSerializerWithDifferentMediaTypes() { - return "test4"; - } - - @Produces(value={"text/a","text/d"},contentType="text/d") - public static class TestSerializerD extends WriterSerializer { - @Override /* Serializer */ - protected void doSerialize(SerializerSession session, Object o) throws Exception { - session.getWriter().write("text/d - " + o); - } - } - - //==================================================================================================== - // Check for valid 406 error response. - //==================================================================================================== - @RestMethod(name="GET", path="/test406") - public String test406() { - return "test406"; - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestStaticFiles.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestStaticFiles.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestStaticFiles.java deleted file mode 100755 index 253e814..0000000 --- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestStaticFiles.java +++ /dev/null @@ -1,35 +0,0 @@ -/*************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - ***************************************************************************************************************************/ -package org.apache.juneau.server; - -import org.apache.juneau.server.annotation.*; - -/** - * JUnit automated testcase resource. - */ -@RestResource( - path="/testStaticFiles", - staticFiles="{xdocs:'xdocs'}" -) -public class TestStaticFiles extends RestServlet { - private static final long serialVersionUID = 1L; - - //==================================================================================================== - // Tests the @RestResource(staticFiles) annotation. - //==================================================================================================== - @RestMethod(name="GET", path="/*") - public String testXdocs() { - return null; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestTransforms.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestTransforms.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestTransforms.java deleted file mode 100755 index 5918f06..0000000 --- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestTransforms.java +++ /dev/null @@ -1,114 +0,0 @@ -/*************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - ***************************************************************************************************************************/ -package org.apache.juneau.server; - - -import org.apache.juneau.parser.*; -import org.apache.juneau.serializer.*; -import org.apache.juneau.server.annotation.*; -import org.apache.juneau.transform.*; - -/** - * JUnit automated testcase resource. - */ -@RestResource( - path="/testTransforms", - transforms={TestTransforms.SwapA2.class} -) -public class TestTransforms extends TestTransformsParent { - private static final long serialVersionUID = 1L; - - //==================================================================================================== - // Test class transform overrides parent class transform - // Should return "A2-1". - //==================================================================================================== - @RestMethod(name="GET", path="/testClassTransformOverridesParentClassTransform") - public A testClassTransformOverridesParentClassTransform() { - return new A(); - } - @RestMethod(name="PUT", path="/testClassTransformOverridesParentClassTransform") - public A test1b(@Content A a) { - return a; - } - @RestMethod(name="PUT", path="/testClassTransformOverridesParentClassTransform/{a}") - public A test1c(@Attr A a) { - return a; - } - - //==================================================================================================== - // Test method transform overrides class transform - // Should return "A3-1". - //==================================================================================================== - @RestMethod(name="GET", path="/testMethodTransformOverridesClassTransform", transforms={SwapA3.class}) - public A test2a() { - return new A(); - } - @RestMethod(name="PUT", path="/testMethodTransformOverridesClassTransform", transforms={SwapA3.class}) - public A test2b(@Content A a) { - return a; - } - @RestMethod(name="PUT", path="/testMethodTransformOverridesClassTransform/{a}", transforms={SwapA3.class}) - public A test2c(@Attr A a) { - return a; - } - - - public static class A { - public int f1; - } - - public static class SwapA1 extends PojoSwap<A,String> { - @Override /* PojoSwap */ - public String swap(A a) throws SerializeException { - return "A1-" + a.f1; - } - @Override /* PojoSwap */ - public A unswap(String in) throws ParseException { - if (! in.startsWith("A1")) - throw new RuntimeException("Invalid input for SwapA1!"); - A a = new A(); - a.f1 = Integer.parseInt(in.substring(3)); - return a; - } - } - - public static class SwapA2 extends PojoSwap<A,String> { - @Override /* PojoSwap */ - public String swap(A a) throws SerializeException { - return "A2-" + a.f1; - } - @Override /* PojoSwap */ - public A unswap(String in) throws ParseException { - if (! in.startsWith("A2")) - throw new RuntimeException("Invalid input for SwapA2!"); - A a = new A(); - a.f1 = Integer.parseInt(in.substring(3)); - return a; - } - } - - public static class SwapA3 extends PojoSwap<A,String> { - @Override /* PojoSwap */ - public String swap(A a) throws SerializeException { - return "A3-" + a.f1; - } - @Override /* PojoSwap */ - public A unswap(String in) throws ParseException { - if (! in.startsWith("A3")) - throw new RuntimeException("Invalid input for SwapA3!"); - A a = new A(); - a.f1 = Integer.parseInt(in.substring(3)); - return a; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestTransformsParent.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestTransformsParent.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestTransformsParent.java deleted file mode 100755 index 4e8ddb8..0000000 --- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestTransformsParent.java +++ /dev/null @@ -1,25 +0,0 @@ -/*************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - ***************************************************************************************************************************/ -package org.apache.juneau.server; - -import org.apache.juneau.server.annotation.*; - -/** - * JUnit automated testcase resource. - */ -@RestResource( - transforms={TestTransforms.SwapA1.class} -) -public class TestTransformsParent extends RestServletDefault { - private static final long serialVersionUID = 1L; -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestUris.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestUris.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestUris.java deleted file mode 100755 index b2db727..0000000 --- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestUris.java +++ /dev/null @@ -1,120 +0,0 @@ -/*************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - ***************************************************************************************************************************/ -package org.apache.juneau.server; - -import org.apache.juneau.*; -import org.apache.juneau.server.annotation.*; - -@RestResource( - path="/testuris", - children={ - TestUris.Child.class - } -) -public class TestUris extends RestServletDefault { - private static final long serialVersionUID = 1L; - - @RestMethod(name="GET", path="/*") - public ObjectMap test1(RestRequest req) throws Exception { - return getPathInfoObject(req).append("testMethod", "root.test1"); - } - - @RestMethod(name="GET", path="/test2/*") - public ObjectMap test2(RestRequest req) throws Exception { - return getPathInfoObject(req).append("testMethod", "root.test2"); - } - - @RestMethod(name="GET", path="/test3%2Ftest3/*") - public ObjectMap test3(RestRequest req) throws Exception { - return getPathInfoObject(req).append("testMethod", "root.test3"); - } - - @RestMethod(name="GET", path="/test4/test4/*") - public ObjectMap test4(RestRequest req) throws Exception { - return getPathInfoObject(req).append("testMethod", "root.test4"); - } - - @RestResource( - path="/child", - children={ - GrandChild.class - } - ) - public static class Child extends RestServletDefault { - private static final long serialVersionUID = 1L; - - @RestMethod(name="GET", path="/*") - public ObjectMap test1(RestRequest req) throws Exception { - return getPathInfoObject(req).append("testMethod", "child.test1"); - } - - @RestMethod(name="GET", path="/test2/*") - public ObjectMap test2(RestRequest req) throws Exception { - return getPathInfoObject(req).append("testMethod", "child.test2"); - } - - @RestMethod(name="GET", path="/test3%2Ftest3/*") - public ObjectMap test3(RestRequest req) throws Exception { - return getPathInfoObject(req).append("testMethod", "child.test3"); - } - - @RestMethod(name="GET", path="/test4/test4/*") - public ObjectMap test4(RestRequest req) throws Exception { - return getPathInfoObject(req).append("testMethod", "child.test4"); - } - } - - @RestResource( - path="/grandchild" - ) - public static class GrandChild extends RestServletDefault { - private static final long serialVersionUID = 1L; - - @RestMethod(name="GET", path="/*") - public ObjectMap test1(RestRequest req) throws Exception { - return getPathInfoObject(req).append("testMethod", "grandchild.test1"); - } - - @RestMethod(name="GET", path="/test2/*") - public ObjectMap test2(RestRequest req) throws Exception { - return getPathInfoObject(req).append("testMethod", "grandchild.test2"); - } - - @RestMethod(name="GET", path="/test3%2Ftest3/*") - public ObjectMap test3(RestRequest req) throws Exception { - return getPathInfoObject(req).append("testMethod", "grandchild.test3"); - } - - @RestMethod(name="GET", path="/test4/test4/*") - public ObjectMap test4(RestRequest req) throws Exception { - return getPathInfoObject(req).append("testMethod", "grandchild.test4"); - } - } - - static ObjectMap getPathInfoObject(RestRequest req) throws Exception { - ObjectMap m = new ObjectMap(); - m.put("contextPath", req.getContextPath()); - m.put("pathInfo", req.getPathInfo()); - m.put("pathRemainder", req.getPathRemainder()); - m.put("pathTranslated", req.getPathTranslated()); - m.put("requestParentURI", req.getRequestParentURI()); - m.put("requestURI", req.getRequestURI()); - m.put("requestURL", req.getRequestURL()); - m.put("servletPath", req.getServletPath()); - m.put("servletURI", req.getServletURI()); - m.put("testURL1", req.getURL("testURL")); - m.put("testURL2", req.getURL("/testURL")); - m.put("testURL3", req.getURL("http://testURL")); - return m; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TestUrlContent.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TestUrlContent.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TestUrlContent.java deleted file mode 100755 index ad0c64d..0000000 --- a/juneau-server-test/src/main/java/org/apache/juneau/server/TestUrlContent.java +++ /dev/null @@ -1,58 +0,0 @@ -/*************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - ***************************************************************************************************************************/ -package org.apache.juneau.server; - -import org.apache.juneau.json.*; -import org.apache.juneau.plaintext.*; -import org.apache.juneau.server.annotation.*; - -/** - * JUnit automated testcase resource. - */ -@RestResource( - path="/testUrlContent", - serializers={PlainTextSerializer.class}, - parsers={JsonParser.class} -) -public class TestUrlContent extends RestServlet { - private static final long serialVersionUID = 1L; - - @RestMethod(name="GET", path="/testString") - public String testString(@Content String content) { - return String.format("class=%s, value=%s", content.getClass().getName(), content.toString()); - } - - @RestMethod(name="GET", path="/testEnum") - public String testEnum(@Content TestEnum content) { - return String.format("class=%s, value=%s", content.getClass().getName(), content.toString()); - } - - public static enum TestEnum { - X1 - } - - @RestMethod(name="GET", path="/testBean") - public String testBean(@Content TestBean content) throws Exception { - return String.format("class=%s, value=%s", content.getClass().getName(), JsonSerializer.DEFAULT_LAX.serialize(content)); - } - - public static class TestBean { - public int f1; - public String f2; - } - - @RestMethod(name="GET", path="/testInt") - public String testString(@Content Integer content) { - return String.format("class=%s, value=%s", content.getClass().getName(), content.toString()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TransformsParentResource.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TransformsParentResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TransformsParentResource.java new file mode 100755 index 0000000..f7db4d3 --- /dev/null +++ b/juneau-server-test/src/main/java/org/apache/juneau/server/TransformsParentResource.java @@ -0,0 +1,25 @@ +/*************************************************************************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + ***************************************************************************************************************************/ +package org.apache.juneau.server; + +import org.apache.juneau.server.annotation.*; + +/** + * JUnit automated testcase resource. + */ +@RestResource( + transforms={TransformsResource.SwapA1.class} +) +public class TransformsParentResource extends RestServletDefault { + private static final long serialVersionUID = 1L; +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/TransformsResource.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/TransformsResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/TransformsResource.java new file mode 100755 index 0000000..4301411 --- /dev/null +++ b/juneau-server-test/src/main/java/org/apache/juneau/server/TransformsResource.java @@ -0,0 +1,114 @@ +/*************************************************************************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + ***************************************************************************************************************************/ +package org.apache.juneau.server; + + +import org.apache.juneau.parser.*; +import org.apache.juneau.serializer.*; +import org.apache.juneau.server.annotation.*; +import org.apache.juneau.transform.*; + +/** + * JUnit automated testcase resource. + */ +@RestResource( + path="/testTransforms", + transforms={TransformsResource.SwapA2.class} +) +public class TransformsResource extends TransformsParentResource { + private static final long serialVersionUID = 1L; + + //==================================================================================================== + // Test class transform overrides parent class transform + // Should return "A2-1". + //==================================================================================================== + @RestMethod(name="GET", path="/testClassTransformOverridesParentClassTransform") + public A testClassTransformOverridesParentClassTransform() { + return new A(); + } + @RestMethod(name="PUT", path="/testClassTransformOverridesParentClassTransform") + public A test1b(@Content A a) { + return a; + } + @RestMethod(name="PUT", path="/testClassTransformOverridesParentClassTransform/{a}") + public A test1c(@Attr A a) { + return a; + } + + //==================================================================================================== + // Test method transform overrides class transform + // Should return "A3-1". + //==================================================================================================== + @RestMethod(name="GET", path="/testMethodTransformOverridesClassTransform", transforms={SwapA3.class}) + public A test2a() { + return new A(); + } + @RestMethod(name="PUT", path="/testMethodTransformOverridesClassTransform", transforms={SwapA3.class}) + public A test2b(@Content A a) { + return a; + } + @RestMethod(name="PUT", path="/testMethodTransformOverridesClassTransform/{a}", transforms={SwapA3.class}) + public A test2c(@Attr A a) { + return a; + } + + + public static class A { + public int f1; + } + + public static class SwapA1 extends PojoSwap<A,String> { + @Override /* PojoSwap */ + public String swap(A a) throws SerializeException { + return "A1-" + a.f1; + } + @Override /* PojoSwap */ + public A unswap(String in) throws ParseException { + if (! in.startsWith("A1")) + throw new RuntimeException("Invalid input for SwapA1!"); + A a = new A(); + a.f1 = Integer.parseInt(in.substring(3)); + return a; + } + } + + public static class SwapA2 extends PojoSwap<A,String> { + @Override /* PojoSwap */ + public String swap(A a) throws SerializeException { + return "A2-" + a.f1; + } + @Override /* PojoSwap */ + public A unswap(String in) throws ParseException { + if (! in.startsWith("A2")) + throw new RuntimeException("Invalid input for SwapA2!"); + A a = new A(); + a.f1 = Integer.parseInt(in.substring(3)); + return a; + } + } + + public static class SwapA3 extends PojoSwap<A,String> { + @Override /* PojoSwap */ + public String swap(A a) throws SerializeException { + return "A3-" + a.f1; + } + @Override /* PojoSwap */ + public A unswap(String in) throws ParseException { + if (! in.startsWith("A3")) + throw new RuntimeException("Invalid input for SwapA3!"); + A a = new A(); + a.f1 = Integer.parseInt(in.substring(3)); + return a; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/UrisResource.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/UrisResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/UrisResource.java new file mode 100755 index 0000000..46c0445 --- /dev/null +++ b/juneau-server-test/src/main/java/org/apache/juneau/server/UrisResource.java @@ -0,0 +1,120 @@ +/*************************************************************************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + ***************************************************************************************************************************/ +package org.apache.juneau.server; + +import org.apache.juneau.*; +import org.apache.juneau.server.annotation.*; + +@RestResource( + path="/testuris", + children={ + UrisResource.Child.class + } +) +public class UrisResource extends RestServletDefault { + private static final long serialVersionUID = 1L; + + @RestMethod(name="GET", path="/*") + public ObjectMap test1(RestRequest req) throws Exception { + return getPathInfoObject(req).append("testMethod", "root.test1"); + } + + @RestMethod(name="GET", path="/test2/*") + public ObjectMap test2(RestRequest req) throws Exception { + return getPathInfoObject(req).append("testMethod", "root.test2"); + } + + @RestMethod(name="GET", path="/test3%2Ftest3/*") + public ObjectMap test3(RestRequest req) throws Exception { + return getPathInfoObject(req).append("testMethod", "root.test3"); + } + + @RestMethod(name="GET", path="/test4/test4/*") + public ObjectMap test4(RestRequest req) throws Exception { + return getPathInfoObject(req).append("testMethod", "root.test4"); + } + + @RestResource( + path="/child", + children={ + GrandChild.class + } + ) + public static class Child extends RestServletDefault { + private static final long serialVersionUID = 1L; + + @RestMethod(name="GET", path="/*") + public ObjectMap test1(RestRequest req) throws Exception { + return getPathInfoObject(req).append("testMethod", "child.test1"); + } + + @RestMethod(name="GET", path="/test2/*") + public ObjectMap test2(RestRequest req) throws Exception { + return getPathInfoObject(req).append("testMethod", "child.test2"); + } + + @RestMethod(name="GET", path="/test3%2Ftest3/*") + public ObjectMap test3(RestRequest req) throws Exception { + return getPathInfoObject(req).append("testMethod", "child.test3"); + } + + @RestMethod(name="GET", path="/test4/test4/*") + public ObjectMap test4(RestRequest req) throws Exception { + return getPathInfoObject(req).append("testMethod", "child.test4"); + } + } + + @RestResource( + path="/grandchild" + ) + public static class GrandChild extends RestServletDefault { + private static final long serialVersionUID = 1L; + + @RestMethod(name="GET", path="/*") + public ObjectMap test1(RestRequest req) throws Exception { + return getPathInfoObject(req).append("testMethod", "grandchild.test1"); + } + + @RestMethod(name="GET", path="/test2/*") + public ObjectMap test2(RestRequest req) throws Exception { + return getPathInfoObject(req).append("testMethod", "grandchild.test2"); + } + + @RestMethod(name="GET", path="/test3%2Ftest3/*") + public ObjectMap test3(RestRequest req) throws Exception { + return getPathInfoObject(req).append("testMethod", "grandchild.test3"); + } + + @RestMethod(name="GET", path="/test4/test4/*") + public ObjectMap test4(RestRequest req) throws Exception { + return getPathInfoObject(req).append("testMethod", "grandchild.test4"); + } + } + + static ObjectMap getPathInfoObject(RestRequest req) throws Exception { + ObjectMap m = new ObjectMap(); + m.put("contextPath", req.getContextPath()); + m.put("pathInfo", req.getPathInfo()); + m.put("pathRemainder", req.getPathRemainder()); + m.put("pathTranslated", req.getPathTranslated()); + m.put("requestParentURI", req.getRequestParentURI()); + m.put("requestURI", req.getRequestURI()); + m.put("requestURL", req.getRequestURL()); + m.put("servletPath", req.getServletPath()); + m.put("servletURI", req.getServletURI()); + m.put("testURL1", req.getURL("testURL")); + m.put("testURL2", req.getURL("/testURL")); + m.put("testURL3", req.getURL("http://testURL")); + return m; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/java/org/apache/juneau/server/UrlContentResource.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/main/java/org/apache/juneau/server/UrlContentResource.java b/juneau-server-test/src/main/java/org/apache/juneau/server/UrlContentResource.java new file mode 100755 index 0000000..a1b4726 --- /dev/null +++ b/juneau-server-test/src/main/java/org/apache/juneau/server/UrlContentResource.java @@ -0,0 +1,58 @@ +/*************************************************************************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + ***************************************************************************************************************************/ +package org.apache.juneau.server; + +import org.apache.juneau.json.*; +import org.apache.juneau.plaintext.*; +import org.apache.juneau.server.annotation.*; + +/** + * JUnit automated testcase resource. + */ +@RestResource( + path="/testUrlContent", + serializers={PlainTextSerializer.class}, + parsers={JsonParser.class} +) +public class UrlContentResource extends RestServlet { + private static final long serialVersionUID = 1L; + + @RestMethod(name="GET", path="/testString") + public String testString(@Content String content) { + return String.format("class=%s, value=%s", content.getClass().getName(), content.toString()); + } + + @RestMethod(name="GET", path="/testEnum") + public String testEnum(@Content TestEnum content) { + return String.format("class=%s, value=%s", content.getClass().getName(), content.toString()); + } + + public static enum TestEnum { + X1 + } + + @RestMethod(name="GET", path="/testBean") + public String testBean(@Content TestBean content) throws Exception { + return String.format("class=%s, value=%s", content.getClass().getName(), JsonSerializer.DEFAULT_LAX.serialize(content)); + } + + public static class TestBean { + public int f1; + public String f2; + } + + @RestMethod(name="GET", path="/testInt") + public String testString(@Content Integer content) { + return String.format("class=%s, value=%s", content.getClass().getName(), content.toString()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/resources/org/apache/juneau/server/Messages2Resource.properties ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/main/resources/org/apache/juneau/server/Messages2Resource.properties b/juneau-server-test/src/main/resources/org/apache/juneau/server/Messages2Resource.properties new file mode 100755 index 0000000..9a5fe73 --- /dev/null +++ b/juneau-server-test/src/main/resources/org/apache/juneau/server/Messages2Resource.properties @@ -0,0 +1,16 @@ +# *************************************************************************************************************************** +# * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * +# * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * +# * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * +# * with the License. You may obtain a copy of the License at * +# * * +# * http://www.apache.org/licenses/LICENSE-2.0 * +# * * +# * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * +# * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * +# * specific language governing permissions and limitations under the License. * +# * * +# *************************************************************************************************************************** + +key2 = value2b +key3 = value3b \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/resources/org/apache/juneau/server/MessagesResource.properties ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/main/resources/org/apache/juneau/server/MessagesResource.properties b/juneau-server-test/src/main/resources/org/apache/juneau/server/MessagesResource.properties new file mode 100755 index 0000000..d107ee8 --- /dev/null +++ b/juneau-server-test/src/main/resources/org/apache/juneau/server/MessagesResource.properties @@ -0,0 +1,16 @@ +# *************************************************************************************************************************** +# * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * +# * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * +# * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * +# * with the License. You may obtain a copy of the License at * +# * * +# * http://www.apache.org/licenses/LICENSE-2.0 * +# * * +# * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * +# * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * +# * specific language governing permissions and limitations under the License. * +# * * +# *************************************************************************************************************************** + +key1 = value1a +key2 = value2a \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/resources/org/apache/juneau/server/NlsPropertyResource.properties ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/main/resources/org/apache/juneau/server/NlsPropertyResource.properties b/juneau-server-test/src/main/resources/org/apache/juneau/server/NlsPropertyResource.properties new file mode 100755 index 0000000..a833256 --- /dev/null +++ b/juneau-server-test/src/main/resources/org/apache/juneau/server/NlsPropertyResource.properties @@ -0,0 +1,16 @@ +# *************************************************************************************************************************** +# * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * +# * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * +# * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * +# * with the License. You may obtain a copy of the License at * +# * * +# * http://www.apache.org/licenses/LICENSE-2.0 * +# * * +# * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * +# * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * +# * specific language governing permissions and limitations under the License. * +# * * +# *************************************************************************************************************************** + +key1 = value1 +key2 = value2 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/resources/org/apache/juneau/server/NlsResource.properties ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/main/resources/org/apache/juneau/server/NlsResource.properties b/juneau-server-test/src/main/resources/org/apache/juneau/server/NlsResource.properties new file mode 100755 index 0000000..9833d00 --- /dev/null +++ b/juneau-server-test/src/main/resources/org/apache/juneau/server/NlsResource.properties @@ -0,0 +1,79 @@ +# *************************************************************************************************************************** +# * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * +# * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * +# * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * +# * with the License. You may obtain a copy of the License at * +# * * +# * http://www.apache.org/licenses/LICENSE-2.0 * +# * * +# * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * +# * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * +# * specific language governing permissions and limitations under the License. * +# * * +# *************************************************************************************************************************** + +label = Test2.a +description = Test2.b +test2 = Test2.c +test2.req.attr.a = Test2.d +test2.req.param.b = Test2.e +test2.req.content = Test2.f +test2.req.header.D = Test2.g +test2.req.attr.a2 = Test2.h +test2.req.param.b2 = Test2.i +test2.req.header.D2 = Test2.j +test2.req.foo.bar = Test2.k +test2.res.200 = OK2 +test2.res.201 = Test2.l +test2.res.201.foo.bar = Test2.m + +Test3.label = Test3.a +Test3.description = Test3.b +Test3.test3 = Test3.c +Test3.test3.req.attr.a = Test3.d +Test3.test3.req.param.b = Test3.e +Test3.test3.req.content = Test3.f +Test3.test3.req.header.D = Test3.g +Test3.test3.req.attr.a2 = Test3.h +Test3.test3.req.param.b2 = Test3.i +Test3.test3.req.header.D2 = Test3.j +Test3.test3.req.foo.bar = Test3.k +Test3.test3.res.200 = OK3 +Test3.test3.res.201 = Test3.l +Test3.test3.res.201.foo.bar = Test3.m + +Test4.label = $L{foo} +Test4.description = $L{foo} +Test4.test4 = $L{foo} +Test4.test4.req.attr.a = $L{foo} +Test4.test4.req.param.b = $L{foo} +Test4.test4.req.content = $L{foo} +Test4.test4.req.header.D = $L{foo} +Test4.test4.req.attr.a2 = $L{foo} +Test4.test4.req.param.b2 = $L{foo} +Test4.test4.req.header.D2 = $L{foo} +Test4.test4.req.foo.bar = $L{foo} +Test4.test4.res.200 = foo$L{foo}foo$L{foo}foo +Test4.test4.res.201 = $L{foo} +Test4.test4.res.201.foo.bar = $L{foo} + +foo = $L{bar} +bar = baz + +Test5.label = $L{foo2} +Test5.description = $R{servletLabel} +Test5.test5 = $R{servletLabel} +Test5.test5.req.attr.a = $R{servletLabel} +Test5.test5.req.param.b = $R{servletLabel} +Test5.test5.req.content = $R{servletLabel} +Test5.test5.req.header.D = $R{servletLabel} +Test5.test5.req.attr.a2 = $R{servletLabel} +Test5.test5.req.param.b2 = $R{servletLabel} +Test5.test5.req.header.D2 = $R{servletLabel} +Test5.test5.req.foo.bar = $R{servletLabel} +Test5.test5.res.200 = foo$R{servletLabel}foo$R{servletLabel}foo +Test5.test5.res.201 = $R{servletLabel} +Test5.test5.res.201.foo.bar = $R{servletLabel} +Test5.foo2 = $L{bar2} +Test5.bar2 = baz2 + http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/resources/org/apache/juneau/server/TestMessages.properties ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/main/resources/org/apache/juneau/server/TestMessages.properties b/juneau-server-test/src/main/resources/org/apache/juneau/server/TestMessages.properties deleted file mode 100755 index d107ee8..0000000 --- a/juneau-server-test/src/main/resources/org/apache/juneau/server/TestMessages.properties +++ /dev/null @@ -1,16 +0,0 @@ -# *************************************************************************************************************************** -# * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -# * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -# * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -# * with the License. You may obtain a copy of the License at * -# * * -# * http://www.apache.org/licenses/LICENSE-2.0 * -# * * -# * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -# * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -# * specific language governing permissions and limitations under the License. * -# * * -# *************************************************************************************************************************** - -key1 = value1a -key2 = value2a \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/resources/org/apache/juneau/server/TestMessages2.properties ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/main/resources/org/apache/juneau/server/TestMessages2.properties b/juneau-server-test/src/main/resources/org/apache/juneau/server/TestMessages2.properties deleted file mode 100755 index 9a5fe73..0000000 --- a/juneau-server-test/src/main/resources/org/apache/juneau/server/TestMessages2.properties +++ /dev/null @@ -1,16 +0,0 @@ -# *************************************************************************************************************************** -# * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -# * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -# * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -# * with the License. You may obtain a copy of the License at * -# * * -# * http://www.apache.org/licenses/LICENSE-2.0 * -# * * -# * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -# * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -# * specific language governing permissions and limitations under the License. * -# * * -# *************************************************************************************************************************** - -key2 = value2b -key3 = value3b \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/resources/org/apache/juneau/server/TestNls.properties ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/main/resources/org/apache/juneau/server/TestNls.properties b/juneau-server-test/src/main/resources/org/apache/juneau/server/TestNls.properties deleted file mode 100755 index 9833d00..0000000 --- a/juneau-server-test/src/main/resources/org/apache/juneau/server/TestNls.properties +++ /dev/null @@ -1,79 +0,0 @@ -# *************************************************************************************************************************** -# * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -# * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -# * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -# * with the License. You may obtain a copy of the License at * -# * * -# * http://www.apache.org/licenses/LICENSE-2.0 * -# * * -# * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -# * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -# * specific language governing permissions and limitations under the License. * -# * * -# *************************************************************************************************************************** - -label = Test2.a -description = Test2.b -test2 = Test2.c -test2.req.attr.a = Test2.d -test2.req.param.b = Test2.e -test2.req.content = Test2.f -test2.req.header.D = Test2.g -test2.req.attr.a2 = Test2.h -test2.req.param.b2 = Test2.i -test2.req.header.D2 = Test2.j -test2.req.foo.bar = Test2.k -test2.res.200 = OK2 -test2.res.201 = Test2.l -test2.res.201.foo.bar = Test2.m - -Test3.label = Test3.a -Test3.description = Test3.b -Test3.test3 = Test3.c -Test3.test3.req.attr.a = Test3.d -Test3.test3.req.param.b = Test3.e -Test3.test3.req.content = Test3.f -Test3.test3.req.header.D = Test3.g -Test3.test3.req.attr.a2 = Test3.h -Test3.test3.req.param.b2 = Test3.i -Test3.test3.req.header.D2 = Test3.j -Test3.test3.req.foo.bar = Test3.k -Test3.test3.res.200 = OK3 -Test3.test3.res.201 = Test3.l -Test3.test3.res.201.foo.bar = Test3.m - -Test4.label = $L{foo} -Test4.description = $L{foo} -Test4.test4 = $L{foo} -Test4.test4.req.attr.a = $L{foo} -Test4.test4.req.param.b = $L{foo} -Test4.test4.req.content = $L{foo} -Test4.test4.req.header.D = $L{foo} -Test4.test4.req.attr.a2 = $L{foo} -Test4.test4.req.param.b2 = $L{foo} -Test4.test4.req.header.D2 = $L{foo} -Test4.test4.req.foo.bar = $L{foo} -Test4.test4.res.200 = foo$L{foo}foo$L{foo}foo -Test4.test4.res.201 = $L{foo} -Test4.test4.res.201.foo.bar = $L{foo} - -foo = $L{bar} -bar = baz - -Test5.label = $L{foo2} -Test5.description = $R{servletLabel} -Test5.test5 = $R{servletLabel} -Test5.test5.req.attr.a = $R{servletLabel} -Test5.test5.req.param.b = $R{servletLabel} -Test5.test5.req.content = $R{servletLabel} -Test5.test5.req.header.D = $R{servletLabel} -Test5.test5.req.attr.a2 = $R{servletLabel} -Test5.test5.req.param.b2 = $R{servletLabel} -Test5.test5.req.header.D2 = $R{servletLabel} -Test5.test5.req.foo.bar = $R{servletLabel} -Test5.test5.res.200 = foo$R{servletLabel}foo$R{servletLabel}foo -Test5.test5.res.201 = $R{servletLabel} -Test5.test5.res.201.foo.bar = $R{servletLabel} -Test5.foo2 = $L{bar2} -Test5.bar2 = baz2 - http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/main/resources/org/apache/juneau/server/TestNlsProperty.properties ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/main/resources/org/apache/juneau/server/TestNlsProperty.properties b/juneau-server-test/src/main/resources/org/apache/juneau/server/TestNlsProperty.properties deleted file mode 100755 index a833256..0000000 --- a/juneau-server-test/src/main/resources/org/apache/juneau/server/TestNlsProperty.properties +++ /dev/null @@ -1,16 +0,0 @@ -# *************************************************************************************************************************** -# * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -# * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -# * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -# * with the License. You may obtain a copy of the License at * -# * * -# * http://www.apache.org/licenses/LICENSE-2.0 * -# * * -# * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -# * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -# * specific language governing permissions and limitations under the License. * -# * * -# *************************************************************************************************************************** - -key1 = value1 -key2 = value2 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/AcceptCharsetTest.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/AcceptCharsetTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/AcceptCharsetTest.java new file mode 100755 index 0000000..6a6e9b6 --- /dev/null +++ b/juneau-server-test/src/test/java/org/apache/juneau/server/AcceptCharsetTest.java @@ -0,0 +1,123 @@ +/*************************************************************************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + ***************************************************************************************************************************/ +package org.apache.juneau.server; + +import static javax.servlet.http.HttpServletResponse.*; +import static org.apache.juneau.server.TestUtils.*; +import static org.junit.Assert.*; + +import java.io.*; + +import org.apache.juneau.client.*; +import org.apache.juneau.internal.*; +import org.junit.*; + +public class AcceptCharsetTest { + + boolean debug = false; + + //==================================================================================================== + // Test that Q-values are being resolved correctly. + //==================================================================================================== + @Test + public void testQValues() throws Exception { + RestClient client = new TestRestClient().setHeader("Accept", "text/plain"); + + check1(client, "utf-8", "utf-8"); + check1(client, "iso-8859-1", "iso-8859-1"); + check1(client, "bad,utf-8", "utf-8"); + check1(client, "utf-8,bad", "utf-8"); + check1(client, "bad;q=0.9,utf-8;q=0.1", "utf-8"); + check1(client, "bad;q=0.1,utf-8;q=0.9", "utf-8"); + check1(client, "utf-8,iso-8859-1", "utf-8"); + check1(client, "iso-8859-1,utf-8", "utf-8"); + check1(client, "utf-8;q=0.9,iso-8859-1;q=0.1", "utf-8"); + check1(client, "utf-8;q=0.1,iso-8859-1;q=0.9", "iso-8859-1"); + check1(client, "*", "utf-8"); + check1(client, "bad,iso-8859-1;q=0.5,*;q=0.1", "iso-8859-1"); + check1(client, "bad,iso-8859-1;q=0.1,*;q=0.5", "utf-8"); + + client.closeQuietly(); + } + + private void check1(RestClient client, String requestCharset, String responseCharset) throws Exception { + RestCall r; + InputStream is; + String url = "/testAcceptCharset/testQValues"; + r = client.doGet(url).setHeader("Accept-Charset", requestCharset).connect(); + assertTrue(r.getResponse().getFirstHeader("Content-Type").getValue().toLowerCase().contains(responseCharset)); + is = r.getInputStream(); + assertEquals("foo", IOUtils.read(new InputStreamReader(is, responseCharset))); + } + + //==================================================================================================== + // Validate various Accept-Charset variations. + //==================================================================================================== + @Test + public void testCharsetOnResponse() throws Exception { + RestClient client = new TestRestClient().setAccept("text/plain").setContentType("text/plain"); + String url = "/testAcceptCharset/testCharsetOnResponse"; + String r; + + r = client.doPut(url, new StringReader("")).getResponseAsString(); + assertEquals("utf-8/utf-8", r.toLowerCase()); + + r = client.doPut(url, new StringReader("")).setHeader("Accept-Charset", "Shift_JIS").getResponseAsString(); + assertEquals("utf-8/shift_jis", r.toLowerCase()); + + try { + r = client.doPut(url+"?noTrace=true", new StringReader("")).setHeader("Accept-Charset", "BAD").getResponseAsString(); + fail("Exception expected"); + } catch (RestCallException e) { + checkErrorResponse(debug, e, SC_NOT_ACCEPTABLE, "No supported charsets in header 'Accept-Charset': 'BAD'"); + } + + r = client.doPut(url, new StringReader("")).setHeader("Accept-Charset", "UTF-8").getResponseAsString(); + assertEquals("utf-8/utf-8", r.toLowerCase()); + + r = client.doPut(url, new StringReader("")).setHeader("Accept-Charset", "bad,iso-8859-1").getResponseAsString(); + assertEquals("utf-8/iso-8859-1", r.toLowerCase()); + + r = client.doPut(url, new StringReader("")).setHeader("Accept-Charset", "bad;q=0.9,iso-8859-1;q=0.1").getResponseAsString(); + assertEquals("utf-8/iso-8859-1", r.toLowerCase()); + + r = client.doPut(url, new StringReader("")).setHeader("Accept-Charset", "bad;q=0.1,iso-8859-1;q=0.9").getResponseAsString(); + assertEquals("utf-8/iso-8859-1", r.toLowerCase()); + + client.setHeader("Accept-Charset", "utf-8"); + + r = client.doPut(url, new StringReader("")).setHeader("Content-Type", "text/plain").getResponseAsString(); + assertEquals("utf-8/utf-8", r.toLowerCase()); + + r = client.doPut(url, new StringReader("")).setHeader("Content-Type", "text/plain;charset=utf-8").getResponseAsString(); + assertEquals("utf-8/utf-8", r.toLowerCase()); + + r = client.doPut(url, new StringReader("")).setHeader("Content-Type", "text/plain;charset=UTF-8").getResponseAsString(); + assertEquals("utf-8/utf-8", r.toLowerCase()); + + r = client.doPut(url, new StringReader("")).setHeader("Content-Type", "text/plain;charset=iso-8859-1").getResponseAsString(); + assertEquals("iso-8859-1/utf-8", r.toLowerCase()); + + r = client.doPut(url, new StringReader("")).setHeader("Content-Type", "text/plain;charset=Shift_JIS").getResponseAsString(); + assertEquals("shift_jis/utf-8", r.toLowerCase()); + + try { + r = client.doPut(url + "?noTrace=true&Content-Type=text/plain;charset=BAD", new StringReader("")).getResponseAsString(); + fail("Exception expected"); + } catch (RestCallException e) { + checkErrorResponse(debug, e, SC_UNSUPPORTED_MEDIA_TYPE, "Unsupported charset in header 'Content-Type': 'text/plain;charset=BAD'"); + } + + client.closeQuietly(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/bea31abd/juneau-server-test/src/test/java/org/apache/juneau/server/BeanContextPropertiesTest.java ---------------------------------------------------------------------- diff --git a/juneau-server-test/src/test/java/org/apache/juneau/server/BeanContextPropertiesTest.java b/juneau-server-test/src/test/java/org/apache/juneau/server/BeanContextPropertiesTest.java new file mode 100755 index 0000000..a5ffd65 --- /dev/null +++ b/juneau-server-test/src/test/java/org/apache/juneau/server/BeanContextPropertiesTest.java @@ -0,0 +1,37 @@ +/*************************************************************************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + ***************************************************************************************************************************/ +package org.apache.juneau.server; + +import static org.junit.Assert.*; + +import org.apache.juneau.client.*; +import org.apache.juneau.json.*; +import org.junit.*; + +public class BeanContextPropertiesTest { + + boolean debug = false; + + //==================================================================================================== + // Validate that filters defined on class filter to underlying bean context. + //==================================================================================================== + @Test + public void testClassTransforms() throws Exception { + RestClient client = new TestRestClient(JsonSerializer.class, JsonParser.class); + String r; + r = client.doGet("/testBeanContext/testClassTransforms/2001-07-04T15:30:45Z?d2=2001-07-05T15:30:45Z").setHeader("X-D3", "2001-07-06T15:30:45Z").getResponseAsString(); + assertEquals("d1=2001-07-04T15:30:45Z,d2=2001-07-05T15:30:45Z,d3=2001-07-06T15:30:45Z", r); + + client.closeQuietly(); + } +} \ No newline at end of file
