You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wink.apache.org by bl...@apache.org on 2009/07/21 03:45:55 UTC
svn commit: r796113 [4/5] - in
/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-context/src:
main/java/org/apache/wink/jaxrs/test/context/providers/
main/java/org/apache/wink/jaxrs/test/context/providers/otherxml...
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-context/src/test/java/org/apache/wink/jaxrs/test/context/request/RequestMethodsTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-context/src/test/java/org/apache/wink/jaxrs/test/context/request/RequestMethodsTest.java?rev=796113&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-context/src/test/java/org/apache/wink/jaxrs/test/context/request/RequestMethodsTest.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-context/src/test/java/org/apache/wink/jaxrs/test/context/request/RequestMethodsTest.java Tue Jul 21 01:45:53 2009
@@ -0,0 +1,816 @@
+/*
+ * 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.context.request;
+
+import java.io.IOException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+
+import javax.ws.rs.core.Request;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+/**
+ * Tests the {@link Request} implementation.
+ */
+public class RequestMethodsTest extends TestCase {
+
+ final private static SimpleDateFormat rfc1123Format =
+ new SimpleDateFormat(
+ "EEE, dd MMM yyyy HH:mm:ss zzz",
+ Locale.ENGLISH);
+
+ final private static SimpleDateFormat rfc850Format =
+ new SimpleDateFormat(
+ "EEEE, dd-MMM-yy HH:mm:ss zzz",
+ Locale.ENGLISH);
+
+ final private static SimpleDateFormat asctimeDateFormat =
+ new SimpleDateFormat(
+ "EEE MMM dd HH:mm:ss yyyy",
+ Locale.ENGLISH);
+
+ final private static SimpleDateFormat asctimeDateFormatWithOneDigit =
+ new SimpleDateFormat(
+ "EEE MMM d HH:mm:ss yyyy",
+ Locale.ENGLISH);
+
+ {
+ /*
+ * the implementation allows you to set a different time zone on the
+ * requests for If-Modified-Since headers and it will do the
+ * "right thing" (this is more leniant). However, asctime does not have
+ * a time zone specified so it is assumed that all datetimes are in
+ * GMT/UTC so the tests have to assume that the GMT time zone is used.
+ */
+ asctimeDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
+ asctimeDateFormatWithOneDigit.setTimeZone(TimeZone.getTimeZone("GMT"));
+ }
+
+ public String getBaseURI() {
+ return ServerEnvironmentInfo.getBaseURI() + "/request";
+ }
+
+ /**
+ * Tests the {@link Request#evaluatePreconditions(Date)} that uses the
+ * <code>If-Modified-Since</code> header and the RFC 1123 date format.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testEvaluateDateIfModifiedSinceUsingRFC1123Format() throws HttpException,
+ IOException {
+ checkIfModifiedSinceUsingSuppliedDateFormat(rfc1123Format);
+ }
+
+ /**
+ * Tests the {@link Request#evaluatePreconditions(Date)} that uses the
+ * <code>If-Modified-Since</code> header and the RFC 850 date format.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testEvaluateDateIfModifiedSinceUsingRFC850Format() throws HttpException,
+ IOException {
+ checkIfModifiedSinceUsingSuppliedDateFormat(rfc850Format);
+ }
+
+ /**
+ * Tests the {@link Request#evaluatePreconditions(Date)} that uses the
+ * <code>If-Modified-Since</code> header and the Asctime date format.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testEvaluateDateIfModifiedSinceUsingAscTimeFormat() throws HttpException,
+ IOException {
+ SimpleDateFormat formatter =
+ (Calendar.getInstance().get(Calendar.DAY_OF_MONTH) < 10)
+ ? asctimeDateFormatWithOneDigit : asctimeDateFormat;
+ checkIfModifiedSinceUsingSuppliedDateFormat(formatter);
+ }
+
+ private void checkIfModifiedSinceUsingSuppliedDateFormat(SimpleDateFormat formatter)
+ throws IOException, HttpException {
+ HttpClient client = new HttpClient();
+
+ PutMethod putMethod = new PutMethod(getBaseURI() + "/context/request/date");
+ Date d2 = new Date(System.currentTimeMillis() - 120000);
+ Date d = new Date(System.currentTimeMillis() - 60000);
+ String date = DateFormat.getDateTimeInstance().format(d);
+ putMethod.setRequestEntity(new StringRequestEntity(date, "text/string", "UTF-8"));
+ try {
+ /*
+ * sets a last modified date
+ */
+ client.executeMethod(putMethod);
+ assertEquals(204, putMethod.getStatusCode());
+ } finally {
+ putMethod.releaseConnection();
+ }
+
+ GetMethod getMethod = new GetMethod(getBaseURI() + "/context/request/date");
+ getMethod.setRequestHeader("If-Modified-Since", formatter.format(d));
+ try {
+ /*
+ * verifies that if the exact date is sent in and used in
+ * If-Modified-Since header, then the server will be ok and that it
+ * will return 304
+ */
+ client.executeMethod(getMethod);
+ assertEquals(304, getMethod.getStatusCode());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod = new GetMethod(getBaseURI() + "/context/request/date");
+ try {
+ /*
+ * verifies that if no If-Modified-Since header is sent, then the
+ * server will be ok and the Request instance won't build a
+ * response.
+ */
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("the date: " + rfc1123Format.format(d), getMethod
+ .getResponseBodyAsString());
+
+ rfc1123Format.setTimeZone(TimeZone.getTimeZone("GMT"));
+ assertEquals(rfc1123Format.format(d), getMethod.getResponseHeader("Last-Modified")
+ .getValue());
+ rfc1123Format.setTimeZone(TimeZone.getDefault());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ String lastModified = getMethod.getResponseHeader("Last-Modified").getValue();
+ getMethod = new GetMethod(getBaseURI() + "/context/request/date");
+ getMethod.setRequestHeader("If-Modified-Since", lastModified);
+ try {
+ /*
+ * verifies that using Last-Modified response header sent by server
+ * as If-Modified-Since request header, then the server will return
+ * a 304
+ */
+ client.executeMethod(getMethod);
+ assertEquals(304, getMethod.getStatusCode());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod = new GetMethod(getBaseURI() + "/context/request/date");
+ getMethod.setRequestHeader("If-Modified-Since", formatter.format(d2));
+ try {
+ /*
+ * verifies that using a If-Modified-Since earlier than the
+ * Last-Modified response header sent by server then the server will
+ * return a 200 with entity
+ */
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("the date: " + rfc1123Format.format(d), getMethod
+ .getResponseBodyAsString());
+
+ rfc1123Format.setTimeZone(TimeZone.getTimeZone("GMT"));
+ assertEquals(rfc1123Format.format(d), getMethod.getResponseHeader("Last-Modified")
+ .getValue());
+ rfc1123Format.setTimeZone(TimeZone.getDefault());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod = new GetMethod(getBaseURI() + "/context/request/date");
+ getMethod.setRequestHeader("If-Modified-Since", formatter.format(new Date()));
+ try {
+ /*
+ * verifies that using a If-Modified-Since later than the
+ * Last-Modified response header sent by server, then the server
+ * will return a 304
+ */
+ client.executeMethod(getMethod);
+ assertEquals(304, getMethod.getStatusCode());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link Request#evaluatePreconditions(Date)} that uses the
+ * <code>If-Unmodified-Since</code> header using RFC 1123.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testEvaluateDateIfUnmodifiedSinceUsingRFC1123() throws HttpException, IOException {
+ checkIfUnmodifiedSinceUsingSuppliedDateFormat(rfc1123Format);
+ }
+
+ /**
+ * Tests the {@link Request#evaluatePreconditions(Date)} that uses the
+ * <code>If-Unmodified-Since</code> header using RFC 850.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testEvaluateDateIfUnmodifiedSinceUsingRFC850() throws HttpException, IOException {
+ checkIfUnmodifiedSinceUsingSuppliedDateFormat(rfc850Format);
+ }
+
+ /**
+ * Tests the {@link Request#evaluatePreconditions(Date)} that uses the
+ * <code>If-Unmodified-Since</code> header using Asctime.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testEvaluateDateIfUnmodifiedSinceUsingAscTime() throws HttpException, IOException {
+ SimpleDateFormat dateFormat =
+ (Calendar.getInstance().get(Calendar.DAY_OF_MONTH) < 10)
+ ? asctimeDateFormatWithOneDigit : asctimeDateFormat;
+ checkIfUnmodifiedSinceUsingSuppliedDateFormat(dateFormat);
+ }
+
+ private void checkIfUnmodifiedSinceUsingSuppliedDateFormat(SimpleDateFormat formatter)
+ throws IOException, HttpException {
+ HttpClient client = new HttpClient();
+
+ PutMethod putMethod = new PutMethod(getBaseURI() + "/context/request/date");
+ Date d2 = new Date(System.currentTimeMillis() - 120000);
+ Date d = new Date(System.currentTimeMillis() - 60000);
+ String date = DateFormat.getDateTimeInstance().format(d);
+ putMethod.setRequestEntity(new StringRequestEntity(date, "text/string", "UTF-8"));
+ try {
+ /*
+ * sets a last modified date
+ */
+ client.executeMethod(putMethod);
+ assertEquals(204, putMethod.getStatusCode());
+ } finally {
+ putMethod.releaseConnection();
+ }
+
+ GetMethod getMethod = new GetMethod(getBaseURI() + "/context/request/date");
+ getMethod.setRequestHeader("If-Unmodified-Since", formatter.format(d));
+ try {
+ /*
+ * verifies that if the exact date is sent in and used in
+ * If-Unmodified-Since header, then the server will be ok and that
+ * it will return 200
+ */
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("the date: " + rfc1123Format.format(d), getMethod
+ .getResponseBodyAsString());
+
+ rfc1123Format.setTimeZone(TimeZone.getTimeZone("GMT"));
+ assertEquals(rfc1123Format.format(d), getMethod.getResponseHeader("Last-Modified")
+ .getValue());
+ rfc1123Format.setTimeZone(TimeZone.getDefault());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod = new GetMethod(getBaseURI() + "/context/request/date");
+ try {
+ /*
+ * verifies that if no If-Unmodified-Since header is sent, then the
+ * server will be ok and the Request instance won't build a
+ * response.
+ */
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("the date: " + rfc1123Format.format(d), getMethod
+ .getResponseBodyAsString());
+
+ rfc1123Format.setTimeZone(TimeZone.getTimeZone("GMT"));
+ assertEquals(rfc1123Format.format(d), getMethod.getResponseHeader("Last-Modified")
+ .getValue());
+ rfc1123Format.setTimeZone(TimeZone.getDefault());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ String lastModified = getMethod.getResponseHeader("Last-Modified").getValue();
+
+ getMethod = new GetMethod(getBaseURI() + "/context/request/date");
+ getMethod.setRequestHeader("If-Unmodified-Since", lastModified);
+ try {
+ /*
+ * verifies that using Last-Modified response header sent by server
+ * as If-Unmodified-Since request header, then the server will
+ * return the entity
+ */
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("the date: " + rfc1123Format.format(d), getMethod
+ .getResponseBodyAsString());
+
+ rfc1123Format.setTimeZone(TimeZone.getTimeZone("GMT"));
+ assertEquals(rfc1123Format.format(d), getMethod.getResponseHeader("Last-Modified")
+ .getValue());
+ rfc1123Format.setTimeZone(TimeZone.getDefault());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod = new GetMethod(getBaseURI() + "/context/request/date");
+ getMethod.setRequestHeader("If-Unmodified-Since", formatter.format(d2));
+ try {
+ /*
+ * verifies that using a If-Unmodified-Since earlier than the
+ * Last-Modified response header sent by server then the server will
+ * return a 412
+ */
+ client.executeMethod(getMethod);
+ assertEquals(412, getMethod.getStatusCode());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod = new GetMethod(getBaseURI() + "/context/request/date");
+ getMethod.setRequestHeader("If-Unmodified-Since", formatter.format(new Date()));
+ try {
+ /*
+ * verifies that using a If-Unmodified-Since later than the
+ * Last-Modified response header sent by server, then the server
+ * will return 200 and the entity
+ */
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("the date: " + rfc1123Format.format(d), getMethod
+ .getResponseBodyAsString());
+
+ rfc1123Format.setTimeZone(TimeZone.getTimeZone("GMT"));
+ assertEquals(rfc1123Format.format(d), getMethod.getResponseHeader("Last-Modified")
+ .getValue());
+ rfc1123Format.setTimeZone(TimeZone.getDefault());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the
+ * {@link Request#evaluatePreconditions(javax.ws.rs.core.EntityTag)} that
+ * uses the <code>If-Match</code> header and a strong ETag.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testEvaluateEtagIfMatchStrong() throws HttpException, IOException {
+ try {
+ checkETagIfMatch("\"myentitytagABCXYZ\"", false);
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * Tests the
+ * {@link Request#evaluatePreconditions(javax.ws.rs.core.EntityTag)} that
+ * uses the <code>If-Match</code> header and a weak ETag.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testEvaluateEtagIfMatchWeak() throws HttpException, IOException {
+ try {
+ checkETagIfMatch("\"myentitytagABCXYZ\"", true);
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * Tests the
+ * {@link Request#evaluatePreconditions(javax.ws.rs.core.EntityTag)} that
+ * uses the <code>If-Match</code> header.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void checkETagIfMatch(String etag, boolean isEntityTagWeak) throws HttpException,
+ IOException {
+ HttpClient client = new HttpClient();
+
+ final String justTheTag = etag;
+ final String setETag = isEntityTagWeak ? "W/" + justTheTag : justTheTag;
+ String isWeak = isEntityTagWeak ? "true" : "false";
+
+ PutMethod putMethod = new PutMethod(getBaseURI() + "/context/request/etag");
+ putMethod.setRequestEntity(new StringRequestEntity(setETag, "text/string", "UTF-8"));
+ try {
+ /*
+ * sets an entity tag
+ */
+ client.executeMethod(putMethod);
+ assertEquals(204, putMethod.getStatusCode());
+ } finally {
+ putMethod.releaseConnection();
+ }
+
+ GetMethod getMethod = new GetMethod(getBaseURI() + "/context/request/etag");
+ getMethod.setRequestHeader("If-Match", setETag);
+ try {
+ /*
+ * verifies that if the exact etag is sent in, then the request is
+ * allowed to proceed
+ */
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("the etag: " + justTheTag + isWeak, getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod = new GetMethod(getBaseURI() + "/context/request/etag");
+ try {
+ /*
+ * verifies that a request without an If-Match header will still
+ * proceed
+ */
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("the etag: " + justTheTag + isWeak, getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod = new GetMethod(getBaseURI() + "/context/request/etag");
+ getMethod.setRequestHeader("If-Match", setETag.substring(1, setETag.length() - 1));
+ try {
+ /*
+ * verifies that an unquoted entity tag is not a valid entity tag
+ */
+ client.executeMethod(getMethod);
+ assertEquals(400, getMethod.getStatusCode());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod = new GetMethod(getBaseURI() + "/context/request/etag");
+ getMethod.setRequestHeader("If-Match", setETag.substring(0, setETag.length() - 1));
+ try {
+ /*
+ * verifies that a misquoted entity tag is not a valid entity tag
+ */
+ client.executeMethod(getMethod);
+ assertEquals(400, getMethod.getStatusCode());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod = new GetMethod(getBaseURI() + "/context/request/etag");
+ getMethod.setRequestHeader("If-Match", setETag.substring(1, setETag.length()));
+ try {
+ /*
+ * verifies that a misquoted entity tag is not a valid entity tag
+ */
+ client.executeMethod(getMethod);
+ assertEquals(400, getMethod.getStatusCode());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod = new GetMethod(getBaseURI() + "/context/request/etag");
+ getMethod.setRequestHeader("If-Match", "\"someothervalue\"");
+ try {
+ /*
+ * verifies that if an etag is sent that does not match the server
+ * etag, that a 412 is returned
+ */
+ client.executeMethod(getMethod);
+ assertEquals(412, getMethod.getStatusCode());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod = new GetMethod(getBaseURI() + "/context/request/etag");
+ getMethod.setRequestHeader("If-Match", "\"austin\", \"powers\"");
+ try {
+ /*
+ * verifies that if multiple etags are sent that do not match the
+ * server etag, that a 412 is returned
+ */
+ client.executeMethod(getMethod);
+ assertEquals(412, getMethod.getStatusCode());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod = new GetMethod(getBaseURI() + "/context/request/etag");
+ getMethod.addRequestHeader("If-Match", "\"austin\", \"powers\"");
+ try {
+ /*
+ * verifies that if multiple etags are sent that do not match the
+ * server etag, that a 412 is returned
+ */
+ client.executeMethod(getMethod);
+ assertEquals(412, getMethod.getStatusCode());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod = new GetMethod(getBaseURI() + "/context/request/etag");
+ getMethod.addRequestHeader("If-Match", "\"austin\", " + setETag + " , \"powers\"");
+ try {
+ /*
+ * verifies that if multiple etags are sent that do match the server
+ * etag, that a 200 and entity body is returned
+ */
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("the etag: " + justTheTag + isWeak, getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the
+ * {@link Request#evaluatePreconditions(javax.ws.rs.core.EntityTag)} that
+ * uses the <code>If-None-Match</code> header with strong entity tag.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testEvaluateEtagIfNoneMatchStrong() throws HttpException, IOException {
+ checkETagIfNoneMatch("\"myentitytagABCXYZ\"", false);
+ }
+
+ /**
+ * Tests the
+ * {@link Request#evaluatePreconditions(javax.ws.rs.core.EntityTag)} that
+ * uses the <code>If-None-Match</code> header with weak entity tag.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testEvaluateEtagIfNoneMatchWeak() throws HttpException, IOException {
+ checkETagIfNoneMatch("\"myentitytagABCXYZ\"", true);
+ }
+
+ /**
+ * Tests the
+ * {@link Request#evaluatePreconditions(javax.ws.rs.core.EntityTag)} that
+ * uses the <code>If-None-Match</code> header.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void checkETagIfNoneMatch(String etag, boolean isEntityTagWeak) throws HttpException,
+ IOException {
+ HttpClient client = new HttpClient();
+ final String justTheTag = etag;
+ final String setETag = isEntityTagWeak ? "W/" + justTheTag : justTheTag;
+ String isWeak = isEntityTagWeak ? "true" : "false";
+
+ PutMethod putMethod = new PutMethod(getBaseURI() + "/context/request/etag");
+ putMethod.setRequestEntity(new StringRequestEntity(setETag, "text/string", "UTF-8"));
+ try {
+ /*
+ * sets an entity tag
+ */
+ client.executeMethod(putMethod);
+ assertEquals(204, putMethod.getStatusCode());
+ } finally {
+ putMethod.releaseConnection();
+ }
+
+ GetMethod getMethod = new GetMethod(getBaseURI() + "/context/request/etag");
+ getMethod.setRequestHeader("If-None-Match", setETag);
+ try {
+ /*
+ * verifies that if the exact etag is sent in, then the response is
+ * a 304
+ */
+ client.executeMethod(getMethod);
+ assertEquals(304, getMethod.getStatusCode());
+ assertEquals(setETag, getMethod.getResponseHeader("ETag").getValue());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod = new GetMethod(getBaseURI() + "/context/request/etag");
+ getMethod.setRequestHeader("If-None-Match", "\"*\"");
+ try {
+ /*
+ * verifies that if a "*" etag is sent in, then the response returns
+ * a 304
+ */
+ client.executeMethod(getMethod);
+ assertEquals(304, getMethod.getStatusCode());
+ assertEquals(setETag, getMethod.getResponseHeader("ETag").getValue());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ PostMethod postMethod = new PostMethod(getBaseURI() + "/context/request/etag");
+ postMethod.setRequestHeader("If-None-Match", setETag);
+ try {
+ /*
+ * verifies that if a matching etag is sent in, then the response
+ * returns a 412
+ */
+ client.executeMethod(postMethod);
+ assertEquals(412, postMethod.getStatusCode());
+ assertEquals(setETag, postMethod.getResponseHeader("ETag").getValue());
+ } finally {
+ postMethod.releaseConnection();
+ }
+
+ postMethod = new PostMethod(getBaseURI() + "/context/request/etag");
+ postMethod.setRequestHeader("If-None-Match", "\"*\"");
+ try {
+ /*
+ * verifies that if a "*" etag is sent in, then the response returns
+ * a 412
+ */
+ client.executeMethod(postMethod);
+ assertEquals(412, postMethod.getStatusCode());
+ assertEquals(setETag, postMethod.getResponseHeader("ETag").getValue());
+ } finally {
+ postMethod.releaseConnection();
+ }
+
+ getMethod = new GetMethod(getBaseURI() + "/context/request/etag");
+ try {
+ /*
+ * verifies that a request without an If-None-Match header will
+ * still proceed
+ */
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("the etag: " + justTheTag + isWeak, getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ postMethod = new PostMethod(getBaseURI() + "/context/request/etag");
+ try {
+ /*
+ * verifies that a request without an If-None-Match header will
+ * still proceed
+ */
+ client.executeMethod(postMethod);
+ assertEquals(200, postMethod.getStatusCode());
+ assertEquals("the etag: " + justTheTag + isWeak, postMethod.getResponseBodyAsString());
+ } finally {
+ postMethod.releaseConnection();
+ }
+
+ getMethod = new GetMethod(getBaseURI() + "/context/request/etag");
+ getMethod.setRequestHeader("If-None-Match", setETag.substring(1, setETag.length() - 1));
+ try {
+ /*
+ * verifies that an unquoted entity tag is invalid
+ */
+ client.executeMethod(getMethod);
+ assertEquals(400, getMethod.getStatusCode());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod = new GetMethod(getBaseURI() + "/context/request/etag");
+ getMethod.setRequestHeader("If-None-Match", setETag.substring(0, setETag.length() - 1));
+ try {
+ /*
+ * verifies that a misquoted entity tag is invalid
+ */
+ client.executeMethod(getMethod);
+ assertEquals(400, getMethod.getStatusCode());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod = new GetMethod(getBaseURI() + "/context/request/etag");
+ getMethod.setRequestHeader("If-None-Match", setETag.substring(1, setETag.length()));
+ try {
+ /*
+ * verifies that a misquoted entity tag is invalid
+ */
+ client.executeMethod(getMethod);
+ assertEquals(400, getMethod.getStatusCode());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod = new GetMethod(getBaseURI() + "/context/request/etag");
+ getMethod.setRequestHeader("If-None-Match", "\"someothervalue\"");
+ try {
+ /*
+ * verifies that if an etag is sent that does not match the server
+ * etag, that request is allowed to proceed
+ */
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("the etag: " + justTheTag + isWeak, getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod = new GetMethod(getBaseURI() + "/context/request/etag");
+ getMethod.setRequestHeader("If-None-Match", "\"austin\", \"powers\"");
+ try {
+ /*
+ * verifies that if multiple etags are sent that do not match the
+ * server etag, that the request is allowed to proceed
+ */
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("the etag: " + justTheTag + isWeak, getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod = new GetMethod(getBaseURI() + "/context/request/etag");
+ getMethod.addRequestHeader("If-None-Match", "\"austin\", \"powers\"");
+ try {
+ /*
+ * verifies that if multiple etags are sent that do not match the
+ * server etag, then a 200 and the request entity is returned
+ */
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("the etag: " + justTheTag + isWeak, getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ postMethod = new PostMethod(getBaseURI() + "/context/request/etag");
+ postMethod.addRequestHeader("If-None-Match", "\"austin\", \"powers\"");
+ try {
+ /*
+ * verifies that a request without an If-None-Match header will
+ * still proceed
+ */
+ client.executeMethod(postMethod);
+ assertEquals(200, postMethod.getStatusCode());
+ assertEquals("the etag: " + justTheTag + isWeak, postMethod.getResponseBodyAsString());
+ } finally {
+ postMethod.releaseConnection();
+ }
+
+ getMethod = new GetMethod(getBaseURI() + "/context/request/etag");
+ getMethod.addRequestHeader("If-None-Match", "\"austin\", " + setETag + " , \"powers\"");
+ try {
+ /*
+ * verifies that if multiple etags are sent that do match the server
+ * etag, that a 304 is returned
+ */
+ client.executeMethod(getMethod);
+ assertEquals(304, getMethod.getStatusCode());
+ assertEquals(setETag, getMethod.getResponseHeader("ETag").getValue());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ postMethod = new PostMethod(getBaseURI() + "/context/request/etag");
+ postMethod.addRequestHeader("If-None-Match", "\"austin\", " + setETag + " , \"powers\"");
+ try {
+ /*
+ * verifies that a request with an If-None-Match header will fail
+ */
+ client.executeMethod(postMethod);
+ assertEquals(412, postMethod.getStatusCode());
+ assertEquals(setETag, getMethod.getResponseHeader("ETag").getValue());
+ } finally {
+ postMethod.releaseConnection();
+ }
+ }
+
+ // TODO: add selectVariant tests by querying the various
+ // /context/request/variant/* paths
+
+}
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-context/src/test/java/org/apache/wink/jaxrs/test/context/securitycontext/SecurityContextTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-context/src/test/java/org/apache/wink/jaxrs/test/context/securitycontext/SecurityContextTest.java?rev=796113&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-context/src/test/java/org/apache/wink/jaxrs/test/context/securitycontext/SecurityContextTest.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-context/src/test/java/org/apache/wink/jaxrs/test/context/securitycontext/SecurityContextTest.java Tue Jul 21 01:45:53 2009
@@ -0,0 +1,190 @@
+/*
+ * 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.context.securitycontext;
+
+import java.io.IOException;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.wink.jaxrs.test.context.securitycontext.xml.ObjectFactory;
+import org.apache.wink.jaxrs.test.context.securitycontext.xml.SecurityContextInfo;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+public class SecurityContextTest extends TestCase {
+
+ public String getBaseURI() {
+ return ServerEnvironmentInfo.getBaseURI() + "/securitycontext";
+ }
+
+ /**
+ * Tests that a security context can be injected via a parameter.
+ *
+ * @throws IOException
+ * @throws HttpException
+ * @throws JAXBException
+ */
+ public void testSecurityContextParamResource() throws HttpException, IOException, JAXBException {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod = new GetMethod(getBaseURI() + "/context/securitycontext/param");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+
+ JAXBContext context =
+ JAXBContext.newInstance(ObjectFactory.class.getPackage().getName());
+ SecurityContextInfo secContextInfo =
+ (SecurityContextInfo)context.createUnmarshaller().unmarshal(getMethod
+ .getResponseBodyAsStream());
+ assertNotNull(secContextInfo);
+ assertEquals(false, secContextInfo.isSecure());
+ assertEquals(false, secContextInfo.isUserInRoleAdmin());
+ assertEquals(false, secContextInfo.isUserInRoleNull());
+ assertEquals(false, secContextInfo.isUserInRoleUser());
+ assertEquals("null", secContextInfo.getUserPrincipal());
+ assertNull(secContextInfo.getAuthScheme());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a security context can be injected via a constructor.
+ *
+ * @throws IOException
+ * @throws HttpException
+ * @throws JAXBException
+ */
+ public void testSecurityContextConstructorResource() throws HttpException, IOException,
+ JAXBException {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod = new GetMethod(getBaseURI() + "/context/securitycontext/constructor");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+
+ JAXBContext context =
+ JAXBContext.newInstance(ObjectFactory.class.getPackage().getName());
+ SecurityContextInfo secContextInfo =
+ (SecurityContextInfo)context.createUnmarshaller().unmarshal(getMethod
+ .getResponseBodyAsStream());
+ assertNotNull(secContextInfo);
+ assertEquals(false, secContextInfo.isSecure());
+ assertEquals(false, secContextInfo.isUserInRoleAdmin());
+ assertEquals(false, secContextInfo.isUserInRoleNull());
+ assertEquals(false, secContextInfo.isUserInRoleUser());
+ assertEquals("null", secContextInfo.getUserPrincipal());
+ assertNull(secContextInfo.getAuthScheme());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a security context can be injected via a bean method.
+ *
+ * @throws IOException
+ * @throws HttpException
+ * @throws JAXBException
+ */
+ public void testSecurityContextBeanResource() throws HttpException, IOException, JAXBException {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod = new GetMethod(getBaseURI() + "/context/securitycontext/bean");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+
+ JAXBContext context =
+ JAXBContext.newInstance(ObjectFactory.class.getPackage().getName());
+ SecurityContextInfo secContextInfo =
+ (SecurityContextInfo)context.createUnmarshaller().unmarshal(getMethod
+ .getResponseBodyAsStream());
+ assertNotNull(secContextInfo);
+ assertEquals(false, secContextInfo.isSecure());
+ assertEquals(false, secContextInfo.isUserInRoleAdmin());
+ assertEquals(false, secContextInfo.isUserInRoleNull());
+ assertEquals(false, secContextInfo.isUserInRoleUser());
+ assertEquals("null", secContextInfo.getUserPrincipal());
+ assertNull(secContextInfo.getAuthScheme());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a security context will not be injected into non-bean methods.
+ *
+ * @throws IOException
+ * @throws HttpException
+ */
+ public void testSecurityContextNotBeanResource() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod =
+ new GetMethod(getBaseURI() + "/context/securitycontext/notbeanmethod");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals(getMethod.getResponseBodyAsString(), "false");
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a security context can be injected via a member field.
+ *
+ * @throws IOException
+ * @throws HttpException
+ * @throws JAXBException
+ */
+ public void testSecurityContextFieldResource() throws HttpException, IOException, JAXBException {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod = new GetMethod(getBaseURI() + "/context/securitycontext/field");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+
+ JAXBContext context =
+ JAXBContext.newInstance(ObjectFactory.class.getPackage().getName());
+ SecurityContextInfo secContextInfo =
+ (SecurityContextInfo)context.createUnmarshaller().unmarshal(getMethod
+ .getResponseBodyAsStream());
+ assertNotNull(secContextInfo);
+ assertEquals(false, secContextInfo.isSecure());
+ assertEquals(false, secContextInfo.isUserInRoleAdmin());
+ assertEquals(false, secContextInfo.isUserInRoleNull());
+ assertEquals(false, secContextInfo.isUserInRoleUser());
+ assertEquals("null", secContextInfo.getUserPrincipal());
+ assertNull(secContextInfo.getAuthScheme());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+}
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-context/src/test/java/org/apache/wink/jaxrs/test/context/uriinfo/URIInfoDetailedMethodTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-context/src/test/java/org/apache/wink/jaxrs/test/context/uriinfo/URIInfoDetailedMethodTest.java?rev=796113&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-context/src/test/java/org/apache/wink/jaxrs/test/context/uriinfo/URIInfoDetailedMethodTest.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-context/src/test/java/org/apache/wink/jaxrs/test/context/uriinfo/URIInfoDetailedMethodTest.java Tue Jul 21 01:45:53 2009
@@ -0,0 +1,913 @@
+/*
+ * 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.context.uriinfo;
+
+import java.io.IOException;
+
+import javax.ws.rs.core.UriInfo;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+/**
+ * Tests that various {@link UriInfo} methods work as expected.
+ */
+public class URIInfoDetailedMethodTest extends TestCase {
+
+ public String appBase = "/uriinfo";
+
+ public String getBaseURI() {
+ return ServerEnvironmentInfo.getBaseURI() + appBase;
+ }
+
+ /**
+ * Tests the {@link UriInfo#getAbsolutePath()}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetAbsolutePath() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(getBaseURI() + "/context/uriinfo/detailed?reqInfo=getAbsolutePath");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals(getBaseURI() + "/context/uriinfo/detailed", getMethod
+ .getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getAbsolutePathBuilder()}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetAbsoluteBuilder() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(getBaseURI() + "/context/uriinfo/detailed?reqInfo=getAbsolutePathBuilder");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals(getBaseURI().replace(ServerEnvironmentInfo.getHostname(), "abcd") + "/context/uriinfo/detailed",
+ getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getBaseUri()}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetBaseUri() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(getBaseURI() + "/context/uriinfo/detailed?reqInfo=getBaseUri");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals(getBaseURI() + "/", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getBaseUriBuilder()}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetBaseUriBuilder() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(getBaseURI() + "/context/uriinfo/detailed?reqInfo=getBaseUriBuilder");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ String contextRoot = ServerEnvironmentInfo.getContextRoot();
+ if (!"".equals(contextRoot)) {
+ contextRoot = "/" + contextRoot;
+ }
+ String baseUri =
+ "http://" + "abcd"
+ + ":"
+ + ServerEnvironmentInfo.getPort()
+ + contextRoot
+ + appBase
+ + "/";
+ assertEquals(baseUri, getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getPath()}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetPath() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(getBaseURI() + "/context/uriinfo/detailed?reqInfo=getPath");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("context/uriinfo/detailed", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getPath(boolean)}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetPathDecoded() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(getBaseURI() + "/context/uriinfo/detailed?reqInfo=getPathDecodedTrue");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("context/uriinfo/detailed", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod =
+ new GetMethod(getBaseURI() + "/context/uriinfo/detailed?reqInfo=getPathDecodedFalse");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("context/uriinfo/detailed", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod =
+ new GetMethod(
+ getBaseURI() + "/context/uriinfo/detailed/decoded/!%40%23%24%25%5E%26*()?decoded=false");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("context/uriinfo/detailed/decoded/!%40%23%24%25%5E%26*()", getMethod
+ .getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod =
+ new GetMethod(
+ getBaseURI() + "/context/uriinfo/detailed/decoded/!%40%23%24%25%5E%26*()?decoded=true");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("context/uriinfo/detailed/decoded/!@#$%^&*()", getMethod
+ .getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ }
+
+ /**
+ * Tests the {@link UriInfo#getMatchedResources()}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetMatchedResourcesSimple() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(getBaseURI() + "/context/uriinfo/detailed?reqInfo=getMatchedResources");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals(UriInfoDetailedMethods.class.getName() + ":", getMethod
+ .getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getMatchedResources()} in a sub resource method.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetMatchedResourcesSubresource() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(getBaseURI() + "/context/uriinfo/detailed/matchedresources");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals(UriInfoDetailedMethods.class.getName() + ":"
+ + "-"
+ + MatchedResourcesSubResource.class.getName()
+ + ":"
+ + UriInfoDetailedMethods.class.getName()
+ + ":", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getMatchedURIs()}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetMatchedURIs() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(getBaseURI() + "/context/uriinfo/detailed?reqInfo=getMatchedURIs");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("context/uriinfo/detailed" + ":", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getMatchedURIs()} in a sub-resource method.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetMatchedURIsSubresource() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod = new GetMethod(getBaseURI() + "/context/uriinfo/detailed/matcheduris");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("context/uriinfo/detailed/matcheduris" + ":"
+ + "context/uriinfo/detailed"
+ + ":"
+ + "-"
+ + "context/uriinfo/detailed/matcheduris"
+ + ":"
+ + "context/uriinfo/detailed"
+ + ":", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getMatchedURIs(boolean)}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetMatchedURIsDecodeTrue() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(
+ getBaseURI() + "/context/uriinfo/detailed?reqInfo=getMatchedURIsDecodedTrue");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("context/uriinfo/detailed" + ":", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getMatchedURIs(boolean)}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetMatchedURIsDecodeFalse() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(
+ getBaseURI() + "/context/uriinfo/detailed?reqInfo=getMatchedURIsDecodedFalse");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("context/uriinfo/detailed" + ":", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getMatchedURIs(boolean)} in a sub-locator.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetMatchedURIsSublocatorDecodeTrue() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(
+ getBaseURI() + "/context/uriinfo/detailed/matchedurisdecoded/!%40%23%24%25%5E%26*()?decoded=true");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("context/uriinfo/detailed/matchedurisdecoded/!@#$%^&*()", getMethod
+ .getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getMatchedURIs(boolean)} in a sub-locator.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetMatchedURIsSublocatorDecodeFalse() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(
+ getBaseURI() + "/context/uriinfo/detailed/matchedurisdecoded/!%40%23%24%25%5E%26*()?decoded=false");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("context/uriinfo/detailed/matchedurisdecoded/!%40%23%24%25%5E%26*()",
+ getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getPathParameters()}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetPathParametersZero() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(getBaseURI() + "/context/uriinfo/detailed?reqInfo=getPathParameters");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getPathParameters()}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetPathParametersOne() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(getBaseURI() + "/context/uriinfo/detailed/pathparamsone/");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("p1=/:", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod = new GetMethod(getBaseURI() + "/context/uriinfo/detailed/pathparamsone");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("p1=:", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod = new GetMethod(getBaseURI() + "/context/uriinfo/detailed/pathparamsone/foo");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("p1=/foo:", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod = new GetMethod(getBaseURI() + "/context/uriinfo/detailed/pathparamsone/foo/bar");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("p1=/foo/bar:", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getPathParameters()}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetPathParametersMany() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(getBaseURI() + "/context/uriinfo/detailed/pathparamsmany/foo/bar/xyz");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("p1=foo:p2=b:p3=ar/xyz:", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod =
+ new GetMethod(getBaseURI() + "/context/uriinfo/detailed/pathparamsmany/foo/bar");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("p1=foo:p2=b:p3=ar:", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getPathParameters(boolean)}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetPathParametersZeroDecodedFalse() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(
+ getBaseURI() + "/context/uriinfo/detailed?reqInfo=getPathParametersDecodedFalse");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getPathParameters(boolean)}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetPathParametersOneDecodedFalse() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(getBaseURI() + "/context/uriinfo/detailed/pathparamsone/?decoded=false");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("p1=/:", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod =
+ new GetMethod(getBaseURI() + "/context/uriinfo/detailed/pathparamsone?decoded=false");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("p1=:", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod =
+ new GetMethod(
+ getBaseURI() + "/context/uriinfo/detailed/pathparamsone/!%40%23%24%25%5E%26*()?decoded=false");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("p1=/!%40%23%24%25%5E%26*():", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod =
+ new GetMethod(
+ getBaseURI() + "/context/uriinfo/detailed/pathparamsone/!%40%23%24%25%5E%26*()/!%40%23%24%25%5E%26*()?decoded=false");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("p1=/!%40%23%24%25%5E%26*()/!%40%23%24%25%5E%26*():", getMethod
+ .getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getPathParameters(boolean)}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetPathParametersManyDecodedFalse() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(
+ getBaseURI() + "/context/uriinfo/detailed/pathparamsmany/foo/bar/xyz?decoded=false");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("p1=foo:p2=b:p3=ar/xyz:", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod =
+ new GetMethod(
+ getBaseURI() + "/context/uriinfo/detailed/pathparamsmany/foo/bar?decoded=false");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("p1=foo:p2=b:p3=ar:", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getPathParameters(boolean)}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetPathParametersZeroDecodedTrue() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(
+ getBaseURI() + "/context/uriinfo/detailed?reqInfo=getPathParametersDecodedTrue");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getPathParameters(boolean)}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetPathParametersOneDecodedTrue() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(getBaseURI() + "/context/uriinfo/detailed/pathparamsone/?decoded=true");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("p1=/:", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod =
+ new GetMethod(getBaseURI() + "/context/uriinfo/detailed/pathparamsone?decoded=true");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("p1=:", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod =
+ new GetMethod(
+ getBaseURI() + "/context/uriinfo/detailed/pathparamsone/!%40%23%24%25%5E%26*()?decoded=true");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("p1=/!@#$%^&*():", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod =
+ new GetMethod(
+ getBaseURI() + "/context/uriinfo/detailed/pathparamsone/!%40%23%24%25%5E%26*()/!%40%23%24%25%5E%26*()?decoded=true");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("p1=/!@#$%^&*()/!@#$%^&*():", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getPathParameters(boolean)}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetPathParametersManyDecodedTrue() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(
+ getBaseURI() + "/context/uriinfo/detailed/pathparamsmany/!%40%23%24%25%5E%26*()/bar/xyz?decoded=true");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("p1=!@#$%^&*():p2=b:p3=ar/xyz:", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod =
+ new GetMethod(
+ getBaseURI() + "/context/uriinfo/detailed/pathparamsmany/!%40%23%24%25%5E%26*()/bar?decoded=true");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("p1=!@#$%^&*():p2=b:p3=ar:", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getPathSegments()}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetPathSegments() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(getBaseURI() + "/context/uriinfo/detailed?reqInfo=getPathSegments");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("context#:uriinfo#:detailed#:", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod =
+ new GetMethod(
+ getBaseURI() + "/context;matrixp1=value1;matrixp2=value2;foo=bar/uriinfo/detailed?reqInfo=getPathSegments");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("context#foo=bar:matrixp1=value1:matrixp2=value2::uriinfo#:detailed#:",
+ getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod =
+ new GetMethod(
+ getBaseURI() + "/context;matrixp1=!%40%23%24%25%5E%26*();matrixp2=value2;foo=bar/uriinfo/detailed?reqInfo=getPathSegments");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("context#foo=bar:matrixp1=!@#$%^&*():matrixp2=value2::uriinfo#:detailed#:",
+ getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getPathSegments(boolean)}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetPathSegmentsDecodedFalse() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(
+ getBaseURI() + "/context/uriinfo/detailed?reqInfo=getPathSegmentsDecodedFalse");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("context#:uriinfo#:detailed#:", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod =
+ new GetMethod(
+ getBaseURI() + "/context;matrixp1=value1;matrixp2=value2;foo=bar/uriinfo/detailed?reqInfo=getPathSegmentsDecodedFalse");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("context#foo=bar:matrixp1=value1:matrixp2=value2::uriinfo#:detailed#:",
+ getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod =
+ new GetMethod(
+ getBaseURI() + "/context;matrixp1=!%40%23%24%25%5E%26*();matrixp2=value2;foo=bar/uriinfo/detailed?reqInfo=getPathSegmentsDecodedFalse");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("context#foo=bar:matrixp1=!%40%23%24%25%5E%26*():matrixp2=value2::uriinfo#:detailed#:",
+ getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getQueryParameters()}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetQueryParametersZero() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod = new GetMethod(getBaseURI() + "/context/uriinfo/detailed/queryparams");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getQueryParameters()}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetQueryParametersOne() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(getBaseURI() + "/context/uriinfo/detailed?reqInfo=getQueryParameters");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("reqInfo=getQueryParameters:", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod =
+ new GetMethod(
+ getBaseURI() + "/context/uriinfo/detailed/queryparams?q1=value1&q1=value2");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("q1=value1:value2:", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ getMethod =
+ new GetMethod(
+ getBaseURI() + "/context/uriinfo/detailed/queryparams?q1=value1&q1=value2");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("q1=value1:value2:", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getQueryParameters()}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetQueryParametersMany() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(
+ getBaseURI() + "/context/uriinfo/detailed/queryparams?q1=value1&q2=value2");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("q1=value1:q2=value2:", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+
+ getMethod =
+ new GetMethod(
+ getBaseURI() + "/context/uriinfo/detailed/queryparams?q1=!%40%23%24%25%5E%26*()&q2=value2");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("q1=!@#$%^&*():q2=value2:", getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getQueryParameters(boolean)}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetQueryParametersManyDecodedFalse() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(
+ getBaseURI() + "/context/uriinfo/detailed/queryparams?q1=!%40%23%24%25%5E%26*()&q2=value2&decoded=false");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("decoded=false:q1=!%40%23%24%25%5E%26*():q2=value2:", getMethod
+ .getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getRequestUri()}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetRequestUri() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(getBaseURI() + "/context/uriinfo/detailed?reqInfo=getRequestUri");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals(getBaseURI() + "/context/uriinfo/detailed?reqInfo=getRequestUri",
+ getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests the {@link UriInfo#getRequestUriBuilder()}.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testURIInfoGetRequestUriBuilder() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod =
+ new GetMethod(getBaseURI() + "/context/uriinfo/detailed?reqInfo=getRequestUriBuilder");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ String expected =
+ (getBaseURI() + "/context/uriinfo/detailed?reqInfo=getRequestUriBuilder")
+ .replace(ServerEnvironmentInfo.getHostname(), "abcd");
+ assertEquals(expected, getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+}
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-context/src/test/java/org/apache/wink/jaxrs/test/context/uriinfo/URIInfoInjectionTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-context/src/test/java/org/apache/wink/jaxrs/test/context/uriinfo/URIInfoInjectionTest.java?rev=796113&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-context/src/test/java/org/apache/wink/jaxrs/test/context/uriinfo/URIInfoInjectionTest.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-context/src/test/java/org/apache/wink/jaxrs/test/context/uriinfo/URIInfoInjectionTest.java Tue Jul 21 01:45:53 2009
@@ -0,0 +1,125 @@
+/*
+ * 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.context.uriinfo;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+/**
+ * Tests that the UriInfo can be injected via various means.
+ */
+public class URIInfoInjectionTest extends TestCase {
+
+ public String getBaseURI() {
+ return ServerEnvironmentInfo.getBaseURI() + "/uriinfo";
+ }
+
+ /**
+ * Tests that a URIInfo object is injected into method parameters.
+ *
+ * @throws IOException
+ * @throws HttpException
+ */
+ public void testURIInfoParamInjection() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod = new GetMethod(getBaseURI() + "/context/uriinfo/param");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(204, getMethod.getStatusCode());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a URIInfo object is injected via a bean method.
+ *
+ * @throws IOException
+ * @throws HttpException
+ */
+ public void testURIInfoBeanMethodInjection() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod = new GetMethod(getBaseURI() + "/context/uriinfo/bean");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(204, getMethod.getStatusCode());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a URIInfo object is injected via a constructor parameter.
+ *
+ * @throws IOException
+ * @throws HttpException
+ */
+ public void testURIInfoConstructorInjection() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod = new GetMethod(getBaseURI() + "/context/uriinfo/constructor");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(204, getMethod.getStatusCode());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a URIInfo object is injected via a field member.
+ *
+ * @throws IOException
+ * @throws HttpException
+ */
+ public void testURIInfoFieldMemberInjection() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod = new GetMethod(getBaseURI() + "/context/uriinfo/field");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(204, getMethod.getStatusCode());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a URIInfo object is not injected via non bean methods.
+ *
+ * @throws IOException
+ * @throws HttpException
+ */
+ public void testURIInfoNotBeanMethod() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+ GetMethod getMethod = new GetMethod(getBaseURI() + "/context/uriinfo/notbeanmethod");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(204, getMethod.getStatusCode());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+}