You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wink.apache.org by bl...@apache.org on 2009/07/09 00:10:23 UTC
svn commit: r792337 [2/2] - in
/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src:
main/java/org/apache/wink/jaxrs/test/providers/standard/
main/webapp/WEB-INF/ test/java/org/apache/wink/jaxrs/test/pr...
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/standard/JAXRSSourceTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/standard/JAXRSSourceTest.java?rev=792337&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/standard/JAXRSSourceTest.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/standard/JAXRSSourceTest.java Wed Jul 8 22:10:22 2009
@@ -0,0 +1,244 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.wink.jaxrs.test.providers.standard;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Random;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+public class JAXRSSourceTest extends TestCase {
+
+ public String getBaseURI() {
+ return ServerEnvironmentInfo.getBaseURI() + "/standard";
+ }
+
+ /**
+ * Tests posting to a Source entity parameter with text/xml
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testPostSourceWithTextXMLMediaType() throws HttpException,
+ IOException {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI()
+ + "/providers/standard/source");
+ postMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<message><user>user1</user><password>user1pwd</password></message>",
+ "text/xml", "UTF-8"));
+ postMethod.addRequestHeader("Accept", "text/xml");
+ try {
+ client.executeMethod(postMethod);
+
+ assertEquals(200, postMethod.getStatusCode());
+ String str = postMethod.getResponseBodyAsString();
+ assertEquals(
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><message><user>user1</user><password>user1pwd</password></message>",
+ str);
+ assertEquals("text/xml", postMethod.getResponseHeader(
+ "Content-Type").getValue());
+ Header contentLengthHeader = postMethod
+ .getResponseHeader("Content-Length");
+ assertNull(contentLengthHeader == null ? "null"
+ : contentLengthHeader.getValue(), contentLengthHeader);
+ } finally {
+ postMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests posting to a Source entity parameter with application/xml as the
+ * media type.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testPostSourceWithApplicationXMLMediaType()
+ throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI()
+ + "/providers/standard/source");
+ postMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<message><user>user1</user><password>user1pwd</password></message>",
+ "application/xml", "UTF-8"));
+ postMethod.addRequestHeader("Accept", "application/xml");
+ try {
+ client.executeMethod(postMethod);
+
+ assertEquals(200, postMethod.getStatusCode());
+ String str = postMethod.getResponseBodyAsString();
+ assertEquals(
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><message><user>user1</user><password>user1pwd</password></message>",
+ str);
+ assertEquals("application/xml", postMethod.getResponseHeader(
+ "Content-Type").getValue());
+ Header contentLengthHeader = postMethod
+ .getResponseHeader("Content-Length");
+ assertNull(contentLengthHeader == null ? "null"
+ : contentLengthHeader.getValue(), contentLengthHeader);
+ } finally {
+ postMethod.releaseConnection();
+ }
+ }
+
+ // public void testPostSourceWithApplicationWildcardXMLSubtypeMediaType() {
+ // fail();
+ // }
+
+ /**
+ * Tests posting to a Source entity parameter and returning Source entity
+ * response with an unacceptable response media type.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testPostSourceWithNonExpectedAcceptType() throws HttpException,
+ IOException {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI()
+ + "/providers/standard/source");
+ postMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<message><user>user1</user><password>user1pwd</password></message>",
+ "application/xml", "UTF-8"));
+ postMethod.addRequestHeader("Accept", "text/plain");
+ try {
+ client.executeMethod(postMethod);
+
+ assertEquals(500, postMethod.getStatusCode());
+ } finally {
+ postMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests posting to a Source entity parameter and returning Source entity
+ * response with an unacceptable request content-type.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testPostSourceWithNonExpectedRequestContentType()
+ throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI()
+ + "/providers/standard/source");
+ postMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<message><user>user1</user><password>user1pwd</password></message>",
+ "text/plain", "UTF-8"));
+ postMethod.addRequestHeader("Accept", "application/xml");
+ try {
+ client.executeMethod(postMethod);
+
+ assertEquals(415, postMethod.getStatusCode());
+ } finally {
+ postMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests putting and then getting a source.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testPutSource() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+
+ PutMethod putMethod = new PutMethod(getBaseURI()
+ + "/providers/standard/source");
+ putMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<message><user>user1</user><password>user1pwd</password></message>",
+ "application/xml", "UTF-8"));
+ try {
+ client.executeMethod(putMethod);
+ assertEquals(204, putMethod.getStatusCode());
+ } finally {
+ putMethod.releaseConnection();
+ }
+
+ GetMethod getMethod = new GetMethod(getBaseURI()
+ + "/providers/standard/source");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+
+ String str = getMethod.getResponseBodyAsString();
+ assertEquals(
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><message><user>user1</user><password>user1pwd</password></message>",
+ str);
+ assertEquals("application/xml", getMethod
+ .getResponseHeader("Content-Type").getValue());
+ Header contentLengthHeader = getMethod
+ .getResponseHeader("Content-Length");
+ assertNull(contentLengthHeader == null ? "null"
+ : contentLengthHeader.getValue(), contentLengthHeader);
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests a resource method invoked with a SAXSource as a parameter. This
+ * should fail with a 415 since the reader has no way to necessarily wrap it
+ * to the type.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testSourceSubclassImplementation() throws HttpException,
+ IOException {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI()
+ + "/providers/standard/source/subclasses/shouldfail");
+ byte[] barr = new byte[1000];
+ Random r = new Random();
+ r.nextBytes(barr);
+ postMethod.setRequestEntity(new InputStreamRequestEntity(
+ new ByteArrayInputStream(barr), "application/xml"));
+ try {
+ client.executeMethod(postMethod);
+ assertEquals(415, postMethod.getStatusCode());
+ } finally {
+ postMethod.releaseConnection();
+ }
+ }
+}
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/standard/JAXRSStreamingOutputTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/standard/JAXRSStreamingOutputTest.java?rev=792337&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/standard/JAXRSStreamingOutputTest.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/standard/JAXRSStreamingOutputTest.java Wed Jul 8 22:10:22 2009
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.wink.jaxrs.test.providers.standard;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Random;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+public class JAXRSStreamingOutputTest extends TestCase {
+
+ public String getBaseURI() {
+ return ServerEnvironmentInfo.getBaseURI() + "/standard";
+ }
+
+ /**
+ * Tests posting to a StreamingOutput and then returning StreamingOutput.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testPostStreamingOutput() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI()
+ + "/providers/standard/streamingoutput");
+ byte[] barr = new byte[100000];
+ Random r = new Random();
+ r.nextBytes(barr);
+ postMethod.setRequestEntity(new InputStreamRequestEntity(
+ new ByteArrayInputStream(barr), "text/plain"));
+ postMethod.addRequestHeader("Accept", "text/plain");
+ try {
+ client.executeMethod(postMethod);
+
+ assertEquals(200, postMethod.getStatusCode());
+ InputStream is = postMethod.getResponseBodyAsStream();
+
+ byte[] receivedBArr = new byte[barr.length];
+ DataInputStream dis = new DataInputStream(is);
+ dis.readFully(receivedBArr);
+
+ int checkEOF = dis.read();
+ assertEquals(-1, checkEOF);
+ for (int c = 0; c < barr.length; ++c) {
+ assertEquals(barr[c], receivedBArr[c]);
+ }
+ assertEquals("text/plain", postMethod.getResponseHeader(
+ "Content-Type").getValue());
+ Header contentLengthHeader = postMethod
+ .getResponseHeader("Content-Length");
+ assertNull(contentLengthHeader == null ? "null"
+ : contentLengthHeader.getValue(), contentLengthHeader);
+ } finally {
+ postMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests putting and then getting a StreamingOutput.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testPutStreamngOutput() throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+
+ PutMethod putMethod = new PutMethod(getBaseURI()
+ + "/providers/standard/streamingoutput");
+ byte[] barr = new byte[100000];
+ Random r = new Random();
+ r.nextBytes(barr);
+ putMethod.setRequestEntity(new InputStreamRequestEntity(
+ new ByteArrayInputStream(barr), "bytes/array"));
+ try {
+ client.executeMethod(putMethod);
+ assertEquals(204, putMethod.getStatusCode());
+ } finally {
+ putMethod.releaseConnection();
+ }
+
+ GetMethod getMethod = new GetMethod(getBaseURI()
+ + "/providers/standard/streamingoutput");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ InputStream is = getMethod.getResponseBodyAsStream();
+
+ byte[] receivedBArr = new byte[barr.length];
+ DataInputStream dis = new DataInputStream(is);
+ dis.readFully(receivedBArr);
+
+ int checkEOF = dis.read();
+ assertEquals(-1, checkEOF);
+ for (int c = 0; c < barr.length; ++c) {
+ assertEquals(barr[c], receivedBArr[c]);
+ }
+ assertEquals("application/xml", getMethod
+ .getResponseHeader("Content-Type").getValue());
+
+ Header contentLengthHeader = getMethod
+ .getResponseHeader("Content-Length");
+ assertNull(contentLengthHeader == null ? "null"
+ : contentLengthHeader.getValue(), contentLengthHeader);
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests receiving a StreamingOutput with a non-standard content-type.
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public void testWithRequestAcceptHeaderWillReturnRequestedContentType()
+ throws HttpException, IOException {
+ HttpClient client = new HttpClient();
+
+ PutMethod putMethod = new PutMethod(getBaseURI()
+ + "/providers/standard/streamingoutput");
+ byte[] barr = new byte[100000];
+ Random r = new Random();
+ r.nextBytes(barr);
+ putMethod.setRequestEntity(new InputStreamRequestEntity(
+ new ByteArrayInputStream(barr), "any/type"));
+ try {
+ client.executeMethod(putMethod);
+ assertEquals(204, putMethod.getStatusCode());
+ } finally {
+ putMethod.releaseConnection();
+ }
+
+ GetMethod getMethod = new GetMethod(getBaseURI()
+ + "/providers/standard/streamingoutput");
+ getMethod.addRequestHeader("Accept", "mytype/subtype");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ InputStream is = getMethod.getResponseBodyAsStream();
+
+ byte[] receivedBArr = new byte[barr.length];
+ DataInputStream dis = new DataInputStream(is);
+ dis.readFully(receivedBArr);
+
+ int checkEOF = dis.read();
+ assertEquals(-1, checkEOF);
+ for (int c = 0; c < barr.length; ++c) {
+ assertEquals(barr[c], receivedBArr[c]);
+ }
+ assertEquals("mytype/subtype", getMethod.getResponseHeader(
+ "Content-Type").getValue());
+ Header contentLengthHeader = getMethod
+ .getResponseHeader("Content-Length");
+ assertNull(contentLengthHeader == null ? "null"
+ : contentLengthHeader.getValue(), contentLengthHeader);
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+}