Search in sources :

Example 1 with EntityTag

use of javax.ws.rs.core.EntityTag 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 EntityTag

use of javax.ws.rs.core.EntityTag 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)

Example 3 with EntityTag

use of javax.ws.rs.core.EntityTag in project che by eclipse.

the class ETagResponseFilterTest method filterListEntityTestWithEtag.

/**
     * Check if ETag sent with header is redirecting to NOT_MODIFIED
     */
@Test
public void filterListEntityTestWithEtag() throws Exception {
    Map<String, List<String>> headers = new HashMap<>();
    headers.put("If-None-Match", Collections.singletonList(new EntityTag("900150983cd24fb0d6963f7d28e17f72").toString()));
    final ContainerResponse response = resourceLauncher.service(HttpMethod.GET, SERVICE_PATH + "/list", 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 4 with EntityTag

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

the class ContainerRequestTest method testPreconditionsMatch.

@Test
public void testPreconditionsMatch() {
    ContainerRequest r = new ContainerRequest(URI.create("http://example.org/app"), URI.create("http://example.org/app/resource"), "GET", SECURITY_CONTEXT, new MapPropertiesDelegate());
    r.header(HttpHeaders.IF_MATCH, "\"686897696a7c876b7e\"");
    assertNull(r.evaluatePreconditions(new EntityTag("686897696a7c876b7e")));
    assertEquals(r.evaluatePreconditions(new EntityTag("0")).build().getStatus(), Response.Status.PRECONDITION_FAILED.getStatusCode());
}
Also used : MapPropertiesDelegate(org.glassfish.jersey.internal.MapPropertiesDelegate) EntityTag(javax.ws.rs.core.EntityTag) Test(org.junit.Test)

Example 5 with EntityTag

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

the class MatchingEntityTagTest method testOneEntityTag.

@Test
public void testOneEntityTag() throws Exception {
    String header = "\"1\"";
    Set<MatchingEntityTag> s = HttpHeaderReader.readMatchingEntityTag(header);
    assertEquals(1, s.size());
    assertTrue(s.contains(new EntityTag("1")));
}
Also used : EntityTag(javax.ws.rs.core.EntityTag) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Aggregations

EntityTag (javax.ws.rs.core.EntityTag)73 GET (javax.ws.rs.GET)24 Response (javax.ws.rs.core.Response)24 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)23 Path (javax.ws.rs.Path)21 CacheControl (javax.ws.rs.core.CacheControl)20 Test (org.junit.Test)18 Produces (javax.ws.rs.Produces)13 Date (java.util.Date)10 Test (org.testng.annotations.Test)9 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)8 Timestamp (com.yahoo.rdl.Timestamp)5 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)5 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)5 List (java.util.List)5 ContainerResponse (org.everrest.core.impl.ContainerResponse)5 Principal (com.yahoo.athenz.auth.Principal)4 EnvironmentUser (fi.otavanopisto.muikku.model.users.EnvironmentUser)4 ArrayList (java.util.ArrayList)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4