Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/server/form/FormParamResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/server/form/FormParamResource.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/server/form/FormParamResource.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/server/form/FormParamResource.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jaxrs.tests.params.server.form;
+
+import javax.ws.rs.FormParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.MultivaluedMap;
+
+@Path("params/form")
+public class FormParamResource {
+
+ public FormParamResource() {
+
+ }
+
+ @POST
+ @Path("withOnlyEntity")
+ public String getRes(MultivaluedMap<String, String> entity) {
+ return entity.toString();
+ }
+
+ @POST
+ @Path("withOneKeyAndEntity")
+ public String getRes(@FormParam("firstkey") String firstKey, MultivaluedMap<String, String> entity) {
+ return "firstkey=" + firstKey + "&entity=" + entity.toString();
+ }
+
+ @POST
+ @Path("withStringEntity")
+ public String getStrEntity(String entity) {
+ return "str:" + entity;
+ }
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/server/header/HeaderParamDefaultResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/server/header/HeaderParamDefaultResource.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/server/header/HeaderParamDefaultResource.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/server/header/HeaderParamDefaultResource.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,101 @@
+/*
+ * 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 jaxrs.tests.params.server.header;
+
+import javax.ws.rs.DELETE;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+@Path("/params/headerparam/default")
+public class HeaderParamDefaultResource {
+
+ private String customConstructorHeaderParam;
+
+ private String customPropertyHeaderParam;
+
+ private String agent;
+
+ @DefaultValue("english")
+ @HeaderParam("Accept-Language")
+ private String acceptLanguageHeaderParam;
+
+ public HeaderParamDefaultResource(@DefaultValue("MyCustomConstructorHeader") @HeaderParam("CustomConstructorHeader") String cstrHeaderParam) {
+ this.customConstructorHeaderParam = cstrHeaderParam;
+ }
+
+ public Response info(String customMethodHeader) {
+ Response r = Response.status(Status.OK).header(
+ "RespCustomConstructorHeader", customConstructorHeaderParam)
+ .header("RespAccept-Language", acceptLanguageHeaderParam)
+ .header("RespCustomMethodHeader", customMethodHeader).header(
+ "RespUserAgent", agent).header(
+ "RespCustomPropertyHeader", customPropertyHeaderParam)
+ .build();
+ return r;
+ }
+
+ @DefaultValue("MyAgent")
+ @HeaderParam("User-Agent")
+ public void setUserAgent(String aUserAgent) {
+ agent = aUserAgent;
+ }
+
+ public String getUserAgent() {
+ return agent;
+ }
+
+ @DefaultValue("MyCustomPropertyHeader")
+ @HeaderParam("CustomPropertyHeader")
+ public void setCustomPropertyHeader(String customProperty) {
+ customPropertyHeaderParam = customProperty;
+ }
+
+ public String getCustomPropertyHeader() {
+ return customPropertyHeaderParam;
+ }
+
+ @GET
+ public Response getHeaderParam(@DefaultValue("MyCustomMethodHeader") @HeaderParam("CustomMethodHeader") String c) {
+ return info(c);
+ }
+
+ @POST
+ public Response postHeaderParam(@DefaultValue("MyCustomMethodHeader") @HeaderParam("CustomMethodHeader") String c) {
+ return info(c);
+ }
+
+ @PUT
+ public Response putHeaderParam(@DefaultValue("MyCustomMethodHeader") @HeaderParam("CustomMethodHeader") String c) {
+ return info(c);
+ }
+
+ @DELETE
+ public Response deleteHeaderParam(@DefaultValue("MyCustomMethodHeader") @HeaderParam("CustomMethodHeader") String c) {
+ return info(c);
+ }
+
+ /* FIXME: Check if ResponseBuilder header values can be null */
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/server/header/HeaderParamExceptionResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/server/header/HeaderParamExceptionResource.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/server/header/HeaderParamExceptionResource.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/server/header/HeaderParamExceptionResource.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,166 @@
+/*
+ * 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 jaxrs.tests.params.server.header;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.Path;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+
+@Path("/params/headerparam/exception")
+public class HeaderParamExceptionResource {
+
+ public HeaderParamExceptionResource() {
+ /* do nothing */
+ }
+
+ @HeaderParam("CustomStringConstructorFieldHeader")
+ private HeaderStringConstructor customStringConstructorFieldHeader;
+
+ @HeaderParam("CustomValueOfFieldHeader")
+ private HeaderValueOf customValueOfFieldHeader;
+
+ private HeaderValueOf customPropertyValueOfHeader;
+
+ private HeaderStringConstructor customPropertyStringConstructorHeader;
+
+ @HeaderParam("CustomValueOfPropertyHeader")
+ public void setCustomValueOfPropertyHeader(HeaderValueOf param) {
+ customPropertyValueOfHeader = param;
+ }
+
+ @HeaderParam("CustomStringConstructorPropertyHeader")
+ public void setCustomValueOfPropertyHeader(HeaderStringConstructor param) {
+ customPropertyStringConstructorHeader = param;
+ }
+
+ @GET
+ @Path("primitive")
+ public Response getHeaderParam(@HeaderParam("CustomNumHeader") int customNumHeader) {
+ return Response.ok().header("RespCustomNumHeader", customNumHeader)
+ .build();
+ }
+
+ @GET
+ @Path("constructor")
+ public Response getStringConstructorHeaderParam(@HeaderParam("CustomStringHeader") HeaderStringConstructor customStringHeader) {
+ return Response.ok().header("RespCustomStringHeader",
+ customStringHeader.getHeader()).build();
+ }
+
+ public static class HeaderValueOf {
+ String header;
+
+ private HeaderValueOf(String aHeader, int num) {
+ header = aHeader;
+ }
+
+ public String getHeader() {
+ return header;
+ }
+
+ public static HeaderValueOf valueOf(String v) throws Exception {
+ if ("throwWeb".equals(v)) {
+ throw new WebApplicationException(Response.status(498).entity(
+ "HeaderValueOfWebAppEx").build());
+ } else if ("throwNull".equals(v)) {
+ throw new NullPointerException("HeaderValueOf NPE");
+ } else if ("throwEx".equals(v)) {
+ throw new Exception("HeaderValueOf Exception");
+ }
+ return new HeaderValueOf(v, 100);
+ }
+ }
+
+ @GET
+ @Path("valueof")
+ public Response getValueOfHeaderParam(@HeaderParam("CustomValueOfHeader") HeaderValueOf customValueOfHeader) {
+ return Response.ok().header("RespCustomValueOfHeader",
+ customValueOfHeader.getHeader()).build();
+ }
+
+ @GET
+ @Path("listvalueof")
+ public Response getValueOfHeaderParam(@HeaderParam("CustomListValueOfHeader") List<HeaderValueOf> customValueOfHeader) {
+ if (customValueOfHeader.size() != 1) {
+ throw new IllegalArgumentException();
+ }
+ return Response.ok().header("RespCustomListValueOfHeader",
+ customValueOfHeader.get(0).getHeader()).build();
+ }
+
+ @GET
+ @Path("setvalueof")
+ public Response getValueOfHeaderParam(@HeaderParam("CustomSetValueOfHeader") Set<HeaderValueOf> customValueOfHeader) {
+ if (customValueOfHeader.size() != 1) {
+ throw new IllegalArgumentException();
+ }
+ return Response.ok().header(
+ "RespCustomSetValueOfHeader",
+ new ArrayList<HeaderValueOf>(customValueOfHeader).get(0)
+ .getHeader()).build();
+ }
+
+ @GET
+ @Path("sortedsetvalueof")
+ public Response getValueOfHeaderParam(@HeaderParam("CustomSortedSetValueOfHeader") SortedSet<HeaderValueOf> customValueOfHeader) {
+ if (customValueOfHeader.size() != 1) {
+ throw new IllegalArgumentException();
+ }
+ return Response.ok().header("RespCustomSortedSetValueOfHeader",
+ customValueOfHeader.first().getHeader()).build();
+ }
+
+ @GET
+ @Path("fieldstrcstr")
+ public Response getFieldStringConstructorHeaderParam() {
+ return Response.ok().header("RespCustomStringConstructorFieldHeader",
+ customStringConstructorFieldHeader.getHeader()).build();
+ }
+
+ @GET
+ @Path("fieldvalueof")
+ public Response getFieldValueOfHeaderParam() {
+ return Response.ok().header("RespCustomValueOfFieldHeader",
+ customValueOfFieldHeader.getHeader()).build();
+ }
+
+ @GET
+ @Path("propertystrcstr")
+ public Response getPropertyStringConstructorHeaderParam() {
+ return Response.ok().header(
+ "RespCustomStringConstructorPropertyHeader",
+ customPropertyStringConstructorHeader.getHeader()).build();
+ }
+
+ @GET
+ @Path("propertyvalueof")
+ public Response getPropertyValueOfHeaderParam() {
+ return Response.ok().header("RespCustomValueOfPropertyHeader",
+ customPropertyValueOfHeader.getHeader()).build();
+ }
+
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/server/header/HeaderStringConstructor.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/server/header/HeaderStringConstructor.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/server/header/HeaderStringConstructor.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/server/header/HeaderStringConstructor.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jaxrs.tests.params.server.header;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+
+public class HeaderStringConstructor {
+ String header;
+
+ public HeaderStringConstructor(String aHeader) throws Exception {
+ if ("throwWeb".equals(aHeader)) {
+ throw new WebApplicationException(Response.status(499).entity(
+ "HeaderStringConstructorWebAppEx").build());
+ } else if ("throwNull".equals(aHeader)) {
+ throw new NullPointerException("HeaderStringConstructor NPE");
+ } else if ("throwEx".equals(aHeader)) {
+ throw new Exception("HeaderStringConstructor Exception");
+ }
+ header = aHeader;
+ }
+
+ public String getHeader() {
+ return header;
+ }
+}
\ No newline at end of file
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/server/query/ParamStringConstructor.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/server/query/ParamStringConstructor.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/server/query/ParamStringConstructor.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/server/query/ParamStringConstructor.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jaxrs.tests.params.server.query;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+
+public class ParamStringConstructor {
+
+ String value;
+
+ public ParamStringConstructor(String aValue) throws Exception {
+ if ("throwWeb".equals(aValue)) {
+ throw new WebApplicationException(Response.status(499).entity(
+ "ParamStringConstructor").build());
+ } else if ("throwNull".equals(aValue)) {
+ throw new NullPointerException("ParamStringConstructor NPE");
+ } else if ("throwEx".equals(aValue)) {
+ throw new Exception("ParamStringConstructor Exception");
+ }
+ value = aValue;
+ }
+
+ public String getParamValue() {
+ return value;
+ }
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/server/query/QueryParamsExceptionResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/server/query/QueryParamsExceptionResource.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/server/query/QueryParamsExceptionResource.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/server/query/QueryParamsExceptionResource.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,163 @@
+/*
+ * 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 jaxrs.tests.params.server.query;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+
+@Path("/params/queryparam/exception")
+public class QueryParamsExceptionResource {
+
+ public QueryParamsExceptionResource() {
+ /* do nothing */
+ }
+
+ @QueryParam("CustomStringConstructorFieldQuery")
+ private ParamStringConstructor customStringConstructorFieldQuery;
+
+ @QueryParam("CustomValueOfFieldQuery")
+ private QueryValueOf customValueOfFieldQuery;
+
+ private ParamStringConstructor customPropertyStringConstructorQuery;
+
+ private QueryValueOf customPropertyValueOfQuery;
+
+ @QueryParam("CustomStringConstructorPropertyHeader")
+ public void setCustomValueOfPropertyHeader(ParamStringConstructor param) {
+ customPropertyStringConstructorQuery = param;
+ }
+
+ @QueryParam("CustomValueOfPropertyHeader")
+ public void setCustomValueOfPropertyHeader(QueryValueOf param) {
+ customPropertyValueOfQuery = param;
+ }
+
+ @GET
+ @Path("primitive")
+ public Response getHeaderParam(@QueryParam("CustomNumQuery") int customNumHeader) {
+ return Response.ok().header("RespCustomNumQuery", customNumHeader)
+ .build();
+ }
+
+ // @GET
+ // @Path("constructor")
+ // public Response getStringConstructorHeaderParam(
+ // @HeaderParam("CustomStringHeader") HeaderStringConstructor customStringHeader) {
+ // return Response.ok().header("RespCustomStringHeader", customStringHeader.getHeader())
+ // .build();
+ // }
+
+ public static class QueryValueOf {
+ String header;
+
+ private QueryValueOf(String aHeader, int num) {
+ header = aHeader;
+ }
+
+ public String getParamValue() {
+ return header;
+ }
+
+ public static QueryValueOf valueOf(String v) throws Exception {
+ if ("throwWeb".equals(v)) {
+ throw new WebApplicationException(Response.status(498).entity(
+ "ParamValueOfWebAppEx").build());
+ } else if ("throwNull".equals(v)) {
+ throw new NullPointerException("ParamValueOf NPE");
+ } else if ("throwEx".equals(v)) {
+ throw new Exception("ParamValueOf Exception");
+ }
+ return new QueryValueOf(v, 100);
+ }
+ }
+
+ // @GET
+ // @Path("valueof")
+ // public Response getValueOfHeaderParam(
+ // @QueryParam("CustomValueOfQuery") QueryValueOf customValueOfQuery) {
+ // return Response.ok().header("RespCustomValueOfQuery", customValueOfQuery.getParamValue())
+ // .build();
+ // }
+ //
+ // @GET
+ // @Path("listvalueof")
+ // public Response getValueOfHeaderParam(
+ // @HeaderParam("CustomListValueOfHeader") List<QueryValueOf> customValueOfHeader) {
+ // if (customValueOfHeader.size() != 1) {
+ // throw new IllegalArgumentException();
+ // }
+ // return Response.ok().header("RespCustomListValueOfHeader",
+ // customValueOfHeader.get(0).getHeader()).build();
+ // }
+ //
+ // @GET
+ // @Path("setvalueof")
+ // public Response getValueOfHeaderParam(
+ // @HeaderParam("CustomSetValueOfHeader") Set<QueryValueOf> customValueOfHeader) {
+ // if (customValueOfHeader.size() != 1) {
+ // throw new IllegalArgumentException();
+ // }
+ // return Response.ok().header("RespCustomSetValueOfHeader",
+ // new ArrayList<QueryValueOf>(customValueOfHeader).get(0).getHeader()).build();
+ // }
+ //
+ // @GET
+ // @Path("sortedsetvalueof")
+ // public Response getValueOfHeaderParam(
+ // @HeaderParam("CustomSortedSetValueOfHeader") SortedSet<QueryValueOf> customValueOfHeader) {
+ // if (customValueOfHeader.size() != 1) {
+ // throw new IllegalArgumentException();
+ // }
+ // return Response.ok().header("RespCustomSortedSetValueOfHeader",
+ // customValueOfHeader.first().getHeader()).build();
+ // }
+ //
+ @GET
+ @Path("fieldstrcstr")
+ public Response getFieldStringConstructorHeaderParam() {
+ return Response.ok().entity(
+ customStringConstructorFieldQuery.getParamValue()).build();
+ }
+
+ @GET
+ @Path("fieldvalueof")
+ public Response getFieldValueOfHeaderParam() {
+ return Response.ok().header("RespCustomValueOfFieldHeader",
+ customValueOfFieldQuery.getParamValue()).build();
+ }
+
+ @GET
+ @Path("propertystrcstr")
+ public Response getPropertyStringConstructorHeaderParam() {
+ return Response.ok().header("RespCustomStringConstructorPropertyQuery",
+ customPropertyStringConstructorQuery.getParamValue()).build();
+ }
+
+ @GET
+ @Path("propertyvalueof")
+ public Response getPropertyValueOfHeaderParam() {
+ return Response.ok().header("RespCustomValueOfPropertyQuery",
+ customPropertyValueOfQuery.getParamValue()).build();
+ }
+
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/test/CookieParamTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/test/CookieParamTest.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/test/CookieParamTest.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/test/CookieParamTest.java Tue Jun 23 05:37:57 2009
@@ -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 jaxrs.tests.params.test;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+import junit.framework.Test;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.URI;
+import org.apache.commons.httpclient.URIException;
+import org.apache.commons.httpclient.cookie.CookiePolicy;
+import org.apache.commons.httpclient.methods.PutMethod;
+
+import framework.defaults.test.DefaultURIInfo;
+import framework.defaults.test.FVTTestCase;
+
+/**
+ * Tests the use of cookie parameter.
+ */
+public class CookieParamTest extends FVTTestCase {
+
+ protected HttpClient httpclient = new HttpClient();
+
+ final private static String BASE_URI = DefaultURIInfo
+ .getClassDefaultBaseURI(CookieParamTest.class)
+ + "/cookiemonster";
+
+ public static Test suite() {
+ return FVTTestCase.getTestSuite(CookieParamTest.class,
+ "jaxrs.tests.params.server.Application");
+ }
+
+ /**
+ * Tests that a cookie parameter is retrieved.
+ */
+ public void testCookieParam() {
+
+ try {
+ PutMethod httpMethod = new PutMethod();
+ httpMethod.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
+ httpMethod.setURI(new URI(BASE_URI, false));
+ System.out.println("Request headers:");
+ System.out.println(Arrays.asList(httpMethod.getRequestHeaders()));
+ httpclient = new HttpClient();
+
+ try {
+ int result = httpclient.executeMethod(httpMethod);
+ System.out.println("Response status code: " + result);
+ System.out.println("Response body: ");
+ String responseBody = httpMethod.getResponseBodyAsString();
+ System.out.println(responseBody);
+ System.out.println("Response headers:");
+ System.out.println(Arrays.asList(httpMethod
+ .getResponseHeaders()));
+ assertEquals(200, result);
+ assertEquals("swiped:" + 0, responseBody);
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ fail(ioe.getMessage());
+ } finally {
+ httpMethod.releaseConnection();
+ }
+
+ System.out.println("---");
+
+ httpMethod = new PutMethod();
+ httpMethod.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
+ httpMethod.setURI(new URI(BASE_URI, false));
+ httpMethod.setRequestHeader("Cookie", "jar=1");
+ System.out.println("Request headers:");
+ System.out.println(Arrays.asList(httpMethod.getRequestHeaders()));
+ httpclient = new HttpClient();
+ try {
+ int result = httpclient.executeMethod(httpMethod);
+ System.out.println("Response status code: " + result);
+ System.out.println("Response body: ");
+ String responseBody = httpMethod.getResponseBodyAsString();
+ System.out.println(responseBody);
+ System.out.println("Response headers:");
+ System.out.println(Arrays.asList(httpMethod
+ .getResponseHeaders()));
+ assertEquals(200, result);
+ assertEquals("swiped:" + 1, responseBody);
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ fail(ioe.getMessage());
+ } finally {
+ httpMethod.releaseConnection();
+ }
+ } catch (URIException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/test/DefaultValueParamTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/test/DefaultValueParamTest.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/test/DefaultValueParamTest.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/test/DefaultValueParamTest.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,117 @@
+/*
+ * 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 jaxrs.tests.params.test;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+import junit.framework.Test;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.URI;
+import org.apache.commons.httpclient.URIException;
+import org.apache.commons.httpclient.methods.GetMethod;
+
+import framework.defaults.test.DefaultURIInfo;
+import framework.defaults.test.FVTTestCase;
+
+/**
+ * Tests <code>@DefaultValue</code> annotation.
+ */
+public class DefaultValueParamTest extends FVTTestCase {
+
+ protected HttpClient httpclient = new HttpClient();
+
+ final private static String BASE_URI = DefaultURIInfo
+ .getClassDefaultBaseURI(DefaultValueParamTest.class)
+ + "/defaultvalue";
+
+ public static Test suite() {
+ return FVTTestCase.getTestSuite(
+ DefaultValueParamTest.class,
+ "jaxrs.tests.params.server.Application");
+ }
+
+ /**
+ * Test that if no parameters are passed, the default values are used.
+ */
+ public void testDefaultValue() {
+
+ try {
+ GetMethod httpMethod = new GetMethod();
+ httpMethod.setURI(new URI(BASE_URI, false));
+ System.out.println(Arrays.asList(httpMethod.getRequestHeaders()));
+ httpclient = new HttpClient();
+
+ try {
+ int result = httpclient.executeMethod(httpMethod);
+ System.out.println("Response status code: " + result);
+ System.out.println("Response body: ");
+ String responseBody = httpMethod.getResponseBodyAsString();
+ System.out.println(responseBody);
+ assertEquals(200, result);
+ assertEquals("getRow:" + "offset=" + "0" + ";version=" + "1.0"
+ + ";limit=" + "100" + ";sort=" + "normal", responseBody);
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ fail(ioe.getMessage());
+ } finally {
+ httpMethod.releaseConnection();
+ }
+ } catch (URIException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * Test using some default values.
+ */
+ public void testUseSomeDefaultValue() {
+
+ try {
+ GetMethod httpMethod = new GetMethod();
+ httpMethod.setURI(new URI(BASE_URI + "?sort=backward&offset=314",
+ false));
+ System.out.println(Arrays.asList(httpMethod.getRequestHeaders()));
+ httpclient = new HttpClient();
+
+ try {
+ int result = httpclient.executeMethod(httpMethod);
+ System.out.println("Response status code: " + result);
+ System.out.println("Response body: ");
+ String responseBody = httpMethod.getResponseBodyAsString();
+ System.out.println(responseBody);
+ assertEquals(200, result);
+ assertEquals("getRow:" + "offset=" + "314" + ";version="
+ + "1.0" + ";limit=" + "100" + ";sort=" + "backward",
+ responseBody);
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ fail(ioe.getMessage());
+ } finally {
+ httpMethod.releaseConnection();
+ }
+ } catch (URIException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/test/EncodingParamTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/test/EncodingParamTest.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/test/EncodingParamTest.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/test/EncodingParamTest.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,604 @@
+/*
+ * 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 jaxrs.tests.params.test;
+
+import java.io.IOException;
+
+import junit.framework.Test;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.NameValuePair;
+import org.apache.commons.httpclient.URI;
+import org.apache.commons.httpclient.URIException;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+
+import framework.defaults.test.DefaultURIInfo;
+import framework.defaults.test.FVTTestCase;
+
+/**
+ * Tests that <code>@Encoded</code> annotated method and parameter level works.
+ */
+public class EncodingParamTest extends FVTTestCase {
+
+ protected HttpClient httpclient = new HttpClient();
+
+ final private static String BASE_URI_DECODE = DefaultURIInfo
+ .getClassDefaultBaseURI(EncodingParamTest.class)
+ + "/decodedparams";
+
+ final private static String BASE_URI_ENCODE = DefaultURIInfo
+ .getClassDefaultBaseURI(EncodingParamTest.class)
+ + "/encodingparam";
+
+ public static Test suite() {
+ return FVTTestCase.getTestSuite(EncodingParamTest.class,
+ "jaxrs.tests.params.server.Application");
+ }
+
+ // /**
+ // * Test that if regular parameters are passed, the parameters are correct.
+ // */
+ // public void testRegularParametersEncodedMethod() {
+ // try {
+ // GetMethod httpMethod = new GetMethod();
+ // httpMethod.setURI(new URI(BASE_URI_ENCODE
+ // + "/city/Austin/;appversion=1.1?q=Pizza", false));
+ // httpclient = new HttpClient();
+ //
+ // try {
+ // int result = httpclient.executeMethod(httpMethod);
+ // System.out.println("Response status code: " + result);
+ // System.out.println("Response body: ");
+ // String responseBody = httpMethod.getResponseBodyAsString();
+ // System.out.println(responseBody);
+ // assertEquals(200, result);
+ // assertEquals("getShopInCity:q=Pizza;city=Austin;appversion=1.1",
+ // responseBody);
+ // } catch (IOException ioe) {
+ // ioe.printStackTrace();
+ // fail(ioe.getMessage());
+ // } finally {
+ // httpMethod.releaseConnection();
+ // }
+ // } catch (URIException e) {
+ // e.printStackTrace();
+ // fail(e.getMessage());
+ // }
+ // }
+
+ // /**
+ // * Tests that if
+ // */
+ // public void testEncodedMethod() {
+ // try {
+ // GetMethod httpMethod = new GetMethod();
+ // httpMethod.setURI(new URI(BASE_URI_ENCODE
+ // + "/city/Earth, TX/;appversion=1.1+?q=Dave %26 Buster's",
+ // false));
+ // httpclient = new HttpClient();
+ //
+ // try {
+ // int result = httpclient.executeMethod(httpMethod);
+ // System.out.println("Response status code: " + result);
+ // System.out.println("Response body: ");
+ // String responseBody = httpMethod.getResponseBodyAsString();
+ // System.out.println(responseBody);
+ // assertEquals(200, result);
+ // assertEquals(
+ // "getShopInCity:q=Dave%20%26%20Buster's;city=Earth%2C%%20%TX%20D.C.;appversion=1.1"
+ // ,
+ // responseBody);
+ // } catch (IOException ioe) {
+ // ioe.printStackTrace();
+ // fail(ioe.getMessage());
+ // } finally {
+ // httpMethod.releaseConnection();
+ // }
+ // } catch (URIException e) {
+ // e.printStackTrace();
+ // fail(e.getMessage());
+ // }
+ // }
+ //
+ // public void testLocationDecodedMethod() {
+ // try {
+ // GetMethod httpMethod = new GetMethod();
+ // httpMethod.setURI(new URI(BASE_URI_ENCODE
+ // +
+ // "/loc/Earth%2C%20TX/;appversion=1.1%2B?q=Dave%20%26%20Buster's"
+ // ,
+ // true));
+ // httpclient = new HttpClient();
+ //
+ // try {
+ // int result = httpclient.executeMethod(httpMethod);
+ // System.out.println("Response status code: " + result);
+ // System.out.println("Response body: ");
+ // String responseBody = httpMethod.getResponseBodyAsString();
+ // System.out.println(responseBody);
+ // assertEquals(200, result);
+ // assertEquals(
+ // "getShopInLocation:q=Dave%20%26%20Buster's;location=Earth%2C%20TX;appversion=1.1%2B"
+ // ,
+ // responseBody);
+ // } catch (IOException ioe) {
+ // ioe.printStackTrace();
+ // fail(ioe.getMessage());
+ // } finally {
+ // httpMethod.releaseConnection();
+ // }
+ // } catch (URIException e) {
+ // e.printStackTrace();
+ // fail(e.getMessage());
+ // }
+ // }
+ //
+ // public void testPathParamEncoded() {
+ // try {
+ // GetMethod httpMethod = new GetMethod();
+ // httpMethod.setURI(new URI(BASE_URI_ENCODE
+ // + "/country/United%20States/;appversion=1.1%2B", true));
+ // httpclient = new HttpClient();
+ //
+ // try {
+ // int result = httpclient.executeMethod(httpMethod);
+ // System.out.println("Response status code: " + result);
+ // System.out.println("Response body: ");
+ // String responseBody = httpMethod.getResponseBodyAsString();
+ // System.out.println(responseBody);
+ // assertEquals(200, result);
+ //assertEquals("getShopInCountry:location=United%20States;appversion=1.1%2B"
+ // ,
+ // responseBody);
+ // } catch (IOException ioe) {
+ // ioe.printStackTrace();
+ // fail(ioe.getMessage());
+ // } finally {
+ // httpMethod.releaseConnection();
+ // }
+ // } catch (URIException e) {
+ // e.printStackTrace();
+ // fail(e.getMessage());
+ // }
+ // }
+ //
+ // public void testDecodedMethod() {
+ // try {
+ // GetMethod httpMethod = new GetMethod();
+ // httpMethod
+ // .setURI(new URI(BASE_URI_DECODE
+ // +
+ // "/city/Washington D.C./;appversion=1 1?q=Austin's City Pizza"
+ // ,
+ // false));
+ // httpclient = new HttpClient();
+ //
+ // try {
+ // int result = httpclient.executeMethod(httpMethod);
+ // System.out.println("Response status code: " + result);
+ // System.out.println("Response body: ");
+ // String responseBody = httpMethod.getResponseBodyAsString();
+ // System.out.println(responseBody);
+ // assertEquals(200, result);
+ // assertEquals("getRow:" + "offset=" + "0" + ";version=" + "1.0" +
+ // ";limit=" + "100"
+ // + ";sort=" + "normal", responseBody);
+ // } catch (IOException ioe) {
+ // ioe.printStackTrace();
+ // fail(ioe.getMessage());
+ // } finally {
+ // httpMethod.releaseConnection();
+ // }
+ // } catch (URIException e) {
+ // e.printStackTrace();
+ // fail(e.getMessage());
+ // }
+ // }
+
+ public void testSingleDecodedQueryParam() {
+ try {
+ GetMethod httpMethod = new GetMethod();
+ // httpMethod.setURI(new URI(BASE_URI_DECODE
+ // +
+ // "/city;appversion=1.1?location=! * ' ( ) ; : @ & = + $ , / ? % # [ ]"
+ // , false));
+
+ httpMethod
+ .setURI(new URI(
+ BASE_URI_DECODE
+ + "/city;appversion=1.1?location=%21%20%2A%20%27%20%28%20%29%20%3B%20%3A%20%40%20%26%20%3D%20%2B%20%24%20%2C%20%2F%20%3F%20%25%20%23%20%5B%20%5D",
+ true));
+ httpclient = new HttpClient();
+
+ try {
+ int result = httpclient.executeMethod(httpMethod);
+ System.out.println("Response status code: " + result);
+ System.out.println("Response body: ");
+ String responseBody = httpMethod.getResponseBodyAsString();
+ System.out.println(responseBody);
+ assertEquals(200, result);
+ assertEquals(
+ "getShopInCityDecoded:location=! * ' ( ) ; : @ & = + $ , / ? % # [ ];appversion=1.1",
+ responseBody);
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ fail(ioe.getMessage());
+ } finally {
+ httpMethod.releaseConnection();
+ }
+ } catch (URIException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ public void testSingleEncodedQueryParam() {
+ try {
+ GetMethod httpMethod = new GetMethod();
+ httpMethod.setURI(new URI(BASE_URI_ENCODE
+ + "/city;appversion=1.1%2B?location=Austin%2B%20Texas",
+ true));
+ httpclient = new HttpClient();
+
+ try {
+ int result = httpclient.executeMethod(httpMethod);
+ System.out.println("Response status code: " + result);
+ System.out.println("Response body: ");
+ String responseBody = httpMethod.getResponseBodyAsString();
+ System.out.println(responseBody);
+ assertEquals(200, result);
+ assertEquals(
+ "getShopInCity:location=Austin%2B%20Texas;appversion=1.1%2B",
+ responseBody);
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ fail(ioe.getMessage());
+ } finally {
+ httpMethod.releaseConnection();
+ }
+ } catch (URIException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ public void testSingleEncodedQueryParamMethod() {
+ try {
+ GetMethod httpMethod = new GetMethod();
+ httpMethod
+ .setURI(new URI(
+ BASE_URI_ENCODE
+ + "/method/city;appversion=1.1%2B?location=Austin%2B%20Texas",
+ true));
+ httpclient = new HttpClient();
+
+ try {
+ int result = httpclient.executeMethod(httpMethod);
+ System.out.println("Response status code: " + result);
+ System.out.println("Response body: ");
+ String responseBody = httpMethod.getResponseBodyAsString();
+ System.out.println(responseBody);
+ assertEquals(200, result);
+ assertEquals(
+ "getShopInCityMethod:location=Austin%2B%20Texas;appversion=1.1%2B",
+ responseBody);
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ fail(ioe.getMessage());
+ } finally {
+ httpMethod.releaseConnection();
+ }
+ } catch (URIException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ public void testSingleDecodedPathParm() {
+ try {
+ GetMethod httpMethod = new GetMethod();
+ httpMethod
+ .setURI(new URI(
+ BASE_URI_DECODE
+ + "/country/United%20States%20of%20America;appversion=1.1%2C2",
+ true));
+ httpclient = new HttpClient();
+
+ try {
+ int result = httpclient.executeMethod(httpMethod);
+ System.out.println("Response status code: " + result);
+ System.out.println("Response body: ");
+ String responseBody = httpMethod.getResponseBodyAsString();
+ System.out.println(responseBody);
+ assertEquals(200, result);
+ assertEquals(
+ "getShopInCountryDecoded:location=United States of America;appversion=1.1,2;appversion=1.1,2",
+ responseBody);
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ fail(ioe.getMessage());
+ } finally {
+ httpMethod.releaseConnection();
+ }
+ } catch (URIException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ public void testSingleEncodedPathParam() {
+ try {
+ GetMethod httpMethod = new GetMethod();
+ httpMethod
+ .setURI(new URI(
+ BASE_URI_ENCODE
+ + "/country/United%20States%20of%20America;appversion=1.1%2B",
+ true));
+ httpclient = new HttpClient();
+
+ try {
+ int result = httpclient.executeMethod(httpMethod);
+ System.out.println("Response status code: " + result);
+ System.out.println("Response body: ");
+ String responseBody = httpMethod.getResponseBodyAsString();
+ System.out.println(responseBody);
+ assertEquals(200, result);
+ assertEquals(
+ "getShopInCountry:location=United%20States%20of%20America;appversion=1.1%2B;appversion=1.1%2B",
+ responseBody);
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ fail(ioe.getMessage());
+ } finally {
+ httpMethod.releaseConnection();
+ }
+ } catch (URIException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ public void testSingleEncodedPathParamMethod() {
+ try {
+ GetMethod httpMethod = new GetMethod();
+ httpMethod
+ .setURI(new URI(
+ BASE_URI_ENCODE
+ + "/method/country/United%20States%20of%20America;appversion=1.1%2B",
+ true));
+ httpclient = new HttpClient();
+
+ try {
+ int result = httpclient.executeMethod(httpMethod);
+ System.out.println("Response status code: " + result);
+ System.out.println("Response body: ");
+ String responseBody = httpMethod.getResponseBodyAsString();
+ System.out.println(responseBody);
+ assertEquals(200, result);
+ assertEquals(
+ "getShopInCountryMethod:location=United%20States%20of%20America;appversion=1.1%2B;appversion=1.1%2B",
+ responseBody);
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ fail(ioe.getMessage());
+ } finally {
+ httpMethod.releaseConnection();
+ }
+ } catch (URIException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ public void testSingleDecodedMatrixParam() {
+ try {
+ GetMethod httpMethod = new GetMethod();
+ httpMethod
+ .setURI(new URI(
+ BASE_URI_DECODE
+ + "/street;location=Burnet%20Road;appversion=1.1%2B",
+ true));
+ httpclient = new HttpClient();
+
+ try {
+ int result = httpclient.executeMethod(httpMethod);
+ System.out.println("Response status code: " + result);
+ System.out.println("Response body: ");
+ String responseBody = httpMethod.getResponseBodyAsString();
+ System.out.println(responseBody);
+ assertEquals(200, result);
+ assertEquals(
+ "getShopOnStreetDecoded:location=Burnet Road;appversion=1.1+",
+ responseBody);
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ fail(ioe.getMessage());
+ } finally {
+ httpMethod.releaseConnection();
+ }
+ } catch (URIException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ public void testSingleEncodedMatrixParam() {
+ try {
+ GetMethod httpMethod = new GetMethod();
+ httpMethod
+ .setURI(new URI(
+ BASE_URI_ENCODE
+ + "/street;location=Burnet%20Road;appversion=1.1%2B",
+ true));
+ httpclient = new HttpClient();
+
+ try {
+ int result = httpclient.executeMethod(httpMethod);
+ System.out.println("Response status code: " + result);
+ System.out.println("Response body: ");
+ String responseBody = httpMethod.getResponseBodyAsString();
+ System.out.println(responseBody);
+ assertEquals(200, result);
+ assertEquals(
+ "getShopOnStreet:location=Burnet%20Road;appversion=1.1%2B",
+ responseBody);
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ fail(ioe.getMessage());
+ } finally {
+ httpMethod.releaseConnection();
+ }
+ } catch (URIException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ public void testSingleEncodedMatrixParamMethod() {
+ try {
+ GetMethod httpMethod = new GetMethod();
+ httpMethod
+ .setURI(new URI(
+ BASE_URI_ENCODE
+ + "/method/street;location=Burnet%20Road;appversion=1.1%2B",
+ true));
+ httpclient = new HttpClient();
+
+ try {
+ int result = httpclient.executeMethod(httpMethod);
+ System.out.println("Response status code: " + result);
+ System.out.println("Response body: ");
+ String responseBody = httpMethod.getResponseBodyAsString();
+ System.out.println(responseBody);
+ assertEquals(200, result);
+ assertEquals(
+ "getShopOnStreetMethod:location=Burnet%20Road;appversion=1.1%2B",
+ responseBody);
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ fail(ioe.getMessage());
+ } finally {
+ httpMethod.releaseConnection();
+ }
+ } catch (URIException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ public void testSingleDecodedFormParam() {
+ try {
+ PostMethod httpMethod = new PostMethod();
+ httpMethod.setURI(new URI(BASE_URI_DECODE + "/region;appversion=",
+ true));
+ // httpMethod.setParameter("location", "The%20Southwest");
+ httpMethod
+ .setRequestBody(new NameValuePair[] { new NameValuePair(
+ "location",
+ "%21%20%2A%20%27%20%28%20%29%20%3B%20%3A%20%40%20%26%20%3D%20%2B%20%24%20%2C%20%2F%20%3F%20%25%20%23%20%5B%20%5D") });
+ httpclient = new HttpClient();
+
+ try {
+ int result = httpclient.executeMethod(httpMethod);
+ System.out.println("Response status code: " + result);
+ System.out.println("Response body: ");
+ String responseBody = httpMethod.getResponseBodyAsString();
+ System.out.println(responseBody);
+ assertEquals(200, result);
+ assertEquals(
+ "getShopInRegionDecoded:location=! * ' ( ) ; : @ & = + $ , / ? % # [ ];appversion=",
+ responseBody);
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ fail(ioe.getMessage());
+ } finally {
+ httpMethod.releaseConnection();
+ }
+ } catch (URIException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ public void testSingleEncodedFormParam() {
+ try {
+ PostMethod httpMethod = new PostMethod();
+ httpMethod.setURI(new URI(BASE_URI_ENCODE
+ + "/region;appversion=1.1%2B", true));
+ // httpMethod.setParameter("location", "The%20Southwest");
+ httpMethod.setRequestBody(new NameValuePair[] { new NameValuePair(
+ "location", "The%20Southwest") });
+ httpclient = new HttpClient();
+
+ try {
+ int result = httpclient.executeMethod(httpMethod);
+ System.out.println("Response status code: " + result);
+ System.out.println("Response body: ");
+ String responseBody = httpMethod.getResponseBodyAsString();
+ System.out.println(responseBody);
+ assertEquals(200, result);
+ assertEquals(
+ "getShopInRegion:location=The%20Southwest;appversion=1.1%2B",
+ responseBody);
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ fail(ioe.getMessage());
+ } finally {
+ httpMethod.releaseConnection();
+ }
+ } catch (URIException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ public void testSingleEncodedFormParamMethod() {
+ try {
+ PostMethod httpMethod = new PostMethod();
+ httpMethod.setURI(new URI(BASE_URI_ENCODE
+ + "/method/region;appversion=1.1%2B", true));
+ // httpMethod.setParameter("location", "The%20Southwest");
+ httpMethod.setRequestBody(new NameValuePair[] { new NameValuePair(
+ "location", "The%20Southwest") });
+ httpclient = new HttpClient();
+
+ try {
+ int result = httpclient.executeMethod(httpMethod);
+ System.out.println("Response status code: " + result);
+ System.out.println("Response body: ");
+ String responseBody = httpMethod.getResponseBodyAsString();
+ System.out.println(responseBody);
+ assertEquals(200, result);
+ assertEquals(
+ "getShopInRegionMethod:location=The%20Southwest;appversion=1.1%2B",
+ responseBody);
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ fail(ioe.getMessage());
+ } finally {
+ httpMethod.releaseConnection();
+ }
+ } catch (URIException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/test/FormParamTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/test/FormParamTest.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/test/FormParamTest.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/test/FormParamTest.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,113 @@
+/*
+ * 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 jaxrs.tests.params.test;
+
+import junit.framework.Test;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+
+import framework.defaults.test.DefaultURIInfo;
+import framework.defaults.test.FVTTestCase;
+
+public class FormParamTest extends FVTTestCase {
+
+ public String getBaseURI() {
+ return DefaultURIInfo.getClassDefaultBaseURI(FormParamTest.class)
+ + "/params/form";
+ }
+
+ public static Test suite() {
+ return FVTTestCase.getTestSuite(FormParamTest.class,
+ jaxrs.tests.params.server.Application.class.getName());
+ }
+
+ public void testOnlyEntityFormParam() throws Exception {
+ HttpClient httpclient = new HttpClient();
+
+ PostMethod httpMethod = new PostMethod(getBaseURI() + "/withOnlyEntity");
+ try {
+ StringRequestEntity s = new StringRequestEntity(
+ "firstkey=somevalue&someothervalue=somethingelse",
+ "application/x-www-form-urlencoded", null);
+ httpMethod.setRequestEntity(s);
+ httpclient.executeMethod(httpMethod);
+ assertEquals(200, httpMethod.getStatusCode());
+ String resp = httpMethod.getResponseBodyAsString();
+ System.out.println(resp);
+ assertTrue(resp.contains("someothervalue=[somethingelse]"));
+ assertTrue(resp.contains("firstkey=[somevalue]"));
+ } finally {
+ httpMethod.releaseConnection();
+ }
+ }
+
+ public void testEntityFormParamWithOneFormParam() throws Exception {
+ HttpClient httpclient = new HttpClient();
+
+ PostMethod httpMethod = new PostMethod(getBaseURI()
+ + "/withOneKeyAndEntity");
+ try {
+ StringRequestEntity s = new StringRequestEntity(
+ "firstkey=somevalue&someothervalue=somethingelse",
+ "application/x-www-form-urlencoded", null);
+ httpMethod.setRequestEntity(s);
+ httpclient.executeMethod(httpMethod);
+ assertEquals(200, httpMethod.getStatusCode());
+ String resp = httpMethod.getResponseBodyAsString();
+ System.out.println(resp);
+ assertTrue(resp.startsWith("firstkey=somevalue"));
+ assertTrue(resp.contains("someothervalue=[somethingelse]"));
+ assertTrue(resp.contains("firstkey=[somevalue]"));
+ } finally {
+ httpMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * In a weird instance, client posts a form encoded data but the resource is
+ * expecting something else (say a String) as its entity. The engine should
+ * not mangle the InputStream with ServletRequest.getParameter until
+ * absolutely required.
+ *
+ * @throws Exception
+ */
+ public void testPostFormEntityButResourceDoesNotExpect() throws Exception {
+ HttpClient httpclient = new HttpClient();
+
+ PostMethod httpMethod = new PostMethod(getBaseURI()
+ + "/withStringEntity");
+ try {
+ StringRequestEntity s = new StringRequestEntity(
+ "firstkey=somevalue&someothervalue=somethingelse",
+ "application/x-www-form-urlencoded", null);
+ httpMethod.setRequestEntity(s);
+ httpclient.executeMethod(httpMethod);
+ assertEquals(200, httpMethod.getStatusCode());
+ String resp = httpMethod.getResponseBodyAsString();
+ System.out.println(resp);
+ assertEquals(resp,
+ "str:firstkey=somevalue&someothervalue=somethingelse");
+ } finally {
+ httpMethod.releaseConnection();
+ }
+ }
+}
\ No newline at end of file
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/test/HeaderParamTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/test/HeaderParamTest.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/test/HeaderParamTest.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/params/test/HeaderParamTest.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,517 @@
+/*
+ * 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 jaxrs.tests.params.test;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+import javax.ws.rs.HeaderParam;
+import javax.xml.ws.http.HTTPException;
+
+import junit.framework.Test;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.URI;
+import org.apache.commons.httpclient.URIException;
+import org.apache.commons.httpclient.methods.GetMethod;
+
+import framework.defaults.test.DefaultURIInfo;
+import framework.defaults.test.FVTTestCase;
+
+/**
+ * Tests the <code>@HeaderParam</code>.
+ *
+ * @see HeaderParam
+ */
+public class HeaderParamTest extends FVTTestCase {
+
+ final private static String BASE_URI = DefaultURIInfo
+ .getClassDefaultBaseURI(HeaderParamTest.class)
+ + "/header";
+
+ public static Test suite() {
+ return FVTTestCase.getTestSuite(HeaderParamTest.class,
+ jaxrs.tests.params.server.Application.class.getName());
+ }
+
+ /**
+ * Tests that a custom header is sent and received properly. Uses
+ * constructor, property, field, and parameter parameters.
+ */
+ public void testCustomHeaderParam() {
+ HttpClient httpclient = new HttpClient();
+ try {
+ GetMethod httpMethod = new GetMethod();
+ httpMethod.setURI(new URI(BASE_URI, false));
+ httpMethod.setRequestHeader("customHeaderParam", "somevalue");
+ httpMethod.setRequestHeader(new Header("User-Agent", "httpclient"));
+ httpMethod.setRequestHeader("Accept-Language", "en");
+ System.out.println(Arrays.asList(httpMethod.getRequestHeaders()));
+ httpclient = new HttpClient();
+
+ try {
+ int result = httpclient.executeMethod(httpMethod);
+ System.out.println("Response status code: " + result);
+ System.out.println("Response body: ");
+ String responseBody = httpMethod.getResponseBodyAsString();
+ System.out.println(responseBody);
+ assertEquals(200, result);
+ assertEquals("secret", httpMethod.getResponseHeader(
+ "custResponseHeader").getValue());
+ assertEquals(
+ "getHeaderParam:somevalue;User-Agent:httpclient;Accept-Language:en;language-method:en",
+ responseBody);
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ fail(ioe.getMessage());
+ } finally {
+ httpMethod.releaseConnection();
+ }
+ } catch (URIException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * Tests that headers are properly set with <code>@DefaultValue</code>s set.
+ */
+ public void testHeaderDefaultValue() throws IOException, HTTPException {
+ HttpClient httpclient = new HttpClient();
+
+ /*
+ * the default values with no headers set.
+ */
+ GetMethod getMethod = new GetMethod(getBaseURI()
+ + "/params/headerparam/default");
+ // System.out.println(Arrays.asList(getMethod.getRequestHeaders()));
+
+ try {
+ int result = httpclient.executeMethod(getMethod);
+ String responseBody = getMethod.getResponseBodyAsString();
+ assertEquals(result, 200);
+ assertEquals("", responseBody);
+ assertEquals("MyCustomPropertyHeader", getMethod.getResponseHeader(
+ "RespCustomPropertyHeader").getValue());
+ assertEquals("MyCustomConstructorHeader", getMethod
+ .getResponseHeader("RespCustomConstructorHeader")
+ .getValue());
+ assertEquals("Jakarta Commons-HttpClient/3.1", getMethod
+ .getResponseHeader("RespUserAgent").getValue());
+ assertEquals("english", getMethod.getResponseHeader(
+ "RespAccept-Language").getValue());
+ assertEquals("MyCustomMethodHeader", getMethod.getResponseHeader(
+ "RespCustomMethodHeader").getValue());
+ //System.out.println(Arrays.asList(getMethod.getResponseHeaders()));
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ /*
+ * set values for custom headers
+ */
+ getMethod = new GetMethod(getBaseURI() + "/params/headerparam/default");
+ getMethod.setRequestHeader("CustomPropertyHeader",
+ "setCustPropertyHeader");
+ getMethod.setRequestHeader("CustomConstructorHeader",
+ "setCustConstructorHeader");
+ getMethod.setRequestHeader("Accept-Language", "da;en-gb;en");
+ getMethod.setRequestHeader("CustomMethodHeader", "12345678910");
+ // System.out.println(Arrays.asList(getMethod.getRequestHeaders()));
+
+ try {
+ int result = httpclient.executeMethod(getMethod);
+ String responseBody = getMethod.getResponseBodyAsString();
+ assertEquals(result, 200);
+ assertEquals("", responseBody);
+ assertEquals("setCustPropertyHeader", getMethod.getResponseHeader(
+ "RespCustomPropertyHeader").getValue());
+ assertEquals("setCustConstructorHeader", getMethod
+ .getResponseHeader("RespCustomConstructorHeader")
+ .getValue());
+ assertEquals("Jakarta Commons-HttpClient/3.1", getMethod
+ .getResponseHeader("RespUserAgent").getValue());
+ assertEquals("da;en-gb;en", getMethod.getResponseHeader(
+ "RespAccept-Language").getValue());
+ assertEquals("12345678910", getMethod.getResponseHeader(
+ "RespCustomMethodHeader").getValue());
+ //System.out.println(Arrays.asList(getMethod.getResponseHeaders()));
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a custom header with a primitive type (int) can be used.
+ *
+ */
+ public void testHeaderParamPrimitiveException() throws IOException,
+ HTTPException {
+ HttpClient httpclient = new HttpClient();
+
+ GetMethod getMethod = new GetMethod(getBaseURI()
+ + "/params/headerparam/exception/primitive");
+ getMethod.setRequestHeader("CustomNumHeader", "314");
+
+ try {
+ int result = httpclient.executeMethod(getMethod);
+ String responseBody = getMethod.getResponseBodyAsString();
+ assertEquals(200, result);
+ assertEquals("", responseBody);
+ assertEquals("314", getMethod.getResponseHeader(
+ "RespCustomNumHeader").getValue());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod = new GetMethod(getBaseURI()
+ + "/params/headerparam/exception/primitive");
+ getMethod.setRequestHeader("CustomNumHeader", "abcd");
+
+ try {
+ int result = httpclient.executeMethod(getMethod);
+ String responseBody = getMethod.getResponseBodyAsString();
+ assertEquals(400, result);
+ assertEquals("", responseBody);
+ assertLogContainsException("javax.ws.rs.WebApplicationException: java.lang.NumberFormatException: For input string: \"abcd\"");
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a custom header with a custom constructor can be used.
+ * <ul>
+ * <li>If the header is not set, then the header parameter is set to null.</li>
+ * <li>If the header constructor throws an exception, then 400 Bad Request
+ * status is returned.</li>
+ * <li>If a <code>WebApplicationException</code> is thrown during parameter
+ * construction, then use that.</li>
+ * </ul>
+ *
+ */
+ public void testHeaderParamStringConstructorException() throws IOException,
+ HTTPException {
+ executeStringConstructorHeaderTest(
+ "/params/headerparam/exception/constructor",
+ "CustomStringHeader");
+ }
+
+ /**
+ * Tests that a custom header with a custom static valueOf method can be
+ * used.
+ * <ul>
+ * <li>If the header is not set, then the header parameter is set to null.</li>
+ * <li>If the header valueOf throws an exception, then 400 Bad Request
+ * status is returned.</li>
+ * <li>If a <code>WebApplicationException</code> is thrown during parameter
+ * valueOf construction, then use that.</li>
+ * </ul>
+ *
+ */
+ public void testHeaderParamValueOfException() throws IOException,
+ HTTPException {
+ executeValueOfHeaderTest("/params/headerparam/exception/valueof",
+ "CustomValueOfHeader");
+ }
+
+ /**
+ * Tests that a custom header is set correctly in a List of a type with a
+ * custom static valueOf method.
+ * <ul>
+ * <li>If the header is not set, then the header parameter is set to null.</li>
+ * <li>If the header valueOf throws an exception, then 400 Bad Request
+ * status is returned.</li>
+ * <li>If a <code>WebApplicationException</code> is thrown during parameter
+ * valueOf construction, then use that.</li>
+ * </ul>
+ *
+ */
+ public void testHeaderParamListValueOfException() throws IOException,
+ HTTPException {
+ executeValueOfHeaderTest("/params/headerparam/exception/listvalueof",
+ "CustomListValueOfHeader");
+ }
+
+ /**
+ * Tests that a custom header is set correctly in a Set of a type with a
+ * custom static valueOf method.
+ * <ul>
+ * <li>If the header is not set, then the header parameter is set to null.</li>
+ * <li>If the header valueOf throws an exception, then 400 Bad Request
+ * status is returned.</li>
+ * <li>If a <code>WebApplicationException</code> is thrown during parameter
+ * valueOf construction, then use that.</li>
+ * </ul>
+ *
+ */
+ public void testHeaderParamSetValueOfException() throws IOException,
+ HTTPException {
+ executeValueOfHeaderTest("/params/headerparam/exception/setvalueof",
+ "CustomSetValueOfHeader");
+ }
+
+ /**
+ * Tests that a custom header is set correctly in a Set of a type with a
+ * custom static valueOf method.
+ * <ul>
+ * <li>If the header is not set, then the header parameter is set to null.</li>
+ * <li>If the header valueOf throws an exception, then 400 Bad Request
+ * status is returned.</li>
+ * <li>If a <code>WebApplicationException</code> is thrown during parameter
+ * valueOf construction, then use that.</li>
+ * </ul>
+ *
+ */
+ public void testHeaderParamSortedSetValueOfException() throws IOException,
+ HTTPException {
+ executeValueOfHeaderTest(
+ "/params/headerparam/exception/sortedsetvalueof",
+ "CustomSortedSetValueOfHeader");
+ }
+
+ /**
+ * Tests that a custom header is set correctly in a field with a String
+ * constructor type.
+ * <ul>
+ * <li>If the header is not set, then the header parameter is set to null.</li>
+ * <li>If the header valueOf throws an exception, then 400 Bad Request
+ * status is returned.</li>
+ * <li>If a <code>WebApplicationException</code> is thrown during parameter
+ * valueOf construction, then use that.</li>
+ * </ul>
+ *
+ */
+ public void testHeaderFieldStringConstructorException() throws IOException,
+ HTTPException {
+ executeStringConstructorHeaderTest(
+ "/params/headerparam/exception/fieldstrcstr",
+ "CustomStringConstructorFieldHeader");
+ }
+
+ /**
+ * Tests that a custom header is set correctly in a field with a static
+ * valueOf method.
+ * <ul>
+ * <li>If the header is not set, then the header parameter is set to null.</li>
+ * <li>If the header valueOf throws an exception, then 400 Bad Request
+ * status is returned.</li>
+ * <li>If a <code>WebApplicationException</code> is thrown during parameter
+ * valueOf construction, then use that.</li>
+ * </ul>
+ *
+ */
+ public void testHeaderFieldValueOfException() throws IOException,
+ HTTPException {
+ executeValueOfHeaderTest("/params/headerparam/exception/fieldvalueof",
+ "CustomValueOfFieldHeader");
+ }
+
+ /**
+ * Tests that a custom header is set correctly in a field with a string
+ * constructor.
+ * <ul>
+ * <li>If the header is not set, then the header parameter is set to null.</li>
+ * <li>If the header valueOf throws an exception, then 400 Bad Request
+ * status is returned.</li>
+ * <li>If a <code>WebApplicationException</code> is thrown during parameter
+ * valueOf construction, then use that.</li>
+ * </ul>
+ *
+ */
+ public void testHeaderPropertyStringConstructorException()
+ throws IOException, HTTPException {
+ executeStringConstructorHeaderTest(
+ "/params/headerparam/exception/propertystrcstr",
+ "CustomStringConstructorPropertyHeader");
+ }
+
+ /**
+ * Tests that a custom header is set correctly in a field with a type with a
+ * static valueOf method.
+ * <ul>
+ * <li>If the header is not set, then the header parameter is set to null.</li>
+ * <li>If the header valueOf throws an exception, then 400 Bad Request
+ * status is returned.</li>
+ * <li>If a <code>WebApplicationException</code> is thrown during parameter
+ * valueOf construction, then use that.</li>
+ * </ul>
+ *
+ */
+ public void testHeaderPropertyValueOfException() throws IOException,
+ HTTPException {
+ executeValueOfHeaderTest(
+ "/params/headerparam/exception/propertyvalueof",
+ "CustomValueOfPropertyHeader");
+ }
+
+ /**
+ * Tests a custom string constructor type.
+ *
+ * @param path
+ * @param header
+ * @throws IOException
+ * @throws HTTPException
+ */
+ private void executeStringConstructorHeaderTest(String path, String header)
+ throws IOException, HTTPException {
+ HttpClient httpclient = new HttpClient();
+
+ /* normal */
+ GetMethod getMethod = new GetMethod(getBaseURI() + path);
+ getMethod.setRequestHeader(header, "MyCustomHeaderValue");
+
+ try {
+ int result = httpclient.executeMethod(getMethod);
+ String responseBody = getMethod.getResponseBodyAsString();
+ assertEquals(200, result);
+ assertEquals("", responseBody);
+ assertEquals("MyCustomHeaderValue", getMethod.getResponseHeader(
+ "Resp" + header).getValue());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ /* no header set */
+ getMethod = new GetMethod(getBaseURI() + path);
+
+ try {
+ int result = httpclient.executeMethod(getMethod);
+ assertEquals(500, result);
+ assertLogContainsException("java.lang.NullPointerException");
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ /* web app ex thrown */
+ getMethod = new GetMethod(getBaseURI() + path);
+ getMethod.setRequestHeader(header, "throwWeb");
+
+ try {
+ int result = httpclient.executeMethod(getMethod);
+ String responseBody = getMethod.getResponseBodyAsString();
+ assertEquals(499, result);
+ assertEquals("HeaderStringConstructorWebAppEx", responseBody);
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ /* runtime exception thrown */
+ getMethod = new GetMethod(getBaseURI() + path);
+ getMethod.setRequestHeader(header, "throwNull");
+ try {
+ int result = httpclient.executeMethod(getMethod);
+ assertEquals(400, result);
+ assertEquals("", getMethod.getResponseBodyAsString());
+ assertLogContainsException("HeaderStringConstructor NPE");
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ /* exception thrown */
+ getMethod = new GetMethod(getBaseURI() + path);
+ getMethod.setRequestHeader(header, "throwEx");
+ try {
+ int result = httpclient.executeMethod(getMethod);
+ assertEquals(400, result);
+ assertEquals("", getMethod.getResponseBodyAsString());
+ assertLogContainsException("HeaderStringConstructor Exception");
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests a custom valueOf header.
+ *
+ * @param path the path to the resource
+ * @param header the name of the header to test
+ * @throws IOException
+ * @throws HTTPException
+ */
+ private void executeValueOfHeaderTest(String path, String header)
+ throws IOException, HTTPException {
+ HttpClient httpclient = new HttpClient();
+
+ /* normal */
+ GetMethod getMethod = new GetMethod(getBaseURI() + path);
+ getMethod.setRequestHeader(header, "MyCustomHeaderValue");
+
+ try {
+ int result = httpclient.executeMethod(getMethod);
+ String responseBody = getMethod.getResponseBodyAsString();
+ assertEquals(200, result);
+ assertEquals("", responseBody);
+ assertEquals("MyCustomHeaderValue", getMethod.getResponseHeader(
+ "Resp" + header).getValue());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ /* no header set */
+ getMethod = new GetMethod(getBaseURI() + path);
+
+ try {
+ int result = httpclient.executeMethod(getMethod);
+ assertEquals(500, result);
+ assertLogContainsException("java.lang.NullPointerException");
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ /* web app ex thrown */
+ getMethod = new GetMethod(getBaseURI() + path);
+ getMethod.setRequestHeader(header, "throwWeb");
+
+ try {
+ int result = httpclient.executeMethod(getMethod);
+ String responseBody = getMethod.getResponseBodyAsString();
+ assertEquals(498, result);
+ assertEquals("HeaderValueOfWebAppEx", responseBody);
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ /* runtime exception thrown */
+ getMethod = new GetMethod(getBaseURI() + path);
+ getMethod.setRequestHeader(header, "throwNull");
+ try {
+ int result = httpclient.executeMethod(getMethod);
+ assertEquals(400, result);
+ assertEquals("", getMethod.getResponseBodyAsString());
+ assertLogContainsException("HeaderValueOf NPE");
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ /* exception thrown */
+ getMethod = new GetMethod(getBaseURI() + path);
+ getMethod.setRequestHeader(header, "throwEx");
+ try {
+ int result = httpclient.executeMethod(getMethod);
+ assertEquals(400, result);
+ assertEquals("", getMethod.getResponseBodyAsString());
+ assertLogContainsException("HeaderValueOf Exception");
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+}
|