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