http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/ParamsResource.java ---------------------------------------------------------------------- diff --git a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/ParamsResource.java b/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/ParamsResource.java deleted file mode 100644 index 2ebcdaf..0000000 --- a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/ParamsResource.java +++ /dev/null @@ -1,419 +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.rest.test; - -import static org.apache.juneau.internal.IOUtils.*; -import static org.apache.juneau.rest.RestContext.*; - -import java.io.*; -import java.util.*; -import java.util.logging.*; - -import javax.servlet.*; -import javax.servlet.http.*; - -import org.apache.juneau.*; -import org.apache.juneau.dto.swagger.*; -import org.apache.juneau.examples.addressbook.*; -import org.apache.juneau.http.*; -import org.apache.juneau.ini.*; -import org.apache.juneau.internal.*; -import org.apache.juneau.json.*; -import org.apache.juneau.parser.*; -import org.apache.juneau.plaintext.*; -import org.apache.juneau.rest.*; -import org.apache.juneau.rest.annotation.*; -import org.apache.juneau.transforms.*; -import org.apache.juneau.urlencoding.*; -import org.apache.juneau.utils.*; - -/** - * JUnit automated testcase resource. - */ -@RestResource( - path="/testParams", - serializers=PlainTextSerializer.class, - properties={ - @Property(name=REST_allowMethodParam, value="*") - }, - pojoSwaps={CalendarSwap.DateMedium.class}, - messages="ParamsResource" -) -public class ParamsResource extends RestServletDefault { - private static final long serialVersionUID = 1L; - - //==================================================================================================== - // Basic tests - //==================================================================================================== - @RestMethod(name="GET", path="/") - public void doGet(RestResponse res) { - res.setOutput("GET"); - } - - @RestMethod(name="GET", path="/get1") - public String doGet1() { - return "GET /get1"; - } - - @RestMethod(name="GET", path="/get1/{foo}") - public void doGet1a(RestResponse res, String foo) { - res.setOutput("GET /get1a " + foo); - } - - @RestMethod(name="GET", path="/get1/{foo}/{bar}") - public void doGet1b(RestResponse res, String foo, String bar) { - res.setOutput("GET /get1b " + foo + "," + bar); - } - - @RestMethod(name="GET", path="/get3/{foo}/{bar}/*") - public void doGet3(HttpServletRequest reqx, HttpServletResponse resx, String foo, int bar) { - RestRequest req = (RestRequest)reqx; - RestResponse res = (RestResponse)resx; - res.setOutput("GET /get3/"+foo+"/"+bar+" remainder="+req.getPathMatch().getRemainder()); - } - - // Test method name with overlapping name, remainder allowed. - @RestMethod(name="GET2") - public void get2(RestRequest req, RestResponse res) { - res.setOutput("GET2 remainder="+req.getPathMatch().getRemainder()); - } - - // Default POST - @RestMethod(name="POST") - public void doPost(RestRequest req, RestResponse res) { - res.setOutput("POST remainder="+req.getPathMatch().getRemainder()); - } - - // Bean parameter - @RestMethod(name="POST", path="/person/{person}") - public void doPost(RestRequest req, RestResponse res, Person p) { - res.setOutput("POST /person/{name="+p.name+",birthDate.year="+p.birthDate.get(Calendar.YEAR)+"} remainder="+req.getPathMatch().getRemainder()); - } - - // Various primitive types - @RestMethod(name="PUT", path="/primitives/{xInt}/{xShort}/{xLong}/{xChar}/{xFloat}/{xDouble}/{xByte}/{xBoolean}") - public void doPut1(RestResponse res, int xInt, short xShort, long xLong, char xChar, float xFloat, double xDouble, byte xByte, boolean xBoolean) { - res.setOutput("PUT /primitives/"+xInt+"/"+xShort+"/"+xLong+"/"+xChar+"/"+xFloat+"/"+xDouble+"/"+xByte+"/"+xBoolean); - } - - // Various primitive objects - @RestMethod(name="PUT", path="/primitiveObjects/{xInt}/{xShort}/{xLong}/{xChar}/{xFloat}/{xDouble}/{xByte}/{xBoolean}") - public void doPut2(RestResponse res, Integer xInt, Short xShort, Long xLong, Character xChar, Float xFloat, Double xDouble, Byte xByte, Boolean xBoolean) { - res.setOutput("PUT /primitiveObjects/"+xInt+"/"+xShort+"/"+xLong+"/"+xChar+"/"+xFloat+"/"+xDouble+"/"+xByte+"/"+xBoolean); - } - - // Object with forString(String) method - @RestMethod(name="PUT", path="/uuid/{uuid}") - public void doPut1(RestResponse res, UUID uuid) { - res.setOutput("PUT /uuid/"+uuid); - } - - //==================================================================================================== - // @FormData annotation - GET - //==================================================================================================== - @RestMethod(name="GET", path="/testParamGet/*") - public String testParamGet(RestRequest req, @Query("p1") String p1, @Query("p2") int p2) throws Exception { - RequestQuery q = req.getQuery(); - return "p1=["+p1+","+req.getQuery().getString("p1")+","+q.get("p1", String.class)+"],p2=["+p2+","+q.getString("p2")+","+q.get("p2", int.class)+"]"; - } - - //==================================================================================================== - // @FormData annotation - POST - //==================================================================================================== - @RestMethod(name="POST", path="/testParamPost/*") - public String testParamPost(RestRequest req, @FormData("p1") String p1, @FormData("p2") int p2) throws Exception { - RequestFormData f = req.getFormData(); - return "p1=["+p1+","+req.getFormData().getString("p1")+","+f.get("p1", String.class)+"],p2=["+p2+","+req.getFormData().getString("p2")+","+f.get("p2", int.class)+"]"; - } - - //==================================================================================================== - // @Query annotation - GET - //==================================================================================================== - @RestMethod(name="GET", path="/testQParamGet/*") - public String testQParamGet(RestRequest req, @Query("p1") String p1, @Query("p2") int p2) throws Exception { - RequestQuery q = req.getQuery(); - return "p1=["+p1+","+req.getQuery().getString("p1")+","+q.get("p1", String.class)+"],p2=["+p2+","+q.getString("p2")+","+q.get("p2", int.class)+"]"; - } - - //==================================================================================================== - // @Query annotation - POST - //==================================================================================================== - @RestMethod(name="POST", path="/testQParamPost/*") - public String testQParamPost(RestRequest req, @Query("p1") String p1, @Query("p2") int p2) throws Exception { - RequestQuery q = req.getQuery(); - return "p1=["+p1+","+req.getQuery().getString("p1")+","+q.get("p1", String.class)+"],p2=["+p2+","+q.getString("p2")+","+q.get("p2", int.class)+"]"; - } - - //==================================================================================================== - // @FormData(format=PLAIN) annotation - GET - //==================================================================================================== - @RestMethod(name="GET", path="/testPlainParamGet/*") - public String testPlainParamGet(RestRequest req, @Query(value="p1",format="PLAIN") String p1) throws Exception { - RequestQuery q = req.getQuery(); - return "p1=["+p1+","+req.getQuery().getString("p1")+","+q.get("p1", String.class)+"]"; - } - - //==================================================================================================== - // @FormData(format=PLAIN) annotation - POST - //==================================================================================================== - @RestMethod(name="POST", path="/testPlainParamPost/*") - public String testPlainParamPost(RestRequest req, @FormData(value="p1",format="PLAIN") String p1) throws Exception { - RequestFormData f = req.getFormData(); - return "p1=["+p1+","+req.getFormData().getString("p1")+","+f.get("p1", String.class)+"]"; - } - - //==================================================================================================== - // @Query(format=PLAIN) annotation - GET - //==================================================================================================== - @RestMethod(name="GET", path="/testPlainQParamGet/*") - public String testPlainQParamGet(RestRequest req, @Query(value="p1",format="PLAIN") String p1) throws Exception { - RequestQuery q = req.getQuery(); - return "p1=["+p1+","+req.getQuery().getString("p1")+","+q.get("p1", String.class)+"]"; - } - - //==================================================================================================== - // @Query(format=PLAIN) annotation - POST - //==================================================================================================== - @RestMethod(name="POST", path="/testPlainQParamPost/*") - public String testPlainQParamPost(RestRequest req, @Query(value="p1",format="PLAIN") String p1) throws Exception { - RequestQuery q = req.getQuery(); - return "p1=["+p1+","+req.getQuery().getString("p1")+","+q.get("p1", String.class)+"]"; - } - - //==================================================================================================== - // @HasQuery annotation - GET - //==================================================================================================== - @RestMethod(name="GET", path="/testHasParamGet/*") - public String testHasParamGet(RestRequest req, @HasQuery("p1") boolean p1, @HasQuery("p2") Boolean p2) throws Exception { - RequestQuery q = req.getQuery(); - return "p1=["+p1+","+q.containsKey("p1")+"],p2=["+p2+","+q.containsKey("p2")+"]"; - } - - //==================================================================================================== - // @HasQuery annotation - POST - //==================================================================================================== - @RestMethod(name="POST", path="/testHasParamPost/*") - public String testHasParamPost(RestRequest req, @HasFormData("p1") boolean p1, @HasFormData("p2") Boolean p2) throws Exception { - RequestFormData f = req.getFormData(); - return "p1=["+p1+","+f.containsKey("p1")+"],p2=["+p2+","+f.containsKey("p2")+"]"; - } - - //==================================================================================================== - // @HasQuery annotation - GET - //==================================================================================================== - @RestMethod(name="GET", path="/testHasQParamGet/*") - public String testHasQParamGet(RestRequest req, @HasQuery("p1") boolean p1, @HasQuery("p2") Boolean p2) throws Exception { - RequestQuery q = req.getQuery(); - return "p1=["+p1+","+q.containsKey("p1")+"],p2=["+p2+","+q.containsKey("p2")+"]"; - } - - //==================================================================================================== - // @HasQuery annotation - POST - //==================================================================================================== - @RestMethod(name="POST", path="/testHasQParamPost/*") - public String testHasQParamPost_post(RestRequest req, @HasQuery("p1") boolean p1, @HasQuery("p2") Boolean p2) throws Exception { - RequestQuery q = req.getQuery(); - return "p1=["+p1+","+q.containsKey("p1")+"],p2=["+p2+","+q.containsKey("p2")+"]"; - } - - //==================================================================================================== - // Form POSTS with @Body parameter - //==================================================================================================== - @RestMethod(name="POST", path="/testFormPostAsContent/*") - public String testFormPostAsContent(@Body Test6Bean bean, - @HasQuery("p1") boolean hqp1, @HasQuery("p2") boolean hqp2, - @Query("p1") String qp1, @Query("p2") int qp2) throws Exception { - return "bean=["+JsonSerializer.DEFAULT_LAX.toString(bean)+"],qp1=["+qp1+"],qp2=["+qp2+"],hqp1=["+hqp1+"],hqp2=["+hqp2+"]"; - } - - public static class Test6Bean { - public String p1; - public int p2; - } - - //==================================================================================================== - // Test @FormData and @Query annotations when using multi-part parameters (e.g. &key=val1,&key=val2). - //==================================================================================================== - @RestMethod(name="GET", path="/testMultiPartParams") - public String testMultiPartParams( - @Query(value="p1",multipart=true) String[] p1, - @Query(value="p2",multipart=true) int[] p2, - @Query(value="p3",multipart=true) List<String> p3, - @Query(value="p4",multipart=true) List<Integer> p4, - @Query(value="p5",multipart=true) String[] p5, - @Query(value="p6",multipart=true) int[] p6, - @Query(value="p7",multipart=true) List<String> p7, - @Query(value="p8",multipart=true) List<Integer> p8, - @Query(value="p9",multipart=true) A[] p9, - @Query(value="p10",multipart=true) List<A> p10, - @Query(value="p11",multipart=true) A[] p11, - @Query(value="p12",multipart=true) List<A> p12) throws Exception { - ObjectMap m = new ObjectMap() - .append("p1", p1) - .append("p2", p2) - .append("p3", p3) - .append("p4", p4) - .append("p5", p5) - .append("p6", p6) - .append("p7", p7) - .append("p8", p8) - .append("p9", p9) - .append("p10", p10) - .append("p11", p11) - .append("p12", p12); - return JsonSerializer.DEFAULT_LAX.toString(m); - } - - public static class A { - public String a; - public int b; - public boolean c; - } - - //==================================================================================================== - // Test multi-part parameter keys on bean properties of type array/Collection (i.e. &key=val1,&key=val2) - // using URLENC_expandedParams property. - // A simple round-trip test to verify that both serializing and parsing works. - //==================================================================================================== - @RestMethod(name="POST", path="/testFormPostsWithMultiParamsUsingProperty", - properties={ - @Property(name=UrlEncodingContext.URLENC_expandedParams, value="true") - } - ) - public DTO2s.B testFormPostsWithMultiParamsViaProperty(@Body DTO2s.B content) throws Exception { - return content; - } - - //==================================================================================================== - // Test multi-part parameter keys on bean properties of type array/Collection (i.e. &key=val1,&key=val2) - // using @UrlEncoding(expandedParams=true) annotation. - // A simple round-trip test to verify that both serializing and parsing works. - //==================================================================================================== - @RestMethod(name="POST", path="/testFormPostsWithMultiParamsUsingAnnotation") - public DTO2s.C testFormPostsWithMultiParamsUsingAnnotation(@Body DTO2s.C content) throws Exception { - return content; - } - - //==================================================================================================== - // Test other available object types as parameters. - //==================================================================================================== - - @RestMethod(name="GET", path="/otherObjects/ResourceBundle") - public String testOtherResourceBundle(ResourceBundle t) { - if (t != null) - return t.getString("foo"); - return null; - } - - @RestMethod(name="GET", path="/otherObjects/MessageBundle") - public String testOtherMessages(MessageBundle t) { - if (t != null) - return t.getString("foo"); - return null; - } - - @RestMethod(name="POST", path="/otherObjects/InputStream") - public String testOtherInputStream(InputStream t) throws IOException { - return read(t); - } - - @RestMethod(name="POST", path="/otherObjects/ServletInputStream") - public String testOtherServletInputStream(ServletInputStream t) throws IOException { - return read(t); - } - - @RestMethod(name="POST", path="/otherObjects/Reader") - public String testOtherReader(Reader t) throws IOException { - return read(t); - } - - @RestMethod(name="GET", path="/otherObjects/OutputStream") - public void testOtherOutputStream(OutputStream t) throws IOException { - t.write("OK".getBytes()); - } - - @RestMethod(name="GET", path="/otherObjects/ServletOutputStream") - public void testOtherServletOutputStream(ServletOutputStream t) throws IOException { - t.write("OK".getBytes()); - } - - @RestMethod(name="GET", path="/otherObjects/Writer") - public void testOtherWriter(Writer t) throws IOException { - t.write("OK"); - } - - @RestMethod(name="GET", path="/otherObjects/RequestHeaders") - public boolean testOtherRequestHeaders(RequestHeaders t) { - return t != null; - } - - @RestMethod(name="GET", path="/otherObjects/RequestQuery") - public boolean testOtherRequestQueryParams(RequestQuery t) { - return t != null; - } - - @RestMethod(name="GET", path="/otherObjects/RequestFormData") - public boolean testOtherRequestFormData(RequestFormData t) { - return t != null; - } - - @RestMethod(name="GET", path="/otherObjects/HttpMethod") - public String testOtherHttpMethod(HttpMethod t) { - return t.toString(); - } - - @RestMethod(name="GET", path="/otherObjects/Logger") - public boolean testOtherLogger(Logger t) { - return t != null; - } - - @RestMethod(name="GET", path="/otherObjects/JuneauLogger") - public boolean testOtherJuneauLogger(JuneauLogger t) { - return t != null; - } - - @RestMethod(name="GET", path="/otherObjects/RestContext") - public boolean testOtherRestContext(RestContext t) { - return t != null; - } - - @RestMethod(name="GET", path="/otherObjects/Parser") - public String testOtherParser(Parser t) { - return t.getClass().getName(); - } - - @RestMethod(name="GET", path="/otherObjects/Locale") - public String testOtherLocale(Locale t) { - return t.toString(); - } - - @RestMethod(name="GET", path="/otherObjects/Swagger") - public boolean testOtherSwagger(Swagger t) { - return t != null; - } - - @RestMethod(name="GET", path="/otherObjects/RequestPathMatch") - public boolean testOtherRequestPathMatch(RequestPathMatch t) { - return t != null; - } - - @RestMethod(name="GET", path="/otherObjects/RequestBody") - public boolean testOtherRequestBody(RequestBody t) { - return t != null; - } - - @RestMethod(name="GET", path="/otherObjects/ConfigFile") - public boolean testOtherConfigFile(ConfigFile t) { - return t != null; - } -}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/ParsersResource.java ---------------------------------------------------------------------- diff --git a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/ParsersResource.java b/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/ParsersResource.java deleted file mode 100644 index 9cb9d13..0000000 --- a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/ParsersResource.java +++ /dev/null @@ -1,151 +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.rest.test; - -import static org.apache.juneau.internal.IOUtils.*; -import static org.apache.juneau.rest.annotation.Inherit.*; - -import org.apache.juneau.*; -import org.apache.juneau.parser.*; -import org.apache.juneau.plaintext.*; -import org.apache.juneau.rest.*; -import org.apache.juneau.rest.annotation.*; - -/** - * JUnit automated testcase resource. - * Validates correct parser is used. - */ -@RestResource( - path="/testParsers", - parsers=ParsersResource.TestParserA.class, - serializers=PlainTextSerializer.class -) -public class ParsersResource extends RestServletDefault { - private static final long serialVersionUID = 1L; - - public static class TestParserA extends ReaderParser { - - public TestParserA(PropertyStore propertyStore) { - super(propertyStore, "text/a"); - } - - @Override /* Parser */ - public ReaderParserSession createSession(ParserSessionArgs args) { - return new ReaderParserSession(args) { - - @Override /* ParserSession */ - @SuppressWarnings("unchecked") - protected <T> T doParse(ParserPipe pipe, ClassMeta<T> type) throws Exception { - return (T)("text/a - " + read(pipe.getReader()).trim()); - } - }; - } - } - - //==================================================================================================== - // Parser defined on class. - //==================================================================================================== - @RestMethod(name="PUT", path="/testParserOnClass") - public String testParserOnClass(@Body String in) { - return in; - } - - //==================================================================================================== - // Parser defined on method. - //==================================================================================================== - @RestMethod(name="PUT", path="/testParserOnMethod", parsers=TestParserB.class) - public String testParserOnMethod(@Body String in) { - return in; - } - - public static class TestParserB extends ReaderParser { - - public TestParserB(PropertyStore propertyStore) { - super(propertyStore, "text/b"); - } - - @Override /* Parser */ - public ReaderParserSession createSession(ParserSessionArgs args) { - return new ReaderParserSession(args) { - - @Override /* ParserSession */ - @SuppressWarnings("unchecked") - protected <T> T doParse(ParserPipe pipe, ClassMeta<T> type) throws Exception { - return (T)("text/b - " + read(pipe.getReader()).trim()); - } - }; - } - } - - //==================================================================================================== - // Parser overridden on method. - //==================================================================================================== - @RestMethod(name="PUT", path="/testParserOverriddenOnMethod", parsers={TestParserB.class,TestParserC.class}, parsersInherit=PARSERS) - public String testParserOverriddenOnMethod(@Body String in) { - return in; - } - - public static class TestParserC extends ReaderParser { - - public TestParserC(PropertyStore propertyStore) { - super(propertyStore, "text/c"); - } - - @Override /* Parser */ - public ReaderParserSession createSession(ParserSessionArgs args) { - return new ReaderParserSession(args) { - - @Override /* ParserSession */ - @SuppressWarnings("unchecked") - protected <T> T doParse(ParserPipe pipe, ClassMeta<T> type) throws Exception { - return (T)("text/c - " + read(pipe.getReader()).trim()); - } - }; - } - } - - //==================================================================================================== - // Parser with different Accept than Content-Type. - //==================================================================================================== - @RestMethod(name="PUT", path="/testParserWithDifferentMediaTypes", parsers={TestParserD.class}, parsersInherit=PARSERS) - public String testParserWithDifferentMediaTypes(@Body String in) { - return in; - } - - public static class TestParserD extends ReaderParser { - - public TestParserD(PropertyStore propertyStore) { - super(propertyStore, "text/d"); - } - - @Override /* Parser */ - public ReaderParserSession createSession(ParserSessionArgs args) { - return new ReaderParserSession(args) { - - @Override /* ParserSession */ - @SuppressWarnings("unchecked") - protected <T> T doParse(ParserPipe pipe, ClassMeta<T> type) throws Exception { - return (T)("text/d - " + read(pipe.getReader()).trim()); - } - }; - } - } - - //==================================================================================================== - // Check for valid error response. - //==================================================================================================== - @RestMethod(name="PUT", path="/testValidErrorResponse") - public String testValidErrorResponse(@Body String in) { - return in; - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PathResource.java ---------------------------------------------------------------------- diff --git a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PathResource.java b/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PathResource.java deleted file mode 100644 index e1b7f5c..0000000 --- a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PathResource.java +++ /dev/null @@ -1,69 +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.rest.test; - -import org.apache.juneau.rest.*; -import org.apache.juneau.rest.annotation.*; - -/** - * JUnit automated testcase resource. - * Tests the RestServlet.getPath() method. - */ -@RestResource( - path="/testPath", - children={ - PathResource.TestPath2.class - } -) -public class PathResource extends RestServletDefault { - private static final long serialVersionUID = 1L; - - //==================================================================================================== - // Basic tests - //==================================================================================================== - @RestMethod(name="GET", path="/") - public String doGet() { - return getContext().getPath(); - } - - @RestResource( - path="/testPath2", - children={ - PathResource.TestPath3.class - } - ) - public static class TestPath2 extends RestServletDefault { - private static final long serialVersionUID = 1L; - // Basic tests - @RestMethod(name="GET", path="/") - public String doGet() { - return getContext().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 getContext().getPath(); - } - } - - public static class TestPath3 extends TestPath3a { - private static final long serialVersionUID = 1L; - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PathVariablesResource.java ---------------------------------------------------------------------- diff --git a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PathVariablesResource.java b/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PathVariablesResource.java deleted file mode 100644 index 1a72297..0000000 --- a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PathVariablesResource.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.rest.test; - -import org.apache.juneau.rest.*; -import org.apache.juneau.rest.annotation.*; -import org.apache.juneau.utils.*; - -/** - * JUnit automated testcase resource. - * Tests the <code>@RestMethod.path()</code> annotation. - */ -@RestResource( - path="/testPathVariables" -) -public class PathVariablesResource extends RestServletDefault { - private static final long serialVersionUID = 1L; - - @RestMethod(name="GET", path="/test1/{x}/foo/{y}/bar/{z}/*") - public StringMessage test1(@Path String x, @Path int y, @Path boolean z) { - return new StringMessage("x={0},y={1},z={2}", x, y, z); - } - - @RestMethod(name="GET", path="/test2/{z}/foo/{y}/bar/{x}/*") - public StringMessage test2(@Path("x") String x, @Path("y") int y, @Path("z") boolean z) { - return new StringMessage("x={0},y={1},z={2}", x, y, z); - } - - @RestMethod(name="GET", path="/test3/{0}/foo/{1}/bar/{2}/*") - public StringMessage test3(@Path String x, @Path int y, @Path boolean z) { - return new StringMessage("x={0},y={1},z={2}", x, y, z); - } - - @RestMethod(name="GET", path="/test4/{2}/foo/{1}/bar/{0}/*") - public StringMessage test4(@Path String x, @Path int y, @Path boolean z) { - return new StringMessage("x={0},y={1},z={2}", x, y, z); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PathsResource.java ---------------------------------------------------------------------- diff --git a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PathsResource.java b/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PathsResource.java deleted file mode 100644 index d9de449..0000000 --- a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PathsResource.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.rest.test; - -import org.apache.juneau.*; -import org.apache.juneau.rest.*; -import org.apache.juneau.rest.annotation.*; - -/** - * JUnit automated testcase resource. - * Tests the URL-related methods on RestRequest. - */ -@RestResource( - path="/testPaths", - children={ - PathsResource.A.class - } -) -public class PathsResource extends RestServletDefault { - private static final long serialVersionUID = 1L; - - @RestMethod(name="GET", path="/*") - public ObjectMap doGet1(RestRequest req, @PathRemainder String r) { - return getPaths(req).append("pathRemainder2", r).append("method",1); - } - - @RestMethod(name="GET", path="/test2/*") - public ObjectMap doGet2(RestRequest req, @PathRemainder String r) { - return getPaths(req).append("pathRemainder2", r).append("method",2); - } - - @RestResource( - path="/a" - ) - public static class A extends RestServletDefault { - private static final long serialVersionUID = 1L; - @RestMethod(name="GET", path="/*") - public ObjectMap doGet1(RestRequest req, @PathRemainder String r) { - return getPaths(req).append("pathRemainder2", r).append("method",3); - } - @RestMethod(name="GET", path="/test2/*") - public ObjectMap doGet2(RestRequest req, @PathRemainder String r) { - return getPaths(req).append("pathRemainder2", r).append("method",4); - } - } - - private static ObjectMap getPaths(RestRequest req) { - return new ObjectMap() - .append("pathInfo", req.getPathInfo()) - .append("pathRemainder", req.getPathMatch().getRemainder()) - .append("pathRemainderUndecoded", req.getPathMatch().getRemainderUndecoded()) - .append("requestURI", req.getRequestURI()) - .append("requestParentURI", req.getUriContext().getRootRelativePathInfoParent()) - .append("requestURL", req.getRequestURL()) - .append("servletPath", req.getServletPath()) - .append("servletURI", req.getUriContext().getRootRelativeServletPath()) - .append("servletParentURI", req.getUriContext().getRootRelativeServletPathParent()); - - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PropertiesResource.java ---------------------------------------------------------------------- diff --git a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PropertiesResource.java b/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PropertiesResource.java deleted file mode 100644 index c608a68..0000000 --- a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/PropertiesResource.java +++ /dev/null @@ -1,106 +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.rest.test; - -import static java.lang.String.*; - -import org.apache.juneau.*; -import org.apache.juneau.rest.*; -import org.apache.juneau.rest.annotation.*; -import org.apache.juneau.serializer.*; - -/** - * JUnit automated testcase resource. - */ -@RestResource( - path="/testProperties", - properties={ - @Property(name="A1",value="a1"), - @Property(name="A2",value="a2"), - @Property(name="foo",value="bar"), - @Property(name="bar",value="baz"), - @Property(name="R1a",value="$R{requestURI}"), - @Property(name="R1b",value="$R{requestParentURI}"), - @Property(name="R2",value="$R{foo}"), - @Property(name="R3",value="$R{$R{foo}}"), - @Property(name="R4",value="$R{A1}"), - @Property(name="R5",value="$R{A2}"), - @Property(name="R6",value="$R{C}"), - } -) -public class PropertiesResource extends RestServletDefault { - private static final long serialVersionUID = 1L; - - //==================================================================================================== - // Properties defined on method. - //==================================================================================================== - @RestMethod(name="GET", path="/testPropertiesDefinedOnMethod", - properties={ - @Property(name="B1",value="b1"), - @Property(name="B2",value="b2") - }, - serializers=PropertySerializer1.class - ) - public void testPropertiesDefinedOnMethod(RestResponse res) { - res.setProperty("A2", "c"); - res.setProperty("B2", "c"); - res.setProperty("C", "c"); - res.setOutput(null); - } - - public static class PropertySerializer1 extends WriterSerializer { - - public PropertySerializer1(PropertyStore propertyStore) { - super(propertyStore, "application/json", "*/json"); - } - - @Override /* Serializer */ - public WriterSerializerSession createSession(SerializerSessionArgs args) { - return new WriterSerializerSession(args) { - - @Override /* SerializerSession */ - protected void doSerialize(SerializerPipe out, Object o) throws Exception { - out.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", - getStringProperty("A1"), getStringProperty("A2"), getStringProperty("B1"), getStringProperty("B2"), getStringProperty("C"), - getStringProperty("R1a"), getStringProperty("R1b"), getStringProperty("R2"), getStringProperty("R3"), getStringProperty("R4"), getStringProperty("R5"), getStringProperty("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); - } - - public static class PropertySerializer2 extends WriterSerializer { - - public PropertySerializer2(PropertyStore propertyStore) { - super(propertyStore, "application/json", "*/json"); - } - - @Override /* Serializer */ - public WriterSerializerSession createSession(SerializerSessionArgs args) { - return new WriterSerializerSession(args) { - - @Override /* SerializerSession */ - protected void doSerialize(SerializerPipe out, Object o) throws Exception { - out.getWriter().write(format("A=%s,P=%s,H=%s", getStringProperty("A"), getStringProperty("P"), getStringProperty("h"))); - } - }; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/QueryResource.java ---------------------------------------------------------------------- diff --git a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/QueryResource.java b/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/QueryResource.java deleted file mode 100644 index db470ac..0000000 --- a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/QueryResource.java +++ /dev/null @@ -1,63 +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.rest.test; - -import org.apache.juneau.*; -import org.apache.juneau.rest.*; -import org.apache.juneau.rest.annotation.*; - -/** - * JUnit automated testcase resource. - */ -@RestResource( - path="/testQuery" -) -public class QueryResource extends RestServletDefault { - private static final long serialVersionUID = 1L; - - //==================================================================================================== - // Default values. - //==================================================================================================== - - @RestMethod(name="GET", path="/defaultQuery", defaultQuery={"f1:1","f2=2"," f3 : 3 "}) - public ObjectMap defaultQuery(RequestQuery query) { - return new ObjectMap() - .append("f1", query.getString("f1")) - .append("f2", query.getString("f2")) - .append("f3", query.getString("f3")); - } - - @RestMethod(name="GET", path="/annotatedQuery") - public ObjectMap annotatedQuery(@Query("f1") String f1, @Query("f2") String f2, @Query("f3") String f3) { - return new ObjectMap() - .append("f1", f1) - .append("f2", f2) - .append("f3", f3); - } - - @RestMethod(name="GET", path="/annotatedQueryDefault") - public ObjectMap annotatedQueryDefault(@Query(value="f1",def="1") String f1, @Query(value="f2",def="2") String f2, @Query(value="f3",def="3") String f3) { - return new ObjectMap() - .append("f1", f1) - .append("f2", f2) - .append("f3", f3); - } - - @RestMethod(name="GET", path="/annotatedAndDefaultQuery", defaultQuery={"f1:1","f2=2"," f3 : 3 "}) - public ObjectMap annotatedAndDefaultQuery(@Query(value="f1",def="4") String f1, @Query(value="f2",def="5") String f2, @Query(value="f3",def="6") String f3) { - return new ObjectMap() - .append("f1", f1) - .append("f2", f2) - .append("f3", f3); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/RequestBeanProxyResource.java ---------------------------------------------------------------------- diff --git a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/RequestBeanProxyResource.java b/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/RequestBeanProxyResource.java deleted file mode 100644 index eed0679..0000000 --- a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/RequestBeanProxyResource.java +++ /dev/null @@ -1,50 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.rest.test; - - -import java.io.*; - -import org.apache.juneau.microservice.*; -import org.apache.juneau.rest.*; -import org.apache.juneau.rest.annotation.*; - -/** - * Validates the functionality of <ja>@RequestBeans</ja>. - */ -@RestResource( - path="/testRequestBeanProxy" -) -@SuppressWarnings("serial") -public class RequestBeanProxyResource extends ResourceJena { - - @RestMethod(name="GET", path="/echoQuery") - public Reader echoQuery(RestRequest req) throws Exception { - return new StringReader(req.getQuery().toString(true)); - } - - @RestMethod(name="POST", path="/echoFormData") - public Reader echoFormData(RestRequest req) throws Exception { - return new StringReader(req.getFormData().toString(true)); - } - - @RestMethod(name="GET", path="/echoHeaders") - public Reader echoHeaders(RestRequest req) throws Exception { - return new StringReader(req.getHeaders().subset("a,b,c,d,e,f,g,h,i,a1,a2,a3,a4,b1,b2,b3,b4,c1,c2,c3,c4").toString(true)); - } - - @RestMethod(name="GET", path="/echoPath/*") - public Reader echoPath(RestRequest req) throws Exception { - return new StringReader(req.getPathMatch().getRemainder()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/RestClient2Resource.java ---------------------------------------------------------------------- diff --git a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/RestClient2Resource.java b/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/RestClient2Resource.java deleted file mode 100644 index 5aa04b9..0000000 --- a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/RestClient2Resource.java +++ /dev/null @@ -1,36 +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.rest.test; - -import java.io.*; - -import org.apache.juneau.rest.*; -import org.apache.juneau.rest.annotation.*; - -/** - * JUnit automated testcase resource. - */ -@RestResource( - path="/testRestClient" -) -public class RestClient2Resource extends RestServletDefault { - private static final long serialVersionUID = 1L; - - //==================================================================================================== - // Echo response - //==================================================================================================== - @RestMethod(name="POST", path="/") - public Reader test1(RestRequest req) throws Exception { - return new StringReader(req.getBody().asString()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/RestHooksInitResource.java ---------------------------------------------------------------------- diff --git a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/RestHooksInitResource.java b/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/RestHooksInitResource.java deleted file mode 100644 index 4a85c2c..0000000 --- a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/RestHooksInitResource.java +++ /dev/null @@ -1,274 +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.rest.test; - -import static org.apache.juneau.rest.annotation.HookEvent.*; - -import java.util.*; - -import javax.servlet.*; - -import org.apache.juneau.rest.*; -import org.apache.juneau.rest.annotation.*; - -/** - * Validates the behavior of the @RestHook(INIT/POST_INIT/POST_INIT_CHILD_FIRST) annotations. - */ -@RestResource( - path="/testRestHooksInit", - children={ - RestHooksInitResource.Super.class, - RestHooksInitResource.Sub.class - } -) -public class RestHooksInitResource extends RestServletDefault { - private static final long serialVersionUID = 1L; - - @RestResource( - path="/super" - ) - public static class Super extends RestServletDefault { - private static final long serialVersionUID = 1L; - - protected List<String> init = new ArrayList<String>(); - protected List<String> postInit = new ArrayList<String>(); - protected List<String> postInitChildFirst = new ArrayList<String>(); - - @RestHook(INIT) - public void init1c(RestConfig config) { - init.add("super-1c"); - } - - @RestHook(INIT) - public void init1a(ServletConfig config) { - init.add("super-1a"); - } - - @RestHook(INIT) - public void init1b() { - init.add("super-1b"); - } - - @RestHook(INIT) - public void init2a() { - init.add("super-2a"); - } - - @RestHook(POST_INIT) - public void postInit1c(RestContext context) { - postInit.add("super-1c"); - } - - @RestHook(POST_INIT) - public void postInit1a(RestContext context) { - postInit.add("super-1a"); - } - - @RestHook(POST_INIT) - public void postInit1b() { - postInit.add("super-1b"); - } - - @RestHook(POST_INIT) - public void postInit2a() { - postInit.add("super-2a"); - } - - @RestHook(POST_INIT_CHILD_FIRST) - public void postInitChildFirst1c(RestContext context) { - postInitChildFirst.add("super-1c"); - } - - @RestHook(POST_INIT_CHILD_FIRST) - public void postInitChildFirst1a(RestContext context) { - postInitChildFirst.add("super-1a"); - } - - @RestHook(POST_INIT_CHILD_FIRST) - public void postInitChildFirst1b() { - postInitChildFirst.add("super-1b"); - } - - @RestHook(POST_INIT_CHILD_FIRST) - public void postInitChildFirst2a() { - postInitChildFirst.add("super-2a"); - } - - @RestMethod(name="GET", path="/init") - public List<String> getInitEvents() { - return init; - } - - @RestMethod(name="GET", path="/postInit") - public List<String> getPostInitEvents() { - return postInit; - } - - @RestMethod(name="GET", path="/postInitChildFirst") - public List<String> getPostInitChildFirstEvents() { - return postInitChildFirst; - } - } - - @RestResource( - path="/sub", - children={ - Child.class - } - ) - public static class Sub extends Super { - private static final long serialVersionUID = 1L; - - protected static String postInitOrderTest; - protected static String postInitChildFirstOrderTest; - - @Override - @RestHook(INIT) - public void init1c(RestConfig config) { - init.add("sub-1c"); - } - - @Override - @RestHook(INIT) - public void init1a(ServletConfig config) { - init.add("sub-1a"); - } - - @Override - @RestHook(INIT) - public void init1b() { - init.add("sub-1b"); - } - - @RestHook(INIT) - public void init2b() { - init.add("sub-2b"); - } - - @Override - @RestHook(POST_INIT) - public void postInit1c(RestContext context) { - postInit.add("sub-1c"); - } - - @Override - @RestHook(POST_INIT) - public void postInit1a(RestContext context) { - postInit.add("sub-1a"); - } - - @Override - @RestHook(POST_INIT) - public void postInit1b() { - postInit.add("sub-1b"); - } - - @RestHook(POST_INIT) - public void postInit2b() { - postInit.add("sub-2b"); - } - - @Override - @RestHook(POST_INIT_CHILD_FIRST) - public void postInitChildFirst1c(RestContext context) { - postInitChildFirst.add("sub-1c"); - } - - @Override - @RestHook(POST_INIT_CHILD_FIRST) - public void postInitChildFirst1a(RestContext context) { - postInitChildFirst.add("sub-1a"); - } - - @Override - @RestHook(POST_INIT_CHILD_FIRST) - public void postInitChildFirst1b() { - postInitChildFirst.add("sub-1b"); - } - - @RestHook(POST_INIT_CHILD_FIRST) - public void postInitChildFirst2b() { - postInitChildFirst.add("sub-2b"); - } - - @RestHook(POST_INIT) - public void postInitOrderTestSub() { - postInitOrderTest = "PARENT"; - } - - @RestHook(POST_INIT_CHILD_FIRST) - public void postInitChildFirstOrderTestSub() { - postInitChildFirstOrderTest = "PARENT"; - } - - @RestMethod(name="GET", path="/postInitOrder") - public String postInitOrderTest() { - return postInitOrderTest; - } - - @RestMethod(name="GET", path="/postInitChildFirstOrder") - public String postInitChildFirstOrderTest() { - return postInitChildFirstOrderTest; - } - } - - @RestResource( - path="/child" - ) - public static class Child extends Super { - private static final long serialVersionUID = 1L; - - @Override - @RestHook(INIT) - public void init1c(RestConfig config) { - init.add("child-1c"); - } - - @RestHook(INIT) - public void init2b() { - init.add("child-2b"); - } - - @Override - @RestHook(POST_INIT) - public void postInit1c(RestContext context) { - postInit.add("child-1c"); - } - - @RestHook(POST_INIT) - public void postInit2b() { - postInit.add("child-2b"); - } - - @Override - @RestHook(POST_INIT_CHILD_FIRST) - public void postInitChildFirst1c(RestContext context) { - postInitChildFirst.add("child-1c"); - } - - @RestHook(POST_INIT_CHILD_FIRST) - public void postInitChildFirst2b() { - postInitChildFirst.add("child-2b"); - } - - @RestHook(POST_INIT) - public void postInitOrderTestSub() { - Sub.postInitOrderTest = "CHILD"; - } - - @RestHook(POST_INIT_CHILD_FIRST) - public void postInitChildFirstOrderTestSub() { - Sub.postInitChildFirstOrderTest = "CHILD"; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/RestHooksResource.java ---------------------------------------------------------------------- diff --git a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/RestHooksResource.java b/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/RestHooksResource.java deleted file mode 100644 index 0597272..0000000 --- a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/RestHooksResource.java +++ /dev/null @@ -1,189 +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.rest.test; - -import static org.apache.juneau.rest.annotation.HookEvent.*; - -import java.util.*; - -import javax.servlet.http.*; - -import org.apache.juneau.http.*; -import org.apache.juneau.rest.*; -import org.apache.juneau.rest.annotation.*; -import org.apache.juneau.utils.*; - -/** - * Validates the behavior of the @RestHook(START/PRE/POST) annotations. - */ -@RestResource( - path="/testRestHooks", - children={ - RestHooksResource.Start.class, - RestHooksResource.Pre.class, - RestHooksResource.Post.class, - } -) -public class RestHooksResource extends RestServletDefault { - private static final long serialVersionUID = 1L; - - @RestResource( - path="/start" - ) - public static class Start extends StartParent { - private static final long serialVersionUID = 1L; - - private boolean start3Called; - - @RestHook(START_CALL) - public void start3() { - start3Called = true; - } - - @RestHook(START_CALL) - public void start4(HttpServletRequest req, HttpServletResponse res) { - res.setHeader("start3-called", ""+start3Called); - start3Called = false; - if (res.getHeader("start4-called") != null) - throw new RuntimeException("start4 called multiple times."); - res.setHeader("start4-called", "true"); - } - - @RestMethod(path="/") - public Map<String,Object> getHeaders(RestRequest req, RestResponse res) { - return new AMap<String,Object>() - .append("1", res.getHeader("start1-called")) - .append("2", res.getHeader("start2-called")) - .append("3", res.getHeader("start3-called")) - .append("4", res.getHeader("start4-called")); - } - } - - public static class StartParent extends RestServletDefault { - private static final long serialVersionUID = 1L; - - private boolean start1Called; - - @RestHook(START_CALL) - public void start1() { - start1Called = true; - } - - @RestHook(START_CALL) - public void start2(HttpServletRequest req, HttpServletResponse res) { - res.setHeader("start1-called", ""+start1Called); - start1Called = false; - if (res.getHeader("start2-called") != null) - throw new RuntimeException("start2 called multiple times."); - res.setHeader("start2-called", "true"); - } - } - - @RestResource( - path="/pre" - ) - public static class Pre extends PreParent { - private static final long serialVersionUID = 1L; - - private boolean pre3Called; - - @RestHook(PRE_CALL) - public void pre3() { - pre3Called = true; - } - - @RestHook(PRE_CALL) - public void pre4(HttpServletRequest req, HttpServletResponse res) { - res.setHeader("pre3-called", ""+pre3Called); - pre3Called = false; - if (res.getHeader("pre4-called") != null) - throw new RuntimeException("pre4 called multiple times."); - res.setHeader("pre4-called", "true"); - } - - @RestMethod(path="/") - public Map<String,Object> getHeaders(RestRequest req, RestResponse res) { - return new AMap<String,Object>() - .append("1", res.getHeader("pre1-called")) - .append("2", res.getHeader("pre2-called")) - .append("3", res.getHeader("pre3-called")) - .append("4", res.getHeader("pre4-called")); - } - } - - public static class PreParent extends RestServletDefault { - private static final long serialVersionUID = 1L; - - private boolean pre1Called; - - @RestHook(PRE_CALL) - public void pre1() { - pre1Called = true; - } - - @RestHook(PRE_CALL) - public void pre2(Accept accept, RestRequest req, RestResponse res) { - res.setHeader("pre1-called", ""+pre1Called); - pre1Called = false; - if (res.getHeader("pre2-called") != null) - throw new RuntimeException("pre2 called multiple times."); - res.setHeader("pre2-called", "true"); - } - } - - @RestResource( - path="/post" - ) - public static class Post extends PostParent { - private static final long serialVersionUID = 1L; - private boolean post3Called; - - @RestHook(POST_CALL) - public void post3() { - post3Called = true; - } - - @RestHook(POST_CALL) - public void post4(HttpServletRequest req, HttpServletResponse res) { - res.setHeader("post3-called", ""+post3Called); - post3Called = false; - if (res.getHeader("post4-called") != null) - throw new RuntimeException("post4 called multiple times."); - res.setHeader("post4-called", "true"); - } - - @RestMethod(path="/") - public String doGet() { - return "OK"; - } - } - - public static class PostParent extends RestServletDefault { - private static final long serialVersionUID = 1L; - private boolean post1Called; - - @RestHook(POST_CALL) - public void post1() { - post1Called = true; - } - - @RestHook(POST_CALL) - public void post2(Accept accept, RestRequest req, RestResponse res) { - res.setHeader("post1-called", ""+post1Called); - post1Called = false; - if (res.getHeader("post2-called") != null) - throw new RuntimeException("post2 called multiple times."); - res.setHeader("post2-called", "true"); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/Root.java ---------------------------------------------------------------------- diff --git a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/Root.java b/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/Root.java deleted file mode 100644 index a7f51e1..0000000 --- a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/Root.java +++ /dev/null @@ -1,84 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.rest.test; - -import org.apache.juneau.microservice.resources.*; -import org.apache.juneau.rest.*; -import org.apache.juneau.rest.annotation.*; -import org.apache.juneau.rest.labels.*; - -@RestResource( - path="/", - children={ - AcceptCharsetResource.class, - BeanContextPropertiesResource.class, - BpiResource.class, - CallbackStringsResource.class, - CharsetEncodingsResource.class, - ClientFuturesResource.class, - ClientVersionResource.class, - ConfigResource.class, - ContentResource.class, - DefaultContentTypesResource.class, - ErrorConditionsResource.class, - TransformsResource.class, - FormDataResource.class, - GroupsResource.class, - GzipResource.TestGzipOff.class, - GzipResource.TestGzipOn.class, - HeadersResource.class, - HtmlDocResource.class, - HtmlDocLinksResource.class, - InheritanceResource.TestEncoders.class, - InheritanceResource.TestTransforms.class, - InheritanceResource.TestParsers.class, - InheritanceResource.TestProperties.class, - InheritanceResource.TestSerializers.class, - InterfaceProxyResource.class, - LargePojosResource.class, - MessagesResource.Messages2Resource.class, - MessagesResource.class, - NlsResource.class, - NlsPropertyResource.class, - NoParserInputResource.class, - OnPostCallResource.class, - OnPreCallResource.class, - OptionsWithoutNlsResource.class, - OverlappingMethodsResource.class, - ParamsResource.class, - ParsersResource.class, - PathResource.class, - PathsResource.class, - PathVariablesResource.class, - PropertiesResource.class, - QueryResource.class, - RequestBeanProxyResource.class, - RestClient2Resource.class, - RestHooksInitResource.class, - RestHooksResource.class, - SerializersResource.class, - StaticFilesResource.class, - ThirdPartyProxyResource.class, - UrisResource.class, - UrlContentResource.class, - ShutdownResource.class - } -) -public class Root extends RestServletDefault { - private static final long serialVersionUID = 1L; - - @RestMethod(name="GET", path="/") - public ChildResourceDescriptions doGet(RestRequest req) { - return new ChildResourceDescriptions(getContext(), req); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/SerializersResource.java ---------------------------------------------------------------------- diff --git a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/SerializersResource.java b/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/SerializersResource.java deleted file mode 100644 index 21b1f37..0000000 --- a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/SerializersResource.java +++ /dev/null @@ -1,143 +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.rest.test; - -import static org.apache.juneau.rest.annotation.Inherit.*; - -import org.apache.juneau.*; -import org.apache.juneau.rest.*; -import org.apache.juneau.rest.annotation.*; -import org.apache.juneau.serializer.*; - -/** - * JUnit automated testcase resource. - */ -@RestResource( - path="/testSerializers", - serializers=SerializersResource.TestSerializerA.class -) -public class SerializersResource extends RestServletDefault { - private static final long serialVersionUID = 1L; - - public static class TestSerializerA extends WriterSerializer { - - public TestSerializerA(PropertyStore propertyStore) { - super(propertyStore, "text/a"); - } - - @Override /* Serializer */ - public WriterSerializerSession createSession(SerializerSessionArgs args) { - return new WriterSerializerSession(args) { - - @Override /* SerializerSession */ - protected void doSerialize(SerializerPipe out, Object o) throws Exception { - out.getWriter().write("text/a - " + o); - } - }; - } - } - - public static class TestSerializerB extends WriterSerializer { - - public TestSerializerB(PropertyStore propertyStore) { - super(propertyStore, "text/b"); - } - - @Override /* Serializer */ - public WriterSerializerSession createSession(SerializerSessionArgs args) { - return new WriterSerializerSession(args) { - - @Override /* SerializerSession */ - protected void doSerialize(SerializerPipe out, Object o) throws Exception { - out.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"; - } - - public static class TestSerializerC extends WriterSerializer { - - public TestSerializerC(PropertyStore propertyStore) { - super(propertyStore, "text/a"); - } - - @Override /* Serializer */ - public WriterSerializerSession createSession(SerializerSessionArgs args) { - return new WriterSerializerSession(args) { - - @Override /* SerializerSession */ - protected void doSerialize(SerializerPipe out, Object o) throws Exception { - out.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"; - } - - public static class TestSerializerD extends WriterSerializer { - - public TestSerializerD(PropertyStore propertyStore) { - super(propertyStore, "text/d", "text/a", "text/d"); - } - - @Override /* Serializer */ - public WriterSerializerSession createSession(SerializerSessionArgs args) { - return new WriterSerializerSession(args) { - - @Override /* SerializerSession */ - protected void doSerialize(SerializerPipe out, Object o) throws Exception { - out.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/750916a9/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/StaticFilesResource.java ---------------------------------------------------------------------- diff --git a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/StaticFilesResource.java b/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/StaticFilesResource.java deleted file mode 100644 index ba9d895..0000000 --- a/juneau-rest/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/StaticFilesResource.java +++ /dev/null @@ -1,36 +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.rest.test; - -import org.apache.juneau.rest.*; -import org.apache.juneau.rest.annotation.*; - -/** - * JUnit automated testcase resource. - */ -@RestResource( - path="/testStaticFiles", - staticFiles="{xdocs:'xdocs'}" -) -public class StaticFilesResource extends RestServlet { - private static final long serialVersionUID = 1L; - - //==================================================================================================== - // Tests the @RestResource(staticFiles) annotation. - //==================================================================================================== - @RestMethod(name="GET", path="/*") - public String testXdocs() { - return null; - } - -}
