Search in sources :

Example 16 with Response

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

the class HelloWorldTest method testFooBarOptions.

@Test
public void testFooBarOptions() {
    Response response = target().path(ROOT_PATH).request().header("Accept", "foo/bar").options();
    assertEquals(200, response.getStatus());
    final String allowHeader = response.getHeaderString("Allow");
    _checkAllowContent(allowHeader);
    assertEquals("foo/bar", response.getMediaType().toString());
    assertEquals(0, response.getLength());
}
Also used : Response(javax.ws.rs.core.Response) HttpResponse(org.apache.http.HttpResponse) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 17 with Response

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

the class HelloWorldTest method testTextPlainOptions.

@Test
public void testTextPlainOptions() {
    Response response = target().path(ROOT_PATH).request().header("Accept", MediaType.TEXT_PLAIN).options();
    assertEquals(200, response.getStatus());
    final String allowHeader = response.getHeaderString("Allow");
    _checkAllowContent(allowHeader);
    assertEquals(MediaType.TEXT_PLAIN_TYPE, response.getMediaType());
    final String responseBody = response.readEntity(String.class);
    _checkAllowContent(responseBody);
}
Also used : Response(javax.ws.rs.core.Response) HttpResponse(org.apache.http.HttpResponse) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 18 with Response

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

the class HelloWorldTest method testMissingResourceNotFound.

@Test
public void testMissingResourceNotFound() {
    Response response;
    response = target().path(ROOT_PATH + "arbitrary").request().get();
    assertEquals(404, response.getStatus());
    response.close();
    response = target().path(ROOT_PATH).path("arbitrary").request().get();
    assertEquals(404, response.getStatus());
    response.close();
}
Also used : Response(javax.ws.rs.core.Response) HttpResponse(org.apache.http.HttpResponse) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 19 with Response

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

the class AuthTest method testAuthDelete.

@Test
public void testAuthDelete() {
    CredentialsProvider credentialsProvider = new org.apache.http.impl.client.BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("name", "password"));
    ClientConfig cc = new ClientConfig();
    cc.property(ApacheClientProperties.CREDENTIALS_PROVIDER, credentialsProvider);
    cc.connectorProvider(new ApacheConnectorProvider());
    Client client = ClientBuilder.newClient(cc);
    WebTarget r = client.target(getBaseUri()).path("test");
    Response response = r.request().delete();
    assertEquals(response.getStatus(), 204);
}
Also used : Response(javax.ws.rs.core.Response) CredentialsProvider(org.apache.http.client.CredentialsProvider) WebTarget(javax.ws.rs.client.WebTarget) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 20 with Response

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

the class FollowRedirectsTest method testDoFollow.

@Test
public void testDoFollow() {
    Response r = target("test/redirect").register(RedirectTestFilter.class).request().get();
    assertEquals(200, r.getStatus());
    assertEquals("GET", r.readEntity(String.class));
    assertEquals(UriBuilder.fromUri(getBaseUri()).path(RedirectResource.class).build().toString(), r.getHeaderString(RedirectTestFilter.RESOLVED_URI_HEADER));
}
Also used : ClientResponse(org.glassfish.jersey.client.ClientResponse) Response(javax.ws.rs.core.Response) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

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