コード例 #1
0
  @Test
  public void testNewHeadersAreAddedByMerge() throws IOException {

    Header[] headers = {
      new BasicHeader("Date", formatDate(requestDate)), new BasicHeader("ETag", "\"etag\"")
    };

    entry = HttpTestUtils.makeCacheEntry(headers);
    response.setHeaders(
        new Header[] {
          new BasicHeader("Last-Modified", formatDate(responseDate)),
          new BasicHeader("Cache-Control", "public"),
        });

    HttpCacheEntry updatedEntry =
        impl.updateCacheEntry(null, entry, new Date(), new Date(), response);

    Header[] updatedHeaders = updatedEntry.getAllHeaders();
    assertEquals(4, updatedHeaders.length);

    headersContain(updatedHeaders, "Date", formatDate(requestDate));
    headersContain(updatedHeaders, "ETag", "\"etag\"");
    headersContain(updatedHeaders, "Last-Modified", formatDate(responseDate));
    headersContain(updatedHeaders, "Cache-Control", "public");
  }
コード例 #2
0
 @Test
 public void testUpdateCacheEntryReturnsDifferentEntryInstance() throws IOException {
   entry = HttpTestUtils.makeCacheEntry();
   HttpCacheEntry newEntry =
       impl.updateCacheEntry(null, entry, requestDate, responseDate, response);
   assertNotSame(newEntry, entry);
 }
コード例 #3
0
  @Test
  public void testUpdatedEntryHasLatestRequestAndResponseDates() throws IOException {
    entry = HttpTestUtils.makeCacheEntry(tenSecondsAgo, eightSecondsAgo);
    HttpCacheEntry updated =
        impl.updateCacheEntry(null, entry, twoSecondsAgo, oneSecondAgo, response);

    assertEquals(twoSecondsAgo, updated.getRequestDate());
    assertEquals(oneSecondAgo, updated.getResponseDate());
  }
コード例 #4
0
 @Test
 public void cannotUpdateFromANon304OriginResponse() throws Exception {
   entry = HttpTestUtils.makeCacheEntry();
   response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
   try {
     impl.updateCacheEntry("A", entry, new Date(), new Date(), response);
     fail("should have thrown exception");
   } catch (IllegalArgumentException expected) {
   }
 }
コード例 #5
0
  @Test
  public void entryWithMalformedDateIsStillUpdated() throws Exception {
    Header[] headers = {new BasicHeader("ETag", "\"old\""), new BasicHeader("Date", "bad-date")};
    entry = HttpTestUtils.makeCacheEntry(tenSecondsAgo, eightSecondsAgo, headers);
    response.setHeader("ETag", "\"new\"");
    response.setHeader("Date", formatDate(twoSecondsAgo));
    HttpCacheEntry updated =
        impl.updateCacheEntry(null, entry, twoSecondsAgo, oneSecondAgo, response);

    assertEquals("\"new\"", updated.getFirstHeader("ETag").getValue());
  }
コード例 #6
0
 @Test
 public void oldHeadersRetainedIfResponseOlderThanEntry() throws Exception {
   Header[] headers = {
     new BasicHeader("Date", formatDate(oneSecondAgo)), new BasicHeader("ETag", "\"new-etag\"")
   };
   entry = HttpTestUtils.makeCacheEntry(twoSecondsAgo, now, headers);
   response.setHeader("Date", formatDate(tenSecondsAgo));
   response.setHeader("ETag", "\"old-etag\"");
   HttpCacheEntry result = impl.updateCacheEntry("A", entry, new Date(), new Date(), response);
   assertEquals(2, result.getAllHeaders().length);
   headersContain(result.getAllHeaders(), "Date", formatDate(oneSecondAgo));
   headersContain(result.getAllHeaders(), "ETag", "\"new-etag\"");
 }
コード例 #7
0
  @Test
  public void entry1xxWarningsAreRemovedOnUpdate() throws Exception {
    Header[] headers = {
      new BasicHeader("Warning", "110 fred \"Response is stale\""),
      new BasicHeader("ETag", "\"old\""),
      new BasicHeader("Date", formatDate(eightSecondsAgo))
    };
    entry = HttpTestUtils.makeCacheEntry(tenSecondsAgo, eightSecondsAgo, headers);
    response.setHeader("ETag", "\"new\"");
    response.setHeader("Date", formatDate(twoSecondsAgo));
    HttpCacheEntry updated =
        impl.updateCacheEntry(null, entry, twoSecondsAgo, oneSecondAgo, response);

    assertEquals(0, updated.getHeaders("Warning").length);
  }
コード例 #8
0
  @Test
  public void testHeadersAreMergedCorrectly() throws IOException {
    Header[] headers = {
      new BasicHeader("Date", formatDate(responseDate)), new BasicHeader("ETag", "\"etag\"")
    };
    entry = HttpTestUtils.makeCacheEntry(headers);
    response.setHeaders(new Header[] {});

    HttpCacheEntry updatedEntry =
        impl.updateCacheEntry(null, entry, new Date(), new Date(), response);

    Header[] updatedHeaders = updatedEntry.getAllHeaders();
    assertEquals(2, updatedHeaders.length);
    headersContain(updatedHeaders, "Date", formatDate(responseDate));
    headersContain(updatedHeaders, "ETag", "\"etag\"");
  }