Search in sources :

Example 1 with ClientResponse

use of com.sun.jersey.api.client.ClientResponse in project photon-core by 1000Memories.

the class PhotoResourceTest method testNoModifications.

@Test
public void testNoModifications() throws Exception {
    when(photoProvider.getPhotoInputStream("mf.jpg")).thenReturn(getImage("mf.jpg"));
    ClientResponse response = client().resource("/mf.jpg").get(ClientResponse.class);
    assertThat(response.getEntity(byte[].class), is(ByteStreams.toByteArray(getImage("mf.jpg"))));
    assertThat(response.getType().toString(), is("image/jpeg"));
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Test(org.junit.Test) ResourceTest(com.yammer.dropwizard.testing.ResourceTest)

Example 2 with ClientResponse

use of com.sun.jersey.api.client.ClientResponse in project hadoop by apache.

the class TestRMWithCSRFFilter method testAllowNonBrowserInteractionWithoutHeader.

@Test
public void testAllowNonBrowserInteractionWithoutHeader() throws Exception {
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("cluster").path("info").accept("application/xml").get(ClientResponse.class);
    assertTrue("Should have been accepted", response.getStatus() == Status.OK.getStatusCode());
    assertEquals(MediaType.APPLICATION_XML_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    String xml = response.getEntity(String.class);
    verifyClusterInfoXML(xml);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 3 with ClientResponse

use of com.sun.jersey.api.client.ClientResponse in project hadoop by apache.

the class TestRMWithXFSFilter method testSameOrigin.

@Test
public void testSameOrigin() throws Exception {
    createInjector("SAMEORIGIN");
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("cluster").path("info").accept("application/xml").get(ClientResponse.class);
    assertTrue("Should have received SAMEORIGIN x-frame options header", response.getHeaders().get(XFrameOptionsFilter.X_FRAME_OPTIONS).get(0).equals("SAMEORIGIN"));
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 4 with ClientResponse

use of com.sun.jersey.api.client.ClientResponse in project hadoop by apache.

the class TestRMWithXFSFilter method testExplicitlyDisabled.

@Test
public void testExplicitlyDisabled() throws Exception {
    createInjector(null, true);
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("cluster").path("info").accept("application/xml").get(ClientResponse.class);
    assertFalse("Should have not received x-frame options header", response.getHeaders().get(XFrameOptionsFilter.X_FRAME_OPTIONS) == null);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 5 with ClientResponse

use of com.sun.jersey.api.client.ClientResponse in project hadoop by apache.

the class TestRMWebServicesReservation method testListReservationHelper.

private JSONObject testListReservationHelper(WebResource resource, Status status) throws Exception {
    Thread.sleep(1000);
    ClientResponse response = resource.get(ClientResponse.class);
    if (!this.isAuthenticationEnabled()) {
        assertResponseStatusCode(Status.UNAUTHORIZED, response.getStatusInfo());
        return null;
    }
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    assertResponseStatusCode(status, response.getStatusInfo());
    return response.getEntity(JSONObject.class);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse)

Aggregations

ClientResponse (com.sun.jersey.api.client.ClientResponse)2042 Test (org.junit.Test)1153 WebResource (com.sun.jersey.api.client.WebResource)699 JSONObject (org.codehaus.jettison.json.JSONObject)412 URI (java.net.URI)293 HashMap (java.util.HashMap)131 Client (com.sun.jersey.api.client.Client)123 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)110 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)103 ArrayList (java.util.ArrayList)100 IOException (java.io.IOException)91 JSONArray (org.codehaus.jettison.json.JSONArray)81 InputStream (java.io.InputStream)77 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)76 Gson (com.google.gson.Gson)59 JSONException (org.codehaus.jettison.json.JSONException)58 List (java.util.List)57 JavaResult (org.milyn.payload.JavaResult)52 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)48 Map (java.util.Map)47