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 [9/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/de...
Date Tue, 23 Jun 2009 05:38:19 GMT
Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/context/providers/test/ProvidersMethodsTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/context/providers/test/ProvidersMethodsTest.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/context/providers/test/ProvidersMethodsTest.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/context/providers/test/ProvidersMethodsTest.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,1267 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jaxrs.tests.context.providers.test;
+
+import java.io.IOException;
+
+import javax.ws.rs.Produces;
+import javax.ws.rs.ext.ContextResolver;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Providers;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.methods.GetMethod;
+
+import framework.defaults.test.FVTTestCase;
+
+public class ProvidersMethodsTest extends FVTTestCase {
+
+    public static junit.framework.Test suite() {
+        return FVTTestCase.getTestSuite(ProvidersMethodsTest.class,
+                "jaxrs.tests.context.providers.server.Application");
+    }
+
+    /**
+     * Tests that
+     * {@link Providers#getContextResolver(Class, javax.ws.rs.core.MediaType)}
+     * will return null when a {@link ContextResolver} is not provided that
+     * matches the requested Context type.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testContextResolverNoMatch() throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/contextresolver?className=java.lang.Throwable&mediaType=*%2F*");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("nullcontextresolver", getMethod
+                    .getResponseBodyAsString());
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a
+     * {@link Providers#getContextResolver(Class, javax.ws.rs.core.MediaType)}
+     * will return a single context resolver when a single matching
+     * {@link ContextResolver} is provided by the application.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testContextResolverMatchSingle() throws HttpException,
+            IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/contextresolver?className=java.lang.Exception&mediaType=*%2F*");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals(
+                    "jaxrs.tests.context.providers.server.MyExceptionContextResolver",
+                    getMethod.getResponseBodyAsString());
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    //
+    // /**
+    // * Tests that a
+    // * {@link Providers#getContextResolver(Class, javax.ws.rs.core.MediaType)}
+    // * will return a context resolver if a subclass of the context generic
+    // type
+    // * is provided when a single matching {@link ContextResolver} is provided
+    // by
+    // * the application.
+    // *
+    // * @throws IOException
+    // * @throws HttpException
+    // */
+    // public void testContextResolverMatchSubclassOfGenericTypeSingle() throws
+    // HttpException,
+    // IOException {
+    // HttpClient client = new HttpClient();
+    //
+    // GetMethod getMethod = new GetMethod(
+    // getBaseURI()
+    // +
+    //
+    // "/context/providers/contextresolver?className=jaxrs.tests.context.providers.server.MyException&mediaType=*%2F*");
+    // try {
+    // client.executeMethod(getMethod);
+    // assertEquals(200, getMethod.getStatusCode());
+    //
+    // assertEquals("jaxrs.tests.context.providers.server.MyExceptionContextResolver",
+    // getMethod.getResponseBodyAsString());
+    // } finally {
+    // getMethod.releaseConnection();
+    // }
+    // }
+    //
+    // /**
+    // * Tests that a ContextResolver with a generic type (such as
+    // List<T>)
+    // * will resolve correctly.
+    // */
+    // public void testContextResolverMatchWithGenericTypedContextResolver() {
+    // fail();
+    // }
+    //
+    // public void testContextResolverMatchInheritedClass() throws
+    // HttpException, IOException {
+    // fail();
+    // }
+
+    /**
+     * Tests that a {@link ContextResolver} with a {@link Produces} annotation
+     * of text/xml will not be returned when given a non-compatible media type
+     * (my/type).
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testContextResolverNoMatchBySpecificMediaType()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/contextresolver?className=java.lang.Exception&mediaType=my%2Ftype");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("nullcontextresolver", getMethod
+                    .getResponseBodyAsString());
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a {@link ContextResolver} with a {@link Produces} annotation
+     * of text/xml will be returned when given the specific text/xml type.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testContextResolverMatchBySpecificMediaType()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/contextresolver?className=java.lang.Exception&mediaType=text%2Fxml");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals(
+                    "jaxrs.tests.context.providers.server.MyExceptionContextResolver",
+                    getMethod.getResponseBodyAsString());
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a {@link ContextResolver} with a {@link Produces} annotation
+     * of text/xml will be returned when given the wildcard/xml type.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testContextResolverMatchBySpecificMediaTypeTypeWildcard()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/contextresolver?className=java.lang.Exception&mediaType=*%2Fxml");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals(
+                    "jaxrs.tests.context.providers.server.MyExceptionContextResolver",
+                    getMethod.getResponseBodyAsString());
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a {@link ContextResolver} with a {@link Produces} annotation
+     * of text/xml will be returned when given the text/* type.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testContextResolverMatchBySpecificMediaTypeSubtypeWildcard()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/contextresolver?className=java.lang.Exception&mediaType=text%2F*");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals(
+                    "jaxrs.tests.context.providers.server.MyExceptionContextResolver",
+                    getMethod.getResponseBodyAsString());
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that when finding a {@link ContextResolver} both the application
+     * provided and runtime provided context resolvers are searched. Invokes
+     * with a specific JAXB class and verifies that the final context is a
+     * JAXBContext. In this case, the runtime provided context resolver is used.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testMultipleContextResolverRuntimeAndApplicationMatchByMediaTypeWildcardInvokeWithClassInvokeRuntimeProvided()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/contextresolver?className=javax.xml.bind.JAXBContext&mediaType=*%2F*&invokeWithClassName=jaxrs.tests.context.providers.server.otherxml.OtherRootElement");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertTrue(getMethod.getResponseBodyAsString(), getMethod
+                    .getResponseBodyAsString().contains("JAXBContext"));
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that when finding a {@link ContextResolver} both the application
+     * provided and runtime provided context resolvers are searched. Invokes
+     * with a specific JAXB class and verifies that the final context is a
+     * JAXBContext. In this case, the application provided context resolver is
+     * used.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testMultipleContextResolverRuntimeAndApplicationMatchByMediaTypeWildcardInvokeWithClassInvokeApplicationProvided()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/contextresolver?className=javax.xml.bind.JAXBContext&mediaType=*%2F*&invokeWithClassName=jaxrs.tests.context.providers.server.xml.RootElement");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertTrue(getMethod.getResponseBodyAsString(), getMethod
+                    .getResponseBodyAsString().contains("JAXBContext"));
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that when there are multiple {@link ContextResolver}s that could
+     * respond to a given type, that a proxy is returned that will call all of
+     * them.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testMultipleContextResolverRuntimeAndApplicationMatchByMediaTypeSpecificTextXML()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/contextresolver?className=javax.xml.bind.JAXBContext&mediaType=text%2Fxml");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("org.apache.cxf.jaxrs.provider.ProviderFactory$1",
+                    getMethod.getResponseBodyAsString());
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that when the application provided {@link ContextResolver} which
+     * has a {@link Produces} annotation with text/xml is not the
+     * ContextResolver returned when searching for application/json media type.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testMultipleContextResolverRuntimeAndApplicationMatchByMediaTypeSpecificApplicationJSON()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/contextresolver?className=javax.xml.bind.JAXBContext&mediaType=application%2Fjson");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("com.ibm.ws.jaxrs.resolver.JAXBContextResolver",
+                    getMethod.getResponseBodyAsString());
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that when the application provided {@link ContextResolver} which
+     * has a {@link Produces} annotation with text/xml is not called when an
+     * application/json is searched. This method should be able to invoke the
+     * runtime provided JAXBContext ContextResolver but return null.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testMultipleContextResolverRuntimeAndApplicationMatchByMediaTypeSpecificApplicationJSONInvokeNegative()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/contextresolver?className=javax.xml.bind.JAXBContext&mediaType=application%2Fjson&invokeWithClassName=jaxrs.tests.context.providers.server.xml.RootElement");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("null", getMethod.getResponseBodyAsString());
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that when the application provided {@link ContextResolver} which
+     * has a {@link Produces} annotation with text/xml is called when an
+     * text/xml is searched. This method should be able to invoke the
+     * application provided JAXBContext ContextResolver and return a
+     * JAXBContext.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testMultipleContextResolverRuntimeAndApplicationMatchByMediaTypeSpecificTextXMLInvoke()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/contextresolver?className=javax.xml.bind.JAXBContext&mediaType=text%2Fxml&invokeWithClassName=jaxrs.tests.context.providers.server.xml.RootElement");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertTrue(getMethod.getResponseBodyAsString(), getMethod
+                    .getResponseBodyAsString().contains("JAXBContext"));
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a {@link ContextResolver} with a wildcard/xml {@link Produces}
+     * annotation will match a (specific)/xml type.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testContextResolverMatchMultipleSortByProducesWildcardType()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/contextresolver?className=java.lang.String&mediaType=abcd%2Fxml&invokeWithClassName=java.lang.Short&returnToStringValue=true");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("allwildcardshort", getMethod
+                    .getResponseBodyAsString());
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a {@link ContextResolver} with a text/wildcard
+     * {@link Produces} annotation will match a text/(specific) type.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testContextResolverMatchMultipleSortByProducesWildcardSubtype()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/contextresolver?className=java.lang.String&mediaType=text%2Fabcd&invokeWithClassName=java.lang.Short&returnToStringValue=true");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("textwildcardonly", getMethod
+                    .getResponseBodyAsString());
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a {@link ContextResolver} with a wildcard/wildcard
+     * {@link Produces} annotation will match a (specific)/(specific) type.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testContextResolverMatchMultipleSortByProducesAllWildcard()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/contextresolver?className=java.lang.String&mediaType=abcd%2Fdef&invokeWithClassName=java.lang.Short&returnToStringValue=true");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("allwildcardshort", getMethod
+                    .getResponseBodyAsString());
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a match with multiple {@link ContextResolver}s with the same
+     * media type and generic type will use a proxy that finds the single
+     * resolver that returns a non-null.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testContextResolverMatchMultipleSortByProducesFindOne()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/contextresolver?className=java.lang.String&mediaType=text%2Fxml&invokeWithClassName=java.lang.Integer&returnToStringValue=true");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("integerxmlonly", getMethod.getResponseBodyAsString());
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        client = new HttpClient();
+
+        getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/contextresolver?className=java.lang.String&mediaType=text%2Fxml&invokeWithClassName=java.lang.Long&returnToStringValue=true");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("longxml2only", getMethod.getResponseBodyAsString());
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a match with multiple {@link ContextResolver}s will return the
+     * most specific responses before the wildcard responses.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testContextResolverMatchAnyMoreSpecificThanWildcards()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/contextresolver?className=java.lang.String&mediaType=text%2Fxml&invokeWithClassName=java.lang.Short&returnToStringValue=true");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String responseBody = getMethod.getResponseBodyAsString();
+            assertTrue(responseBody, "shortxmlandjson".equals(responseBody)
+                    || "shortxml2only".equals(responseBody)
+                    || "shortxmlonly".equals(responseBody));
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a {@link ContextResolver} with a wildcard/wildcard
+     * {@link Produces} annotation will match any media type.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testContextResolverNoProducesMatchNotExpectedMediaType()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/contextresolver?className=java.lang.String&mediaType=my%2Ftype");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals(
+                    "jaxrs.tests.context.providers.server.MyStringContextForAllWildcard",
+                    getMethod.getResponseBodyAsString());
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a Provider can return an {@link ExceptionMapper}.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testGetExceptionMapperAppSuppliedProvider()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/exception?className=jaxrs.tests.context.providers.server.MyException");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals(
+                    "jaxrs.tests.context.providers.server.ExceptionMapperForMyException",
+                    getMethod.getResponseBodyAsString());
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a {@link Providers} will return the correct exception mapper
+     * given an exception that is a sub-class of the {@link ExceptionMapper}
+     * class.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testGetExceptionMapperAppSuppliedInheritanceTree()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/exception?className=jaxrs.tests.context.providers.server.MyException2");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals(
+                    "jaxrs.tests.context.providers.server.ExceptionMapperForMyException",
+                    getMethod.getResponseBodyAsString());
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a {@link Providers} will return a null value when given a
+     * class that does not have an {@link ExceptionMapper}.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testGetExceptionMapperNoMatching() throws HttpException,
+            IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(getBaseURI()
+                + "/context/providers/exception?className=java.lang.Throwable");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            assertEquals("null", getMethod.getResponseBodyAsString());
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that
+     * {@link Providers#getMessageBodyWriter(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+     * uses the media type to filter out potential message body writers.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testGetMessageBodyWriterSortByProducesMediaType()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodywriter?className=java.lang.Integer&mediaType=text%2Fxml");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertEquals(
+                    "jaxrs.tests.context.providers.server.MyMessageBodyWriterXMLAndJSONForNumber",
+                    response);
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodywriter?className=java.lang.Integer&mediaType=application%2Fjson");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertTrue(
+                    response,
+                    response
+                            .contains("jaxrs.tests.context.providers.server.MyMessageBodyWriterXMLAndJSONForNumber")
+                            || response
+                                    .contains("jaxrs.tests.context.providers.server.MyMessageBodyWriterJSONForInteger"));
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that
+     * {@link Providers#getMessageBodyWriter(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+     * uses the media type to filter out potential message body writers and will
+     * respect more specific types over wildcards.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testGetMessageBodyWriterSortByProducesMediaTypeWithWildcards()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodywriter?className=java.lang.Short&mediaType=application%2Fjson");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertEquals(
+                    "jaxrs.tests.context.providers.server.MyMessageBodyWriterJSONForShort",
+                    response);
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodywriter?className=java.lang.Short&mediaType=application%2F*");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertTrue(
+                    response,
+                    response
+                            .contains("jaxrs.tests.context.providers.server.MyMessageBodyWriterJSONForShort"));
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodywriter?className=java.lang.Short&mediaType=application%2Fmytype");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertEquals(
+                    "jaxrs.tests.context.providers.server.MyMessageBodyWriterApplicationWildcardForShort",
+                    response);
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodywriter?className=java.lang.Short&mediaType=mytype%2Fmysubtype");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+
+            assertEquals(
+                    "jaxrs.tests.context.providers.server.MyMessageBodyWriterWildcardForShort",
+                    response);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that
+     * {@link Providers#getMessageBodyWriter(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+     * will find MessageBodyWriters that have inherited the MessageBodyWriter
+     * interface.
+     *
+     * @throws IOException
+     * @throws HttpException
+     */
+    public void testGetMessageBodyWriterWhichInheritsWriterInterface()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodywriter?className=java.util.List&mediaType=abcd%2Fefgh");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertEquals(
+                    "jaxrs.tests.context.providers.server.MyMessageBodyWriterInherited",
+                    response);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that
+     * {@link Providers#getMessageBodyWriter(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+     * will filter out writers that do not match the isWritable method.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testGetMessageBodyWriterSortByIsWritable()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodywriter?className=java.lang.Integer&mediaType=application%2Fjson");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertTrue(
+                    response,
+                    "jaxrs.tests.context.providers.server.MyMessageBodyWriterJSONForInteger"
+                            .equals(response)
+                            || "jaxrs.tests.context.providers.server.MyMessageBodyWriterXMLAndJSONForNumber"
+                                    .equals(response));
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodywriter?className=java.lang.Long&mediaType=application%2Fjson");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertTrue(
+                    response,
+                    "jaxrs.tests.context.providers.server.MyMessageBodyWriterJSONForLong"
+                            .equals(response)
+                            || "jaxrs.tests.context.providers.server.MyMessageBodyWriterXMLAndJSONForNumber"
+                                    .equals(response));
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodywriter?className=java.lang.Short&mediaType=application%2Fjson");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertEquals(response,
+                    "jaxrs.tests.context.providers.server.MyMessageBodyWriterJSONForShort");
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodywriter?className=java.lang.Long&mediaType=text%2Fxml");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertEquals(
+                    "jaxrs.tests.context.providers.server.MyMessageBodyWriterXMLAndJSONForNumber",
+                    response);
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodywriter?className=java.lang.Integer&mediaType=text%2Fxml");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertEquals(
+                    "jaxrs.tests.context.providers.server.MyMessageBodyWriterXMLAndJSONForNumber",
+                    response);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that
+     * {@link Providers#getMessageBodyWriter(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+     * will use the application provided MessageBodyWriters before runtime
+     * provided.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testGetMessageBodyWriterUserPrecedenceOverRuntime()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodywriter?className=java.lang.String&mediaType=text%2Fplain");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertEquals(
+                    "jaxrs.tests.context.providers.server.MyStringWriterForStrings",
+                    response);
+        } finally {
+            getMethod.releaseConnection();
+        }
+        client = new HttpClient();
+
+        getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodywriter?className=java.lang.Number&mediaType=text%2Fplain");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertEquals("org.apache.cxf.jaxrs.provider.PrimitiveTextProvider",
+                    response);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that a null is returned when calling
+     * {@link Providers#getMessageBodyWriter(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+     * if there are no suitable MessageBodyWriters.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testGetMessageBodyWriterNoMatching() throws HttpException,
+            IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodywriter?className=java.lang.Float&mediaType=application%2Fjson");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertEquals("nullwriter", response);
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodywriter?className=java.lang.Exception&mediaType=*%2F*");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertEquals("nullwriter", response);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    //
+    // public void testGetMessageBodyWriterWithMultipleWriterInterfaces() {
+    // fail();
+    // }
+
+    /**
+     * Tests that a null is returned when calling
+     * {@link Providers#getMessageBodyReader(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+     * if there are no suitable MessageBodyReader.
+     *
+     * @throws IOException
+     * @throws HttpException
+     */
+    public void testGetMessageBodyReaderNoMatching() throws HttpException,
+            IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodyreader?className=java.lang.Float&mediaType=mynonexistenttype%2Fmysubtype");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertEquals("nullreader", response);
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodyreader?className=java.lang.Exception&mediaType=*%2F*");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertEquals("nullreader", response);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that
+     * {@link Providers#getMessageBodyReader(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+     * will filter out writers that do not match the isWritable method.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testGetMessageBodyReaderSortByIsReadable()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodyreader?className=java.lang.Integer&mediaType=application%2Fjson");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertTrue(
+                    response,
+                    "jaxrs.tests.context.providers.server.readers.MyMessageBodyReaderJSONForInteger"
+                            .equals(response)
+                            || "jaxrs.tests.context.providers.server.readers.MyMessageBodyReaderXMLAndJSONForNumber"
+                                    .equals(response));
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodyreader?className=java.lang.Long&mediaType=application%2Fjson");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertTrue(
+                    response,
+                    "jaxrs.tests.context.providers.server.readers.MyMessageBodyReaderJSONForLong"
+                            .equals(response)
+                            || "jaxrs.tests.context.providers.server.readers.MyMessageBodyReaderXMLAndJSONForNumber"
+                                    .equals(response));
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodyreader?className=java.lang.Short&mediaType=application%2Fjson");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertEquals(
+                    "jaxrs.tests.context.providers.server.readers.MyMessageBodyReaderJSONForShort",
+                    response);
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodyreader?className=java.lang.Long&mediaType=text%2Fxml");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertEquals(
+                    "jaxrs.tests.context.providers.server.readers.MyMessageBodyReaderXMLAndJSONForNumber",
+                    response);
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodyreader?className=java.lang.Integer&mediaType=text%2Fxml");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertEquals(
+                    "jaxrs.tests.context.providers.server.readers.MyMessageBodyReaderXMLAndJSONForNumber",
+                    response);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that
+     * {@link Providers#getMessageBodyReader(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+     * uses the media type to filter out potential message body readers.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testGetMessageBodyReaderSortByConsumesMediaType()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodyreader?className=java.lang.Integer&mediaType=text%2Fxml");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertEquals(
+                    "jaxrs.tests.context.providers.server.readers.MyMessageBodyReaderXMLAndJSONForNumber",
+                    response);
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodyreader?className=java.lang.Integer&mediaType=application%2Fjson");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertTrue(
+                    response,
+                    response
+                            .contains("jaxrs.tests.context.providers.server.readers.MyMessageBodyReaderXMLAndJSONForNumber")
+                            || response
+                                    .contains("jaxrs.tests.context.providers.server.readers.MyMessageBodyReaderJSONForInteger"));
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that
+     * {@link Providers#getMessageBodyReader(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+     * uses the media type to filter out potential message body readers and will
+     * respect more specific types over wildcards.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testGetMessageBodyReaderSortByConsumesMediaTypeWithWildcards()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodyreader?className=java.lang.Short&mediaType=application%2Fjson");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertEquals(
+                    "jaxrs.tests.context.providers.server.readers.MyMessageBodyReaderJSONForShort",
+                    response);
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodyreader?className=java.lang.Short&mediaType=application%2F*");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertEquals(
+                    "jaxrs.tests.context.providers.server.readers.MyMessageBodyReaderJSONForShort",
+                    response);
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodyreader?className=java.lang.Short&mediaType=application%2Fmytype");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertEquals(
+                    "jaxrs.tests.context.providers.server.readers.MyMessageBodyReaderApplicationWildcardForShort",
+                    response);
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodyreader?className=java.lang.Short&mediaType=mytype%2Fmysubtype");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+
+            assertEquals(
+                    "jaxrs.tests.context.providers.server.readers.MyMessageBodyReaderWildcardForShort",
+                    response);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that
+     * {@link Providers#getMessageBodyReader(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+     * will use the application provided MessageBodyReaders before runtime
+     * provided.
+     *
+     * @throws HttpException
+     * @throws IOException
+     */
+    public void testGetMessageBodyReaderUserPrecedenceOverRuntime()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodyreader?className=java.lang.String&mediaType=text%2Fplain");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertEquals(
+                    "jaxrs.tests.context.providers.server.readers.MyMessageBodyReaderForStrings",
+                    response);
+        } finally {
+            getMethod.releaseConnection();
+        }
+        client = new HttpClient();
+
+        getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodyreader?className=java.lang.Number&mediaType=text%2Fplain");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertEquals("org.apache.cxf.jaxrs.provider.PrimitiveTextProvider",
+                    response);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests that
+     * {@link Providers#getMessageBodyReader(Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)}
+     * will find MessageBodyReaders that have inherited the MessageBodyReader
+     * interface.
+     *
+     * @throws IOException
+     * @throws HttpException
+     */
+    public void testGetMessageBodyReaderWhichInheritsReaderInterface()
+            throws HttpException, IOException {
+        HttpClient client = new HttpClient();
+
+        GetMethod getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodyreader?className=java.util.Set&mediaType=tuv%2Fwxyz");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertEquals(
+                    "jaxrs.tests.context.providers.server.readers.MyMessageBodyReaderInherited",
+                    response);
+        } finally {
+            getMethod.releaseConnection();
+        }
+
+        getMethod = new GetMethod(
+                getBaseURI()
+                        + "/context/providers/messagebodyreader?className=java.util.List&mediaType=tuv%2Fwxyz");
+        try {
+            client.executeMethod(getMethod);
+            assertEquals(200, getMethod.getStatusCode());
+            String response = getMethod.getResponseBodyAsString();
+            assertEquals("nullreader", response);
+        } finally {
+            getMethod.releaseConnection();
+        }
+    }
+}

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

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

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/context/request/server/ObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/context/request/server/ObjectFactory.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/context/request/server/ObjectFactory.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/context/request/server/ObjectFactory.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 jaxrs.tests.context.request.server;
+
+import javax.xml.bind.annotation.XmlRegistry;
+
+@XmlRegistry
+public class ObjectFactory {
+
+    public Variant createVariant() {
+        return new Variant();
+    }
+
+}

