|
50 | 50 | import org.junit.Test; |
51 | 51 |
|
52 | 52 | import static org.junit.Assert.assertEquals; |
| 53 | +import static org.junit.Assert.assertNotEquals; |
53 | 54 | import static org.junit.Assert.assertNotNull; |
54 | 55 |
|
55 | 56 | public class ClientCacheTest { |
@@ -204,6 +205,25 @@ public void testGetJaxbBookCacheByValue() { |
204 | 205 | } |
205 | 206 | } |
206 | 207 |
|
| 208 | + @Test |
| 209 | + public void testGetNonCacheBook() { |
| 210 | + try (CacheControlFeature feature = new CacheControlFeature()) { |
| 211 | + final WebTarget base = ClientBuilder.newBuilder().register(feature).build().target(ADDRESS); |
| 212 | + final Invocation.Builder cached = |
| 213 | + setAsLocal(base.request("text/xml")).header(HttpHeaders.CACHE_CONTROL, "public"); |
| 214 | + final Response r = cached.get(); |
| 215 | + assertEquals(Response.Status.OK.getStatusCode(), r.getStatus()); |
| 216 | + final Book b1 = r.readEntity(Book.class); |
| 217 | + assertEquals("JNonCache", b1.getName()); |
| 218 | + assertNotNull(b1.getId()); |
| 219 | + waitABit(); |
| 220 | + final Response r2 = cached.get(); |
| 221 | + final Book b2 = r2.readEntity(Book.class); |
| 222 | + assertNotEquals(b1, b2); |
| 223 | + assertEquals(b1.getName(), b2.getName()); |
| 224 | + } |
| 225 | + } |
| 226 | + |
207 | 227 | private static Invocation.Builder setAsLocal(final Invocation.Builder client) { |
208 | 228 | WebClient.getConfig(client).getRequestContext().put(LocalConduit.DIRECT_DISPATCH, Boolean.TRUE); |
209 | 229 | return client; |
@@ -233,6 +253,14 @@ public Response getJaxbBook() { |
233 | 253 | b.setName("JCache"); |
234 | 254 | return Response.ok(b).tag("123").cacheControl(CacheControl.valueOf("max-age=50000")).build(); |
235 | 255 | } |
| 256 | + @GET |
| 257 | + @Produces("text/xml") |
| 258 | + public Response getNonCacheBook() { |
| 259 | + Book b = new Book(); |
| 260 | + b.setId(System.currentTimeMillis()); |
| 261 | + b.setName("JNonCache"); |
| 262 | + return Response.ok(b).tag("123").build(); |
| 263 | + } |
236 | 264 | } |
237 | 265 | @XmlRootElement |
238 | 266 | public static class Book implements Serializable { |
|
0 commit comments