use of org.glassfish.jersey.server.ApplicationHandler in project jersey by jersey.
the class AcceptTest method testAcceptNoProduces.
@Test
public void testAcceptNoProduces() throws Exception {
ApplicationHandler app = createApplication(NoProducesResource.class);
// media type order in the accept header does not impose output media type!
ContainerResponse response = app.apply(RequestContextBuilder.from("/", "GET").accept("image/png, text/plain;q=0.9").build()).get();
assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
assertEquals("GET", response.getEntity());
assertEquals(MediaType.valueOf("image/png"), response.getMediaType());
response = app.apply(RequestContextBuilder.from("/", "GET").accept("text/plain;q=0.5, text/html").build()).get();
assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
assertEquals("GET", response.getEntity());
assertEquals(MediaType.TEXT_HTML_TYPE, response.getMediaType());
}
use of org.glassfish.jersey.server.ApplicationHandler in project jersey by jersey.
the class AcceptTest method test.
private void test(Class<?> c) throws Exception {
ApplicationHandler app = createApplication(c);
ContainerResponse response = app.apply(RequestContextBuilder.from("/", "GET").accept("application/foo").build()).get();
assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
assertEquals("GET", response.getEntity());
assertEquals(MediaType.valueOf("application/foo"), response.getMediaType());
response = app.apply(RequestContextBuilder.from("/", "GET").accept("application/bar").build()).get();
assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
assertEquals("GET", response.getEntity());
assertEquals(MediaType.valueOf("application/bar"), response.getMediaType());
response = app.apply(RequestContextBuilder.from("/", "GET").accept("application/foo", "application/bar").build()).get();
assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
assertEquals("GET", response.getEntity());
assertEquals(MediaType.valueOf("application/foo"), response.getMediaType());
response = app.apply(RequestContextBuilder.from("/", "GET").accept("application/bar", "application/foo").build()).get();
assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
assertEquals("GET", response.getEntity());
assertEquals(MediaType.valueOf("application/bar"), response.getMediaType());
}
use of org.glassfish.jersey.server.ApplicationHandler in project jersey by jersey.
the class AcceptTest method testAcceptMultiple.
@Test
public void testAcceptMultiple() throws Exception {
ApplicationHandler app = createApplication(MultipleResource.class);
MediaType foo = MediaType.valueOf("application/foo");
MediaType bar = MediaType.valueOf("application/bar");
ContainerResponse response = app.apply(RequestContextBuilder.from("/", "GET").accept(foo).build()).get();
assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
assertEquals("GET", response.getEntity());
assertEquals(foo, response.getMediaType());
response = app.apply(RequestContextBuilder.from("/", "GET").accept(bar).build()).get();
assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
assertEquals("GET", response.getEntity());
assertEquals(bar, response.getMediaType());
response = app.apply(RequestContextBuilder.from("/", "GET").accept("*/*").build()).get();
assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
assertEquals("GET", response.getEntity());
assertEquals(foo, response.getMediaType());
response = app.apply(RequestContextBuilder.from("/", "GET").accept("application/*").build()).get();
assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
assertEquals("GET", response.getEntity());
assertEquals(foo, response.getMediaType());
response = app.apply(RequestContextBuilder.from("/", "GET").accept("application/foo;q=0.1", "application/bar").build()).get();
assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
assertEquals("GET", response.getEntity());
assertEquals(bar, response.getMediaType());
response = app.apply(RequestContextBuilder.from("/", "GET").accept("application/foo;q=0.5", "application/bar;q=0.1").build()).get();
assertTrue("Status: " + response.getStatus(), response.getStatus() < 300);
assertEquals("GET", response.getEntity());
assertEquals(foo, response.getMediaType());
}
use of org.glassfish.jersey.server.ApplicationHandler in project jersey by jersey.
the class AcceptWriterTest method testAcceptGet.
@Test
public void testAcceptGet() throws Exception {
final ResourceConfig resourceConfig = new ResourceConfig(Resource.class, FooStringWriter.class, BarStringWriter.class);
final ApplicationHandler app = new ApplicationHandler(resourceConfig);
_test(app, "foo: content", "GET", null, null, "application/foo");
_test(app, "foo: content", "GET", null, null, "applcation/baz, application/foo;q=0.8");
_test(app, "bar: content", "GET", null, null, "application/bar");
_test(app, "bar: content", "GET", null, null, "applcation/baz, application/bar;q=0.8");
}
use of org.glassfish.jersey.server.ApplicationHandler in project jersey by jersey.
the class AmbiguousTemplateTest method testPathParamOnAmbiguousTemplate3.
@Test
public void testPathParamOnAmbiguousTemplate3() throws ExecutionException, InterruptedException {
final ApplicationHandler applicationHandler = new ApplicationHandler(new ResourceConfig(ResourceABC.class, ResourceXYZ.class));
final ContainerResponse response = applicationHandler.apply(RequestContextBuilder.from("/uuu", "GET").build()).get();
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals("abc:uuu", response.getEntity());
}
Aggregations