}
@Test
public void testAcceptGet() throws Exception
{
Registry registry = new ResourceMethodRegistry(ResteasyProviderFactory.getInstance());
registry.addPerRequestResource(WebResource.class);
MediaType contentType = new MediaType("text", "plain");
{
ArrayList<MediaType> accepts = new ArrayList<MediaType>();
accepts.add(MediaType.valueOf("application/foo"));
ResourceMethod method = (ResourceMethod) registry.getResourceInvoker(createRequest("GET", "/", contentType, accepts));
Assert.assertNotNull(method);
Assert.assertEquals(WebResource.class.getMethod("doGetFoo"), method.getMethod());
}
{
ArrayList<MediaType> accepts = new ArrayList<MediaType>();
accepts.add(MediaType.valueOf("application/foo;q=0.1"));
ResourceMethod method = (ResourceMethod) registry.getResourceInvoker(createRequest("GET", "/", contentType, accepts));
Assert.assertNotNull(method);
Assert.assertEquals(WebResource.class.getMethod("doGetFoo"), method.getMethod());
}
{
ArrayList<MediaType> accepts = new ArrayList<MediaType>();
accepts.add(MediaType.valueOf("application/foo"));
accepts.add(MediaType.valueOf("application/bar;q=0.4"));
accepts.add(MediaType.valueOf("application/baz;q=0.2"));
ResourceMethod method = (ResourceMethod) registry.getResourceInvoker(createRequest("GET", "/", contentType, accepts));
Assert.assertNotNull(method);
Assert.assertEquals(WebResource.class.getMethod("doGetFoo"), method.getMethod());
}
{
ArrayList<MediaType> accepts = new ArrayList<MediaType>();
accepts.add(MediaType.valueOf("application/foo;q=0.4"));
accepts.add(MediaType.valueOf("application/bar"));
accepts.add(MediaType.valueOf("application/baz;q=0.2"));
ResourceMethod method = (ResourceMethod) registry.getResourceInvoker(createRequest("GET", "/", contentType, accepts));
Assert.assertNotNull(method);
Assert.assertEquals(WebResource.class.getMethod("doGetBar"), method.getMethod());
}
{
ArrayList<MediaType> accepts = new ArrayList<MediaType>();
accepts.add(MediaType.valueOf("application/foo;q=0.4"));
accepts.add(MediaType.valueOf("application/bar;q=0.2"));
accepts.add(MediaType.valueOf("application/baz"));
ResourceMethod method = (ResourceMethod) registry.getResourceInvoker(createRequest("GET", "/", contentType, accepts));
Assert.assertNotNull(method);
Assert.assertEquals(WebResource.class.getMethod("doGetBaz"), method.getMethod());
}
}