You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wink.apache.org by jr...@apache.org on 2009/07/14 21:47:02 UTC
svn commit: r794036 [2/3] - in
/incubator/wink/trunk/wink-integration-test/wink-server-integration-test:
./ wink-jaxrs-test-params/ wink-jaxrs-test-params/src/
wink-jaxrs-test-params/src/main/ wink-jaxrs-test-params/src/main/java/
wink-jaxrs-test-param...
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/main/java/org/apache/wink/jaxrs/test/params/query/QueryParamsExceptionResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/main/java/org/apache/wink/jaxrs/test/params/query/QueryParamsExceptionResource.java?rev=794036&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/main/java/org/apache/wink/jaxrs/test/params/query/QueryParamsExceptionResource.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/main/java/org/apache/wink/jaxrs/test/params/query/QueryParamsExceptionResource.java Tue Jul 14 19:47:00 2009
@@ -0,0 +1,161 @@
+/*
+ * 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.wink.jaxrs.test.params.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 setCustomPropertyStringConstructorQuery(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/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/main/webapp/WEB-INF/web.xml?rev=794036&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/main/webapp/WEB-INF/web.xml (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/main/webapp/WEB-INF/web.xml Tue Jul 14 19:47:00 2009
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+
+<!DOCTYPE web-app PUBLIC
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd" >
+
+<web-app>
+ <display-name>Archetype Created Web Application</display-name>
+ <servlet>
+ <servlet-name>Params</servlet-name>
+ <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.apache.wink.jaxrs.test.params.Application</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>Params</servlet-name>
+ <url-pattern>/params/*</url-pattern>
+ </servlet-mapping>
+</web-app>
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/main/webapp/index.jsp
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/main/webapp/index.jsp?rev=794036&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/main/webapp/index.jsp (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/main/webapp/index.jsp Tue Jul 14 19:47:00 2009
@@ -0,0 +1,5 @@
+<html>
+<body>
+<h2>Hello World!</h2>
+</body>
+</html>
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/test/java/org/apache/wink/jaxrs/test/params/CookieParamTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/test/java/org/apache/wink/jaxrs/test/params/CookieParamTest.java?rev=794036&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/test/java/org/apache/wink/jaxrs/test/params/CookieParamTest.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/test/java/org/apache/wink/jaxrs/test/params/CookieParamTest.java Tue Jul 14 19:47:00 2009
@@ -0,0 +1,103 @@
+/*
+ * 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.wink.jaxrs.test.params;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+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 org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+/**
+ * Tests the use of cookie parameter.
+ */
+public class CookieParamTest extends TestCase {
+
+ protected HttpClient httpclient = new HttpClient();
+
+ final private static String BASE_URI = ServerEnvironmentInfo.getBaseURI() + "/params/cookiemonster";
+
+ /**
+ * 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/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/test/java/org/apache/wink/jaxrs/test/params/DefaultValueParamTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/test/java/org/apache/wink/jaxrs/test/params/DefaultValueParamTest.java?rev=794036&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/test/java/org/apache/wink/jaxrs/test/params/DefaultValueParamTest.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/test/java/org/apache/wink/jaxrs/test/params/DefaultValueParamTest.java Tue Jul 14 19:47:00 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 org.apache.wink.jaxrs.test.params;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+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 org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+/**
+ * Tests <code>@DefaultValue</code> annotation.
+ */
+public class DefaultValueParamTest extends TestCase {
+
+ protected HttpClient httpclient = new HttpClient();
+
+ final private static String BASE_URI = ServerEnvironmentInfo.getBaseURI() + "/params/defaultvalue";
+
+ /**
+ * 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/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/test/java/org/apache/wink/jaxrs/test/params/EncodingParamTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/test/java/org/apache/wink/jaxrs/test/params/EncodingParamTest.java?rev=794036&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/test/java/org/apache/wink/jaxrs/test/params/EncodingParamTest.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/test/java/org/apache/wink/jaxrs/test/params/EncodingParamTest.java Tue Jul 14 19:47:00 2009
@@ -0,0 +1,581 @@
+/*
+ * 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.wink.jaxrs.test.params;
+
+import java.io.IOException;
+
+import javax.ws.rs.core.MediaType;
+
+import junit.framework.TestCase;
+
+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 org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+/**
+ * Tests that <code>@Encoded</code> annotated method and parameter level works.
+ */
+public class EncodingParamTest extends TestCase {
+
+ protected HttpClient httpclient = new HttpClient();
+
+ final private static String BASE_URI_DECODE =
+ ServerEnvironmentInfo.getBaseURI() + "/params/decodedparams";
+
+ final private static String BASE_URI_ENCODE =
+ ServerEnvironmentInfo.getBaseURI() + "/params/encodingparam";
+
+ // /**
+ // * 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);
+ System.out.println(responseBody);
+ 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",
+ 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",
+ 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",
+ 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%2B%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%2B%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() throws Exception {
+ try {
+ PostMethod httpMethod = new PostMethod();
+ httpMethod.setURI(new URI(BASE_URI_DECODE + "/region;appversion=", true));
+ // httpMethod.setParameter("location", "The%20Southwest");
+ httpMethod
+ .setRequestEntity(new StringRequestEntity(
+ "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",
+ "application/x-www-form-urlencoded",
+ "UTF-8"));
+ 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() throws Exception {
+ try {
+ PostMethod httpMethod = new PostMethod();
+ httpMethod.setURI(new URI(BASE_URI_ENCODE + "/region;appversion=1.1%2B", true));
+ // httpMethod.setParameter("location", "The%20Southwest");
+ httpMethod
+ .setRequestEntity(new StringRequestEntity("location=The%20Southwest",
+ "application/x-www-form-urlencoded",
+ "UTF-8"));
+ 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() throws Exception {
+ try {
+ PostMethod httpMethod = new PostMethod();
+ httpMethod.setURI(new URI(BASE_URI_ENCODE + "/method/region;appversion=1.1%2B", true));
+ httpMethod
+ .setRequestEntity(new StringRequestEntity("location=The%20Southwest",
+ "application/x-www-form-urlencoded",
+ "UTF-8"));
+ 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/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/test/java/org/apache/wink/jaxrs/test/params/FormParamTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/test/java/org/apache/wink/jaxrs/test/params/FormParamTest.java?rev=794036&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/test/java/org/apache/wink/jaxrs/test/params/FormParamTest.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/test/java/org/apache/wink/jaxrs/test/params/FormParamTest.java Tue Jul 14 19:47:00 2009
@@ -0,0 +1,102 @@
+/*
+ * 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.wink.jaxrs.test.params;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+public class FormParamTest extends TestCase {
+
+ public String getBaseURI() {
+ return ServerEnvironmentInfo.getBaseURI() + "/params/params/form";
+ }
+
+ 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, resp.contains("someothervalue=somethingelse"));
+ assertTrue(resp, resp.contains("firstkey=somevalue"));
+ } finally {
+ httpMethod.releaseConnection();
+ }
+ }
+
+ // TODO Fails due to WINK-35 which is not going to be resolved for the time being
+// 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, resp.startsWith("firstkey=somevalue"));
+// assertTrue(resp, resp.contains("someothervalue=somethingelse"));
+// assertTrue(resp, 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();
+ }
+ }
+}
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/test/java/org/apache/wink/jaxrs/test/params/HeaderParamTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/test/java/org/apache/wink/jaxrs/test/params/HeaderParamTest.java?rev=794036&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/test/java/org/apache/wink/jaxrs/test/params/HeaderParamTest.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/test/java/org/apache/wink/jaxrs/test/params/HeaderParamTest.java Tue Jul 14 19:47:00 2009
@@ -0,0 +1,456 @@
+/*
+ * 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.wink.jaxrs.test.params;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+import javax.ws.rs.HeaderParam;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.URI;
+import org.apache.commons.httpclient.URIException;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+/**
+ * Tests the <code>@HeaderParam</code>.
+ *
+ * @see HeaderParam
+ */
+public class HeaderParamTest extends TestCase {
+
+ final private static String BASE_URI = ServerEnvironmentInfo.getBaseURI() + "/params/header";
+
+ public String getBaseURI() {
+ return ServerEnvironmentInfo.getBaseURI() + "/params";
+ }
+
+ /**
+ * 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 {
+ 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 {
+ 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);
+ } 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 {
+ 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 {
+ 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 {
+ 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 {
+ 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 {
+ 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 {
+ 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 {
+ 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 {
+ 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);
+ } 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());
+ } 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());
+ } 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);
+ } 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());
+ } 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());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+}
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/test/java/org/apache/wink/jaxrs/test/params/MatrixParamTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/test/java/org/apache/wink/jaxrs/test/params/MatrixParamTest.java?rev=794036&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/test/java/org/apache/wink/jaxrs/test/params/MatrixParamTest.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-params/src/test/java/org/apache/wink/jaxrs/test/params/MatrixParamTest.java Tue Jul 14 19:47:00 2009
@@ -0,0 +1,228 @@
+/*
+ * 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.wink.jaxrs.test.params;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.URI;
+import org.apache.commons.httpclient.URIException;
+import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+/**
+ * Tests the <code>@MatrixParam</code>.
+ */
+public class MatrixParamTest extends TestCase {
+
+ protected HttpClient httpclient = new HttpClient();
+
+ final private static String BASE_URI = ServerEnvironmentInfo.getBaseURI() + "/params/";
+
+ protected String sendGoodRequestAndGetResponse(String aPartialRequestURL,
+ Class<? extends HttpMethod> aClass) {
+ try {
+ HttpMethod httpMethod = aClass.newInstance();
+ httpMethod.setURI(new URI(BASE_URI + aPartialRequestURL, 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(result, 200);
+ return responseBody;
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ fail(ioe.getMessage());
+ } finally {
+ httpMethod.releaseConnection();
+ }
+ } catch (URIException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ } catch (InstantiationException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ return null;
+ }
+
+ /**
+ * Tests that no matrix parameters sent still calls proper resource.
+ */
+ public void testNoParam() {
+ assertEquals("deleteConstructorMatrixParam:null",
+ sendGoodRequestAndGetResponse("matrix", DeleteMethod.class));
+ assertEquals("getConstructorMatrixParam:null",
+ sendGoodRequestAndGetResponse("matrix", GetMethod.class));
+ assertEquals("putConstructorMatrixParam:null",
+ sendGoodRequestAndGetResponse("matrix", PutMethod.class));
+ assertEquals("postConstructorMatrixParam:null",
+ sendGoodRequestAndGetResponse("matrix", PostMethod.class));
+ }
+
+ /**
+ * Tests the constructor matrix parameter is processed.
+ */
+ public void testConstructorParam() {
+ assertEquals("getConstructorMatrixParam:HelloWorld",
+ sendGoodRequestAndGetResponse("matrix;cstrparam=HelloWorld", GetMethod.class));
+ assertEquals("deleteConstructorMatrixParam:HelloWorld",
+ sendGoodRequestAndGetResponse("matrix;cstrparam=HelloWorld",
+ DeleteMethod.class));
+ assertEquals("putConstructorMatrixParam:HelloWorld",
+ sendGoodRequestAndGetResponse("matrix;cstrparam=HelloWorld", PutMethod.class));
+ assertEquals("postConstructorMatrixParam:HelloWorld",
+ sendGoodRequestAndGetResponse("matrix;cstrparam=HelloWorld", PostMethod.class));
+ }
+
+ /**
+ * Tests both the simple constructor and method matrix parameter are processed.
+ */
+ public void testSimpleMatrixParam() {
+ assertEquals("getSimpleMatrixParam:Hello;good",
+ sendGoodRequestAndGetResponse("matrix/simple;cstrparam=Hello;life=good",
+ GetMethod.class));
+ assertEquals("putSimpleMatrixParam:Hello;good",
+ sendGoodRequestAndGetResponse("matrix/simple;cstrparam=Hello;life=good",
+ PutMethod.class));
+ assertEquals("postSimpleMatrixParam:Hello;good",
+ sendGoodRequestAndGetResponse("matrix/simple;cstrparam=Hello;life=good",
+ PostMethod.class));
+ assertEquals("deleteSimpleMatrixParam:Hello;good",
+ sendGoodRequestAndGetResponse("matrix/simple;cstrparam=Hello;life=good",
+ DeleteMethod.class));
+ }
+
+ /**
+ * Tests that a no constructor matrix parameter is set.
+ */
+ public void testNoConstructorMatrixParamAndSimpleMatrixParam() {
+ assertEquals("deleteSimpleMatrixParam:null;erase",
+ sendGoodRequestAndGetResponse("matrix/simple;life=erase", DeleteMethod.class));
+ assertEquals("getSimpleMatrixParam:null;good",
+ sendGoodRequestAndGetResponse("matrix/simple;life=good", GetMethod.class));
+ assertEquals("postSimpleMatrixParam:null;new",
+ sendGoodRequestAndGetResponse("matrix/simple;life=new", PostMethod.class));
+ assertEquals("putSimpleMatrixParam:null;progress",
+ sendGoodRequestAndGetResponse("matrix/simple;life=progress", PutMethod.class));
+ }
+
+ /**
+ * Tests the constructor and simple matrix parameter can be out of order.
+ */
+ public void testOutOfOrderMatrixParam() {
+ assertEquals("getSimpleMatrixParam:Hello;good",
+ sendGoodRequestAndGetResponse("matrix/simple;life=good;cstrparam=Hello;",
+ GetMethod.class));
+ assertEquals("putSimpleMatrixParam:Hello;good",
+ sendGoodRequestAndGetResponse("matrix/simple;life=good;cstrparam=Hello;",
+ PutMethod.class));
+ assertEquals("postSimpleMatrixParam:Hello;good",
+ sendGoodRequestAndGetResponse("matrix/simple;life=good;cstrparam=Hello",
+ PostMethod.class));
+ assertEquals("deleteSimpleMatrixParam:Hello;good",
+ sendGoodRequestAndGetResponse("matrix/simple;life=good;cstrparam=Hello",
+ DeleteMethod.class));
+ }
+
+ /**
+ * Tests that matrix parameters are case sensitive.
+ */
+ public void testLowercaseMatrixParam() {
+ assertEquals("getSimpleMatrixParam:null;null",
+ sendGoodRequestAndGetResponse("matrix/simple;LIFE=good;cstrParam=Hello",
+ GetMethod.class));
+ assertEquals("postSimpleMatrixParam:null;null",
+ sendGoodRequestAndGetResponse("matrix/simple;LIFE=good;cstrParam=Hello",
+ PostMethod.class));
+ assertEquals("putSimpleMatrixParam:null;null",
+ sendGoodRequestAndGetResponse("matrix/simple;LIFE=good;cstrParam=Hello",
+ PutMethod.class));
+ assertEquals("deleteSimpleMatrixParam:null;null",
+ sendGoodRequestAndGetResponse("matrix/simple;LIFE=good;cstrParam=Hello",
+ DeleteMethod.class));
+ }
+
+ /**
+ * Tests multiple matrix parameters sent to same resource.
+ */
+ public void testMultipleMatrixParam() {
+ assertEquals("getMultipleMatrixParam:first;capital;done",
+ sendGoodRequestAndGetResponse("matrix/multiple;1st=first;ONEMOREPARAM=capital;onemoreparam=done",
+ GetMethod.class));
+ assertEquals("deleteMultipleMatrixParam:first;capital;done",
+ sendGoodRequestAndGetResponse("matrix/multiple;1st=first;ONEMOREPARAM=capital;onemoreparam=done",
+ DeleteMethod.class));
+ assertEquals("postMultipleMatrixParam:first;capital;done",
+ sendGoodRequestAndGetResponse("matrix/multiple;1st=first;ONEMOREPARAM=capital;onemoreparam=done",
+ PostMethod.class));
+ assertEquals("putMultipleMatrixParam:first;capital;done",
+ sendGoodRequestAndGetResponse("matrix/multiple;1st=first;ONEMOREPARAM=capital;onemoreparam=done",
+ PutMethod.class));
+ }
+
+ /**
+ * Tests that primitive types are accepted in matrix parameters.
+ */
+ public void testPrimitiveTypedMatrixParameter() {
+ assertEquals("getMatrixParameterPrimitiveTypes:false;12;3.14;3;b;1234567890;32456;123.0",
+ sendGoodRequestAndGetResponse("matrix/types/primitive;bool=false;intNumber=12;dbl=3.14;bite=3;ch=b;lng=1234567890;float=32456;short=123",
+ GetMethod.class));
+ }
+
+ /**
+ * Tests that primitive types are accepted in parameters.
+ */
+ public void testParameterTypeWithStringConstructor() {
+ assertEquals("getMatrixParameterStringConstructor:1234",
+ sendGoodRequestAndGetResponse("matrix/types/stringcstr;paramStringConstructor=1234",
+ GetMethod.class));
+ }
+
+ /**
+ * Tests that primitive types are accepted in parameters.
+ */
+ public void testParameterTypeWithValueOfMethod() {
+ assertEquals("getMatrixParameterValueOf:456789",
+ sendGoodRequestAndGetResponse("matrix/types/valueof;staticValueOf=456",
+ GetMethod.class));
+ }
+
+ /*
+ * TODO: More tests. Need to add urlencoding tests Need to add "weird" parameter tests (i.e. not
+ * standard inputs) Need to add precedence tests Need to add where both constructor and major
+ * get are in the same URL Need to add invalid tests. Need to add mixed tests and error tests
+ * for special parameters (i.e. not strings) Need to test cases where more/less inputs are given
+ * than expected
+ */
+}