Search in sources :

Example 41 with Response

use of javax.ws.rs.core.Response in project jersey by jersey.

the class ImplicitProducesViewProcessorTest method testImplicitTemplate.

@Test
public void testImplicitTemplate() throws IOException {
    final WebTarget target = target("implicit");
    Properties p = new Properties();
    Response cr = target.request("text/plain", "application/foo").get(Response.class);
    assertEquals(MediaType.TEXT_PLAIN_TYPE, cr.getMediaType());
    p.load(cr.readEntity(InputStream.class));
    assertEquals("/org/glassfish/jersey/tests/e2e/server/mvc/ImplicitProducesViewProcessorTest/ImplicitTemplate/index.testp", p.getProperty("path"));
    assertEquals("ImplicitTemplate", p.getProperty("model"));
    p = new Properties();
    cr = target.request("application/foo", "text/plain").get(Response.class);
    assertEquals(MediaType.TEXT_PLAIN_TYPE, cr.getMediaType());
    p.load(cr.readEntity(InputStream.class));
    assertEquals("/org/glassfish/jersey/tests/e2e/server/mvc/ImplicitProducesViewProcessorTest/ImplicitTemplate/index.testp", p.getProperty("path"));
    assertEquals("ImplicitTemplate", p.getProperty("model"));
    p = new Properties();
    cr = target.request("text/plain;q=0.5", "application/foo").get(Response.class);
    assertEquals(MediaType.TEXT_PLAIN_TYPE, cr.getMediaType());
    p.load(cr.readEntity(InputStream.class));
    assertEquals("/org/glassfish/jersey/tests/e2e/server/mvc/ImplicitProducesViewProcessorTest/ImplicitTemplate/index.testp", p.getProperty("path"));
    assertEquals("ImplicitTemplate", p.getProperty("model"));
    p = new Properties();
    cr = target.request("application/foo", "text/plain;q=0.5").get(Response.class);
    assertEquals(MediaType.TEXT_PLAIN_TYPE, cr.getMediaType());
    p.load(cr.readEntity(InputStream.class));
    assertEquals("/org/glassfish/jersey/tests/e2e/server/mvc/ImplicitProducesViewProcessorTest/ImplicitTemplate/index.testp", p.getProperty("path"));
    assertEquals("ImplicitTemplate", p.getProperty("model"));
}
Also used : Response(javax.ws.rs.core.Response) InputStream(java.io.InputStream) WebTarget(javax.ws.rs.client.WebTarget) Properties(java.util.Properties) TestProperties(org.glassfish.jersey.test.TestProperties) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 42 with Response

use of javax.ws.rs.core.Response in project jersey by jersey.

the class ImplicitViewWithResourceFilterTest method testImplicitTemplate.

@Test
public void testImplicitTemplate() throws IOException {
    final Invocation.Builder request = target("/").request();
    Response cr = request.get(Response.class);
    assertEquals(200, cr.getStatus());
    List<Object> xTest = cr.getMetadata().get("X-TEST");
    assertEquals(2, xTest.size());
    assertEquals("two", xTest.get(1));
    assertEquals("one", xTest.get(0));
    Properties p = new Properties();
    p.load(cr.readEntity(InputStream.class));
    assertEquals("/org/glassfish/jersey/tests/e2e/server/mvc/ImplicitViewWithResourceFilterTest/ImplicitTemplate/index.testp", p.getProperty("path"));
    assertEquals("ImplicitTemplate", p.getProperty("model"));
}
Also used : Response(javax.ws.rs.core.Response) Invocation(javax.ws.rs.client.Invocation) InputStream(java.io.InputStream) Properties(java.util.Properties) TestProperties(org.glassfish.jersey.test.TestProperties) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 43 with Response

use of javax.ws.rs.core.Response in project jersey by jersey.

the class BasicValidationTest method testInputParamsCustomConstraintsPositive.

@Test
public void testInputParamsCustomConstraintsPositive() throws Exception {
    final Response response = testInputParams("customParam", getDefaultParamBean());
    assertEquals(200, response.getStatus());
    assertEquals("pathParam_matrixParam_queryParam_headerParam_cookieParam_formParam", response.readEntity(String.class));
}
Also used : Response(javax.ws.rs.core.Response) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 44 with Response

use of javax.ws.rs.core.Response in project jersey by jersey.

the class BasicValidationTest method testCustomBeanParamNegative.

@Test
public void testCustomBeanParamNegative() throws Exception {
    final ContactBean contactBean = new ContactBean();
    contactBean.setEmail("jersey@example.com");
    contactBean.setPhone("134539");
    final Response response = testBean("customBeanParam", contactBean);
    assertEquals(400, response.getStatus());
    final String message = response.readEntity(String.class);
    assertTrue(message.contains("arg0"));
}
Also used : Response(javax.ws.rs.core.Response) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 45 with Response

use of javax.ws.rs.core.Response in project jersey by jersey.

the class BasicValidationTest method testValidBeanWrappedInResponsePositive.

@Test
public void testValidBeanWrappedInResponsePositive() throws Exception {
    final ContactBean contactBean = new ContactBean();
    contactBean.setName("Jersey");
    contactBean.setEmail("jersey@example.com");
    final Response response = testBean("validBeanWrappedInResponse", contactBean);
    assertEquals(contactBean, response.readEntity(ContactBean.class));
}
Also used : Response(javax.ws.rs.core.Response) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Aggregations

Response (javax.ws.rs.core.Response)10205 Test (org.junit.Test)5764 Test (org.testng.annotations.Test)1113 JerseyTest (org.glassfish.jersey.test.JerseyTest)870 Test (org.junit.jupiter.api.Test)701 WebTarget (javax.ws.rs.client.WebTarget)668 Builder (javax.ws.rs.client.Invocation.Builder)638 WebClient (org.apache.cxf.jaxrs.client.WebClient)620 DBUnitTest (org.orcid.test.DBUnitTest)611 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)577 Parameters (org.testng.annotations.Parameters)537 URI (java.net.URI)515 HashMap (java.util.HashMap)508 Path (javax.ws.rs.Path)506 List (java.util.List)465 ArrayList (java.util.ArrayList)419 Produces (javax.ws.rs.Produces)396 IOException (java.io.IOException)393 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)354 GET (javax.ws.rs.GET)348