incubator-wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ngalla...@apache.org
Subject svn commit: r787553 [14/34] - in /incubator/wink/contrib/ibm-jaxrs/tests: ./ fvt/ fvt/demo/ fvt/demo/jaxrs/ fvt/demo/jaxrs/cache/ fvt/demo/jaxrs/cache/server/ fvt/demo/jaxrs/cache/test/ fvt/demo/jaxrs/datasource/ fvt/demo/jaxrs/datasource/server/ fvt/d...
Date Tue, 23 Jun 2009 05:38:19 GMT
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nomapping/test/ExceptionsNoMappingTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nomapping/test/ExceptionsNoMappingTest.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nomapping/test/ExceptionsNoMappingTest.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nomapping/test/ExceptionsNoMappingTest.java Tue Jun 23 05:37:57 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 jaxrs.tests.exceptions.nomapping.test;
+
+import javax.ws.rs.core.Response.Status;
+
+import junit.framework.Test;
+
+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 framework.defaults.test.FVTTestCase;
+
+/**
+ * Tests exception throwing without any exception mapping providers.
+ */
+public class ExceptionsNoMappingTest extends FVTTestCase {
+
+    public static Test suite() {
+        return FVTTestCase
+                .getTestSuite(
+                        ExceptionsNoMappingTest.class,
+                        jaxrs.tests.exceptions.nomapping.server.GuestbookApplication.class
+                                .getName());
+    }
+
+    public String getBaseURI() {
+        return super.getBaseURI() + "/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());
+        assertEquals("", 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());
+        assertEquals("", 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());
+        assertEquals("", 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/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/buildTest.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/buildTest.xml?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/buildTest.xml (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/buildTest.xml Tue Jun 23 05:37:57 2009
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements. See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership. The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License. You may obtain a copy of the License at
+  ~
+  ~ http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied. See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<project name="jaxrs.tests.exceptions.nullconditions" default="all">
+	<import file="../../../../buildCommon.xml" />
+</project>

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/Application.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/Application.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/Application.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/Application.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,38 @@
+/*
+ * 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 jaxrs.tests.exceptions.nullconditions.server;
+
+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(GuestbookNullExceptionMapper.class);
+        clazzes.add(GuestbookResource.class);
+        clazzes.add(GuestbookThrowExceptionMapper.class);
+        clazzes.add(GuestbookRuntimeExceptionMapper.class);
+        clazzes.add(GuestbookThrowableMapper.class);
+        return clazzes;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookException.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookException.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookException.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookException.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,41 @@
+/*
+ * 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 jaxrs.tests.exceptions.nullconditions.server;
+
+public class GuestbookException extends Exception {
+
+    private static final long serialVersionUID = -6902290168001222679L;
+
+    public GuestbookException() {
+        super();
+    }
+
+    public GuestbookException(String message) {
+        super(message);
+    }
+
+    public GuestbookException(Throwable cause) {
+        super(cause);
+    }
+
+    public GuestbookException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookNullException.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookNullException.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookNullException.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookNullException.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,41 @@
+/*
+ * 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 jaxrs.tests.exceptions.nullconditions.server;
+
+public class GuestbookNullException extends RuntimeException {
+
+    private static final long serialVersionUID = 1L;
+
+    public GuestbookNullException() {
+        super();
+    }
+
+    public GuestbookNullException(String message) {
+        super(message);
+    }
+
+    public GuestbookNullException(Throwable cause) {
+        super(cause);
+    }
+
+    public GuestbookNullException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookNullExceptionMapper.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookNullExceptionMapper.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookNullExceptionMapper.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookNullExceptionMapper.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,34 @@
+/*
+ * 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 jaxrs.tests.exceptions.nullconditions.server;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+public class GuestbookNullExceptionMapper implements ExceptionMapper<GuestbookNullException> {
+
+    public Response toResponse(GuestbookNullException arg0) {
+        /* intentionally return null */
+        return null;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookResource.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookResource.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookResource.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,104 @@
+/*
+ * 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 jaxrs.tests.exceptions.nullconditions.server;
+
+import javax.ws.rs.DELETE;
+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.Response.Status;
+
+@Path("guestbooknullconditions")
+public class GuestbookResource {
+
+    @GET
+    @Path("emptywebappexception")
+    public String exception() {
+        throw new WebApplicationException();
+    }
+
+    @GET
+    @Path("webappexceptionwithcause")
+    public String exceptionWithCause() {
+        throw new WebApplicationException(new GuestbookException(
+                "Threw checked exception"));
+    }
+
+    @POST
+    @Path("webappexceptionwithcauseandstatus")
+    public String exceptionWithCauseAndStatus() {
+        throw new WebApplicationException(new GuestbookException(
+                "Threw checked exception"), 499);
+    }
+
+    @PUT
+    @Path("webappexceptionwithcauseandresponse")
+    public String exceptionWithCauseAndResponse() {
+        Response resp = Response.status(Status.NOT_ACCEPTABLE).entity(
+                "Entity inside response").build();
+        throw new WebApplicationException(new GuestbookException(
+                "Threw checked exception"), resp);
+    }
+
+    @DELETE
+    @Path("webappexceptionwithcauseandresponsestatus")
+    public String exceptionWithCauseAndResponseStatus() {
+        throw new WebApplicationException(new GuestbookException(
+                "Threw checked exception"), Response.Status.BAD_REQUEST);
+    }
+
+    @GET
+    @Path("exceptionmappernull")
+    public String exceptionMapperReturnNull() {
+        throw new GuestbookNullException("Should not see me");
+    }
+
+    @POST
+    @Path("exceptionmapperthrowsexception")
+    public String exceptionMapperThrowsException()
+            throws GuestbookThrowException {
+        throw new GuestbookThrowException("Re-throw an exception");
+    }
+
+    @POST
+    @Path("exceptionmapperthrowserror")
+    public String exceptionMapperThrowsError() throws GuestbookThrowException {
+        throw new GuestbookThrowException("Re-throw an error");
+    }
+
+    @PUT
+    @Path("throwableexceptionmapper")
+    public String throwableExceptionMapper() throws GuestbookThrowable {
+        throw new GuestbookThrowable();
+    }
+
+    @DELETE
+    @Path("throwsthrowable")
+    public String throwThrowable() throws Throwable {
+        throw new Throwable("Throwable was thrown") {
+
+            private static final long serialVersionUID = 1L;
+
+        };
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookRuntimeExceptionMapper.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookRuntimeExceptionMapper.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookRuntimeExceptionMapper.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookRuntimeExceptionMapper.java Tue Jun 23 05:37:57 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 jaxrs.tests.exceptions.nullconditions.server;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+
+public class GuestbookRuntimeExceptionMapper implements ExceptionMapper<RuntimeException> {
+
+    public Response toResponse(RuntimeException arg0) {
+        return Response.serverError().entity("RuntimeExceptionMapper was used")
+                .build();
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookThrowException.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookThrowException.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookThrowException.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookThrowException.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,41 @@
+/*
+ * 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 jaxrs.tests.exceptions.nullconditions.server;
+
+public class GuestbookThrowException extends Exception {
+
+    private static final long serialVersionUID = 1L;
+
+    public GuestbookThrowException() {
+        super();
+    }
+
+    public GuestbookThrowException(String message) {
+        super(message);
+    }
+
+    public GuestbookThrowException(Throwable cause) {
+        super(cause);
+    }
+
+    public GuestbookThrowException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookThrowExceptionMapper.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookThrowExceptionMapper.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookThrowExceptionMapper.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookThrowExceptionMapper.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,44 @@
+/*
+ * 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 jaxrs.tests.exceptions.nullconditions.server;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+public class GuestbookThrowExceptionMapper implements ExceptionMapper<GuestbookThrowException> {
+
+    public Response toResponse(GuestbookThrowException arg0) {
+        /*
+         * throwing exception/error in here should cause a HTTP 500 status to
+         * occur
+         */
+
+        if (arg0.getMessage().contains("exception")) {
+            throw new GuestbookNullException();
+        } else {
+            throw new Error("error");
+        }
+
+        // TODO: throw this inside a subresource locator
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookThrowable.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookThrowable.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookThrowable.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookThrowable.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,26 @@
+/*
+ * 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 jaxrs.tests.exceptions.nullconditions.server;
+
+public class GuestbookThrowable extends Throwable {
+
+    private static final long serialVersionUID = 1L;
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookThrowableMapper.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookThrowableMapper.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookThrowableMapper.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/server/GuestbookThrowableMapper.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,33 @@
+/*
+ * 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 jaxrs.tests.exceptions.nullconditions.server;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+public class GuestbookThrowableMapper implements ExceptionMapper<GuestbookThrowable> {
+
+    public Response toResponse(GuestbookThrowable arg0) {
+        return Response.serverError().entity("Throwable mapper used").build();
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/test/ExceptionsNullConditionsTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/test/ExceptionsNullConditionsTest.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/test/ExceptionsNullConditionsTest.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/nullconditions/test/ExceptionsNullConditionsTest.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,270 @@
+/*
+ * 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 jaxrs.tests.exceptions.nullconditions.test;
+
+import javax.ws.rs.core.Response;
+
+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 framework.defaults.test.FVTTestCase;
+
+/**
+ * Tests various default null conditions and error paths when exceptions are
+ * thrown in resource methods.
+ */
+public class ExceptionsNullConditionsTest extends FVTTestCase {
+
+    public static junit.framework.Test suite() {
+        return FVTTestCase.getTestSuite(ExceptionsNullConditionsTest.class,
+                "jaxrs.tests.exceptions.nullconditions.server.Application");
+    }
+
+    @Override
+    public String getBaseURI() {
+        return super.getBaseURI() + "/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());
+            assertEquals("", 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());
+            assertEquals("", 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());
+            assertEquals("", 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());
+            assertEquals("", 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());
+            assertEquals("", 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.
+     *
+     * TODO: Verify this is correct in spec.
+     *
+     * @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());
+            /*
+             * this reply is dependent on the container but should be correct
+             * for Jetty and WebSphere defaults
+             */
+            assertTrue(
+                    postMethod.getResponseBodyAsString(),
+                    (postMethod.getResponseBodyAsString().contains("Error 500") || postMethod
+                            .getResponseBodyAsString().contains(
+                                    "java.lang.Error")));
+        } finally {
+            postMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a <code>ExceptionMapper</code> can catch a generic Throwable.
+     *
+     * TODO: Verify this is correct in spec.
+     *
+     * @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.
+     *
+     * TODO: Verify this is correct in spec.
+     *
+     * @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();
+        }
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/old/buildTest.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/old/buildTest.xml?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/old/buildTest.xml (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/old/buildTest.xml Tue Jun 23 05:37:57 2009
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements. See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership. The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License. You may obtain a copy of the License at
+  ~
+  ~ http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied. See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<project name="jaxrs.tests.exceptions.old" default="all">
+	<import file="../../../../buildCommon.xml" />
+</project>

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/old/server/ExceptionWebAppExceptionResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/old/server/ExceptionWebAppExceptionResource.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/old/server/ExceptionWebAppExceptionResource.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/old/server/ExceptionWebAppExceptionResource.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,62 @@
+/*
+ * 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 jaxrs.tests.exceptions.old.server;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+
+/**
+ * Resource for <code>WebApplicationException</code>.
+ *
+ */
+@Path("exceptions")
+public class ExceptionWebAppExceptionResource {
+
+    @GET
+    public String getThrownExceptionOKResponse() {
+        throw new WebApplicationException(Response.ok().entity(
+                "Exception returns OK").build());
+    }
+
+    @POST
+    public String postThrownExceptionOKResponse() {
+        final Response r = Response.ok().build();
+        throw new WebApplicationException(new Response() {
+            @Override
+            public Object getEntity() {
+                return null;
+            }
+
+            @Override
+            public MultivaluedMap<String, Object> getMetadata() {
+                return r.getMetadata();
+            }
+
+            @Override
+            public int getStatus() {
+                return -1;
+            }
+        });
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/old/server/ExceptionsApplication.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/old/server/ExceptionsApplication.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/old/server/ExceptionsApplication.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/old/server/ExceptionsApplication.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,40 @@
+/*
+ * 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 jaxrs.tests.exceptions.old.server;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+public class ExceptionsApplication extends Application {
+
+    private Set<Class<?>> clazzes = new HashSet<Class<?>>();
+
+    public ExceptionsApplication() {
+        clazzes.add(ExceptionWebAppExceptionResource.class);
+    }
+
+    @Override
+    public Set<Class<?>> getClasses() {
+        return clazzes;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/old/server/WEB-INF/web-no-runtime.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/old/server/WEB-INF/web-no-runtime.xml?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/old/server/WEB-INF/web-no-runtime.xml (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/old/server/WEB-INF/web-no-runtime.xml Tue Jun 23 05:37:57 2009
@@ -0,0 +1,34 @@
+<?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.
+  -->
+
+<web-app id="WebApp_ID" version="2.5"
+	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+	<servlet>
+		<servlet-name>jaxws.tests.exceptions</servlet-name>
+		<servlet-class>jaxrs.tests.exceptions.old.server.ExceptionsApplication</servlet-class>
+		<load-on-startup>1</load-on-startup>
+	</servlet>
+	<servlet-mapping>
+		<servlet-name>jaxws.tests.exceptions</servlet-name>
+		<url-pattern>/*</url-pattern>
+	</servlet-mapping>
+</web-app>
\ No newline at end of file

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/old/server/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/old/server/WEB-INF/web.xml?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/old/server/WEB-INF/web.xml (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/old/server/WEB-INF/web.xml Tue Jun 23 05:37:57 2009
@@ -0,0 +1,38 @@
+<?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.
+  -->
+
+<web-app id="WebApp_ID" version="2.5"
+	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+	<servlet>
+		<servlet-name>jaxws.tests.exceptions</servlet-name>
+		<servlet-class>com.ibm.ws.jaxrs.web.RESTServlet</servlet-class>
+		<init-param>
+			<param-name>javax.ws.rs.Application</param-name>
+			<param-value>jaxrs.tests.exceptions.old.server.ExceptionsApplication</param-value>
+		</init-param>
+		<load-on-startup>1</load-on-startup>
+	</servlet>
+	<servlet-mapping>
+		<servlet-name>jaxws.tests.exceptions</servlet-name>
+		<url-pattern>/*</url-pattern>
+	</servlet-mapping>
+</web-app>
\ No newline at end of file

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/old/test/ExceptionWebAppExceptionTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/old/test/ExceptionWebAppExceptionTest.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/old/test/ExceptionWebAppExceptionTest.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/old/test/ExceptionWebAppExceptionTest.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,111 @@
+/*
+ * 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 jaxrs.tests.exceptions.old.test;
+
+import java.io.IOException;
+
+import jaxrs.tests.exceptions.old.server.ExceptionsApplication;
+import junit.framework.Test;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.URI;
+import org.apache.commons.httpclient.URIException;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+
+import framework.defaults.test.DefaultURIInfo;
+import framework.defaults.test.FVTTestCase;
+
+public class ExceptionWebAppExceptionTest extends FVTTestCase {
+
+    protected HttpClient httpclient = new HttpClient();
+
+    final private static String BASE_URI = DefaultURIInfo
+            .getClassDefaultBaseURI(ExceptionWebAppExceptionTest.class)
+            + "/exceptions";
+
+    public static Test suite() {
+        return FVTTestCase.getTestSuite(ExceptionWebAppExceptionTest.class,
+                ExceptionsApplication.class.getName());
+    }
+
+    /**
+     * Tests that if a <code>WebApplicationException</code> is thrown, the
+     * <code>Response</code> is used if there's an entity provided.
+     */
+    public void testWebAppExceptionWithResponseThrown() {
+        try {
+            GetMethod httpMethod = new GetMethod();
+            httpMethod.setURI(new URI(BASE_URI, false));
+            httpclient = new HttpClient();
+
+            try {
+                int result = httpclient.executeMethod(httpMethod);
+                System.out.println("Response status code: " + result);
+                System.out.println("Response body: ");
+                String responseBody = httpMethod.getResponseBodyAsString();
+                System.out.println(responseBody);
+                assertEquals(200, result);
+                assertEquals("Exception returns OK", responseBody);
+            } catch (IOException ioe) {
+                ioe.printStackTrace();
+                fail(ioe.getMessage());
+            } finally {
+                httpMethod.releaseConnection();
+            }
+        } catch (URIException e) {
+            e.printStackTrace();
+            fail(e.getMessage());
+        }
+    }
+
+    /**
+     * Tests that if a <code>WebApplicationException</code> is thrown, the
+     * custom application <code>Response</code> is used if there's an entity
+     * provided. There is no entity in the custom <code>Response</code> but
+     * there is no exception mapper, so this should be just like a custom
+     * application <code>Response</code>.
+     */
+    public void testWebAppExceptionWithCustomResponseThrown() {
+        try {
+            PostMethod httpMethod = new PostMethod();
+            httpMethod.setURI(new URI(BASE_URI, false));
+            httpclient = new HttpClient();
+
+            try {
+                int result = httpclient.executeMethod(httpMethod);
+                System.out.println("Response status code: " + result);
+                System.out.println("Response body: ");
+                String responseBody = httpMethod.getResponseBodyAsString();
+                System.out.println(responseBody);
+                assertEquals(204, result);
+                assertNull(responseBody);
+            } catch (IOException ioe) {
+                ioe.printStackTrace();
+                fail(ioe.getMessage());
+            } finally {
+                httpMethod.releaseConnection();
+            }
+        } catch (URIException e) {
+            e.printStackTrace();
+            fail(e.getMessage());
+        }
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/buildTest.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/buildTest.xml?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/buildTest.xml (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/buildTest.xml Tue Jun 23 05:37:57 2009
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements. See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership. The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License. You may obtain a copy of the License at
+  ~
+  ~ http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied. See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<project name="jaxrs.tests.exceptions.subresources" default="all">
+	<import file="../../../../buildCommon.xml" />
+</project>

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/Application.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/Application.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/Application.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/Application.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,34 @@
+/*
+ * 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 jaxrs.tests.exceptions.subresources.server;
+
+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(GuestbookResource.class);
+        return clazzes;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/Comment.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/Comment.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/Comment.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/Comment.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,58 @@
+/*
+ * 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 jaxrs.tests.exceptions.subresources.server;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "comment")
+public class Comment {
+
+    private Integer id;
+
+    private String message;
+
+    private String author;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    @XmlElement(nillable = false)
+    public String getMessage() {
+        return message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+
+    public String getAuthor() {
+        return author;
+    }
+
+    public void setAuthor(String author) {
+        this.author = author;
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/CommentData.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/CommentData.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/CommentData.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/CommentData.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,114 @@
+/*
+ * 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 jaxrs.tests.exceptions.subresources.server;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.core.Response.Status;
+
+public class CommentData {
+
+    final private String commentId;
+
+    public CommentData(String id) {
+        this.commentId = id;
+    }
+
+    @GET
+    @Produces("text/xml")
+    public Response retrieveComment() {
+        if (commentId == null) {
+            return Response.status(Status.NOT_FOUND).build();
+        }
+
+        Comment existingComment = GuestbookDatabase.getGuestbook().getComment(
+                Integer.valueOf(commentId));
+        if (existingComment == null) {
+            return Response.status(Status.NOT_FOUND).build();
+        }
+        return Response.ok(existingComment).build();
+    }
+
+    @POST
+    @Produces("text/xml")
+    @Consumes("text/xml")
+    public Response createComment(Comment comment, @Context UriInfo uriInfo) {
+        /*
+         * If no comment data was sent, then return a bad request.
+         */
+        if (comment == null) {
+            throw new WebApplicationException(Response.Status.BAD_REQUEST);
+        }
+
+        if (comment.getId() == null || comment.getMessage() == null
+                || comment.getAuthor() == null) {
+            CommentError commentError = new CommentError();
+            commentError
+                    .setErrorMessage("Please include a comment ID, a message, and your name.");
+            Response resp = Response.status(Response.Status.BAD_REQUEST)
+                    .entity(commentError).build();
+            throw new WebApplicationException(resp);
+        }
+
+        GuestbookDatabase.getGuestbook().storeComment(comment);
+        try {
+            return Response.created(
+                    new URI(uriInfo.getAbsolutePath() + "/" + comment.getId()))
+                    .entity(comment).build();
+        } catch (URISyntaxException e) {
+            e.printStackTrace();
+            throw new WebApplicationException(e);
+        }
+    }
+
+    @PUT
+    public Response updateComment(Comment comment) throws GuestbookException {
+        if (comment.getId() == null
+                || !Integer.valueOf(commentId).equals(comment.getId())) {
+            throw new GuestbookException("Unexpected ID.");
+        }
+
+        Comment existingComment = GuestbookDatabase.getGuestbook().getComment(
+                Integer.valueOf(comment.getId()));
+        if (existingComment == null) {
+            throw new GuestbookException(
+                    "Cannot find existing comment to update.");
+        }
+        GuestbookDatabase.getGuestbook().storeComment(comment);
+        return Response.ok(comment).build();
+    }
+
+    @DELETE
+    public void deleteComment() {
+        GuestbookDatabase.getGuestbook().deleteComment(
+                Integer.valueOf(commentId));
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/CommentError.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/CommentError.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/CommentError.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/CommentError.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,39 @@
+/*
+ * 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 jaxrs.tests.exceptions.subresources.server;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "commenterror")
+public class CommentError {
+
+    private String errorMessage;
+
+    public String getErrorMessage() {
+        return errorMessage;
+    }
+
+    @XmlElement(name = "message")
+    public void setErrorMessage(String errorMessage) {
+        this.errorMessage = errorMessage;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/GuestbookDatabase.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/GuestbookDatabase.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/GuestbookDatabase.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/GuestbookDatabase.java Tue Jun 23 05:37:57 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 jaxrs.tests.exceptions.subresources.server;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A simple in-memory data store.
+ */
+public class GuestbookDatabase {
+
+    private static GuestbookDatabase guestbook = new GuestbookDatabase();
+
+    private Map<Integer, Comment> comments = Collections
+            .synchronizedMap(new HashMap<Integer, Comment>());
+
+    private int counter = 0;
+
+    private GuestbookDatabase() {
+        /* private singleton constructor */
+    }
+
+    public static GuestbookDatabase getGuestbook() {
+        return guestbook;
+    }
+
+    public Comment getComment(Integer id) {
+        return comments.get(id);
+    }
+
+    public void storeComment(Comment c) {
+        comments.put(c.getId(), c);
+    }
+
+    public Collection<Integer> getCommentKeys() {
+        return comments.keySet();
+    }
+
+    public void deleteComment(Integer id) {
+        if (id == -99999) {
+            throw new Error("Simulated error");
+        }
+
+        if (comments.remove(id) == null) {
+            throw new NullPointerException(
+                    "The comment did not previously exist.");
+        }
+    }
+
+    public synchronized int getAndIncrementCounter() {
+        ++counter;
+        return counter;
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/GuestbookException.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/GuestbookException.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/GuestbookException.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/GuestbookException.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,42 @@
+/*
+ * 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 jaxrs.tests.exceptions.subresources.server;
+
+public class GuestbookException extends Exception {
+
+    private static final long serialVersionUID = -1975560538784455458L;
+
+    public GuestbookException() {
+        super();
+    }
+
+    public GuestbookException(String message) {
+        super(message);
+    }
+
+    public GuestbookException(Throwable cause) {
+        super(cause);
+    }
+
+    public GuestbookException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/GuestbookResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/GuestbookResource.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/GuestbookResource.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/GuestbookResource.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,57 @@
+/*
+ * 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 jaxrs.tests.exceptions.subresources.server;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+
+@Path("guestbooksubresources")
+public class GuestbookResource {
+    //
+    //     @Path("commentdata/{commentid}")
+    //     @Produces(value = { "text/xml" })
+    //     public CommentData resolveComment() {
+    //     return new CommentData(aCommentId, null);
+    //     }
+
+    @Path("commentdata/{commentid}")
+    public CommentData resolveComment(@PathParam("commentid") String aCommentId) {
+        return new CommentData(aCommentId);
+    }
+
+    @Path("commentdata")
+    public CommentData resolveComment() {
+        return new CommentData(null);
+    }
+
+    @GET
+    @Path("somecomment")
+    @Produces("text/xml")
+    public Comment getComment(Comment c2) {
+        Comment c = new Comment();
+        c.setAuthor("Anonymous");
+        c.setId(10);
+        c.setMessage("Hello World!");
+        return c;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/ObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/ObjectFactory.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/ObjectFactory.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/server/ObjectFactory.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,35 @@
+/*
+ * 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 jaxrs.tests.exceptions.subresources.server;
+
+import javax.xml.bind.annotation.XmlRegistry;
+
+@XmlRegistry
+public class ObjectFactory {
+
+    public CommentError createCommentError() {
+        return new CommentError();
+    }
+
+    public Comment createComment() {
+        return new Comment();
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/test/ExceptionsSubresourcesTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/test/ExceptionsSubresourcesTest.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/test/ExceptionsSubresourcesTest.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/exceptions/subresources/test/ExceptionsSubresourcesTest.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,148 @@
+/*
+ * 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 jaxrs.tests.exceptions.subresources.test;
+
+import javax.ws.rs.core.Response.Status;
+
+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 framework.defaults.test.FVTTestCase;
+
+public class ExceptionsSubresourcesTest extends FVTTestCase {
+
+    public static junit.framework.Test suite() {
+        return FVTTestCase.getTestSuite(ExceptionsSubresourcesTest.class,
+                "jaxrs.tests.exceptions.subresources.server.Application");
+    }
+
+    @Override
+    public String getBaseURI() {
+        return super.getBaseURI() + "/guestbooksubresources";
+    }
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+    }
+
+    /**
+     * 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() + "/commentdata");
+        try {
+            postMethod
+                    .setRequestEntity(new StringRequestEntity(
+                            "<comment><id>10000</id><author>Anonymous</author><message>Hi there</message></comment>",
+                            "text/xml", null));
+            client.executeMethod(postMethod);
+            assertEquals(201, postMethod.getStatusCode());
+        } finally {
+            postMethod.releaseConnection();
+        }
+        String postURILocation = postMethod.getResponseHeader("Location")
+                .getValue();
+
+        GetMethod getMethod = new GetMethod(postURILocation);
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals(
+                    "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><comment><author>Anonymous</author><id>10000</id><message>Hi there</message></comment>",
+                    getMethod.getResponseBodyAsString());
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Test that a <code>WebApplicationException</code> thrown from a
+     * sub-resource is still processed properly.
+     *
+     * @throws Exception
+     */
+    public void testWebApplicationException() throws Exception {
+        HttpClient client = new HttpClient();
+
+        PostMethod postMethod = new PostMethod(getBaseURI() + "/commentdata");
+        try {
+            postMethod.setRequestEntity(new StringRequestEntity(
+                    "<comment></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>Please include a comment ID, a message, and your name.</message></commenterror>",
+                    postMethod.getResponseBodyAsString());
+        } finally {
+            postMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Test that a checked exception is processed properly.
+     *
+     * @throws Exception
+     */
+    public void testCheckedException() throws Exception {
+        HttpClient client = new HttpClient();
+
+        PutMethod putMethod = new PutMethod(getBaseURI() + "/commentdata");
+        try {
+            putMethod.setRequestEntity(new StringRequestEntity(
+                    "<comment></comment>", "text/xml", null));
+            client.executeMethod(putMethod);
+            assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(),
+                    putMethod.getStatusCode());
+            assertLogContainsException("jaxrs.tests.exceptions.subresources.server.GuestbookException: Unexpected ID.");
+        } finally {
+            putMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Test the positive workflow where a comment with a message and author is
+     * successfully posted to the Guestbook.
+     *
+     * @throws Exception
+     */
+    public void testRuntimeException() throws Exception {
+        HttpClient client = new HttpClient();
+        DeleteMethod deleteMethod = new DeleteMethod(getBaseURI()
+                + "/commentdata/afdsfsdf");
+        try {
+            client.executeMethod(deleteMethod);
+            assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(),
+                    deleteMethod.getStatusCode());
+            assertLogContainsException("java.lang.NumberFormatException: For input string: \"afdsfsdf\"");
+        } finally {
+            deleteMethod.releaseConnection();
+        }
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/headers/buildTest.xml
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/headers/buildTest.xml?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/headers/buildTest.xml (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/headers/buildTest.xml Tue Jun 23 05:37:57 2009
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements. See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership. The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License. You may obtain a copy of the License at
+  ~
+  ~ http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied. See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<project name="jaxrs.tests.headers" default="all">
+	<import file="../../../buildCommon.xml" />
+</project>



Mime
View raw message