wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r819192 [1/3] - in /incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src: main/resources/ main/resources/tests/ main/resources/tests/test-resources/ test/java/org/apache/wink/itest/addressbook/ test/java/org/apache/wink/ites...
Date Sat, 26 Sep 2009 19:21:12 GMT
Author: bluk
Date: Sat Sep 26 19:21:10 2009
New Revision: 819192

URL: http://svn.apache.org/viewvc?rev=819192&view=rev
Log:
Port wink-itest-targeting to RestClient

Added:
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/resources/
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/resources/tests/
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/resources/tests/test-resources/
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/resources/tests/test-resources/1040_2007.xml   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/resources/tests/test-resources/1040_2008.xml   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/addressbook/WinkApacheClientStringTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/addressbook/WinkClientStringTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/cachetest/NewsWinkApacheClient.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/cachetest/NewsWinkClient.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/cachetest/WinkApacheNewsClientTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/cachetest/WinkNewsClientTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentencoding/WinkApacheContentEncodingTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentencoding/WinkContentEncodingTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentnegotiation/WinkApacheContentNegotiationClientTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentnegotiation/WinkContentNegotiationClientTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/exceptions/WinkApacheExceptionsDuringTargetingTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/exceptions/WinkApacheNullValuesDuringTargetingTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/exceptions/WinkApacheValidationDuringTargetingTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/exceptions/WinkExceptionsWhileTargetingTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/exceptions/WinkNullValuesDuringTargetingTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/exceptions/WinkValidationDuringTargetingTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/headers/WinkApacheHeadersTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/headers/WinkHeadersTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/largeentity/WinkApacheClientLargeEntityTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/largeentity/WinkClientLargeEntityTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/lifecycles/WinkApacheClientLifeCycleTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/lifecycles/WinkClientLifeCycleTest.java
      - copied, changed from r819007, incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/lifecycles/LifeCycleTest.java
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/methodannotations/WinkApacheHttpMethodTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/methodannotations/WinkApacheHttpMethodWarningsTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/methodannotations/WinkHttpMethodTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/methodannotations/WinkHttpMethodWarningsTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/nofindmethods/WinkApacheDoNotUseMethodNamesForHTTPVerbsTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/nofindmethods/WinkDoNotUseMethodNamesForHTTPVerbsTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/returntypes/WinkApacheClientReturnTypeStatusTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/returntypes/WinkClientReturnTypeStatusTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/sequence/WinkApacheClientSequenceTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/sequence/WinkClientSequenceTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/transferencoding/WinkApacheTransferEncodingTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/transferencoding/WinkTransferEncodingTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/version/VersioningTest.java   (contents, props changed)
      - copied, changed from r819007, incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/version/VersioningTests.java
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/version/WinkApacheClientVersioningTest.java   (with props)
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/version/WinkClientVersioningTest.java   (with props)
Removed:
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/version/VersioningTests.java
Modified:
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/addressbook/StringTest.java
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentnegotiation/ContentNegotiationClientTest.java
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/exceptions/ExceptionsWhileTargettingTest.java
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/exceptions/NullValuesDuringTargettingTest.java
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/exceptions/ValidationDuringTargettingTest.java
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/headers/HeadersTest.java
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/largeentity/LargeEntityTest.java
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/lifecycles/LifeCycleTest.java
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/nofindmethods/DoNotUseMethodNamesForHTTPVerbsTest.java
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/returntypes/ReturnTypeStatusTest.java
    incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/sequence/SequenceTest.java

Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/resources/tests/test-resources/1040_2007.xml
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/resources/tests/test-resources/1040_2007.xml?rev=819192&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/resources/tests/test-resources/1040_2007.xml (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/resources/tests/test-resources/1040_2007.xml Sat Sep 26 19:21:10 2009
@@ -0,0 +1,25 @@
+<!--
+    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.
+-->
+<taxform name="1040" version="2007">
+
+<name></name>
+<address></address>
+<income></income>
+<deductions></deductions>
+</taxform>

Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/resources/tests/test-resources/1040_2007.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/resources/tests/test-resources/1040_2008.xml
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/resources/tests/test-resources/1040_2008.xml?rev=819192&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/resources/tests/test-resources/1040_2008.xml (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/resources/tests/test-resources/1040_2008.xml Sat Sep 26 19:21:10 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.
+-->
+<taxform name="1040" version="2007">
+<name></name>
+<address></address>
+<income></income>
+</taxform>

Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/main/resources/tests/test-resources/1040_2008.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/addressbook/StringTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/addressbook/StringTest.java?rev=819192&r1=819191&r2=819192&view=diff
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/addressbook/StringTest.java (original)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/addressbook/StringTest.java Sat Sep 26 19:21:10 2009
@@ -29,8 +29,6 @@
 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.itest.addressbook.Address;
-import org.apache.wink.itest.addressbook.AddressBook;
 import org.apache.wink.test.integration.ServerContainerAssertions;
 import org.apache.wink.test.integration.ServerEnvironmentInfo;
 
@@ -41,20 +39,33 @@
  */
 public class StringTest extends TestCase {
 
-    final private static String BASE_URI =
-                                             ServerEnvironmentInfo.getBaseURI() + (ServerEnvironmentInfo
-                                                 .isRestFilterUsed() ? "" : "/addressBook/")
-                                                 + "/unittests/addresses";
+    protected static String getBaseURI() {
+        if (ServerEnvironmentInfo.isRestFilterUsed()) {
+            return ServerEnvironmentInfo.getBaseURI() + "/unittests/addresses";
+        }
+        return ServerEnvironmentInfo.getBaseURI() + "/addressBook/unittests/addresses";
+    }
+
+    protected HttpClient client;
 
     @Override
-    public void setUp() {
+    public void setUp() throws Exception {
+        super.setUp();
+        client = new HttpClient();
+
+        /*
+         * clear the database entries
+         */
+        clearDatabase();
+    }
+
+    public void clearDatabase() {
         /*
          * clear the database entries
          */
-        HttpClient client = new HttpClient();
         HttpMethod method = null;
         try {
-            method = new PostMethod(BASE_URI + "/clear");
+            method = new PostMethod(getBaseURI() + "/clear");
             client.executeMethod(method);
             assertEquals(204, method.getStatusCode());
         } catch (Exception e) {
@@ -75,7 +86,7 @@
         HttpMethod method = null;
         try {
             HttpClient client = new HttpClient();
-            method = new GetMethod(BASE_URI);
+            method = new GetMethod(getBaseURI());
             client.executeMethod(method);
             String responseBody = method.getResponseBodyAsString();
             Address addr = AddressBook.defaultAddress;
@@ -105,13 +116,13 @@
 
             // make sure everything is clear before testing
             HttpClient client = new HttpClient();
-            method = new PostMethod(BASE_URI);
+            method = new PostMethod(getBaseURI());
             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");
+            getMethod = new GetMethod(getBaseURI() + "/newAddress");
             client.executeMethod(getMethod);
             assertEquals(200, getMethod.getStatusCode());
             String responseBody = getMethod.getResponseBodyAsString();
@@ -149,14 +160,14 @@
 
             // make sure everything is clear before testing
             HttpClient client = new HttpClient();
-            method = new PostMethod(BASE_URI + "/fromBody");
+            method = new PostMethod(getBaseURI() + "/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");
+            getMethod = new GetMethod(getBaseURI() + "/tempAddress");
             client.executeMethod(getMethod);
             String responseBody = getMethod.getResponseBodyAsString();
             getMethod.releaseConnection();
@@ -172,7 +183,7 @@
             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 = new PutMethod(getBaseURI());
             put.setQueryString(query);
             client.executeMethod(put);
 
@@ -187,7 +198,7 @@
 
             // now let's delete the address
             client = new HttpClient();
-            deleteMethod = new DeleteMethod(BASE_URI + "/tempAddress");
+            deleteMethod = new DeleteMethod(getBaseURI() + "/tempAddress");
             client.executeMethod(deleteMethod);
             assertEquals(204, deleteMethod.getStatusCode());
 

Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/addressbook/WinkApacheClientStringTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/addressbook/WinkApacheClientStringTest.java?rev=819192&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/addressbook/WinkApacheClientStringTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/addressbook/WinkApacheClientStringTest.java Sat Sep 26 19:21:10 2009
@@ -0,0 +1,36 @@
+/*
+ * 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.itest.addressbook;
+
+import org.apache.wink.client.ApacheHttpClientConfig;
+import org.apache.wink.client.RestClient;
+
+public class WinkApacheClientStringTest extends WinkClientStringTest {
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        client = new RestClient(new ApacheHttpClientConfig());
+
+        /*
+         * clear the database entries
+         */
+        clearDatabase();
+    }
+}

Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/addressbook/WinkApacheClientStringTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/addressbook/WinkClientStringTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/addressbook/WinkClientStringTest.java?rev=819192&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/addressbook/WinkClientStringTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/addressbook/WinkClientStringTest.java Sat Sep 26 19:21:10 2009
@@ -0,0 +1,146 @@
+/*
+ * 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.itest.addressbook;
+
+import javax.ws.rs.core.MediaType;
+
+import junit.framework.TestCase;
+
+import org.apache.wink.client.ClientResponse;
+import org.apache.wink.client.RestClient;
+import org.apache.wink.common.internal.MultivaluedMapImpl;
+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 WinkClientStringTest extends TestCase {
+
+    protected static String getBaseURI() {
+        if (ServerEnvironmentInfo.isRestFilterUsed()) {
+            return ServerEnvironmentInfo.getBaseURI() + "/unittests/addresses";
+        }
+        return ServerEnvironmentInfo.getBaseURI() + "/addressBook/unittests/addresses";
+    }
+
+    protected RestClient client;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        client = new RestClient();
+
+        /*
+         * clear the database entries
+         */
+        clearDatabase();
+    }
+
+    public void clearDatabase() {
+        ClientResponse response = client.resource(getBaseURI() + "/clear").post(null);
+        assertEquals(204, response.getStatusCode());
+    }
+
+    /**
+     * This will drive a GET request with no input parameters
+     */
+    public void testGetNoParams() {
+        String responseBody = client.resource(getBaseURI()).get(String.class);
+
+        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()));
+    }
+
+    /**
+     * This will drive a POST request with parameters from the query string
+     */
+    public void testPostWithQueryParams() {
+        MultivaluedMapImpl<String, String> queryParams = new MultivaluedMapImpl<String, String>();
+        queryParams.putSingle("entryName", "newAddress");
+        queryParams.putSingle("streetAddress", "1234 Any Street");
+        queryParams.putSingle("city", "AnyTown");
+        queryParams.putSingle("zipCode", "90210");
+        queryParams.putSingle("state", "TX");
+        queryParams.putSingle("country", "US");
+        client.resource(getBaseURI()).queryParams(queryParams).post(null);
+
+        // now let's see if the address we just created is available
+        ClientResponse response = client.resource(getBaseURI() + "/newAddress").get();
+        assertEquals(200, response.getStatusCode());
+        String responseBody = response.getEntity(String.class);
+        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"));
+    }
+
+    /**
+     * This will drive a POST, GET, UPDATE, and DELETE on the
+     * AddressBookResource
+     */
+    public void testAddressBookResource() {
+        // make sure everything is clear before testing
+        String input = "tempAddress&1234 Any Street&AnyTown&90210&TX&US";
+        ClientResponse response =
+            client.resource(getBaseURI() + "/fromBody").contentType(MediaType.TEXT_XML).post(input);
+        assertEquals(204, response.getStatusCode());
+
+        // now let's see if the address we just created is available
+        String responseBody = client.resource(getBaseURI() + "/tempAddress").get(String.class);
+        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
+        client.resource(getBaseURI()).queryParam("entryName", "tempAddress")
+            .queryParam("streetAddress", "1234 Any Street").queryParam("city", "AnyTown")
+            .queryParam("zipCode", "90210").queryParam("state", "AL").queryParam("country", "US")
+            .put(null);
+
+        // make sure the state has been updated
+        responseBody = client.resource(getBaseURI() +"/tempAddress").get(String.class);
+        assertNotNull(responseBody);
+        assertTrue(responseBody, responseBody.contains("tempAddress"));
+        assertFalse(responseBody, responseBody.contains("TX"));
+        assertTrue(responseBody, responseBody.contains("AL"));
+
+        // now let's delete the address
+        response = client.resource(getBaseURI() + "/tempAddress").delete();
+        assertEquals(204, response.getStatusCode());
+
+        // now try to get the address
+        response = client.resource(getBaseURI() + "/tempAddress").get();
+        assertEquals(404, response.getStatusCode());
+    }
+
+}

Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/addressbook/WinkClientStringTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/cachetest/NewsWinkApacheClient.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/cachetest/NewsWinkApacheClient.java?rev=819192&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/cachetest/NewsWinkApacheClient.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/cachetest/NewsWinkApacheClient.java Sat Sep 26 19:21:10 2009
@@ -0,0 +1,164 @@
+/*
+ * 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.itest.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.wink.client.ApacheHttpClientConfig;
+import org.apache.wink.client.ClientResponse;
+import org.apache.wink.client.Resource;
+import org.apache.wink.client.RestClient;
+import org.apache.wink.itest.cache.NewsStory;
+
+public class NewsWinkApacheClient implements NewsResource {
+
+    private String   baseURI;
+
+    private Header[] requestHeaders;
+
+    public NewsWinkApacheClient(String baseURI, Map<String, String> reqHdrs) {
+        this.baseURI = baseURI;
+        requestHeaders = createRequestHeaders(reqHdrs);
+    }
+
+    public Response addNewsStory(NewsStory story) throws Exception {
+        RestClient client = new RestClient(new ApacheHttpClientConfig());
+        Resource resource = client.resource(baseURI);
+        setRequestHeaders(resource);
+        JAXBContext context = JAXBContext.newInstance(NewsStory.class);
+        StringWriter sw = new StringWriter();
+        context.createMarshaller().marshal(story, sw);
+        ClientResponse response = resource.contentType("text/xml").post(sw.toString().getBytes());
+        int status = response.getStatusCode();
+        Response resp = Response.status(status).build();
+        for (String key : response.getHeaders().keySet()) {
+            List<String> values = response.getHeaders().get(key);
+            List<Object> objValues = new ArrayList<Object>();
+            for (String v : values) {
+                objValues.add(v);
+            }
+            resp.getMetadata().put(key, objValues);
+        }
+        return resp;
+    }
+
+    public Response updateNewsStory(NewsStory story) throws Exception {
+        RestClient client = new RestClient(new ApacheHttpClientConfig());
+        Resource resource = client.resource(baseURI);
+        setRequestHeaders(resource);
+
+        JAXBContext context = JAXBContext.newInstance(NewsStory.class);
+        StringWriter sw = new StringWriter();
+        context.createMarshaller().marshal(story, sw);
+
+        ClientResponse response = resource.contentType("text/xml").put(sw.toString().getBytes());
+        int status = response.getStatusCode();
+
+        Response resp = Response.status(status).build();
+        for (String key : response.getHeaders().keySet()) {
+            List<String> values = response.getHeaders().get(key);
+            List<Object> objValues = new ArrayList<Object>();
+            for (String v : values) {
+                objValues.add(v);
+            }
+            resp.getMetadata().put(key, objValues);
+        }
+        return resp;
+    }
+
+    public Response getNewsStory(String title) throws Exception {
+        RestClient client = new RestClient(new ApacheHttpClientConfig());
+        Resource resource = client.resource(this.baseURI + "/" + title);
+        setRequestHeaders(resource);
+
+        ClientResponse response = resource.contentType("text/xml").get();
+        int status = response.getStatusCode();
+
+        InputStream is = response.getEntity(InputStream.class);
+
+        NewsStory newsStory = null;
+        String contentLength = response.getHeaders().getFirst("Content-Length");
+        long cl = 0;
+        if(contentLength != null) {
+            cl = Long.valueOf(response.getHeaders().getFirst("Content-Length"));   
+        } 
+        if (is != null && status != 304 && status != 412) {
+            JAXBContext context = JAXBContext.newInstance(NewsStory.class);
+            newsStory = (NewsStory)context.createUnmarshaller().unmarshal(is);
+        }
+
+        Response resp = Response.status(status).entity(newsStory).build();
+        for (String key : response.getHeaders().keySet()) {
+            List<String> values = response.getHeaders().get(key);
+            List<Object> objValues = new ArrayList<Object>();
+            for (String v : values) {
+                objValues.add(v);
+            }
+            resp.getMetadata().put(key, objValues);
+        }
+        return resp;
+    }
+
+    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(Resource resource) {
+        if (requestHeaders != null) {
+            for (Header header : requestHeaders) {
+                resource.header(header.getName(), header.getValue());
+            }
+        }
+    }
+}

Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/cachetest/NewsWinkApacheClient.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/cachetest/NewsWinkClient.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/cachetest/NewsWinkClient.java?rev=819192&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/cachetest/NewsWinkClient.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/cachetest/NewsWinkClient.java Sat Sep 26 19:21:10 2009
@@ -0,0 +1,169 @@
+/*
+ * 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.itest.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.PutMethod;
+import org.apache.commons.httpclient.methods.RequestEntity;
+import org.apache.wink.client.ClientResponse;
+import org.apache.wink.client.Resource;
+import org.apache.wink.client.RestClient;
+import org.apache.wink.itest.cache.NewsStory;
+
+public class NewsWinkClient implements NewsResource {
+
+    private String   baseURI;
+
+    private Header[] requestHeaders;
+
+    public NewsWinkClient(String baseURI, Map<String, String> reqHdrs) {
+        this.baseURI = baseURI;
+        requestHeaders = createRequestHeaders(reqHdrs);
+    }
+
+    public Response addNewsStory(NewsStory story) throws Exception {
+        RestClient client = new RestClient();
+        Resource resource = client.resource(baseURI);
+        setRequestHeaders(resource);
+        JAXBContext context = JAXBContext.newInstance(NewsStory.class);
+        StringWriter sw = new StringWriter();
+        context.createMarshaller().marshal(story, sw);
+        ClientResponse response = resource.contentType("text/xml").post(sw.toString().getBytes());
+        int status = response.getStatusCode();
+        Response resp = Response.status(status).build();
+        for (String key : response.getHeaders().keySet()) {
+            List<String> values = response.getHeaders().get(key);
+            List<Object> objValues = new ArrayList<Object>();
+            for (String v : values) {
+                objValues.add(v);
+            }
+            resp.getMetadata().put(key, objValues);
+        }
+        return resp;
+    }
+
+    public Response updateNewsStory(NewsStory story) throws Exception {
+        RestClient client = new RestClient();
+        Resource resource = client.resource(baseURI);
+        setRequestHeaders(resource);
+
+        JAXBContext context = JAXBContext.newInstance(NewsStory.class);
+        StringWriter sw = new StringWriter();
+        context.createMarshaller().marshal(story, sw);
+
+        ClientResponse response = resource.contentType("text/xml").put(sw.toString().getBytes());
+        int status = response.getStatusCode();
+
+        Response resp = Response.status(status).build();
+        for (String key : response.getHeaders().keySet()) {
+            List<String> values = response.getHeaders().get(key);
+            List<Object> objValues = new ArrayList<Object>();
+            for (String v : values) {
+                objValues.add(v);
+            }
+            resp.getMetadata().put(key, objValues);
+        }
+        return resp;
+    }
+
+    public Response getNewsStory(String title) throws Exception {
+        RestClient client = new RestClient();
+        Resource resource = client.resource(this.baseURI + "/" + title);
+        setRequestHeaders(resource);
+
+        ClientResponse response = resource.contentType("text/xml").get();
+        int status = response.getStatusCode();
+
+        InputStream is = response.getEntity(InputStream.class);
+
+        NewsStory newsStory = null;
+        String contentLength = response.getHeaders().getFirst("Content-Length");
+        long cl = 0;
+        if(contentLength != null) {
+            cl = Long.valueOf(response.getHeaders().getFirst("Content-Length"));   
+        } 
+        if (is != null && status != 304) {
+            JAXBContext context = JAXBContext.newInstance(NewsStory.class);
+            newsStory = (NewsStory)context.createUnmarshaller().unmarshal(is);
+        }
+
+        Response resp = Response.status(status).entity(newsStory).build();
+        for (String key : response.getHeaders().keySet()) {
+            List<String> values = response.getHeaders().get(key);
+            List<Object> objValues = new ArrayList<Object>();
+            for (String v : values) {
+                objValues.add(v);
+            }
+            resp.getMetadata().put(key, objValues);
+        }
+        return resp;
+    }
+
+    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(Resource resource) {
+        if (requestHeaders != null) {
+            for (Header header : requestHeaders) {
+                resource.header(header.getName(), header.getValue());
+            }
+        }
+    }
+}

Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/cachetest/NewsWinkClient.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/cachetest/WinkApacheNewsClientTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/cachetest/WinkApacheNewsClientTest.java?rev=819192&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/cachetest/WinkApacheNewsClientTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/cachetest/WinkApacheNewsClientTest.java Sat Sep 26 19:21:10 2009
@@ -0,0 +1,159 @@
+/*
+ * 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.itest.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.wink.client.ApacheHttpClientConfig;
+import org.apache.wink.client.ClientResponse;
+import org.apache.wink.client.RestClient;
+import org.apache.wink.itest.cache.NewsStory;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+public class WinkApacheNewsClientTest extends TestCase {
+
+    final private static String     NEWS_BASE_URI =
+                                                      ServerEnvironmentInfo.getBaseURI() + ((ServerEnvironmentInfo
+                                                          .isRestFilterUsed()) ? "" : "/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"));
+    }
+
+    protected RestClient            client;
+
+    @Override
+    public void setUp() {
+        /*
+         * clear the database entries
+         */
+        client = new RestClient(new ApacheHttpClientConfig());
+        ClientResponse response = client.resource(NEWS_BASE_URI + "/clear").post(null);
+        assertEquals(204, response.getStatusCode());
+    }
+
+    /**
+     * 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");
+        NewsWinkApacheClient client = new NewsWinkApacheClient(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 NewsWinkApacheClient(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 NewsWinkApacheClient(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 NewsWinkApacheClient(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 NewsWinkApacheClient(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");
+        NewsWinkApacheClient client = new NewsWinkApacheClient(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 NewsWinkApacheClient(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 NewsWinkApacheClient(NEWS_BASE_URI, reqHdrs);
+        response = client.getNewsStory("Local%20Hero%20Saves%20Kid");
+        assertNotNull(response);
+        story = (NewsStory)response.getEntity();
+        assertNotNull(story);
+    }
+}

Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/cachetest/WinkApacheNewsClientTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/cachetest/WinkNewsClientTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/cachetest/WinkNewsClientTest.java?rev=819192&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/cachetest/WinkNewsClientTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/cachetest/WinkNewsClientTest.java Sat Sep 26 19:21:10 2009
@@ -0,0 +1,159 @@
+/*
+ * 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.itest.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.wink.client.ClientResponse;
+import org.apache.wink.client.RestClient;
+import org.apache.wink.itest.cache.NewsStory;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+public class WinkNewsClientTest extends TestCase {
+
+    final private static String     NEWS_BASE_URI =
+                                                      ServerEnvironmentInfo.getBaseURI() + ((ServerEnvironmentInfo
+                                                          .isRestFilterUsed()) ? "" : "/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"));
+    }
+
+    protected RestClient            client;
+
+    @Override
+    public void setUp() {
+        /*
+         * clear the database entries
+         */
+        client = new RestClient();
+        ClientResponse response = client.resource(NEWS_BASE_URI + "/clear").post(null);
+        assertEquals(204, response.getStatusCode());
+    }
+
+    /**
+     * 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");
+        NewsWinkClient client = new NewsWinkClient(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 NewsWinkClient(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 NewsWinkClient(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 NewsWinkClient(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 NewsWinkClient(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");
+        NewsWinkClient client = new NewsWinkClient(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 NewsWinkClient(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 NewsWinkClient(NEWS_BASE_URI, reqHdrs);
+        response = client.getNewsStory("Local%20Hero%20Saves%20Kid");
+        assertNotNull(response);
+        story = (NewsStory)response.getEntity();
+        assertNotNull(story);
+    }
+
+}

Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/cachetest/WinkNewsClientTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentencoding/WinkApacheContentEncodingTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentencoding/WinkApacheContentEncodingTest.java?rev=819192&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentencoding/WinkApacheContentEncodingTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentencoding/WinkApacheContentEncodingTest.java Sat Sep 26 19:21:10 2009
@@ -0,0 +1,66 @@
+/*
+ * 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.itest.contentencoding;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.zip.GZIPOutputStream;
+
+import javax.ws.rs.core.MediaType;
+
+import org.apache.commons.httpclient.HttpException;
+import org.apache.wink.client.ApacheHttpClientConfig;
+import org.apache.wink.client.ClientResponse;
+import org.apache.wink.client.RestClient;
+
+public class WinkApacheContentEncodingTest extends WinkContentEncodingTest {
+
+    @Override
+    public void setUp() {
+        client = new RestClient(new ApacheHttpClientConfig());
+    }
+
+    /**
+     * Tests sending in small bits of gzip encoded content.
+     * 
+     * @throws HttpException
+     * @throws IOException
+     */
+    @Override
+    public void testSendSmallGzipContentEncoded() throws HttpException, IOException {
+        ByteArrayOutputStream originalContent = new ByteArrayOutputStream();
+        originalContent.write("Hello world".getBytes("UTF-8"));
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        GZIPOutputStream gzipOut = new GZIPOutputStream(baos);
+
+        originalContent.writeTo(gzipOut);
+
+        gzipOut.finish();
+        byte[] content = baos.toByteArray();
+
+        ClientResponse response =
+            client.resource(BASE_URI + "/bigbook").accept(MediaType.TEXT_PLAIN)
+                .header("Content-Encoding", "gzip").contentType("text/plain; charset=utf-8")
+                .post(content);
+        assertEquals(200, response.getStatusCode());
+        String responseBody = response.getEntity(String.class);
+        assertEquals("Hello world" + "helloworld", responseBody);
+    }
+}

Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentencoding/WinkApacheContentEncodingTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentencoding/WinkContentEncodingTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentencoding/WinkContentEncodingTest.java?rev=819192&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentencoding/WinkContentEncodingTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentencoding/WinkContentEncodingTest.java Sat Sep 26 19:21:10 2009
@@ -0,0 +1,146 @@
+/*
+ * 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.itest.contentencoding;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
+
+import javax.ws.rs.core.MediaType;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.ChunkedOutputStream;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.wink.client.ClientResponse;
+import org.apache.wink.client.RestClient;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+public class WinkContentEncodingTest extends TestCase {
+
+    protected RestClient          client;
+
+    final protected static String BASE_URI =
+                                             ServerEnvironmentInfo.getBaseURI() + ((ServerEnvironmentInfo
+                                                 .isRestFilterUsed()) ? "" : "/contentencoding");
+
+    @Override
+    public void setUp() {
+        client = new RestClient();
+    }
+
+    /**
+     * Tests sending in small bits of gzip encoded content.
+     * 
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testSendSmallGzipContentEncoded() throws HttpException, IOException {
+        ByteArrayOutputStream originalContent = new ByteArrayOutputStream();
+        originalContent.write("Hello world".getBytes("UTF-8"));
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ChunkedOutputStream chunkedOut = new ChunkedOutputStream(baos);
+        GZIPOutputStream gzipOut = new GZIPOutputStream(chunkedOut);
+
+        originalContent.writeTo(gzipOut);
+
+        gzipOut.finish();
+        chunkedOut.finish();
+        byte[] content = baos.toByteArray();
+
+        ClientResponse response =
+            client.resource(BASE_URI + "/bigbook").accept(MediaType.TEXT_PLAIN)
+                .header("Transfer-Encoding", "chunked").header("Content-Encoding", "gzip")
+                .contentType("text/plain; charset=utf-8").post(content);
+        assertEquals(200, response.getStatusCode());
+        String responseBody = response.getEntity(String.class);
+        assertEquals("Hello world" + "helloworld", responseBody);
+    }
+
+    /**
+     * Tests sending in small bits of gzip encoded content.
+     * 
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testSendLargeGzipContentEncoded() throws HttpException, IOException {
+        ByteArrayOutputStream originalContent = new ByteArrayOutputStream();
+        for (int c = 0; c < 5000000; ++c) {
+            originalContent.write(c);
+        }
+
+        /*
+         * gzip the contents
+         */
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        GZIPOutputStream gzipOut = new GZIPOutputStream(baos);
+        originalContent.writeTo(gzipOut);
+        gzipOut.finish();
+        byte[] content = baos.toByteArray();
+
+        ClientResponse response =
+            client.resource(BASE_URI + "/bigbook/mirror").accept(MediaType.TEXT_PLAIN)
+                .header("Content-Encoding", "gzip").contentType("text/plain; charset=utf-8")
+                .post(content);
+
+        assertEquals(200, response.getStatusCode());
+        InputStream responseStream = response.getEntity(InputStream.class);
+        for (int c = 0; c < 5000000; ++c) {
+            assertEquals(c % 256, responseStream.read());
+        }
+    }
+
+    /**
+     * Tests sending in small bits of gzip encoded content.
+     * 
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testSendLargeGzipContentEncodedAndReceiveContentEncoded() throws HttpException,
+        IOException {
+        ByteArrayOutputStream originalContent = new ByteArrayOutputStream();
+        for (int c = 0; c < 5000000; ++c) {
+            originalContent.write(c);
+        }
+
+        /*
+         * gzip the contents
+         */
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        GZIPOutputStream gzipOut = new GZIPOutputStream(baos);
+        originalContent.writeTo(gzipOut);
+        gzipOut.finish();
+        byte[] content = baos.toByteArray();
+
+        ClientResponse response =
+            client.resource(BASE_URI + "/bigbook/mirror").header("Accept-Encoding", "gzip")
+                .accept(MediaType.TEXT_PLAIN).header("Content-Encoding", "gzip")
+                .contentType("text/plain; charset=utf-8").post(content);
+
+        assertEquals(200, response.getStatusCode());
+        InputStream responseStream = new GZIPInputStream(response.getEntity(InputStream.class));
+        for (int c = 0; c < 5000000; ++c) {
+            assertEquals(c % 256, responseStream.read());
+        }
+    }
+
+}

Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentencoding/WinkContentEncodingTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentnegotiation/ContentNegotiationClientTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentnegotiation/ContentNegotiationClientTest.java?rev=819192&r1=819191&r2=819192&view=diff
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentnegotiation/ContentNegotiationClientTest.java (original)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentnegotiation/ContentNegotiationClientTest.java Sat Sep 26 19:21:10 2009
@@ -41,18 +41,19 @@
  */
 public class ContentNegotiationClientTest extends TestCase {
 
-    HttpClient                  httpclient = new HttpClient();
+    private HttpClient httpclient = new HttpClient();
 
-    final private static String BASE_URI   =
-                                               ServerEnvironmentInfo.getBaseURI() + ((ServerEnvironmentInfo
-                                                   .isRestFilterUsed()) ? ""
-                                                   : "/contentNegotiation")
-                                                   + "/customerservice";
+    protected static String getBaseURI() {
+        if (ServerEnvironmentInfo.isRestFilterUsed()) {
+            return ServerEnvironmentInfo.getBaseURI() + "/customerservice";
+        }
+        return ServerEnvironmentInfo.getBaseURI() + "/contentNegotiation" + "/customerservice";
+    }
 
     public void testGetReturningXML() throws JAXBException {
         // 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");
+        GetMethod get = new GetMethod(getBaseURI() + "/customers/123");
         get.addRequestHeader("Accept", "application/xml");
 
         try {
@@ -81,7 +82,7 @@
         // 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");
+        GetMethod get = new GetMethod(getBaseURI() + "/customers/123");
         get.addRequestHeader("Accept", "application/json");
         httpclient = new HttpClient();
 
@@ -114,7 +115,7 @@
         // 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");
+        GetMethod get = new GetMethod(getBaseURI() + "/customers/123");
         httpclient = new HttpClient();
 
         try {

Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentnegotiation/WinkApacheContentNegotiationClientTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentnegotiation/WinkApacheContentNegotiationClientTest.java?rev=819192&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentnegotiation/WinkApacheContentNegotiationClientTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentnegotiation/WinkApacheContentNegotiationClientTest.java Sat Sep 26 19:21:10 2009
@@ -0,0 +1,30 @@
+/*
+ * 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.itest.contentnegotiation;
+
+import org.apache.wink.client.ApacheHttpClientConfig;
+import org.apache.wink.client.RestClient;
+
+public class WinkApacheContentNegotiationClientTest extends WinkContentNegotiationClientTest {
+
+    @Override
+    public void setUp() {
+        client = new RestClient(new ApacheHttpClientConfig());
+    }
+}

Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentnegotiation/WinkApacheContentNegotiationClientTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentnegotiation/WinkContentNegotiationClientTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentnegotiation/WinkContentNegotiationClientTest.java?rev=819192&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentnegotiation/WinkContentNegotiationClientTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentnegotiation/WinkContentNegotiationClientTest.java Sat Sep 26 19:21:10 2009
@@ -0,0 +1,86 @@
+/*
+ * 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.itest.contentnegotiation;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+
+import junit.framework.TestCase;
+
+import org.apache.wink.client.ClientResponse;
+import org.apache.wink.client.RestClient;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.json.JSONTokener;
+
+public class WinkContentNegotiationClientTest extends TestCase {
+
+    protected RestClient client;
+
+    @Override
+    public void setUp() {
+        client = new RestClient();
+    }
+
+    protected static String getBaseURI() {
+        if (ServerEnvironmentInfo.isRestFilterUsed()) {
+            return ServerEnvironmentInfo.getBaseURI() + "/customerservice";
+        }
+        return ServerEnvironmentInfo.getBaseURI() + "/contentNegotiation" + "/customerservice";
+    }
+
+    public void testGetReturningXML() throws JAXBException {
+        ClientResponse response =
+            client.resource(getBaseURI() + "/customers/123").accept("application/xml").get();
+        assertEquals(200, response.getStatusCode());
+        Unmarshaller unmarshaller =
+            JAXBContext.newInstance(ObjectFactory.class.getPackage().getName())
+                .createUnmarshaller();
+        Customer c = (Customer)unmarshaller.unmarshal(response.getEntity(InputStream.class));
+        assertEquals(123, c.getId());
+        assertEquals("John", c.getName());
+    }
+
+    public void testGetReturningJSON() throws IOException, JSONException {
+        // Sent HTTP GET request to query customer info, expect JSON.
+        ClientResponse response =
+            client.resource(getBaseURI() + "/customers/123").accept("application/json").get();
+        String responseBody = response.getEntity(String.class);
+        assertEquals(200, response.getStatusCode());
+        JSONTokener tokenizer = new JSONTokener(responseBody);
+        JSONObject jObj = new JSONObject(tokenizer);
+        assertEquals("John", jObj.get("name"));
+        assertEquals(123L, jObj.getLong("id"));
+    }
+
+    public void testGetForCustomerInfoReturningJSON() throws JSONException {
+        ClientResponse response = client.resource(getBaseURI() + "/customers/123").get();
+        String responseBody = response.getEntity(String.class);
+        assertEquals(200, response.getStatusCode());
+        JSONTokener tokenizer = new JSONTokener(responseBody);
+        JSONObject jObj = new JSONObject(tokenizer);
+        assertEquals("John", jObj.get("name"));
+        assertEquals(123L, jObj.getLong("id"));
+    }
+}

Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/contentnegotiation/WinkContentNegotiationClientTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/exceptions/ExceptionsWhileTargettingTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/exceptions/ExceptionsWhileTargettingTest.java?rev=819192&r1=819191&r2=819192&view=diff
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/exceptions/ExceptionsWhileTargettingTest.java (original)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/exceptions/ExceptionsWhileTargettingTest.java Sat Sep 26 19:21:10 2009
@@ -39,6 +39,13 @@
         return ServerEnvironmentInfo.getBaseURI() + "/exceptional";
     }
 
+    protected HttpClient client;
+
+    @Override
+    public void setUp() {
+        client = new HttpClient();
+    }
+
     /**
      * Tests that a 404 error is thrown when no resource can be found for a
      * path.
@@ -46,8 +53,6 @@
      * @throws Exception
      */
     public void test404WhenNoResourceExists() throws Exception {
-        HttpClient client = new HttpClient();
-
         GetMethod getMethod = new GetMethod(getBaseURI() + "/doesnotexist");
         try {
             client.executeMethod(getMethod);
@@ -66,8 +71,6 @@
      * @throws Exception
      */
     public void test405WhenNoMethodExistsOnExistingResource() throws Exception {
-        HttpClient client = new HttpClient();
-
         GetMethod getMethod = new GetMethod(getBaseURI() + "/existingresource/");
         try {
             client.executeMethod(getMethod);
@@ -87,8 +90,6 @@
      * @throws Exception
      */
     public void test404WhenNoSubResourceExists() throws Exception {
-        HttpClient client = new HttpClient();
-
         GetMethod getMethod = new GetMethod(getBaseURI() + "/existingresource/noexistsub");
         try {
             client.executeMethod(getMethod);
@@ -119,8 +120,6 @@
      * @throws Exception
      */
     public void test405WhenResourceMethodDoesNotExistButOthersDo() throws Exception {
-        HttpClient client = new HttpClient();
-
         GetMethod getMethod = new GetMethod(getBaseURI() + "/existingresource/noexistsub");
         try {
             client.executeMethod(getMethod);
@@ -150,8 +149,6 @@
      * @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",
@@ -184,8 +181,6 @@
      * @throws Exception
      */
     public void test406WhenResourceMethodDoesNotProduceResponseEntityType() throws Exception {
-        HttpClient client = new HttpClient();
-
         PutMethod putMethod = new PutMethod(getBaseURI() + "/targeting/resourcewithmethod");
 
         try {

Modified: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/exceptions/NullValuesDuringTargettingTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/exceptions/NullValuesDuringTargettingTest.java?rev=819192&r1=819191&r2=819192&view=diff
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/exceptions/NullValuesDuringTargettingTest.java (original)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/exceptions/NullValuesDuringTargettingTest.java Sat Sep 26 19:21:10 2009
@@ -41,6 +41,13 @@
         return ServerEnvironmentInfo.getBaseURI() + "/exceptional";
     }
 
+    protected HttpClient client;
+
+    @Override
+    public void setUp() {
+        client = new HttpClient();
+    }
+
     /**
      * 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.
@@ -49,8 +56,6 @@
      */
     public void testNoContentTypeWithNoRequestEntityIncomingRequestWithConsumesMethod()
         throws IOException {
-        HttpClient client = new HttpClient();
-
         PostMethod postMethod =
             new PostMethod(getBaseURI() + "/targeting/nullresource/withconsumes");
         try {
@@ -74,8 +79,6 @@
      */
     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}));
@@ -101,8 +104,6 @@
      */
     public void testNoContentTypeWithRequestEntityIncomingRequestWithNoConsumesMethod()
         throws IOException {
-        HttpClient client = new HttpClient();
-
         PostMethod postMethod =
             new PostMethod(getBaseURI() + "/targeting/nullresource/withoutconsumes");
         postMethod.setRequestEntity(new ByteArrayRequestEntity("calledWithString".getBytes()));
@@ -128,8 +129,6 @@
      */
     public void testContentTypeWithRequestEntityIncomingRequestWithNoConsumesMethod()
         throws IOException {
-        HttpClient client = new HttpClient();
-
         PostMethod postMethod =
             new PostMethod(getBaseURI() + "/targeting/nullresource/withoutconsumes");
         postMethod
@@ -156,8 +155,6 @@
      */
     public void testContentTypeWithNoRequestEntityIncomingRequestWithNoConsumesMethod()
         throws IOException {
-        HttpClient client = new HttpClient();
-
         PostMethod postMethod =
             new PostMethod(getBaseURI() + "/targeting/nullresource/withoutconsumes");
         postMethod.setRequestHeader("Content-Type", "text/plain");
@@ -183,8 +180,6 @@
      */
     public void testNoContentTypeWithNoRequestEntityIncomingRequestWithNoConsumesMethod()
         throws IOException {
-        HttpClient client = new HttpClient();
-
         PostMethod postMethod =
             new PostMethod(getBaseURI() + "/targeting/nullresource/withoutconsumes");
         try {
@@ -209,8 +204,6 @@
      */
     public void testContentTypeWithNoRequestEntityIncomingRequestWithConsumesMethod()
         throws IOException {
-        HttpClient client = new HttpClient();
-
         PostMethod postMethod =
             new PostMethod(getBaseURI() + "/targeting/nullresource/withconsumes");
         postMethod.setRequestHeader("Content-Type", "text/plain");
@@ -236,8 +229,6 @@
      */
     public void testContentTypeWithRequestEntityIncomingRequestWithConsumesMethod()
         throws IOException {
-        HttpClient client = new HttpClient();
-
         PostMethod postMethod =
             new PostMethod(getBaseURI() + "/targeting/nullresource/withconsumes");
         postMethod
@@ -262,8 +253,6 @@
      * @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");
@@ -285,8 +274,6 @@
      * @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");
@@ -308,8 +295,6 @@
      * @throws IOException
      */
     public void testNoAcceptHeaderIncomingRequestWithProducesMethod() throws IOException {
-        HttpClient client = new HttpClient();
-
         PostMethod postMethod =
             new PostMethod(getBaseURI() + "/targeting/nullresource/withproduces");
         try {
@@ -329,8 +314,6 @@
      * @throws IOException
      */
     public void testNoAcceptHeaderIncomingRequestWithNoProducesMethod() throws IOException {
-        HttpClient client = new HttpClient();
-
         PostMethod postMethod =
             new PostMethod(getBaseURI() + "/targeting/nullresource/withoutproduces");
         try {



Mime
View raw message