Added: incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/context/request/server/RequestResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/context/request/server/RequestResource.java?rev=787553&view=auto
==============================================================================
--- incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/context/request/server/RequestResource.java (added)
+++ incubator/wink/contrib/ibm-jaxrs/tests/fvt/jaxrs/tests/context/request/server/RequestResource.java Tue Jun 23 05:37:57 2009
@@ -0,0 +1,280 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jaxrs.tests.context.request.server;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.EntityTag;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Request;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Variant;
+import javax.ws.rs.core.Response.ResponseBuilder;
+
+/**
+ * A resource for testing the {@link Request} interface. This is treated like a
+ * singleton in the application.
+ */
+@Path("context/request")
+public class RequestResource {
+
+    private Date date;
+
+    private EntityTag etag;
+
+    final private static SimpleDateFormat rfc1123Format = new SimpleDateFormat(
+            "EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH);
+
+    @GET
+    @Path("date")
+    public Response evalDate(@Context Request req) {
+        if (!"GET".equals(req.getMethod())) {
+            throw new WebApplicationException();
+        }
+        if (date == null) {
+            return Response.serverError().build();
+        }
+        ResponseBuilder respBuilder = req.evaluatePreconditions(date);
+        if (respBuilder != null) {
+            return respBuilder.build();
+        }
+        return Response.ok("the date: " + rfc1123Format.format(date))
+                .lastModified(date).build();
+    }
+
+    @PUT
+    @Path("date")
+    public Response putDate(String dateSource, @Context Request req) {
+        if (!"PUT".equals(req.getMethod())) {
+            throw new WebApplicationException();
+        }
+        try {
+            date = DateFormat.getDateTimeInstance().parse(dateSource);
+        } catch (ParseException e) {
+            throw new WebApplicationException(e);
+        }
+        return Response.noContent().build();
+    }
+
+    @GET
+    @Path("etag")
+    public Response evalEtag(@Context Request req) {
+        if (!"GET".equals(req.getMethod())) {
+            throw new WebApplicationException();
+        }
+        if (etag == null) {
+            return Response.serverError().build();
+        }
+        ResponseBuilder respBuilder = req.evaluatePreconditions(etag);
+        if (respBuilder != null) {
+            return respBuilder.build();
+        }
+        return Response.ok(
+                "the etag: \"" + etag.getValue() + "\"" + etag.isWeak()).tag(
+                etag).build();
+    }
+
+    @POST
+    @Path("etag")
+    public Response evalPostEtag(@Context Request req) {
+        if (!"POST".equals(req.getMethod())) {
+            throw new WebApplicationException();
+        }
+        if (etag == null) {
+            return Response.serverError().build();
+        }
+        ResponseBuilder respBuilder = req.evaluatePreconditions(etag);
+        if (respBuilder != null) {
+            return respBuilder.build();
+        }
+        return Response.ok(
+                "the etag: \"" + etag.getValue() + "\"" + etag.isWeak()).tag(
+                etag).build();
+    }
+
+    @PUT
+    @Path("etag")
+    public Response putEtag(@Context Request req, String etag) {
+        if (!"PUT".equals(req.getMethod())) {
+            throw new WebApplicationException();
+        }
+        this.etag = EntityTag.valueOf(etag);
+        return Response.noContent().build();
+    }
+
+    @GET
+    @Path("variant/acceptonly")
+    public Response evalAcceptVariant(@Context Request req) {
+        if (!"GET".equals(req.getMethod())) {
+            throw new WebApplicationException();
+        }
+        List<Variant> variants = Variant.mediaTypes(
+                MediaType.APPLICATION_JSON_TYPE, MediaType.valueOf("text/*"),
+                MediaType.TEXT_XML_TYPE, MediaType.TEXT_HTML_TYPE).add()
+                .build();
+        Variant targettedVariant = req.selectVariant(variants);
+        if (targettedVariant == null) {
+            return Response.status(466).build();
+        }
+
+        if ("xml".equals(targettedVariant.getMediaType().getSubtype())) {
+            jaxrs.tests.context.request.server.Variant v = new jaxrs.tests.context.request.server.Variant();
+            v.setMediatype(targettedVariant.getMediaType().getType() + "/"
+                    + targettedVariant.getMediaType().getSubtype());
+            v.setEncoding(targettedVariant.getEncoding());
+            v
+                    .setLanguage((targettedVariant.getLanguage() != null) ? targettedVariant
+                            .getLanguage().getLanguage()
+                            : null);
+            return Response.ok(v).build();
+        }
+
+        return Response.ok(
+                targettedVariant.getMediaType().getType() + "/"
+                        + targettedVariant.getMediaType().getSubtype()).build();
+    }
+
+    @GET
+    @Path("variant/acceptlanguageonly")
+    public Response evalAcceptLanguageVariant(@Context Request req) {
+        if (!"GET".equals(req.getMethod())) {
+            throw new WebApplicationException();
+        }
+        List<Variant> variants = Variant.languages(Locale.ENGLISH,
+                Locale.JAPANESE, Locale.CHINESE, Locale.GERMAN).add().build();
+        Variant targettedVariant = req.selectVariant(variants);
+        if (targettedVariant == null) {
+            return Response.status(466).build();
+        }
+
+        return Response.ok(targettedVariant.getLanguage().getLanguage())
+                .build();
+    }
+
+    @GET
+    @Path("variant/acceptencodingonly")
+    public Response evalAcceptEncodingVariant(@Context Request req) {
+        if (!"GET".equals(req.getMethod())) {
+            throw new WebApplicationException();
+        }
+        List<Variant> variants = Variant.encodings("compress", "gzip",
+                "identity").add().build();
+        Variant targettedVariant = req.selectVariant(variants);
+        if (targettedVariant == null) {
+            return Response.status(466).build();
+        }
+
+        return Response.ok(targettedVariant.getEncoding()).build();
+    }
+
+    @GET
+    @Path("variant/responsebuilder")
+    public Response evalResponseBuilderVary(@Context Request req, @QueryParam("type") String type) {
+        if (!"GET".equals(req.getMethod())) {
+            throw new WebApplicationException();
+        }
+        List<Variant> variants = Variant.languages(Locale.ENGLISH,
+                Locale.JAPANESE, Locale.CHINESE, Locale.GERMAN).mediaTypes(
+                MediaType.APPLICATION_JSON_TYPE, MediaType.valueOf("text/*"),
+                MediaType.TEXT_XML_TYPE, MediaType.TEXT_HTML_TYPE).encodings(
+                "compress", "gzip", "identity").add().build();
+        Variant targettedVariant = req.selectVariant(variants);
+        if ("notacceptable".equals(type)) {
+            List<Variant> notAcceptableVariants = Variant.mediaTypes(
+                    MediaType.APPLICATION_JSON_TYPE,
+                    MediaType.valueOf("text/*"), MediaType.TEXT_XML_TYPE,
+                    MediaType.TEXT_HTML_TYPE).encodings("compress", "gzip",
+                    "identity").add().build();
+            return Response.notAcceptable(notAcceptableVariants).build();
+        } else if ("variants".equals(type)) {
+            List<Variant> okVariants = Variant.languages(Locale.ENGLISH,
+                    Locale.JAPANESE, Locale.CHINESE, Locale.GERMAN).encodings(
+                    "compress", "gzip", "identity").add().build();
+            return Response.ok().variants(okVariants).build();
+        }
+        if (targettedVariant == null) {
+            return Response.status(466).build();
+        }
+        return Response
+                .ok(
+                        targettedVariant.getMediaType().getType()
+                                + "/"
+                                + targettedVariant.getMediaType().getSubtype()
+                                + "-"
+                                + ((targettedVariant.getLanguage() != null) ? targettedVariant
+                                        .getLanguage().getLanguage()
+                                        : "") + "-"
+                                + targettedVariant.getEncoding(),
+                        new Variant(new MediaType("text", "plain"),
+                                Locale.ENGLISH, "identity")).build();
+    }
+
+    @GET
+    @Path("variant/acceptmultiple")
+    public Response evalAcceptMultipleVariant(@Context Request req) {
+        if (!"GET".equals(req.getMethod())) {
+            throw new WebApplicationException();
+        }
+        List<Variant> variants = Variant.languages(Locale.ENGLISH,
+                Locale.JAPANESE, Locale.CHINESE, Locale.GERMAN).mediaTypes(
+                MediaType.APPLICATION_JSON_TYPE, MediaType.valueOf("text/*"),
+                MediaType.TEXT_XML_TYPE, MediaType.TEXT_HTML_TYPE).encodings(
+                "compress", "gzip", "identity").add().build();
+        Variant targettedVariant = req.selectVariant(variants);
+        if (targettedVariant == null) {
+            return Response.status(466).build();
+        }
+
+        if ("xml".equals(targettedVariant.getMediaType().getSubtype())) {
+            jaxrs.tests.context.request.server.Variant v = new jaxrs.tests.context.request.server.Variant();
+            v.setMediatype(targettedVariant.getMediaType().getType() + "/"
+                    + targettedVariant.getMediaType().getSubtype());
+            v.setEncoding(targettedVariant.getEncoding());
+            v
+                    .setLanguage((targettedVariant.getLanguage() != null) ? targettedVariant
+                            .getLanguage().getLanguage()
+                            : null);
+            return Response.ok(v).build();
+        }
+
+        return Response
+                .ok(
+                        targettedVariant.getMediaType().getType()
+                                + "/"
+                                + targettedVariant.getMediaType().getSubtype()
+                                + "-"
+                                + ((targettedVariant.getLanguage() != null) ? targettedVariant
+                                        .getLanguage().getLanguage()
+                                        : "") + "-"
+                                + targettedVariant.getEncoding()).build();
+    }
+}

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



Mime
View raw message