You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wink.apache.org by ng...@apache.org on 2009/06/23 07:38:19 UTC
svn commit: r787553 [28/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...
Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/ApplicationProcessorTests.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/ApplicationProcessorTests.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/ApplicationProcessorTests.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/ApplicationProcessorTests.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,173 @@
+/*
+ * 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;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+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.lifecycle.LifecycleManager;
+import com.ibm.ws.jaxrs.lifecycle.LifecycleManagerFactory;
+import com.ibm.ws.jaxrs.model.testimpls.Book;
+import com.ibm.ws.jaxrs.model.testimpls.ContextProvider;
+import com.ibm.ws.jaxrs.model.testimpls.Magazine;
+
+/**
+ * Verify function in ApplicationProcessor class
+ * @author Dustin
+ *
+ */
+public class ApplicationProcessorTests extends TestCase {
+
+ /*
+ * Verify we can build metadata from Class instances
+ */
+ public void testBuildFromClasses() throws Exception {
+ Set<Class<?>> classes = new HashSet<Class<?>>();
+ classes.add(Book.class);
+ classes.add(Magazine.class);
+ classes.add(ContextProvider.class);
+ MyApplication app = new MyApplication(classes, null);
+ ApplicationProcessor appProcessor = new ApplicationProcessor(null,
+ Thread.currentThread().getContextClassLoader());
+ JAXRSInfoOutput output = appProcessor.processApplication(app);
+ assertNotNull(output);
+ List<ClassResourceInfo> classInfoList = output.getClassInfoList();
+ assertNotNull(classInfoList);
+ assertEquals(2, classInfoList.size());
+ ClassResourceInfo info = TestUtils.getClassResourceInfo(classInfoList,
+ Book.class.getName());
+ assertNotNull(info);
+ info = TestUtils.getClassResourceInfo(classInfoList, Magazine.class
+ .getName());
+ assertNotNull(info);
+ List<ProviderInfo> providerInfoList = output.getProviderInfoList();
+ assertNotNull(providerInfoList);
+ assertEquals(1, providerInfoList.size());
+ ProviderInfo providerInfo = TestUtils.getProviderInfo(providerInfoList,
+ ContextProvider.class.getName());
+ assertNotNull(providerInfo);
+ }
+
+ /*
+ * Verify we can build metadata from Class and singleton instances
+ */
+ public void testBuildFromClassesAndSingletons() throws Exception {
+ Set<Class<?>> classes = new HashSet<Class<?>>();
+ classes.add(Book.class);
+ classes.add(Magazine.class);
+ Set<Object> singletons = new HashSet<Object>();
+ ContextProvider singleton = new ContextProvider();
+ singletons.add(singleton);
+ MyApplication app = new MyApplication(classes, singletons);
+ ApplicationProcessor appProcessor = new ApplicationProcessor(null,
+ Thread.currentThread().getContextClassLoader());
+ JAXRSInfoOutput output = appProcessor.processApplication(app);
+ assertNotNull(output);
+ List<ClassResourceInfo> classInfoList = output.getClassInfoList();
+ assertNotNull(classInfoList);
+ assertEquals(2, classInfoList.size());
+ ClassResourceInfo info = TestUtils.getClassResourceInfo(classInfoList,
+ Book.class.getName());
+ assertNotNull(info);
+ info = TestUtils.getClassResourceInfo(classInfoList, Magazine.class
+ .getName());
+ assertNotNull(info);
+ List<ProviderInfo> providerInfoList = output.getProviderInfoList();
+ assertNotNull(providerInfoList);
+ assertEquals(1, providerInfoList.size());
+ ProviderInfo providerInfo = TestUtils.getProviderInfo(providerInfoList,
+ ContextProvider.class.getName());
+ assertNotNull(providerInfo);
+ assertTrue(providerInfo.isSingleton());
+ LifecycleManager mgr = LifecycleManagerFactory
+ .getLifeCycleManager(providerInfo);
+ assertEquals(singleton, mgr.createInstance(providerInfo, null));
+ }
+
+ /*
+ * Verify no metadata is built if an @Path or @Provider annotation is not present
+ */
+ public void testBuildFromNonResourceProviderClasses() throws Exception {
+ Set<Class<?>> classes = new HashSet<Class<?>>();
+ classes.add(String.class);
+ MyApplication app = new MyApplication(classes, null);
+ ApplicationProcessor appProcessor = new ApplicationProcessor(null,
+ Thread.currentThread().getContextClassLoader());
+ JAXRSInfoOutput output = appProcessor.processApplication(app);
+ assertNotNull(output);
+ List<ClassResourceInfo> classInfoList = output.getClassInfoList();
+ assertNotNull(classInfoList);
+ assertEquals(0, classInfoList.size());
+ }
+
+ /*
+ * Verify error is logged when multiple instances of the same class are provided in
+ * the list of singletons returned by the Application subclass
+ */
+ public void testErrorMultipleSingletons() throws Exception {
+ Set<Class<?>> classes = new HashSet<Class<?>>();
+ classes.add(Book.class);
+ classes.add(Magazine.class);
+ Set<Object> singletons = new HashSet<Object>();
+ singletons.add(new ContextProvider());
+ singletons.add(new ContextProvider());
+ MyApplication app = new MyApplication(classes, singletons);
+ ApplicationProcessor appProcessor = new ApplicationProcessor(null,
+ Thread.currentThread().getContextClassLoader());
+ RuntimeException re = null;
+ try {
+ JAXRSInfoOutput output = appProcessor.processApplication(app);
+ } catch (RuntimeException e) {
+ re = e;
+ }
+ assertNotNull(re);
+ }
+
+ public class MyApplication extends Application {
+
+ private Set<Class<?>> classes;
+
+ private Set<Object> singletons;
+
+ public MyApplication(Set<Class<?>> classes, Set<Object> singletons) {
+ this.classes = classes;
+ this.singletons = singletons;
+ }
+
+ public Set<Class<?>> getClasses() {
+ return classes;
+ }
+
+ public Set<Object> getSingletons() {
+ return singletons;
+ }
+
+ }
+
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/ProviderModelBuilderTests.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/ProviderModelBuilderTests.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/ProviderModelBuilderTests.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/ProviderModelBuilderTests.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,198 @@
+/*
+ * 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;
+
+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.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.jaxrs.model.ProviderInfo;
+
+import com.ibm.ws.jaxrs.metadata.MetadataRegistry;
+
+/**
+ * This class will hold a collection of tests that will verify functionality
+ * responsible for building metadata about classes annotated with the
+ *
+ * @Provider annoation.
+ *
+ */
+public class ProviderModelBuilderTests extends TestCase {
+
+ /**
+ * This will verify we correctly build metadata for a class annotated with
+ * the
+ *
+ * @Provider annotation that implements a single provider type.
+ */
+ public void testBuildSimpleProviderMetadata() throws Exception {
+ JAXRSInfoInput source = new JAXRSInfoInput(
+ JAXRSInfoInput.Type.REFLECTION);
+ Map<String, Class<?>> classes = new HashMap<String, Class<?>>();
+ classes.put(StringMessageReader.class.getName(),
+ StringMessageReader.class);
+ source.setClasses(classes);
+ JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry
+ .getImplementation(JAXRSInfoBuilderFactory.class);
+ JAXRSInfoBuilder builder = factory
+ .getInfoBuilder(source.getInputType());
+ JAXRSInfoOutput output = builder.buildRESTInfo(source);
+ List<ProviderInfo> providerInfoList = output.getProviderInfoList();
+ assertNotNull(providerInfoList);
+ assertEquals(1, providerInfoList.size());
+ ProviderInfo providerInfo = providerInfoList.get(0);
+ assertNotNull(providerInfo.getProviderTypes());
+ List<ProviderInfo.Type> typeList = providerInfo.getProviderTypes();
+ assertNotNull(typeList);
+ assertEquals(1, typeList.size());
+ assertTrue(typeList.contains(ProviderInfo.Type.MessageBodyReader));
+
+ source = new JAXRSInfoInput(JAXRSInfoInput.Type.REFLECTION);
+ classes.clear();
+ classes.put(StringMessageWriter.class.getName(),
+ StringMessageWriter.class);
+ source.setClasses(classes);
+ output = builder.buildRESTInfo(source);
+ providerInfoList = output.getProviderInfoList();
+ assertNotNull(providerInfoList);
+ assertEquals(1, providerInfoList.size());
+ providerInfo = providerInfoList.get(0);
+ assertNotNull(providerInfo.getProviderTypes());
+ typeList = providerInfo.getProviderTypes();
+ assertNotNull(typeList);
+ assertEquals(1, typeList.size());
+ assertTrue(typeList.contains(ProviderInfo.Type.MessageBodyWriter));
+ }
+
+ /**
+ * This will verify we correctly build metadata for a class annotated with
+ * the
+ *
+ * @Provider annotation that implements multiple provider types.
+ */
+ public void testBuildComplexProvider() throws Exception {
+ JAXRSInfoInput source = new JAXRSInfoInput(
+ JAXRSInfoInput.Type.REFLECTION);
+ Map<String, Class<?>> classes = new HashMap<String, Class<?>>();
+ classes.put(MultiProvider.class.getName(), MultiProvider.class);
+ source.setClasses(classes);
+ JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry
+ .getImplementation(JAXRSInfoBuilderFactory.class);
+ JAXRSInfoBuilder builder = factory
+ .getInfoBuilder(source.getInputType());
+ JAXRSInfoOutput output = builder.buildRESTInfo(source);
+ List<ProviderInfo> providerInfoList = output.getProviderInfoList();
+ assertNotNull(providerInfoList);
+ assertEquals(1, providerInfoList.size());
+ ProviderInfo providerInfo = providerInfoList.get(0);
+ assertNotNull(providerInfo.getProviderTypes());
+ List<ProviderInfo.Type> typeList = providerInfo.getProviderTypes();
+ assertEquals(3, typeList.size());
+ assertTrue(typeList.contains(ProviderInfo.Type.MessageBodyWriter));
+ assertTrue(typeList.contains(ProviderInfo.Type.MessageBodyReader));
+ assertTrue(typeList.contains(ProviderInfo.Type.ExceptionMapper));
+ }
+
+ @Provider
+ public static class StringMessageReader implements MessageBodyReader<String> {
+
+ public boolean isReadable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) {
+ return false;
+ }
+
+ public String readFrom(Class<String> arg0, Type arg1, Annotation[] arg2, MediaType arg3, MultivaluedMap<String, String> arg4, InputStream arg5)
+ throws IOException, WebApplicationException {
+ return null;
+ }
+ }
+
+ @Provider
+ public static class StringMessageWriter implements MessageBodyWriter<String> {
+
+ 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<String, Object> 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;
+ }
+
+ }
+
+ @Provider
+ public static class MultiProvider implements MessageBodyWriter<String>, MessageBodyReader<String>, ExceptionMapper<Exception> {
+
+ public Response toResponse(Exception exception) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ 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<String, Object> 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;
+ }
+
+ public boolean isReadable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) {
+ return false;
+ }
+
+ public String readFrom(Class<String> arg0, Type arg1, Annotation[] arg2, MediaType arg3, MultivaluedMap<String, String> arg4, InputStream arg5)
+ throws IOException, WebApplicationException {
+ return null;
+ }
+
+ }
+
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/ResourceModelBuilderTests.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/ResourceModelBuilderTests.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/ResourceModelBuilderTests.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/ResourceModelBuilderTests.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,643 @@
+/*
+ * 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;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HEAD;
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.model.MethodDispatcher;
+import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+
+import com.ibm.rest.test.utils.TestUtils;
+import com.ibm.ws.jaxrs.annotations.Alias;
+import com.ibm.ws.jaxrs.annotations.Aliases;
+import com.ibm.ws.jaxrs.metadata.MetadataRegistry;
+
+/**
+ * Various tests for resource data model building functionality.
+ *
+ */
+public class ResourceModelBuilderTests extends TestCase {
+
+ /**
+ * Verify the functionality in our ResourceBuilderFactory.
+ */
+ public void testGetBuilder() throws Exception {
+
+ // first test the positive case
+ JAXRSInfoInput source = new JAXRSInfoInput(
+ JAXRSInfoInput.Type.REFLECTION);
+ JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry
+ .getImplementation(JAXRSInfoBuilderFactory.class);
+ JAXRSInfoBuilder builder = factory
+ .getInfoBuilder(source.getInputType());
+ assertTrue(builder instanceof ReflectiveJAXRSInfoBuilder);
+
+ // now verify that we throw an IllegalArgumentException when appropriate
+ source = new JAXRSInfoInput(null);
+ Exception e = null;
+ try {
+ builder = factory.getInfoBuilder(source.getInputType());
+ } catch (Exception caught) {
+ e = caught;
+ }
+ assertTrue(e instanceof IllegalArgumentException);
+ }
+
+ /**
+ * Verify the functionality in our ResourceBuilderFactory.
+ */
+ public void testGetBuilderXML() throws Exception {
+
+ // first test the positive case
+ JAXRSInfoInput source = new JAXRSInfoInput(
+ JAXRSInfoInput.Type.XMLCONFIG);
+ JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry
+ .getImplementation(JAXRSInfoBuilderFactory.class);
+ JAXRSInfoBuilder builder = factory
+ .getInfoBuilder(source.getInputType());
+ assertTrue(builder instanceof XMLJAXRSInfoBuilder);
+ }
+
+ /**
+ * Test that we can correctly build a single ClassResourceInfo object from a
+ * single Class object.
+ */
+ public void testBuildSingleClassResourceInfo() throws Exception {
+
+ // first let's make sure we get back a ClassResourceInfo if necessary
+ Map<String, Class<?>> classes = new HashMap<String, Class<?>>();
+ classes.put(Employees.class.getName(), Employees.class);
+ 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);
+ assertNotNull(output);
+ List<ClassResourceInfo> classInfoList = output.getClassInfoList();
+ assertNotNull(classInfoList);
+ assertEquals(classInfoList.size(), 1);
+ ClassResourceInfo info = classInfoList.get(0);
+ assertNotNull(info.getPath());
+ assertEquals(info.getPath(), "/employees");
+ assertNotNull(info.getAliasPaths());
+ assertEquals(1, info.getAliasPaths().length);
+ assertEquals("/workers", info.getAliasPaths()[0]);
+
+ // now let's make sure that if we supply a class without an @Path
+ // annotation
+ // that we get back an empty list
+ classes.clear();
+ classes.put(NotAResourceClass.class.getName(), NotAResourceClass.class);
+ source = new JAXRSInfoInput(JAXRSInfoInput.Type.REFLECTION);
+ source.setClasses(classes);
+ builder = factory.getInfoBuilder(source.getInputType());
+ output = builder.buildRESTInfo(source);
+ assertNotNull(output);
+ classInfoList = output.getClassInfoList();
+ assertNotNull(classInfoList);
+ assertEquals(classInfoList.size(), 0);
+ }
+
+ /**
+ * This will verify that our ResourceBuilder builds the appropriate objects
+ * to model REST operations on a resource class.
+ */
+ public void testBuildSingleOperationInfo() throws Exception {
+ Map<String, Class<?>> classes = new HashMap<String, Class<?>>();
+ classes.put(Employees.class.getName(), Employees.class);
+ 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);
+ assertNotNull(output);
+ List<ClassResourceInfo> classInfoList = output.getClassInfoList();
+ assertNotNull(classInfoList);
+ assertEquals(classInfoList.size(), 1);
+ ClassResourceInfo classInfo = classInfoList.get(0);
+ MethodDispatcher md = classInfo.getMethodDispatcher();
+ assertNotNull(md);
+ assertNotNull(md.getOperationResourceInfos());
+ assertEquals(md.getOperationResourceInfos().size(), 1);
+ OperationResourceInfo orInfo = md.getOperationResourceInfos()
+ .iterator().next();
+ // assertNotNull(orInfo.getURITemplate());
+ // assertEquals(orInfo.getURITemplate().getValue(), "/lastname/{id}");
+ assertEquals(orInfo.getHttpMethod(), "GET");
+ }
+
+ /**
+ * Test that we can correctly build a multiple ClassResourceInfo object from
+ * a list of Class objects.
+ */
+ public void testBuildMultipleClassResourceInfos() throws Exception {
+ Map<String, Class<?>> classes = new HashMap<String, Class<?>>();
+ classes.put(Employees.class.getName(), Employees.class);
+ classes.put(Departments.class.getName(), Departments.class);
+ 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);
+ assertNotNull(output);
+ List<ClassResourceInfo> classInfoList = output.getClassInfoList();
+ assertNotNull(classInfoList);
+ assertEquals(classInfoList.size(), 2);
+ for (ClassResourceInfo classInfo : classInfoList) {
+ if (classInfo.getServiceClass().getName().equals(Employees.class)) {
+ assertEquals(classInfo.getPath(), "/employees");
+ assertNotNull(classInfo.getAliasPaths());
+ assertEquals(1, classInfo.getAliasPaths().length);
+ assertEquals("/workers", classInfo.getAliasPaths()[0]);
+ } else if (classInfo.getServiceClass().getName().equals(
+ Departments.class)) {
+ assertEquals(classInfo.getPath(), "/departments");
+ assertNotNull(classInfo.getAliasPaths());
+ assertEquals(2, classInfo.getAliasPaths().length);
+ assertEquals("/teams", classInfo.getAliasPaths()[0]);
+ assertEquals("/depts", classInfo.getAliasPaths()[1]);
+ }
+ }
+ }
+
+ /**
+ * This will verify that our ResourceBuilder builds the appropriate objects
+ * to model REST operations on a resource class.
+ */
+ public void testBuildMultipleOperationResourceInfos() throws Exception {
+ Map<String, Class<?>> classes = new HashMap<String, Class<?>>();
+ classes.put(Departments.class.getName(), Departments.class);
+ 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);
+ assertNotNull(output);
+ List<ClassResourceInfo> classInfoList = output.getClassInfoList();
+ ClassResourceInfo classInfo = classInfoList.get(0);
+ MethodDispatcher md = classInfo.getMethodDispatcher();
+ assertNotNull(md);
+ assertNotNull(md.getOperationResourceInfos());
+ assertEquals(md.getOperationResourceInfos().size(), 8);
+ for (OperationResourceInfo orInfo : md.getOperationResourceInfos()) {
+ if (orInfo.getAnnotatedMethod().getName().equals("getDepartments")) {
+ assertEquals(orInfo.getHttpMethod(), "GET");
+ assertFalse(orInfo.isSubResourceMethod());
+ } else if (orInfo.getAnnotatedMethod().getName().equals(
+ "getDepartmentLocation")) {
+ assertEquals(orInfo.getHttpMethod(), "GET");
+ assertTrue(orInfo.isSubResourceMethod());
+ } else if (orInfo.getAnnotatedMethod().getName().equals(
+ "getDepartmentTimeZone")) {
+ assertEquals(orInfo.getHttpMethod(), "HEAD");
+ assertTrue(orInfo.isSubResourceMethod());
+ } else if (orInfo.getAnnotatedMethod().getName().equals(
+ "createDepartment")) {
+ assertEquals(orInfo.getHttpMethod(), "POST");
+ assertTrue(orInfo.isSubResourceMethod());
+ } else if (orInfo.getAnnotatedMethod().getName().equals(
+ "updateDepartmentName")) {
+ assertEquals(orInfo.getHttpMethod(), "PUT");
+ assertTrue(orInfo.isSubResourceMethod());
+ } else if (orInfo.getAnnotatedMethod().getName().equals(
+ "deleteDepartment")) {
+ assertEquals(orInfo.getHttpMethod(), "DELETE");
+ assertTrue(orInfo.isSubResourceMethod());
+ } else if (orInfo.getAnnotatedMethod().getName().equals(
+ "getDepartmentsCustom")) {
+ assertEquals(orInfo.getHttpMethod(), "GET");
+ assertFalse(orInfo.isSubResourceMethod());
+ } else if (orInfo.getAnnotatedMethod().getName().equals(
+ "updateDepartmentNameCustom")) {
+ assertEquals(orInfo.getHttpMethod(), "PUT");
+ assertTrue(orInfo.isSubResourceMethod());
+ }
+ }
+ }
+
+ /**
+ * This test will verify that we can correctly build a list of
+ * ClassResourceInfo objects that contain subresources.
+ */
+ public void testBuildSubResources() throws Exception {
+ Map<String, Class<?>> classes = new HashMap<String, Class<?>>();
+ classes.put(Leagues.class.getName(), Leagues.class);
+ 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);
+ assertNotNull(output);
+ List<ClassResourceInfo> classInfoList = output.getClassInfoList();
+ assertNotNull(classInfoList);
+ assertEquals(classInfoList.size(), 1);
+ ClassResourceInfo classInfo = TestUtils.getClassResourceInfo(
+ classInfoList, Leagues.class.getName());
+ assertNotNull(classInfo);
+ assertNotNull(classInfo.getSubClassResourceInfo());
+ assertEquals(classInfo.getSubClassResourceInfo().size(), 1);
+ }
+
+ /**
+ * This will verify that we build up OperationResourceInfo objects when
+ * a method starts with 'get', 'put', 'post', or 'delete', but does
+ * not contain a request method designator.
+ */
+ public void testBuildNoMethodAnnotations() throws Exception {
+ Map<String, Class<?>> classes = new HashMap<String, Class<?>>();
+ classes.put(Reservation.class.getName(), Reservation.class);
+ 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);
+ assertNotNull(output);
+ List<ClassResourceInfo> classInfoList = output.getClassInfoList();
+ assertNotNull(classInfoList);
+ assertEquals(classInfoList.size(), 1);
+ ClassResourceInfo info = classInfoList.get(0);
+ MethodDispatcher md = info.getMethodDispatcher();
+ assertNotNull(md);
+ List<OperationResourceInfo> opInfos = md.getOperationResourceInfos();
+ assertNotNull(opInfos);
+ assertEquals(0, opInfos.size());
+
+ // test a resource with an annotated method that happened to have a "get" in
+ // front of the method name but has a @POST on it
+ classes = new HashMap<String, Class<?>>();
+ classes.put(ReservationWithMismatchAnnotationAndName.class.getName(),
+ ReservationWithMismatchAnnotationAndName.class);
+ source = new JAXRSInfoInput(JAXRSInfoInput.Type.REFLECTION);
+ source.setClasses(classes);
+ factory = (JAXRSInfoBuilderFactory) MetadataRegistry
+ .getImplementation(JAXRSInfoBuilderFactory.class);
+ builder = factory.getInfoBuilder(source.getInputType());
+ output = builder.buildRESTInfo(source);
+ assertNotNull(output);
+ classInfoList = output.getClassInfoList();
+ assertNotNull(classInfoList);
+ assertEquals(classInfoList.size(), 1);
+ info = classInfoList.get(0);
+ md = info.getMethodDispatcher();
+ assertNotNull(md);
+ opInfos = md.getOperationResourceInfos();
+ assertNotNull(opInfos);
+ assertEquals(1, opInfos.size());
+
+ // test a resource with an annotation on a mismatched method (@POST on get*) and then
+ // another method with a post* name
+ classes = new HashMap<String, Class<?>>();
+ classes.put(ReservationWithNameAndAnnotationMethod.class.getName(),
+ ReservationWithNameAndAnnotationMethod.class);
+ source = new JAXRSInfoInput(JAXRSInfoInput.Type.REFLECTION);
+ source.setClasses(classes);
+ factory = (JAXRSInfoBuilderFactory) MetadataRegistry
+ .getImplementation(JAXRSInfoBuilderFactory.class);
+ builder = factory.getInfoBuilder(source.getInputType());
+ output = builder.buildRESTInfo(source);
+ assertNotNull(output);
+ classInfoList = output.getClassInfoList();
+ assertNotNull(classInfoList);
+ assertEquals(classInfoList.size(), 1);
+ info = classInfoList.get(0);
+ md = info.getMethodDispatcher();
+ assertNotNull(md);
+ opInfos = md.getOperationResourceInfos();
+ assertNotNull(opInfos);
+ assertEquals(1, opInfos.size());
+ }
+
+ /**
+ * This will verify that we build up OperationResourceInfo objects based
+ * on annotations when they are present and that we do NOT automatically
+ * match the methods that start with the HTTP method types.
+ */
+ public void testBuildMethodAnnotationsAndNoAnnotations() throws Exception {
+ Map<String, Class<?>> classes = new HashMap<String, Class<?>>();
+ classes.put(Tickets.class.getName(), Tickets.class);
+ 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);
+ assertNotNull(output);
+ List<ClassResourceInfo> classInfoList = output.getClassInfoList();
+ assertNotNull(classInfoList);
+ assertEquals(classInfoList.size(), 1);
+ ClassResourceInfo info = classInfoList.get(0);
+ MethodDispatcher md = info.getMethodDispatcher();
+ assertNotNull(md);
+ List<OperationResourceInfo> opInfos = md.getOperationResourceInfos();
+ assertNotNull(opInfos);
+ assertEquals(4, opInfos.size());
+ for (OperationResourceInfo opInfo : opInfos) {
+ if ("GET".equalsIgnoreCase(opInfo.getHttpMethod())) {
+ assertEquals("showTickets", opInfo.getAnnotatedMethod()
+ .getName());
+ }
+ if ("POST".equalsIgnoreCase(opInfo.getHttpMethod())) {
+ assertEquals("createTickets", opInfo.getAnnotatedMethod()
+ .getName());
+ }
+ if ("PUT".equalsIgnoreCase(opInfo.getHttpMethod())) {
+ assertEquals("updateTickets", opInfo.getAnnotatedMethod()
+ .getName());
+ }
+ if ("DELETE".equalsIgnoreCase(opInfo.getHttpMethod())) {
+ assertEquals("removeTickets", opInfo.getAnnotatedMethod()
+ .getName());
+ }
+ }
+ }
+
+ @Path(value = "/employees")
+ @Alias(value = "/workers")
+ public class Employees {
+
+ @GET
+ @Path(value = "/{id}/lastname")
+ public String getEmployeeLastName(String empId) {
+ return "Smith";
+ }
+
+ }
+
+ @Path(value = "/departments")
+ @Aliases(value = { @Alias(value = "/teams"), @Alias(value = "/depts") })
+ public class Departments {
+
+ @GET
+ public List getDepartments() {
+ return null;
+ }
+
+ @CustomGetAnnotation
+ public List getDepartmentsCustom() {
+ return null;
+ }
+
+ @GET
+ @Path(value = "/{id}/location")
+ public String getDepartmentLocation(String deptId) {
+ return "Austin, TX";
+ }
+
+ @HEAD
+ @Path(value = "/{id}")
+ public String getDepartmentTimeZone(String deptId) {
+ return "CST";
+ }
+
+ @POST
+ @Path(value = "/{id}")
+ public void createDepartment(Object dept) {
+
+ }
+
+ @PUT
+ @Path(value = "{id}/{name}")
+ public void updateDepartmentName(String deptId, String newName) {
+
+ }
+
+ @CustomPutAnnotation
+ @Path(value = "{id}/{name}")
+ public void updateDepartmentNameCustom(String deptId, String newName) {
+
+ }
+
+ @DELETE
+ @Path(value = "/{id}")
+ public void deleteDepartment(String deptId) {
+
+ }
+
+ public void someNonHttpMethod() {
+
+ }
+ }
+
+ @Path(value = "/leagues")
+ public class Leagues {
+
+ Map<String, League> leagues = new HashMap<String, League>();
+
+ @Path(value = "{name}")
+ public League getLeague(String leagueName) {
+ return leagues.get(leagueName);
+ }
+
+ @POST
+ @Path(value = "{name}")
+ public League createLeague(String name) {
+ League league = new League(name);
+ leagues.put(name, league);
+ return league;
+ }
+
+ }
+
+ public class League {
+
+ String name;
+
+ League(String name) {
+ this.name = name;
+ }
+
+ @GET
+ public String getName() {
+ return name;
+ }
+
+ @PUT
+ public void updateName(String name) {
+ this.name = name;
+ }
+
+ }
+
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target(ElementType.METHOD)
+ @HttpMethod("GET")
+ public @interface CustomGetAnnotation {
+ }
+
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target(ElementType.METHOD)
+ @HttpMethod("PUT")
+ public @interface CustomPutAnnotation {
+ }
+
+ public class NotAResourceClass {
+
+ public void doSomething() {
+
+ }
+ }
+
+ @Path(value = "/reservation")
+ public class Reservation {
+
+ public void getReservation() {
+
+ }
+
+ public void deleteReservation() {
+
+ }
+
+ public void postReservation() {
+
+ }
+
+ public void putReservation() {
+
+ }
+
+ public void getAllReservations() {
+
+ }
+
+ }
+
+ @Path(value = "/reservationwithmismatch")
+ public class ReservationWithMismatchAnnotationAndName {
+
+ @POST
+ public void getReservation() {
+
+ }
+
+ public void deleteReservation() {
+
+ }
+
+ public void putReservation() {
+
+ }
+
+ public void getAllReservations() {
+
+ }
+
+ }
+
+ @Path(value = "/reservationwithnameandannotation")
+ public class ReservationWithNameAndAnnotationMethod {
+
+ @POST
+ public void getReservation() {
+
+ }
+
+ public void deleteReservation() {
+
+ }
+
+ public void postReservation() {
+
+ }
+
+ public void putReservation() {
+
+ }
+ }
+
+ @Path(value = "/reservation")
+ public class Tickets {
+
+ @GET
+ public void showTickets() {
+
+ }
+
+ public void getTickets() {
+
+ }
+
+ @POST
+ public void createTickets() {
+
+ }
+
+ public void postTickets() {
+
+ }
+
+ @PUT
+ public void updateTickets() {
+
+ }
+
+ public void putTickets() {
+
+ }
+
+ @DELETE
+ public void removeTickets() {
+
+ }
+
+ public void deleteTickets() {
+
+ }
+
+ }
+
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/CustomProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/CustomProvider.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/CustomProvider.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/CustomProvider.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,47 @@
+/*
+ * 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.dd;
+
+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;
+
+public class CustomProvider implements MessageBodyWriter<String> {
+
+ 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 void writeTo(String arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4, MultivaluedMap<String, Object> arg5, OutputStream arg6)
+ throws IOException, WebApplicationException {
+
+ }
+
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/League.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/League.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/League.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/League.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.model.dd;
+
+import java.util.Collection;
+
+public class League {
+
+ public String getName() {
+ return null;
+ }
+
+ public Collection<Team> getTeams() {
+ return null;
+ }
+
+ public Team getTeam(String team) {
+ return null;
+ }
+
+ public void createTeam(Team team) {
+
+ }
+
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/ModelDDTests.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/ModelDDTests.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/ModelDDTests.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/ModelDDTests.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,267 @@
+/*
+ * 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.dd;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.util.List;
+
+import javax.ws.rs.core.MediaType;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.model.MethodDispatcher;
+import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+import org.apache.cxf.jaxrs.model.ProviderInfo;
+
+import com.ibm.rest.test.utils.TestUtils;
+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;
+
+public class ModelDDTests extends TestCase {
+
+ /**
+ * Verify we can build metadata for a simple resource from a
+ * configuration file.
+ */
+ public void testBuildInfoFromDD() throws Exception {
+ String path = TestUtils.getTestResourceDirPath();
+ path = !path.endsWith("/") ? (path + "/") : path;
+ path = path + "modelddtests/newsstory/ibm-jaxrs.xml";
+ File configFile = new File(path);
+ JAXRSInfoInput source = new JAXRSInfoInput(
+ JAXRSInfoInput.Type.XMLCONFIG);
+ source.setConfigFile(configFile);
+ source.setClassLoader(Thread.currentThread().getContextClassLoader());
+ JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry
+ .getImplementation(JAXRSInfoBuilderFactory.class);
+ JAXRSInfoBuilder builder = factory
+ .getInfoBuilder(source.getInputType());
+ JAXRSInfoOutput output = builder.buildRESTInfo(source);
+ assertNotNull(output);
+
+ // test the class information
+ List<ClassResourceInfo> classInfoList = output.getClassInfoList();
+ assertNotNull(classInfoList);
+ assertEquals(1, classInfoList.size());
+ ClassResourceInfo classInfo = classInfoList.get(0);
+ assertEquals("/newsstory/{id}", classInfo.getPath());
+ assertNotNull(classInfo.getURITemplate());
+
+ // now let's move on to testing the method information
+ MethodDispatcher md = classInfo.getMethodDispatcher();
+ assertNotNull(md);
+ List<OperationResourceInfo> opInfos = md.getOperationResourceInfos();
+ assertNotNull(opInfos);
+ assertEquals(1, opInfos.size());
+ OperationResourceInfo opInfo = opInfos.iterator().next();
+ assertEquals("/title", opInfo.getPath());
+ assertEquals("GET", opInfo.getHttpMethod());
+ assertNotNull(opInfo.getURITemplate());
+
+ // let's do some consumes/produces testing
+ List<MediaType> consumes = opInfo.getConsumes();
+ assertNotNull(consumes);
+ assertEquals(1, consumes.size());
+ assertEquals("text", consumes.get(0).getType());
+ assertEquals("xml", consumes.get(0).getSubtype());
+
+ List<MediaType> produces = opInfo.getProduces();
+ assertNotNull(produces);
+ assertEquals(1, produces.size());
+ assertEquals("text", produces.get(0).getType());
+ assertEquals("xml", produces.get(0).getSubtype());
+
+ // check encoding and default value
+ assertTrue(opInfo.isEncodedEnabled());
+ assertEquals("someDefaultValue", opInfo.getDefaultParameterValue());
+
+ }
+
+ /**
+ * Verify we can build metadata for a resource and subresource from the
+ * configuration file.
+ */
+ public void testBuildSubInfoFromDD() throws Exception {
+ String path = TestUtils.getTestResourceDirPath();
+ path = !path.endsWith("/") ? (path + "/") : path;
+ path = path + "modelddtests/league/ibm-jaxrs.xml";
+ File configFile = new File(path);
+ JAXRSInfoInput source = new JAXRSInfoInput(
+ JAXRSInfoInput.Type.XMLCONFIG);
+ source.setConfigFile(configFile);
+ source.setClassLoader(Thread.currentThread().getContextClassLoader());
+ JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry
+ .getImplementation(JAXRSInfoBuilderFactory.class);
+ JAXRSInfoBuilder builder = factory
+ .getInfoBuilder(source.getInputType());
+ JAXRSInfoOutput output = builder.buildRESTInfo(source);
+ assertNotNull(output);
+
+ // test the class and subclass information
+ List<ClassResourceInfo> classInfoList = output.getClassInfoList();
+ assertNotNull(classInfoList);
+ assertEquals(1, classInfoList.size());
+ ClassResourceInfo leagueInfo = classInfoList.get(0);
+ assertEquals("/league/{id}", leagueInfo.getPath());
+ assertNotNull(leagueInfo.getURITemplate());
+ List<ClassResourceInfo> subResourceInfos = leagueInfo
+ .getSubClassResourceInfo();
+ assertNotNull(subResourceInfos);
+ assertEquals(1, subResourceInfos.size());
+ ClassResourceInfo teamInfo = subResourceInfos.get(0);
+
+ // verify the contents of the League resource
+ MethodDispatcher md = leagueInfo.getMethodDispatcher();
+ assertNotNull(md);
+ List<OperationResourceInfo> opInfos = md.getOperationResourceInfos();
+ assertNotNull(opInfos);
+ assertEquals(4, opInfos.size());
+
+ // verify each of the methods
+ Method method = League.class.getMethod("getName", null);
+ OperationResourceInfo opInfo = md.getOperationResourceInfo(method);
+ assertNotNull(opInfo);
+ assertEquals("GET", opInfo.getHttpMethod());
+ assertEquals("/name", opInfo.getPath());
+ List<MediaType> consumes = opInfo.getConsumes();
+ assertNotNull(consumes);
+ assertEquals(1, consumes.size());
+ assertEquals("text", consumes.get(0).getType());
+ assertEquals("xml", consumes.get(0).getSubtype());
+ List<MediaType> produces = opInfo.getProduces();
+ assertNotNull(produces);
+ assertEquals(1, produces.size());
+ assertEquals("text", produces.get(0).getType());
+ assertEquals("xml", produces.get(0).getSubtype());
+
+ method = League.class.getMethod("getTeams", null);
+ opInfo = md.getOperationResourceInfo(method);
+ assertNotNull(opInfo);
+ assertEquals("GET", opInfo.getHttpMethod());
+ assertEquals("/teams", opInfo.getPath());
+ consumes = opInfo.getConsumes();
+ assertNotNull(consumes);
+ assertEquals(1, consumes.size());
+ assertEquals("text", consumes.get(0).getType());
+ assertEquals("xml", consumes.get(0).getSubtype());
+ produces = opInfo.getProduces();
+ assertNotNull(produces);
+ assertEquals(1, produces.size());
+ assertEquals("application", produces.get(0).getType());
+ assertEquals("xml", produces.get(0).getSubtype());
+
+ method = League.class.getMethod("getTeam", java.lang.String.class);
+ opInfo = md.getOperationResourceInfo(method);
+ assertNotNull(opInfo);
+ assertTrue(opInfo.isSubResourceLocator());
+ assertEquals("/team/{id}", opInfo.getPath());
+ consumes = opInfo.getConsumes();
+ assertNotNull(consumes);
+ assertEquals(1, consumes.size());
+ assertEquals("text", consumes.get(0).getType());
+ assertEquals("xml", consumes.get(0).getSubtype());
+ produces = opInfo.getProduces();
+ assertNotNull(produces);
+ assertEquals(1, produces.size());
+ assertEquals("application", produces.get(0).getType());
+ assertEquals("xml", produces.get(0).getSubtype());
+
+ method = League.class.getMethod("createTeam", Team.class);
+ opInfo = md.getOperationResourceInfo(method);
+ assertNotNull(opInfo);
+ assertEquals("POST", opInfo.getHttpMethod());
+ assertEquals("/team", opInfo.getPath());
+ consumes = opInfo.getConsumes();
+ assertNotNull(consumes);
+ assertEquals(1, consumes.size());
+ assertEquals("application", consumes.get(0).getType());
+ assertEquals("xml", consumes.get(0).getSubtype());
+ produces = opInfo.getProduces();
+ assertNotNull(produces);
+ assertEquals(1, produces.size());
+ assertEquals("*", produces.get(0).getType());
+ assertEquals("*", produces.get(0).getSubtype());
+
+ // now let's verify the Team subresource
+ md = teamInfo.getMethodDispatcher();
+ assertNotNull(md);
+ opInfos = md.getOperationResourceInfos();
+ assertNotNull(opInfos);
+ assertEquals(1, opInfos.size());
+
+ // verify the method
+ method = Team.class.getMethod("getName", null);
+ opInfo = md.getOperationResourceInfo(method);
+ assertNotNull(opInfo);
+ assertEquals("GET", opInfo.getHttpMethod());
+
+ }
+
+ /**
+ * Verify we can build metadata for Providers from XML configuration file.
+ * @throws Exception
+ */
+ public void testBuildProviderInfo() throws Exception {
+ String path = TestUtils.getTestResourceDirPath();
+ path = !path.endsWith("/") ? (path + "/") : path;
+ path = path + "modelddtests/league/ibm-jaxrs.xml";
+ File configFile = new File(path);
+ JAXRSInfoInput source = new JAXRSInfoInput(
+ JAXRSInfoInput.Type.XMLCONFIG);
+ source.setConfigFile(configFile);
+ source.setClassLoader(Thread.currentThread().getContextClassLoader());
+ JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry
+ .getImplementation(JAXRSInfoBuilderFactory.class);
+ JAXRSInfoBuilder builder = factory
+ .getInfoBuilder(source.getInputType());
+ JAXRSInfoOutput output = builder.buildRESTInfo(source);
+ assertNotNull(output);
+
+ List<ProviderInfo> providerInfoList = output.getProviderInfoList();
+ assertNotNull(providerInfoList);
+ assertEquals(1, providerInfoList.size());
+ ProviderInfo providerInfo = providerInfoList.get(0);
+ assertEquals(CustomProvider.class.getName(), providerInfo
+ .getProviderClass().getName());
+ List<ProviderInfo.Type> providerTypes = providerInfo.getProviderTypes();
+ assertNotNull(providerTypes);
+ assertTrue(providerTypes.contains(ProviderInfo.Type.MessageBodyWriter));
+
+ // check the consumes/produces
+ List<MediaType> consumes = providerInfo.getConsumesTypes();
+ assertNotNull(consumes);
+ assertEquals(1, consumes.size());
+ assertEquals("application", consumes.get(0).getType());
+ assertEquals("custom", consumes.get(0).getSubtype());
+
+ List<MediaType> produces = providerInfo.getProducesTypes();
+ assertNotNull(produces);
+ assertEquals(1, produces.size());
+ assertEquals("application", produces.get(0).getType());
+ assertEquals("custom", produces.get(0).getSubtype());
+
+ }
+
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/NewsStory.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/NewsStory.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/NewsStory.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/NewsStory.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,28 @@
+/*
+ * 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.dd;
+
+public class NewsStory {
+
+ public void getTitle() {
+
+ }
+
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/Team.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/Team.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/Team.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/Team.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,28 @@
+/*
+ * 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.dd;
+
+public class Team {
+
+ public String getName() {
+ return null;
+ }
+
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/CustomProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/CustomProvider.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/CustomProvider.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/CustomProvider.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,51 @@
+/*
+ * 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.dd.merge;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.Produces;
+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
+@Produces(value = "application/custom")
+public class CustomProvider implements MessageBodyWriter<String> {
+
+ 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 void writeTo(String arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4, MultivaluedMap<String, Object> arg5, OutputStream arg6)
+ throws IOException, WebApplicationException {
+
+ }
+
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/League.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/League.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/League.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/League.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,50 @@
+/*
+ * 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.dd.merge;
+
+import java.util.Collection;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+@Path(value = "/leagues_test/{id}")
+public class League {
+
+ public String getName() {
+ return null;
+ }
+
+ @GET
+ public Collection<Team> getTeams() {
+ return null;
+ }
+
+ @Path(value = "/team/{id}")
+ public Team getTeam(String team) {
+ return null;
+ }
+
+ @Consumes(value = "application/xml")
+ public void createTeam(Team team) {
+
+ }
+
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/LeagueApplication.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/LeagueApplication.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/LeagueApplication.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/LeagueApplication.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,36 @@
+/*
+ * 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.dd.merge;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+public class LeagueApplication extends Application {
+
+ public Set<Class<?>> getClasses() {
+ Set<Class<?>> classes = new HashSet<Class<?>>();
+ classes.add(League.class);
+ classes.add(Team.class);
+ return classes;
+ }
+
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/ModelDDTests.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/ModelDDTests.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/ModelDDTests.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/ModelDDTests.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,281 @@
+/*
+ * 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.dd.merge;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.core.MediaType;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.model.MethodDispatcher;
+import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+import org.apache.cxf.jaxrs.model.ProviderInfo;
+
+import com.ibm.rest.test.utils.TestUtils;
+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;
+
+public class ModelDDTests extends TestCase {
+
+ /**
+ * Verify we can build metadata for a simple resource from a
+ * configuration file.
+ */
+ public void testBuildInfoFromDD() throws Exception {
+ String path = TestUtils.getTestResourceDirPath();
+ path = !path.endsWith("/") ? (path + "/") : path;
+ path = path + "modelddtests_merge/newsstory/ibm-jaxrs.xml";
+ File configFile = new File(path);
+ JAXRSInfoInput source = new JAXRSInfoInput(
+ JAXRSInfoInput.Type.XML_REFLECTION);
+ source.setConfigFile(configFile);
+ source.setClassLoader(Thread.currentThread().getContextClassLoader());
+ Map<String, Class<?>> classes = new HashMap<String, Class<?>>();
+ classes.put(NewsStory.class.getName(), NewsStory.class);
+ source.setClasses(classes);
+ JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry
+ .getImplementation(JAXRSInfoBuilderFactory.class);
+ JAXRSInfoBuilder builder = factory
+ .getInfoBuilder(source.getInputType());
+ JAXRSInfoOutput output = builder.buildRESTInfo(source);
+ assertNotNull(output);
+
+ // test the class information
+ List<ClassResourceInfo> classInfoList = output.getClassInfoList();
+ assertNotNull(classInfoList);
+ assertEquals(1, classInfoList.size());
+ ClassResourceInfo classInfo = classInfoList.get(0);
+ assertEquals("/story/{id}", classInfo.getPath());
+ assertNotNull(classInfo.getURITemplate());
+
+ // now let's move on to testing the method information
+ MethodDispatcher md = classInfo.getMethodDispatcher();
+ assertNotNull(md);
+ List<OperationResourceInfo> opInfos = md.getOperationResourceInfos();
+ assertNotNull(opInfos);
+ assertEquals(1, opInfos.size());
+ OperationResourceInfo opInfo = opInfos.iterator().next();
+ assertEquals("/title", opInfo.getPath());
+ assertEquals("GET", opInfo.getHttpMethod());
+ assertNotNull(opInfo.getURITemplate());
+
+ // let's do some consumes/produces testing
+ List<MediaType> consumes = opInfo.getConsumes();
+ assertNotNull(consumes);
+ assertEquals(1, consumes.size());
+ assertEquals("text", consumes.get(0).getType());
+ assertEquals("xml", consumes.get(0).getSubtype());
+
+ List<MediaType> produces = opInfo.getProduces();
+ assertNotNull(produces);
+ assertEquals(1, produces.size());
+ assertEquals("text", produces.get(0).getType());
+ assertEquals("xml", produces.get(0).getSubtype());
+
+ // check encoding and default value
+ assertTrue(opInfo.isEncodedEnabled());
+ assertEquals("someDefaultValue", opInfo.getDefaultParameterValue());
+
+ }
+
+ /**
+ * Verify we can build metadata for a resource and subresource from the
+ * configuration file.
+ */
+ public void testBuildSubInfoFromDD() throws Exception {
+ String path = TestUtils.getTestResourceDirPath();
+ path = !path.endsWith("/") ? (path + "/") : path;
+ path = path + "modelddtests_merge/league/ibm-jaxrs.xml";
+ File configFile = new File(path);
+ JAXRSInfoInput source = new JAXRSInfoInput(
+ JAXRSInfoInput.Type.XML_REFLECTION);
+ source.setConfigFile(configFile);
+ source.setClassLoader(Thread.currentThread().getContextClassLoader());
+ Map<String, Class<?>> classes = new HashMap<String, Class<?>>();
+ classes.put(League.class.getName(), League.class);
+ classes.put(Team.class.getName(), Team.class);
+ source.setClasses(classes);
+ JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry
+ .getImplementation(JAXRSInfoBuilderFactory.class);
+ JAXRSInfoBuilder builder = factory
+ .getInfoBuilder(source.getInputType());
+ JAXRSInfoOutput output = builder.buildRESTInfo(source);
+ assertNotNull(output);
+
+ // test the class and subclass information
+ List<ClassResourceInfo> classInfoList = output.getClassInfoList();
+ assertNotNull(classInfoList);
+ assertEquals(1, classInfoList.size());
+ ClassResourceInfo leagueInfo = classInfoList.get(0);
+ assertEquals("/league/{id}", leagueInfo.getPath());
+ assertNotNull(leagueInfo.getURITemplate());
+ List<ClassResourceInfo> subResourceInfos = leagueInfo
+ .getSubClassResourceInfo();
+ assertNotNull(subResourceInfos);
+ assertEquals(1, subResourceInfos.size());
+ ClassResourceInfo teamInfo = subResourceInfos.get(0);
+
+ // verify the contents of the League resource
+ MethodDispatcher md = leagueInfo.getMethodDispatcher();
+ assertNotNull(md);
+ List<OperationResourceInfo> opInfos = md.getOperationResourceInfos();
+ assertNotNull(opInfos);
+ assertEquals(4, opInfos.size());
+
+ // verify each of the methods
+ Method method = League.class.getMethod("getName", null);
+ OperationResourceInfo opInfo = md.getOperationResourceInfo(method);
+ assertNotNull(opInfo);
+ assertEquals("GET", opInfo.getHttpMethod());
+ assertEquals("/name", opInfo.getPath());
+ List<MediaType> consumes = opInfo.getConsumes();
+ assertNotNull(consumes);
+ assertEquals(1, consumes.size());
+ assertEquals("text", consumes.get(0).getType());
+ assertEquals("xml", consumes.get(0).getSubtype());
+ List<MediaType> produces = opInfo.getProduces();
+ assertNotNull(produces);
+ assertEquals(1, produces.size());
+ assertEquals("text", produces.get(0).getType());
+ assertEquals("xml", produces.get(0).getSubtype());
+
+ method = League.class.getMethod("getTeams", null);
+ opInfo = md.getOperationResourceInfo(method);
+ assertNotNull(opInfo);
+ assertEquals("GET", opInfo.getHttpMethod());
+ assertEquals("/teams", opInfo.getPath());
+ consumes = opInfo.getConsumes();
+ assertNotNull(consumes);
+ assertEquals(1, consumes.size());
+ assertEquals("text", consumes.get(0).getType());
+ assertEquals("xml", consumes.get(0).getSubtype());
+ produces = opInfo.getProduces();
+ assertNotNull(produces);
+ assertEquals(1, produces.size());
+ assertEquals("application", produces.get(0).getType());
+ assertEquals("xml", produces.get(0).getSubtype());
+
+ method = League.class.getMethod("getTeam", java.lang.String.class);
+ opInfo = md.getOperationResourceInfo(method);
+ assertNotNull(opInfo);
+ assertTrue(opInfo.isSubResourceLocator());
+ assertEquals("/team/{id}", opInfo.getPath());
+ consumes = opInfo.getConsumes();
+ assertNotNull(consumes);
+ assertEquals(1, consumes.size());
+ assertEquals("text", consumes.get(0).getType());
+ assertEquals("xml", consumes.get(0).getSubtype());
+ produces = opInfo.getProduces();
+ assertNotNull(produces);
+ assertEquals(1, produces.size());
+ assertEquals("application", produces.get(0).getType());
+ assertEquals("xml", produces.get(0).getSubtype());
+
+ method = League.class.getMethod("createTeam", Team.class);
+ opInfo = md.getOperationResourceInfo(method);
+ assertNotNull(opInfo);
+ assertEquals("POST", opInfo.getHttpMethod());
+ assertEquals("/team", opInfo.getPath());
+ consumes = opInfo.getConsumes();
+ assertNotNull(consumes);
+ assertEquals(1, consumes.size());
+ assertEquals("application", consumes.get(0).getType());
+ assertEquals("xml", consumes.get(0).getSubtype());
+ produces = opInfo.getProduces();
+ assertNotNull(produces);
+ assertEquals(1, produces.size());
+ assertEquals("*", produces.get(0).getType());
+ assertEquals("*", produces.get(0).getSubtype());
+
+ // now let's verify the Team subresource
+ md = teamInfo.getMethodDispatcher();
+ assertNotNull(md);
+ opInfos = md.getOperationResourceInfos();
+ assertNotNull(opInfos);
+ assertEquals(1, opInfos.size());
+
+ // verify the method
+ method = Team.class.getMethod("getName", null);
+ opInfo = md.getOperationResourceInfo(method);
+ assertNotNull(opInfo);
+ assertEquals("GET", opInfo.getHttpMethod());
+
+ }
+
+ /**
+ * Verify we can build metadata for Providers from XML configuration file.
+ * @throws Exception
+ */
+ public void testBuildProviderInfo() throws Exception {
+ String path = TestUtils.getTestResourceDirPath();
+ path = !path.endsWith("/") ? (path + "/") : path;
+ path = path + "modelddtests_merge/league/ibm-jaxrs.xml";
+ File configFile = new File(path);
+ JAXRSInfoInput source = new JAXRSInfoInput(
+ JAXRSInfoInput.Type.XML_REFLECTION);
+ source.setConfigFile(configFile);
+ source.setClassLoader(Thread.currentThread().getContextClassLoader());
+ Map<String, Class<?>> classes = new HashMap<String, Class<?>>();
+ classes.put(League.class.getName(), League.class);
+ classes.put(Team.class.getName(), Team.class);
+ classes.put(CustomProvider.class.getName(), CustomProvider.class);
+ source.setClasses(classes);
+ JAXRSInfoBuilderFactory factory = (JAXRSInfoBuilderFactory) MetadataRegistry
+ .getImplementation(JAXRSInfoBuilderFactory.class);
+ JAXRSInfoBuilder builder = factory
+ .getInfoBuilder(source.getInputType());
+ JAXRSInfoOutput output = builder.buildRESTInfo(source);
+ assertNotNull(output);
+
+ List<ProviderInfo> providerInfoList = output.getProviderInfoList();
+ assertNotNull(providerInfoList);
+ assertEquals(1, providerInfoList.size());
+ ProviderInfo providerInfo = providerInfoList.get(0);
+ assertEquals(CustomProvider.class.getName(), providerInfo
+ .getProviderClass().getName());
+ List<ProviderInfo.Type> providerTypes = providerInfo.getProviderTypes();
+ assertNotNull(providerTypes);
+ assertTrue(providerTypes.contains(ProviderInfo.Type.MessageBodyWriter));
+
+ // check the consumes/produces
+ List<MediaType> consumes = providerInfo.getConsumesTypes();
+ assertNotNull(consumes);
+ assertEquals(1, consumes.size());
+ assertEquals("application", consumes.get(0).getType());
+ assertEquals("custom", consumes.get(0).getSubtype());
+
+ List<MediaType> produces = providerInfo.getProducesTypes();
+ assertNotNull(produces);
+ assertEquals(1, produces.size());
+ assertEquals("application", produces.get(0).getType());
+ assertEquals("custom", produces.get(0).getSubtype());
+
+ }
+
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/NewsStory.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/NewsStory.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/NewsStory.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/NewsStory.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.dd.merge;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+@Path(value = "/newsstory/{id}")
+public class NewsStory {
+
+ @GET
+ public void getTitle() {
+
+ }
+
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/StoryApplication.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/StoryApplication.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/StoryApplication.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/StoryApplication.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.model.dd.merge;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+public class StoryApplication extends Application {
+
+ public Set<Class<?>> getClasses() {
+ Set<Class<?>> classes = new HashSet<Class<?>>();
+ classes.add(NewsStory.class);
+ return classes;
+ }
+
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/Team.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/Team.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/Team.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/dd/merge/Team.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.model.dd.merge;
+
+import javax.ws.rs.GET;
+
+public class Team {
+
+ @GET
+ public String getName() {
+ return null;
+ }
+
+}
Added: incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/reflective/AbstractResourceInfoImplTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/reflective/AbstractResourceInfoImplTest.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/reflective/AbstractResourceInfoImplTest.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/unittests/com/ibm/ws/jaxrs/model/reflective/AbstractResourceInfoImplTest.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,78 @@
+/*
+ * 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.reflective;
+
+import java.lang.reflect.Constructor;
+
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Request;
+import javax.ws.rs.core.SecurityContext;
+
+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.ResourceDefaultCstr;
+import com.ibm.ws.jaxrs.model.reflective.AbstractResourceInfoImpl;
+
+import junit.framework.TestCase;
+
+public class AbstractResourceInfoImplTest extends TestCase {
+
+ /**
+ * Test our ability to select an appropriate constructor
+ */
+ public void testSelectConstructor() throws Exception {
+ // try a class with a default constructor
+ Constructor<?> cstr = AbstractResourceInfoImpl
+ .selectConstructor(ResourceDefaultCstr.class);
+ assertNotNull(cstr);
+
+ // now try a class with a constructor with one @Context parameter
+ cstr = AbstractResourceInfoImpl
+ .selectConstructor(ContextConstructor.class);
+ assertNotNull(cstr);
+ assertNotNull(cstr.getParameterTypes());
+ assertEquals(1, cstr.getParameterTypes().length);
+ assertEquals(HttpHeaders.class, cstr.getParameterTypes()[0]);
+
+ // now try a class with a constructor with multiple @Context parameters
+ cstr = AbstractResourceInfoImpl
+ .selectConstructor(MultiContextCstr.class);
+ assertNotNull(cstr);
+ assertNotNull(cstr.getParameterTypes());
+ assertEquals(3, cstr.getParameterTypes().length);
+ assertEquals(HttpHeaders.class, cstr.getParameterTypes()[0]);
+ assertEquals(SecurityContext.class, cstr.getParameterTypes()[1]);
+ assertEquals(Request.class, cstr.getParameterTypes()[2]);
+
+ // now try a class with a constructor with multiple annotated parameters
+ cstr = AbstractResourceInfoImpl
+ .selectConstructor(MultiAnnotationCstr.class);
+ assertNotNull(cstr);
+ assertNotNull(cstr.getParameterTypes());
+ assertEquals(5, cstr.getParameterTypes().length);
+ assertEquals(HttpHeaders.class, cstr.getParameterTypes()[0]);
+ assertEquals(SecurityContext.class, cstr.getParameterTypes()[1]);
+ assertEquals(Request.class, cstr.getParameterTypes()[2]);
+ assertEquals(String.class, cstr.getParameterTypes()[3]);
+ assertEquals(String.class, cstr.getParameterTypes()[4]);
+ }
+
+}