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 [29/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/model/testimpls/Book.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/testimpls/Book.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/testimpls/Book.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/testimpls/Book.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.ws.jaxrs.model.testimpls;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+
+@Path(value = "/book/{id}")
+public class Book {
+
+    @GET
+    public String get() {
+        return null;
+    }
+
+    @POST
+    public void post() {
+
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/testimpls/ContextProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/testimpls/ContextProvider.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/testimpls/ContextProvider.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/testimpls/ContextProvider.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.ws.jaxrs.model.testimpls;
+
+import javax.ws.rs.ext.ContextResolver;
+import javax.ws.rs.ext.Provider;
+import javax.xml.bind.JAXBContext;
+
+@Provider
+public class ContextProvider implements ContextResolver<JAXBContext> {
+
+    public JAXBContext getContext(Class<?> type) {
+        return null;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/testimpls/Magazine.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/testimpls/Magazine.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/testimpls/Magazine.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/testimpls/Magazine.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.model.testimpls;
+
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HEAD;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+
+@Path(value = "/magazine/{id}")
+public class Magazine {
+
+    @GET
+    public String get() {
+        return null;
+    }
+
+    @POST
+    public void post(String input) {
+
+    }
+
+    @HEAD
+    public void head() {
+
+    }
+
+    @DELETE
+    public void delete() {
+
+    }
+
+    @PUT
+    public void put(String input) {
+
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/param/ParamTestUtils.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/param/ParamTestUtils.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/param/ParamTestUtils.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/param/ParamTestUtils.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,73 @@
+/*
+ * 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.param;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.model.MethodDispatcher;
+import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+
+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;
+
+/*
+ * A collection of utility methods used for testing parameter processing
+ */
+public class ParamTestUtils {
+
+    public static ClassResourceInfo buildMetadata(Class clazz) throws Exception {
+        Map<String, Class<?>> classes = new HashMap<String, Class<?>>();
+        classes.put(clazz.getName(), clazz);
+
+        JAXRSInfoInput source = new JAXRSInfoInput(
+                JAXRSInfoInput.Type.REFLECTION);
+        source.setClasses(classes);
+
+        JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry
+                .getImplementation(JAXRSInfoBuilderFactory.class);
+        JAXRSInfoBuilder builder = factory
+                .getInfoBuilder(source.getInputType());
+        JAXRSInfoOutput output = builder.buildRESTInfo(source);
+
+        List<ClassResourceInfo> classInfoList = output.getClassInfoList();
+        return classInfoList.get(0);
+    }
+
+    public static OperationResourceInfo findOperationResourceInfo(ClassResourceInfo cri, String operationName) {
+        MethodDispatcher md = cri.getMethodDispatcher();
+        Iterator<OperationResourceInfo> itr = md.getOperationResourceInfos()
+                .iterator();
+        while (itr.hasNext()) {
+            OperationResourceInfo ori = itr.next();
+            if (ori.getAnnotatedMethod().getName().equals(operationName))
+                return ori;
+        }
+
+        return null;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/param/PathParamTests.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/param/PathParamTests.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/param/PathParamTests.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/param/PathParamTests.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,116 @@
+/*
+ * 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.param;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.core.MultivaluedMap;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.jaxrs.impl.MetadataMap;
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+
+import com.ibm.ws.jaxrs.context.ContextConstants;
+import com.ibm.ws.jaxrs.context.RESTContext;
+import com.ibm.ws.jaxrs.web.mock.ServletRequest;
+
+public class PathParamTests extends TestCase {
+
+    public void testResourceMethodNoParams() throws Exception {
+        ClassResourceInfo cri = ParamTestUtils.buildMetadata(Foo.class);
+        OperationResourceInfo ori = ParamTestUtils.findOperationResourceInfo(
+                cri, "getFoo");
+
+        assertTrue(
+                "An OperationResourceInfo should have been found for operation [getFoo]",
+                ori != null);
+
+        MultivaluedMap<String, String> values = new MetadataMap<String, String>();
+
+        String requestUrl = "http://localhost:9080/rest/foo";
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put(ServletRequest.PATH_INFO, "/foo");
+        props.put(ServletRequest.CONTENT_TYPE, "text/plain");
+
+        HttpServletRequest request = new ServletRequest(requestUrl, null, props);
+        RESTContext context = new RESTContext();
+        context.setProperty(ContextConstants.SERVLET_REQUEST, request);
+        context.setProperty(ContextConstants.TEMPLATE_VALUES, values);
+        List<Object> paramList = JAXRSUtils.processParameters(ori, context);
+        assertTrue(paramList != null);
+        assertTrue(paramList.size() == 0);
+    }
+
+    public void testResourceMethodSinglePathParams() throws Exception {
+        ClassResourceInfo cri = ParamTestUtils.buildMetadata(Foo.class);
+        OperationResourceInfo ori = ParamTestUtils.findOperationResourceInfo(
+                cri, "getFooWithId");
+
+        assertTrue(
+                "An OperationResourceInfo should have been found for operation [getFooWithId]",
+                ori != null);
+
+        List<String> idValues = new ArrayList<String>();
+        idValues.add("123");
+
+        MultivaluedMap<String, String> values = new MetadataMap<String, String>();
+        values.put("id", idValues);
+
+        String requestUrl = "http://localhost:9080/rest/foo";
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put(ServletRequest.PATH_INFO, "/foo/123");
+        props.put(ServletRequest.CONTENT_TYPE, "text/plain");
+
+        HttpServletRequest request = new ServletRequest(requestUrl, null, props);
+        RESTContext context = new RESTContext();
+        context.setProperty(ContextConstants.SERVLET_REQUEST, request);
+        context.setProperty(ContextConstants.TEMPLATE_VALUES, values);
+        List<Object> paramList = JAXRSUtils.processParameters(ori, context);
+        assertTrue(paramList != null);
+        assertTrue(paramList.size() == 1);
+        assertTrue(paramList.get(0).equals("123"));
+    }
+
+    @Path("/foo")
+    class Foo {
+
+        @GET
+        public String getFoo() {
+            return "Hi!";
+        }
+
+        @GET
+        @Path("/{id}")
+        public String getFooWithId(@PathParam(value = "id") String id) {
+            return id;
+        }
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/provider/DataSourceProviderTests.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/provider/DataSourceProviderTests.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/provider/DataSourceProviderTests.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/provider/DataSourceProviderTests.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,89 @@
+/*
+ * 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.provider;
+
+import java.io.ByteArrayInputStream;
+import java.io.StringWriter;
+
+import javax.activation.DataSource;
+import javax.activation.FileDataSource;
+import javax.ws.rs.core.MediaType;
+
+import junit.framework.TestCase;
+
+import com.ibm.ws.jaxrs.web.mock.ServletOutputStream;
+
+/**
+ * Verify the functionality of the DataSourceProvider
+ *
+ */
+public class DataSourceProviderTests extends TestCase {
+
+    public void testIsReadable() throws Exception {
+        DataSourceProvider provider = new DataSourceProvider();
+        assertTrue(provider.isReadable(DataSource.class, null, null, null));
+        assertFalse(provider.isReadable(RESTDataSource.class, null, null, null));
+        assertFalse(provider.isReadable(FileDataSource.class, null, null, null));
+        assertFalse(provider.isReadable(String.class, null, null, null));
+    }
+
+    public void testIsWriteable() throws Exception {
+        DataSourceProvider provider = new DataSourceProvider();
+        assertTrue(provider.isWriteable(RESTDataSource.class, null, null, null));
+        assertTrue(provider.isWriteable(FileDataSource.class, null, null, null));
+        assertFalse(provider.isWriteable(String.class, null, null, null));
+    }
+
+    public void testWriteTo() throws Exception {
+        DataSourceProvider provider = new DataSourceProvider();
+        String input = "This is some test input";
+        RESTDataSource dataSource = new RESTDataSource(input.getBytes(), null,
+                "application/datasource");
+        StringWriter sw = new StringWriter();
+        ServletOutputStream os = new ServletOutputStream(sw);
+        provider.writeTo(dataSource, RESTDataSource.class, null, null,
+                new MediaType("application", "datasource"), null, os);
+        assertNotNull(sw.toString());
+        assertEquals("This is some test input", sw.toString());
+    }
+
+    public void testReadFrom() throws Exception {
+        DataSourceProvider provider = new DataSourceProvider();
+        String input = "This is some test input";
+        byte[] bytes = input.getBytes();
+        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+        DataSource dataSource = provider.readFrom(DataSource.class, null, null,
+                new MediaType("application", "datasource"), null, bais);
+        assertNotNull(dataSource);
+        byte[] newBytes = new byte[bytes.length];
+        assertNotNull(dataSource.getInputStream());
+        dataSource.getInputStream().read(newBytes);
+        String newInput = new String(newBytes);
+        assertEquals(input, newInput);
+
+        // now make sure that calling getInputStream() results in a new readable stream
+        newBytes = new byte[bytes.length];
+        assertNotNull(dataSource.getInputStream());
+        dataSource.getInputStream().read(newBytes);
+        newInput = new String(newBytes);
+        assertEquals(input, newInput);
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/addressbook/Address.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/addressbook/Address.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/addressbook/Address.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/addressbook/Address.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,120 @@
+/*
+ * 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.addressbook;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.Produces;
+
+public class Address {
+
+    private String entryName;
+
+    private String zipCode;
+
+    private String streetAddress;
+
+    private String city;
+
+    private String state;
+
+    private String country;
+
+    public Address(String entryName, String zipCode, String streetAddress, String city, String state, String country) {
+        this.entryName = entryName;
+        this.zipCode = zipCode;
+        this.streetAddress = streetAddress;
+        this.city = city;
+        this.state = state;
+        this.country = country;
+    }
+
+    @GET
+    @Consumes(value = { "text/xml" })
+    @Produces(value = { "text/xml" })
+    public String get() {
+        return toString();
+    }
+
+    public String getEntryName() {
+        return entryName;
+    }
+
+    public void setEntryName(String entryName) {
+        this.entryName = entryName;
+    }
+
+    public String getZipCode() {
+        return zipCode;
+    }
+
+    public void setZipCode(String zipCode) {
+        this.zipCode = zipCode;
+    }
+
+    public String getStreetAddress() {
+        return streetAddress;
+    }
+
+    public void setStreetAddress(String streetAddress) {
+        this.streetAddress = streetAddress;
+    }
+
+    public String getCity() {
+        return city;
+    }
+
+    public void setCity(String city) {
+        this.city = city;
+    }
+
+    public String getState() {
+        return state;
+    }
+
+    public void setState(String state) {
+        this.state = state;
+    }
+
+    public String getCountry() {
+        return country;
+    }
+
+    public void setCountry(String country) {
+        this.country = country;
+    }
+
+    public String toString() {
+        StringBuffer sb = new StringBuffer();
+        sb.append("Entry Name: " + entryName);
+        sb.append("\n");
+        sb.append("Street Address: " + streetAddress);
+        sb.append("\n");
+        sb.append("City: " + city);
+        sb.append("\n");
+        sb.append("Zip Code: " + zipCode);
+        sb.append("\n");
+        sb.append("State: " + state);
+        sb.append("\n");
+        sb.append("Country: " + country);
+        return sb.toString();
+    }
+
+}

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

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/addressbook/AddressBook.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/addressbook/AddressBook.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/addressbook/AddressBook.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/addressbook/AddressBook.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,142 @@
+/*
+ * 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.addressbook;
+
+import java.util.Iterator;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+
+@Path(value = "/unittests/addresses")
+public class AddressBook {
+
+    private static AddressBookDatabase db = AddressBookDatabase.getInstance();
+
+    private @Context
+    HttpServletRequest request;
+
+    public static Address defaultAddress = new Address("defaultAddress",
+            "12345", "Loop 1", "Austin", "TX", "US");
+
+    public AddressBook() {
+        db.storeAddress(defaultAddress.getEntryName(), defaultAddress);
+    }
+
+    @Path("/{entryName}")
+    public Address getAddress(@PathParam(value = "entryName") String entryName) {
+        Address addr = db.getAddress(entryName);
+        return addr;
+    }
+
+    @GET
+    @Consumes(value = { "text/xml" })
+    @Produces(value = { "text/xml" })
+    public Response getAddresses() {
+        Response resp = null;
+        if (request.getMethod().equalsIgnoreCase("HEAD")) {
+            ResponseBuilder builder = Response.ok();
+            resp = builder.build();
+            resp.getMetadata().putSingle("head-matched", "true");
+        } else {
+            StringBuffer sb = new StringBuffer();
+            Iterator<Address> addressIter = db.getAddresses();
+            while (addressIter.hasNext()) {
+                sb.append(addressIter.next().toString());
+                sb.append("\n");
+            }
+            ResponseBuilder builder = Response.ok(sb.toString());
+            resp = builder.build();
+        }
+        return resp;
+    }
+
+    @POST
+    @Consumes(value = { "text/xml" })
+    public void createAddress(@QueryParam(value = "entryName") String entryName, @QueryParam(value = "zipCode") String zipCode, @QueryParam(value = "streetAddress") String streetAddress, @QueryParam(value = "city") String city, @QueryParam(value = "state") String state, @QueryParam(value = "country") String country) {
+        Address address = new Address(entryName, zipCode, streetAddress, city,
+                state, country);
+        db.storeAddress(entryName, address);
+    }
+
+    @POST
+    @Consumes(value = { "text/xml" })
+    @Path(value = "/fromBody")
+    public void createAddressFromBody(String input) {
+        String[] inputs = input.split("&");
+        String entryName = inputs[0];
+        String zipCode = inputs[1];
+        String streetAddress = inputs[2];
+        String city = inputs[3];
+        String state = inputs[4];
+        String country = inputs[5];
+        Address address = new Address(entryName, zipCode, streetAddress, city,
+                state, country);
+        db.storeAddress(entryName, address);
+    }
+
+    @DELETE
+    @Consumes(value = { "text/xml" })
+    @Path(("/{entryName}"))
+    public void removeAddress(@PathParam(value = "entryName") String entryName) {
+        db.removeAddress(entryName);
+    }
+
+    @PUT
+    @Consumes(value = { "text/xml" })
+    public void updateAddress(@QueryParam(value = "entryName") String entryName, @QueryParam(value = "zipCode") String zipCode, @QueryParam(value = "streetAddress") String streetAddress, @QueryParam(value = "city") String city, @QueryParam(value = "state") String state, @QueryParam(value = "country") String country) {
+        Address address = db.getAddress(entryName);
+        if (address == null) {
+            address = new Address(entryName, zipCode, streetAddress, city,
+                    state, country);
+            db.storeAddress(entryName, address);
+        } else {
+            address.setCity(city);
+            address.setCountry(country);
+            address.setState(state);
+            address.setStreetAddress(streetAddress);
+            address.setZipCode(zipCode);
+        }
+    }
+
+    @POST
+    @PUT
+    @Path(value = "/invalidMultipleHttpMethodAnnots")
+    public void invalidMultipleHttpMethodAnnots() {
+
+    }
+
+    @GET
+    @Path(value = "/invalidNonPublic")
+    void invalidNonPublic() {
+
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/addressbook/AddressBookDatabase.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/addressbook/AddressBookDatabase.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/addressbook/AddressBookDatabase.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/addressbook/AddressBookDatabase.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.ws.jaxrs.sample.addressbook;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * Sample that will mock a database for the AddressBook resource
+ * @author Dustin
+ *
+ */
+public class AddressBookDatabase {
+
+    private static Map<String, Address> addressMap;
+
+    private static AddressBookDatabase instance;
+
+    private AddressBookDatabase() {
+        addressMap = new HashMap<String, Address>();
+    }
+
+    public static AddressBookDatabase getInstance() {
+        if (instance == null) {
+            instance = new AddressBookDatabase();
+        }
+        return instance;
+    }
+
+    public Address getAddress(String entryName) {
+        return addressMap.get(entryName);
+    }
+
+    public void storeAddress(String entryName, Address address) {
+        addressMap.put(entryName, address);
+    }
+
+    public Iterator<Address> getAddresses() {
+        return addressMap.values().iterator();
+    }
+
+    public void removeAddress(String entryName) {
+        addressMap.remove(entryName);
+    }
+
+    public static void clearEntries() {
+        if (addressMap != null) {
+            addressMap.clear();
+        }
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/addressbook/AddressBookTests.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/addressbook/AddressBookTests.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/addressbook/AddressBookTests.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/addressbook/AddressBookTests.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,305 @@
+/*
+ * 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.addressbook;
+
+import java.io.ByteArrayInputStream;
+import java.util.List;
+
+import javax.ws.rs.HttpMethod;
+
+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 AddressBookTests extends ServletTestFramework {
+
+    private static final String URI_ROOT_RESOURCE = "/unittests/addresses";
+    private static final String URI_DEFAULT_RESOURCE = "/unittests/addresses/defaultAddress";
+    private static final String URI_FROM_BODY = "/unittests/addresses/fromBody";
+
+    /**
+     * Test the servlet flow for a GET request with no parameters.
+     *
+     * INPUT: none
+     * OUTPUT: the list of addresses available in the address book
+     */
+    public void testGetNoParams() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.addressbook.AddressApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE, HttpMethod.GET);
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+
+            // make sure we have our default entry at the least
+            String responseContent = ServletTestFramework.getContent(response);
+
+            assertTrue("The response did not contain any content.",
+                    responseContent != null);
+            assertTrue("The response did not contain the expected key.",
+                    responseContent.contains("defaultAddress"));
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Test the servlet flow for an OPTIONS request with no parameters.
+     *
+     * INPUT: none
+     * OUTPUT: response headers indicating aspects about the resource
+     */
+    public void testOptions() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.addressbook.AddressApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE, "OPTIONS");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doOptions(request, response);
+
+            assertTrue("The expected response header 'Allow' was not found",
+                    response.containsHeader("Allow"));
+            List<String> allowHeaders = response.getHeaders("Allow");
+            assertNotNull(allowHeaders);
+            assertEquals(6, allowHeaders.size());
+            assertTrue(
+                    "Expected 'GET' was not found in the 'Allow' response header",
+                    allowHeaders.contains("GET"));
+            assertTrue(
+                    "Expected 'POST' was not found in the 'Allow' response header",
+                    allowHeaders.contains("POST"));
+            assertTrue(
+                    "Expected 'PUT' was not found in the 'Allow' response header",
+                    allowHeaders.contains("PUT"));
+            assertTrue(
+                    "Expected 'DELETE' was not found in the 'Allow' response header",
+                    allowHeaders.contains("DELETE"));
+            assertTrue(
+                    "Expected 'OPTIONS' was not found in the 'Allow' response header",
+                    allowHeaders.contains("OPTIONS"));
+            assertTrue(
+                    "Expected 'HEAD' was not found in the 'Allow' response header",
+                    allowHeaders.contains("HEAD"));
+
+            assertTrue("The expected response header 'Accept' was not found",
+                    response.containsHeader("Accept"));
+            List<String> acceptHeaders = response.getHeaders("Accept");
+            assertNotNull(acceptHeaders);
+            assertTrue("Expected '*/*' was not found in 'Accept' header",
+                    acceptHeaders.contains("*/*"));
+            assertTrue("Expected '*/*' was not found in 'Accept' header",
+                    acceptHeaders.contains("text/xml"));
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Test the servlet flow for a HEAD request when there is no method
+     * configured for HEAD requests. In this case, the GET method should
+     * be invoked.
+     *
+     * INPUT: none
+     * OUTPUT: response header set by resource
+     */
+    public void testHeadToGet() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.addressbook.AddressApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE, HttpMethod.HEAD);
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doHead(request, response);
+            assertTrue("Expected 'head-matched' header not found in response",
+                    response.containsHeader("head-matched"));
+
+            // make sure we have our default entry at the least
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Test the servlet flow for a GET request with parameters
+     */
+    public void testGetWithUriParams() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.addressbook.AddressApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_DEFAULT_RESOURCE, HttpMethod.GET);
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+
+            String responseContent = ServletTestFramework.getContent(response);
+
+            assertTrue("The response did not contain any content.",
+                    responseContent != null);
+            assertTrue("The response did not contain the expected key.",
+                    responseContent.contains("defaultAddress"));
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Test the servlet flow for a POST request with query string parameters
+     */
+    public void testPostWithQueryStringParams() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.addressbook.AddressApplication");
+
+        // First try adding a new address via the POST
+        String queryString = "entryName=newAddress&streetAddress=1234 Any Street&city=AnyTown&zipCode=90210&state=TX&country=US";
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE, queryString, HttpMethod.POST);
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doPost(request, response);
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+
+        // The new address should exist and be returned in the list of all addresses
+        // from the root resource.
+        request = ServletTestFramework.createServletRequest(URI_ROOT_RESOURCE,
+                HttpMethod.GET);
+        response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+
+            String responseContent = ServletTestFramework.getContent(response);
+
+            assertTrue("The response content was null.",
+                    responseContent != null);
+            assertTrue("The response did not contain the expected key.",
+                    responseContent.contains("newAddress"));
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Test the servlet flow for a POST request with data in the body
+     */
+    public void testFlowPOSTBodyData() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.addressbook.AddressApplication");
+
+        // First try to add a new entry with content from the body.
+        String input = "bodyEntry&78727&some street&some city&tx&us";
+        ByteArrayInputStream bais = new ByteArrayInputStream(input.getBytes());
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_FROM_BODY, "", HttpMethod.POST, bais);
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doPost(request, response);
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+
+        // The new address should exist and be returned in the list of all addresses
+        // from the root resource.
+        request = ServletTestFramework.createServletRequest(URI_ROOT_RESOURCE,
+                HttpMethod.GET);
+        response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+
+            String responseContent = ServletTestFramework.getContent(response);
+
+            assertTrue("The returned content was null.",
+                    responseContent != null);
+            assertTrue("The content did not contain the expected key.",
+                    responseContent.contains("bodyEntry"));
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Test that a 404 is returned when a method with multiple @HttpMethod type annotations
+     * is targetted for a RESTful request.
+     *
+     * INPUT: none
+     * OUTPUT: 404 error
+     */
+    public void testMultipleHttpMethodAnnots() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.addressbook.AddressApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/invalidMultipleHttpMethodAnnots",
+                HttpMethod.POST);
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doPost(request, response);
+            assertEquals("Expected '404' response code, received: "
+                    + response.getStatus(), response.getStatus(), 404);
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * Test that a 404 is returned when a non-public method is targetted for a
+     * RESTful request.
+     *
+     * INPUT: none
+     * OUTPUT: 404 error
+     */
+    public void testNonPublicMethod() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.addressbook.AddressApplication");
+
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/invalidNonPublic", HttpMethod.GET);
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            servlet.doGet(request, response);
+            assertEquals("Expected '404' response code, received: "
+                    + response.getStatus(), response.getStatus(), 404);
+        } 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/customcontent/Car.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/customcontent/Car.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/customcontent/Car.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/customcontent/Car.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.ws.jaxrs.sample.customcontent;
+
+public class Car {
+
+    private String licenseNumber;
+
+    private String make;
+
+    private String model;
+
+    private String year;
+
+    private String color;
+
+    public String getMake() {
+        return make;
+    }
+
+    public void setMake(String make) {
+        this.make = make;
+    }
+
+    public String getModel() {
+        return model;
+    }
+
+    public void setModel(String model) {
+        this.model = model;
+    }
+
+    public String getYear() {
+        return year;
+    }
+
+    public void setYear(String year) {
+        this.year = year;
+    }
+
+    public String getColor() {
+        return color;
+    }
+
+    public void setColor(String color) {
+        this.color = color;
+    }
+
+    public String getLicenseNumber() {
+        return licenseNumber;
+    }
+
+    public void setLicenseNumber(String licenseNumber) {
+        this.licenseNumber = licenseNumber;
+    }
+
+    public String toString() {
+        return licenseNumber + ":" + make + ":" + model + ":" + year + ":"
+                + color;
+    }
+
+}

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

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/customcontent/CarCollection.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/customcontent/CarCollection.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/customcontent/CarCollection.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/customcontent/CarCollection.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.ws.jaxrs.sample.customcontent;
+
+import java.util.LinkedList;
+import java.util.List;
+
+public class CarCollection {
+
+    private List<Car> cars = new LinkedList<Car>();
+
+    public List<Car> getCars() {
+        return cars;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/customcontent/CarDatabase.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/customcontent/CarDatabase.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/customcontent/CarDatabase.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/customcontent/CarDatabase.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.ws.jaxrs.sample.customcontent;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+public class CarDatabase {
+
+    private static Map<String, Car> cars = new HashMap<String, Car>();
+
+    public static void addCar(Car car) {
+        cars.put(car.getLicenseNumber(), car);
+    }
+
+    public static Car getCar(String licenseNumber) {
+        return cars.get(licenseNumber);
+    }
+
+    public static Iterator<Car> getCars() {
+        return cars.values().iterator();
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/customcontent/Cars.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/customcontent/Cars.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/customcontent/Cars.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/customcontent/Cars.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.ws.jaxrs.sample.customcontent;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+
+@Path(value = "/cars")
+public class Cars {
+
+    @GET
+    @Consumes("application/car")
+    @Produces("application/car")
+    public CarCollection getCars() {
+        CarCollection cars = new CarCollection();
+        List<Car> carList = cars.getCars();
+        Iterator<Car> carIter = CarDatabase.getCars();
+        while (carIter.hasNext()) {
+            carList.add(carIter.next());
+        }
+        return cars;
+    }
+
+    @GET
+    @Path(value = "{licenseNum}")
+    @Consumes("text/xml")
+    @Produces("application/carstring")
+    public String getCar(@PathParam(value = "licenseNum") String licenseNumber) {
+        return CarDatabase.getCar(licenseNumber) != null ? CarDatabase.getCar(
+                licenseNumber).toString() : "";
+    }
+
+    @POST
+    @Consumes("application/car")
+    public void addCar(Car car) {
+        CarDatabase.addCar(car);
+    }
+
+    @POST
+    @Path(value = "/fromstring")
+    @Consumes("application/carstring")
+    public void addCar(String carstring) {
+        Car car = new Car();
+        String[] parts = carstring.split(":");
+        car.setColor(parts[4]);
+        car.setLicenseNumber(parts[0]);
+        car.setMake(parts[1]);
+        car.setModel(parts[2]);
+        car.setYear(parts[3]);
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/customcontent/CarsTests.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/customcontent/CarsTests.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/customcontent/CarsTests.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/customcontent/CarsTests.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,342 @@
+/*
+ * 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.customcontent;
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.activation.CommandInfo;
+import javax.activation.CommandMap;
+import javax.activation.DataContentHandler;
+import javax.activation.DataSource;
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+import javax.ws.rs.ext.Providers;
+
+import org.apache.cxf.helpers.IOUtils;
+
+import com.ibm.ws.jaxrs.context.ContextConstants;
+import com.ibm.ws.jaxrs.context.RESTContext;
+import com.ibm.ws.jaxrs.context.RESTContextFactory;
+import com.ibm.ws.jaxrs.metadata.RESTMetaData;
+import com.ibm.ws.jaxrs.model.ApplicationProcessor;
+import com.ibm.ws.jaxrs.model.JAXRSInfoOutput;
+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;
+
+/**
+ * Tests for custom DataHandlers using Java Activation Framework
+ *
+ */
+public class CarsTests extends ServletTestFramework {
+
+    private static final String URI_ROOT_RESOURCE = "/cars";
+
+    /**
+     * This test will send data that will be unmarshalled using a custom
+     * DataHandler registered via the JAF. We will then send a GET request
+     * to retrieve the data and allow our DataHandler to be called to marshall
+     * the response.
+     *
+     */
+    public void testCustomDataHandler() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.customcontent.CarApplication");
+        String input = "{cars:[{licenseNumber:123XYZ,make:Honda,model:Accord,year:2009,color:red}]}";
+        byte[] inputBytes = input.getBytes();
+        ByteArrayInputStream bais = new ByteArrayInputStream(inputBytes);
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE, "", HttpMethod.POST, bais);
+        request.setAttribute(ServletRequest.CONTENT_TYPE, "application/car");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        try {
+            CommandMap.setDefaultCommandMap(new CarCommandMap(
+                    "com.ibm.ws.jaxrs.sample.customcontent.Car"));
+            servlet.doPost(request, response);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+
+        request = ServletTestFramework.createServletRequest(URI_ROOT_RESOURCE,
+                HttpMethod.GET);
+        request.setAttribute(ServletRequest.CONTENT_TYPE, "application/car");
+        response = ServletTestFramework.createServletResponse();
+
+        try {
+            CommandMap.setDefaultCommandMap(new CarCommandMap(
+                    "com.ibm.ws.jaxrs.sample.customcontent.CarCollection"));
+            servlet.doGet(request, response);
+            String responseContent = ServletTestFramework.getContent(response);
+            assertTrue("Expected: " + input + ", received: " + responseContent,
+                    responseContent.contains(input));
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    /**
+     * This test will use injection of the Providers interface in a user-supplied
+     * EntityProvider to locate and utilize the default String writer/reader to
+     * handle a request/response flow.
+     *
+     */
+    public void testProviders() throws Exception {
+        RESTServlet servlet = createServlet("com.ibm.ws.jaxrs.sample.customcontent.CarApplication");
+        Car car = new Car();
+        car.setColor("red");
+        car.setLicenseNumber("123XYZ");
+        car.setMake("Honda");
+        car.setModel("Accord");
+        car.setYear("2009");
+        byte[] inputBytes = car.toString().getBytes();
+        ByteArrayInputStream bais = new ByteArrayInputStream(inputBytes);
+        ServletRequest request = ServletTestFramework.createServletRequest(
+                URI_ROOT_RESOURCE + "/fromstring", "", HttpMethod.POST, bais);
+        request.setAttribute(ServletRequest.CONTENT_TYPE,
+                "application/carstring");
+        ServletResponse response = ServletTestFramework.createServletResponse();
+
+        RESTContext context = RESTContextFactory.createRequestContext();
+
+        ApplicationProcessor processor = new ApplicationProcessor(null, Thread
+                .currentThread().getContextClassLoader());
+        JAXRSInfoOutput output = processor
+                .processApplication(new Application() {
+
+                    @Override
+                    public Set<Class<?>> getClasses() {
+                        Set<Class<?>> clazzes = new HashSet<Class<?>>();
+                        clazzes.add(CarStringProvider.class);
+                        return clazzes;
+                    }
+
+                });
+
+        RESTMetaData metadata = new RESTMetaData();
+        metadata.getProviderInfoList().addAll(output.getProviderInfoList());
+
+        context.setProperty(ContextConstants.REST_METADATA, metadata);
+        context.setProperty(ContextConstants.INTEGRATION_REGISTRATION_KEY,
+                "carKey");
+
+        try {
+            servlet.doPost(request, response);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+
+        request = ServletTestFramework.createServletRequest(URI_ROOT_RESOURCE
+                + "/123XYZ", HttpMethod.GET);
+        request.setAttribute(ServletRequest.CONTENT_TYPE, "text/xml");
+        response = ServletTestFramework.createServletResponse();
+
+        try {
+            CommandMap.setDefaultCommandMap(new CarCommandMap(
+                    "com.ibm.ws.jaxrs.sample.customcontent.Car"));
+            servlet.doGet(request, response);
+            String responseContent = ServletTestFramework.getContent(response);
+            assertTrue("Expected: " + car.toString() + ", received: "
+                    + responseContent, responseContent.contains(car.toString()));
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("The servlet invocation failed: " + e.toString());
+        }
+    }
+
+    public class CarContentHandler implements DataContentHandler {
+
+        private DataFlavor[] flavors;
+
+        public CarContentHandler(DataFlavor... flavors) {
+            this.flavors = flavors;
+        }
+
+        public Object getContent(DataSource ds) throws IOException {
+            String input = IOUtils.readStringFromStream(ds.getInputStream());
+            input = input.substring(input.indexOf("[") + 1, input
+                    .lastIndexOf("]"));
+            input = input.substring(input.indexOf("{") + 1, input
+                    .lastIndexOf("}"));
+            String[] inputs = input.split(",");
+            String licenseNumber = inputs[0]
+                    .substring(inputs[0].indexOf(":") + 1);
+            String make = inputs[1].substring(inputs[1].indexOf(":") + 1);
+            String model = inputs[2].substring(inputs[2].indexOf(":") + 1);
+            String year = inputs[3].substring(inputs[3].indexOf(":") + 1);
+            String color = inputs[4].substring(inputs[4].indexOf(":") + 1);
+            Car car = new Car();
+            car.setLicenseNumber(licenseNumber);
+            car.setMake(make);
+            car.setModel(model);
+            car.setYear(year);
+            car.setColor(color);
+            return car;
+        }
+
+        public Object getTransferData(DataFlavor df, DataSource ds)
+                throws UnsupportedFlavorException, IOException {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        public DataFlavor[] getTransferDataFlavors() {
+            return flavors;
+        }
+
+        public void writeTo(Object obj, String mimeType, OutputStream os)
+                throws IOException {
+            CarCollection collection = null;
+            if (obj instanceof CarCollection) {
+                collection = (CarCollection) obj;
+            } else if (obj instanceof Car) {
+                collection = new CarCollection();
+                collection.getCars().add((Car) obj);
+            }
+            String content = "{cars:[";
+            if (collection != null) {
+                int lastIndex = collection.getCars().size() - 1;
+                int count = 0;
+                for (Car car : collection.getCars()) {
+                    content += "{licenseNumber:" + car.getLicenseNumber() + ",";
+                    content += "make:" + car.getMake() + ",";
+                    content += "model:" + car.getModel() + ",";
+                    content += "year:" + car.getYear() + ",";
+                    content += "color:" + car.getColor() + "}";
+                    if (count != lastIndex) {
+                        content += ",";
+                    }
+                    count++;
+                }
+            }
+            content += "]}";
+            os.write(content.getBytes());
+        }
+
+    }
+
+    public class CarCommandMap extends CommandMap {
+
+        private String dataFlavorString;
+
+        public CarCommandMap() {
+            dataFlavorString = "application/car";
+        }
+
+        public CarCommandMap(String className) {
+            dataFlavorString = "application/car;class=" + className;
+        }
+
+        public DataContentHandler createDataContentHandler(String mimeType) {
+            if (mimeType.equals("application/car")) {
+                try {
+                    DataFlavor flavor = new DataFlavor(dataFlavorString);
+                    return new CarContentHandler(flavor);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+            return null;
+        }
+
+        @Override
+        public CommandInfo[] getAllCommands(String mimeType) {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        @Override
+        public CommandInfo getCommand(String mimeType, String cmdName) {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        @Override
+        public CommandInfo[] getPreferredCommands(String mimeType) {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+    }
+
+    @Provider
+    public class CarStringProvider implements MessageBodyWriter<String>, MessageBodyReader<String> {
+
+        @Context
+        Providers providers;
+
+        public long getSize(String obj, Class<?> clazz, Type type, Annotation[] annotations, MediaType mediaType) {
+            return obj != null ? obj.length() : -1;
+        }
+
+        public boolean isWriteable(Class<?> clazz, Type type, Annotation[] annotations, MediaType mediaType) {
+            return mediaType.toString().equals("application/carstring");
+        }
+
+        public void writeTo(String obj, Class<?> clazz, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> values, OutputStream out)
+                throws IOException, WebApplicationException {
+
+            // let's try to get the default String writer
+            MessageBodyWriter<String> writer = providers.getMessageBodyWriter(
+                    String.class, null, null, new MediaType("application",
+                            "car"));
+            writer.writeTo(obj, clazz, type, annotations, mediaType, values,
+                    out);
+        }
+
+        public boolean isReadable(Class<?> clazz, Type type, Annotation[] annotations, MediaType mediaType) {
+            return mediaType.toString().equals("application/carstring");
+        }
+
+        public String readFrom(Class<String> clazz, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> values, InputStream inputStream)
+                throws IOException, WebApplicationException {
+            // let's try to get the default String reader
+            MessageBodyReader<String> reader = providers.getMessageBodyReader(
+                    String.class, null, null, new MediaType("text", "xml"));
+            return reader.readFrom(clazz, type, annotations, mediaType, values,
+                    inputStream);
+        }
+
+    }
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/dd/ObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/dd/ObjectFactory.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/dd/ObjectFactory.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/dd/ObjectFactory.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.ws.jaxrs.sample.dd;
+
+import javax.xml.bind.annotation.XmlRegistry;
+
+@XmlRegistry
+public class ObjectFactory {
+
+    public PhoneBookBean createPhoneBookBean() {
+        return new PhoneBookBean();
+    }
+
+    public PhoneBookEntryBean createPhoneBookEntryBean() {
+        return new PhoneBookEntryBean();
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/dd/PhoneBook.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/dd/PhoneBook.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/dd/PhoneBook.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/dd/PhoneBook.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.ws.jaxrs.sample.dd;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+
+import javax.ws.rs.PathParam;
+import javax.ws.rs.core.Response;
+
+public class PhoneBook {
+
+    private static Map<String, PhoneBookEntry> phoneBookEntryMapping = new HashMap<String, PhoneBookEntry>();
+
+    public Response createEntry(PhoneBookEntryBean bean) {
+        Response resp = null;
+        PhoneBookEntry entry = new PhoneBookEntry(bean.getFirstName(), bean
+                .getLastName(), bean.getPhoneNumber());
+        phoneBookEntryMapping.put(bean.getPhoneNumber(), entry);
+        return resp;
+    }
+
+    public Response updateEntry(PhoneBookEntryBean bean) {
+        Response resp = null;
+        PhoneBookEntry entry = phoneBookEntryMapping.get(bean.getPhoneNumber());
+        if (entry == null) {
+            return Response.status(404).build();
+        }
+        entry.setFirstName(bean.getFirstName());
+        entry.setLastName(bean.getLastName());
+        return resp;
+    }
+
+    public PhoneBookEntry getEntry(@PathParam(value = "phoneNumber") String phoneNumber) {
+        return phoneBookEntryMapping.get(phoneNumber);
+    }
+
+    public Response deleteEntry(@PathParam(value = "phoneNumber") String phoneNumber) {
+        PhoneBookEntry entry = phoneBookEntryMapping.remove(phoneNumber);
+        if (entry == null) {
+            return Response.status(404).build();
+        }
+        return Response.ok().build();
+    }
+
+    public PhoneBookBean getEntries() {
+        PhoneBookBean bean = new PhoneBookBean();
+        Collection<PhoneBookEntryBean> entryBeans = new HashSet<PhoneBookEntryBean>();
+        for (PhoneBookEntry entry : phoneBookEntryMapping.values()) {
+            entryBeans.add(entry.get());
+        }
+        bean.setEntries(entryBeans);
+        return bean;
+    }
+
+    public static void clear() {
+        phoneBookEntryMapping.clear();
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/dd/PhoneBookBean.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/dd/PhoneBookBean.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/dd/PhoneBookBean.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/dd/PhoneBookBean.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.ws.jaxrs.sample.dd;
+
+import java.util.Collection;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "entries", namespace = "http://com.ibm.ws.jaxrs.sample.dd")
+@XmlAccessorType(value = XmlAccessType.FIELD)
+public class PhoneBookBean {
+
+    @XmlElement(name = "entry", namespace = "http://com.ibm.ws.jaxrs.sample.dd")
+    private Collection<PhoneBookEntryBean> entries;
+
+    public Collection<PhoneBookEntryBean> getEntries() {
+        return entries;
+    }
+
+    public void setEntries(Collection<PhoneBookEntryBean> entries) {
+        this.entries = entries;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/dd/PhoneBookEntry.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/dd/PhoneBookEntry.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/dd/PhoneBookEntry.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/dd/PhoneBookEntry.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.ws.jaxrs.sample.dd;
+
+public class PhoneBookEntry {
+
+    private String firstName;
+
+    private String lastName;
+
+    private String phoneNumber;
+
+    public PhoneBookEntry(String firstName, String lastName, String phoneNumber) {
+        this.firstName = firstName;
+        this.lastName = lastName;
+        this.phoneNumber = phoneNumber;
+    }
+
+    public PhoneBookEntryBean get() {
+        PhoneBookEntryBean bean = new PhoneBookEntryBean();
+        bean.setFirstName(firstName);
+        bean.setLastName(lastName);
+        bean.setPhoneNumber(phoneNumber);
+        return bean;
+    }
+
+    public String getPhoneNumber() {
+        return phoneNumber;
+    }
+
+    public String getFirstName() {
+        return firstName;
+    }
+
+    public void setFirstName(String firstName) {
+        this.firstName = firstName;
+    }
+
+    public String getLastName() {
+        return lastName;
+    }
+
+    public void setLastName(String lastName) {
+        this.lastName = lastName;
+    }
+
+    public void setPhoneNumber(String phoneNumber) {
+        this.phoneNumber = phoneNumber;
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/dd/PhoneBookEntryBean.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/dd/PhoneBookEntryBean.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/dd/PhoneBookEntryBean.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/sample/dd/PhoneBookEntryBean.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.sample.dd;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "entry", namespace = "http://com.ibm.ws.jaxrs.sample.dd")
+public class PhoneBookEntryBean {
+
+    private String firstName;
+
+    private String lastName;
+
+    private String phoneNumber;
+
+    public String getFirstName() {
+        return firstName;
+    }
+
+    public void setFirstName(String firstName) {
+        this.firstName = firstName;
+    }
+
+    public String getLastName() {
+        return lastName;
+    }
+
+    public void setLastName(String lastName) {
+        this.lastName = lastName;
+    }
+
+    public String getPhoneNumber() {
+        return phoneNumber;
+    }
+
+    public void setPhoneNumber(String phoneNumber) {
+        this.phoneNumber = phoneNumber;
+    }
+
+}



Mime
View raw message