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 [1/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...

Author: bluk
Date: Wed Jul  8 22:10:22 2009
New Revision: 792337

URL: http://svn.apache.org/viewvc?rev=792337&view=rev
Log:
add Provider standard tests

See [WINK-51]

Added:
    incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/
    incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/Application.java
    incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/ArrayUtils.java
    incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/BytesArrayResource.java
    incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/DataSourceResource.java
    incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/FileResource.java
    incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/InputStreamResource.java
    incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/MultiValuedMapResource.java
    incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/ReaderResource.java
    incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/SourceResource.java
    incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/StreamingOutputResource.java
    incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/standard/
    incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/standard/JAXRSBytesArrayTest.java
    incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/standard/JAXRSDataSourceTest.java
    incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/standard/JAXRSFileTest.java
    incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/standard/JAXRSInputStreamTest.java
    incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/standard/JAXRSMultivaluedMapTest.java
    incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/test/java/org/apache/wink/jaxrs/test/providers/standard/JAXRSReaderTest.java
    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
    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
Modified:
    incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/webapp/WEB-INF/web.xml

Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/Application.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/Application.java?rev=792337&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/Application.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/Application.java Wed Jul  8 22:10:22 2009
@@ -0,0 +1,47 @@
+/*
+ * 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.util.HashSet;
+import java.util.Set;
+
+public class Application extends javax.ws.rs.core.Application {
+
+    @Override
+    public Set<Class<?>> getClasses() {
+        Set<Class<?>> clazzes = new HashSet<Class<?>>();
+        clazzes.add(FileResource.class);
+        return clazzes;
+    }
+
+    @Override
+    public Set<Object> getSingletons() {
+        Set<Object> objs = new HashSet<Object>();
+        objs.add(new BytesArrayResource());
+        objs.add(new InputStreamResource());
+        objs.add(new ReaderResource());
+        objs.add(new StreamingOutputResource());
+        objs.add(new MultiValuedMapResource());
+        objs.add(new SourceResource());
+        objs.add(new DataSourceResource());
+        return objs;
+    }
+
+}

Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/ArrayUtils.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/ArrayUtils.java?rev=792337&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/ArrayUtils.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/ArrayUtils.java Wed Jul  8 22:10:22 2009
@@ -0,0 +1,52 @@
+/*
+ * 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;
+
+public class ArrayUtils {
+
+    /**
+     * copyOf performs the very same function that JDK6 java.util.Arrays.copyOf performs.  We need
+     * it here to support JDK5
+     * 
+     * @param buffer
+     * @param size
+     * @return
+     */
+    public static byte[] copyOf(byte[] buffer, int size) {
+        byte[] copy = new byte[size];
+        System.arraycopy(buffer, 0, copy, 0, Math.min(buffer.length, size));
+        return copy;
+    }
+    
+    /**
+     * copyOf performs the very same function that JDK6 java.util.Arrays.copyOf performs.  We need
+     * it here to support JDK5
+     * 
+     * @param buffer
+     * @param size
+     * @return
+     */
+    public static char[] copyOf(char[] buffer, int size) {
+        char[] copy = new char[size];
+        System.arraycopy(buffer, 0, copy, 0, Math.min(buffer.length, size));
+        return copy;
+    }
+    
+}

Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/BytesArrayResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/BytesArrayResource.java?rev=792337&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/BytesArrayResource.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/BytesArrayResource.java Wed Jul  8 22:10:22 2009
@@ -0,0 +1,48 @@
+/*
+ * 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 javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+
+@Path("providers/standard/bytesarray")
+public class BytesArrayResource {
+
+    private byte[] barr = null;
+
+    @GET
+    public Response getByteArray() {
+        return Response.ok(barr).build();
+    }
+
+    @POST
+    public byte[] postByteArray(byte[] bytearray) {
+        return bytearray;
+    }
+
+    @PUT
+    public void putByteArray(byte[] bytearray) {
+        barr = bytearray;
+    }
+
+}

Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/DataSourceResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/DataSourceResource.java?rev=792337&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/DataSourceResource.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/DataSourceResource.java Wed Jul  8 22:10:22 2009
@@ -0,0 +1,55 @@
+/*
+ * 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 javax.activation.DataSource;
+import javax.activation.FileDataSource;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+
+@Path("providers/standard/datasource")
+public class DataSourceResource {
+
+    private DataSource ds = null;
+
+    @GET
+    public Response getDataSource() {
+        return Response.ok(ds).build();
+    }
+
+    @POST
+    public DataSource postDataSource(DataSource ds) {
+        return ds;
+    }
+
+    @PUT
+    public void putDataSource(DataSource ds) {
+        this.ds = ds;
+    }
+
+    @POST
+    @Path("subclass/should/fail")
+    public DataSource postDataSource(FileDataSource ds) {
+        return ds;
+    }
+}

Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/FileResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/FileResource.java?rev=792337&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/FileResource.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/FileResource.java Wed Jul  8 22:10:22 2009
@@ -0,0 +1,50 @@
+/*
+ * 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.File;
+import java.io.IOException;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+
+@Path("providers/standard/file")
+public class FileResource {
+
+    private static File f;
+
+    @POST
+    public File postFile(File f) {
+        return f;
+    }
+
+    @GET
+    public Response getFile() {
+        return Response.ok(FileResource.f).build();
+    }
+
+    @PUT
+    public void putFile(File f) throws IOException {
+        FileResource.f = f;
+    }
+}

Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/InputStreamResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/InputStreamResource.java?rev=792337&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/InputStreamResource.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/InputStreamResource.java Wed Jul  8 22:10:22 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.jaxrs.test.providers.standard;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+
+@Path("providers/standard/inputstream")
+public class InputStreamResource {
+
+    private byte[] barr = null;
+
+    @GET
+    public Response getInputStream() {
+        return Response.ok(new ByteArrayInputStream(barr)).build();
+    }
+
+    @POST
+    public InputStream postInputStream(InputStream is) {
+        return is;
+    }
+
+    @POST
+    @Path("/subclasses/shouldfail")
+    public ByteArrayInputStream postInputStream(ByteArrayInputStream is) {
+        return is;
+    }
+
+    @PUT
+    public void putInputStream(InputStream is) throws IOException {
+        byte[] buffer = new byte[(is.available() <= 0) ? 1 : is.available()];
+        int read = 0;
+        int offset = 0;
+        while ((read = is.read(buffer, offset, buffer.length - offset)) != -1) {
+            offset += read;
+            if (offset >= buffer.length) {
+                buffer = ArrayUtils.copyOf(buffer, buffer.length * 2);
+            }
+        }
+        barr = ArrayUtils.copyOf(buffer, offset);
+    }
+}

Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/MultiValuedMapResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/MultiValuedMapResource.java?rev=792337&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/MultiValuedMapResource.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/MultiValuedMapResource.java Wed Jul  8 22:10:22 2009
@@ -0,0 +1,65 @@
+/*
+ * 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.IOException;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+
+@Path("providers/standard/multivaluedmap")
+public class MultiValuedMapResource {
+
+    private MultivaluedMap<String, String> formData = null;
+
+    @GET
+    public Response getMultivaluedMap() {
+        return Response.ok(formData).build();
+    }
+
+    @POST
+    @Produces("application/x-www-form-urlencoded")
+    public MultivaluedMap<String, String> postMultivaluedMap(MultivaluedMap<String, String> map) {
+        return map;
+    }
+
+    @POST
+    @Path("/noproduces")
+    public MultivaluedMap<String, String> postMultivaluedMapNoProduces(MultivaluedMap<String, String> map) {
+        return map;
+    }
+
+    @POST
+    @Path("/subclasses/shouldfail")
+    public MultivaluedMap<String, Object> postMultivaluedMapWithNotRightTypes(MultivaluedMap<String, Object> map) {
+        return map;
+    }
+
+    @PUT
+    public void putMultivaluedMap(MultivaluedMap<String, String> map)
+            throws IOException {
+        formData = map;
+    }
+}

Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/ReaderResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/ReaderResource.java?rev=792337&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/ReaderResource.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/ReaderResource.java Wed Jul  8 22:10:22 2009
@@ -0,0 +1,68 @@
+/*
+ * 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.BufferedReader;
+import java.io.CharArrayReader;
+import java.io.IOException;
+import java.io.Reader;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+
+@Path("providers/standard/reader")
+public class ReaderResource {
+
+    private char[] carr = null;
+
+    @GET
+    public Response getReader() {
+        return Response.ok(new BufferedReader(new CharArrayReader(carr)))
+                .build();
+    }
+
+    @POST
+    public Reader postReader(Reader reader) {
+        return reader;
+    }
+
+    @POST
+    @Path("/subclasses/shouldfail")
+    public BufferedReader postReader(BufferedReader br) {
+        return br;
+    }
+
+    @PUT
+    public void putReader(Reader is) throws IOException {
+        char[] buffer = new char[1];
+        int read = 0;
+        int offset = 0;
+        while ((read = is.read(buffer, offset, buffer.length - offset)) != -1) {
+            offset += read;
+            if (offset >= buffer.length) {
+                buffer = ArrayUtils.copyOf(buffer, buffer.length * 2);
+            }
+        }
+        carr = ArrayUtils.copyOf(buffer, offset);
+    }
+}

Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/SourceResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/SourceResource.java?rev=792337&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/SourceResource.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/SourceResource.java Wed Jul  8 22:10:22 2009
@@ -0,0 +1,70 @@
+/*
+ * 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.IOException;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+import javax.xml.transform.Source;
+
+@Path("providers/standard/source")
+public class SourceResource {
+
+    private Source source = null;
+
+    @GET
+    public Response getSource() {
+        return Response.ok(source).build();
+    }
+
+    @POST
+    public Source postSource(Source src) {
+        return src;
+    }
+    
+    public static class UnsupportedSourceSubclass implements Source {
+
+        public String getSystemId() {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        public void setSystemId(String systemId) {
+            // TODO Auto-generated method stub
+            
+        }
+        
+    }
+
+    @POST
+    @Path("/subclasses/shouldfail")
+    public UnsupportedSourceSubclass postReader(UnsupportedSourceSubclass saxSource) {
+        return saxSource;
+    }
+
+    @PUT
+    public void putSource(Source source) throws IOException {
+        this.source = source;
+    }
+}

Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/StreamingOutputResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/StreamingOutputResource.java?rev=792337&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/StreamingOutputResource.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/java/org/apache/wink/jaxrs/test/providers/standard/StreamingOutputResource.java Wed Jul  8 22:10:22 2009
@@ -0,0 +1,79 @@
+/*
+ * 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.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.StreamingOutput;
+
+@Path("providers/standard/streamingoutput")
+public class StreamingOutputResource {
+
+    private byte[] barr = null;
+
+    @GET
+    public Response getStreamingOutputStream() {
+        return Response.ok(new StreamingOutput() {
+
+            public void write(OutputStream arg0) throws IOException,
+                    WebApplicationException {
+                arg0.write(barr);
+            }
+
+        }).build();
+    }
+
+    @POST
+    public StreamingOutput postInputStream(final InputStream is) {
+        return new StreamingOutput() {
+
+            public void write(OutputStream arg0) throws IOException,
+                    WebApplicationException {
+                int read = 0;
+                while ((read = is.read()) != -1) {
+                    arg0.write(read);
+                }
+            }
+
+        };
+    }
+
+    @PUT
+    public void putInputStream(InputStream is) throws IOException {
+        byte[] buffer = new byte[(is.available() <= 0) ? 1 : is.available()];
+        int read = 0;
+        int offset = 0;
+        while ((read = is.read(buffer, offset, buffer.length - offset)) != -1) {
+            offset += read;
+            if (offset >= buffer.length) {
+                buffer = ArrayUtils.copyOf(buffer, buffer.length * 2);
+            }
+        }
+        barr = ArrayUtils.copyOf(buffer, offset);
+    }
+}

Modified: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/webapp/WEB-INF/web.xml?rev=792337&r1=792336&r2=792337&view=diff
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/webapp/WEB-INF/web.xml (original)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/webapp/WEB-INF/web.xml Wed Jul  8 22:10:22 2009
@@ -70,6 +70,19 @@
         </init-param>
         <load-on-startup>1</load-on-startup>
     </servlet>
+    <servlet>
+        <servlet-name>StandardEntityProviders</servlet-name>
+        <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
+        <init-param>
+            <param-name>javax.ws.rs.Application</param-name>
+            <param-value>org.apache.wink.jaxrs.test.providers.standard.Application</param-value>
+        </init-param>
+        <init-param>
+            <param-name>requestProcessorAttribute</param-name>
+            <param-value>requestProcessorAttribute_standard</param-value>
+        </init-param>
+        <load-on-startup>1</load-on-startup>
+    </servlet>
     <servlet-mapping>
         <servlet-name>MessageBodyReaders</servlet-name>
         <url-pattern>/readers/*</url-pattern>
@@ -86,4 +99,8 @@
         <servlet-name>MessageBodyWriterExceptions</servlet-name>
         <url-pattern>/writerexceptions/*</url-pattern>
     </servlet-mapping>
+    <servlet-mapping>
+        <servlet-name>StandardEntityProviders</servlet-name>
+        <url-pattern>/standard/*</url-pattern>
+    </servlet-mapping>
 </web-app>

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/JAXRSBytesArrayTest.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/JAXRSBytesArrayTest.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/JAXRSBytesArrayTest.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/JAXRSBytesArrayTest.java Wed Jul  8 22:10:22 2009
@@ -0,0 +1,175 @@
+/*
+ * 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.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 JAXRSBytesArrayTest extends TestCase {
+
+    public String getBaseURI() {
+        return ServerEnvironmentInfo.getBaseURI() + "/standard";
+    }
+
+    /**
+     * Tests posting a byte array.
+     * 
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testPostByteArray() throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        PostMethod postMethod = new PostMethod(getBaseURI() + "/providers/standard/bytesarray");
+        byte[] barr = new byte[1000];
+        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[1000];
+            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());
+            assertEquals(barr.length, Integer.valueOf(postMethod
+                .getResponseHeader("Content-Length").getValue()).intValue());
+        } finally {
+            postMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests putting and then getting a byte array.
+     * 
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testPutByteArray() throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        PutMethod putMethod = new PutMethod(getBaseURI() + "/providers/standard/bytesarray");
+        byte[] barr = new byte[1000];
+        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/bytesarray");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            InputStream is = getMethod.getResponseBodyAsStream();
+
+            byte[] receivedBArr = new byte[1000];
+            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());
+            assertEquals(barr.length, Integer.valueOf(getMethod.getResponseHeader("Content-Length")
+                .getValue()).intValue());
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests receiving an empty byte array.
+     * 
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testWithRequestAcceptHeaderWillReturnRequestedContentType() throws HttpException,
+        IOException {
+        HttpClient client = new HttpClient();
+
+        PutMethod putMethod = new PutMethod(getBaseURI() + "/providers/standard/bytesarray");
+        byte[] barr = new byte[1000];
+        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/bytesarray");
+        getMethod.addRequestHeader("Accept", "mytype/subtype");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            InputStream is = getMethod.getResponseBodyAsStream();
+
+            byte[] receivedBArr = new byte[1000];
+            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());
+            assertEquals(barr.length, Integer.valueOf(getMethod.getResponseHeader("Content-Length")
+                .getValue()).intValue());
+        } finally {
+            getMethod.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/JAXRSDataSourceTest.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/JAXRSDataSourceTest.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/JAXRSDataSourceTest.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/JAXRSDataSourceTest.java Wed Jul  8 22:10:22 2009
@@ -0,0 +1,206 @@
+/*
+ * 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.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 JAXRSDataSourceTest extends TestCase {
+
+    public String getBaseURI() {
+        return ServerEnvironmentInfo.getBaseURI() + "/standard";
+    }
+
+    /**
+     * Tests posting to a DataSource entity parameter.
+     * 
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testPostDataSource() throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        PostMethod postMethod = new PostMethod(getBaseURI() + "/providers/standard/datasource");
+        byte[] barr = new byte[1000];
+        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[1000];
+            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());
+            assertNull((postMethod.getResponseHeader("Content-Length") == null) ? "" : postMethod
+                .getResponseHeader("Content-Length").getValue(), postMethod
+                .getResponseHeader("Content-Length"));
+        } finally {
+            postMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests putting and then getting a DataSource entity.
+     * 
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testPutDataSource() throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        PutMethod putMethod = new PutMethod(getBaseURI() + "/providers/standard/datasource");
+        byte[] barr = new byte[1000];
+        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/datasource");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            InputStream is = getMethod.getResponseBodyAsStream();
+
+            byte[] receivedBArr = new byte[1000];
+            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());
+            assertNull((getMethod.getResponseHeader("Content-Length") == null) ? "" : getMethod
+                .getResponseHeader("Content-Length").getValue(), getMethod
+                .getResponseHeader("Content-Length"));
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests receiving a DataSource with any media type.
+     * 
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testWithRequestAcceptHeaderWillReturnRequestedContentType() throws HttpException,
+        IOException {
+        HttpClient client = new HttpClient();
+
+        PutMethod putMethod = new PutMethod(getBaseURI() + "/providers/standard/datasource");
+        byte[] barr = new byte[1000];
+        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/datasource");
+        getMethod.addRequestHeader("Accept", "mytype/subtype");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            InputStream is = getMethod.getResponseBodyAsStream();
+
+            byte[] receivedBArr = new byte[1000];
+            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());
+            assertNull((getMethod.getResponseHeader("Content-Length") == null) ? "" : getMethod
+                .getResponseHeader("Content-Length").getValue(), getMethod
+                .getResponseHeader("Content-Length"));
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests posting to a DataSource subclass. This should result in a 415
+     * error.
+     * 
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testPostDataSourceSubclass() throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        PostMethod postMethod =
+            new PostMethod(getBaseURI() + "/providers/standard/datasource/subclass/should/fail");
+        byte[] barr = new byte[1000];
+        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(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/JAXRSFileTest.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/JAXRSFileTest.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/JAXRSFileTest.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/JAXRSFileTest.java Wed Jul  8 22:10:22 2009
@@ -0,0 +1,138 @@
+/*
+ * 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.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 JAXRSFileTest extends TestCase {
+
+    public String getBaseURI() {
+        return ServerEnvironmentInfo.getBaseURI() + "/standard";
+    }
+
+    /**
+     * Tests posting to a File entity parameter.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testPostFile() throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        PostMethod postMethod = new PostMethod(getBaseURI()
+                + "/providers/standard/file");
+        byte[] barr = new byte[1000];
+        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[1000];
+            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());
+            assertEquals(1000, Integer.valueOf(
+                    postMethod.getResponseHeader("Content-Length").getValue())
+                    .intValue());
+        } finally {
+            postMethod.releaseConnection();
+        }
+
+        /* TODO : need to test that any temporary files created are deleted */
+    }
+
+    /**
+     * Tests receiving an empty byte array.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testWithRequestAcceptHeaderWillReturnRequestedContentType()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        PutMethod putMethod = new PutMethod(getBaseURI()
+                + "/providers/standard/file");
+        byte[] barr = new byte[1000];
+        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/file");
+        getMethod.addRequestHeader("Accept", "mytype/subtype");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            InputStream is = getMethod.getResponseBodyAsStream();
+
+            byte[] receivedBArr = new byte[1000];
+            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());
+            assertEquals(barr.length, Integer.valueOf(
+                    getMethod.getResponseHeader("Content-Length").getValue())
+                    .intValue());
+        } finally {
+            getMethod.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/JAXRSInputStreamTest.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/JAXRSInputStreamTest.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/JAXRSInputStreamTest.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/JAXRSInputStreamTest.java Wed Jul  8 22:10:22 2009
@@ -0,0 +1,217 @@
+/*
+ * 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 JAXRSInputStreamTest extends TestCase {
+
+    public String getBaseURI() {
+        return ServerEnvironmentInfo.getBaseURI() + "/standard";
+    }
+
+    /**
+     * Tests posting to an InputStream
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testPostInputStream() throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        PostMethod postMethod = new PostMethod(getBaseURI()
+                + "/providers/standard/inputstream");
+        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 byte array.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testPutInputStream() throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        PutMethod putMethod = new PutMethod(getBaseURI()
+                + "/providers/standard/inputstream");
+        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/inputstream");
+        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 an empty byte array.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testWithRequestAcceptHeaderWillReturnRequestedContentType()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        PutMethod putMethod = new PutMethod(getBaseURI()
+                + "/providers/standard/inputstream");
+        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/inputstream");
+        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();
+        }
+    }
+
+    /**
+     * Tests a resource method invoked with a ByteArrayInputStream 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 testInputStreamImplementation() throws HttpException,
+            IOException {
+        HttpClient client = new HttpClient();
+
+        PostMethod postMethod = new PostMethod(getBaseURI()
+                + "/providers/standard/inputstream/subclasses/shouldfail");
+        byte[] barr = new byte[100000];
+        Random r = new Random();
+        r.nextBytes(barr);
+        postMethod.setRequestEntity(new InputStreamRequestEntity(
+                new ByteArrayInputStream(barr), "any/type"));
+        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/JAXRSMultivaluedMapTest.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/JAXRSMultivaluedMapTest.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/JAXRSMultivaluedMapTest.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/JAXRSMultivaluedMapTest.java Wed Jul  8 22:10:22 2009
@@ -0,0 +1,240 @@
+/*
+ * 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.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+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.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+public class JAXRSMultivaluedMapTest extends TestCase {
+
+    public String getBaseURI() {
+        return ServerEnvironmentInfo.getBaseURI() + "/standard";
+    }
+
+    /**
+     * Tests posting to a MultivaluedMap with application/x-www-form-urlencoded
+     * request Content-Type.
+     * 
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testPostMultivaluedMap() throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        PostMethod postMethod = new PostMethod(getBaseURI() + "/providers/standard/multivaluedmap");
+        postMethod.setRequestEntity(new StringRequestEntity("tuv=wxyz&abcd=",
+                                                            "application/x-www-form-urlencoded",
+                                                            "UTF-8"));
+        try {
+            client.executeMethod(postMethod);
+
+            assertEquals(200, postMethod.getStatusCode());
+            InputStream is = postMethod.getResponseBodyAsStream();
+
+            InputStreamReader isr = new InputStreamReader(is);
+            char[] buffer = new char[1];
+            int read = 0;
+            int offset = 0;
+            while ((read = isr.read(buffer, offset, buffer.length - offset)) != -1) {
+                offset += read;
+                if (offset >= buffer.length) {
+                    buffer = ArrayUtils.copyOf(buffer, buffer.length * 2);
+                }
+            }
+            char[] carr = ArrayUtils.copyOf(buffer, offset);
+
+            int checkEOF = is.read();
+            assertEquals(-1, checkEOF);
+            String str = new String(carr);
+
+            assertTrue(str, "abcd=&tuv=wxyz".equals(str) || "tuv=wxyz&abcd=".equals(str));
+            assertEquals("application/x-www-form-urlencoded", postMethod
+                .getResponseHeader("Content-Type").getValue());
+            Header contentLengthHeader = postMethod.getResponseHeader("Content-Length");
+            if (contentLengthHeader != null) {
+                // some of the containers can be "smarter" and set the
+                // content-length for us if the payload is small
+                assertEquals("14", contentLengthHeader.getValue());
+            }
+        } finally {
+            postMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests posting to a MultivaluedMap with a request Content-Type that is not
+     * application/x-www-form-urlencoded.
+     * 
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testPostMultivaluedMapNotFormURLEncoded() throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        PostMethod postMethod = new PostMethod(getBaseURI() + "/providers/standard/multivaluedmap");
+        postMethod
+            .setRequestEntity(new StringRequestEntity("tuv=wxyz&abcd=", "text/plain", "UTF-8"));
+        try {
+            client.executeMethod(postMethod);
+
+            assertEquals(415, postMethod.getStatusCode());
+        } finally {
+            postMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests posting to a MultivaluedMap with a request Accept type that is not
+     * application/x-www-form-urlencoded.
+     * 
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testPostMultivaluedMapAcceptNotFormURLEncoded() throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        PostMethod postMethod =
+            new PostMethod(getBaseURI() + "/providers/standard/multivaluedmap/noproduces");
+        postMethod.setRequestEntity(new StringRequestEntity("tuv=wxyz&abcd=",
+                                                            "application/x-www-form-urlencoded",
+                                                            "UTF-8"));
+        postMethod.addRequestHeader("Accept", "text/plain");
+        try {
+            client.executeMethod(postMethod);
+
+            assertEquals(500, postMethod.getStatusCode());
+        } finally {
+            postMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests putting and then getting a /multivaluedmap.
+     * 
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testPutReader() throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        PutMethod putMethod = new PutMethod(getBaseURI() + "/providers/standard/multivaluedmap");
+        putMethod.setRequestEntity(new StringRequestEntity("username=user1&password=user1password",
+                                                           "application/x-www-form-urlencoded",
+                                                           "UTF-8"));
+        try {
+            client.executeMethod(putMethod);
+            assertEquals(204, putMethod.getStatusCode());
+        } finally {
+            putMethod.releaseConnection();
+        }
+
+        GetMethod getMethod = new GetMethod(getBaseURI() + "/providers/standard/multivaluedmap");
+        getMethod.addRequestHeader("Accept", "application/x-www-form-urlencoded");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            InputStream is = getMethod.getResponseBodyAsStream();
+
+            InputStreamReader isr = new InputStreamReader(is);
+            char[] buffer = new char[1];
+            int read = 0;
+            int offset = 0;
+            while ((read = isr.read(buffer, offset, buffer.length - offset)) != -1) {
+                offset += read;
+                if (offset >= buffer.length) {
+                    buffer = ArrayUtils.copyOf(buffer, buffer.length * 2);
+                }
+            }
+            char[] carr = ArrayUtils.copyOf(buffer, offset);
+
+            int checkEOF = is.read();
+            assertEquals(-1, checkEOF);
+            String str = new String(carr);
+
+            assertTrue(str,
+                       "username=user1&password=user1password".equals(str) || "password=user1password&username=user1"
+                           .equals(str));
+            assertEquals("application/x-www-form-urlencoded", getMethod
+                .getResponseHeader("Content-Type").getValue());
+            Header contentLengthHeader = getMethod.getResponseHeader("Content-Length");
+            if (contentLengthHeader != null) {
+                // some of the containers can be "smarter" and set the
+                // content-length for us if the payload is small
+                assertEquals("37", contentLengthHeader.getValue());
+            }
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+    //
+    // /**
+    // * Tests a resource method invoked with a MultivaluedMap&lt;String,
+    // * Object&gt; 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 testMultivaluedMapImplementation() throws HttpException,
+    // IOException {
+    // HttpClient client = new HttpClient();
+    //
+    // PostMethod postMethod = new PostMethod(getBaseURI()
+    // + "/providers/standard/multivaluedmap/subclasses/shouldfail");
+    // byte[] barr = new byte[1000];
+    // Random r = new Random();
+    // r.nextBytes(barr);
+    // postMethod.setRequestEntity(new InputStreamRequestEntity(new
+    // ByteArrayInputStream(barr),
+    // "any/type"));
+    // try {
+    // client.executeMethod(postMethod);
+    // assertEquals(415, postMethod.getStatusCode());
+    // } finally {
+    // postMethod.releaseConnection();
+    // }
+    //
+    // postMethod = new PostMethod(getBaseURI()
+    // + "/providers/standard/multivaluedmap/subclasses/shouldfail");
+    // postMethod.setRequestEntity(new InputStreamRequestEntity(new
+    // ByteArrayInputStream(barr),
+    // "application/x-www-form-urlencoded"));
+    // try {
+    // client.executeMethod(postMethod);
+    // assertEquals(415, postMethod.getStatusCode());
+    // System.out.println(postMethod.getResponseBodyAsString());
+    // } 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/JAXRSReaderTest.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/JAXRSReaderTest.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/JAXRSReaderTest.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/JAXRSReaderTest.java Wed Jul  8 22:10:22 2009
@@ -0,0 +1,234 @@
+/*
+ * 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.io.InputStream;
+import java.io.InputStreamReader;
+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 JAXRSReaderTest extends TestCase {
+
+    public String getBaseURI() {
+        return ServerEnvironmentInfo.getBaseURI() + "/standard";
+    }
+
+    /**
+     * Tests posting to a Reader parameter.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testPostReader() throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        PostMethod postMethod = new PostMethod(getBaseURI()
+                + "/providers/standard/reader");
+        postMethod.setRequestEntity(new StringRequestEntity("abcd",
+                "text/plain", "UTF-8"));
+        postMethod.addRequestHeader("Accept", "text/plain");
+        try {
+            client.executeMethod(postMethod);
+
+            assertEquals(200, postMethod.getStatusCode());
+            InputStream is = postMethod.getResponseBodyAsStream();
+
+            InputStreamReader isr = new InputStreamReader(is);
+            char[] buffer = new char[1];
+            int read = 0;
+            int offset = 0;
+            while ((read = isr.read(buffer, offset, buffer.length - offset)) != -1) {
+                offset += read;
+                if (offset >= buffer.length) {
+                    buffer = ArrayUtils.copyOf(buffer, buffer.length * 2);
+                }
+            }
+            char[] carr = ArrayUtils.copyOf(buffer, offset);
+
+            int checkEOF = is.read();
+            assertEquals(-1, checkEOF);
+            String str = new String(carr);
+
+            assertEquals("abcd", str);
+            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 Reader.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testPutReader() throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        PutMethod putMethod = new PutMethod(getBaseURI()
+                + "/providers/standard/reader");
+        putMethod.setRequestEntity(new StringRequestEntity("wxyz",
+                "char/array", "UTF-8"));
+        try {
+            client.executeMethod(putMethod);
+            assertEquals(204, putMethod.getStatusCode());
+        } finally {
+            putMethod.releaseConnection();
+        }
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/providers/standard/reader");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            InputStream is = getMethod.getResponseBodyAsStream();
+
+            InputStreamReader isr = new InputStreamReader(is);
+            char[] buffer = new char[1];
+            int read = 0;
+            int offset = 0;
+            while ((read = isr.read(buffer, offset, buffer.length - offset)) != -1) {
+                offset += read;
+                if (offset >= buffer.length) {
+                    buffer = ArrayUtils.copyOf(buffer, buffer.length * 2);
+                }
+            }
+            char[] carr = ArrayUtils.copyOf(buffer, offset);
+
+            int checkEOF = is.read();
+            assertEquals(-1, checkEOF);
+            String str = new String(carr);
+
+            assertEquals("wxyz", 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();
+        }
+    }
+
+    /**
+     *
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testWithRequestAcceptHeaderWillReturnRequestedContentType()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        PutMethod putMethod = new PutMethod(getBaseURI()
+                + "/providers/standard/reader");
+        putMethod.setRequestEntity(new StringRequestEntity("wxyz",
+                "char/array", "UTF-8"));
+        try {
+            client.executeMethod(putMethod);
+            assertEquals(204, putMethod.getStatusCode());
+        } finally {
+            putMethod.releaseConnection();
+        }
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/providers/standard/reader");
+        getMethod.addRequestHeader("Accept", "mytype/subtype");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            InputStream is = getMethod.getResponseBodyAsStream();
+
+            InputStreamReader isr = new InputStreamReader(is);
+            char[] buffer = new char[1];
+            int read = 0;
+            int offset = 0;
+            while ((read = isr.read(buffer, offset, buffer.length - offset)) != -1) {
+                offset += read;
+                if (offset >= buffer.length) {
+                    buffer = ArrayUtils.copyOf(buffer, buffer.length * 2);
+                }
+            }
+            char[] carr = ArrayUtils.copyOf(buffer, offset);
+
+            int checkEOF = is.read();
+            assertEquals(-1, checkEOF);
+            String str = new String(carr);
+
+            assertEquals("wxyz", str);
+            assertEquals("mytype/subtype", 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 BufferedReader 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 testInputStreamImplementation() throws HttpException,
+            IOException {
+        HttpClient client = new HttpClient();
+
+        PostMethod postMethod = new PostMethod(getBaseURI()
+                + "/providers/standard/reader/subclasses/shouldfail");
+        byte[] barr = new byte[1000];
+        Random r = new Random();
+        r.nextBytes(barr);
+        postMethod.setRequestEntity(new InputStreamRequestEntity(
+                new ByteArrayInputStream(barr), "any/type"));
+        try {
+            client.executeMethod(postMethod);
+            assertEquals(415, postMethod.getStatusCode());
+        } finally {
+            postMethod.releaseConnection();
+        }
+    }
+}