-
Notifications
You must be signed in to change notification settings - Fork 888
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In ResteasyProviderFactory, user defined context providers should be registered as "not builtin".
- Loading branch information
Showing
2 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...tests/src/test/java/org/jboss/resteasy/test/providers/UserDefinedContextResolverTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.jboss.resteasy.test.providers; | ||
|
||
import java.lang.annotation.Annotation; | ||
|
||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.ext.ContextResolver; | ||
import javax.xml.bind.JAXBContext; | ||
import javax.xml.bind.JAXBException; | ||
|
||
import org.jboss.resteasy.plugins.providers.jaxb.JAXBContextFinder; | ||
import org.jboss.resteasy.spi.ResteasyProviderFactory; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @tpSubChapter Providers | ||
* @tpChapter Unit tests | ||
* @tpTestCaseDetails Regression test for RESTEASY-1471 | ||
* @tpSince RESTEasy 3.1.0.Final | ||
*/ | ||
public class UserDefinedContextResolverTest { | ||
|
||
public static class TestException extends RuntimeException { | ||
private static final long serialVersionUID = 1L; | ||
} | ||
|
||
@Produces({"text/*+xml", "application/*+xml"}) | ||
@SuppressWarnings("rawtypes") | ||
public static class TestContextFinder implements JAXBContextFinder { | ||
|
||
@Override | ||
public JAXBContext findCachedContext(Class type, MediaType mediaType, Annotation[] parameterAnnotations) throws JAXBException { | ||
return null; | ||
} | ||
@Override | ||
public JAXBContext findCacheContext(MediaType mediaType, Annotation[] paraAnnotations, Class... classes) throws JAXBException { | ||
return null; | ||
} | ||
@Override | ||
public JAXBContext findCacheXmlTypeContext(MediaType mediaType, Annotation[] paraAnnotations, Class... classes) throws JAXBException { | ||
return null; | ||
} | ||
@Override | ||
public JAXBContext createContext(Annotation[] parameterAnnotations, Class... classes) throws JAXBException { | ||
return null; | ||
} | ||
} | ||
|
||
@Produces({"text/*+xml", "application/*+xml"}) | ||
public static class TestContextResolver implements ContextResolver<JAXBContextFinder> { | ||
|
||
@Override | ||
public JAXBContextFinder getContext(Class<?> type) { | ||
return new TestContextFinder(); | ||
} | ||
} | ||
|
||
@Test | ||
public void testUserDefinedContextResolver() { | ||
|
||
ResteasyProviderFactory providerFactory = ResteasyProviderFactory.getInstance(); | ||
ContextResolver<JAXBContextFinder> finder1 = providerFactory.getContextResolver(JAXBContextFinder.class, MediaType.TEXT_XML_TYPE); | ||
Assert.assertNotNull(finder1); | ||
System.out.println(finder1); | ||
providerFactory.register(TestContextResolver.class); | ||
ContextResolver<JAXBContextFinder> finder2 = providerFactory.getContextResolver(JAXBContextFinder.class, MediaType.TEXT_XML_TYPE); | ||
System.out.println(finder2); | ||
JAXBContextFinder finder = finder2.getContext(JAXBContextFinder.class); | ||
System.out.println(finder); | ||
Assert.assertTrue(finder instanceof TestContextFinder); | ||
} | ||
} |