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/09/26 21:21:12 UTC
svn commit: r819192 [3/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...
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/nofindmethods/WinkApacheDoNotUseMethodNamesForHTTPVerbsTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/nofindmethods/WinkApacheDoNotUseMethodNamesForHTTPVerbsTest.java?rev=819192&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/nofindmethods/WinkApacheDoNotUseMethodNamesForHTTPVerbsTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/nofindmethods/WinkApacheDoNotUseMethodNamesForHTTPVerbsTest.java Sat Sep 26 19:21:10 2009
@@ -0,0 +1,31 @@
+/*
+ * 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.nofindmethods;
+
+import org.apache.wink.client.ApacheHttpClientConfig;
+import org.apache.wink.client.RestClient;
+
+public class WinkApacheDoNotUseMethodNamesForHTTPVerbsTest extends
+ WinkDoNotUseMethodNamesForHTTPVerbsTest {
+
+ @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/nofindmethods/WinkApacheDoNotUseMethodNamesForHTTPVerbsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/nofindmethods/WinkDoNotUseMethodNamesForHTTPVerbsTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/nofindmethods/WinkDoNotUseMethodNamesForHTTPVerbsTest.java?rev=819192&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/nofindmethods/WinkDoNotUseMethodNamesForHTTPVerbsTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/nofindmethods/WinkDoNotUseMethodNamesForHTTPVerbsTest.java Sat Sep 26 19:21:10 2009
@@ -0,0 +1,110 @@
+/*
+ * 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.nofindmethods;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+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 WinkDoNotUseMethodNamesForHTTPVerbsTest extends TestCase {
+
+ public static String getBaseURI() {
+ if (ServerEnvironmentInfo.isRestFilterUsed()) {
+ return ServerEnvironmentInfo.getBaseURI();
+ }
+ return ServerEnvironmentInfo.getBaseURI() + "/nofindmethods";
+ }
+
+ protected RestClient client;
+
+ @Override
+ public void setUp() {
+ client = new RestClient();
+ }
+
+ /**
+ * Negative tests that method names that begin with HTTP verbs are not
+ * invoked on a root resource.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testMethodsNotValid() throws HttpException, IOException {
+ ClientResponse response =
+ client.resource(getBaseURI() + "/nousemethodnamesforhttpverbs/someresource").post(null);
+ assertEquals(405, response.getStatusCode());
+
+ response =
+ client.resource(getBaseURI() + "/nousemethodnamesforhttpverbs/someresource").get();
+ assertEquals(405, response.getStatusCode());
+
+ response =
+ client.resource(getBaseURI() + "/nousemethodnamesforhttpverbs/someresource").put(null);
+ assertEquals(405, response.getStatusCode());
+
+ response =
+ client.resource(getBaseURI() + "/nousemethodnamesforhttpverbs/someresource").delete();
+ assertEquals(405, response.getStatusCode());
+
+ response =
+ client.resource(getBaseURI() + "/nousemethodnamesforhttpverbs/counter/root").get();
+ assertEquals(200, response.getStatusCode());
+ assertEquals("0", response.getEntity(String.class));
+ }
+
+ /**
+ * Negative tests that method names that begin with HTTP verbs are not
+ * invoked on a sublocator method.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testSublocatorMethodsNotValid() throws HttpException, IOException {
+ ClientResponse response =
+ client.resource(getBaseURI() + "/nousemethodnamesforhttpverbs/sublocatorresource/sub")
+ .post(null);
+ assertEquals(405, response.getStatusCode());
+
+ response =
+ client.resource(getBaseURI() + "/nousemethodnamesforhttpverbs/sublocatorresource/sub")
+ .get();
+ assertEquals(405, response.getStatusCode());
+
+ response =
+ client.resource(getBaseURI() + "/nousemethodnamesforhttpverbs/sublocatorresource/sub")
+ .put(null);
+ assertEquals(405, response.getStatusCode());
+
+ response =
+ client.resource(getBaseURI() + "/nousemethodnamesforhttpverbs/sublocatorresource/sub")
+ .delete();
+ assertEquals(405, response.getStatusCode());
+
+ response =
+ client.resource(getBaseURI() + "/nousemethodnamesforhttpverbs/counter/sublocator")
+ .get();
+ assertEquals(200, response.getStatusCode());
+ assertEquals("0", response.getEntity(String.class));
+ }
+}
Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/nofindmethods/WinkDoNotUseMethodNamesForHTTPVerbsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/returntypes/ReturnTypeStatusTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/returntypes/ReturnTypeStatusTest.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/returntypes/ReturnTypeStatusTest.java (original)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/returntypes/ReturnTypeStatusTest.java Sat Sep 26 19:21:10 2009
@@ -40,13 +40,11 @@
public static String getBaseURI() {
if (ServerEnvironmentInfo.isRestFilterUsed()) {
- return ServerEnvironmentInfo.getBaseURI();
+ return ServerEnvironmentInfo.getBaseURI()+ "/returntypestatus";
}
- return ServerEnvironmentInfo.getBaseURI() + "/returntypes";
+ return ServerEnvironmentInfo.getBaseURI() + "/returntypes"+ "/returntypestatus";
}
- final private static String BASE_URI = getBaseURI() + "/returntypestatus";
-
/**
* Tests that a void return type results in a response that has:
* <ul>
@@ -57,7 +55,7 @@
public void testVoidReturnType() {
try {
GetMethod httpMethod = new GetMethod();
- httpMethod.setURI(new URI(BASE_URI + "/void", false));
+ httpMethod.setURI(new URI(getBaseURI() + "/void", false));
httpclient = new HttpClient();
try {
@@ -95,7 +93,7 @@
public void testNullObjectReturnType() {
try {
GetMethod httpMethod = new GetMethod();
- httpMethod.setURI(new URI(BASE_URI + "/null", false));
+ httpMethod.setURI(new URI(getBaseURI() + "/null", false));
httpclient = new HttpClient();
try {
@@ -133,7 +131,7 @@
public void testNullResponseReturnType() {
try {
GetMethod httpMethod = new GetMethod();
- httpMethod.setURI(new URI(BASE_URI + "/nullresponse", false));
+ httpMethod.setURI(new URI(getBaseURI() + "/nullresponse", false));
httpclient = new HttpClient();
try {
@@ -169,7 +167,7 @@
try {
GetMethod httpMethod = new GetMethod();
httpMethod
- .setURI(new URI(BASE_URI + "/responsestatus?code=" + status.name(), false));
+ .setURI(new URI(getBaseURI() + "/responsestatus?code=" + status.name(), false));
httpclient = new HttpClient();
try {
@@ -207,7 +205,7 @@
public void testStatusCodeNotSetResponseReturnType() {
try {
GetMethod httpMethod = new GetMethod();
- httpMethod.setURI(new URI(BASE_URI + "/CustomResponseStatusNotSet", false));
+ httpMethod.setURI(new URI(getBaseURI() + "/CustomResponseStatusNotSet", false));
httpclient = new HttpClient();
try {
@@ -238,7 +236,7 @@
public void testStatusCodeNotSetNullEntityResponseReturnType() {
try {
GetMethod httpMethod = new GetMethod();
- httpMethod.setURI(new URI(BASE_URI + "/CustomNullResponseStatusNotSet", false));
+ httpMethod.setURI(new URI(getBaseURI() + "/CustomNullResponseStatusNotSet", false));
httpclient = new HttpClient();
try {
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/returntypes/WinkApacheClientReturnTypeStatusTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/returntypes/WinkApacheClientReturnTypeStatusTest.java?rev=819192&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/returntypes/WinkApacheClientReturnTypeStatusTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/returntypes/WinkApacheClientReturnTypeStatusTest.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.returntypes;
+
+import org.apache.wink.client.ApacheHttpClientConfig;
+import org.apache.wink.client.RestClient;
+
+public class WinkApacheClientReturnTypeStatusTest extends WinkClientReturnTypeStatusTest {
+
+ @Override
+ public void setUp() {
+ client = new RestClient(new ApacheHttpClientConfig().followRedirects(false));
+ }
+}
Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/returntypes/WinkApacheClientReturnTypeStatusTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/returntypes/WinkClientReturnTypeStatusTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/returntypes/WinkClientReturnTypeStatusTest.java?rev=819192&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/returntypes/WinkClientReturnTypeStatusTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/returntypes/WinkClientReturnTypeStatusTest.java Sat Sep 26 19:21:10 2009
@@ -0,0 +1,130 @@
+/*
+ * 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.returntypes;
+
+import javax.ws.rs.core.Response.Status;
+
+import junit.framework.TestCase;
+
+import org.apache.wink.client.ClientResponse;
+import org.apache.wink.client.RestClient;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+public class WinkClientReturnTypeStatusTest extends TestCase {
+
+ protected RestClient client;
+
+ protected static String getBaseURI() {
+ if (ServerEnvironmentInfo.isRestFilterUsed()) {
+ return ServerEnvironmentInfo.getBaseURI() + "/returntypestatus";
+ }
+ return ServerEnvironmentInfo.getBaseURI() + "/returntypes" + "/returntypestatus";
+ }
+
+ @Override
+ public void setUp() {
+ client = new RestClient();
+ }
+
+ /**
+ * Tests that a void return type results in a response that has:
+ * <ul>
+ * <li>HTTP status code of 204
+ * <li>empty response body
+ * </ul>
+ */
+ public void testVoidReturnType() {
+ ClientResponse response = client.resource(getBaseURI() + "/void").get();
+ assertEquals(204, response.getStatusCode());
+ assertEquals("", response.getEntity(String.class));
+ }
+
+ /**
+ * Tests that a null return type on a method that returns an arbitrary
+ * object results in a response that has:
+ * <ul>
+ * <li>HTTP status code of 204
+ * <li>empty response body
+ * </ul>
+ */
+ public void testNullObjectReturnType() {
+ ClientResponse response = client.resource(getBaseURI() + "/null").get();
+ assertEquals(204, response.getStatusCode());
+ assertEquals("", response.getEntity(String.class));
+ }
+
+ /**
+ * Tests that a null return on a method that is suppose to return a Response
+ * object type results in a response that has:
+ * <ul>
+ * <li>HTTP status code of 204
+ * <li>empty response body
+ * </ul>
+ */
+ public void testNullResponseReturnType() {
+ ClientResponse response = client.resource(getBaseURI() + "/nullresponse").get();
+ assertEquals(204, response.getStatusCode());
+ assertEquals("", response.getEntity(String.class));
+ }
+
+ /**
+ * Tests that the status code can be set and returned correctly via a method
+ * that returns a <code>Response</code> return type.
+ */
+ public void testStatusCodeSetResponseReturnType() {
+ for (Status status : Status.values()) {
+
+ ClientResponse response =
+ client.resource(getBaseURI() + "/responsestatus?code=" + status.name()).get();
+ int result = response.getStatusCode();
+ String responseBody = response.getEntity(String.class);
+ assertEquals(status.getStatusCode(), result);
+ if (status.equals(Status.NO_CONTENT) || status.equals(Status.NOT_MODIFIED)) {
+ assertEquals("", responseBody);
+ } else {
+ assertEquals("Requested status: " + status.getStatusCode() + " " + status.name(),
+ responseBody);
+ }
+ }
+ }
+
+ /**
+ * Resource method returns a custom application response which does not have
+ * the status code set but does have an entity. Expect the status code to be
+ * 200 and the entity to be returned.
+ */
+ public void testStatusCodeNotSetResponseReturnType() {
+ ClientResponse response =
+ client.resource(getBaseURI() + "/CustomResponseStatusNotSet").get();
+ assertEquals(200, response.getStatusCode());
+ assertEquals("CustomApplicationResponse", response.getEntity(String.class));
+ }
+
+ /**
+ * Resource method returns a custom application response which does not have
+ * the status code set and does not have an entity. Expect the status code
+ * to be 204 and no content.
+ */
+ public void testStatusCodeNotSetNullEntityResponseReturnType() {
+ ClientResponse response =
+ client.resource(getBaseURI() + "/CustomNullResponseStatusNotSet").get();
+ assertEquals(204, response.getStatusCode());
+ assertEquals("", response.getEntity(String.class));
+ }
+}
Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/returntypes/WinkClientReturnTypeStatusTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/sequence/SequenceTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/sequence/SequenceTest.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/sequence/SequenceTest.java (original)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/sequence/SequenceTest.java Sat Sep 26 19:21:10 2009
@@ -36,7 +36,7 @@
*/
public class SequenceTest extends TestCase {
- private HttpClient client = new HttpClient();
+ private HttpClient client;
public static String getBaseURI() {
if (ServerEnvironmentInfo.isRestFilterUsed()) {
@@ -45,6 +45,11 @@
return ServerEnvironmentInfo.getBaseURI() + "/sequence";
}
+ @Override
+ public void setUp() throws Exception {
+ client = new HttpClient();
+ }
+
/**
* Calls a resource (which is not a singleton) several times. Verifies that
* the resource instance is created each time.
@@ -52,8 +57,6 @@
* @throws Exception
*/
public void testHit100TimesRegularResource() throws Exception {
- client = new HttpClient();
-
DeleteMethod deleteMethod = new DeleteMethod(getBaseURI() + "/sequence/static");
try {
client.executeMethod(deleteMethod);
@@ -130,8 +133,6 @@
* @throws Exception
*/
public void testHit100TimesSingletonResource() throws Exception {
- client = new HttpClient();
-
DeleteMethod deleteMethod = new DeleteMethod(getBaseURI() + "/singletonsequence/static");
try {
client.executeMethod(deleteMethod);
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/sequence/WinkApacheClientSequenceTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/sequence/WinkApacheClientSequenceTest.java?rev=819192&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/sequence/WinkApacheClientSequenceTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/sequence/WinkApacheClientSequenceTest.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.sequence;
+
+import org.apache.wink.client.ApacheHttpClientConfig;
+import org.apache.wink.client.RestClient;
+
+public class WinkApacheClientSequenceTest extends WinkClientSequenceTest {
+
+ @Override
+ public void setUp() throws Exception {
+ client = new RestClient(new ApacheHttpClientConfig());
+ }
+}
Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/sequence/WinkApacheClientSequenceTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/sequence/WinkClientSequenceTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/sequence/WinkClientSequenceTest.java?rev=819192&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/sequence/WinkClientSequenceTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/sequence/WinkClientSequenceTest.java Sat Sep 26 19:21:10 2009
@@ -0,0 +1,123 @@
+/*
+ * 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.sequence;
+
+import junit.framework.TestCase;
+
+import org.apache.wink.client.ClientResponse;
+import org.apache.wink.client.RestClient;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+/**
+ * Verifies that a sequence of basic calls to the same resource have the
+ * appropriate resource life-cycles.
+ */
+public class WinkClientSequenceTest extends TestCase {
+
+ protected RestClient client;
+
+ public static String getBaseURI() {
+ if (ServerEnvironmentInfo.isRestFilterUsed()) {
+ return ServerEnvironmentInfo.getBaseURI();
+ }
+ return ServerEnvironmentInfo.getBaseURI() + "/sequence";
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ client = new RestClient();
+ }
+
+ /**
+ * Calls a resource (which is not a singleton) several times. Verifies that
+ * the resource instance is created each time.
+ *
+ * @throws Exception
+ */
+ public void testHit100TimesRegularResource() throws Exception {
+ ClientResponse response = client.resource(getBaseURI() + "/sequence/static").delete();
+ assertEquals(204, response.getStatusCode());
+
+ response = client.resource(getBaseURI() + "/sequence/constructor").delete();
+ assertEquals(204, response.getStatusCode());
+
+ for (int c = 0; c < 10; ++c) {
+ response = client.resource(getBaseURI() + "/sequence").get();
+ assertEquals(200, response.getStatusCode());
+ assertEquals("0", response.getEntity(String.class));
+
+ response = client.resource(getBaseURI() + "/sequence/static").get();
+ assertEquals(200, response.getStatusCode());
+ assertEquals("" + c, response.getEntity(String.class));
+
+ response = client.resource(getBaseURI() + "/sequence").post(null);
+ assertEquals(200, response.getStatusCode());
+ assertEquals("1", response.getEntity(String.class));
+
+ response = client.resource(getBaseURI() + "/sequence/static").get();
+ assertEquals(200, response.getStatusCode());
+ assertEquals("" + (c + 1), response.getEntity(String.class));
+
+ response = client.resource(getBaseURI() + "/sequence/constructor").get();
+ assertEquals(200, response.getStatusCode());
+ assertEquals("" + ((c + 1) * 5), response.getEntity(String.class));
+ }
+ }
+
+ /**
+ * Calls a singleton resource several times. Verifies that the resource
+ * instance is re-used each time.
+ *
+ * @throws Exception
+ */
+ public void testHit100TimesSingletonResource() throws Exception {
+ ClientResponse response =
+ client.resource(getBaseURI() + "/singletonsequence/static").delete();
+ assertEquals(204, response.getStatusCode());
+
+ response = client.resource(getBaseURI() + "/singletonsequence/").delete();
+ assertEquals(204, response.getStatusCode());
+
+ for (int c = 0; c < 10; ++c) {
+ response = client.resource(getBaseURI() + "/singletonsequence/").get();
+ assertEquals(200, response.getStatusCode());
+ assertEquals("" + c, response.getEntity(String.class));
+
+ response = client.resource(getBaseURI() + "/singletonsequence/static").get();
+ assertEquals(200, response.getStatusCode());
+ assertEquals("" + c, response.getEntity(String.class));
+
+ response = client.resource(getBaseURI() + "/singletonsequence/").post(null);
+ assertEquals(200, response.getStatusCode());
+ assertEquals("" + (c + 1), response.getEntity(String.class));
+
+ response = client.resource(getBaseURI() + "/singletonsequence/static").get();
+ assertEquals(200, response.getStatusCode());
+ assertEquals("" + (c + 1), response.getEntity(String.class));
+
+ /*
+ * the constructor for this resource should never be more than 1.
+ * note the constructor hit count is never cleared.
+ */
+ response = client.resource(getBaseURI() + "/singletonsequence/constructor").get();
+ assertEquals(200, response.getStatusCode());
+ assertEquals("1", response.getEntity(String.class));
+ }
+ }
+}
Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/sequence/WinkClientSequenceTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/transferencoding/WinkApacheTransferEncodingTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/transferencoding/WinkApacheTransferEncodingTest.java?rev=819192&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/transferencoding/WinkApacheTransferEncodingTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/transferencoding/WinkApacheTransferEncodingTest.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.transferencoding;
+
+import org.apache.wink.client.ApacheHttpClientConfig;
+import org.apache.wink.client.RestClient;
+
+public class WinkApacheTransferEncodingTest extends WinkTransferEncodingTest {
+
+ @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/transferencoding/WinkApacheTransferEncodingTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/transferencoding/WinkTransferEncodingTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/transferencoding/WinkTransferEncodingTest.java?rev=819192&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/transferencoding/WinkTransferEncodingTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/transferencoding/WinkTransferEncodingTest.java Sat Sep 26 19:21:10 2009
@@ -0,0 +1,67 @@
+/*
+ * 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.transferencoding;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import javax.ws.rs.core.MediaType;
+
+import junit.framework.TestCase;
+
+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 WinkTransferEncodingTest extends TestCase {
+
+ protected RestClient client;
+
+ final private static String BASE_URI =
+ ServerEnvironmentInfo.getBaseURI() + ((ServerEnvironmentInfo
+ .isRestFilterUsed()) ? "" : "/transferencoding");
+
+ @Override
+ public void setUp() {
+ client = new RestClient();
+ }
+
+ /**
+ * Tests sending in small bits of chunked 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();
+ originalContent.writeTo(baos);
+ byte[] content = baos.toByteArray();
+
+ ClientResponse response =
+ client.resource(BASE_URI + "/chunkedbook").accept(MediaType.TEXT_PLAIN_TYPE)
+ .contentType("text/plain; charset=utf-8").post(content);
+ assertEquals(200, response.getStatusCode());
+ String responseBody = response.getEntity(String.class);
+ assertEquals("Hello world", responseBody);
+ }
+}
Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/transferencoding/WinkTransferEncodingTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/version/VersioningTest.java (from r819007, incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/version/VersioningTests.java)
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/version/VersioningTest.java?p2=incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/version/VersioningTest.java&p1=incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/version/VersioningTests.java&r1=819007&r2=819192&rev=819192&view=diff
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/version/VersioningTests.java (original)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/version/VersioningTest.java Sat Sep 26 19:21:10 2009
@@ -33,23 +33,21 @@
/**
* Demonstrates different versioning techniques
*/
-public class VersioningTests extends TestCase {
+public class VersioningTest extends TestCase {
protected HttpClient httpclient = new HttpClient();
public static String getBaseURI() {
if (ServerEnvironmentInfo.isRestFilterUsed()) {
- return ServerEnvironmentInfo.getBaseURI();
+ return ServerEnvironmentInfo.getBaseURI() + "/taxform";
}
- return ServerEnvironmentInfo.getBaseURI() + "/version";
+ return ServerEnvironmentInfo.getBaseURI() + "/version" + "/taxform";
}
- final private static String BASE_URI = getBaseURI() + "/taxform";
-
public void testVersionByAccept() {
try {
GetMethod httpMethod = new GetMethod();
- httpMethod.setURI(new URI(BASE_URI, false));
+ httpMethod.setURI(new URI(getBaseURI(), false));
httpMethod.setQueryString("form=1040");
System.out.println(Arrays.asList(httpMethod.getRequestHeaders()));
httpclient = new HttpClient();
@@ -89,7 +87,7 @@
public void testVersionByQueryString() {
try {
GetMethod httpMethod = new GetMethod();
- httpMethod.setURI(new URI(BASE_URI + "/1040", false));
+ httpMethod.setURI(new URI(getBaseURI() + "/1040", false));
httpMethod.setQueryString("version=2007");
System.out.println(Arrays.asList(httpMethod.getRequestHeaders()));
httpclient = new HttpClient();
@@ -104,7 +102,7 @@
.contains("<deductions>"));
assertEquals(200, result);
- httpMethod.setURI(new URI(BASE_URI + "/1040", false));
+ httpMethod.setURI(new URI(getBaseURI() + "/1040", false));
httpMethod.setQueryString("version=2008");
result = httpclient.executeMethod(httpMethod);
System.out.println("Response status code: " + result);
@@ -129,7 +127,7 @@
public void testVersionByPath() {
try {
GetMethod httpMethod = new GetMethod();
- httpMethod.setURI(new URI(BASE_URI + "/1040/2007", false));
+ httpMethod.setURI(new URI(getBaseURI() + "/1040/2007", false));
System.out.println(Arrays.asList(httpMethod.getRequestHeaders()));
httpclient = new HttpClient();
@@ -143,7 +141,7 @@
.contains("<deductions>"));
assertEquals(200, result);
- httpMethod.setURI(new URI(BASE_URI + "/1040/2008", false));
+ httpMethod.setURI(new URI(getBaseURI() + "/1040/2008", false));
result = httpclient.executeMethod(httpMethod);
System.out.println("Response status code: " + result);
System.out.println("Response body: ");
Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/version/VersioningTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/version/WinkApacheClientVersioningTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/version/WinkApacheClientVersioningTest.java?rev=819192&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/version/WinkApacheClientVersioningTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/version/WinkApacheClientVersioningTest.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.version;
+
+import org.apache.wink.client.ApacheHttpClientConfig;
+import org.apache.wink.client.RestClient;
+
+public class WinkApacheClientVersioningTest extends WinkClientVersioningTest {
+
+ @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/version/WinkApacheClientVersioningTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/version/WinkClientVersioningTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/version/WinkClientVersioningTest.java?rev=819192&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/version/WinkClientVersioningTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/version/WinkClientVersioningTest.java Sat Sep 26 19:21:10 2009
@@ -0,0 +1,91 @@
+/*
+ * 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.version;
+
+import junit.framework.TestCase;
+
+import org.apache.wink.client.ClientResponse;
+import org.apache.wink.client.RestClient;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+public class WinkClientVersioningTest extends TestCase {
+
+ protected RestClient client;
+
+ protected static String getBaseURI() {
+ if (ServerEnvironmentInfo.isRestFilterUsed()) {
+ return ServerEnvironmentInfo.getBaseURI() + "/taxform";
+ }
+ return ServerEnvironmentInfo.getBaseURI() + "/version" + "/taxform";
+ }
+
+ @Override
+ public void setUp() {
+ client = new RestClient();
+ }
+
+ public void testVersionByAccept() {
+ ClientResponse response =
+ client.resource(getBaseURI()).queryParam("form", "1040")
+ .header("Accept", "application/taxform+2007").get();
+
+ String responseBody = response.getEntity(String.class);
+ assertTrue("Response does not contain expected 'deductions' element", responseBody
+ .contains("<deductions>"));
+ assertEquals(200, response.getStatusCode());
+
+ response =
+ client.resource(getBaseURI()).queryParam("form", "1040")
+ .header("Accept", "application/taxform+2008").get();
+ responseBody = response.getEntity(String.class);
+ assertFalse("Response contains unexpected 'deductions' element", responseBody
+ .contains("<deductions>"));
+ assertEquals(200, response.getStatusCode());
+ }
+
+ public void testVersionByQueryString() {
+ ClientResponse response =
+ client.resource(getBaseURI() + "/1040").queryParam("version", "2007").get();
+ String responseBody = response.getEntity(String.class);
+ assertTrue("Response does not contain expected 'deductions' element", responseBody
+ .contains("<deductions>"));
+ assertEquals(200, response.getStatusCode());
+
+ response = client.resource(getBaseURI() + "/1040").queryParam("version", "2008").get();
+ responseBody = response.getEntity(String.class);
+ assertFalse("Response contains unexpected 'deductions' element", responseBody
+ .contains("<deductions>"));
+ assertEquals(200, response.getStatusCode());
+ }
+
+ public void testVersionByPath() {
+ ClientResponse response = client.resource(getBaseURI() + "/1040/2007").get();
+ String responseBody = response.getEntity(String.class);
+ assertTrue("Response does not contain expected 'deductions' element", responseBody
+ .contains("<deductions>"));
+ assertEquals(200, response.getStatusCode());
+
+ response = client.resource(getBaseURI() + "/1040/2008").get();
+ responseBody = response.getEntity(String.class);
+ assertFalse("Response contains unexpected 'deductions' element", responseBody
+ .contains("<deductions>"));
+ assertEquals(200, response.getStatusCode());
+ }
+
+}
Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-targeting/src/test/java/org/apache/wink/itest/version/WinkClientVersioningTest.java
------------------------------------------------------------------------------
svn:eol-style = native