You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wink.apache.org by ng...@apache.org on 2009/06/23 07:38:19 UTC

svn commit: r787553 [10/34] - in /incubator/wink/contrib/ibm-jaxrs/tests: ./ fvt/ fvt/demo/ fvt/demo/jaxrs/ fvt/demo/jaxrs/cache/ fvt/demo/jaxrs/cache/server/ fvt/demo/jaxrs/cache/test/ fvt/demo/jaxrs/datasource/ fvt/demo/jaxrs/datasource/server/ fvt/d...

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/context/request/test/RequestMethodsTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/context/request/test/RequestMethodsTest.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/context/request/test/RequestMethodsTest.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/context/request/test/RequestMethodsTest.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,2130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jaxrs.tests.context.request.test;
+
+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 javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.ws.http.HTTPException;
+
+import jaxrs.tests.context.request.server.Variant;
+
+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 framework.defaults.test.FVTTestCase;
+
+/**
+ * Tests the {@link Request} implementation.
+ */
+public class RequestMethodsTest extends FVTTestCase {
+
+    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 static junit.framework.Test suite() {
+        return FVTTestCase.getTestSuite(RequestMethodsTest.class,
+                "jaxrs.tests.context.request.server.Application");
+    }
+
+    /**
+     * 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 {
+        checkETagIfMatch("\"myentitytagABCXYZ\"", false);
+    }
+
+    /**
+     * 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 {
+        checkETagIfMatch("\"myentitytagABCXYZ\"", true);
+    }
+
+    /**
+     * 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(412, 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(412, 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(412, 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\"");
+        getMethod.addRequestHeader("If-Match", "\"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\"");
+        getMethod.addRequestHeader("If-Match", setETag);
+        getMethod.addRequestHeader("If-Match", "\"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();
+        }
+
+        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 not a valid entity tag so
+             * 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.setRequestHeader("If-None-Match", setETag.substring(0,
+                setETag.length() - 1));
+        try {
+            /*
+             * verifies that a misquoted entity tag is not a valid entity tag so
+             * 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.setRequestHeader("If-None-Match", setETag.substring(1,
+                setETag.length()));
+        try {
+            /*
+             * verifies that a misquoted entity tag is not a valid entity tag so
+             * 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.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\"");
+        getMethod.addRequestHeader("If-None-Match", "\"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\"");
+        getMethod.addRequestHeader("If-None-Match", setETag);
+        getMethod.addRequestHeader("If-None-Match", "\"powers\"");
+        try {
+            /*
+             * verifies that if multiple etags are sent that do match the server
+             * etag, that a 304 is returned with the etag
+             */
+            client.executeMethod(getMethod);
+            assertEquals(304, getMethod.getStatusCode());
+            assertEquals(setETag, getMethod.getResponseHeader("ETag")
+                    .getValue());
+        } 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 without an If-None-Match header will
+             * still proceed
+             */
+            client.executeMethod(postMethod);
+            assertEquals(412, postMethod.getStatusCode());
+            assertEquals(setETag, getMethod.getResponseHeader("ETag")
+                    .getValue());
+        } finally {
+            postMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with no request
+     * headers sent.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantNoHeaders() throws HttpException, IOException,
+            JAXBException {
+        HttpClient client = new HttpClient();
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptonly/");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertNotNull(getMethod.getResponseBodyAsString());
+            assertNull(getMethod.getResponseHeader("Vary"));
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with Accept:
+     * text/xml request header sent.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptOnlyXMLHeaders() throws HttpException,
+            IOException, JAXBException {
+        HttpClient client = new HttpClient();
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptonly");
+        getMethod.setRequestHeader("Accept", "text/xml");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertNotNull(getMethod.getResponseBodyAsString());
+
+            Unmarshaller unmarshaller = JAXBContext.newInstance(
+                    "jaxrs.tests.context.request.server").createUnmarshaller();
+            Variant v = (Variant) unmarshaller.unmarshal(getMethod
+                    .getResponseBodyAsStream());
+            assertNotNull(v);
+            assertEquals("text/xml", v.getMediatype());
+            assertEquals("text/xml", getMethod
+                    .getResponseHeader("Content-Type").getValue());
+
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertEquals("Accept", value);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with Accept:
+     * application/json request header sent.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptOnlyJSONHeaders() throws HttpException,
+            IOException, JAXBException {
+        HttpClient client = new HttpClient();
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptonly");
+        getMethod.setRequestHeader("Accept", "application/json");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertNotNull(getMethod.getResponseBodyAsString());
+
+            assertEquals("application/json", getMethod
+                    .getResponseBodyAsString());
+            assertEquals("application/json", getMethod.getResponseHeader(
+                    "Content-Type").getValue());
+
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertEquals("Accept", value);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with "Accept:
+     * application/json;q=0.2,text/xml;q=0.8" request header sent.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptPreferXMLOverJSONHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptonly");
+        getMethod.setRequestHeader("Accept",
+                "application/json;q=0.2 , text/xml;q=0.8");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertNotNull(getMethod.getResponseBodyAsString());
+
+            Unmarshaller unmarshaller = JAXBContext.newInstance(
+                    "jaxrs.tests.context.request.server").createUnmarshaller();
+            Variant v = (Variant) unmarshaller.unmarshal(getMethod
+                    .getResponseBodyAsStream());
+            assertNotNull(v);
+            assertEquals("text/xml", v.getMediatype());
+            assertEquals("text/xml", getMethod
+                    .getResponseHeader("Content-Type").getValue());
+
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertEquals("Accept", value);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with "Accept:
+     * application/json;q=0.8,text/xml;q=0.2" request header sent.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptPreferJSONOverXMLHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptonly");
+        getMethod.setRequestHeader("Accept",
+                "application/json;q=0.8 , text/xml;q=0.2");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertNotNull(getMethod.getResponseBodyAsString());
+
+            assertEquals("application/json", getMethod
+                    .getResponseBodyAsString());
+            assertEquals("application/json", getMethod.getResponseHeader(
+                    "Content-Type").getValue());
+
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertEquals("Accept", value);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with "Accept:
+     * application/json;q=0.8,text/xml;q=0.2" request header sent.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptPreferJSONImplicitlyOverXMLHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptonly");
+        getMethod.setRequestHeader("Accept",
+                "application/json , text/xml;q=0.2");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertNotNull(getMethod.getResponseBodyAsString());
+
+            assertEquals("application/json", getMethod
+                    .getResponseBodyAsString());
+            assertEquals("application/json", getMethod.getResponseHeader(
+                    "Content-Type").getValue());
+
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertEquals("Accept", value);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with "Accept:
+     * text/wildcard , text/xml;q=0.2" request header sent. This is not a real
+     * world condition but just to make sure that text/wildcard does not cause
+     * problems.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptPreferTextWildcardOverTextXMLHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptonly");
+
+        getMethod.setRequestHeader("Accept", "text/* , text/xml;q=0.2");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertNotNull(getMethod.getResponseBodyAsString());
+            assertTrue(getMethod.getResponseBodyAsString().contains("text"));
+
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertEquals("Accept", value);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with "Accept:
+     * text/*;q=0.2,text/xml;q=0.8" request header sent.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptPreferTextXMLOverTextWildcardHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptonly");
+        getMethod.setRequestHeader("Accept", "text/*;q=0.2,text/xml;q=0.8");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertNotNull(getMethod.getResponseBodyAsString());
+
+            Unmarshaller unmarshaller = JAXBContext.newInstance(
+                    "jaxrs.tests.context.request.server").createUnmarshaller();
+            Variant v = (Variant) unmarshaller.unmarshal(getMethod
+                    .getResponseBodyAsStream());
+            assertNotNull(v);
+            assertEquals("text/xml", v.getMediatype());
+            assertEquals("text/xml", getMethod
+                    .getResponseHeader("Content-Type").getValue());
+
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertEquals("Accept", value);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with "Accept:
+     * text/*;q=0.2,text/xml;q=0.8,text/html;q=0.9" request header sent.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptPreferTextHTMLOverMultipleTextSubtypesHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptonly");
+        getMethod.setRequestHeader("Accept",
+                "text/*;q=0.2,text/xml;q=0.8,text/html;q=0.9");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertNotNull(getMethod.getResponseBodyAsString());
+
+            assertEquals("text/html", getMethod.getResponseBodyAsString());
+            assertEquals("text/html", getMethod.getResponseHeader(
+                    "Content-Type").getValue());
+
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertEquals("Accept", value);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with "Accept:
+     * text/*;q=0.2,text/plain; q=.95, text/xml;q=0.8,text/html;q=0.9" request
+     * header sent.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptPreferTextPlainOverMultipleTextSubtypesHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptonly");
+        getMethod
+                .setRequestHeader("Accept",
+                        "text/*;q=0.2,text/plain; q=.95, text/xml;q=0.8,text/html;q=0.9");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertNotNull(getMethod.getResponseBodyAsString());
+
+            assertEquals("text/*", getMethod.getResponseBodyAsString());
+            assertEquals("text/plain", getMethod.getResponseHeader(
+                    "Content-Type").getValue());
+
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertEquals("Accept", value);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with "Accept:
+     * application/* , text/xml;q=0.2" request header sent.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptPreferApplicationWildcardOverTextXMLHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptonly");
+        getMethod.setRequestHeader("Accept", "application/* , text/xml;q=0.2");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertNotNull(getMethod.getResponseBodyAsString());
+
+            assertEquals("application/json", getMethod
+                    .getResponseBodyAsString());
+            /*
+             * This is fine as an octet-stream
+             */
+            assertEquals("application/octet-stream", getMethod
+                    .getResponseHeader("Content-Type").getValue());
+
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertEquals("Accept", value);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with "Accept:
+     * application/*;q=0.2 , text/xml;q=0.2" request header sent.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptEqualApplicationWildcardWithTextXMLHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptonly");
+        getMethod.setRequestHeader("Accept",
+                "application/*;q=0.2, text/xml;q=0.2");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertNotNull(getMethod.getResponseBodyAsString());
+
+            if ("application/octet-stream".equals(getMethod.getResponseHeader(
+                    "Content-Type").getValue())) {
+                assertEquals("application/json", getMethod
+                        .getResponseBodyAsString());
+                assertEquals("application/octet-stream", getMethod
+                        .getResponseHeader("Content-Type").getValue());
+            } else {
+                Unmarshaller unmarshaller = JAXBContext.newInstance(
+                        "jaxrs.tests.context.request.server")
+                        .createUnmarshaller();
+                Variant v = (Variant) unmarshaller.unmarshal(getMethod
+                        .getResponseBodyAsStream());
+                assertNotNull(v);
+                assertEquals("text/xml", v.getMediatype());
+                assertEquals("text/xml", getMethod.getResponseHeader(
+                        "Content-Type").getValue());
+
+                String value = getMethod.getResponseHeader("Vary").getValue();
+                assertNotNull(value);
+                assertEquals("Accept", value);
+            }
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with "Accept:
+     * application/*;q=0.2 , abcd/efgh;q=0.2" request header sent.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptApplicationWildcardWithWeirdTypeHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptonly");
+        getMethod.setRequestHeader("Accept",
+                "application/*;q=0.2 , abcd/efgh;q=0.2");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertNotNull(getMethod.getResponseBodyAsString());
+
+            assertEquals("application/json", getMethod
+                    .getResponseBodyAsString());
+            /*
+             * this is correct because the Request does not know about abcd/efgh
+             */
+            assertEquals("abcd/efgh", getMethod.getResponseHeader(
+                    "Content-Type").getValue());
+
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertEquals("Accept", value);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with "Accept:
+     * application/*;q=0.2 , abcd/efgh;q=0.9" request header sent. This should
+     * result in application/json being returned because the variant list does
+     * not have abcd/efgh and only application/json matches
+     * application/wildcard.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptPreferWeirdTypeOverApplicationWildcardHeaders()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptonly");
+        getMethod.setRequestHeader("Accept",
+                "application/*;q=0.2 , abcd/efgh;q=0.9");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertNotNull(getMethod.getResponseBodyAsString());
+
+            assertEquals("application/json", getMethod
+                    .getResponseBodyAsString());
+            assertEquals("abcd/efgh", getMethod.getResponseHeader(
+                    "Content-Type").getValue());
+
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertEquals("Accept", value);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with "Accept:
+     * abcd/efgh;q=0.9" request header sent.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptWeirdUnsupportedTypeHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptonly");
+        getMethod.setRequestHeader("Accept", "abcd/efgh;q=0.9");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertNotNull(getMethod.getResponseBodyAsString());
+            /*
+             * a "random" content-type is expected back
+             */
+            assertNotNull(getMethod.getResponseHeader("Content-Type")
+                    .getValue());
+            assertNull(getMethod.getResponseHeader("Vary"));
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with no request
+     * headers sent.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptLanguageNoHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptlanguageonly");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertNotNull(getMethod.getResponseBodyAsString());
+
+            assertNull(getMethod.getResponseHeader("Vary"));
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with
+     * "Accept-Language: en" request header sent.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptLanguagePreferEnglishHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptlanguageonly");
+        getMethod.setRequestHeader("Accept-Language", "en");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("en", getMethod.getResponseBodyAsString());
+
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertEquals("Accept-Language", value);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with
+     * "Accept-Language: en-US" request header sent. This should result in a
+     * random variant returned since there is no exact match.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptLanguageNotExpectedLanguageHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptlanguageonly");
+        getMethod.setRequestHeader("Accept-Language", "en-US");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertNotNull(getMethod.getResponseBodyAsString());
+
+            assertNull(getMethod.getResponseHeader("Vary"));
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with
+     * "Accept-Language: *" request header sent. This should result in a random
+     * variant being returned.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptLanguageWildcardHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptlanguageonly");
+        getMethod.setRequestHeader("Accept-Language", "*");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertNotNull(getMethod.getResponseBodyAsString());
+
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertEquals("Accept-Language", value);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with
+     * "Accept-Language: de" request header sent. This should result in de being
+     * returned.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptLanguagePreferGermanHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptlanguageonly");
+        getMethod.setRequestHeader("Accept-Language", "de");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("de", getMethod.getResponseBodyAsString());
+
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertEquals("Accept-Language", value);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with
+     * "Accept-Language: de;q=0.8,en;q=0.2" request header sent. This should
+     * result in German language being returned.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptLanguagePreferGermanOverEnglishHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptlanguageonly");
+        getMethod.setRequestHeader("Accept-Language", "de;q=0.8,en;q=0.2");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("de", getMethod.getResponseBodyAsString());
+
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertEquals("Accept-Language", value);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with
+     * "Accept-Language: de;q=0.2,en;q=0.8" request header sent. This should
+     * result in English language being returned.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptLanguagePreferEnglishOverGermanHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptlanguageonly");
+        getMethod.setRequestHeader("Accept-Language", "de;q=0.2,en;q=0.8");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("en", getMethod.getResponseBodyAsString());
+
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertEquals("Accept-Language", value);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with no request
+     * headers sent. This should result in a random variation returned.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptTypeAcceptLanguageNoHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptmultiple");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertNotNull(getMethod.getResponseBodyAsString());
+
+            assertNull(getMethod.getResponseHeader("Vary"));
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)}. This should
+     * result in English language being returned with application/json.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptTypeAcceptLanguageEnglishJSONHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptmultiple");
+        getMethod.setRequestHeader("Accept", "application/json");
+        getMethod.setRequestHeader("Accept-Language", "en");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("application/json-en-compress", getMethod
+                    .getResponseBodyAsString());
+
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertTrue(value.contains("Accept"));
+            assertTrue(value.contains("Accept-Language"));
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)}. This should
+     * result in English language being returned with application/json in gzip
+     * encoding.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptTypeAcceptLanguageEnglishJSONGzipHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptmultiple");
+        getMethod.setRequestHeader("Accept", "application/json");
+        getMethod.setRequestHeader("Accept-Language", "en");
+        getMethod.setRequestHeader("Accept-Encoding", "gzip");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+
+            assertEquals("application/json-en-gzip", getMethod
+                    .getResponseBodyAsString());
+
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertTrue(value.contains("Accept"));
+            assertTrue(value.contains("Accept-Language"));
+            assertTrue(value.contains("Accept-Encoding"));
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)}. This should
+     * result in English language being returned with text/html.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptTypeAcceptLanguageEnglishWeirdTypeHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptmultiple");
+        getMethod.setRequestHeader("Accept", "efgh/abcd");
+        getMethod.setRequestHeader("Accept-Language", "en");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String content = getMethod.getResponseBodyAsString();
+            // assertTrue(content, content.contains("efgh/abcd"));
+            assertTrue(content, content.contains("en"));
+
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertTrue(value.contains("Accept"));
+            assertTrue(value.contains("Accept-Language"));
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)}. This should
+     * result in English language being returned with text/html with compress
+     * encoding.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptTypeAcceptLanguageEnglishAcceptEncodingCompressWeirdTypeHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptmultiple");
+        getMethod.setRequestHeader("Accept", "efgh/abcd");
+        getMethod.setRequestHeader("Accept-Language", "en");
+        getMethod.setRequestHeader("Accept-Encoding", "compress");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String content = getMethod.getResponseBodyAsString();
+            // assertTrue(content, content.contains("efgh/abcd"));
+            assertTrue(content, content.contains("en"));
+            assertTrue(content, content.contains("compress"));
+
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertTrue(value.contains("Accept"));
+            assertTrue(value.contains("Accept-Language"));
+            assertTrue(value.contains("Accept-Encoding"));
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)}. This should
+     * result in German language being returned with application/json with gzip
+     * encoding.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantMultipleAcceptTypeAcceptEncodingAcceptLanguageTypeHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptmultiple");
+        getMethod.setRequestHeader("Accept",
+                "text/xml;q=0.5, application/json;q=0.8, */*;q=0.2");
+        getMethod.setRequestHeader("Accept-Language", "en;q=0.2,de;q=0.8");
+        getMethod.setRequestHeader("Accept-Encoding", "compress;q=0.8,gzip");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+
+            assertEquals("application/json-de-gzip", getMethod
+                    .getResponseBodyAsString());
+
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertTrue(value.contains("Accept"));
+            assertTrue(value.contains("Accept-Language"));
+            assertTrue(value.contains("Accept-Encoding"));
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with no request
+     * headers sent.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptEncodingNoHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptencodingonly");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertNotNull(getMethod.getResponseBodyAsString());
+
+            assertNull(getMethod.getResponseHeader("Vary"));
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with
+     * "Accept-Encoding: compress" request header sent.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptEncodingPreferCompressHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptencodingonly");
+        getMethod.setRequestHeader("Accept-Encoding", "compress");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("compress", getMethod.getResponseBodyAsString());
+
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertEquals("Accept-Encoding", value);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with
+     * "Accept-Encoding: abcdefg" request header sent. This should result in a
+     * random variant returned since there is no exact match.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptEncodingNotExpectedEncodingHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptencodingonly");
+        getMethod.setRequestHeader("Accept-Encoding", "abcdefg");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertNotNull(getMethod.getResponseBodyAsString());
+
+            assertNull(getMethod.getResponseHeader("Vary"));
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with
+     * "Accept-Language: *" request header sent. This should result in German
+     * being returned.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptEncodingWildcardHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptlanguageonly");
+        getMethod.setRequestHeader("Accept-Encoding", "*");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertNotNull(getMethod.getResponseBodyAsString());
+
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertEquals("Accept-Encoding", value);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with
+     * "Accept-Encoding: gzip" request header sent. This should result in a gzip
+     * encoding returned.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptEncodingPreferGzip()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptencodingonly");
+        getMethod.setRequestHeader("Accept-Encoding", "gzip");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("gzip", getMethod.getResponseBodyAsString());
+
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertEquals("Accept-Encoding", value);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with
+     * "Accept-Encoding: compress;q=0.2,gzip;q=0.8" request header sent. This
+     * should result in gzip being returned.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptEncodingPreferGzipOverCompressHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptencodingonly");
+        getMethod.setRequestHeader("Accept-Encoding",
+                "compress;q=0.2,gzip;q=0.8");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("gzip", getMethod.getResponseBodyAsString());
+
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertEquals("Accept-Encoding", value);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Request#selectVariant(java.util.List)} with
+     * "Accept-Encoding: compress;q=0.8,gzip;q=0.2" request header sent. This
+     * should result in compress being returned.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testSelectVariantAcceptEncodingPreferCompressOverGzipHeaders()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/acceptencodingonly");
+        getMethod.setRequestHeader("Accept-Encoding",
+                "compress;q=0.8,gzip;q=0.2");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("compress", getMethod.getResponseBodyAsString());
+
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertEquals("Accept-Encoding", value);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link ResponseBuilder#variants(java.util.List)} would override
+     * the Vary header set by{@link Request#selectVariant(java.util.List)}.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testResponseBuilderVariantsOverrideSelectVariants()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/responsebuilder");
+        getMethod.setRequestHeader("Accept", "text/plain");
+        getMethod.setRequestHeader("Accept-Language", "en");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertTrue(value, value.contains("Accept"));
+            assertTrue(value, value.contains("Accept-Language"));
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/responsebuilder?type=variants");
+        getMethod.setRequestHeader("Accept", "text/xml");
+        getMethod.setRequestHeader("Accept-Language", "en");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertTrue(value, value.contains("Accept-Language"));
+            assertTrue(value, value.contains("Accept-Encoding"));
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests the {@link Response#notAcceptable(java.util.List)} would override
+     * the Vary header set by{@link Request#selectVariant(java.util.List)}.
+     *
+     * @throws HttpException
+     * @throws IOException
+     * @throws JAXBException
+     */
+    public void testResponseBuilderNotAcceptableVariantsOverrideSelectVariants()
+            throws HttpException, IOException, JAXBException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/responsebuilder");
+        getMethod.setRequestHeader("Accept", "text/plain");
+        getMethod.setRequestHeader("Accept-Language", "en");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertTrue(value, value.contains("Accept"));
+            assertTrue(value, value.contains("Accept-Language"));
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        getMethod = new GetMethod(getBaseURI()
+                + "/context/request/variant/responsebuilder?type=notacceptable");
+        getMethod.setRequestHeader("Accept", "text/xml");
+        getMethod.setRequestHeader("Accept-Language", "en");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(406, getMethod.getStatusCode());
+            String value = getMethod.getResponseHeader("Vary").getValue();
+            assertNotNull(value);
+            assertTrue(value, value.contains("Accept"));
+            assertTrue(value, value.contains("Accept-Encoding"));
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    //
+    // public void testSelectVariantThenDoAnotherEvaluatePrecondition() {
+    // fail();
+    // /*
+    // * should check about Vary header
+    // */
+    // }
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/context/securitycontext/buildTest.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/context/securitycontext/buildTest.xml?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/context/securitycontext/buildTest.xml (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/context/securitycontext/buildTest.xml Tue Jun 23 05:37:57 2009
@@ -0,0 +1,24 @@
+<?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.
+  -->
+
+<project name="jaxrs.tests.context.securitycontext" default="all">
+	<import file="../../../../buildCommon.xml" />
+</project>

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/context/securitycontext/server/Application.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/context/securitycontext/server/Application.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/context/securitycontext/server/Application.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/context/securitycontext/server/Application.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jaxrs.tests.context.securitycontext.server;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class Application extends javax.ws.rs.core.Application {
+
+    @Override
+    public Set<Class<?>> getClasses() {
+        Set<Class<?>> clazzes = new HashSet<Class<?>>();
+        clazzes.add(SecurityContextBeanResource.class);
+        clazzes.add(SecurityContextConstructorResource.class);
+        clazzes.add(SecurityContextFieldResource.class);
+        clazzes.add(SecurityContextNotBeanMethodResource.class);
+        clazzes.add(SecurityContextParamResource.class);
+        return clazzes;
+    }
+
+}