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/08/07 05:10:46 UTC
svn commit: r801869 [13/21] - in /incubator/wink/trunk:
wink-integration-test/
wink-integration-test/wink-server-integration-test-support/
wink-integration-test/wink-server-integration-test-support/src/main/java/org/apache/wink/test/integration/
wink-i...
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableGenericEntitySetString.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableGenericEntitySetString.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableGenericEntitySetString.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableGenericEntitySetString.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.wink.itest.writers;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+public class MessageBodyWriterIsWritableGenericEntitySetString implements MessageBodyWriter<Object> {
+
+ public long getSize(Object arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4) {
+ return -1;
+ }
+
+ public boolean isWriteable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) {
+ if (arg0.isAssignableFrom(HashSet.class)) {
+ if (arg1 instanceof ParameterizedType) {
+ ParameterizedType pt = (ParameterizedType)arg1;
+ Type[] args = pt.getActualTypeArguments();
+ if (args.length == 1 && args[0].equals(String.class)) {
+ if (pt.getRawType().equals(Set.class)) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void writeTo(Object arg0,
+ Class<?> arg1,
+ Type arg2,
+ Annotation[] arg3,
+ MediaType arg4,
+ MultivaluedMap<String, Object> arg5,
+ OutputStream arg6) throws IOException, WebApplicationException {
+ Writer writer = new OutputStreamWriter(arg6);
+ Set<String> s = (Set<String>)arg0;
+ writer.write("set<string>:");
+ List<String> list = new ArrayList<String>(s);
+ Collections.sort(list);
+ for (Object o : list) {
+ writer.write(o.toString());
+ }
+ writer.flush();
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableGetAnnotated.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableGetAnnotated.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableGetAnnotated.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableGetAnnotated.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.wink.itest.writers;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.List;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+public class MessageBodyWriterIsWritableGetAnnotated implements MessageBodyWriter<Object> {
+
+ public long getSize(Object arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4) {
+ return -1;
+ }
+
+ public boolean isWriteable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) {
+ boolean isGetAnnotated = false;
+ boolean isMyWriterAnnotated = false;
+ if (arg2 != null) {
+ for (Annotation ann : arg2) {
+ if (MyWriterAnnotation.class.equals(ann.annotationType())) {
+ isMyWriterAnnotated = true;
+ } else if (GET.class.equals(ann.annotationType())) {
+ isGetAnnotated = true;
+ }
+ }
+ if (isMyWriterAnnotated && isGetAnnotated) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void writeTo(Object arg0,
+ Class<?> arg1,
+ Type arg2,
+ Annotation[] arg3,
+ MediaType arg4,
+ MultivaluedMap<String, Object> arg5,
+ OutputStream arg6) throws IOException, WebApplicationException {
+ Writer writer = new OutputStreamWriter(arg6);
+ writer.write("getannotation:");
+ List list = (List)arg0;
+ for (Object o : list) {
+ writer.write(o.toString());
+ }
+ writer.flush();
+ }
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableMediaTypeHashMap.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableMediaTypeHashMap.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableMediaTypeHashMap.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableMediaTypeHashMap.java Fri Aug 7 03: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.itest.writers;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Map;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+public class MessageBodyWriterIsWritableMediaTypeHashMap implements MessageBodyWriter<Object> {
+
+ public long getSize(Object arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4) {
+ return -1;
+ }
+
+ public boolean isWriteable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) {
+ if (arg3.equals(new MediaType("custom", "correct"))) {
+ return true;
+ }
+ return false;
+ }
+
+ public void writeTo(Object arg0,
+ Class<?> arg1,
+ Type arg2,
+ Annotation[] arg3,
+ MediaType arg4,
+ MultivaluedMap<String, Object> arg5,
+ OutputStream arg6) throws IOException, WebApplicationException {
+ Writer writer = new OutputStreamWriter(arg6);
+ writer.write("mediatype:");
+ Map map = (Map)arg0;
+ for (Object k : map.keySet()) {
+ writer.write(k.toString() + "=" + map.get(k));
+ }
+ writer.flush();
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritablePostAnnotated.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritablePostAnnotated.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritablePostAnnotated.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritablePostAnnotated.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.wink.itest.writers;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.List;
+
+import javax.ws.rs.POST;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+public class MessageBodyWriterIsWritablePostAnnotated implements MessageBodyWriter<List> {
+
+ public long getSize(List arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4) {
+ return -1;
+ }
+
+ public boolean isWriteable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) {
+ boolean isPostAnnotated = false;
+ boolean isMyWriterAnnotated = false;
+ for (Annotation ann : arg2) {
+ if (MyWriterAnnotation.class.equals(ann.annotationType())) {
+ isMyWriterAnnotated = true;
+ } else if (POST.class.equals(ann.annotationType())) {
+ isPostAnnotated = true;
+ }
+ }
+ if (isMyWriterAnnotated && isPostAnnotated) {
+ return true;
+ }
+ return false;
+ }
+
+ public void writeTo(List arg0,
+ Class<?> arg1,
+ Type arg2,
+ Annotation[] arg3,
+ MediaType arg4,
+ MultivaluedMap<String, Object> arg5,
+ OutputStream arg6) throws IOException, WebApplicationException {
+ Writer writer = new OutputStreamWriter(arg6);
+ writer.write("postannotation:");
+ for (Object o : arg0) {
+ writer.write(o.toString());
+ }
+ writer.flush();
+ }
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableSet.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableSet.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableSet.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableSet.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.wink.itest.writers;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+public class MessageBodyWriterIsWritableSet implements MessageBodyWriter<Set> {
+
+ public long getSize(Set arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4) {
+ return -1;
+ }
+
+ public boolean isWriteable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) {
+ if (arg0.isAssignableFrom(HashSet.class)) {
+ if (arg1 instanceof Class) {
+ return arg1.equals(HashSet.class);
+ }
+ }
+ return false;
+ }
+
+ @SuppressWarnings( {"unchecked", "cast"})
+ public void writeTo(Set arg0,
+ Class<?> arg1,
+ Type arg2,
+ Annotation[] arg3,
+ MediaType arg4,
+ MultivaluedMap<String, Object> arg5,
+ OutputStream arg6) throws IOException, WebApplicationException {
+ Writer writer = new OutputStreamWriter(arg6);
+ Set<?> s = (Set<?>)arg0;
+ writer.write("set:");
+ List list = new ArrayList(s);
+ Collections.sort(list);
+ for (Object o : list) {
+ writer.write(o.toString());
+ }
+ writer.flush();
+
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableThrowsExceptions.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableThrowsExceptions.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableThrowsExceptions.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MessageBodyWriterIsWritableThrowsExceptions.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.wink.itest.writers;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+public class MessageBodyWriterIsWritableThrowsExceptions implements MessageBodyWriter<Object> {
+
+ public long getSize(Object arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4) {
+ return -1;
+ }
+
+ public boolean isWriteable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) {
+ if (arg3.equals(new MediaType("throw", "runtime"))) {
+ throw new RuntimeException();
+ } else if (arg3.equals(new MediaType("throw", "nullpointer"))) {
+ throw new NullPointerException();
+ } else if (arg3.equals(new MediaType("throw", "webapplicationexception"))) {
+ throw new WebApplicationException(Response.status(461)
+ .entity("throwiswritableexception").build());
+ }
+ return false;
+ }
+
+ public void writeTo(Object arg0,
+ Class<?> arg1,
+ Type arg2,
+ Annotation[] arg3,
+ MediaType arg4,
+ MultivaluedMap<String, Object> arg5,
+ OutputStream arg6) throws IOException, WebApplicationException {
+ /* do nothing */
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MyWriterAnnotation.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MyWriterAnnotation.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MyWriterAnnotation.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/MyWriterAnnotation.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.wink.itest.writers;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(value = {ElementType.FIELD, ElementType.LOCAL_VARIABLE, ElementType.PARAMETER,
+ ElementType.METHOD})
+public @interface MyWriterAnnotation {
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/Queue.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/Queue.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/Queue.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/Queue.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.wink.itest.writers;
+
+/**
+ * this class is a dummy class to fill in for the Queue we were originally using
+ * from JDK6.
+ *
+ * @param <T>
+ */
+public interface Queue<T> extends Iterable<T> {
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/WriterResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/WriterResource.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/WriterResource.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/java/org/apache/wink/itest/writers/WriterResource.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,188 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.wink.itest.writers;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.Vector;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.GenericEntity;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.xml.transform.dom.DOMSource;
+
+@Path("jaxrs/tests/providers/messagebodywriter")
+public class WriterResource {
+
+ private static int counter = 0;
+
+ @GET
+ @Path("concretetype")
+ public String getConcretTypeBack() {
+ return "Hello there";
+ }
+
+ @GET
+ @Path("contentlength")
+ @CustomAnnotation
+ public Response getContentLength(@QueryParam("mt") String mt, @QueryParam("class") String clazz) {
+ if (clazz == null) {
+ byte[] barr = new byte[100000];
+ for (int c = 0; c < barr.length; ++c) {
+ barr[c] = (byte)c;
+ }
+ return Response.ok(barr).type(mt).build();
+ } else if ("Vector".equals(clazz)) {
+ Vector v = new Vector(2);
+ v.add("Hello");
+ v.add("There");
+ return Response.ok(v).type(mt).build();
+ } else if ("ListInteger".equals(clazz)) {
+ List<Integer> v = new ArrayList<Integer>(2);
+ v.add(1);
+ v.add(2);
+ return Response.ok(new GenericEntity<List<Integer>>(v) {
+ }).build();
+ } else if ("String".equals(clazz)) {
+ return Response.ok("hello there").build();
+ }
+ return null;
+ }
+
+ @Path("classtype")
+ @GET
+ public Object getWriterClassType(@QueryParam("type") String type) {
+ if ("deque".equals(type)) {
+ ArrayDeque<String> d = new ArrayDeque<String>();
+ d.add("str:foo");
+ d.add("str:bar");
+ return d;
+ } else if ("hashmap".equals(type)) {
+ return new HashMap<String, String>();
+ } else if ("string".equals(type)) {
+ return "str:foobar";
+ } else if ("stringcontenttype".equals(type)) {
+ return Response.ok("str:foobarcontenttype").type(MediaType.APPLICATION_XML_TYPE)
+ .build();
+ } else if ("sourcecontenttype".equals(type)) {
+ return Response.ok(new DOMSource()).type(MediaType.APPLICATION_JSON).build();
+ } else if ("source".equals(type)) {
+ return Response.ok(new DOMSource()).type(MediaType.TEXT_XML).build();
+ }
+ return null;
+ }
+
+ @Path("notannotated")
+ @GET
+ public Object getWriterNotAnnotatedMethod() {
+ List<String> l = new ArrayList<String>();
+ l.add("foo");
+ l.add("bar");
+ return l;
+ }
+
+ @Path("annotated")
+ @GET
+ @MyWriterAnnotation
+ public Object getWriterAnnotatedMethod() {
+ List<String> l = new ArrayList<String>();
+ l.add("foo");
+ l.add("bar");
+ return l;
+ }
+
+ @Path("annotated")
+ @POST
+ @MyWriterAnnotation
+ public Object postWriterAnnotatedMethod() {
+ List<String> l = new ArrayList<String>();
+ l.add("foo");
+ l.add("bar");
+ return l;
+ }
+
+ @Path("genericentity")
+ @POST
+ public Response getWriterResponse(@QueryParam("query") String q) {
+ if ("setstring".equals(q)) {
+ HashSet<String> s = new HashSet<String>();
+ s.add("hello");
+ s.add("world");
+ return Response.ok(new GenericEntity<Set<String>>(s) {
+ }).build();
+ } else if ("setinteger".equals(q)) {
+ HashSet<Integer> s = new HashSet<Integer>();
+ s.add(Integer.valueOf(1));
+ s.add(Integer.valueOf(2));
+ return Response.ok(new GenericEntity<Set<Integer>>(s) {
+ }).build();
+ } else if ("setshort".equals(q)) {
+ HashSet<Short> s = new HashSet<Short>();
+ s.add(Short.valueOf((short)1));
+ s.add(Short.valueOf((short)2));
+ return Response.ok(new GenericEntity<Set<Short>>(s) {
+ }).build();
+ }
+ return null;
+ }
+
+ @Path("nogenericentity")
+ @POST
+ public Response getNoWriterResponse(@QueryParam("query") String q) {
+ if ("setstring".equals(q)) {
+ HashSet<String> s = new HashSet<String>();
+ s.add("hello");
+ s.add("world");
+ return Response.ok(s).build();
+ } else if ("setinteger".equals(q)) {
+ HashSet<Integer> s = new HashSet<Integer>();
+ s.add(Integer.valueOf(1));
+ s.add(Integer.valueOf(2));
+ return Response.ok(s).build();
+ } else if ("setshort".equals(q)) {
+ HashSet<Short> s = new HashSet<Short>();
+ s.add(Short.valueOf((short)1));
+ s.add(Short.valueOf((short)2));
+ return Response.ok(s).build();
+ }
+ return null;
+ }
+
+ @Path("mediatype")
+ @POST
+ public Response getMediaType(@QueryParam("mt") String mt) {
+ HashMap<String, String> hm = new HashMap<String, String>();
+ hm.put("foo", "bar");
+ return Response.ok(hm).type(mt).build();
+ }
+
+ @Path("throwsexception")
+ @POST
+ public Response throwsException(@QueryParam("mt") String mt) {
+ return Response.ok("something").type(mt).build();
+ }
+}
Copied: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/webapp/WEB-INF/geronimo-web.xml (from r801788, incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/webapp/WEB-INF/geronimo-web.xml)
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/webapp/WEB-INF/geronimo-web.xml?p2=incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/webapp/WEB-INF/geronimo-web.xml&p1=incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/webapp/WEB-INF/geronimo-web.xml&r1=801788&r2=801869&rev=801869&view=diff
==============================================================================
(empty)
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/webapp/WEB-INF/web.xml?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/webapp/WEB-INF/web.xml (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/webapp/WEB-INF/web.xml Fri Aug 7 03:10:22 2009
@@ -0,0 +1,195 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+<!DOCTYPE web-app PUBLIC
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd" >
+
+<web-app>
+ <display-name>Archetype Created Web Application</display-name>
+ <servlet>
+ <servlet-name>MessageBodyReaders</servlet-name>
+ <servlet-class>${wink.rest.servlet}</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.apache.wink.itest.readers.Application</param-value>
+ </init-param>
+ <init-param>
+ <param-name>requestProcessorAttribute</param-name>
+ <param-value>requestProcessorAttribute_3</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet>
+ <servlet-name>MessageBodyReaderExceptions</servlet-name>
+ <servlet-class>${wink.rest.servlet}</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.apache.wink.itest.readerexceptions.Application</param-value>
+ </init-param>
+ <init-param>
+ <param-name>requestProcessorAttribute</param-name>
+ <param-value>requestProcessorAttribute_2</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet>
+ <servlet-name>MessageBodyWriters</servlet-name>
+ <servlet-class>${wink.rest.servlet}</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.apache.wink.itest.writers.Application</param-value>
+ </init-param>
+ <init-param>
+ <param-name>requestProcessorAttribute</param-name>
+ <param-value>requestProcessorAttribute_4</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet>
+ <servlet-name>MessageBodyWriterExceptions</servlet-name>
+ <servlet-class>${wink.rest.servlet}</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.apache.wink.itest.writerexceptions.Application</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet>
+ <servlet-name>StandardEntityProviders</servlet-name>
+ <servlet-class>${wink.rest.servlet}</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.apache.wink.itest.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>
+ <servlet-name>ExceptionMapperMappedProviders</servlet-name>
+ <servlet-class>${wink.rest.servlet}</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.apache.wink.itest.exceptionmappers.mapped.GuestbookApplication</param-value>
+ </init-param>
+ <init-param>
+ <param-name>requestProcessorAttribute</param-name>
+ <param-value>requestProcessorAttribute_exceptionmappers</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet>
+ <servlet-name>ExceptionMapperNoMapper</servlet-name>
+ <servlet-class>${wink.rest.servlet}</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.apache.wink.itest.exceptionmappers.nomapper.GuestbookApplication</param-value>
+ </init-param>
+ <init-param>
+ <param-name>requestProcessorAttribute</param-name>
+ <param-value>requestProcessorAttribute_noexceptionmappers</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet>
+ <servlet-name>ExceptionMapperNull</servlet-name>
+ <servlet-class>${wink.rest.servlet}</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.apache.wink.itest.exceptionmappers.nullconditions.Application</param-value>
+ </init-param>
+ <init-param>
+ <param-name>requestProcessorAttribute</param-name>
+ <param-value>requestProcessorAttribute_nullconditions</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet>
+ <servlet-name>SubresourceExceptions</servlet-name>
+ <servlet-class>${wink.rest.servlet}</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.apache.wink.itest.subresource.Application</param-value>
+ </init-param>
+ <init-param>
+ <param-name>requestProcessorAttribute</param-name>
+ <param-value>requestProcessorAttribute_subresourceexceptions</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet>
+ <servlet-name>SimpleContestResolver</servlet-name>
+ <servlet-class>${wink.rest.servlet}</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.apache.wink.itest.contextresolver.Application</param-value>
+ </init-param>
+ <init-param>
+ <param-name>requestProcessorAttribute</param-name>
+ <param-value>requestProcessorAttribute_simplecontextresolver</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>MessageBodyReaders</servlet-name>
+ <url-pattern>/readers/*</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>MessageBodyReaderExceptions</servlet-name>
+ <url-pattern>/readerexceptions/*</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>MessageBodyWriters</servlet-name>
+ <url-pattern>/writers/*</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <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>
+ <servlet-mapping>
+ <servlet-name>ExceptionMapperMappedProviders</servlet-name>
+ <url-pattern>/exceptionsmapped/*</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>ExceptionMapperNoMapper</servlet-name>
+ <url-pattern>/exceptionsnomapper/*</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>ExceptionMapperNull</servlet-name>
+ <url-pattern>/exceptionsnull/*</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>SubresourceExceptions</servlet-name>
+ <url-pattern>/subresourceexceptions/*</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>SimpleContestResolver</servlet-name>
+ <url-pattern>/simplecontextresolver/*</url-pattern>
+ </servlet-mapping>
+
+</web-app>
Copied: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/webapp/index.jsp (from r801788, incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/webapp/index.jsp)
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/webapp/index.jsp?p2=incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/main/webapp/index.jsp&p1=incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-test-providers/src/main/webapp/index.jsp&r1=801788&r2=801869&rev=801869&view=diff
==============================================================================
(empty)
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/test/java/org/apache/wink/itest/contextresolver/ContextTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/test/java/org/apache/wink/itest/contextresolver/ContextTest.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/test/java/org/apache/wink/itest/contextresolver/ContextTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/test/java/org/apache/wink/itest/contextresolver/ContextTest.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.wink.itest.contextresolver;
+
+import java.io.StringWriter;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.wink.itest.contextresolver.User;
+import org.apache.wink.itest.contextresolver.jaxb.ObjectFactory;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+public class ContextTest extends TestCase {
+
+ final private static String USER_URI = getBaseURI() + "/simplecontextresolver/user";
+
+ public static String getBaseURI() {
+ return ServerEnvironmentInfo.getBaseURI();
+ }
+
+ public void testUserContextProvider() throws Exception {
+ HttpClient httpClient = new HttpClient();
+
+ User user = new User();
+ user.setUserName("joedoe@example.com");
+ JAXBElement<User> element =
+ new JAXBElement<User>(new QName("http://jaxb.context.tests", "user"), User.class, user);
+ JAXBContext context = JAXBContext.newInstance(ObjectFactory.class);
+ StringWriter sw = new StringWriter();
+ Marshaller m = context.createMarshaller();
+ m.marshal(element, sw);
+ PostMethod postMethod = new PostMethod(USER_URI);
+ try {
+ postMethod.setRequestEntity(new ByteArrayRequestEntity(sw.toString().getBytes(),
+ "text/xml"));
+ httpClient.executeMethod(postMethod);
+ assertEquals(204, postMethod.getStatusCode());
+ } finally {
+ postMethod.releaseConnection();
+ }
+
+ GetMethod getMethod = new GetMethod(USER_URI + "/joedoe@example.com");
+ try {
+ httpClient.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ Unmarshaller u = context.createUnmarshaller();
+ element =
+ u.unmarshal(new StreamSource(getMethod.getResponseBodyAsStream()), User.class);
+ assertNotNull(element);
+ user = element.getValue();
+ assertNotNull(user);
+ assertEquals("joedoe@example.com", user.getUserName());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/test/java/org/apache/wink/itest/contextresolver/DepartmentTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/test/java/org/apache/wink/itest/contextresolver/DepartmentTest.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/test/java/org/apache/wink/itest/contextresolver/DepartmentTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/test/java/org/apache/wink/itest/contextresolver/DepartmentTest.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.wink.itest.contextresolver;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.util.List;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
+import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.HeadMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.RequestEntity;
+import org.apache.wink.itest.contextresolver.Department;
+import org.apache.wink.itest.contextresolver.DepartmentDatabase;
+import org.apache.wink.itest.contextresolver.DepartmentListWrapper;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+public class DepartmentTest extends TestCase {
+
+ public static String getBaseURI() {
+ return ServerEnvironmentInfo.getBaseURI() + "/simplecontextresolver/departments";
+ }
+
+ /**
+ * This will drive several different requests that interact with the
+ * Departments resource class.
+ */
+ public void testDepartmentsResourceJAXB() throws Exception {
+ PostMethod postMethod = null;
+ GetMethod getAllMethod = null;
+ GetMethod getOneMethod = null;
+ HeadMethod headMethod = null;
+ DeleteMethod deleteMethod = null;
+ try {
+
+ // make sure everything is clear before testing
+ DepartmentDatabase.clearEntries();
+
+ // create a new Department
+ Department newDepartment = new Department();
+ newDepartment.setDepartmentId("1");
+ newDepartment.setDepartmentName("Marketing");
+ JAXBContext context =
+ JAXBContext.newInstance(new Class<?>[] {Department.class,
+ DepartmentListWrapper.class});
+ Marshaller marshaller = context.createMarshaller();
+ StringWriter sw = new StringWriter();
+ marshaller.marshal(newDepartment, sw);
+ HttpClient client = new HttpClient();
+ postMethod = new PostMethod(getBaseURI());
+ RequestEntity reqEntity =
+ new ByteArrayRequestEntity(sw.toString().getBytes(), "text/xml");
+ postMethod.setRequestEntity(reqEntity);
+ client.executeMethod(postMethod);
+
+ newDepartment = new Department();
+ newDepartment.setDepartmentId("2");
+ newDepartment.setDepartmentName("Sales");
+ sw = new StringWriter();
+ marshaller.marshal(newDepartment, sw);
+ client = new HttpClient();
+ postMethod = new PostMethod(getBaseURI());
+ reqEntity = new ByteArrayRequestEntity(sw.toString().getBytes(), "text/xml");
+ postMethod.setRequestEntity(reqEntity);
+ client.executeMethod(postMethod);
+
+ // now let's get the list of Departments that we just created
+ // (should be 2)
+ client = new HttpClient();
+ getAllMethod = new GetMethod(getBaseURI());
+ client.executeMethod(getAllMethod);
+ byte[] bytes = getAllMethod.getResponseBody();
+ assertNotNull(bytes);
+ InputStream bais = new ByteArrayInputStream(bytes);
+ Unmarshaller unmarshaller = context.createUnmarshaller();
+ Object obj = unmarshaller.unmarshal(bais);
+ assertTrue(obj instanceof DepartmentListWrapper);
+ DepartmentListWrapper wrapper = (DepartmentListWrapper)obj;
+ List<Department> dptList = wrapper.getDepartmentList();
+ assertNotNull(dptList);
+ assertEquals(2, dptList.size());
+
+ // now get a specific Department that was created
+ client = new HttpClient();
+ getOneMethod = new GetMethod(getBaseURI() + "/1");
+ client.executeMethod(getOneMethod);
+ bytes = getOneMethod.getResponseBody();
+ assertNotNull(bytes);
+ bais = new ByteArrayInputStream(bytes);
+ obj = unmarshaller.unmarshal(bais);
+ assertTrue(obj instanceof Department);
+ Department dept = (Department)obj;
+ assertEquals("1", dept.getDepartmentId());
+ assertEquals("Marketing", dept.getDepartmentName());
+
+ // let's send a Head request for both an existent and non-existent
+ // resource
+ // we are testing to see if header values being set in the resource
+ // implementation
+ // are sent back appropriately
+ client = new HttpClient();
+ headMethod = new HeadMethod(getBaseURI() + "/3");
+ client.executeMethod(headMethod);
+ assertNotNull(headMethod.getResponseHeaders());
+ Header header = headMethod.getResponseHeader("unresolved-id");
+ assertNotNull(header);
+ assertEquals("3", header.getValue());
+ headMethod.releaseConnection();
+
+ // now the resource that should exist
+ headMethod = new HeadMethod(getBaseURI() + "/1");
+ client.executeMethod(headMethod);
+ assertNotNull(headMethod.getResponseHeaders());
+ header = headMethod.getResponseHeader("resolved-id");
+ assertNotNull(header);
+ assertEquals("1", header.getValue());
+
+ deleteMethod = new DeleteMethod(getBaseURI() + "/1");
+ client.executeMethod(deleteMethod);
+ assertEquals(204, deleteMethod.getStatusCode());
+
+ deleteMethod = new DeleteMethod(getBaseURI() + "/2");
+ client.executeMethod(deleteMethod);
+ assertEquals(204, deleteMethod.getStatusCode());
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ } finally {
+ if (postMethod != null) {
+ postMethod.releaseConnection();
+ }
+ if (getAllMethod != null) {
+ getAllMethod.releaseConnection();
+ }
+ if (getOneMethod != null) {
+ getOneMethod.releaseConnection();
+ }
+ if (headMethod != null) {
+ headMethod.releaseConnection();
+ }
+ if (deleteMethod != null) {
+ deleteMethod.releaseConnection();
+ }
+ }
+ }
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/test/java/org/apache/wink/itest/exceptionmappers/JAXRSExceptionsMappedProvidersTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/test/java/org/apache/wink/itest/exceptionmappers/JAXRSExceptionsMappedProvidersTest.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/test/java/org/apache/wink/itest/exceptionmappers/JAXRSExceptionsMappedProvidersTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/test/java/org/apache/wink/itest/exceptionmappers/JAXRSExceptionsMappedProvidersTest.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,257 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.wink.itest.exceptionmappers;
+
+import javax.ws.rs.core.Response.Status;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.wink.test.integration.ServerContainerAssertions;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+public class JAXRSExceptionsMappedProvidersTest extends TestCase {
+
+ public String getBaseURI() {
+ return ServerEnvironmentInfo.getBaseURI() + "/exceptionsmapped" + "/guestbookmapped";
+ }
+
+ /**
+ * Test the positive workflow where a comment with a message and author is
+ * successfully posted to the Guestbook.
+ *
+ * @throws Exception
+ */
+ public void testRegularWorkflow() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<comment><message>Hello World!</message><author>Anonymous</author></comment>",
+ "text/xml", null));
+ client.executeMethod(postMethod);
+ assertEquals(201, postMethod.getStatusCode());
+ String newPostURILocation = postMethod.getResponseHeader("Location").getValue();
+
+ GetMethod getMethod = new GetMethod(newPostURILocation);
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><comment><author>Anonymous</author><id>1</id><message>Hello World!</message></comment>",
+ getMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Tests a method that throws an emptily constructed
+ * <code>WebApplicationException</code>.
+ *
+ * @throws Exception
+ */
+ public void testWebApplicationExceptionDefaultMappedProvider() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod
+ .setRequestEntity(new StringRequestEntity("<comment></comment>", "text/xml", null));
+ client.executeMethod(postMethod);
+ assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), postMethod.getStatusCode());
+ assertEquals(getBaseURI(), postMethod.getResponseHeader("ExceptionPage").getValue());
+ ServerContainerAssertions.assertExceptionBodyFromServer(500, postMethod
+ .getResponseBodyAsString());
+ }
+
+ /**
+ * Tests a method that throws a <code>WebApplicationException</code> with an
+ * integer status code.
+ *
+ * @throws Exception
+ */
+ public void testWebApplicationExceptionStatusCodeSetMappedProvider() throws Exception {
+ HttpClient client = new HttpClient();
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<comment><message>Suppose to fail with missing author.</message></comment>",
+ "text/xml", null));
+ client.executeMethod(postMethod);
+ assertEquals(497, postMethod.getStatusCode());
+ assertEquals(getBaseURI(), postMethod.getResponseHeader("ExceptionPage").getValue());
+ ServerContainerAssertions.assertExceptionBodyFromServer(497, postMethod
+ .getResponseBodyAsString());
+
+ }
+
+ /**
+ * Tests a method that throws a <code>WebApplicationException</code> with a
+ * Response.Status set.
+ *
+ * @throws Exception
+ */
+ public void testWebApplicationExceptionResponseStatusSetMappedProvider() throws Exception {
+ HttpClient client = new HttpClient();
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod.setRequestEntity(new StringRequestEntity("", "text/xml", null));
+ client.executeMethod(postMethod);
+ assertEquals(496, postMethod.getStatusCode());
+ assertEquals(getBaseURI(), postMethod.getResponseHeader("ExceptionPage").getValue());
+ ServerContainerAssertions.assertExceptionBodyFromServer(496, postMethod
+ .getResponseBodyAsString());
+ }
+
+ /**
+ * Tests a method that throws a <code>WebApplicationException</code> with a
+ * Response with an entity (which will not get mapped via an exception
+ * mapper).
+ *
+ * @throws Exception
+ */
+ public void testWebApplicationExceptionResponseWithEntitySetMappedProvider() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<comment><author>Anonymous</author></comment>",
+ "text/xml", null));
+ client.executeMethod(postMethod);
+ assertEquals(400, postMethod.getStatusCode());
+ assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><commenterror><message>Missing the message in the comment.</message></commenterror>",
+ postMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Tests a method that throws a <code>WebApplicationException</code> with a
+ * Response with no entity (which will not get mapped via an exception
+ * mapper).
+ *
+ * @throws Exception
+ */
+ public void testWebApplicationExceptionResponseWithNoEntitySetMappedProvider() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<comment><message>throwemptywebappexception</message><author>Anonymous</author></comment>",
+ "text/xml", null));
+ client.executeMethod(postMethod);
+ assertEquals(491, postMethod.getStatusCode());
+ assertEquals("Some message", postMethod
+ .getResponseHeader("throwemptyentitywebappexception").getValue());
+ assertEquals(getBaseURI(), postMethod.getResponseHeader("ExceptionPage").getValue());
+ assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><commenterror><message>WebApplicationExceptionMapProvider set message</message></commenterror>",
+ postMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Tests a method that throws a subclass of
+ * <code>WebApplicationException</code> with a Response.
+ *
+ * @throws Exception
+ */
+ public void testCustomWebApplicationExceptionMappedProvider() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<comment><message></message><author></author></comment>",
+ "text/xml", null));
+ client.executeMethod(postMethod);
+ assertEquals(498, postMethod.getStatusCode());
+ assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><commenterror><message>Cannot post an invalid message.</message></commenterror>",
+ postMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Tests a method that throws a runtime exception.
+ *
+ * @throws Exception
+ */
+ public void testRuntimeExceptionMappedProvider() throws Exception {
+ HttpClient client = new HttpClient();
+
+ /*
+ * abcd is an invalid ID so a NumberFormatException will be thrown in
+ * the resource
+ */
+ DeleteMethod postMethod = new DeleteMethod(getBaseURI() + "/abcd");
+ client.executeMethod(postMethod);
+ assertEquals(450, postMethod.getStatusCode());
+ String responseBody = postMethod.getResponseBodyAsString();
+ assertTrue(responseBody,
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><commenterror><message>For input string: \"abcd\"</message></commenterror>"
+ .equals(responseBody) || "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><commenterror><message>For input string: "abcd"</message></commenterror>"
+ .equals(responseBody));
+ }
+
+ /**
+ * Tests a method that throws a NullPointerException inside a called method.
+ *
+ * @throws Exception
+ */
+ public void testNullPointerExceptionMappedProvider() throws Exception {
+ HttpClient client = new HttpClient();
+
+ DeleteMethod postMethod = new DeleteMethod(getBaseURI() + "/10000");
+ client.executeMethod(postMethod);
+ assertEquals(451, postMethod.getStatusCode());
+ assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><commenterror><message>The comment did not previously exist.</message></commenterror>",
+ postMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Tests a method that throws an error.
+ *
+ * @throws Exception
+ */
+ public void testErrorMappedProvider() throws Exception {
+ HttpClient client = new HttpClient();
+
+ DeleteMethod postMethod = new DeleteMethod(getBaseURI() + "/-99999");
+ client.executeMethod(postMethod);
+ assertEquals(453, postMethod.getStatusCode());
+ assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><commenterror><message>Simulated error</message></commenterror>",
+ postMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Tests a method that throws a checked exception.
+ *
+ * @throws Exception
+ */
+ public void testCheckExceptionMappedProvider() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PutMethod putMethod = new PutMethod(getBaseURI() + "/-99999");
+ putMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<comment><id></id><message></message><author></author></comment>",
+ "text/xml", null));
+ client.executeMethod(putMethod);
+ assertEquals(454, putMethod.getStatusCode());
+ assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><commenterror><message>Unexpected ID.</message></commenterror>",
+ putMethod.getResponseBodyAsString());
+ }
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/test/java/org/apache/wink/itest/exceptionmappers/JAXRSExceptionsNoMapperTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/test/java/org/apache/wink/itest/exceptionmappers/JAXRSExceptionsNoMapperTest.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/test/java/org/apache/wink/itest/exceptionmappers/JAXRSExceptionsNoMapperTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/test/java/org/apache/wink/itest/exceptionmappers/JAXRSExceptionsNoMapperTest.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,230 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.wink.itest.exceptionmappers;
+
+import javax.ws.rs.core.Response.Status;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.wink.test.integration.ServerContainerAssertions;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+/**
+ * Tests exception throwing without any exception mapping providers.
+ */
+public class JAXRSExceptionsNoMapperTest extends TestCase {
+
+ public String getBaseURI() {
+ return ServerEnvironmentInfo.getBaseURI() + "/exceptionsnomapper" + "/guestbooknomap";
+ }
+
+ /**
+ * Test the positive workflow where a comment with a message and author is
+ * successfully posted to the Guestbook.
+ *
+ * @throws Exception
+ */
+ public void testRegularWorkflow() throws Exception {
+ /* FIXME: this is not a repeatable test */
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<comment><message>Hello World!</message><author>Anonymous</author></comment>",
+ "text/xml", null));
+ client.executeMethod(postMethod);
+ assertEquals(201, postMethod.getStatusCode());
+ String newPostURILocation = postMethod.getResponseHeader("Location").getValue();
+
+ GetMethod getMethod = new GetMethod(newPostURILocation);
+ client.executeMethod(getMethod);
+ assertEquals(200, getMethod.getStatusCode());
+ assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><comment><author>Anonymous</author><id>1</id><message>Hello World!</message></comment>",
+ getMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Tests a method that throws an emptily constructed
+ * <code>WebApplicationException</code>.
+ *
+ * @throws Exception
+ */
+ public void testWebApplicationExceptionDefaultNoMappingProvider() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod
+ .setRequestEntity(new StringRequestEntity("<comment></comment>", "text/xml", null));
+ client.executeMethod(postMethod);
+ assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), postMethod.getStatusCode());
+ ServerContainerAssertions.assertExceptionBodyFromServer(500, postMethod
+ .getResponseBodyAsString());
+ }
+
+ /**
+ * Tests a method that throws a <code>WebApplicationException</code> with an
+ * integer status code.
+ *
+ * @throws Exception
+ */
+ public void testWebApplicationExceptionStatusCodeSetNoMappingProvider() throws Exception {
+ HttpClient client = new HttpClient();
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<comment><message>Suppose to fail with missing author.</message></comment>",
+ "text/xml", null));
+ client.executeMethod(postMethod);
+ assertEquals(499, postMethod.getStatusCode());
+ ServerContainerAssertions.assertExceptionBodyFromServer(499, postMethod
+ .getResponseBodyAsString());
+
+ }
+
+ /**
+ * Tests a method that throws a <code>WebApplicationException</code> with a
+ * Response.Status set.
+ *
+ * @throws Exception
+ */
+ public void testWebApplicationExceptionResponseStatusSetNoMappingProvider() throws Exception {
+ HttpClient client = new HttpClient();
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod.setRequestEntity(new StringRequestEntity("", "text/xml", null));
+ client.executeMethod(postMethod);
+ assertEquals(Status.BAD_REQUEST.getStatusCode(), postMethod.getStatusCode());
+ ServerContainerAssertions.assertExceptionBodyFromServer(400, postMethod
+ .getResponseBodyAsString());
+
+ }
+
+ /**
+ * Tests a method that throws a <code>WebApplicationException</code> with a
+ * Response.
+ *
+ * @throws Exception
+ */
+ public void testWebApplicationExceptionResponseSetNoMappingProvider() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<comment><author>Anonymous</author></comment>",
+ "text/xml", null));
+ client.executeMethod(postMethod);
+ assertEquals(Status.BAD_REQUEST.getStatusCode(), postMethod.getStatusCode());
+ assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><commenterror><message>Missing the message in the comment.</message></commenterror>",
+ postMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Tests a method that throws a subclass of
+ * <code>WebApplicationException</code> with a Response.
+ *
+ * @throws Exception
+ */
+ public void testCustomWebApplicationExceptionNoMappingProvider() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI());
+ postMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<comment><message></message><author></author></comment>",
+ "text/xml", null));
+ client.executeMethod(postMethod);
+ assertEquals(498, postMethod.getStatusCode());
+ assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><commenterror><message>Cannot post an invalid message.</message></commenterror>",
+ postMethod.getResponseBodyAsString());
+ }
+
+ /**
+ * Tests a method that throws a runtime exception.
+ *
+ * @throws Exception
+ */
+ public void testRuntimeExceptionNoMappingProvider() throws Exception {
+ HttpClient client = new HttpClient();
+
+ /*
+ * abcd is an invalid ID so a NumberFormatException will be thrown in
+ * the resource
+ */
+ DeleteMethod postMethod = new DeleteMethod(getBaseURI() + "/abcd");
+ client.executeMethod(postMethod);
+ assertEquals(500, postMethod.getStatusCode());
+
+ // assertLogContainsException("java.lang.NumberFormatException: For input string: \"abcd\"");
+ }
+
+ /**
+ * Tests a method that throws a NullPointerException inside a called method.
+ *
+ * @throws Exception
+ */
+ public void testNullPointerExceptionNoMappingProvider() throws Exception {
+ HttpClient client = new HttpClient();
+
+ DeleteMethod postMethod = new DeleteMethod(getBaseURI() + "/10000");
+ client.executeMethod(postMethod);
+ assertEquals(500, postMethod.getStatusCode());
+
+ // assertLogContainsException("java.lang.NullPointerException: The comment did not previously exist.");
+ }
+
+ /**
+ * Tests a method that throws an error.
+ *
+ * @throws Exception
+ */
+ public void testErrorNoMappingProvider() throws Exception {
+ HttpClient client = new HttpClient();
+
+ DeleteMethod postMethod = new DeleteMethod(getBaseURI() + "/-99999");
+ client.executeMethod(postMethod);
+ assertEquals(500, postMethod.getStatusCode());
+ // assertLogContainsException("java.lang.Error: Simulated error");
+ }
+
+ /**
+ * Tests a method that throws a checked exception.
+ *
+ * @throws Exception
+ */
+ public void testCheckExceptionNoMappingProvider() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PutMethod putMethod = new PutMethod(getBaseURI() + "/-99999");
+ putMethod
+ .setRequestEntity(new StringRequestEntity(
+ "<comment><id></id><message></message><author></author></comment>",
+ "text/xml", null));
+ client.executeMethod(putMethod);
+ assertEquals(500, putMethod.getStatusCode());
+ // assertLogContainsException("jaxrs.tests.exceptions.nomapping.server.GuestbookException: Unexpected ID.");
+ }
+}
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/test/java/org/apache/wink/itest/exceptionmappers/JAXRSExceptionsNullConditionsTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/test/java/org/apache/wink/itest/exceptionmappers/JAXRSExceptionsNullConditionsTest.java?rev=801869&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/test/java/org/apache/wink/itest/exceptionmappers/JAXRSExceptionsNullConditionsTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-providers/src/test/java/org/apache/wink/itest/exceptionmappers/JAXRSExceptionsNullConditionsTest.java Fri Aug 7 03:10:22 2009
@@ -0,0 +1,242 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.wink.itest.exceptionmappers;
+
+import javax.ws.rs.core.Response;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.wink.test.integration.ServerContainerAssertions;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+/**
+ * Tests various default null conditions and error paths when exceptions are
+ * thrown in resource methods.
+ */
+public class JAXRSExceptionsNullConditionsTest extends TestCase {
+
+ public String getBaseURI() {
+ return ServerEnvironmentInfo.getBaseURI() + "/exceptionsnull" + "/guestbooknullconditions";
+ }
+
+ /**
+ * Tests that an empty constructor constructed
+ * <code>WebApplicationException</code> will return status 500 and no
+ * response body by default.
+ *
+ * @throws Exception
+ */
+ public void testEmptyWebException() throws Exception {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod = new GetMethod(getBaseURI() + "/emptywebappexception");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(500, getMethod.getStatusCode());
+ ServerContainerAssertions.assertExceptionBodyFromServer(500, getMethod
+ .getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a <code>WebApplicationException</code> constructed with a
+ * cause will return status 500 and no response body by default.
+ *
+ * @throws Exception
+ */
+ public void testWebExceptionWithCause() throws Exception {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod = new GetMethod(getBaseURI() + "/webappexceptionwithcause");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(500, getMethod.getStatusCode());
+ ServerContainerAssertions.assertExceptionBodyFromServer(500, getMethod
+ .getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a <code>WebApplicationException</code> constructed with a
+ * cause and status will return status and no response body by default.
+ *
+ * @throws Exception
+ */
+ public void testWebExceptionWithCauseAndStatus() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI() + "/webappexceptionwithcauseandstatus");
+ try {
+ client.executeMethod(postMethod);
+ assertEquals(499, postMethod.getStatusCode());
+ ServerContainerAssertions.assertExceptionBodyFromServer(499, postMethod
+ .getResponseBodyAsString());
+ } finally {
+ postMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a <code>WebApplicationException</code> constructed with a
+ * cause and response will return the Response entity by default.
+ *
+ * @throws Exception
+ */
+ public void testWebExceptionWithCauseAndResponse() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PutMethod putMethod = new PutMethod(getBaseURI() + "/webappexceptionwithcauseandresponse");
+ try {
+ client.executeMethod(putMethod);
+ assertEquals(Response.Status.NOT_ACCEPTABLE.getStatusCode(), putMethod.getStatusCode());
+ assertEquals("Entity inside response", putMethod.getResponseBodyAsString());
+ } finally {
+ putMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a <code>WebApplicationException</code> constructed with a
+ * cause and response status will return the response status and empty
+ * response body by default.
+ *
+ * @throws Exception
+ */
+ public void testWebExceptionWithCauseAndResponseStatus() throws Exception {
+ HttpClient client = new HttpClient();
+
+ DeleteMethod deleteMethod =
+ new DeleteMethod(getBaseURI() + "/webappexceptionwithcauseandresponsestatus");
+ try {
+ client.executeMethod(deleteMethod);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), deleteMethod.getStatusCode());
+ ServerContainerAssertions.assertExceptionBodyFromServer(400, deleteMethod
+ .getResponseBodyAsString());
+ } finally {
+ deleteMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a <code>ExceptionMapper</code> that returns null should see a
+ * HTTP 204 status.
+ *
+ * @throws Exception
+ */
+ public void testExceptionMapperReturnNull() throws Exception {
+ HttpClient client = new HttpClient();
+
+ GetMethod getMethod = new GetMethod(getBaseURI() + "/exceptionmappernull");
+ try {
+ client.executeMethod(getMethod);
+ assertEquals(Response.Status.NO_CONTENT.getStatusCode(), getMethod.getStatusCode());
+ assertEquals(null, getMethod.getResponseBodyAsString());
+ } finally {
+ getMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a <code>ExceptionMapper</code> that throws an exception or
+ * error should see a HTTP 500 status error and empty response.
+ *
+ * @throws Exception
+ */
+ public void testExceptionMapperThrowsException() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI() + "/exceptionmapperthrowsexception");
+ try {
+ client.executeMethod(postMethod);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), postMethod
+ .getStatusCode());
+ ServerContainerAssertions.assertExceptionBodyFromServer(500, postMethod
+ .getResponseBodyAsString());
+ } finally {
+ postMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a <code>ExceptionMapper</code> that throws an error should see
+ * a HTTP 500 status error and unknown response.
+ *
+ * @throws Exception
+ */
+ public void testExceptionMapperThrowsError() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PostMethod postMethod = new PostMethod(getBaseURI() + "/exceptionmapperthrowserror");
+ try {
+ client.executeMethod(postMethod);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), postMethod
+ .getStatusCode());
+ } finally {
+ postMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a <code>ExceptionMapper</code> can catch a generic Throwable.
+ *
+ * @throws Exception
+ */
+ public void testExceptionMapperForSpecificThrowable() throws Exception {
+ HttpClient client = new HttpClient();
+
+ PutMethod putMethod = new PutMethod(getBaseURI() + "/throwableexceptionmapper");
+ try {
+ client.executeMethod(putMethod);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), putMethod
+ .getStatusCode());
+ assertEquals("Throwable mapper used", putMethod.getResponseBodyAsString());
+ } finally {
+ putMethod.releaseConnection();
+ }
+ }
+
+ /**
+ * Tests that a Throwable can propagate throughout the code.
+ *
+ * @throws Exception
+ */
+ public void testThrowableCanBeThrown() throws Exception {
+ HttpClient client = new HttpClient();
+
+ DeleteMethod deleteMethod = new DeleteMethod(getBaseURI() + "/throwsthrowable");
+ try {
+ client.executeMethod(deleteMethod);
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), deleteMethod
+ .getStatusCode());
+ // assertLogContainsException("jaxrs.tests.exceptions.nullconditions.server.GuestbookResource$1: Throwable was thrown");
+ } finally {
+ deleteMethod.releaseConnection();
+ }
+ }
+}