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/16 22:02:01 UTC

svn commit: r794815 [3/4] - in /incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/wink/ src/main/ja...

Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/addressbook/StringTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/addressbook/StringTest.java?rev=794815&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/addressbook/StringTest.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/addressbook/StringTest.java Thu Jul 16 20:01:58 2009
@@ -0,0 +1,216 @@
+/*
+ * 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.addressbook;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
+import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.commons.httpclient.methods.RequestEntity;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+/**
+ * These tests drive calls to a REST resource that is deployed on our test
+ * framework server. The resources being tested by this class exchange data via
+ * String objects.
+ */
+public class StringTest extends TestCase {
+
+    final private static String BASE_URI =
+                                             ServerEnvironmentInfo.getBaseURI() + "/addressBook/"
+                                                 + "/unittests/addresses";
+
+    @Override
+    public void setUp() {
+        /*
+         * clear the database entries
+         */
+        HttpClient client = new HttpClient();
+        HttpMethod method = null;
+        try {
+            method = new PostMethod(BASE_URI + "/clear");
+            client.executeMethod(method);
+            assertEquals(204, method.getStatusCode());
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail(e.getMessage());
+        } finally {
+            if (method != null) {
+                method.releaseConnection();
+            }
+        }
+    }
+
+    /**
+     * This will drive a GET request with no input parameters
+     */
+    public void testGetNoParams() {
+
+        HttpMethod method = null;
+        try {
+            HttpClient client = new HttpClient();
+            method = new GetMethod(BASE_URI);
+            client.executeMethod(method);
+            String responseBody = method.getResponseBodyAsString();
+            Address addr = AddressBook.defaultAddress;
+            assertTrue(responseBody.contains(addr.getEntryName()));
+            assertTrue(responseBody.contains(addr.getStreetAddress()));
+            assertTrue(responseBody.contains(addr.getZipCode()));
+            assertTrue(responseBody.contains(addr.getCity()));
+            assertTrue(responseBody.contains(addr.getCountry()));
+            assertTrue(responseBody.contains(addr.getState()));
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail(e.getMessage());
+        } finally {
+            if (method != null) {
+                method.releaseConnection();
+            }
+        }
+    }
+
+    /**
+     * This will drive a POST request with parameters from the query string
+     */
+    public void testPostWithQueryParams() {
+        HttpMethod method = null;
+        HttpMethod getMethod = null;
+        try {
+
+            // make sure everything is clear before testing
+            HttpClient client = new HttpClient();
+            method = new PostMethod(BASE_URI);
+            method
+                .setQueryString("entryName=newAddress&streetAddress=1234+Any+Street&city=" + "AnyTown&zipCode=90210&state=TX&country=US");
+            client.executeMethod(method);
+
+            // now let's see if the address we just created is available
+            getMethod = new GetMethod(BASE_URI + "/newAddress");
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String responseBody = getMethod.getResponseBodyAsString();
+            assertNotNull(responseBody);
+            assertTrue(responseBody, responseBody.contains("newAddress"));
+            assertTrue(responseBody, responseBody.contains("1234 Any Street"));
+            assertTrue(responseBody, responseBody.contains("AnyTown"));
+            assertTrue(responseBody, responseBody.contains("90210"));
+            assertTrue(responseBody, responseBody.contains("TX"));
+            assertTrue(responseBody, responseBody.contains("US"));
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail(e.getMessage());
+        } finally {
+            if (method != null) {
+                method.releaseConnection();
+            }
+            if (getMethod != null) {
+                getMethod.releaseConnection();
+            }
+        }
+    }
+
+    /**
+     * This will drive a POST, GET, UPDATE, and DELETE on the
+     * AddressBookResource
+     */
+    public void testAddressBookResource() {
+        PostMethod method = null;
+        GetMethod getMethod = null;
+        PutMethod put = null;
+        DeleteMethod deleteMethod = null;
+        try {
+
+            // make sure everything is clear before testing
+            HttpClient client = new HttpClient();
+            method = new PostMethod(BASE_URI + "/fromBody");
+            String input = "tempAddress&1234 Any Street&AnyTown&90210&TX&US";
+            RequestEntity entity = new ByteArrayRequestEntity(input.getBytes(), "text/xml");
+            method.setRequestEntity(entity);
+            client.executeMethod(method);
+
+            // now let's see if the address we just created is available
+            getMethod = new GetMethod(BASE_URI + "/tempAddress");
+            client.executeMethod(getMethod);
+            String responseBody = getMethod.getResponseBodyAsString();
+            getMethod.releaseConnection();
+            assertNotNull(responseBody);
+            assertTrue(responseBody, responseBody.contains("tempAddress"));
+            assertTrue(responseBody, responseBody.contains("1234 Any Street"));
+            assertTrue(responseBody, responseBody.contains("AnyTown"));
+            assertTrue(responseBody, responseBody.contains("90210"));
+            assertTrue(responseBody, responseBody.contains("TX"));
+            assertTrue(responseBody, responseBody.contains("US"));
+
+            // let's update the state
+            String query =
+                "entryName=tempAddress&streetAddress=1234+Any+Street&city=" + "AnyTown&zipCode=90210&state=AL&country=US";
+            client = new HttpClient();
+            put = new PutMethod(BASE_URI);
+            put.setQueryString(query);
+            client.executeMethod(put);
+
+            // make sure the state has been updated
+            client = new HttpClient();
+            client.executeMethod(getMethod);
+            responseBody = getMethod.getResponseBodyAsString();
+            assertNotNull(responseBody);
+            assertTrue(responseBody.contains("tempAddress"));
+            assertFalse(responseBody.contains("TX"));
+            assertTrue(responseBody.contains("AL"));
+
+            // now let's delete the address
+            client = new HttpClient();
+            deleteMethod = new DeleteMethod(BASE_URI + "/tempAddress");
+            client.executeMethod(deleteMethod);
+            assertEquals(204, deleteMethod.getStatusCode());
+
+            // now try to get the address
+            client = new HttpClient();
+            client.executeMethod(getMethod);
+            assertEquals(404, getMethod.getStatusCode());
+            responseBody = getMethod.getResponseBodyAsString();
+            assertEquals("", responseBody);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail(e.getMessage());
+        } finally {
+            if (method != null) {
+                method.releaseConnection();
+            }
+            if (getMethod != null) {
+                getMethod.releaseConnection();
+            }
+            if (put != null) {
+                put.releaseConnection();
+            }
+            if (deleteMethod != null) {
+                deleteMethod.releaseConnection();
+            }
+        }
+    }
+
+}

Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/cachetest/ClientTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/cachetest/ClientTest.java?rev=794815&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/cachetest/ClientTest.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/cachetest/ClientTest.java Thu Jul 16 20:01:58 2009
@@ -0,0 +1,168 @@
+/*
+ * 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.cachetest;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.TimeZone;
+
+import javax.ws.rs.core.Response;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.wink.jaxrs.test.cache.NewsStory;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+public class ClientTest extends TestCase {
+
+    final private static String     NEWS_BASE_URI = ServerEnvironmentInfo.getBaseURI() + "/cache/news";
+
+    private static final DateFormat formatter        =
+                                                      new SimpleDateFormat(
+                                                                           "EEE, dd MMM yyyy HH:mm:ss zzz",
+                                                                           Locale.ENGLISH);
+    static {
+        formatter.setLenient(false);
+        formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
+    }
+
+    @Override
+    public void setUp() {
+        /*
+         * clear the database entries
+         */
+        HttpClient client = new HttpClient();
+        HttpMethod method = null;
+        try {
+            System.out.println(NEWS_BASE_URI + "/clear");
+            method = new PostMethod(NEWS_BASE_URI + "/clear");
+            client.executeMethod(method);
+            assertEquals(204, method.getStatusCode());
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail(e.getMessage());
+        } finally {
+            if (method != null) {
+                method.releaseConnection();
+            }
+        }
+    }
+
+    /**
+     * This test will demonstrate various usages of the ETag and 'If-Match'
+     * headers. It will show how different scenarios result in different HTTP
+     * status codes and different response entities.
+     */
+    public void testNewsResourceWithETag() throws Exception {
+        // always start with a fresh set of resources for testing purposes
+        // first create the resource
+        NewsStory story = new NewsStory();
+        story.setContent("This is a breaking news story");
+        story.setTitle("Local Hero Saves Kid");
+        NewsHttpClient client = new NewsHttpClient(NEWS_BASE_URI, null);
+        Response response = client.addNewsStory(story);
+        assertNotNull(response);
+        String location = (String)response.getMetadata().getFirst("Location");
+        String etag = (String)response.getMetadata().getFirst("ETag");
+
+        // now send a request with an 'If-Match' with a matching value,
+        // we should get back a 304
+        Map<String, String> reqHdrs = new HashMap<String, String>();
+        reqHdrs.put("If-Match", etag);
+        client = new NewsHttpClient(NEWS_BASE_URI, reqHdrs);
+        location = location.startsWith("/") ? location.substring(1) : location;
+        response = client.getNewsStory("Local%20Hero%20Saves%20Kid");
+        assertNotNull(response);
+        assertEquals("Expected 200 not returned", response.getStatus(), 200);
+
+        // update the content of the story
+        client = new NewsHttpClient(NEWS_BASE_URI, null);
+        String newContent = "A local man rescued a kid from a burning building";
+        story.setContent(newContent);
+        response = client.updateNewsStory(story);
+        String updatedETag = (String)response.getMetadata().getFirst("ETag");
+        assertNotNull(updatedETag);
+
+        // now try to get with the old ETag value, we should get a 412
+        // back indicating our precondition failed
+        client = new NewsHttpClient(NEWS_BASE_URI, reqHdrs);
+        location = location.startsWith("/") ? location.substring(1) : location;
+        response = client.getNewsStory("Local%20Hero%20Saves%20Kid");
+        assertNotNull(response);
+        assertNull(response.getEntity());
+        assertEquals("Expected 412 not returned", response.getStatus(), 412);
+
+        // now ensure that using the ETag we got back on the PUT results
+        // in a 304 status
+        reqHdrs.put("If-Match", updatedETag);
+        client = new NewsHttpClient(NEWS_BASE_URI, reqHdrs);
+        location = location.startsWith("/") ? location.substring(1) : location;
+        response = client.getNewsStory("Local%20Hero%20Saves%20Kid");
+        assertNotNull(response);
+        assertEquals("Expected 200 not returned", response.getStatus(), 200);
+    }
+
+    /**
+     * This test will demonstrate various usages of the Last-Modified header. It
+     * will show how different scenarios result in different HTTP status codes
+     * and different response entities.
+     */
+    public void testNewsResourceWithLastModified() throws Exception {
+
+        // first create the resource
+        NewsStory story = new NewsStory();
+        story.setContent("This is a breaking news story");
+        story.setTitle("Local Hero Saves Kid");
+        NewsHttpClient client = new NewsHttpClient(NEWS_BASE_URI, null);
+        Response response = client.addNewsStory(story);
+        assertNotNull(response);
+        String lastModified = (String)response.getMetadata().getFirst("Last-Modified");
+
+        Date date = formatter.parse(lastModified);
+
+        Map<String, String> reqHdrs = new HashMap<String, String>();
+        reqHdrs.put("If-Modified-Since", lastModified);
+        client = new NewsHttpClient(NEWS_BASE_URI, reqHdrs);
+        response = client.getNewsStory("Local%20Hero%20Saves%20Kid");
+        assertNotNull(response);
+        assertEquals("Expected 304 not returned", 304, response.getStatus());
+
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        calendar.set(Calendar.YEAR, 2006);
+
+        lastModified = formatter.format(calendar.getTime());
+        reqHdrs.put("If-Modified-Since", lastModified);
+        client = new NewsHttpClient(NEWS_BASE_URI, reqHdrs);
+        response = client.getNewsStory("Local%20Hero%20Saves%20Kid");
+        assertNotNull(response);
+        story = (NewsStory)response.getEntity();
+        assertNotNull(story);
+    }
+
+}

Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/cachetest/NewsHttpClient.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/cachetest/NewsHttpClient.java?rev=794815&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/cachetest/NewsHttpClient.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/cachetest/NewsHttpClient.java Thu Jul 16 20:01:58 2009
@@ -0,0 +1,165 @@
+/*
+ * 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.cachetest;
+
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import javax.ws.rs.core.Response;
+import javax.xml.bind.JAXBContext;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
+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.RequestEntity;
+import org.apache.wink.jaxrs.test.cache.NewsStory;
+
+public class NewsHttpClient implements NewsResource {
+
+    private String   baseURI;
+
+    private Header[] requestHeaders;
+
+    public NewsHttpClient(String baseURI, Map<String, String> reqHdrs) {
+        this.baseURI = baseURI;
+        requestHeaders = createRequestHeaders(reqHdrs);
+    }
+
+    public Response addNewsStory(NewsStory story) throws Exception {
+        PostMethod post = new PostMethod(this.baseURI);
+        try {
+            HttpClient client = new HttpClient();
+            setRequestHeaders(post);
+            JAXBContext context = JAXBContext.newInstance(NewsStory.class);
+            StringWriter sw = new StringWriter();
+            context.createMarshaller().marshal(story, sw);
+            RequestEntity entity = new ByteArrayRequestEntity(sw.toString().getBytes(), "text/xml");
+            post.setRequestEntity(entity);
+            int status = client.executeMethod(post);
+            Map<String, List<Object>> headers = getResponseHeaders(post.getResponseHeaders());
+            Response resp = Response.status(status).build();
+            resp.getMetadata().putAll(headers);
+            return resp;
+        } catch (Exception e) {
+            throw e;
+        } finally {
+            if (post != null) {
+                post.releaseConnection();
+            }
+        }
+    }
+
+    public Response updateNewsStory(NewsStory story) throws Exception {
+        PutMethod put = new PutMethod(this.baseURI);
+        try {
+            HttpClient client = new HttpClient();
+            setRequestHeaders(put);
+            JAXBContext context = JAXBContext.newInstance(NewsStory.class);
+            StringWriter sw = new StringWriter();
+            context.createMarshaller().marshal(story, sw);
+            RequestEntity entity = new ByteArrayRequestEntity(sw.toString().getBytes(), "text/xml");
+            put.setRequestEntity(entity);
+            int status = client.executeMethod(put);
+            Map<String, List<Object>> headers = getResponseHeaders(put.getResponseHeaders());
+            Response resp = Response.status(status).build();
+            resp.getMetadata().putAll(headers);
+            return resp;
+        } catch (Exception e) {
+            throw e;
+        } finally {
+            if (put != null) {
+                put.releaseConnection();
+            }
+        }
+    }
+
+    public Response getNewsStory(String title) throws Exception {
+        GetMethod get = new GetMethod(this.baseURI + "/" + title);
+        try {
+            HttpClient client = new HttpClient();
+            setRequestHeaders(get);
+            int status = client.executeMethod(get);
+            InputStream is = get.getResponseBodyAsStream();
+            NewsStory newsStory = null;
+            long cl = get.getResponseContentLength();
+            if (is != null && cl != 0) {
+                JAXBContext context = JAXBContext.newInstance(NewsStory.class);
+                newsStory = (NewsStory)context.createUnmarshaller().unmarshal(is);
+            }
+            Map<String, List<Object>> headers = getResponseHeaders(get.getResponseHeaders());
+            Response resp = Response.status(status).entity(newsStory).build();
+            resp.getMetadata().putAll(headers);
+            return resp;
+        } catch (Exception e) {
+            throw e;
+        } finally {
+            if (get != null) {
+                get.releaseConnection();
+            }
+        }
+    }
+
+    Map<String, List<Object>> getResponseHeaders(Header[] headers) {
+        Map<String, List<Object>> respHeaders = new HashMap<String, List<Object>>();
+        if (headers != null) {
+            for (Header header : headers) {
+                String headerName = header.getName();
+                List<Object> values = new ArrayList<Object>();
+                values.add(header.getValue());
+                respHeaders.put(headerName, values);
+            }
+        }
+        return respHeaders;
+    }
+
+    Header[] createRequestHeaders(Map<String, String> reqHdrs) {
+        Header[] headers = null;
+        if (reqHdrs != null) {
+            headers = new Header[reqHdrs.size()];
+            int i = 0;
+            Set<Entry<String, String>> entries = reqHdrs.entrySet();
+            for (Entry<String, String> entry : entries) {
+                Header header = new Header(entry.getKey(), entry.getValue());
+                headers[i] = header;
+                i++;
+            }
+        }
+        return headers;
+    }
+
+    void setRequestHeaders(HttpMethod method) {
+        if (requestHeaders != null) {
+            for (Header header : requestHeaders) {
+                method.addRequestHeader(header);
+            }
+        }
+    }
+
+}

Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/cachetest/NewsResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/cachetest/NewsResource.java?rev=794815&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/cachetest/NewsResource.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/cachetest/NewsResource.java Thu Jul 16 20:01:58 2009
@@ -0,0 +1,46 @@
+/*
+ * 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.cachetest;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+
+import org.apache.wink.jaxrs.test.cache.NewsStory;
+
+@Path("/news")
+public interface NewsResource {
+
+    @GET
+    @Produces(value = "text/xml")
+    @Path(value = "/{title}")
+    public Response getNewsStory(@PathParam(value = "title") String title) throws Exception;
+
+    @POST
+    public Response addNewsStory(NewsStory story) throws Exception;
+
+    @PUT
+    public Response updateNewsStory(NewsStory story) throws Exception;
+
+}

Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/contentnegotiation/ContentNegotiationClientTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/contentnegotiation/ContentNegotiationClientTest.java?rev=794815&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/contentnegotiation/ContentNegotiationClientTest.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/contentnegotiation/ContentNegotiationClientTest.java Thu Jul 16 20:01:58 2009
@@ -0,0 +1,131 @@
+/**
+ * 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.contentnegotiation;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.json.JSONTokener;
+
+/**
+ * These tests drive calls to a REST resource that is deployed on our test
+ * framework server. The resources being tested by this class exchange data via
+ * String objects.
+ */
+public class ContentNegotiationClientTest extends TestCase {
+
+    HttpClient                  httpclient = new HttpClient();
+
+    final private static String BASE_URI   =
+                                               ServerEnvironmentInfo.getBaseURI() + "/contentNegotiation/customerservice";
+
+    public void testGetReturningXML() {
+        // Sent HTTP GET request to query customer info, expect XML
+        System.out.println("Sent HTTP GET request to query customer info, expect XML");
+        GetMethod get = new GetMethod(BASE_URI + "/customers/123");
+        get.addRequestHeader("Accept", "application/xml");
+
+        try {
+            int result = httpclient.executeMethod(get);
+            System.out.println("Response status code: " + result);
+            System.out.println("Response body: ");
+            String responseBody = get.getResponseBodyAsString();
+            System.out.println(responseBody);
+            assertTrue(result == 200);
+            assertTrue(responseBody.contains("<Customer><id>123</id><name>John</name></Customer>"));
+        } catch (IOException ioe) {
+            ioe.printStackTrace();
+            fail(ioe.getMessage());
+        } finally {
+            get.releaseConnection();
+        }
+
+    }
+
+    public void testGetReturningJSON() throws IOException, JSONException {
+        // Sent HTTP GET request to query customer info, expect JSON.
+        System.out.println("\n");
+        System.out.println("Sent HTTP GET request to query customer info, expect JSON");
+        GetMethod get = new GetMethod(BASE_URI + "/customers/123");
+        get.addRequestHeader("Accept", "application/json");
+        httpclient = new HttpClient();
+
+        try {
+            int result = httpclient.executeMethod(get);
+            System.out.println("Response status code: " + result);
+            System.out.println("Response body: ");
+            String responseBody = get.getResponseBodyAsString();
+            System.out.println(responseBody);
+            assertEquals(200, result);
+            JSONTokener tokenizer = new JSONTokener(responseBody);
+            JSONObject jObj = new JSONObject(tokenizer);
+            assertEquals("John", jObj.get("name"));
+            assertEquals(123L, jObj.getLong("id"));
+        } catch (IOException ioe) {
+            ioe.printStackTrace();
+            fail(ioe.getMessage());
+        } finally {
+            get.releaseConnection();
+        }
+    }
+
+    public void testGetForCustomerInfoReturningJSON() throws JSONException {
+
+        // Sent HTTP GET request to query customer info, expect JSON.
+        System.out.println("\n");
+        System.out.println("Sent HTTP GET request to query customer info, expect JSON");
+        // The default behavior without setting Accept header explicitly is
+        // depending on your client.
+        // In the case of HTTP Client, the Accept header will be absent. The CXF
+        // server will treat this
+        // as "*/*", JSON format is returned
+        GetMethod get = new GetMethod(BASE_URI + "/customers/123");
+        httpclient = new HttpClient();
+
+        try {
+            int result = httpclient.executeMethod(get);
+            System.out.println("Response status code: " + result);
+            System.out.println("Response body: ");
+            String responseBody = get.getResponseBodyAsString();
+            System.out.println(responseBody);
+            assertEquals(200, result);
+            JSONTokener tokenizer = new JSONTokener(responseBody);
+            JSONObject jObj = new JSONObject(tokenizer);
+
+            assertEquals("John", jObj.get("name"));
+            assertEquals(123L, jObj.getLong("id"));
+        } catch (IOException ioe) {
+            ioe.printStackTrace();
+            fail(ioe.getMessage());
+        } finally {
+            get.releaseConnection();
+        }
+
+        System.out.println("\n");
+        System.out.println("Client Invoking is succeeded!");
+
+    }
+}

Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/exceptions/ExceptionsWhileTargettingTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/exceptions/ExceptionsWhileTargettingTest.java?rev=794815&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/exceptions/ExceptionsWhileTargettingTest.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/exceptions/ExceptionsWhileTargettingTest.java Thu Jul 16 20:01:58 2009
@@ -0,0 +1,202 @@
+/*
+ * 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.exceptions;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.URI;
+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;
+
+public class ExceptionsWhileTargettingTest extends TestCase {
+
+    public static String getBaseURI() {
+        return ServerEnvironmentInfo.getBaseURI() + "/exceptional";
+    }
+
+    /**
+     * Tests that a 404 error is thrown when no resource can be found for a
+     * path.
+     * 
+     * @throws Exception
+     */
+    public void test404WhenNoResourceExists() throws Exception {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI() + "/doesnotexist");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(404, getMethod.getStatusCode());
+            assertEquals("", getMethod.getResponseBodyAsString());
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a 405 error is thrown when no subresource can be found for a
+     * path.
+     * 
+     * @throws Exception
+     */
+    public void test405WhenNoMethodExistsOnExistingResource() throws Exception {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI() + "/existingresource/");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(405, getMethod.getStatusCode());
+            assertEquals("", getMethod.getResponseBodyAsString());
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a 404 error is thrown when no subresource can be found for a
+     * path.
+     * 
+     * @throws Exception
+     */
+    public void test404WhenNoSubResourceExists() throws Exception {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI() + "/existingresource/noexistsub");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(404, getMethod.getStatusCode());
+            assertEquals("", getMethod.getResponseBodyAsString());
+
+            getMethod.setURI(new URI(getBaseURI() + "/targeting/resourcewithmethod", true));
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("Hello", getMethod.getResponseBodyAsString());
+
+            getMethod.setURI(new URI(getBaseURI() + "/targeting/resourcewithmethod/noexistsub",
+                                     true));
+            client.executeMethod(getMethod);
+            assertEquals(404, getMethod.getStatusCode());
+            assertEquals("", getMethod.getResponseBodyAsString());
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a 405 error is thrown when other http methods exist on a
+     * resource but not the one looking for.
+     * 
+     * @throws Exception
+     */
+    public void test405WhenResourceMethodDoesNotExistButOthersDo() throws Exception {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI() + "/existingresource/noexistsub");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(404, getMethod.getStatusCode());
+            assertEquals("", getMethod.getResponseBodyAsString());
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        PostMethod postMethod = new PostMethod(getBaseURI() + "/targeting/resourcewithmethod");
+        try {
+            client.executeMethod(postMethod);
+            assertEquals(405, postMethod.getStatusCode());
+            assertEquals("", postMethod.getResponseBodyAsString());
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a 415 error is thrown when request entity data sent is not
+     * acceptable by the resource.
+     * 
+     * @throws Exception
+     */
+    public void test415WhenResourceMethodDoesNotAcceptRequestEntity() throws Exception {
+        HttpClient client = new HttpClient();
+
+        PutMethod putMethod = new PutMethod(getBaseURI() + "/targeting/resourcewithmethod");
+        try {
+            putMethod.setRequestEntity(new StringRequestEntity("some content", "text/plain",
+                                                               "UTF-8"));
+            client.executeMethod(putMethod);
+            assertEquals(200, putMethod.getStatusCode());
+            assertEquals("some content", putMethod.getResponseBodyAsString());
+        } finally {
+            putMethod.releaseConnection();
+        }
+
+        putMethod = new PutMethod(getBaseURI() + "/targeting/resourcewithmethod");
+        try {
+            putMethod.setRequestEntity(new StringRequestEntity("some content",
+                                                               "customplain/something", "UTF-8"));
+            client.executeMethod(putMethod);
+            assertEquals(415, putMethod.getStatusCode());
+            assertEquals("", putMethod.getResponseBodyAsString());
+        } finally {
+            putMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a 406 error is produced if server side cannot produce any
+     * acceptable content type.
+     * 
+     * @throws Exception
+     */
+    public void test406WhenResourceMethodDoesNotProduceResponseEntityType() throws Exception {
+        HttpClient client = new HttpClient();
+
+        PutMethod putMethod = new PutMethod(getBaseURI() + "/targeting/resourcewithmethod");
+
+        try {
+            putMethod.addRequestHeader("Accept", "text/plain");
+            putMethod.setRequestEntity(new StringRequestEntity("some content", "text/plain",
+                                                               "UTF-8"));
+            client.executeMethod(putMethod);
+
+            assertEquals(200, putMethod.getStatusCode());
+            assertEquals("some content", putMethod.getResponseBodyAsString());
+        } finally {
+            putMethod.releaseConnection();
+        }
+
+        putMethod = new PutMethod(getBaseURI() + "/targeting/resourcewithmethod");
+        try {
+            putMethod.addRequestHeader("Accept", "text/customplain");
+            putMethod.setRequestEntity(new StringRequestEntity("some content", "text/plain",
+                                                               "UTF-8"));
+            client.executeMethod(putMethod);
+
+            assertEquals(406, putMethod.getStatusCode());
+            assertEquals("", putMethod.getResponseBodyAsString());
+        } finally {
+            putMethod.releaseConnection();
+        }
+    }
+}

Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/exceptions/NullValuesDuringTargettingTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/exceptions/NullValuesDuringTargettingTest.java?rev=794815&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/exceptions/NullValuesDuringTargettingTest.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/exceptions/NullValuesDuringTargettingTest.java Thu Jul 16 20:01:58 2009
@@ -0,0 +1,336 @@
+/*
+ * 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.exceptions;
+
+import java.io.IOException;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Produces;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+public class NullValuesDuringTargettingTest extends TestCase {
+
+    public static String getBaseURI() {
+        return ServerEnvironmentInfo.getBaseURI() + "/exceptional";
+    }
+
+    /**
+     * Tests that a request to a method with no content type, no request entity,
+     * but with a {@link Consumes} method results in a 415 error.
+     * 
+     * @throws IOException
+     */
+    public void testNoContentTypeWithNoRequestEntityIncomingRequestWithConsumesMethod()
+        throws IOException {
+        HttpClient client = new HttpClient();
+
+        PostMethod postMethod =
+            new PostMethod(getBaseURI() + "/targeting/nullresource/withconsumes");
+        try {
+            client.executeMethod(postMethod);
+            assertEquals(415, postMethod.getStatusCode());
+            assertEquals("", postMethod.getResponseBodyAsString());
+            assertNull(postMethod.getResponseHeader("Content-Type"));
+        } finally {
+            postMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a request to a method with no content type, a request entity,
+     * but with a {@link Consumes} method results in a 415 error.
+     * 
+     * @throws IOException
+     */
+    public void testNoContentTypeWithRequestEntityIncomingRequestWithConsumesMethod()
+        throws IOException {
+        HttpClient client = new HttpClient();
+
+        PostMethod postMethod =
+            new PostMethod(getBaseURI() + "/targeting/nullresource/withconsumes");
+        postMethod.setRequestEntity(new ByteArrayRequestEntity(new byte[] {0, 1, 2}));
+        try {
+            client.executeMethod(postMethod);
+            assertEquals(415, postMethod.getStatusCode());
+            assertEquals("", postMethod.getResponseBodyAsString());
+            assertNull(postMethod.getResponseHeader("Content-Type"));
+        } finally {
+            postMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a request to a method with no content type, a request entity,
+     * but without a {@link Consumes} method results in 200 successful method
+     * invocation.
+     * 
+     * @throws IOException
+     */
+    public void testNoContentTypeWithRequestEntityIncomingRequestWithNoConsumesMethod()
+        throws IOException {
+        HttpClient client = new HttpClient();
+
+        PostMethod postMethod =
+            new PostMethod(getBaseURI() + "/targeting/nullresource/withoutconsumes");
+        postMethod.setRequestEntity(new ByteArrayRequestEntity("calledWithString".getBytes()));
+        try {
+            client.executeMethod(postMethod);
+            assertEquals(200, postMethod.getStatusCode());
+            assertEquals("userReadercalledWithString", postMethod.getResponseBodyAsString());
+            String contentType =
+                (postMethod.getResponseHeader("Content-Type") == null) ? null : postMethod
+                    .getResponseHeader("Content-Type").getValue();
+            assertNotNull(contentType, contentType);
+        } finally {
+            postMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a request to a method with a content type, a request entity,
+     * but without a {@link Consumes} method results in 200 successful method
+     * invocation.
+     * 
+     * @throws IOException
+     */
+    public void testContentTypeWithRequestEntityIncomingRequestWithNoConsumesMethod()
+        throws IOException {
+        HttpClient client = new HttpClient();
+
+        PostMethod postMethod =
+            new PostMethod(getBaseURI() + "/targeting/nullresource/withoutconsumes");
+        postMethod
+            .setRequestEntity(new ByteArrayRequestEntity("myString".getBytes(), "custom/type"));
+        try {
+            client.executeMethod(postMethod);
+            assertEquals(200, postMethod.getStatusCode());
+            assertEquals("myString", postMethod.getResponseBodyAsString());
+            String contentType =
+                (postMethod.getResponseHeader("Content-Type") == null) ? null : postMethod
+                    .getResponseHeader("Content-Type").getValue();
+            assertNotNull(contentType, contentType);
+        } finally {
+            postMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a request to a method with a content type, no request entity,
+     * but without a {@link Consumes} method results in 200 successful method
+     * invocation.
+     * 
+     * @throws IOException
+     */
+    public void testContentTypeWithNoRequestEntityIncomingRequestWithNoConsumesMethod()
+        throws IOException {
+        HttpClient client = new HttpClient();
+
+        PostMethod postMethod =
+            new PostMethod(getBaseURI() + "/targeting/nullresource/withoutconsumes");
+        postMethod.setRequestHeader("Content-Type", "text/plain");
+        try {
+            client.executeMethod(postMethod);
+            assertEquals(200, postMethod.getStatusCode());
+            assertEquals("", postMethod.getResponseBodyAsString());
+            String contentType =
+                (postMethod.getResponseHeader("Content-Type") == null) ? null : postMethod
+                    .getResponseHeader("Content-Type").getValue();
+            assertNotNull(contentType, contentType);
+        } finally {
+            postMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a request to a method with no content type, no request entity,
+     * but without a {@link Consumes} method results in 200 successful method
+     * invocation.
+     * 
+     * @throws IOException
+     */
+    public void testNoContentTypeWithNoRequestEntityIncomingRequestWithNoConsumesMethod()
+        throws IOException {
+        HttpClient client = new HttpClient();
+
+        PostMethod postMethod =
+            new PostMethod(getBaseURI() + "/targeting/nullresource/withoutconsumes");
+        try {
+            client.executeMethod(postMethod);
+            assertEquals(200, postMethod.getStatusCode());
+            assertEquals("userReader", postMethod.getResponseBodyAsString());
+            String contentType =
+                (postMethod.getResponseHeader("Content-Type") == null) ? null : postMethod
+                    .getResponseHeader("Content-Type").getValue();
+            assertNotNull(contentType, contentType);
+        } finally {
+            postMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a request to a method with a content type, no request entity,
+     * but with a {@link Consumes} method results in 200 successful method
+     * invocation.
+     * 
+     * @throws IOException
+     */
+    public void testContentTypeWithNoRequestEntityIncomingRequestWithConsumesMethod()
+        throws IOException {
+        HttpClient client = new HttpClient();
+
+        PostMethod postMethod =
+            new PostMethod(getBaseURI() + "/targeting/nullresource/withconsumes");
+        postMethod.setRequestHeader("Content-Type", "text/plain");
+        try {
+            client.executeMethod(postMethod);
+            assertEquals(200, postMethod.getStatusCode());
+            assertEquals("", postMethod.getResponseBodyAsString());
+            String contentType =
+                (postMethod.getResponseHeader("Content-Type") == null) ? null : postMethod
+                    .getResponseHeader("Content-Type").getValue();
+            assertNotNull(contentType, contentType);
+        } finally {
+            postMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a request to a method with a content type, a request entity,
+     * but with a {@link Consumes} method results in 200 successful method
+     * invocation.
+     * 
+     * @throws IOException
+     */
+    public void testContentTypeWithRequestEntityIncomingRequestWithConsumesMethod()
+        throws IOException {
+        HttpClient client = new HttpClient();
+
+        PostMethod postMethod =
+            new PostMethod(getBaseURI() + "/targeting/nullresource/withconsumes");
+        postMethod
+            .setRequestEntity(new ByteArrayRequestEntity("mystring".getBytes(), "text/plain"));
+        try {
+            client.executeMethod(postMethod);
+            assertEquals(200, postMethod.getStatusCode());
+            assertEquals("mystring", postMethod.getResponseBodyAsString());
+            String contentType =
+                (postMethod.getResponseHeader("Content-Type") == null) ? null : postMethod
+                    .getResponseHeader("Content-Type").getValue();
+            assertNotNull(contentType, contentType);
+        } finally {
+            postMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a request to a method with an Accept header with a
+     * {@link Produces} method results in 200 successful method invocation.
+     * 
+     * @throws IOException
+     */
+    public void testAcceptHeaderIncomingRequestWithProducesMethod() throws IOException {
+        HttpClient client = new HttpClient();
+
+        PostMethod postMethod =
+            new PostMethod(getBaseURI() + "/targeting/nullresource/withproduces");
+        postMethod.setRequestHeader("Accept", "custom/type; q=0.8");
+        try {
+            client.executeMethod(postMethod);
+            assertEquals(200, postMethod.getStatusCode());
+            assertEquals("calledWithProduces", postMethod.getResponseBodyAsString());
+            assertEquals("custom/type;q=0.8", postMethod.getResponseHeader("Content-Type").getValue());
+        } finally {
+            postMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a request to a method with an Accept header with no
+     * {@link Produces} method results in 200 successful method invocation.
+     * 
+     * @throws IOException
+     */
+    public void testAcceptHeaderIncomingRequestWithNoProducesMethod() throws IOException {
+        HttpClient client = new HttpClient();
+
+        PostMethod postMethod =
+            new PostMethod(getBaseURI() + "/targeting/nullresource/withoutproduces");
+        postMethod.setRequestHeader("Accept", "custom/type2; q=0.8");
+        try {
+            client.executeMethod(postMethod);
+            assertEquals(200, postMethod.getStatusCode());
+            assertEquals("calledWithoutProduces", postMethod.getResponseBodyAsString());
+            assertEquals("custom/type2;q=0.8", postMethod.getResponseHeader("Content-Type").getValue());
+        } finally {
+            postMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a request to a method with no Accept header with a
+     * {@link Produces} method results in 200 successful method invocation.
+     * 
+     * @throws IOException
+     */
+    public void testNoAcceptHeaderIncomingRequestWithProducesMethod() throws IOException {
+        HttpClient client = new HttpClient();
+
+        PostMethod postMethod =
+            new PostMethod(getBaseURI() + "/targeting/nullresource/withproduces");
+        try {
+            client.executeMethod(postMethod);
+            assertEquals(200, postMethod.getStatusCode());
+            assertEquals("calledWithProduces", postMethod.getResponseBodyAsString());
+            assertEquals("custom/type", postMethod.getResponseHeader("Content-Type").getValue());
+        } finally {
+            postMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a request to a method with no Accept header with no
+     * {@link Produces} method results in 200 successful method invocation.
+     * 
+     * @throws IOException
+     */
+    public void testNoAcceptHeaderIncomingRequestWithNoProducesMethod() throws IOException {
+        HttpClient client = new HttpClient();
+
+        PostMethod postMethod =
+            new PostMethod(getBaseURI() + "/targeting/nullresource/withoutproduces");
+        try {
+            client.executeMethod(postMethod);
+            assertEquals(200, postMethod.getStatusCode());
+            assertEquals("calledWithoutProduces", postMethod.getResponseBodyAsString());
+            String contentType =
+                (postMethod.getResponseHeader("Content-Type") == null) ? null : postMethod
+                    .getResponseHeader("Content-Type").getValue();
+            assertNotNull(contentType, contentType);
+        } finally {
+            postMethod.releaseConnection();
+        }
+    }
+}

Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/exceptions/ValidationDuringTargettingTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/exceptions/ValidationDuringTargettingTest.java?rev=794815&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/exceptions/ValidationDuringTargettingTest.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/exceptions/ValidationDuringTargettingTest.java Thu Jul 16 20:01:58 2009
@@ -0,0 +1,235 @@
+/*
+ * 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.exceptions;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Produces;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+public class ValidationDuringTargettingTest extends TestCase {
+
+    public static String getBaseURI() {
+        return ServerEnvironmentInfo.getBaseURI() + "/exceptional";
+    }
+
+    /**
+     * Tests that a GET method to various paths only differing by
+     * {@link Produces} works.
+     * 
+     * @throws Exception
+     */
+    public void testGETOnlyDifferByProduces() throws Exception {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI() + "/targeting/resourceonlyproduces");
+        try {
+            getMethod.addRequestHeader("Accept", "application/json");
+            client.executeMethod(getMethod);
+
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("Hello JSON Produces", getMethod.getResponseBodyAsString());
+            assertEquals("application/json", getMethod.getResponseHeader("Content-Type").getValue());
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        getMethod = new GetMethod(getBaseURI() + "/targeting/resourceonlyproduces");
+
+        try {
+            getMethod.addRequestHeader("Accept", "application/xml");
+            client.executeMethod(getMethod);
+
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("Hello XML Produces", getMethod.getResponseBodyAsString());
+            assertEquals("application/xml", getMethod.getResponseHeader("Content-Type").getValue());
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        getMethod = new GetMethod(getBaseURI() + "/targeting/resourceonlyproduces");
+
+        try {
+            getMethod.addRequestHeader("Accept", "text/xml");
+            client.executeMethod(getMethod);
+
+            assertEquals(406, getMethod.getStatusCode());
+            assertEquals("", getMethod.getResponseBodyAsString());
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        // boolean isWarningThrown = true;
+        // try {
+        // FVTAssert.assertLogContainsException("WARN");
+        // FVTAssert.assertInstallLogContainsException("WARN");
+        // } catch (AssertionError e) {
+        // isWarningThrown = false;
+        // }
+        //
+        // assertFalse("Warning should not be emitted", isWarningThrown);
+    }
+
+    /**
+     * Tests that a GET method to various paths only differing by
+     * {@link Consumes} works.
+     * 
+     * @throws Exception
+     */
+    public void testGETOnlyDifferByConsumes() throws Exception {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI() + "/targeting/resourceonlyconsumes");
+        getMethod.setRequestHeader("Content-Type", "application/json");
+        try {
+            client.executeMethod(getMethod);
+
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("Hello JSON Consumes", getMethod.getResponseBodyAsString());
+            assertEquals("text/plain", getMethod.getResponseHeader("Content-Type").getValue());
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        getMethod = new GetMethod(getBaseURI() + "/targeting/resourceonlyconsumes");
+        getMethod.setRequestHeader("Content-Type", "text/xml");
+
+        try {
+            client.executeMethod(getMethod);
+
+            assertEquals(415, getMethod.getStatusCode());
+            assertEquals("", getMethod.getResponseBodyAsString());
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        // boolean isWarningThrown = true;
+        // try {
+        // FVTAssert.assertLogContainsException("WARN");
+        // FVTAssert.assertInstallLogContainsException("WARN");
+        // } catch (AssertionError e) {
+        // isWarningThrown = false;
+        // }
+        //
+        // assertFalse("Warning should not be emitted", isWarningThrown);
+    }
+
+    /**
+     * Tests that a GET method to various paths only differing by
+     * {@link Consumes} works.
+     * 
+     * @throws Exception
+     */
+    public void testGETOnlyDifferByConsumesAndProduces() throws Exception {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod =
+            new GetMethod(getBaseURI() + "/targeting/resourceconsumesandproduces");
+        getMethod.setRequestHeader("Content-Type", "application/json");
+        getMethod.setRequestHeader("Accept", "application/json");
+        try {
+            client.executeMethod(getMethod);
+
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("Hello JSON Consumes And Produces", getMethod.getResponseBodyAsString());
+            assertEquals("application/json", getMethod.getResponseHeader("Content-Type").getValue());
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        getMethod = new GetMethod(getBaseURI() + "/targeting/resourceconsumesandproduces");
+        getMethod.setRequestHeader("Content-Type", "application/json");
+        try {
+            client.executeMethod(getMethod);
+
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("Hello JSON Consumes And Produces", getMethod.getResponseBodyAsString());
+            assertEquals("application/json", getMethod.getResponseHeader("Content-Type").getValue());
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        /*
+         * due to no request Accept header, this is actually undefined behavior
+         * whether it hits the JSON or the XML on the Produces side
+         */
+        getMethod = new GetMethod(getBaseURI() + "/targeting/resourceconsumesandproduces");
+        getMethod.setRequestHeader("Content-Type", "application/xml");
+        try {
+            client.executeMethod(getMethod);
+
+            if ("application/json".equals(getMethod.getResponseHeader("Content-Type").getValue())) {
+                assertEquals(200, getMethod.getStatusCode());
+                assertEquals("Hello XML Consumes And JSON Produces", getMethod
+                    .getResponseBodyAsString());
+                assertEquals("application/json", getMethod.getResponseHeader("Content-Type")
+                    .getValue());
+            } else {
+                assertEquals(200, getMethod.getStatusCode());
+                assertEquals("Hello XML Consumes And Produces", getMethod.getResponseBodyAsString());
+                assertEquals("application/xml", getMethod.getResponseHeader("Content-Type")
+                    .getValue());
+            }
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        getMethod = new GetMethod(getBaseURI() + "/targeting/resourceconsumesandproduces");
+        getMethod.setRequestHeader("Content-Type", "application/xml");
+        getMethod.setRequestHeader("Accept", "application/xml");
+        try {
+            client.executeMethod(getMethod);
+
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("Hello XML Consumes And Produces", getMethod.getResponseBodyAsString());
+            assertEquals("application/xml", getMethod.getResponseHeader("Content-Type").getValue());
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        getMethod = new GetMethod(getBaseURI() + "/targeting/resourceconsumesandproduces");
+        getMethod.setRequestHeader("Content-Type", "application/xml");
+        getMethod.setRequestHeader("Accept", "application/json");
+        try {
+            client.executeMethod(getMethod);
+
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("Hello XML Consumes And JSON Produces", getMethod
+                .getResponseBodyAsString());
+            assertEquals("application/json", getMethod.getResponseHeader("Content-Type").getValue());
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        // boolean isWarningThrown = true;
+        // try {
+        // FVTAssert.assertLogContainsException("WARN");
+        // FVTAssert.assertInstallLogContainsException("WARN");
+        // } catch (AssertionError e) {
+        // isWarningThrown = false;
+        // }
+        //
+        // assertFalse("Warning should not be emitted", isWarningThrown);
+    }
+}

Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/headers/HeadersTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/headers/HeadersTest.java?rev=794815&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/headers/HeadersTest.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/headers/HeadersTest.java Thu Jul 16 20:01:58 2009
@@ -0,0 +1,304 @@
+/*
+ * 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.headers;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.URI;
+import org.apache.commons.httpclient.URIException;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.OptionsMethod;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+public class HeadersTest extends TestCase {
+
+    private HttpClient          httpClient;
+
+    final private static String BASE_URI = getBaseURI() + "/headers";
+
+    public static String getBaseURI() {
+        return ServerEnvironmentInfo.getBaseURI() + "/headers";
+    }
+
+    public void testGetWithCookies() throws Exception {
+        try {
+            GetMethod httpMethod = new GetMethod();
+            httpMethod.setURI(new URI(BASE_URI + "/cookie", false));
+            httpClient = new HttpClient();
+            httpMethod.setRequestHeader("Cookie", "$Version=\"1\";login=\"jdoe\"");
+            try {
+                int result = httpClient.executeMethod(httpMethod);
+                System.out.println("Response status code: " + result);
+                assertEquals(200, result);
+                assertNotNull(httpMethod.getResponseHeader("login"));
+                assertEquals("jdoe", httpMethod.getResponseHeader("login").getValue());
+            } catch (IOException ioe) {
+                ioe.printStackTrace();
+                fail(ioe.getMessage());
+            } finally {
+                httpMethod.releaseConnection();
+            }
+        } catch (URIException e) {
+            e.printStackTrace();
+            fail(e.getMessage());
+        }
+    }
+
+    public void testGetWithLanguage() throws Exception {
+        try {
+            GetMethod httpMethod = new GetMethod();
+            httpMethod.setURI(new URI(BASE_URI + "/language", false));
+            httpClient = new HttpClient();
+            httpMethod.setRequestHeader("Content-Language", "en-us");
+            try {
+                int result = httpClient.executeMethod(httpMethod);
+                System.out.println("Response status code: " + result);
+                assertEquals(200, result);
+                assertNotNull(httpMethod.getResponseHeader("language"));
+                assertEquals("en:US", httpMethod.getResponseHeader("language").getValue());
+            } catch (IOException ioe) {
+                ioe.printStackTrace();
+                fail(ioe.getMessage());
+            } finally {
+                httpMethod.releaseConnection();
+            }
+        } catch (URIException e) {
+            e.printStackTrace();
+            fail(e.getMessage());
+        }
+    }
+
+    public void testGetWithContent() throws Exception {
+        try {
+            GetMethod httpMethod = new GetMethod();
+            httpMethod.setURI(new URI(BASE_URI + "/content", false));
+            httpClient = new HttpClient();
+            httpMethod.setRequestHeader("Content-Type", "application/html");
+            try {
+                int result = httpClient.executeMethod(httpMethod);
+                System.out.println("Response status code: " + result);
+                assertEquals(200, result);
+                assertNotNull(httpMethod.getResponseHeader("content"));
+                assertEquals("application/html", httpMethod.getResponseHeader("content").getValue());
+            } catch (IOException ioe) {
+                ioe.printStackTrace();
+                fail(ioe.getMessage());
+            } finally {
+                httpMethod.releaseConnection();
+            }
+        } catch (URIException e) {
+            e.printStackTrace();
+            fail(e.getMessage());
+        }
+    }
+
+    public void testGetWithAccept() throws Exception {
+        try {
+            GetMethod httpMethod = new GetMethod();
+            httpMethod.setURI(new URI(BASE_URI + "/accept", false));
+            httpClient = new HttpClient();
+            httpMethod.setRequestHeader("Accept", "text/*, text/html, text/html;level=1, */*");
+            try {
+                int result = httpClient.executeMethod(httpMethod);
+                System.out.println("Response status code: " + result);
+                assertEquals(200, result);
+                assertNotNull(httpMethod.getResponseHeader("test-accept"));
+
+                // all q-values = 1, should come back like it was sent
+                String value = httpMethod.getResponseHeader("test-accept").getValue();
+                assertTrue(value, value.endsWith("*/*"));
+                assertTrue(value, value.contains("text/*"));
+                assertTrue(value, value.contains("text/html"));
+                assertTrue(value, value.contains("text/html;level=1"));
+            } catch (IOException ioe) {
+                ioe.printStackTrace();
+                fail(ioe.getMessage());
+            } finally {
+                httpMethod.releaseConnection();
+            }
+        } catch (URIException e) {
+            e.printStackTrace();
+            fail(e.getMessage());
+        }
+    }
+
+    public void testGetWithAcceptLanguage() throws Exception {
+        try {
+            GetMethod httpMethod = new GetMethod();
+            httpMethod.setURI(new URI(BASE_URI + "/acceptlang", false));
+            httpClient = new HttpClient();
+            httpMethod.setRequestHeader("Accept-Language", "fr");
+            try {
+                int result = httpClient.executeMethod(httpMethod);
+                System.out.println("Response status code: " + result);
+                assertEquals(200, result);
+                assertNotNull(httpMethod.getResponseHeader("acceptlang"));
+                assertEquals("fr", httpMethod.getResponseHeader("acceptlang").getValue());
+            } catch (IOException ioe) {
+                ioe.printStackTrace();
+                fail(ioe.getMessage());
+            } finally {
+                httpMethod.releaseConnection();
+            }
+        } catch (URIException e) {
+            e.printStackTrace();
+            fail(e.getMessage());
+        }
+    }
+
+    public void testGetHeadersWithCase() throws Exception {
+        try {
+            GetMethod httpMethod = new GetMethod();
+            httpMethod.setURI(new URI(BASE_URI + "/headercase", false));
+            httpClient = new HttpClient();
+            httpMethod.setRequestHeader("Custom-Header", "MyValue");
+            try {
+                int result = httpClient.executeMethod(httpMethod);
+                System.out.println("Response status code: " + result);
+                assertEquals(200, result);
+                assertNotNull(httpMethod.getResponseHeader("Custom-Header"));
+                assertEquals("MyValue", httpMethod.getResponseHeader("Custom-Header").getValue());
+            } catch (IOException ioe) {
+                ioe.printStackTrace();
+                fail(ioe.getMessage());
+            } finally {
+                httpMethod.releaseConnection();
+            }
+        } catch (URIException e) {
+            e.printStackTrace();
+            fail(e.getMessage());
+        }
+    }
+
+    public void testGetHeadersAcceptAsParam() throws Exception {
+        try {
+            GetMethod httpMethod = new GetMethod();
+            httpMethod.setURI(new URI(BASE_URI + "/headeraccept", false));
+            httpClient = new HttpClient();
+            httpMethod.setRequestHeader("Accept", "text/xml");
+            try {
+                int result = httpClient.executeMethod(httpMethod);
+                System.out.println("Response status code: " + result);
+                assertEquals(200, result);
+                assertNotNull(httpMethod.getResponseHeader("test-accept"));
+                assertEquals("text/xml", httpMethod.getResponseHeader("test-accept").getValue());
+            } catch (IOException ioe) {
+                ioe.printStackTrace();
+                fail(ioe.getMessage());
+            } finally {
+                httpMethod.releaseConnection();
+            }
+        } catch (URIException e) {
+            e.printStackTrace();
+            fail(e.getMessage());
+        }
+    }
+
+    public void testGetHeadersAcceptAsArg() throws Exception {
+        try {
+            GetMethod httpMethod = new GetMethod();
+            httpMethod.setURI(new URI(BASE_URI + "/headersasarg", false));
+            httpClient = new HttpClient();
+            httpMethod.setRequestHeader("Accept", "text/xml application/xml");
+            httpMethod.setRequestHeader("Content-Type", "application/xml");
+            try {
+                int result = httpClient.executeMethod(httpMethod);
+                System.out.println("Response status code: " + result);
+                assertEquals(200, result);
+                assertNotNull(httpMethod.getResponseHeader("test-accept"));
+                assertEquals("text/xml application/xml", httpMethod
+                    .getResponseHeader("test-accept").getValue());
+                assertNotNull(httpMethod.getResponseHeader("test-content-type"));
+                assertEquals("application/xml", httpMethod.getResponseHeader("test-content-type")
+                    .getValue());
+            } catch (IOException ioe) {
+                ioe.printStackTrace();
+                fail(ioe.getMessage());
+            } finally {
+                httpMethod.releaseConnection();
+            }
+        } catch (URIException e) {
+            e.printStackTrace();
+            fail(e.getMessage());
+        }
+    }
+
+    public void testAllowHeaders() throws Exception {
+        try {
+            OptionsMethod httpMethod = new OptionsMethod();
+            httpMethod.setURI(new URI(getBaseURI() + "/headersallow1/allow1", false));
+            httpClient = new HttpClient();
+            try {
+                int result = httpClient.executeMethod(httpMethod);
+                assertEquals(204, result);
+                assertNotNull(httpMethod.getResponseHeader("Allow"));
+                List<String> allowedMethods =
+                    Arrays.asList(httpMethod.getResponseHeader("Allow").getValue().split(", "));
+                System.out.println(allowedMethods);
+                assertEquals(3, allowedMethods.size());
+                assertTrue(allowedMethods.contains("HEAD"));
+                assertTrue(allowedMethods.contains("OPTIONS"));
+                assertTrue(allowedMethods.contains("GET"));
+            } catch (IOException ioe) {
+                ioe.printStackTrace();
+                fail(ioe.getMessage());
+            } finally {
+                httpMethod.releaseConnection();
+            }
+        } catch (URIException e) {
+            e.printStackTrace();
+            fail(e.getMessage());
+        }
+
+        try {
+            OptionsMethod httpMethod = new OptionsMethod();
+            httpMethod.setURI(new URI(getBaseURI() + "/headersallow2", false));
+            httpClient = new HttpClient();
+            try {
+                int result = httpClient.executeMethod(httpMethod);
+                assertEquals(204, result);
+                assertNotNull(httpMethod.getResponseHeader("Allow"));
+                List<String> allowedMethods =
+                    Arrays.asList(httpMethod.getResponseHeader("Allow").getValue().split(", "));
+                System.out.println(allowedMethods);
+                assertEquals(6, allowedMethods.size());
+                assertTrue(allowedMethods.contains("HEAD"));
+                assertTrue(allowedMethods.contains("OPTIONS"));
+                assertTrue(allowedMethods.contains("GET"));
+                assertTrue(allowedMethods.contains("PUT"));
+                assertTrue(allowedMethods.contains("POST"));
+                assertTrue(allowedMethods.contains("DELETE"));
+            } catch (IOException ioe) {
+                ioe.printStackTrace();
+                fail(ioe.getMessage());
+            } finally {
+                httpMethod.releaseConnection();
+            }
+        } catch (URIException e) {
+            e.printStackTrace();
+            fail(e.getMessage());
+        }
+    }
+}

Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/largeentity/LargeEntityTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/largeentity/LargeEntityTest.java?rev=794815&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/largeentity/LargeEntityTest.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-targetting/src/test/java/org/apache/wink/jaxrs/test/largeentity/LargeEntityTest.java Thu Jul 16 20:01:58 2009
@@ -0,0 +1,94 @@
+/*
+ * 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.largeentity;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.FileRequestEntity;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+public class LargeEntityTest extends TestCase {
+
+    public static String getBaseURI() {
+        return ServerEnvironmentInfo.getBaseURI() + "/largeentity";
+    }
+
+    /**
+     * Tests sending a large string. Possible failures including the servlet
+     * request buffer being too small, so the status headers do not get set
+     * correctly since the message body will have to be flushed out of the
+     * servlet response buffer.
+     * 
+     * @throws Exception
+     */
+    public void testSendLargeString() throws Exception {
+        PostMethod postMethod = new PostMethod(getBaseURI() + "/large");
+        HttpClient client = new HttpClient();
+        try {
+            StringBuffer sb = new StringBuffer();
+            for (long c = 0; c < 5000000; ++c) {
+                sb.append("a");
+            }
+            postMethod.setRequestEntity(new StringRequestEntity(sb.toString(), "text/xml", null));
+            client.executeMethod(postMethod);
+            assertEquals(277, postMethod.getStatusCode());
+            Header header = postMethod.getResponseHeader("appendStringsHeader");
+            assertNotNull(header);
+            assertEquals(sb.subSequence(0, 2042) + "header", header.getValue());
+            String resp = postMethod.getResponseBodyAsString();
+            assertEquals(sb.toString() + "entity", resp);
+        } finally {
+            postMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests sending a JAR file.
+     * 
+     * @throws Exception
+     */
+    public void testSendJAR() throws Exception {
+        PostMethod postMethod = new PostMethod(getBaseURI() + "/large/zip");
+        HttpClient client = new HttpClient();
+        try {
+            System.out
+                .println(new File(
+                                  ServerEnvironmentInfo.getWorkDir() + "/wink-jaxrs-test-targetting-0.1-SNAPSHOT.war")
+                    .getAbsoluteFile().getAbsolutePath());
+            postMethod
+                .setRequestEntity(new FileRequestEntity(
+                                                        new File(
+                                  ServerEnvironmentInfo.getWorkDir() + "/wink-jaxrs-test-targetting-0.1-SNAPSHOT.war"),
+                                                        "application/jar"));
+            client.executeMethod(postMethod);
+            assertEquals(290, postMethod.getStatusCode());
+            String resp = postMethod.getResponseBodyAsString();
+            assertEquals("META-INF/DEPENDENCIES", resp);
+        } finally {
+            postMethod.releaseConnection();
+        }
+    }
+}