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 [32/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/unittests/com/ibm/ws/jaxrs/sample/responsebuilder/ResponseBuilderTests.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/responsebuilder/ResponseBuilderTests.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/responsebuilder/ResponseBuilderTests.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/responsebuilder/ResponseBuilderTests.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,385 @@
+/*
+ * 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 com.ibm.ws.jaxrs.sample.responsebuilder;
+
+import java.util.List;
+
+import com.ibm.ws.jaxrs.web.RESTServlet;
+import com.ibm.ws.jaxrs.web.ServletTestFramework;
+import com.ibm.ws.jaxrs.web.mock.ServletRequest;
+import com.ibm.ws.jaxrs.web.mock.ServletResponse;
+
+public class ResponseBuilderTests extends ServletTestFramework {
+
+    private static final String URI_ROOT_RESOURCE = "/responsebuilder";
+
+    /**
+     * Test to make sure a Cache-Control header is sent back
+     *
+     * INPUT: none
+     * OUTPUT: Cache-Control response header
+     */
+    public void testGetCacheControl() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.responsebuilder.ResponseBuilderApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/cachecontrol", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue(
+                    "Response did not contain expected 'Cache-Control' header",
+                    response.containsHeader("Cache-Control"));
+            String value = response.getHeader("Cache-Control");
+            assertTrue(
+                    "Cache-Control header did not contain expected 'private'",
+                    value.contains("private"));
+            assertTrue(
+                    "Cache-Control header did not contain expected 'must-revalidate'",
+                    value.contains("must-revalidate"));
+            assertTrue(
+                    "Cache-Control header did not contain expected 'max-age=50'",
+                    value.contains("max-age=50"));
+            assertTrue(
+                    "Cache-Control header did not contain expected 's-maxage=65'",
+                    value.contains("s-maxage=65"));
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Test to make sure a Set-Cookie header is sent back containing a single
+     * cookie value set in the resource.
+     *
+     * INPUT: none
+     * OUTPUT: Set-Cookie in response header
+     */
+    public void testGetCookie() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.responsebuilder.ResponseBuilderApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/newcookie", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue(
+                    "The expected 'Set-Cookie' header was not found in the response",
+                    response.containsHeader("Set-Cookie"));
+            String value = response.getHeader("Set-Cookie");
+            assertTrue(
+                    "The expected 'sessionid-123' was not found in the 'Set-Cookie' "
+                            + "response header", value
+                            .contains("sessionid=123"));
+            assertTrue(
+                    "The expected 'Comment=this is a newCookie' was not found in the "
+                            + "'Set-Cookie' response header", value
+                            .contains("Comment=this is a newCookie"));
+            assertTrue(
+                    "The expected 'Domain=localhost' was not found in the 'Set-Cookie' "
+                            + "response header", value
+                            .contains("Domain=localhost"));
+            assertTrue(
+                    "The expected 'Path=/responsebuilder/newcookie' was not found in the "
+                            + "'Set-Cookie' response header", value
+                            .contains("Path=/responsebuilder" + "/newcookie"));
+            assertTrue(
+                    "The expected 'Secure' was not found in the 'Set-Cookie' "
+                            + "response header", value.contains("Secure"));
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Test to make sure a Set-Cookie header is sent back containing multiple
+     * cookie values set in the resource
+     *
+     * INPUT: none
+     * OUTPUT: Set-Cookie in response header
+     */
+    public void testGetCookies() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.responsebuilder.ResponseBuilderApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/newcookies", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue(
+                    "The expected 'Set-Cookie' header was not found in the response",
+                    response.containsHeader("Set-Cookie"));
+            List<String> values = response.getHeaders("Set-Cookie");
+            assertEquals(2, values.size());
+
+            String value = values.get(0);
+            assertTrue(
+                    "The expected 'sessionid-123' was not found in the 'Set-Cookie' "
+                            + "response header", value
+                            .contains("sessionid=123"));
+            assertTrue(
+                    "The expected 'Comment=this is a newCookie' was not found in the "
+                            + "'Set-Cookie' response header", value
+                            .contains("Comment=this is a newCookie"));
+            assertTrue(
+                    "The expected 'Domain=localhost' was not found in the 'Set-Cookie' "
+                            + "response header", value
+                            .contains("Domain=localhost"));
+            assertTrue(
+                    "The expected 'Path=/responsebuilder/newcookie' was not found in the "
+                            + "'Set-Cookie' response header", value
+                            .contains("Path=/responsebuilder" + "/newcookie"));
+            assertTrue(
+                    "The expected 'Secure' was not found in the 'Set-Cookie' "
+                            + "response header", value.contains("Secure"));
+
+            value = values.get(1);
+            assertTrue(
+                    "The expected 'pages' was not found in the 'Set-Cookie' "
+                            + "response header", value.contains("pages"));
+            assertTrue("The expected 'full' was not found in the 'Set-Cookie' "
+                    + "response header", value.contains("full"));
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Test to make sure an Expires header is sent back
+     *
+     * INPUT: none
+     * OUTPUT: Expires in response header
+     */
+    public void testGetExpires() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.responsebuilder.ResponseBuilderApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/expires", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue(
+                    "The expected 'Expires' header was not found in the response",
+                    response.containsHeader("Expires"));
+            String value = response.getHeader("Expires");
+            assertTrue(
+                    "The 'Expires' response header did not contain the expected value",
+                    value.contains("Dec 31"));
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Test to make sure a Content-Language header is sent back
+     *
+     * INPUT: none
+     * OUTPUT: Content-Language in response header
+     */
+    public void testGetContentLanguage() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.responsebuilder.ResponseBuilderApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/language", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue(
+                    "The expected 'Content-Language' header was not found in the response",
+                    response.containsHeader("Content-Language"));
+            String value = response.getHeader("Content-Language");
+            assertEquals("en-gb", value);
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Test to make sure a Last-Modified header is sent back
+     *
+     * INPUT: none
+     * OUTPUT: Last-Modified in response header
+     */
+    public void testGetLastModified() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.responsebuilder.ResponseBuilderApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/lastmodified", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue(
+                    "The expected 'Last-Modified' header was not found in the response",
+                    response.containsHeader("Last-Modified"));
+            String value = response.getHeader("Last-Modified");
+            assertTrue(
+                    "The 'Last-Modified' response header did not contain the expected value",
+                    value.contains("31 Dec"));
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Test to make sure a Location header is sent back
+     *
+     * INPUT: none
+     * OUTPUT: Location in response header
+     */
+    public void testGetLocation() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.responsebuilder.ResponseBuilderApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/location", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue(
+                    "The expected 'Location' header was not found in the response",
+                    response.containsHeader("Location"));
+            String value = response.getHeader("Location");
+            assertEquals("/responsebuilder/location", value);
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Test to make sure a Content-Location header is sent back
+     *
+     * INPUT: none
+     * OUTPUT: Content-Location in response header
+     */
+    public void testGetContentLocation() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.responsebuilder.ResponseBuilderApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/contentlocation", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue(
+                    "The expected 'Content-Location' header was not found in the response",
+                    response.containsHeader("Content-Location"));
+            String value = response.getHeader("Content-Location");
+            assertEquals("/responsebuilder/contentlocation", value);
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Test to make sure an ETag header is sent back
+     *
+     * INPUT: none
+     * OUTPUT: ETag in response header
+     */
+    public void testGetETag() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.responsebuilder.ResponseBuilderApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/etag", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue(
+                    "The expected 'ETag' header was not found in the response",
+                    response.containsHeader("ETag"));
+            String value = response.getHeader("ETag");
+            assertEquals("\"myTag\"", value);
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Test to make sure a Content-Type header is sent back
+     *
+     * INPUT: none
+     * OUTPUT: Content-Type in response header
+     */
+    public void testGetContentType() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.responsebuilder.ResponseBuilderApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/contenttype", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue(
+                    "The expected 'Content-Type' header was not found in the response",
+                    response.containsHeader("Content-Type"));
+            String value = response.getHeader("Content-Type");
+            assertEquals("text/xml", value);
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Test to make sure a user-defined header is sent back
+     *
+     * INPUT: none
+     * OUTPUT: User-defined in response header
+     */
+    public void testGetUserHeader() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.responsebuilder.ResponseBuilderApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/userheader", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue(
+                    "The expected 'Resource' header was not found in the response",
+                    response.containsHeader("Resource"));
+            String value = response.getHeader("Resource");
+            assertEquals(ResponseBuilderResource.class.getName(), value);
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/uriinfo/UriInfoApplication.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/uriinfo/UriInfoApplication.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/uriinfo/UriInfoApplication.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/uriinfo/UriInfoApplication.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 com.ibm.ws.jaxrs.sample.uriinfo;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+public class UriInfoApplication extends Application {
+
+    public Set<Class<?>> getClasses() {
+        Set<Class<?>> classes = new HashSet<Class<?>>();
+        classes.add(UriInfoResource.class);
+        return classes;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/uriinfo/UriInfoResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/uriinfo/UriInfoResource.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/uriinfo/UriInfoResource.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/uriinfo/UriInfoResource.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,227 @@
+/*
+ * 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 com.ibm.ws.jaxrs.sample.uriinfo;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.PathSegment;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.UriInfo;
+
+@Path(value = "/uriinfo")
+public class UriInfoResource {
+
+    @Context
+    private UriInfo uriInfo;
+
+    @GET
+    @Path(value = "/getAbsolutePath")
+    public Response getAbsolutePath() {
+        Response resp = Response.ok().build();
+        resp.getMetadata().putSingle("uriInfo", uriInfo.getAbsolutePath());
+        return resp;
+    }
+
+    @GET
+    @Path(value = "/getBaseUri")
+    public Response getBaseUri() {
+        Response resp = Response.ok().build();
+        resp.getMetadata()
+                .putSingle("uriInfo", uriInfo.getBaseUri().toString());
+        return resp;
+    }
+
+    @GET
+    @Path(value = "/getMatchedUrisEncoded/{value}")
+    public Response getMatchedUrisEncoded() {
+        Response resp = Response.ok().build();
+        List<Object> matchedUris = new LinkedList<Object>();
+        List<String> strings = uriInfo.getMatchedURIs(false);
+        for (String string : strings) {
+            matchedUris.add(string);
+        }
+        resp.getMetadata().put("uriInfo", matchedUris);
+        return resp;
+    }
+
+    @GET
+    @Path(value = "/getMatchedUrisDecoded/{value}")
+    public Response getMatchedUrisDecoded() {
+        Response resp = Response.ok().build();
+        List<Object> matchedUris = new LinkedList<Object>();
+        List<String> strings = uriInfo.getMatchedURIs();
+        for (String string : strings) {
+            matchedUris.add(string);
+        }
+        resp.getMetadata().put("uriInfo", matchedUris);
+        return resp;
+    }
+
+    @GET
+    @Path(value = "/getPathEncoded/{value}")
+    public Response getPathEncoded() {
+        Response resp = Response.ok().build();
+        resp.getMetadata().putSingle("uriInfo", uriInfo.getPath(false));
+        return resp;
+    }
+
+    @GET
+    @Path(value = "/getPathDecoded/{value}")
+    public Response getPathDecoded() {
+        Response resp = Response.ok().build();
+        resp.getMetadata().putSingle("uriInfo", uriInfo.getPath());
+        return resp;
+    }
+
+    @GET
+    @Path(value = "/getMatchedResources")
+    public Response getMatchedResources() {
+        Response resp = Response.ok().build();
+        resp.getMetadata().put("uriInfo", uriInfo.getMatchedResources());
+        return resp;
+    }
+
+    @GET
+    @Path(value = "/getPathParamsEncoded/{value}/{id}/{origin}")
+    public Response getPathParamsEncoded() {
+        Response resp = Response.ok().build();
+        MultivaluedMap<String, String> pathParams = uriInfo
+                .getPathParameters(false);
+        Iterator<String> keys = pathParams.keySet().iterator();
+        while (keys.hasNext()) {
+            String key = keys.next();
+            List<Object> values = new LinkedList<Object>();
+            List<String> strings = pathParams.get(key);
+            for (String string : strings) {
+                values.add(string);
+            }
+            resp.getMetadata().put(key, values);
+        }
+        return resp;
+    }
+
+    @GET
+    @Path(value = "/getPathParamsDecoded/{value}/{id}/{origin}")
+    public Response getPathParamsDecoded() {
+        Response resp = Response.ok().build();
+        MultivaluedMap<String, String> pathParams = uriInfo.getPathParameters();
+        Iterator<String> keys = pathParams.keySet().iterator();
+        while (keys.hasNext()) {
+            String key = keys.next();
+            List<Object> values = new LinkedList<Object>();
+            List<String> strings = pathParams.get(key);
+            for (String string : strings) {
+                values.add(string);
+            }
+            resp.getMetadata().put(key, values);
+        }
+        return resp;
+    }
+
+    @GET
+    @Path(value = "/getPathSegsEncoded/{value}/{id}/{origin}")
+    public Response getPathSegsEncoded() {
+        Response resp = Response.ok().build();
+        List<PathSegment> segments = uriInfo.getPathSegments(false);
+        List<Object> segs = new LinkedList<Object>();
+        for (PathSegment segment : segments) {
+            segs.add(segment.getPath());
+        }
+        resp.getMetadata().put("uriInfo", segs);
+        return resp;
+    }
+
+    @GET
+    @Path(value = "/getPathSegsDecoded/{value}/{id}/{origin}")
+    public Response getPathSegsDecoded() {
+        Response resp = Response.ok().build();
+        List<PathSegment> segments = uriInfo.getPathSegments();
+        List<Object> segs = new LinkedList<Object>();
+        for (PathSegment segment : segments) {
+            segs.add(segment.getPath());
+        }
+        resp.getMetadata().put("uriInfo", segs);
+        return resp;
+    }
+
+    @GET
+    @Path(value = "/getQueryParamsEncoded")
+    public Response getQueryParamsEncoded() {
+        Response resp = Response.ok().build();
+        MultivaluedMap<String, String> pathParams = uriInfo
+                .getQueryParameters(false);
+        Iterator<String> keys = pathParams.keySet().iterator();
+        while (keys.hasNext()) {
+            String key = keys.next();
+            List<Object> values = new LinkedList<Object>();
+            List<String> strings = pathParams.get(key);
+            for (String string : strings) {
+                values.add(string);
+            }
+            resp.getMetadata().put(key, values);
+        }
+        return resp;
+    }
+
+    @GET
+    @Path(value = "/getQueryParamsDecoded")
+    public Response getQueryParamsDecoded() {
+        Response resp = Response.ok().build();
+        MultivaluedMap<String, String> pathParams = uriInfo
+                .getQueryParameters();
+        Iterator<String> keys = pathParams.keySet().iterator();
+        while (keys.hasNext()) {
+            String key = keys.next();
+            List<Object> values = new LinkedList<Object>();
+            List<String> strings = pathParams.get(key);
+            for (String string : strings) {
+                values.add(string);
+            }
+            resp.getMetadata().put(key, values);
+        }
+        return resp;
+    }
+
+    @GET
+    @Path(value = "/getRequestUri")
+    public Response getRequestUri() {
+        Response resp = Response.ok().build();
+        resp.getMetadata().putSingle("uriInfo",
+                uriInfo.getRequestUri().toString());
+        return resp;
+    }
+
+    @GET
+    @Path(value = "/getRequestUriBuilder")
+    public Response getRequestUriBuilder() {
+        Response resp = Response.ok().build();
+        UriBuilder builder = uriInfo.getRequestUriBuilder();
+        resp.getMetadata().putSingle("uriInfo", builder.build(null).toString());
+        return resp;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/uriinfo/UriInfoTests.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/uriinfo/UriInfoTests.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/uriinfo/UriInfoTests.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/uriinfo/UriInfoTests.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,501 @@
+/*
+ * 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 com.ibm.ws.jaxrs.sample.uriinfo;
+
+import java.net.URI;
+import java.util.List;
+
+import com.ibm.ws.jaxrs.web.RESTServlet;
+import com.ibm.ws.jaxrs.web.ServletTestFramework;
+import com.ibm.ws.jaxrs.web.mock.ServletRequest;
+import com.ibm.ws.jaxrs.web.mock.ServletResponse;
+
+public class UriInfoTests extends ServletTestFramework {
+
+    private static final String URI_ROOT_RESOURCE = "/uriinfo";
+
+    /**
+     * Verify that UriInfo.getAbsolutePath() returns the correct result
+     *
+     * INPUT: none
+     * OUTPUT: injected value in response header
+     */
+    public void testGetAbsolutePath() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.uriinfo.UriInfoApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/getAbsolutePath", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue("Expected 'uriInfo' header not found in response",
+                    response.containsHeader("uriInfo"));
+            String value = response.getHeader("uriInfo");
+            assertEquals(request.getRequestURL().toString(), value);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Verify that UriInfo.getBaseUri() returns the correct result
+     *
+     * INPUT: none
+     * OUTPUT: injected value in response header
+     */
+    public void testGetBaseUri() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.uriinfo.UriInfoApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/getBaseUri", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue("Expected 'uriInfo' header not found in response",
+                    response.containsHeader("uriInfo"));
+            String value = response.getHeader("uriInfo");
+            URI expectedUri = new URI(request.getRequestURL().toString());
+            String expected = expectedUri.getScheme() + "://"
+                    + expectedUri.getHost() + ":" + expectedUri.getPort()
+                    + request.getContextPath();
+            assertEquals(expected, value);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Verify that UriInfo.getMatchedUris(false) returns the correct result
+     *
+     * INPUT: none
+     * OUTPUT: injected value in response header
+     */
+    public void testGetMatchedUrisEncoded() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.uriinfo.UriInfoApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/getMatchedUrisEncoded/James%20Bond",
+                "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue("Expected 'uriInfo' header not found in response",
+                    response.containsHeader("uriInfo"));
+            List<String> values = response.getHeaders("uriInfo");
+            assertNotNull(values);
+            assertEquals(2, values.size());
+            String value = values.get(0);
+            assertEquals("uriinfo/getMatchedUrisEncoded/James%20Bond", value);
+            value = values.get(1);
+            assertEquals("uriinfo", value);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Verify that UriInfo.getMatchedUris() returns the correct result
+     *
+     * INPUT: none
+     * OUTPUT: injected value in response header
+     */
+    public void testGetMatchedUrisDecoded() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.uriinfo.UriInfoApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/getMatchedUrisDecoded/James%20Bond",
+                "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue("Expected 'uriInfo' header not found in response",
+                    response.containsHeader("uriInfo"));
+            List<String> values = response.getHeaders("uriInfo");
+            assertNotNull(values);
+            assertEquals(2, values.size());
+            String value = values.get(0);
+            assertEquals("uriinfo/getMatchedUrisDecoded/James Bond", value);
+            value = values.get(1);
+            assertEquals("uriinfo", value);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Verify that UriInfo.getPath(false) returns the correct result
+     *
+     * INPUT: none
+     * OUTPUT: injected value in response header
+     */
+    public void testGetPathEncoded() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.uriinfo.UriInfoApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/getPathEncoded/James%20Bond", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue("Expected 'uriInfo' header not found in response",
+                    response.containsHeader("uriInfo"));
+            String value = response.getHeader("uriInfo");
+            assertEquals("/uriinfo/getPathEncoded/James%20Bond", value);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Verify that UriInfo.getPath() returns the correct result
+     *
+     * INPUT: none
+     * OUTPUT: injected value in response header
+     */
+    public void testGetPathDecoded() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.uriinfo.UriInfoApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/getPathDecoded/James%20Bond", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue("Expected 'uriInfo' header not found in response",
+                    response.containsHeader("uriInfo"));
+            String value = response.getHeader("uriInfo");
+            assertEquals("/uriinfo/getPathDecoded/James Bond", value);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Verify that UriInfo.getMatchedResources() returns the correct result
+     *
+     * INPUT: none
+     * OUTPUT: injected value in response header
+     */
+    public void testGetMatchedResources() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.uriinfo.UriInfoApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/getMatchedResources", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue("Expected 'uriInfo' header not found in response",
+                    response.containsHeader("uriInfo"));
+            List<String> values = response.getHeaders("uriInfo");
+            assertEquals(1, values.size());
+            assertEquals(UriInfoResource.class.toString(), values.get(0));
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Verify that UriInfo.getPathParameters(false) returns the correct result
+     *
+     * INPUT: none
+     * OUTPUT: injected value in response header
+     */
+    public void testGetPathParamsEncoded() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.uriinfo.UriInfoApplication");
+
+        ServletRequest request = ServletTestFramework
+                .createServletRequest(
+                        URI_ROOT_RESOURCE
+                                + "/getPathParamsEncoded/James%20Bond/007/Great%20Britain",
+                        "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue("Expected 'value' header not found in response",
+                    response.containsHeader("value"));
+            assertTrue("Expected 'id' header not found in response", response
+                    .containsHeader("id"));
+            assertTrue("Expected 'origin' header not found in response",
+                    response.containsHeader("origin"));
+            String value = response.getHeader("value");
+            assertEquals("James%20Bond", value);
+            value = response.getHeader("id");
+            assertEquals("007", value);
+            value = response.getHeader("origin");
+            assertEquals("Great%20Britain", value);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Verify that UriInfo.getPathParameters() returns the correct result
+     *
+     * INPUT: none
+     * OUTPUT: injected value in response header
+     */
+    public void testGetPathParamsDecoded() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.uriinfo.UriInfoApplication");
+
+        ServletRequest request = ServletTestFramework
+                .createServletRequest(
+                        URI_ROOT_RESOURCE
+                                + "/getPathParamsDecoded/James%20Bond/007/Great%20Britain",
+                        "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue("Expected 'value' header not found in response",
+                    response.containsHeader("value"));
+            assertTrue("Expected 'id' header not found in response", response
+                    .containsHeader("id"));
+            assertTrue("Expected 'origin' header not found in response",
+                    response.containsHeader("origin"));
+            String value = response.getHeader("value");
+            assertEquals("James Bond", value);
+            value = response.getHeader("id");
+            assertEquals("007", value);
+            value = response.getHeader("origin");
+            assertEquals("Great Britain", value);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Verify that UriInfo.getPathSegments(false) returns the correct result
+     *
+     * INPUT: none
+     * OUTPUT: injected value in response header
+     */
+    public void testGetPathSegsEncoded() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.uriinfo.UriInfoApplication");
+
+        ServletRequest request = ServletTestFramework
+                .createServletRequest(
+                        URI_ROOT_RESOURCE
+                                + "/getPathSegsEncoded/James%20Bond/007/Great%20Britain",
+                        "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue("Expected 'uriInfo' header not found in response",
+                    response.containsHeader("uriInfo"));
+            List<String> values = response.getHeaders("uriInfo");
+            assertEquals(5, values.size());
+            assertEquals("uriinfo", values.get(0));
+            assertEquals("getPathSegsEncoded", values.get(1));
+            assertEquals("James%20Bond", values.get(2));
+            assertEquals("007", values.get(3));
+            assertEquals("Great%20Britain", values.get(4));
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Verify that UriInfo.getPathSegments() returns the correct result
+     *
+     * INPUT: none
+     * OUTPUT: injected value in response header
+     */
+    public void testGetPathSegsDecoded() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.uriinfo.UriInfoApplication");
+
+        ServletRequest request = ServletTestFramework
+                .createServletRequest(
+                        URI_ROOT_RESOURCE
+                                + "/getPathSegsDecoded/James%20Bond/007/Great%20Britain",
+                        "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue("Expected 'uriInfo' header not found in response",
+                    response.containsHeader("uriInfo"));
+            List<String> values = response.getHeaders("uriInfo");
+            assertEquals(5, values.size());
+            assertEquals("uriinfo", values.get(0));
+            assertEquals("getPathSegsDecoded", values.get(1));
+            assertEquals("James Bond", values.get(2));
+            assertEquals("007", values.get(3));
+            assertEquals("Great Britain", values.get(4));
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Verify that UriInfo.getQueryParameters(false) returns the correct result
+     *
+     * INPUT: none
+     * OUTPUT: injected value in response header
+     */
+    public void testGetQueryParametersEncoded() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.uriinfo.UriInfoApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/getQueryParamsEncoded",
+                "value=James%20Bond&id=007&origin=Great%20Britain", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue("Expected 'value' header not found in response",
+                    response.containsHeader("value"));
+            assertTrue("Expected 'id' header not found in response", response
+                    .containsHeader("id"));
+            assertTrue("Expected 'origin' header not found in response",
+                    response.containsHeader("origin"));
+            String value = response.getHeader("value");
+            assertEquals("James%20Bond", value);
+            value = response.getHeader("id");
+            assertEquals("007", value);
+            value = response.getHeader("origin");
+            assertEquals("Great%20Britain", value);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Verify that UriInfo.getQueryParameters() returns the correct result
+     *
+     * INPUT: none
+     * OUTPUT: injected value in response header
+     */
+    public void testGetQueryParametersDecoded() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.uriinfo.UriInfoApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/getQueryParamsDecoded",
+                "value=James%20Bond&id=007&origin=Great%20Britain", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue("Expected 'value' header not found in response",
+                    response.containsHeader("value"));
+            assertTrue("Expected 'id' header not found in response", response
+                    .containsHeader("id"));
+            assertTrue("Expected 'origin' header not found in response",
+                    response.containsHeader("origin"));
+            String value = response.getHeader("value");
+            assertEquals("James Bond", value);
+            value = response.getHeader("id");
+            assertEquals("007", value);
+            value = response.getHeader("origin");
+            assertEquals("Great Britain", value);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Verify that UriInfo.getRequestUri() returns the correct result
+     *
+     * INPUT: none
+     * OUTPUT: injected value in response header
+     */
+    public void testGetRequestUri() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.uriinfo.UriInfoApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/getRequestUri",
+                "value=James%20Bond&id=007&origin=Great%20Britain", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue("Expected 'uriInfo' header not found in response",
+                    response.containsHeader("uriInfo"));
+            String value = response.getHeader("uriInfo");
+            String expected = "http://localhost:9080/rest/uriinfo/getRequestUri?value=James%20Bond&id=007&origin=Great%20Britain";
+            assertEquals(expected, value);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Verify that UriInfo.getRequestUriBuilder() returns the correct result
+     *
+     * INPUT: none
+     * OUTPUT: injected value in response header
+     */
+    public void testGetRequestUriBuilder() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.uriinfo.UriInfoApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/getRequestUriBuilder",
+                "value=James%20Bond&id=007&origin=Great%20Britain", "GET");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertTrue("Expected 'uriInfo' header not found in response",
+                    response.containsHeader("uriInfo"));
+            String value = response.getHeader("uriInfo");
+            String expected = "http://localhost:9080/rest/uriinfo/getRequestUriBuilder?value=James%20Bond&id=007&origin=Great%20Britain";
+            assertEquals(expected, value);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/test/api/API.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/test/api/API.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/test/api/API.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/test/api/API.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 com.ibm.ws.jaxrs.test.api;
+
+import java.util.ArrayList;
+
+public class API {
+    private boolean isAnnotation;
+
+    private String className;
+
+    private ArrayList<MethodSignature> methods;
+
+    public void setIsAnnotation(boolean isAnno) {
+        isAnnotation = isAnno;
+    }
+
+    public boolean getIsAnnotation() {
+        return isAnnotation;
+    }
+
+    public void setClassName(String cn) {
+        className = cn;
+    }
+
+    public String getClassName() {
+        return className;
+    }
+
+    public void addMethod(String name, Class returnType) {
+        addMethod(name, new Class[] {}, returnType);
+    }
+
+    public void addMethod(String name, Class[] params, Class returnType) {
+        MethodSignature sig = new MethodSignature();
+        sig.name = name;
+        sig.params = params;
+        sig.returnType = returnType;
+
+        if (methods == null)
+            methods = new ArrayList<MethodSignature>();
+
+        methods.add(sig);
+    }
+
+    public ArrayList<MethodSignature> getMethods() {
+        return methods;
+    }
+
+    class MethodSignature {
+        String name;
+
+        Class[] params;
+
+        Class returnType;
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/test/api/APIValidator.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/test/api/APIValidator.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/test/api/APIValidator.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/test/api/APIValidator.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,100 @@
+/*
+ * 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 com.ibm.ws.jaxrs.test.api;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import com.ibm.ws.jaxrs.test.api.API.MethodSignature;
+
+public class APIValidator {
+
+    private API api;
+
+    public void setAPIInstance(API instance) {
+        api = instance;
+    }
+
+    public void validate() throws Exception {
+        validateClassStructure();
+        validateMethods();
+    }
+
+    private void validateClassStructure() throws Exception {
+        String className = api.getClassName();
+        Boolean isAnnotation = api.getIsAnnotation();
+
+        Class instance = Class.forName(className);
+        if (instance == null)
+            throw new ValidationException("Class [" + className
+                    + "] was not found.");
+
+        if (!isAnnotation.equals(instance.isAnnotation()))
+            throw new ValidationException("Class [" + className
+                    + "] should be an Annotation.");
+    }
+
+    private void validateMethods() throws Exception {
+        ArrayList<MethodSignature> methods = api.getMethods();
+
+        Class instance = Class.forName(api.getClassName());
+        if (methods != null && methods.size() > 0) {
+            Iterator<MethodSignature> i = methods.iterator();
+            while (i.hasNext()) {
+                MethodSignature sig = i.next();
+
+                Method m = instance.getMethod(sig.name, sig.params);
+                if (m == null)
+                    throw new ValidationException("The method [" + sig.name
+                            + "] with " + "params [" + sig.params
+                            + "] was not found.");
+
+                Class returnType = m.getReturnType();
+
+                // If the method is void, make sure we don't have a
+                // return type specified.
+                if (sig.returnType == null) {
+                    if (returnType != null)
+                        throw new ValidationException(
+                                "A void return type was expected but the "
+                                        + "method [" + sig.name
+                                        + "] has a return type specified.");
+                } else {
+                    String foundName = returnType.getName();
+                    String expectedName = sig.returnType.getName();
+                    if (!returnType.equals(sig.returnType))
+                        throw new ValidationException("Method [" + sig.name
+                                + "] return type is incorrect.  " + "["
+                                + foundName
+                                + "] does not match expected value ["
+                                + expectedName + "].");
+                }
+            }
+        }
+    }
+
+    class ValidationException extends RuntimeException {
+
+        ValidationException(String msg) {
+            super(msg);
+        }
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/test/api/UserAPITests.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/test/api/UserAPITests.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/test/api/UserAPITests.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/test/api/UserAPITests.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,56 @@
+/*
+ * 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 com.ibm.ws.jaxrs.test.api;
+
+import junit.framework.TestCase;
+
+public class UserAPITests extends TestCase {
+
+    public UserAPITests(String name) {
+        super(name);
+    }
+
+    public void testPath() throws Exception {
+        API instance = new API();
+
+        instance.setClassName("javax.ws.rs.Path");
+        instance.setIsAnnotation(true);
+
+        instance.addMethod("value", String.class);
+
+        APIValidator test = new APIValidator();
+        test.setAPIInstance(instance);
+        test.validate();
+    }
+
+    public void testPathParam() throws Exception {
+        API instance = new API();
+
+        instance.setClassName("javax.ws.rs.PathParam");
+        instance.setIsAnnotation(true);
+
+        instance.addMethod("value", String.class);
+
+        APIValidator test = new APIValidator();
+        test.setAPIInstance(instance);
+        test.validate();
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/test/uri/URIPatternTests.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/test/uri/URIPatternTests.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/test/uri/URIPatternTests.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/test/uri/URIPatternTests.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,101 @@
+/*
+ * 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 com.ibm.ws.jaxrs.test.uri;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.jaxrs.model.URITemplate;
+
+public class URIPatternTests extends TestCase {
+
+    private static final String PATH_ALBUM = "/album";
+
+    public URIPatternTests(String name) {
+        super(name);
+    }
+
+    /*
+     * Checks to make sure we can get a class level @Path annotation and build a
+     * URITemplate.
+     */
+    public void testCreateSimpleURITemplate() {
+        Path p = PhotoAlbum.class.getAnnotation(Path.class);
+        URITemplate tmpl = URITemplate.createTemplate(null, p.value());
+
+        assertTrue("A null URITemplate was returned", tmpl != null);
+        assertTrue("Found @Path.value [" + tmpl.getValue() + "] expected "
+                + "[" + PATH_ALBUM + "]", PATH_ALBUM.equals(tmpl.getValue()));
+    }
+
+    /*
+     * Gets ALL @Path annotations from the class (class level and methods) and
+     * builds URITemplate objects for each.
+     */
+    public void testCreateURITemplate() {
+        ArrayList<Path> list = new ArrayList<Path>();
+        ArrayList<URITemplate> tmpls = new ArrayList<URITemplate>();
+
+        Path p = PhotoAlbum.class.getAnnotation(Path.class);
+        if (p != null)
+            list.add(p);
+
+        Method[] methods = PhotoAlbum.class.getMethods();
+        for (Method m : methods) {
+            p = m.getAnnotation(Path.class);
+            if (p != null)
+                list.add(p);
+        }
+
+        for (Annotation a : list) {
+            if (a instanceof Path) {
+                URITemplate tmpl = URITemplate.createTemplate(null, ((Path) a)
+                        .value());
+                tmpls.add(tmpl);
+            }
+        }
+
+        // There should be as many URITemplate objects as there are
+        // Path objects on the class
+        assertTrue(list.size() == tmpls.size());
+    }
+
+    @Path(value = "/album")
+    class PhotoAlbum {
+
+        @GET
+        @Path(value = "/album/{name}")
+        public String getAlbumName() {
+            return "Sample Album";
+        }
+
+        @GET
+        @Path(value = "/album/{name}/{imageName}")
+        public String getImage(String name) {
+            return "";
+        }
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/validation/ValidationTests.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/validation/ValidationTests.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/validation/ValidationTests.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/validation/ValidationTests.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,481 @@
+/*
+ * 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 com.ibm.ws.jaxrs.validation;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HEAD;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Application;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+
+import com.ibm.rest.test.utils.TestUtils;
+import com.ibm.ws.jaxrs.model.ApplicationProcessor;
+import com.ibm.ws.jaxrs.model.JAXRSInfoInput;
+
+/*
+ * Verify function within metadata validators
+ */
+public class ValidationTests extends TestCase {
+
+    /*
+     * Verify that a good collection of resource classes validates
+     */
+    public void testValidateClassGood() throws Exception {
+        List<ClassResourceInfo> classInfoList = TestUtils.getClassInfoList(
+                new Class[] { ResourceOne.class, ResourceThree.class }, null);
+        assertNotNull(classInfoList);
+        JAXRSClassResourceValidator validator = new JAXRSClassResourceValidator();
+        List<ValidationMessage> messages = validator.validate(classInfoList);
+        assertNotNull(messages);
+        assertEquals(0, messages.size());
+    }
+
+    /*
+     * Verify that multiple resource classes with the same path do not pass validation
+     */
+    public void testValidateDuplicatePaths() throws Exception {
+        List<ClassResourceInfo> classInfoList = TestUtils.getClassInfoList(
+                new Class[] { ResourceOne.class, ResourceTwo.class }, null);
+        assertNotNull(classInfoList);
+        JAXRSClassResourceValidator validator = new JAXRSClassResourceValidator();
+        List<ValidationMessage> messages = validator.validate(classInfoList);
+        assertNotNull(messages);
+        assertEquals(1, messages.size());
+        ValidationMessage message = messages.get(0);
+        assertEquals(ValidationMessage.Type.ERROR, message.getMessageType());
+    }
+
+    /*
+     * Verify error is logged if no suitable constructors are found
+     */
+    public void testBadConstructorResource() throws Exception {
+        List<ClassResourceInfo> classInfoList = TestUtils.getClassInfoList(
+                new Class[] { BadConstructorResource.class }, null);
+        JAXRSInfoInput input = new JAXRSInfoInput(
+                JAXRSInfoInput.Type.REFLECTION);
+        assertNotNull(classInfoList);
+        JAXRSClassResourceValidator validator = new JAXRSClassResourceValidator();
+        List<ValidationMessage> messages = validator.validate(classInfoList);
+        assertNotNull(messages);
+        assertEquals(1, messages.size());
+        ValidationMessage message = messages.get(0);
+        assertEquals(ValidationMessage.Type.WARNING, message.getMessageType());
+    }
+
+    /*
+     * Verify error is skipped if singleton class is tested
+     */
+    public void testBadConstructorSingletonResource() throws Exception {
+        List<ClassResourceInfo> classInfoList = TestUtils.getClassInfoList(
+                new Class[] {}, new Object[] { BadConstructorSingletonResource
+                        .getInstance() });
+        JAXRSInfoInput input = new JAXRSInfoInput(
+                JAXRSInfoInput.Type.REFLECTION);
+        assertNotNull(classInfoList);
+        JAXRSClassResourceValidator validator = new JAXRSClassResourceValidator();
+        List<ValidationMessage> messages = validator.validate(classInfoList);
+        assertNotNull(messages);
+        assertEquals(0, messages.size());
+    }
+
+    /*
+     * Verify warning is logged when the choice of constructors to create a resource
+     * class is ambiguous (i.e. more than one constructor is sufficient)
+     */
+    public void testAmbiguousConstructorResource() throws Exception {
+        List<ClassResourceInfo> classInfoList = TestUtils.getClassInfoList(
+                new Class[] { AnyConstructorWillDo.class }, null);
+        assertNotNull(classInfoList);
+        JAXRSClassResourceValidator validator = new JAXRSClassResourceValidator();
+        List<ValidationMessage> messages = validator.validate(classInfoList);
+        assertNotNull(messages);
+        assertEquals(1, messages.size());
+        ValidationMessage message = messages.get(0);
+        assertEquals(ValidationMessage.Type.WARNING, message.getMessageType());
+    }
+
+    /*
+     * Verify warning message is logged when singletons have JSR-311 annotations
+     * other than @Context on fields
+     */
+    public void testSingletonWithInjection() throws Exception {
+        List<ClassResourceInfo> classInfoList = TestUtils.getClassInfoList(
+                null, new Object[] { new SingletonWithAnnotations() });
+        assertNotNull(classInfoList);
+        JAXRSClassResourceValidator validator = new JAXRSClassResourceValidator();
+        List<ValidationMessage> messages = validator.validate(classInfoList);
+        assertNotNull(messages);
+        assertEquals(1, messages.size());
+        ValidationMessage message = messages.get(0);
+        assertEquals(ValidationMessage.Type.WARNING, message.getMessageType());
+    }
+
+    /*
+     * Verify that a set of valid methods passes validation
+     */
+    public void testValidateMethodsGood() throws Exception {
+        List<OperationResourceInfo> opInfoList = TestUtils
+                .getOperationInfoList(ResourceOne.class, null);
+        assertNotNull(opInfoList);
+        assertTrue(opInfoList.size() > 0);
+        JAXRSOperationResourceValidator validator = new JAXRSOperationResourceValidator();
+        List<ValidationMessage> messages = validator.validate(opInfoList);
+        assertNotNull(messages);
+        assertEquals(0, messages.size());
+    }
+
+    /*
+     * Verify that a set of methods in which multiple methods have a resource
+     * designator with no @Path annotation results in a warning
+     */
+    public void testValidateMethodsMultipleDesignators() throws Exception {
+        List<OperationResourceInfo> opInfoList = TestUtils
+                .getOperationInfoList(ResourceTwo.class, null);
+        assertNotNull(opInfoList);
+        assertTrue(opInfoList.size() > 0);
+        JAXRSOperationResourceValidator validator = new JAXRSOperationResourceValidator();
+        List<ValidationMessage> messages = validator.validate(opInfoList);
+        assertNotNull(messages);
+        assertEquals(1, messages.size());
+        ValidationMessage message = messages.get(0);
+        assertEquals(ValidationMessage.Type.WARNING, message.getMessageType());
+        assertTrue(message.getMessage().contains(
+                "The annotation should only "
+                        + "appear on a single method within the class unless "
+                        + "there are different @Path, @Consumes, or @Produces "
+                        + "annotations on the methods."));
+    }
+
+    /*
+     * Verify that a set of methods in which multiple methods have duplicate
+     * @Path.value values results in a warning
+     */
+    public void testValidateMethodsDuplicatePaths() throws Exception {
+        List<OperationResourceInfo> opInfoList = TestUtils
+                .getOperationInfoList(ResourceThree.class, null);
+        assertNotNull(opInfoList);
+        assertTrue(opInfoList.size() > 0);
+        JAXRSOperationResourceValidator validator = new JAXRSOperationResourceValidator();
+        List<ValidationMessage> messages = validator.validate(opInfoList);
+        assertNotNull(messages);
+        assertEquals(1, messages.size());
+        ValidationMessage message = messages.get(0);
+        assertEquals(ValidationMessage.Type.WARNING, message.getMessageType());
+
+        // now check the case when there are no request designators
+        opInfoList = TestUtils.getOperationInfoList(ResourceFour.class, null);
+        assertNotNull(opInfoList);
+        assertTrue(opInfoList.size() > 0);
+        validator = new JAXRSOperationResourceValidator();
+        messages = validator.validate(opInfoList);
+        assertNotNull(messages);
+        assertEquals(1, messages.size());
+        message = messages.get(0);
+        assertEquals(ValidationMessage.Type.WARNING, message.getMessageType());
+    }
+
+    /*
+     * Verify a warning is logged if we find a request designator or @Path annotation
+     * on a non-public method
+     */
+    public void testWarnNonPublicMethods() throws Exception {
+        List<OperationResourceInfo> opInfoList = TestUtils
+                .getOperationInfoList(ResourceFive.class, null);
+        assertNotNull(opInfoList);
+        assertTrue(opInfoList.size() > 0);
+        JAXRSOperationResourceValidator validator = new JAXRSOperationResourceValidator();
+        List<ValidationMessage> messages = validator.validate(opInfoList);
+        assertNotNull(messages);
+        assertEquals(2, messages.size());
+        ValidationMessage message = messages.get(0);
+        assertEquals(ValidationMessage.Type.WARNING, message.getMessageType());
+        message = messages.get(1);
+        assertEquals(ValidationMessage.Type.WARNING, message.getMessageType());
+    }
+
+    /*
+     * Verify an error is logged when resource methods have more than one parameter
+     * that is not annotated with an injection-related annotation
+     */
+    public void testWarnNonConformingParams() throws Exception {
+        List<OperationResourceInfo> opInfoList = TestUtils
+                .getOperationInfoList(ResourceSix.class, null);
+        assertNotNull(opInfoList);
+        assertTrue(opInfoList.size() > 0);
+        JAXRSOperationResourceValidator validator = new JAXRSOperationResourceValidator();
+        List<ValidationMessage> messages = validator.validate(opInfoList);
+        assertNotNull(messages);
+        assertEquals(4, messages.size());
+        ValidationMessage message = messages.get(0);
+        assertEquals(ValidationMessage.Type.ERROR, message.getMessageType());
+
+        message = messages.get(1);
+        assertEquals(ValidationMessage.Type.ERROR, message.getMessageType());
+
+        message = messages.get(2);
+        assertEquals(ValidationMessage.Type.ERROR, message.getMessageType());
+
+        message = messages.get(3);
+        assertEquals(ValidationMessage.Type.ERROR, message.getMessageType());
+    }
+
+    /*
+     * Verify an exception is thrown when error ValidationMessages are encountered
+     */
+    public void testExceptionReporting() throws Exception {
+        ApplicationProcessor processor = new ApplicationProcessor(null, Thread
+                .currentThread().getContextClassLoader());
+        ResourceValidationException rve = null;
+        try {
+            processor.processApplication(new ErrorApplication());
+        } catch (ResourceValidationException e) {
+            rve = e;
+        }
+        assertNotNull(rve);
+    }
+
+    public static class ErrorApplication extends Application {
+
+        public Set<Class<?>> getClasses() {
+            Set<Class<?>> classes = new HashSet<Class<?>>();
+            classes.add(ResourceOne.class);
+            classes.add(ResourceTwo.class);
+            return classes;
+        }
+
+    }
+
+    @Path(value = "/resource")
+    public static class ResourceOne {
+
+        @GET
+        public void get() {
+
+        }
+
+        @GET
+        @Path(value = "/get")
+        public void getWithPath() {
+
+        }
+
+        @POST
+        @Path(value = "/{id}")
+        public void post() {
+
+        }
+
+        @DELETE
+        @Path(value = "/method")
+        public void delete() {
+
+        }
+
+        @PUT
+        @Path(value = "/{id}")
+        public void put() {
+
+        }
+
+        @HEAD
+        @Path(value = "/method")
+        public void head() {
+
+        }
+
+    }
+
+    @Path(value = "/resource")
+    public static class ResourceTwo {
+
+        @GET
+        public void get() {
+
+        }
+
+        @GET
+        public void getToo() {
+
+        }
+
+        @POST
+        public void post() {
+
+        }
+
+    }
+
+    @Path(value = "/resourceThree")
+    public static class ResourceThree {
+
+        @GET
+        @Path(value = "/get")
+        public void get() {
+
+        }
+
+        @GET
+        @Path(value = "/get")
+        public void getToo() {
+
+        }
+
+    }
+
+    @Path(value = "/resourceFour")
+    public static class ResourceFour {
+
+        @Path(value = "/locate")
+        public void locate() {
+
+        }
+
+        @Path(value = "/locate")
+        public void locateToo() {
+
+        }
+
+    }
+
+    @Path(value = "/resourceFive")
+    public static class ResourceFive {
+
+        @Path(value = "/locate")
+        void locate() {
+
+        }
+
+        @GET
+        private void locateToo() {
+
+        }
+
+    }
+
+    @Path(value = "/resourceSix")
+    public static class ResourceSix {
+
+        @Path(value = "/locate")
+        public void locate(@QueryParam(value = "id") String id) {
+
+        }
+
+        @GET
+        public void locateToo(String id) {
+
+        }
+
+        @POST
+        public void create(String id, String body) {
+
+        }
+
+        @DELETE
+        public void delete(String id, @QueryParam(value = "someOtherParam") String someOtherParam, @QueryParam(value = "onemoreParam") String onemore) {
+
+        }
+
+        @PUT
+        public void update(@QueryParam(value = "onemore") String id2, String id) {
+
+        }
+
+        @PUT
+        @Path("/somethingelse")
+        public void update(@QueryParam(value = "onemore") String id2, String id, String other) {
+
+        }
+
+        @GET
+        @Path("/somethingelse")
+        public void locate(String id, String other, @QueryParam(value = "onemore") String id2) {
+
+        }
+
+        @POST
+        @Path("/somethingelse")
+        public void newLoc(@QueryParam(value = "abcd") String id, String other, String other2, @QueryParam(value = "onemore") String id2) {
+
+        }
+    }
+
+    @Path(value = "/anywilldo")
+    public static class AnyConstructorWillDo {
+
+        public AnyConstructorWillDo(@QueryParam(value = "id") String qp) {
+
+        }
+
+        public AnyConstructorWillDo(@QueryParam(value = "id") Integer qp) {
+
+        }
+
+    }
+
+    @Path(value = "badConstructor")
+    public static class BadConstructorResource {
+
+        public BadConstructorResource(String dontKnowHowToHandleThis) {
+
+        }
+
+        public BadConstructorResource(String dontKnowHowToHandleThis, @QueryParam(value = "id") String id) {
+
+        }
+
+        BadConstructorResource() {
+
+        }
+
+    }
+
+    @Path(value = "badConstructor")
+    public static class BadConstructorSingletonResource {
+
+        private BadConstructorSingletonResource(String dontKnowHowToHandleThis) {
+
+        }
+
+        public static BadConstructorSingletonResource getInstance() {
+            return new BadConstructorSingletonResource("someString");
+        }
+    }
+
+    @Path(value = "/singletonwithannotations")
+    public static class SingletonWithAnnotations {
+
+        @HeaderParam(value = "id")
+        private String headerParam;
+
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/web/ServletTestFramework.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/web/ServletTestFramework.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/web/ServletTestFramework.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/web/ServletTestFramework.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,178 @@
+/*
+ * 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 com.ibm.ws.jaxrs.web;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import com.ibm.ws.jaxrs.context.RESTContext;
+import com.ibm.ws.jaxrs.web.mock.ServletConfigImpl;
+import com.ibm.ws.jaxrs.web.mock.ServletOutputStream;
+import com.ibm.ws.jaxrs.web.mock.ServletRequest;
+import com.ibm.ws.jaxrs.web.mock.ServletResponse;
+import com.ibm.ws.jaxrs.web.samples.ServletHost;
+
+public class ServletTestFramework extends TestCase {
+
+    protected static final String URL_BASE = "http://localhost:9080/rest";
+
+    protected static final String CONTEXT_PATH = "/rest";
+
+    // prevent warning reports from junit tests
+    public void testDummy() {
+
+    }
+
+    protected static RESTServlet createServlet(String appName) throws Exception {
+        return createServlet(appName, null);
+    }
+
+    protected static RESTServlet createServlet(String appName, String configFileLocation)
+            throws Exception {
+        Map<String, String> initParams = new HashMap<String, String>();
+        initParams.put("javax.ws.rs.Application", appName);
+        initParams.put("com.ibm.ws.jaxrs.ConfigFile", configFileLocation);
+        ServletConfig config = new ServletConfigImpl(appName, initParams);
+
+        RESTServlet servlet = new RESTServlet();
+        try {
+            servlet.init(config);
+        } catch (ServletException e) {
+            e.printStackTrace();
+            fail(e.toString());
+        }
+
+        return servlet;
+    }
+
+    public static void initContext(HttpServletRequest request, HttpServletResponse response, RESTContext context)
+            throws Exception {
+        RESTServlet servlet = new RESTServlet();
+        servlet.initContext(request, response, context);
+    }
+
+    protected static ServletRequest createServletRequest(String pathInfo, String method) {
+        return ServletTestFramework.createServletRequest(pathInfo, null,
+                method, null);
+    }
+
+    protected static ServletRequest createServletRequest(String pathInfo, String queryString, String method) {
+        return ServletTestFramework.createServletRequest(pathInfo, queryString,
+                method, null);
+    }
+
+    protected static ServletRequest createServletRequest(String pathInfo, String queryString, String method, InputStream content) {
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put(ServletRequest.PATH_INFO, pathInfo);
+        props.put(ServletRequest.CONTENT_TYPE, "text/xml");
+        props.put(ServletRequest.QUERY_STRING, queryString);
+        props.put(ServletRequest.METHOD, method);
+        props.put(ServletRequest.CONTEXT_PATH, CONTEXT_PATH);
+
+        String url = URL_BASE + pathInfo;
+        // If a query string was provided, update both the target URL
+        // and the pathInfo that we have saved off.
+        if (queryString != null && queryString.length() > 0) {
+            //url += "?" + queryString;
+
+            //pathInfo += "?" + queryString;
+            //props.put(ServletRequest.PATH_INFO, pathInfo);
+        }
+
+        ServletRequest request = new ServletRequest(url, content, props);
+        return request;
+    }
+
+    protected static ServletResponse createServletResponse() {
+        StringWriter sw = new StringWriter();
+        return createServletResponse(sw);
+    }
+
+    protected static ServletResponse createServletResponse(StringWriter sw) {
+        ServletResponse response = new ServletResponse(sw);
+        return response;
+    }
+
+    protected static String getContent(ServletResponse response) {
+        if (response != null) {
+            try {
+                ServletOutputStream os = (ServletOutputStream) response
+                        .getOutputStream();
+                StringWriter sw = os.getWriter();
+                if (sw != null) {
+                    return sw.toString();
+                }
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+        }
+
+        return null;
+    }
+
+    public static Test getTestSuite(final int serverPort, final Class<?> testclazz, final Class<?>... resourceClazz) {
+        TestSuite testSuite = new TestSuite(testclazz);
+        testSuite.setName(testclazz.getName());
+        return new TestSetup(testSuite) {
+            ServletHost host;
+
+            @Override
+            protected void setUp() throws Exception {
+                host = new ServletHost(serverPort, resourceClazz);
+                host.init();
+            }
+
+            public void tearDown() throws Exception {
+                host.shutdown();
+            }
+        };
+    }
+
+    public static Test getTestSuite(final int serverPort, final Class<?> testclazz, final String applicationClassName) {
+        TestSuite testSuite = new TestSuite(testclazz);
+        testSuite.setName(testclazz.getName());
+        return new TestSetup(testSuite) {
+            ServletHost host;
+
+            @Override
+            protected void setUp() throws Exception {
+                host = new ServletHost(serverPort, applicationClassName);
+                host.init();
+            }
+
+            public void tearDown() throws Exception {
+                host.shutdown();
+            }
+        };
+    }
+}



Mime
View raw message