@Test public void testPreconditionsNoneMatch() { MutableRequest mr = new MutableRequest("", "http://example.org/app/resource", "GET"); mr.header(HttpHeaders.IF_NONE_MATCH, "\"686897696a7c876b7e\""); Request r = mr.toJaxrsRequest(); assertEquals( r.evaluatePreconditions(new EntityTag("686897696a7c876b7e")).build().getStatus(), Status.NOT_MODIFIED.getStatusCode()); assertNull(r.evaluatePreconditions(new EntityTag("000000000000000000"))); }
private void assertIfModifiedSinceFailed(String method, ResponseBuilder responseBuilder) { // if modified since only applies to GET and HEAD; otherwise it process request if (!("GET".equalsIgnoreCase(method) || "HEAD".equalsIgnoreCase(method))) { Assert.assertNull(responseBuilder, "Did NOT expect a response builder"); } else { Assert.assertNotNull(responseBuilder, "Expected a response builder"); Response response = responseBuilder.build(); Assert.assertEquals(response.getStatus(), Status.NOT_MODIFIED.getStatusCode()); } }
private void assertIfNoneMatchFailed(String method, ResponseBuilder responseBuilder) { Assert.assertNotNull(responseBuilder, "Expected a response builder"); Response response = responseBuilder.build(); // not modified only applies to GET and HEAD; otherwise it is a precondition failed if ("GET".equalsIgnoreCase(method) || "HEAD".equalsIgnoreCase(method)) { Assert.assertEquals(response.getStatus(), Status.NOT_MODIFIED.getStatusCode()); } else { Assert.assertEquals(response.getStatus(), Status.PRECONDITION_FAILED.getStatusCode()); } }
@Test public void testPreconditionsModified() throws ParseException { MutableRequest mr = new MutableRequest("", "http://example.org/app/resource", "GET"); mr.header(HttpHeaders.IF_MODIFIED_SINCE, "Sat, 29 Oct 2011 19:43:31 GMT"); Request r = mr.toJaxrsRequest(); SimpleDateFormat f = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z", Locale.ENGLISH); Date date = f.parse("Sat, 29 Oct 2011 19:43:31 GMT"); assertEquals( r.evaluatePreconditions(date).build().getStatus(), Status.NOT_MODIFIED.getStatusCode()); date = f.parse("Sat, 30 Oct 2011 19:43:31 GMT"); assertNull(r.evaluatePreconditions(date)); }