ContainerRequest implements GenericContainerRequest { @Override public ResponseBuilder evaluatePreconditions(EntityTag etag) { checkArgument(etag != null, "Null ETag is not supported"); ResponseBuilder responseBuilder = evaluateIfMatch(etag); if (responseBuilder == null) { responseBuilder = evaluateIfNoneMatch(etag); } return responseBuilder; } ContainerRequest(String method, URI requestUri, URI baseUri, InputStream entityStream,
                            MultivaluedMap<String, String> httpHeaders, SecurityContext securityContext); @Override MediaType getAcceptableMediaType(List<MediaType> mediaTypes); @Override List<String> getCookieHeaders(); @Override InputStream getEntityStream(); @Override URI getRequestUri(); @Override URI getBaseUri(); @Override String getMethod(); @Override void setMethod(String method); @Override void setEntityStream(InputStream entityStream); @Override void setUris(URI requestUri, URI baseUri); @Override void setCookieHeaders(List<String> cookieHeaders); @Override void setRequestHeaders(MultivaluedMap<String, String> httpHeaders); @Override String getAuthenticationScheme(); @Override Principal getUserPrincipal(); @Override boolean isSecure(); @Override boolean isUserInRole(String role); @Override ResponseBuilder evaluatePreconditions(EntityTag etag); @Override ResponseBuilder evaluatePreconditions(Date lastModified); @Override ResponseBuilder evaluatePreconditions(Date lastModified, EntityTag etag); @Override ResponseBuilder evaluatePreconditions(); @Override Variant selectVariant(List<Variant> variants); @Override List<Locale> getAcceptableLanguages(); @Override List<MediaType> getAcceptableMediaTypes(); @Override List<AcceptMediaType> getAcceptMediaTypeList(); @Override Map<String, Cookie> getCookies(); @Override Date getDate(); @Override int getLength(); @Override Locale getLanguage(); @Override MediaType getMediaType(); @Override List<String> getRequestHeader(String name); @Override String getHeaderString(String name); @Override MultivaluedMap<String, String> getRequestHeaders(); @Override String toString();  }
