Return-Path: Delivered-To: apmail-incubator-wink-commits-archive@minotaur.apache.org Received: (qmail 56878 invoked from network); 23 Jun 2009 10:14:25 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 23 Jun 2009 10:14:25 -0000 Received: (qmail 72254 invoked by uid 500); 23 Jun 2009 10:14:36 -0000 Delivered-To: apmail-incubator-wink-commits-archive@incubator.apache.org Received: (qmail 72147 invoked by uid 500); 23 Jun 2009 10:14:36 -0000 Mailing-List: contact wink-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: wink-dev@incubator.apache.org Delivered-To: mailing list wink-commits@incubator.apache.org Delivered-To: moderator for wink-commits@incubator.apache.org Received: (qmail 93396 invoked by uid 99); 23 Jun 2009 05:40:03 -0000 X-ASF-Spam-Status: No, hits=-1998.5 required=10.0 tests=ALL_TRUSTED,WEIRD_PORT X-Spam-Check-By: apache.org Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r787553 [27/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 -0000 To: wink-commits@incubator.apache.org From: ngallardo@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090623053844.2E5CA23889EC@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/InjectionTests.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/InjectionTests.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/InjectionTests.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/InjectionTests.java Tue Jun 23 05:37:57 2009 @@ -0,0 +1,892 @@ +/* + * 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.lifecycle; + +import java.io.StringWriter; +import java.lang.reflect.Constructor; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.core.Cookie; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Request; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.SecurityContext; +import javax.ws.rs.core.UriInfo; +import javax.ws.rs.core.Response.ResponseBuilder; + +import junit.framework.TestCase; + +import org.apache.cxf.jaxrs.impl.MetadataMap; +import org.apache.cxf.jaxrs.model.ClassResourceInfo; + +import com.ibm.rest.test.utils.TestUtils; +import com.ibm.ws.jaxrs.context.ContextConstants; +import com.ibm.ws.jaxrs.context.RESTContext; +import com.ibm.ws.jaxrs.lifecycle.testimpls.InjectablePropertyResource; +import com.ibm.ws.jaxrs.lifecycle.testimpls.ResourceWithContext; +import com.ibm.ws.jaxrs.lifecycle.testimpls.ResourceWithNoParamAnnotations; +import com.ibm.ws.jaxrs.lifecycle.testimpls.ResourceWithContext.DateHeader; +import com.ibm.ws.jaxrs.lifecycle.testimpls.ResourceWithContext.ResourceWithFormContext; +import com.ibm.ws.jaxrs.lifecycle.testimpls.ResourceWithContext.ResourceWithMoreContext; +import com.ibm.ws.jaxrs.metadata.MetadataRegistry; +import com.ibm.ws.jaxrs.model.JAXRSInfoBuilder; +import com.ibm.ws.jaxrs.model.JAXRSInfoBuilderFactory; +import com.ibm.ws.jaxrs.model.JAXRSInfoInput; +import com.ibm.ws.jaxrs.model.JAXRSInfoOutput; +import com.ibm.ws.jaxrs.web.ServletTestFramework; +import com.ibm.ws.jaxrs.web.mock.Principal; +import com.ibm.ws.jaxrs.web.mock.ServletConfigImpl; +import com.ibm.ws.jaxrs.web.mock.ServletContextImpl; +import com.ibm.ws.jaxrs.web.mock.ServletRequest; +import com.ibm.ws.jaxrs.web.mock.ServletResponse; + +/** + * This class will verify functionality that deals with context injection + * + */ +public class InjectionTests extends TestCase { + + /** + * Test injection of an HttpHeader interface implementation + * + */ + public void testInjectHttpHeaders() throws Exception { + String url = "http://localhost:7070/resources/someresource"; + JAXRSInfoInput source = new JAXRSInfoInput( + JAXRSInfoInput.Type.REFLECTION); + Map> classes = new HashMap>(); + classes.put(ResourceWithContext.class.getName(), + ResourceWithContext.class); + source.setClasses(classes); + JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry + .getImplementation(JAXRSInfoBuilderFactory.class); + JAXRSInfoBuilder builder = factory + .getInfoBuilder(source.getInputType()); + JAXRSInfoOutput output = builder.buildRESTInfo(source); + ClassResourceInfo info = TestUtils.getClassResourceInfo(output + .getClassInfoList(), ResourceWithContext.class.getName()); + assertNotNull(info); + MultivaluedMap values = new MetadataMap(); + RESTContext context = new RESTContext(); + Map props = new HashMap(); + ServletRequest request = new ServletRequest(url, null, props); + ServletResponse response = new ServletResponse(new StringWriter()); + ServletTestFramework.initContext(request, response, context); + context.setProperty(ContextConstants.HTTP_HEADER_VALUES, values); + context.setProperty(ContextConstants.CONTENT_LANGUAGE, "en"); + BaseLifecycleManager mgr = new BaseLifecycleManager(); + Constructor cstr = ResourceWithContext.class + .getDeclaredConstructor(new Class[] { HttpHeaders.class }); + Object[] paramInstances = mgr.getParamInstances(info, context, cstr); + assertNotNull(paramInstances); + assertEquals(1, paramInstances.length); + assertTrue(paramInstances[0] instanceof HttpHeaders); + HttpHeaders httpHeaders = (HttpHeaders) paramInstances[0]; + Locale locale = httpHeaders.getLanguage(); + assertNotNull(locale); + assertEquals("en", locale.getLanguage()); + } + + /** + * Test injection of an UriInfo interface implementation + * + */ + public void testInjectUriInfo() throws Exception { + JAXRSInfoInput source = new JAXRSInfoInput( + JAXRSInfoInput.Type.REFLECTION); + Map> classes = new HashMap>(); + classes.put(ResourceWithContext.class.getName(), + ResourceWithContext.class); + source.setClasses(classes); + JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry + .getImplementation(JAXRSInfoBuilderFactory.class); + JAXRSInfoBuilder builder = factory + .getInfoBuilder(source.getInputType()); + JAXRSInfoOutput output = builder.buildRESTInfo(source); + ClassResourceInfo info = TestUtils.getClassResourceInfo(output + .getClassInfoList(), ResourceWithContext.class.getName()); + assertNotNull(info); + String uri = "http://localhost:9080/agents/007/Bond"; + Map props = new HashMap(); + props.put(ServletRequest.PATH_INFO, "/agents/007/Bond"); + MultivaluedMap values = new MetadataMap(); + values.add("id", "007"); + values.add("name", "Bond"); + RESTContext context = new RESTContext(); + ServletRequest request = new ServletRequest(uri, null, props); + ServletResponse response = new ServletResponse(new StringWriter()); + ServletTestFramework.initContext(request, response, context); + context.setProperty(ContextConstants.TEMPLATE_VALUES, values); + BaseLifecycleManager mgr = new BaseLifecycleManager(); + Constructor cstr = ResourceWithContext.class + .getDeclaredConstructor(new Class[] { UriInfo.class }); + Object[] paramInstances = mgr.getParamInstances(info, context, cstr); + assertNotNull(paramInstances); + assertEquals(1, paramInstances.length); + assertTrue(paramInstances[0] instanceof UriInfo); + UriInfo uriInfo = (UriInfo) paramInstances[0]; + assertNotNull(uriInfo); + assertEquals("http://localhost:9080/agents/007/Bond", uriInfo + .getRequestUri().toString()); + MultivaluedMap pathParams = uriInfo.getPathParameters(); + assertNotNull(pathParams); + assertEquals(2, pathParams.keySet().size()); + List paramValues = pathParams.get("id"); + assertNotNull(paramValues); + assertEquals(1, paramValues.size()); + assertEquals("007", paramValues.get(0)); + paramValues = pathParams.get("name"); + assertNotNull(paramValues); + assertEquals(1, paramValues.size()); + assertEquals("Bond", paramValues.get(0)); + } + + /** + * Test injection of a SecurityContext interface implementation + * + */ + public void testInjectSecurityContext() throws Exception { + String url = "http://localhost:7070/resources/someresource"; + JAXRSInfoInput source = new JAXRSInfoInput( + JAXRSInfoInput.Type.REFLECTION); + Map> classes = new HashMap>(); + classes.put(ResourceWithContext.class.getName(), + ResourceWithContext.class); + source.setClasses(classes); + JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry + .getImplementation(JAXRSInfoBuilderFactory.class); + JAXRSInfoBuilder builder = factory + .getInfoBuilder(source.getInputType()); + JAXRSInfoOutput output = builder.buildRESTInfo(source); + ClassResourceInfo info = TestUtils.getClassResourceInfo(output + .getClassInfoList(), ResourceWithContext.class.getName()); + assertNotNull(info); + MultivaluedMap values = new MetadataMap(); + RESTContext context = new RESTContext(); + Map props = new HashMap(); + props.put(ServletRequest.USER_PRINCIPAL, new Principal("Bond")); + ServletRequest request = new ServletRequest(url, null, props); + ServletResponse response = new ServletResponse(new StringWriter()); + ServletTestFramework.initContext(request, response, context); + BaseLifecycleManager mgr = new BaseLifecycleManager(); + Constructor cstr = ResourceWithContext.class + .getDeclaredConstructor(new Class[] { SecurityContext.class }); + Object[] paramInstances = mgr.getParamInstances(info, context, cstr); + assertNotNull(paramInstances); + assertEquals(1, paramInstances.length); + assertTrue(paramInstances[0] instanceof SecurityContext); + SecurityContext secContext = (SecurityContext) paramInstances[0]; + assertNotNull(secContext); + assertNotNull(secContext.getUserPrincipal()); + assertEquals("Bond", secContext.getUserPrincipal().getName()); + } + + /** + * Test injection of a single value using the @QueryParam annotation + * + */ + public void testInjectSingleQueryParam() throws Exception { + JAXRSInfoInput source = new JAXRSInfoInput( + JAXRSInfoInput.Type.REFLECTION); + Map> classes = new HashMap>(); + classes.put(ResourceWithContext.class.getName(), + ResourceWithContext.class); + source.setClasses(classes); + JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry + .getImplementation(JAXRSInfoBuilderFactory.class); + JAXRSInfoBuilder builder = factory + .getInfoBuilder(source.getInputType()); + JAXRSInfoOutput output = builder.buildRESTInfo(source); + ClassResourceInfo info = TestUtils.getClassResourceInfo(output + .getClassInfoList(), ResourceWithContext.class.getName()); + assertNotNull(info); + MultivaluedMap values = new MetadataMap(); + RESTContext context = new RESTContext(); + values.add("id", "007"); + Constructor cstr = ResourceWithContext.class + .getDeclaredConstructor(new Class[] { String.class }); + context.setProperty(ContextConstants.QUERY_STRING_DECODED_VALUES, + values); + BaseLifecycleManager mgr = new BaseLifecycleManager(); + Object[] paramInstances = mgr.getParamInstances(info, context, cstr); + assertNotNull(paramInstances); + assertEquals(1, paramInstances.length); + assertTrue(paramInstances[0] instanceof String); + String queryParam = (String) paramInstances[0]; + assertNotNull(queryParam); + assertEquals("007", queryParam); + } + + /** + * Test injection of multiple values using the @QueryParam annotation + * + */ + public void testInjectMultipleQueryParamsList() throws Exception { + JAXRSInfoInput source = new JAXRSInfoInput( + JAXRSInfoInput.Type.REFLECTION); + Map> classes = new HashMap>(); + classes.put(ResourceWithContext.class.getName(), + ResourceWithContext.class); + source.setClasses(classes); + JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry + .getImplementation(JAXRSInfoBuilderFactory.class); + JAXRSInfoBuilder builder = factory + .getInfoBuilder(source.getInputType()); + JAXRSInfoOutput output = builder.buildRESTInfo(source); + ClassResourceInfo info = TestUtils.getClassResourceInfo(output + .getClassInfoList(), ResourceWithContext.class.getName()); + assertNotNull(info); + MultivaluedMap values = new MetadataMap(); + RESTContext context = new RESTContext(); + values.add("name", "Bond"); + values.add("name", "James+Bond"); + context.setProperty(ContextConstants.QUERY_STRING_DECODED_VALUES, + values); + BaseLifecycleManager mgr = new BaseLifecycleManager(); + Constructor cstr = ResourceWithContext.class + .getDeclaredConstructor(new Class[] { List.class }); + Object[] paramInstances = mgr.getParamInstances(info, context, cstr); + assertNotNull(paramInstances); + assertEquals(1, paramInstances.length); + assertTrue(paramInstances[0] instanceof List); + List queryParams = (List) paramInstances[0]; + assertNotNull(queryParams); + assertEquals(2, queryParams.size()); + } + + /** + * Test injection of multiple values using the @QueryParam annotation + * + */ + public void testInjectMultipleQueryParamsSortedSet() throws Exception { + JAXRSInfoInput source = new JAXRSInfoInput( + JAXRSInfoInput.Type.REFLECTION); + Map> classes = new HashMap>(); + classes.put(ResourceWithContext.class.getName(), + ResourceWithContext.class); + source.setClasses(classes); + JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry + .getImplementation(JAXRSInfoBuilderFactory.class); + JAXRSInfoBuilder builder = factory + .getInfoBuilder(source.getInputType()); + JAXRSInfoOutput output = builder.buildRESTInfo(source); + ClassResourceInfo info = TestUtils.getClassResourceInfo(output + .getClassInfoList(), ResourceWithContext.class.getName()); + assertNotNull(info); + MultivaluedMap values = new MetadataMap(); + RESTContext context = new RESTContext(); + values.add("name", "James+Bond"); + values.add("name", "Bond"); + context.setProperty(ContextConstants.QUERY_STRING_DECODED_VALUES, + values); + BaseLifecycleManager mgr = new BaseLifecycleManager(); + Constructor cstr = ResourceWithContext.class + .getDeclaredConstructor(new Class[] { SortedSet.class }); + Object[] paramInstances = mgr.getParamInstances(info, context, cstr); + assertNotNull(paramInstances); + assertEquals(1, paramInstances.length); + assertTrue(paramInstances[0] instanceof SortedSet); + SortedSet queryParams = (SortedSet) paramInstances[0]; + assertNotNull(queryParams); + assertEquals(2, queryParams.size()); + assertEquals("Bond", queryParams.first()); + } + + /** + * Test injection of user-defined object using the @HeaderParam annotation + * + */ + public void testInjectHeaderParam() throws Exception { + JAXRSInfoInput source = new JAXRSInfoInput( + JAXRSInfoInput.Type.REFLECTION); + Map> classes = new HashMap>(); + classes.put(ResourceWithContext.class.getName(), + ResourceWithContext.class); + source.setClasses(classes); + JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry + .getImplementation(JAXRSInfoBuilderFactory.class); + JAXRSInfoBuilder builder = factory + .getInfoBuilder(source.getInputType()); + JAXRSInfoOutput output = builder.buildRESTInfo(source); + ClassResourceInfo info = TestUtils.getClassResourceInfo(output + .getClassInfoList(), ResourceWithContext.class.getName()); + assertNotNull(info); + MultivaluedMap values = new MetadataMap(); + RESTContext context = new RESTContext(); + values.add("date-sent", "09/19/08"); + context.setProperty(ContextConstants.HTTP_HEADER_VALUES, values); + BaseLifecycleManager mgr = new BaseLifecycleManager(); + Constructor cstr = ResourceWithContext.class + .getDeclaredConstructor(new Class[] { DateHeader.class }); + Object[] paramInstances = mgr.getParamInstances(info, context, cstr); + assertNotNull(paramInstances); + assertEquals(1, paramInstances.length); + assertTrue(paramInstances[0] instanceof DateHeader); + DateHeader dateHeader = (DateHeader) paramInstances[0]; + assertNotNull(dateHeader); + assertEquals("09/19/08", dateHeader.getDate()); + } + + public void testInjectMatrixParameter() throws Exception { + JAXRSInfoInput source = new JAXRSInfoInput( + JAXRSInfoInput.Type.REFLECTION); + Map> classes = new HashMap>(); + classes.put(ResourceWithContext.class.getName(), + ResourceWithContext.class); + source.setClasses(classes); + JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry + .getImplementation(JAXRSInfoBuilderFactory.class); + JAXRSInfoBuilder builder = factory + .getInfoBuilder(source.getInputType()); + JAXRSInfoOutput output = builder.buildRESTInfo(source); + ClassResourceInfo info = TestUtils.getClassResourceInfo(output + .getClassInfoList(), ResourceWithContext.class.getName()); + assertNotNull(info); + MultivaluedMap decodedValues = new MetadataMap(); + RESTContext context = new RESTContext(); + decodedValues.add("id", "007"); + decodedValues.add("last name", "Bond"); + decodedValues.add("first name", "James"); + context.setProperty(ContextConstants.MATRIX_PARAMETER_VALUES_DECODED, + decodedValues); + MultivaluedMap encodedValues = new MetadataMap(); + encodedValues.add("id", "007"); + encodedValues.add("last%20name", "Bond"); + encodedValues.add("first%20name", "James"); + context.setProperty(ContextConstants.MATRIX_PARAMETER_VALUES_ENCODED, + encodedValues); + BaseLifecycleManager mgr = new BaseLifecycleManager(); + Constructor cstr = ResourceWithContext.class + .getDeclaredConstructor(new Class[] { String.class, + String.class, String.class }); + Object[] paramInstances = mgr.getParamInstances(info, context, cstr); + assertNotNull(paramInstances); + assertEquals(3, paramInstances.length); + assertEquals("007", paramInstances[0]); + assertEquals("James", paramInstances[1]); + assertEquals("Bond", paramInstances[2]); + + // now try with the constructor that is using encoded values in the @MatrixParam annotation + cstr = ResourceWithContext.class.getDeclaredConstructor(new Class[] { + String.class, String.class }); + paramInstances = mgr.getParamInstances(info, context, cstr); + assertNotNull(paramInstances); + assertEquals(2, paramInstances.length); + assertEquals("James", paramInstances[0]); + assertEquals("Bond", paramInstances[1]); + } + + /** + * Test injection of values using the @FormParam annotation + * + */ + public void testInjectFormParam() throws Exception { + JAXRSInfoInput source = new JAXRSInfoInput( + JAXRSInfoInput.Type.REFLECTION); + Map> classes = new HashMap>(); + classes.put(ResourceWithFormContext.class.getName(), + ResourceWithFormContext.class); + source.setClasses(classes); + JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry + .getImplementation(JAXRSInfoBuilderFactory.class); + JAXRSInfoBuilder builder = factory + .getInfoBuilder(source.getInputType()); + JAXRSInfoOutput output = builder.buildRESTInfo(source); + ClassResourceInfo info = TestUtils.getClassResourceInfo(output + .getClassInfoList(), ResourceWithFormContext.class.getName()); + assertNotNull(info); + MultivaluedMap values = new MetadataMap(); + RESTContext context = new RESTContext(); + values.add("id", "007"); + values.add("name", "James Bond"); + context.setProperty(ContextConstants.FORM_VALUES, values); + BaseLifecycleManager mgr = new BaseLifecycleManager(); + Constructor cstr = ResourceWithFormContext.class + .getDeclaredConstructor(new Class[] { String.class, + String.class }); + Object[] paramInstances = mgr.getParamInstances(info, context, cstr); + assertNotNull(paramInstances); + assertEquals(2, paramInstances.length); + assertTrue(paramInstances[0] instanceof String); + String formParam = (String) paramInstances[0]; + assertEquals("007", formParam); + assert (paramInstances[1] instanceof String); + formParam = (String) paramInstances[1]; + assertEquals("James Bond", formParam); + } + + public void testInjectPathParam() throws Exception { + JAXRSInfoInput source = new JAXRSInfoInput( + JAXRSInfoInput.Type.REFLECTION); + Map> classes = new HashMap>(); + classes.put(ResourceWithMoreContext.class.getName(), + ResourceWithMoreContext.class); + source.setClasses(classes); + JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry + .getImplementation(JAXRSInfoBuilderFactory.class); + JAXRSInfoBuilder builder = factory + .getInfoBuilder(source.getInputType()); + JAXRSInfoOutput output = builder.buildRESTInfo(source); + ClassResourceInfo info = TestUtils.getClassResourceInfo(output + .getClassInfoList(), ResourceWithMoreContext.class.getName()); + assertNotNull(info); + RESTContext context = new RESTContext(); + MultivaluedMap values = new MetadataMap(); + values.add("id", "007"); + context.setProperty(ContextConstants.TEMPLATE_VALUES, values); + Constructor cstr = ResourceWithMoreContext.class + .getDeclaredConstructor(new Class[] { String.class }); + BaseLifecycleManager mgr = new BaseLifecycleManager(); + Object[] paramInstances = mgr.getParamInstances(info, context, cstr); + assertNotNull(paramInstances); + assertEquals(1, paramInstances.length); + assertEquals("007", paramInstances[0]); + } + + public void testInjectCookieParam() throws Exception { + JAXRSInfoInput source = new JAXRSInfoInput( + JAXRSInfoInput.Type.REFLECTION); + Map> classes = new HashMap>(); + classes.put(ResourceWithMoreContext.class.getName(), + ResourceWithMoreContext.class); + source.setClasses(classes); + JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry + .getImplementation(JAXRSInfoBuilderFactory.class); + JAXRSInfoBuilder builder = factory + .getInfoBuilder(source.getInputType()); + JAXRSInfoOutput output = builder.buildRESTInfo(source); + ClassResourceInfo info = TestUtils.getClassResourceInfo(output + .getClassInfoList(), ResourceWithMoreContext.class.getName()); + assertNotNull(info); + MultivaluedMap values = new MetadataMap(); + values.add("Cookie", "cookie1=cookieValue1;$Version=1"); + RESTContext context = new RESTContext(); + context.setProperty(ContextConstants.HTTP_HEADER_VALUES, values); + Map cookies = new HashMap(); + cookies.put("cookie1", new Cookie("cookie1", "cookieValue1")); + context.setProperty(ContextConstants.HTTP_COOKIES, cookies); + + // first test the injection of a cookie type + Constructor cstr = ResourceWithMoreContext.class + .getDeclaredConstructor(new Class[] { Cookie.class }); + BaseLifecycleManager mgr = new BaseLifecycleManager(); + Object[] paramInstances = mgr.getParamInstances(info, context, cstr); + assertNotNull(paramInstances); + assertEquals(1, paramInstances.length); + assertTrue(paramInstances[0] instanceof Cookie); + Cookie cookie = (Cookie) paramInstances[0]; + assertNotNull(cookie); + assertEquals("cookieValue1", cookie.getValue()); + assertEquals(1, cookie.getVersion()); + + // now ensure we can inject into a type of String as well (this should inject the + // value of the cookie) + cstr = ResourceWithMoreContext.class + .getDeclaredConstructor(new Class[] { Cookie.class, + String.class }); + mgr = new BaseLifecycleManager(); + paramInstances = mgr.getParamInstances(info, context, cstr); + assertNotNull(paramInstances); + assertEquals(2, paramInstances.length); + assertTrue(paramInstances[0] instanceof Cookie); + cookie = (Cookie) paramInstances[0]; + assertNotNull(cookie); + assertEquals("cookieValue1", cookie.getValue()); + assertEquals(1, cookie.getVersion()); + + assertTrue(paramInstances[1] instanceof String); + String cookieValue = (String) paramInstances[1]; + assertEquals("cookieValue1", cookieValue); + } + + /** + * Test the injection of the HttpServletRequest object + */ + public void testInjectHttpServletRequest() throws Exception { + JAXRSInfoInput source = new JAXRSInfoInput( + JAXRSInfoInput.Type.REFLECTION); + Map> classes = new HashMap>(); + classes.put(ResourceWithContext.class.getName(), + ResourceWithContext.class); + source.setClasses(classes); + JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry + .getImplementation(JAXRSInfoBuilderFactory.class); + JAXRSInfoBuilder builder = factory + .getInfoBuilder(source.getInputType()); + JAXRSInfoOutput output = builder.buildRESTInfo(source); + ClassResourceInfo info = TestUtils.getClassResourceInfo(output + .getClassInfoList(), ResourceWithContext.class.getName()); + assertNotNull(info); + RESTContext context = new RESTContext(); + Map properties = new HashMap(); + Map> headers = new HashMap>(); + List customHeaderValues = new LinkedList(); + customHeaderValues.add("thisUser"); + headers.put("custom-header", customHeaderValues); + properties.put(ServletRequest.HTTP_HEADERS, headers); + ServletRequest request = new ServletRequest(properties); + context.setProperty(ContextConstants.SERVLET_REQUEST, request); + BaseLifecycleManager mgr = new BaseLifecycleManager(); + Constructor cstr = ResourceWithContext.class + .getDeclaredConstructor(new Class[] { HttpServletRequest.class }); + Object[] paramInstances = mgr.getParamInstances(info, context, cstr); + assertNotNull(paramInstances); + assertEquals(1, paramInstances.length); + assertTrue(paramInstances[0] instanceof HttpServletRequest); + HttpServletRequest req = (HttpServletRequest) paramInstances[0]; + assertNotNull(req.getHeader("custom-header")); + assertEquals("thisUser", req.getHeader("custom-header")); + } + + public void testInjectHttpServletResponse() throws Exception { + JAXRSInfoInput source = new JAXRSInfoInput( + JAXRSInfoInput.Type.REFLECTION); + Map> classes = new HashMap>(); + classes.put(ResourceWithContext.class.getName(), + ResourceWithContext.class); + source.setClasses(classes); + JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry + .getImplementation(JAXRSInfoBuilderFactory.class); + JAXRSInfoBuilder builder = factory + .getInfoBuilder(source.getInputType()); + JAXRSInfoOutput output = builder.buildRESTInfo(source); + ClassResourceInfo info = TestUtils.getClassResourceInfo(output + .getClassInfoList(), ResourceWithContext.class.getName()); + assertNotNull(info); + RESTContext context = new RESTContext(); + StringWriter sw = new StringWriter(); + ServletResponse response = new ServletResponse(sw); + context.setProperty(ContextConstants.SERVLET_RESPONSE, response); + Constructor cstr = ResourceWithContext.class + .getDeclaredConstructor(new Class[] { HttpServletResponse.class }); + BaseLifecycleManager mgr = new BaseLifecycleManager(); + Object[] paramInstances = mgr.getParamInstances(info, context, cstr); + assertNotNull(paramInstances); + assertEquals(1, paramInstances.length); + assertTrue(paramInstances[0] instanceof HttpServletResponse); + HttpServletResponse httpResponse = (HttpServletResponse) paramInstances[0]; + httpResponse.getWriter().write("test"); + assertEquals("test", sw.toString()); + } + + public void testInjectServletConfig() throws Exception { + JAXRSInfoInput source = new JAXRSInfoInput( + JAXRSInfoInput.Type.REFLECTION); + Map> classes = new HashMap>(); + classes.put(ResourceWithContext.class.getName(), + ResourceWithContext.class); + source.setClasses(classes); + JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry + .getImplementation(JAXRSInfoBuilderFactory.class); + JAXRSInfoBuilder builder = factory + .getInfoBuilder(source.getInputType()); + JAXRSInfoOutput output = builder.buildRESTInfo(source); + ClassResourceInfo info = TestUtils.getClassResourceInfo(output + .getClassInfoList(), ResourceWithContext.class.getName()); + assertNotNull(info); + RESTContext context = new RESTContext(); + ServletConfig config = new ServletConfigImpl("testServlet"); + context.setProperty(ContextConstants.SERVLET_CONFIG, config); + Constructor cstr = ResourceWithContext.class + .getDeclaredConstructor(new Class[] { ServletConfig.class }); + BaseLifecycleManager mgr = new BaseLifecycleManager(); + Object[] paramInstances = mgr.getParamInstances(info, context, cstr); + assertNotNull(paramInstances); + assertEquals(1, paramInstances.length); + assertTrue(paramInstances[0] instanceof ServletConfig); + ServletConfig injectedConfig = (ServletConfig) paramInstances[0]; + assertEquals("testServlet", injectedConfig.getServletName()); + } + + public void testInjectServletContext() throws Exception { + JAXRSInfoInput source = new JAXRSInfoInput( + JAXRSInfoInput.Type.REFLECTION); + Map> classes = new HashMap>(); + classes.put(ResourceWithContext.class.getName(), + ResourceWithContext.class); + source.setClasses(classes); + JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry + .getImplementation(JAXRSInfoBuilderFactory.class); + JAXRSInfoBuilder builder = factory + .getInfoBuilder(source.getInputType()); + JAXRSInfoOutput output = builder.buildRESTInfo(source); + ClassResourceInfo info = TestUtils.getClassResourceInfo(output + .getClassInfoList(), ResourceWithContext.class.getName()); + assertNotNull(info); + RESTContext context = new RESTContext(); + ServletContext servletContext = new ServletContextImpl("/path"); + context.setProperty(ContextConstants.SERVLET_CONTEXT, servletContext); + Constructor cstr = ResourceWithContext.class + .getDeclaredConstructor(new Class[] { ServletContext.class }); + BaseLifecycleManager mgr = new BaseLifecycleManager(); + Object[] paramInstances = mgr.getParamInstances(info, context, cstr); + assertNotNull(paramInstances); + assertEquals(1, paramInstances.length); + assertTrue(paramInstances[0] instanceof ServletContext); + ServletContext injectedContext = (ServletContext) paramInstances[0]; + assertEquals("/path", injectedContext.getContextPath()); + } + + /** + * Test the injection of a Request implementation + */ + public void testInjectRequest() throws Exception { + JAXRSInfoInput source = new JAXRSInfoInput( + JAXRSInfoInput.Type.REFLECTION); + Map> classes = new HashMap>(); + classes.put(ResourceWithContext.class.getName(), + ResourceWithContext.class); + source.setClasses(classes); + JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry + .getImplementation(JAXRSInfoBuilderFactory.class); + JAXRSInfoBuilder builder = factory + .getInfoBuilder(source.getInputType()); + JAXRSInfoOutput output = builder.buildRESTInfo(source); + ClassResourceInfo info = TestUtils.getClassResourceInfo(output + .getClassInfoList(), ResourceWithContext.class.getName()); + assertNotNull(info); + BaseLifecycleManager mgr = new BaseLifecycleManager(); + Constructor cstr = ResourceWithContext.class + .getDeclaredConstructor(new Class[] { Request.class }); + + // setup the context + RESTContext context = new RESTContext(); + MultivaluedMap mValuedHeaders = new MetadataMap(); + Map properties = new HashMap(); + properties.put(ServletRequest.CONTENT_TYPE, "text/xml"); + properties.put(ServletRequest.CHAR_ENCODING, "custom"); + Map> headers = new HashMap>(); + List hValues = new LinkedList(); + hValues.add("en-gb"); + headers.put("Content-Language", hValues); + properties.put(ServletRequest.METHOD, "POST"); + properties.put(ServletRequest.HTTP_HEADERS, headers); + Calendar calendar = Calendar.getInstance(); + calendar.set(2007, 0, 21); + Date date = calendar.getTime(); + SimpleDateFormat dateFormat = new SimpleDateFormat( + "EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH); + dateFormat.setLenient(false); + String dateString = dateFormat.format(date); + mValuedHeaders.putSingle("If-Modified-Since".toLowerCase(), dateString); + ServletRequest servletRequest = new ServletRequest(properties); + context.setProperty(ContextConstants.SERVLET_REQUEST, servletRequest); + context + .setProperty(ContextConstants.HTTP_HEADER_VALUES, + mValuedHeaders); + + Object[] paramInstances = mgr.getParamInstances(info, context, cstr); + assertNotNull(paramInstances); + assertTrue(paramInstances[0] instanceof Request); + Request request = (Request) paramInstances[0]; + ResponseBuilder rb = request.evaluatePreconditions(date); + assertNull(rb); + + // now force a bad one to make sure we have a good implementation of Request + calendar.set(2006, 1, 21); + rb = request.evaluatePreconditions(calendar.getTime()); + assertNotNull(rb); + Response response = rb.build(); + assertNotNull(response); + assertEquals(304, response.getStatus()); + } + + /** + * Test the injection of @DefaultValue when the specified parameter is not available. + * + */ + public void testDefaultValue() throws Exception { + JAXRSInfoInput source = new JAXRSInfoInput( + JAXRSInfoInput.Type.REFLECTION); + Map> classes = new HashMap>(); + classes.put(ResourceWithFormContext.class.getName(), + ResourceWithFormContext.class); + source.setClasses(classes); + JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry + .getImplementation(JAXRSInfoBuilderFactory.class); + JAXRSInfoBuilder builder = factory + .getInfoBuilder(source.getInputType()); + JAXRSInfoOutput output = builder.buildRESTInfo(source); + ClassResourceInfo info = TestUtils.getClassResourceInfo(output + .getClassInfoList(), ResourceWithFormContext.class.getName()); + assertNotNull(info); + + // don't insert anything into the map as we are testing for @DefaultValue + MultivaluedMap values = new MetadataMap(); + RESTContext context = new RESTContext(); + BaseLifecycleManager mgr = new BaseLifecycleManager(); + Constructor cstr = ResourceWithFormContext.class + .getDeclaredConstructor(new Class[] { String.class, + String.class }); + Object[] paramInstances = mgr.getParamInstances(info, context, cstr); + assertNotNull(paramInstances); + assertEquals(2, paramInstances.length); + assertTrue(paramInstances[0] instanceof String); + String formParam = (String) paramInstances[0]; + assertEquals("007", formParam); + assert (paramInstances[1] instanceof String); + formParam = (String) paramInstances[1]; + assertEquals("James Bond", formParam); + } + + /** + * Test the injection of non-context annotations (i.e. @QueryParam, @HeaderParam) + * on fields and methods of a resource class. + * + */ + public void testInjectNonContextValues() throws Exception { + JAXRSInfoInput source = new JAXRSInfoInput( + JAXRSInfoInput.Type.REFLECTION); + Map> classes = new HashMap>(); + classes.put(InjectablePropertyResource.class.getName(), + InjectablePropertyResource.class); + source.setClasses(classes); + JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry + .getImplementation(JAXRSInfoBuilderFactory.class); + JAXRSInfoBuilder builder = factory + .getInfoBuilder(source.getInputType()); + JAXRSInfoOutput output = builder.buildRESTInfo(source); + ClassResourceInfo info = TestUtils + .getClassResourceInfo(output.getClassInfoList(), + InjectablePropertyResource.class.getName()); + assertNotNull(info); + + RESTContext context = new RESTContext(); + + // initialize headers + MultivaluedMap headerMap = new MetadataMap(); + List headerValues = new LinkedList(); + headerValues.add("myHeaderValues1"); + headerValues.add("myHeaderValues2"); + headerMap.put("myHeaderParam".toLowerCase(), headerValues); + context.setProperty(ContextConstants.HTTP_HEADER_VALUES, headerMap); + + // initialize matrix params + MultivaluedMap matrixMap = new MetadataMap(); + matrixMap.putSingle("myMatrixParam", "myMatrixValue1"); + context.setProperty(ContextConstants.MATRIX_PARAMETER_VALUES_DECODED, + matrixMap); + + // initialize form params + MultivaluedMap formMap = new MetadataMap(); + formMap.putSingle("myFormParam", "myFormValue1"); + context.setProperty(ContextConstants.FORM_VALUES, formMap); + + // initialize query params + MultivaluedMap queryMap = new MetadataMap(); + queryMap.putSingle("myQueryParam", "myQueryValue1"); + context.setProperty(ContextConstants.QUERY_STRING_DECODED_VALUES, + queryMap); + + ResourceLifecycleManager mgr = new ResourceLifecycleManager(); + InjectablePropertyResource resource = (InjectablePropertyResource) mgr + .createInstance(info, context); + assertNotNull(resource); + + assertEquals("Expected 'myMatrixValue1' but got: " + + resource.getMyMatrixParam(), "myMatrixValue1", resource + .getMyMatrixParam()); + assertEquals("Expected 'myFormValue1' but got: " + + resource.getFormParam(), "myFormValue1", resource + .getFormParam()); + assertEquals("Expected 'myQueryValue1' but got: " + + resource.getMyQueryParam(), "myQueryValue1", resource + .getMyQueryParam()); + List headers = resource.getMyHeaderParams(); + assertNotNull(headers); + assertEquals("Expected header value list size of 2 but got: " + + headers.size(), 2, headers.size()); + String value = headers.get(0); + assertEquals("Expected 'myheaderValues1' but got: " + value, + "myHeaderValues1", value); + value = headers.get(1); + assertEquals("Expected 'myheaderValues2' but got: " + value, + "myHeaderValues2", value); + + } + + public void testResourceWithTypesNotAnnotated() throws Exception { + JAXRSInfoInput source = new JAXRSInfoInput( + JAXRSInfoInput.Type.REFLECTION); + Map> classes = new HashMap>(); + classes.put(ResourceWithNoParamAnnotations.class.getName(), + ResourceWithNoParamAnnotations.class); + source.setClasses(classes); + JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry + .getImplementation(JAXRSInfoBuilderFactory.class); + JAXRSInfoBuilder builder = factory + .getInfoBuilder(source.getInputType()); + JAXRSInfoOutput output = builder.buildRESTInfo(source); + ClassResourceInfo info = TestUtils.getClassResourceInfo(output + .getClassInfoList(), ResourceWithNoParamAnnotations.class + .getName()); + assertNotNull(info); + + RESTContext context = new RESTContext(); + + // initialize query params + MultivaluedMap queryMap = new MetadataMap(); + queryMap.putSingle("myQueryParamList", "myQueryValue1"); + context.setProperty(ContextConstants.QUERY_STRING_DECODED_VALUES, + queryMap); + + ResourceLifecycleManager mgr = new ResourceLifecycleManager(); + ResourceWithNoParamAnnotations resource = (ResourceWithNoParamAnnotations) mgr + .createInstance(info, context); + assertNotNull(resource); + + assertEquals(null, resource.getMyQueryParamsString()); + assertEquals("StringValue1", resource + .getMyQueryParamsStringNoAnnotation()); + + List l = new ArrayList(); + l.add("ListValue1"); + l.add("ListValue2"); + assertEquals(Collections.emptyList(), resource.getMyQueryParamsList()); + assertEquals(l, resource.getMyQueryParamsListNoAnnotation()); + + Set s = new HashSet(); + s.add("SetValue1"); + s.add("SetValue2"); + assertEquals(Collections.emptySet(), resource.getMyQueryParamsSet()); + assertEquals(s, resource.getMyQueryParamsSetNoAnnotation()); + + assertEquals(0, resource.getMyQueryParamsInt()); + assertEquals(99, resource.getMyQueryParamsIntNoAnnotation()); + } + +} Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/LifecycleTests.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/LifecycleTests.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/LifecycleTests.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/LifecycleTests.java Tue Jun 23 05:37:57 2009 @@ -0,0 +1,296 @@ +/* + * 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.lifecycle; + +import java.lang.reflect.Constructor; +import java.util.HashMap; +import java.util.Map; + +import javax.ws.rs.Path; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.Request; +import javax.ws.rs.core.SecurityContext; + +import junit.framework.TestCase; + +import org.apache.cxf.jaxrs.model.ClassResourceInfo; +import org.apache.cxf.jaxrs.model.ProviderInfo; + +import com.ibm.rest.test.utils.TestUtils; +import com.ibm.ws.jaxrs.context.RESTContext; +import com.ibm.ws.jaxrs.lifecycle.testimpls.ContextConstructor; +import com.ibm.ws.jaxrs.lifecycle.testimpls.MultiAnnotationCstr; +import com.ibm.ws.jaxrs.lifecycle.testimpls.MultiContextCstr; +import com.ibm.ws.jaxrs.lifecycle.testimpls.ResourceBadCstr; +import com.ibm.ws.jaxrs.lifecycle.testimpls.ResourceDefaultCstr; +import com.ibm.ws.jaxrs.lifecycle.testimpls.ResourceDefaultCstrSingleton; +import com.ibm.ws.jaxrs.lifecycle.testimpls.StringWriterBadCstr; +import com.ibm.ws.jaxrs.lifecycle.testimpls.StringWriterDefaultCstr; +import com.ibm.ws.jaxrs.lifecycle.testimpls.StringWriterDefaultCstrSingleton; +import com.ibm.ws.jaxrs.metadata.MetadataRegistry; +import com.ibm.ws.jaxrs.model.JAXRSInfoBuilder; +import com.ibm.ws.jaxrs.model.JAXRSInfoBuilderFactory; +import com.ibm.ws.jaxrs.model.JAXRSInfoInput; +import com.ibm.ws.jaxrs.model.JAXRSInfoOutput; +import com.ibm.ws.jaxrs.model.reflective.AbstractResourceInfoImpl; +import com.ibm.ws.jaxrs.model.reflective.ClassResourceInfoImpl; +import com.ibm.ws.jaxrs.model.reflective.ProviderInfoImpl; + +/** + * These tests will verify functionality that creates instances of JAX-RS + * provider classes. + * + */ +public class LifecycleTests extends TestCase { + + private ProviderInfo providerDefaultCstr; + + // this provider class will NOT have a public constructor + private ProviderInfo providerBadCstr; + + private ClassResourceInfo resourceDefaultCstr; + + // this resource class will NOT have a public constructor + private ClassResourceInfo resourceBadCstr; + + // this will be a singleton + private ClassResourceInfo resourceDefaultCstrSingleton; + + // this will be a singleton + private ProviderInfo providerDefaultCstrSingleton; + + private Object resourceSingleton; + + private Object providerSingleton; + + public void setUp() throws Exception { + JAXRSInfoInput source = new JAXRSInfoInput( + JAXRSInfoInput.Type.REFLECTION); + Map> classes = new HashMap>(); + classes.put(StringWriterDefaultCstr.class.getName(), + StringWriterDefaultCstr.class); + classes.put(StringWriterBadCstr.class.getName(), + StringWriterBadCstr.class); + classes.put(ResourceDefaultCstr.class.getName(), + ResourceDefaultCstr.class); + classes.put(ResourceBadCstr.class.getName(), ResourceBadCstr.class); + resourceSingleton = new ResourceDefaultCstrSingleton(); + providerSingleton = new StringWriterDefaultCstrSingleton(); + source.addInfo(ResourceDefaultCstrSingleton.class.getName(), + ResourceDefaultCstrSingleton.class, resourceSingleton); + source.addInfo(StringWriterDefaultCstrSingleton.class.getName(), + StringWriterDefaultCstrSingleton.class, providerSingleton); + source.setClasses(classes); + JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry + .getImplementation(JAXRSInfoBuilderFactory.class); + JAXRSInfoBuilder builder = factory + .getInfoBuilder(source.getInputType()); + JAXRSInfoOutput output = builder.buildRESTInfo(source); + providerDefaultCstr = TestUtils + .getProviderInfo(output.getProviderInfoList(), + StringWriterDefaultCstr.class.getName()); + assertNotNull(providerDefaultCstr); + providerBadCstr = TestUtils.getProviderInfo(output + .getProviderInfoList(), StringWriterBadCstr.class.getName()); + assertNull(providerBadCstr); + resourceDefaultCstr = TestUtils.getClassResourceInfo(output + .getClassInfoList(), ResourceDefaultCstr.class.getName()); + assertNotNull(resourceDefaultCstr); + resourceBadCstr = TestUtils.getClassResourceInfo(output + .getClassInfoList(), ResourceBadCstr.class.getName()); + assertNotNull(resourceBadCstr); + resourceDefaultCstrSingleton = TestUtils.getClassResourceInfo(output + .getClassInfoList(), ResourceDefaultCstrSingleton.class + .getName()); + assertNotNull(resourceDefaultCstrSingleton); + providerDefaultCstrSingleton = TestUtils.getProviderInfo(output + .getProviderInfoList(), StringWriterDefaultCstrSingleton.class + .getName()); + assertNotNull(providerDefaultCstrSingleton); + + } + + /** + * Verify we successfully create an instance of a provider based on + * ProviderInfo. + */ + public void testCreateProviderSimple() { + Object providerInstance = null; + LifecycleManager mgr = LifecycleManagerFactory + .getLifeCycleManager(providerDefaultCstr); + assertTrue(mgr instanceof ProviderLifecycleManager); + RESTContext context = new RESTContext(); + try { + providerInstance = mgr.createInstance(providerDefaultCstr, context); + } catch (WebApplicationException e) { + e.printStackTrace(); + fail(e.toString()); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + fail(e.toString()); + } + assertNotNull(providerInstance); + assertTrue(providerInstance instanceof StringWriterDefaultCstr); + } + + /** + * Verify error conditions around provider instance creation. + */ + public void testBadCreateProvider() { + + // first let's make sure an IllegalArgumentException is thrown when + // the input is bad + IllegalArgumentException iae = null; + ProviderInfo badInfo = new ProviderInfoImpl(null); + LifecycleManager mgr = LifecycleManagerFactory + .getLifeCycleManager(badInfo); + assertTrue(mgr instanceof ProviderLifecycleManager); + RESTContext context = new RESTContext(); + try { + mgr.createInstance(badInfo, context); + } catch (WebApplicationException e) { + } catch (IllegalArgumentException e) { + iae = e; + } + assertNotNull(iae); + + // now let's make sure we get a ProviderLifecycleException if an error + // occurs + // during instance creation + WebApplicationException wae = null; + try { + mgr.createInstance(providerBadCstr, context); + } catch (WebApplicationException e) { + wae = e; + } catch (IllegalArgumentException e) { + } + assertNull(wae); + + } + + /** + * Verify we successfully create an instance of a resource based on + * ClassResourceInfo. + */ + public void testCreateResourceSimple() { + Object resourceInstance = null; + LifecycleManager mgr = LifecycleManagerFactory + .getLifeCycleManager(resourceDefaultCstr); + assertTrue(mgr instanceof ResourceLifecycleManager); + RESTContext context = new RESTContext(); + try { + resourceInstance = mgr.createInstance(resourceDefaultCstr, context); + } catch (WebApplicationException e) { + e.printStackTrace(); + fail(e.toString()); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + fail(e.toString()); + } + assertNotNull(resourceInstance); + assertTrue(resourceInstance instanceof ResourceDefaultCstr); + } + + /** + * Verify error conditions around resource instance creation. + */ + public void testBadCreateResource() { + + // first let's make sure an IllegalArgumentException is thrown when + // the input is bad + IllegalArgumentException iae = null; + ClassResourceInfo badInfo = new ClassResourceInfoImpl(null); + LifecycleManager mgr = LifecycleManagerFactory + .getLifeCycleManager(badInfo); + assertTrue(mgr instanceof ResourceLifecycleManager); + RESTContext context = new RESTContext(); + try { + mgr.createInstance(badInfo, context); + } catch (WebApplicationException e) { + } catch (IllegalArgumentException e) { + iae = e; + } + assertNotNull(iae); + + // now let's make sure we get a ProviderLifecycleException if an error + // occurs + // during instance creation + WebApplicationException wae = null; + try { + mgr.createInstance(resourceBadCstr, context); + } catch (WebApplicationException e) { + wae = e; + } catch (IllegalArgumentException e) { + } + assertNull(wae); + + } + + /* + * Verify that we do not create instances for singletons + */ + public void testCreateSingleton() throws Exception { + Object instance = null; + LifecycleManager mgr = LifecycleManagerFactory + .getLifeCycleManager(resourceDefaultCstrSingleton); + assertTrue(mgr instanceof ResourceLifecycleManager); + RESTContext context = new RESTContext(); + try { + instance = mgr + .createInstance(resourceDefaultCstrSingleton, context); + } catch (WebApplicationException e) { + e.printStackTrace(); + fail(e.toString()); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + fail(e.toString()); + } + assertNotNull(instance); + assertTrue(instance instanceof ResourceDefaultCstrSingleton); + assertEquals(resourceSingleton, instance); + + mgr = LifecycleManagerFactory + .getLifeCycleManager(providerDefaultCstrSingleton); + assertTrue(mgr instanceof ProviderLifecycleManager); + context = new RESTContext(); + try { + instance = mgr + .createInstance(providerDefaultCstrSingleton, context); + } catch (WebApplicationException e) { + e.printStackTrace(); + fail(e.toString()); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + fail(e.toString()); + } + assertNotNull(instance); + assertTrue(instance instanceof StringWriterDefaultCstrSingleton); + assertEquals(providerSingleton, instance); + } + + @Path(value = "/simplecstr") + public class SimpleCstr { + public SimpleCstr() { + + } + } + +} Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/ContextConstructor.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/ContextConstructor.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/ContextConstructor.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/ContextConstructor.java Tue Jun 23 05:37:57 2009 @@ -0,0 +1,37 @@ +/* + * 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.lifecycle.testimpls; + +import javax.ws.rs.Path; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; + +@Path(value = "/contextconstructor") +public class ContextConstructor { + + public ContextConstructor() { + + } + + public ContextConstructor(@Context HttpHeaders httpHeaders) { + + } + +} Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/InjectablePropertyResource.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/InjectablePropertyResource.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/InjectablePropertyResource.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/InjectablePropertyResource.java Tue Jun 23 05:37:57 2009 @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.ibm.ws.jaxrs.lifecycle.testimpls; + +import java.util.List; + +import javax.ws.rs.FormParam; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.MatrixParam; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +@Path(value = "/injectablePropertyResource") +public class InjectablePropertyResource { + + @MatrixParam("myMatrixParam") + private String myMatrixParam; + + @QueryParam("myQueryParam") + private String myQueryParam; + + @HeaderParam("myHeaderParam") + private List myHeaderParams; + + private String formParam; + + @FormParam("myFormParam") + public void setFormParam(String fp) { + formParam = fp; + } + + public String getMyMatrixParam() { + return myMatrixParam; + } + + public String getMyQueryParam() { + return myQueryParam; + } + + public List getMyHeaderParams() { + return myHeaderParams; + } + + public String getFormParam() { + return formParam; + } + +} Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/MultiAnnotationCstr.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/MultiAnnotationCstr.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/MultiAnnotationCstr.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/MultiAnnotationCstr.java Tue Jun 23 05:37:57 2009 @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.ibm.ws.jaxrs.lifecycle.testimpls; + +import javax.ws.rs.HeaderParam; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.Request; +import javax.ws.rs.core.SecurityContext; +import javax.ws.rs.core.UriInfo; + +public class MultiAnnotationCstr { + + public MultiAnnotationCstr() { + + } + + public MultiAnnotationCstr(@Context HttpHeaders headers, @Context SecurityContext secContext, @Context Request request, @Context UriInfo uriInfo, String something) { + + } + + public MultiAnnotationCstr(@Context HttpHeaders headers, @Context SecurityContext secContext, @Context Request request) { + + } + + // this cstr should be picked + public MultiAnnotationCstr(@Context HttpHeaders headers, @Context SecurityContext secContext, @Context Request request, @HeaderParam(value = "blah") String hParam, @QueryParam(value = "blah") String qParam) { + } + +} Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/MultiContextCstr.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/MultiContextCstr.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/MultiContextCstr.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/MultiContextCstr.java Tue Jun 23 05:37:57 2009 @@ -0,0 +1,45 @@ +/* + * 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.lifecycle.testimpls; + +import javax.ws.rs.Path; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.Request; +import javax.ws.rs.core.SecurityContext; +import javax.ws.rs.core.UriInfo; + +@Path(value = "/multicontextcstr") +public class MultiContextCstr { + + public MultiContextCstr() { + + } + + public MultiContextCstr(@Context HttpHeaders headers, @Context SecurityContext secContext, @Context Request request, @Context UriInfo uriInfo, String something) { + + } + + // this constructor should be picked + public MultiContextCstr(@Context HttpHeaders headers, @Context SecurityContext secContext, @Context Request request) { + + } + +} Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/ResourceBadCstr.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/ResourceBadCstr.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/ResourceBadCstr.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/ResourceBadCstr.java Tue Jun 23 05:37:57 2009 @@ -0,0 +1,31 @@ +/* + * 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.lifecycle.testimpls; + +import javax.ws.rs.Path; + +@Path(value = "/badcstr") +public class ResourceBadCstr { + + ResourceBadCstr() { + + } + +} Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/ResourceDefaultCstr.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/ResourceDefaultCstr.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/ResourceDefaultCstr.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/ResourceDefaultCstr.java Tue Jun 23 05:37:57 2009 @@ -0,0 +1,31 @@ +/* + * 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.lifecycle.testimpls; + +import javax.ws.rs.Path; + +@Path(value = "/defaultcstr") +public class ResourceDefaultCstr { + + public ResourceDefaultCstr() { + + } + +} Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/ResourceDefaultCstrSingleton.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/ResourceDefaultCstrSingleton.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/ResourceDefaultCstrSingleton.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/ResourceDefaultCstrSingleton.java Tue Jun 23 05:37:57 2009 @@ -0,0 +1,31 @@ +/* + * 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.lifecycle.testimpls; + +import javax.ws.rs.Path; + +@Path(value = "/defaultcstrsingleton") +public class ResourceDefaultCstrSingleton { + + public ResourceDefaultCstrSingleton() { + + } + +} Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/ResourceWithContext.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/ResourceWithContext.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/ResourceWithContext.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/ResourceWithContext.java Tue Jun 23 05:37:57 2009 @@ -0,0 +1,152 @@ +/* + * 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.lifecycle.testimpls; + +import java.util.List; +import java.util.SortedSet; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.CookieParam; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.Encoded; +import javax.ws.rs.FormParam; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.MatrixParam; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Cookie; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.Request; +import javax.ws.rs.core.SecurityContext; +import javax.ws.rs.core.UriInfo; + +@Path(value = "/contextualresource") +public class ResourceWithContext { + + public ResourceWithContext() { + + } + + public ResourceWithContext(@Context HttpServletRequest request) { + + } + + public ResourceWithContext(@Context HttpServletResponse response) { + + } + + public ResourceWithContext(@Context ServletConfig config) { + + } + + public ResourceWithContext(@Context ServletContext context) { + + } + + public ResourceWithContext(@Context HttpHeaders httpHeaders) { + + } + + public ResourceWithContext(@Context UriInfo uriInfo) { + + } + + public ResourceWithContext(@Context SecurityContext securityContext) { + + } + + public ResourceWithContext(@QueryParam(value = "id") String queryParam) { + + } + + public ResourceWithContext(@QueryParam(value = "name") List queryParam) { + + } + + public ResourceWithContext(@QueryParam(value = "name") SortedSet queryParamsSorted) { + + } + + public ResourceWithContext(@HeaderParam(value = "date-sent") DateHeader dateHeader) { + + } + + public ResourceWithContext(@MatrixParam(value = "id") String id, @MatrixParam(value = "first name") String firstNameDecoded, @MatrixParam(value = "last name") String lastNameDecoded) { + + } + + public ResourceWithContext(@Encoded @MatrixParam(value = "first%20name") String firstNameDecoded, @Encoded @MatrixParam(value = "last%20name") String lastNameDecoded) { + + } + + public ResourceWithContext(@Context Request request) { + + } + + public ResourceWithContext(@Context HttpHeaders httpHeaders, @Context UriInfo uriInfo, @Context SecurityContext secContext, @QueryParam(value = "id") String queryParam, @QueryParam(value = "name") List queryParams, @QueryParam(value = "name") SortedSet queryParamsSorted) { + } + + @Path(value = "resourcwithmore") + public static class ResourceWithMoreContext { + + public ResourceWithMoreContext(@PathParam(value = "id") String id) { + + } + + public ResourceWithMoreContext(@CookieParam(value = "cookie1") Cookie cookie) { + + } + + public ResourceWithMoreContext(@CookieParam(value = "cookie1") Cookie cookie, @CookieParam(value = "cookie1") String cookieValue) { + + } + } + + @Path(value = "resourcewithform") + public static class ResourceWithFormContext { + + public ResourceWithFormContext(@DefaultValue(value = "007") @FormParam(value = "id") String id, @DefaultValue(value = "James Bond") @FormParam(value = "name") String name) { + + } + + } + + public static class DateHeader { + + private String date; + + public DateHeader(String date) { + this.date = date; + } + + public static DateHeader valueOf(String date) { + return new DateHeader(date); + } + + public String getDate() { + return date; + } + } +} Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/ResourceWithNoParamAnnotations.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/ResourceWithNoParamAnnotations.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/ResourceWithNoParamAnnotations.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/ResourceWithNoParamAnnotations.java Tue Jun 23 05:37:57 2009 @@ -0,0 +1,92 @@ +/* + * 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.lifecycle.testimpls; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +@Path("/resourcenoannotations") +public class ResourceWithNoParamAnnotations { + + @QueryParam("myQueryParamsList") + List myQueryParamsList; + + List myQueryParamsListNoAnnotation = new ArrayList(); + { + myQueryParamsListNoAnnotation.add("ListValue1"); + myQueryParamsListNoAnnotation.add("ListValue2"); + } + + @QueryParam("myQueryParamsSet") + Set myQueryParamsSet; + + Set myQueryParamsSetNoAnnotation = new HashSet(); + { + myQueryParamsSetNoAnnotation.add("SetValue1"); + myQueryParamsSetNoAnnotation.add("SetValue2"); + } + + @QueryParam("myQueryParamsString") + String myQueryParamsString; + + String myQueryParamsStringNoAnnotation = "StringValue1"; + + @QueryParam("myQueryParamInt") + int myQueryParamsInt = 55; + + int myQueryParamsIntNoAnnotation = 99; + + public List getMyQueryParamsList() { + return myQueryParamsList; + } + + public List getMyQueryParamsListNoAnnotation() { + return myQueryParamsListNoAnnotation; + } + + public Set getMyQueryParamsSet() { + return myQueryParamsSet; + } + + public Set getMyQueryParamsSetNoAnnotation() { + return myQueryParamsSetNoAnnotation; + } + + public String getMyQueryParamsString() { + return myQueryParamsString; + } + + public String getMyQueryParamsStringNoAnnotation() { + return myQueryParamsStringNoAnnotation; + } + + public int getMyQueryParamsInt() { + return myQueryParamsInt; + } + + public int getMyQueryParamsIntNoAnnotation() { + return myQueryParamsIntNoAnnotation; + } +} Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/StringWriterBadCstr.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/StringWriterBadCstr.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/StringWriterBadCstr.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/StringWriterBadCstr.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.lifecycle.testimpls; + +import java.io.IOException; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.ext.MessageBodyWriter; +import javax.ws.rs.ext.Provider; + +@Provider +public class StringWriterBadCstr implements MessageBodyWriter { + + StringWriterBadCstr() { + + } + + public boolean isWriteable(Class arg0, Type arg1, Annotation[] arg2) { + return false; + } + + public void writeTo(String arg0, Class arg1, Type arg2, Annotation[] arg3, MediaType arg4, MultivaluedMap arg5, OutputStream arg6) + throws IOException, WebApplicationException { + } + + public long getSize(String arg0, Class arg1, Type arg2, Annotation[] arg3, MediaType arg4) { + return 0; + } + + public boolean isWriteable(Class arg0, Type arg1, Annotation[] arg2, MediaType arg3) { + return false; + } + +} Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/StringWriterDefaultCstr.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/StringWriterDefaultCstr.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/StringWriterDefaultCstr.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/StringWriterDefaultCstr.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 com.ibm.ws.jaxrs.lifecycle.testimpls; + +import java.io.IOException; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.ext.MessageBodyWriter; +import javax.ws.rs.ext.Provider; + +// Sample MessageBodyWriter for unit tests +@Provider +public class StringWriterDefaultCstr implements MessageBodyWriter { + + public StringWriterDefaultCstr() { + + } + + public long getSize(String arg0, Class arg1, Type arg2, Annotation[] arg3, MediaType arg4) { + return 0; + } + + public boolean isWriteable(Class arg0, Type arg1, Annotation[] arg2, MediaType arg3) { + return false; + } + + public boolean isWriteable(Class arg0, Type arg1, Annotation[] arg2) { + return false; + } + + public void writeTo(String arg0, Class arg1, Type arg2, Annotation[] arg3, MediaType arg4, MultivaluedMap arg5, OutputStream arg6) + throws IOException, WebApplicationException { + } + +} Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/StringWriterDefaultCstrSingleton.java URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/StringWriterDefaultCstrSingleton.java?rev=787553&view=auto ============================================================================== --- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/StringWriterDefaultCstrSingleton.java (added) +++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/lifecycle/testimpls/StringWriterDefaultCstrSingleton.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 com.ibm.ws.jaxrs.lifecycle.testimpls; + +import java.io.IOException; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.ext.MessageBodyWriter; +import javax.ws.rs.ext.Provider; + +// Sample MessageBodyWriter for unit tests +@Provider +public class StringWriterDefaultCstrSingleton implements MessageBodyWriter { + + public StringWriterDefaultCstrSingleton() { + + } + + public long getSize(String arg0, Class arg1, Type arg2, Annotation[] arg3, MediaType arg4) { + return 0; + } + + public boolean isWriteable(Class arg0, Type arg1, Annotation[] arg2, MediaType arg3) { + return false; + } + + public boolean isWriteable(Class arg0, Type arg1, Annotation[] arg2) { + return false; + } + + public void writeTo(String arg0, Class arg1, Type arg2, Annotation[] arg3, MediaType arg4, MultivaluedMap arg5, OutputStream arg6) + throws IOException, WebApplicationException { + } + +}