@Override public EntityTag getEntityTag() { return delegate.getEntityTag(); }
/** * Get the EntityTag for a given resource. * @param url the URL * @return the entity tag */ default EntityTag getETag(final String url) { try (final Response res = target(url).request().get()) { return res.getEntityTag(); } }
/** * Get the EntityTag for a given resource. * @param url the URL * @return the entity tag */ default EntityTag getETag(final String url) { try (final Response res = target(url).request().get()) { return res.getEntityTag(); } }
/** * Fetches {@code ETag} header value from latest service run (if available). * * @param <T> any service class * @param service service class instance * @return {@code ETag} header value from latest service run (if available) */ public <T> EntityTag getLatestEntityTag(final T service) { return WebClient.client(service).getResponse().getEntityTag(); }
/** * Fetches {@code ETag} header value from latest service run (if available). * * @param <T> any service class * @param service service class instance * @return {@code ETag} header value from latest service run (if available) */ public <T> EntityTag getLatestEntityTag(final T service) { return WebClient.client(service).getResponse().getEntityTag(); }
@Test public void testGetIfNoneMatchWeak() { final String etag = target("").request().get().getEntityTag().getValue(); final Response res = target("").request().header("If-None-Match", "W/\"" + etag + "\"").get(); assertEquals(SC_NOT_MODIFIED, res.getStatus(), "Unexpected response code!"); }
@Test public void testGetIfMatchBinary() { final String etag = target(BINARY_PATH).request().get().getEntityTag().getValue(); final Response res = target(BINARY_PATH).request().header("If-Match", "\"" + etag + "\"").get(); assertEquals(SC_OK, res.getStatus(), "Unexpected response code!"); }
@Test public void testGetIfNoneMatchBinary() { final String etag = target(BINARY_PATH).request().get().getEntityTag().getValue(); final Response res = target(BINARY_PATH).request().header("If-None-Match", "\"" + etag + "\"").get(); assertEquals(SC_NOT_MODIFIED, res.getStatus(), "Unexpected response code!"); }
@Test public void testGetIfNoneMatchWeakBinary() { final String etag = target(BINARY_PATH).request().get().getEntityTag().getValue(); final Response res = target(BINARY_PATH).request().header("If-None-Match", "W/\"" + etag + "\"").get(); assertEquals(SC_NOT_MODIFIED, res.getStatus(), "Unexpected response code!"); }
@Test public void testGetIfMatchWeak() { final String etag = target("").request().get().getEntityTag().getValue(); final Response res = target("").request().header("If-Match", "W/\"" + etag + "\"").get(); assertEquals(SC_PRECONDITION_FAILED, res.getStatus(), "Unexpected response code!"); }
@Test public void testGetIfMatch() { final String etag = target("").request().get().getEntityTag().getValue(); final Response res = target("").request().header("If-Match", "\"" + etag + "\"").get(); assertEquals(SC_PRECONDITION_FAILED, res.getStatus(), "Unexpected response code!"); }
@Test public void testGetIfNoneMatch() { final String etag = target("").request().get().getEntityTag().getValue(); final Response res = target("").request().header("If-None-Match", "\"" + etag + "\"").get(); assertEquals(SC_NOT_MODIFIED, res.getStatus(), "Unexpected response code!"); }
@Test public void testGetIfMatchBinaryWeak() { final String etag = target(BINARY_PATH).request().get().getEntityTag().getValue(); final Response res = target(BINARY_PATH).request().header("If-Match", "W/\"" + etag + "\"").get(); assertEquals(SC_PRECONDITION_FAILED, res.getStatus(), "Unexpected response code!"); }
@Test public void testPutIfNoneMatchWeakEtag() { final String etag = target(BINARY_PATH).request().get().getEntityTag().getValue(); final Response res = target(BINARY_PATH).request().header("If-None-Match", "W/\"" + etag + "\"") .put(entity("some different data.", TEXT_PLAIN_TYPE)); assertEquals(SC_NO_CONTENT, res.getStatus(), "Unexpected response code!"); }
@Test public void testPutIfMatch() { final String etag = target(BINARY_PATH).request().get().getEntityTag().getValue(); final Response res = target(BINARY_PATH).request().header("If-Match", "\"" + etag + "\"") .put(entity("some different data.", TEXT_PLAIN_TYPE)); assertEquals(SC_NO_CONTENT, res.getStatus(), "Unexpected response code!"); }
@Test public void testPutIfNoneMatchEtag() { final String etag = target(BINARY_PATH).request().get().getEntityTag().getValue(); final Response res = target(BINARY_PATH).request().header("If-None-Match", "\"" + etag + "\"") .put(entity("some different data.", TEXT_PLAIN_TYPE)); assertEquals(SC_PRECONDITION_FAILED, res.getStatus(), "Unexpected response code!"); }
@Test public void testPutIfNoneMatchRdfEtag() { final String etag = target("").request().get().getEntityTag().getValue(); final Response res = target("").request().header("If-None-Match", "\"" + etag + "\"") .put(entity("<> <http://purl.org/dc/terms/title> \"A title\" .", TEXT_TURTLE_TYPE)); assertEquals(SC_PRECONDITION_FAILED, res.getStatus(), "Unexpected response code!"); }
@Test public void testPutIfNoneMatchRdfWeakEtag() { final String etag = target("").request().get().getEntityTag().getValue(); final Response res = target("").request().header("If-None-Match", "W/\"" + etag + "\"") .put(entity("<> <http://purl.org/dc/terms/title> \"A title\" .", TEXT_TURTLE_TYPE)); assertEquals(SC_NO_CONTENT, res.getStatus(), "Unexpected response code!"); }
@Test public void testPutIfMatchMultiple() { final String etag = target(BINARY_PATH).request().get().getEntityTag().getValue(); final Response res = target(BINARY_PATH).request().header("If-Match", "\"blah\", \"" + etag + "\"") .put(entity("some different data.", TEXT_PLAIN_TYPE)); assertEquals(SC_NO_CONTENT, res.getStatus(), "Unexpected response code!"); }
@Test public void testPutIfMatchWeak() { final String etag = target("").request().get().getEntityTag().getValue(); final Response res = target("").request().header("If-Match", "W/\"" + etag + "\"") .put(entity("some different data.", TEXT_PLAIN_TYPE)); assertEquals(SC_PRECONDITION_FAILED, res.getStatus(), "Unexpected response code!"); }