Search in sources :

Example 1 with ContainerResponse

use of org.everrest.core.impl.ContainerResponse in project che by eclipse.

the class ETagResponseFilterTest method filterSingleEntityTestWithEtag.

/**
     * Check if ETag sent with header is redirecting to NOT_MODIFIED
     */
@Test
public void filterSingleEntityTestWithEtag() throws Exception {
    Map<String, List<String>> headers = new HashMap<>();
    headers.put("If-None-Match", Collections.singletonList(new EntityTag("5d41402abc4b2a76b9719d911017c592").toString()));
    final ContainerResponse response = resourceLauncher.service(HttpMethod.GET, SERVICE_PATH + "/single", BASE_URI, headers, null, null);
    assertEquals(response.getStatus(), NOT_MODIFIED.getStatusCode());
    // check null body
    Assert.assertNull(response.getEntity());
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) HashMap(java.util.HashMap) List(java.util.List) EntityTag(javax.ws.rs.core.EntityTag) Test(org.testng.annotations.Test)

Example 2 with ContainerResponse

use of org.everrest.core.impl.ContainerResponse in project che by eclipse.

the class DownloadFileResponseFilterTest method checkOnlyOnGetMethodTest.

/**
     * Check that parameter is only handled if there is a GET method, not POST
     */
@Test
public void checkOnlyOnGetMethodTest() throws Exception {
    final ContainerResponse response = resourceLauncher.service(HttpMethod.POST, SERVICE_PATH + "/modify?" + DownloadFileResponseFilter.QUERY_DOWNLOAD_PARAMETER + "=hello.json", BASE_URI, null, null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    // check entity
    Assert.assertEquals(response.getEntity(), "helloContent");
    // headers = 2
    Assert.assertEquals(response.getHttpHeaders().size(), 1);
    // Check custom header
    List<Object> headers = response.getHttpHeaders().get(HttpHeaders.CONTENT_DISPOSITION);
    Assert.assertNull(headers);
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) Test(org.testng.annotations.Test)

Example 3 with ContainerResponse

use of org.everrest.core.impl.ContainerResponse in project che by eclipse.

the class DownloadFileResponseFilterTest method checkDownloadFileWithParameter.

/**
     * Check if header for downloading is added in response if we're also using a custom header
     */
@Test
public void checkDownloadFileWithParameter() throws Exception {
    final ContainerResponse response = resourceLauncher.service(HttpMethod.GET, SERVICE_PATH + "/list?" + DownloadFileResponseFilter.QUERY_DOWNLOAD_PARAMETER + "=hello.json", BASE_URI, null, null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    // check entity
    Assert.assertEquals(response.getEntity(), Arrays.asList("a", "b", "c"));
    // headers = 2
    Assert.assertEquals(response.getHttpHeaders().size(), 2);
    // Check custom header
    List<Object> headers = response.getHttpHeaders().get(HttpHeaders.CONTENT_DISPOSITION);
    Assert.assertNotNull(headers);
    Assert.assertEquals(headers.size(), 1);
    Assert.assertEquals(headers.get(0), "attachment; filename=hello.json");
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) Test(org.testng.annotations.Test)

Example 4 with ContainerResponse

use of org.everrest.core.impl.ContainerResponse in project che by eclipse.

the class DownloadFileResponseFilterTest method checkNoParameterTest.

/**
     * Check if header is absent when parameter is empty
     */
@Test
public void checkNoParameterTest() throws Exception {
    final ContainerResponse response = resourceLauncher.service(HttpMethod.GET, SERVICE_PATH + "/list", BASE_URI, null, null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    // check entity
    Assert.assertEquals(response.getEntity(), Arrays.asList("a", "b", "c"));
    // Check headers
    MultivaluedMap<String, Object> headerTags = response.getHttpHeaders();
    Assert.assertNotNull(headerTags);
    Assert.assertEquals(headerTags.size(), 1);
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) Test(org.testng.annotations.Test)

Example 5 with ContainerResponse

use of org.everrest.core.impl.ContainerResponse in project che by eclipse.

the class ETagResponseFilterTest method filterListEntityTest.

/**
     * Check if ETag is generated for a list of JSON
     */
@Test
public void filterListEntityTest() throws Exception {
    final ContainerResponse response = resourceLauncher.service(HttpMethod.GET, SERVICE_PATH + "/list", BASE_URI, null, null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    // check entity
    Assert.assertEquals(response.getEntity(), Arrays.asList("a", "b", "c"));
    // Check etag
    List<Object> headerTags = response.getHttpHeaders().get("ETag");
    Assert.assertNotNull(headerTags);
    Assert.assertEquals(headerTags.size(), 1);
    Assert.assertEquals(headerTags.get(0), new EntityTag("900150983cd24fb0d6963f7d28e17f72"));
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) EntityTag(javax.ws.rs.core.EntityTag) Test(org.testng.annotations.Test)

Aggregations

ContainerResponse (org.everrest.core.impl.ContainerResponse)69 Test (org.testng.annotations.Test)68 List (java.util.List)35 LinkedList (java.util.LinkedList)34 ArrayList (java.util.ArrayList)33 Collections.singletonList (java.util.Collections.singletonList)33 HashMap (java.util.HashMap)22 ItemReference (org.eclipse.che.api.project.shared.dto.ItemReference)22 LinkedHashMap (java.util.LinkedHashMap)20 LinkedHashSet (java.util.LinkedHashSet)15 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)12 MoveOptions (org.eclipse.che.api.project.shared.dto.MoveOptions)8 CopyOptions (org.eclipse.che.api.project.shared.dto.CopyOptions)6 TreeElement (org.eclipse.che.api.project.shared.dto.TreeElement)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 EntityTag (javax.ws.rs.core.EntityTag)5 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)5 ServerException (org.eclipse.che.api.core.ServerException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4