@Test public void evaluatesPreconditionsResponseByETagAsNullWhenBothIfMatchAndIfNoneMatchHeaderNotSet() { assertNull(containerRequest.evaluatePreconditions(new EntityTag("1234567"))); }
@Test public void evaluatesPreconditionsResponseByETagAsNullWhenIfMatchHeaderMatchesWithETag() { headers.putSingle(IF_MATCH, "\"1234567\""); assertNull(containerRequest.evaluatePreconditions(new EntityTag("1234567"))); }
@Test public void evaluatesPreconditionsResponseByETagAs_PRECONDITION_FAILED_WhenETagIsWeak() { headers.putSingle(IF_MATCH, "\"1234567\""); Response response = containerRequest.evaluatePreconditions(new EntityTag("W/1234567")).build(); assertEquals(PRECONDITION_FAILED, response.getStatusInfo()); }
@Test public void evaluatesPreconditionsResponseByETagAsNullWhenIfNoneMatchHeaderDoesNotMatchWithETag() { headers.putSingle(IF_NONE_MATCH, "\"1234567\""); assertNull(containerRequest.evaluatePreconditions(new EntityTag("7654321"))); }
@Test public void evaluatesPreconditionsResponseByETagAs_PRECONDITION_FAILED_WhenIfNoneMatchHeaderMatchesWithETag() { headers.putSingle(IF_NONE_MATCH, "\"1234567\""); Response response = containerRequest.evaluatePreconditions(new EntityTag("1234567")).build(); assertEquals(PRECONDITION_FAILED, response.getStatusInfo()); }
@Test public void evaluatesPreconditionsResponseByLastModificationDateAs_PRECONDITION_FAILED_WhenLastModificationDateIsAfterIfUnmodifiedSinceHeader() { Date now = new Date(); Date before = new Date(now.getTime() - 10000); headers.putSingle(IF_UNMODIFIED_SINCE, formatDateInRfc1123DateFormat(before)); Response response = containerRequest.evaluatePreconditions(now).build(); assertEquals(PRECONDITION_FAILED, response.getStatusInfo()); }
@Test public void evaluatesPreconditionsResponseByLastModificationDateAsNullWhenIfUnmodifiedSinceHeaderIsNotSet() { Date now = new Date(); headers.putSingle(IF_UNMODIFIED_SINCE, null); assertNull(containerRequest.evaluatePreconditions(now)); }
@Test public void evaluatesPreconditionsResponseByLastModificationDateAsNullWhenIfUnmodifiedSinceHeaderHasInvalidFormat() { Date now = new Date(); headers.putSingle(IF_UNMODIFIED_SINCE, "foo"); assertNull(containerRequest.evaluatePreconditions(now)); }
@Test public void evaluatesPreconditionsResponseByLastModificationDateAs_NOT_MODIFIED_WhenLastModificationDateIsNotAfterIfModifiedSinceHeader() { Date now = new Date(); Date before = new Date(now.getTime() - 10000); headers.putSingle(IF_MODIFIED_SINCE, formatDateInRfc1123DateFormat(now)); Response response = containerRequest.evaluatePreconditions(before).build(); assertEquals(NOT_MODIFIED, response.getStatusInfo()); }
@Test public void evaluatesPreconditionsResponseByLastModificationDateAsNullWhenIfModifiedSinceHeaderIsNotSet() { Date now = new Date(); headers.putSingle(IF_MODIFIED_SINCE, null); assertNull(containerRequest.evaluatePreconditions(now)); }
@Test public void evaluatesPreconditionsResponseByLastModificationDateAsNullWhenIfModifiedSinceHeaderHasInvalidFormat() { Date now = new Date(); headers.putSingle(IF_MODIFIED_SINCE, "foo"); assertNull(containerRequest.evaluatePreconditions(now)); }
@Test public void evaluatesPreconditionsResponseByETagAndLastModificationDateAsNullWhenHeadersNotSet() { assertNull(containerRequest.evaluatePreconditions(new Date(), new EntityTag("1234567"))); }
@Test public void evaluatesPreconditionsResponseByETagAndLastModificationDateAsNullWhenIfMatchHeaderMatchesWithETag() { headers.putSingle(IF_MATCH, "\"1234567\""); assertNull(containerRequest.evaluatePreconditions(new Date(), new EntityTag("1234567"))); }
@Test public void evaluatesPreconditionsResponseByETagAndLastModificationDateAs_PRECONDITION_FAILED_WhenETagIsWeak() { headers.putSingle(IF_MATCH, "\"1234567\""); Response response = containerRequest.evaluatePreconditions(new Date(), new EntityTag("W/1234567")).build(); assertEquals(PRECONDITION_FAILED, response.getStatusInfo()); }
@Test public void evaluatesPreconditionsResponseByETgaAndLastModificationDateAs_NOT_MODIFIED_WhenLastModificationDateIsNotAfterIfModifiedSinceHeader() { Date now = new Date(); Date before = new Date(now.getTime() - 10000); headers.putSingle(IF_MODIFIED_SINCE, formatDateInRfc1123DateFormat(now)); Response response = containerRequest.evaluatePreconditions(before, new EntityTag("1234567")).build(); assertEquals(NOT_MODIFIED, response.getStatusInfo()); }
@Test public void evaluatesPreconditionsResponseByETagAndLastModificationDateAs_PRECONDITION_FAILED_WhenIfNoneMatchHeaderMatchesWithETag() { headers.putSingle(IF_NONE_MATCH, "\"1234567\""); Response response = containerRequest.evaluatePreconditions(new Date(), new EntityTag("1234567")).build(); assertEquals(PRECONDITION_FAILED, response.getStatusInfo()); }
@Test public void evaluatesPreconditionsResponseAs_PRECONDITION_FAILED_WhenIfMatchHeaderSet() { headers.putSingle(IF_MATCH, "\"1234567\""); Response response = containerRequest.evaluatePreconditions().build(); assertEquals(PRECONDITION_FAILED, response.getStatusInfo()); }
@Test public void evaluatesPreconditionsResponseAsNullWhenIfMatchHeaderNotSet() { headers.putSingle(IF_MATCH, null); assertNull(containerRequest.evaluatePreconditions()); }