Test classes and methods should have default package visibility
This commit is contained in:
parent
e45345876e
commit
185d4e32aa
|
@ -56,7 +56,7 @@ import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestHttpCacheEntry {
|
class TestHttpCacheEntry {
|
||||||
|
|
||||||
private Instant now;
|
private Instant now;
|
||||||
private Instant elevenSecondsAgo;
|
private Instant elevenSecondsAgo;
|
||||||
|
@ -65,7 +65,7 @@ public class TestHttpCacheEntry {
|
||||||
private HttpCacheEntry entry;
|
private HttpCacheEntry entry;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
now = Instant.now();
|
now = Instant.now();
|
||||||
elevenSecondsAgo = now.minusSeconds(11);
|
elevenSecondsAgo = now.minusSeconds(11);
|
||||||
nineSecondsAgo = now.minusSeconds(9);
|
nineSecondsAgo = now.minusSeconds(9);
|
||||||
|
@ -99,7 +99,7 @@ public class TestHttpCacheEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetHeadersReturnsCorrectHeaders() {
|
void testGetHeadersReturnsCorrectHeaders() {
|
||||||
entry = makeEntry(
|
entry = makeEntry(
|
||||||
new BasicHeader("bar", "barValue1"),
|
new BasicHeader("bar", "barValue1"),
|
||||||
new BasicHeader("bar", "barValue2"));
|
new BasicHeader("bar", "barValue2"));
|
||||||
|
@ -107,7 +107,7 @@ public class TestHttpCacheEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetFirstHeaderReturnsCorrectHeader() {
|
void testGetFirstHeaderReturnsCorrectHeader() {
|
||||||
entry = makeEntry(
|
entry = makeEntry(
|
||||||
new BasicHeader("bar", "barValue1"),
|
new BasicHeader("bar", "barValue1"),
|
||||||
new BasicHeader("bar", "barValue2"));
|
new BasicHeader("bar", "barValue2"));
|
||||||
|
@ -115,7 +115,7 @@ public class TestHttpCacheEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetHeadersReturnsEmptyArrayIfNoneMatch() {
|
void testGetHeadersReturnsEmptyArrayIfNoneMatch() {
|
||||||
entry = makeEntry(
|
entry = makeEntry(
|
||||||
new BasicHeader("foo", "fooValue"),
|
new BasicHeader("foo", "fooValue"),
|
||||||
new BasicHeader("bar", "barValue1"),
|
new BasicHeader("bar", "barValue1"),
|
||||||
|
@ -124,7 +124,7 @@ public class TestHttpCacheEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetFirstHeaderReturnsNullIfNoneMatch() {
|
void testGetFirstHeaderReturnsNullIfNoneMatch() {
|
||||||
entry = makeEntry(
|
entry = makeEntry(
|
||||||
new BasicHeader("foo", "fooValue"),
|
new BasicHeader("foo", "fooValue"),
|
||||||
new BasicHeader("bar", "barValue1"),
|
new BasicHeader("bar", "barValue1"),
|
||||||
|
@ -133,7 +133,7 @@ public class TestHttpCacheEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetMethodReturnsCorrectRequestMethod() {
|
void testGetMethodReturnsCorrectRequestMethod() {
|
||||||
entry = makeEntry(
|
entry = makeEntry(
|
||||||
new BasicHeader("foo", "fooValue"),
|
new BasicHeader("foo", "fooValue"),
|
||||||
new BasicHeader("bar", "barValue1"),
|
new BasicHeader("bar", "barValue1"),
|
||||||
|
@ -142,33 +142,33 @@ public class TestHttpCacheEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void statusCodeComesFromOriginalStatusLine() {
|
void statusCodeComesFromOriginalStatusLine() {
|
||||||
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK);
|
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK);
|
||||||
assertEquals(HttpStatus.SC_OK, entry.getStatus());
|
assertEquals(HttpStatus.SC_OK, entry.getStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canGetOriginalRequestDate() {
|
void canGetOriginalRequestDate() {
|
||||||
final Instant requestDate = Instant.now();
|
final Instant requestDate = Instant.now();
|
||||||
entry = makeEntry(requestDate, Instant.now(), HttpStatus.SC_OK);
|
entry = makeEntry(requestDate, Instant.now(), HttpStatus.SC_OK);
|
||||||
assertEquals(requestDate, entry.getRequestInstant());
|
assertEquals(requestDate, entry.getRequestInstant());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canGetOriginalResponseDate() {
|
void canGetOriginalResponseDate() {
|
||||||
final Instant responseDate = Instant.now();
|
final Instant responseDate = Instant.now();
|
||||||
entry = makeEntry(Instant.now(), responseDate, HttpStatus.SC_OK);
|
entry = makeEntry(Instant.now(), responseDate, HttpStatus.SC_OK);
|
||||||
assertEquals(responseDate, entry.getResponseInstant());
|
assertEquals(responseDate, entry.getResponseInstant());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canGetOriginalResource() {
|
void canGetOriginalResource() {
|
||||||
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK);
|
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK);
|
||||||
assertSame(mockResource, entry.getResource());
|
assertSame(mockResource, entry.getResource());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canGetOriginalHeaders() {
|
void canGetOriginalHeaders() {
|
||||||
final Header[] headers = {
|
final Header[] headers = {
|
||||||
new BasicHeader("Server", "MockServer/1.0"),
|
new BasicHeader("Server", "MockServer/1.0"),
|
||||||
new BasicHeader("Date", DateUtils.formatStandardDate(now))
|
new BasicHeader("Date", DateUtils.formatStandardDate(now))
|
||||||
|
@ -182,7 +182,7 @@ public class TestHttpCacheEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canRetrieveOriginalVariantMap() {
|
void canRetrieveOriginalVariantMap() {
|
||||||
final Set<String> variants = new HashSet<>();
|
final Set<String> variants = new HashSet<>();
|
||||||
variants.add("A");
|
variants.add("A");
|
||||||
variants.add("B");
|
variants.add("B");
|
||||||
|
@ -199,7 +199,7 @@ public class TestHttpCacheEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void retrievedVariantMapIsNotModifiable() {
|
void retrievedVariantMapIsNotModifiable() {
|
||||||
final Set<String> variants = new HashSet<>();
|
final Set<String> variants = new HashSet<>();
|
||||||
variants.add("A");
|
variants.add("A");
|
||||||
variants.add("B");
|
variants.add("B");
|
||||||
|
@ -213,27 +213,27 @@ public class TestHttpCacheEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canConvertToString() {
|
void canConvertToString() {
|
||||||
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK);
|
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK);
|
||||||
assertNotNull(entry.toString());
|
assertNotNull(entry.toString());
|
||||||
assertNotEquals("", entry.toString());
|
assertNotEquals("", entry.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMissingDateHeaderIsIgnored() {
|
void testMissingDateHeaderIsIgnored() {
|
||||||
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK);
|
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK);
|
||||||
assertNull(entry.getInstant());
|
assertNull(entry.getInstant());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMalformedDateHeaderIsIgnored() {
|
void testMalformedDateHeaderIsIgnored() {
|
||||||
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK,
|
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK,
|
||||||
new BasicHeader("Date", "asdf"));
|
new BasicHeader("Date", "asdf"));
|
||||||
assertNull(entry.getInstant());
|
assertNull(entry.getInstant());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValidDateHeaderIsParsed() {
|
void testValidDateHeaderIsParsed() {
|
||||||
final Instant date = Instant.now().with(ChronoField.MILLI_OF_SECOND, 0);
|
final Instant date = Instant.now().with(ChronoField.MILLI_OF_SECOND, 0);
|
||||||
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK,
|
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK,
|
||||||
new BasicHeader("Date", DateUtils.formatStandardDate(date)));
|
new BasicHeader("Date", DateUtils.formatStandardDate(date)));
|
||||||
|
@ -243,7 +243,7 @@ public class TestHttpCacheEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEpochDateHeaderIsParsed() {
|
void testEpochDateHeaderIsParsed() {
|
||||||
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK,
|
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK,
|
||||||
new BasicHeader("Date", DateUtils.formatStandardDate(Instant.EPOCH)));
|
new BasicHeader("Date", DateUtils.formatStandardDate(Instant.EPOCH)));
|
||||||
final Instant dateHeaderValue = entry.getInstant();
|
final Instant dateHeaderValue = entry.getInstant();
|
||||||
|
@ -252,7 +252,7 @@ public class TestHttpCacheEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDateParsedOnce() {
|
void testDateParsedOnce() {
|
||||||
final Instant date = Instant.now().with(ChronoField.MILLI_OF_SECOND, 0);
|
final Instant date = Instant.now().with(ChronoField.MILLI_OF_SECOND, 0);
|
||||||
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK,
|
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK,
|
||||||
new BasicHeader("Date", DateUtils.formatStandardDate(date)));
|
new BasicHeader("Date", DateUtils.formatStandardDate(date)));
|
||||||
|
@ -263,7 +263,7 @@ public class TestHttpCacheEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExpiresParsedOnce() {
|
void testExpiresParsedOnce() {
|
||||||
final Instant date = Instant.now().with(ChronoField.MILLI_OF_SECOND, 0);
|
final Instant date = Instant.now().with(ChronoField.MILLI_OF_SECOND, 0);
|
||||||
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK,
|
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK,
|
||||||
new BasicHeader("Last-Modified", DateUtils.formatStandardDate(date)));
|
new BasicHeader("Last-Modified", DateUtils.formatStandardDate(date)));
|
||||||
|
@ -278,7 +278,7 @@ public class TestHttpCacheEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsCacheEntryNewer() throws Exception {
|
void testIsCacheEntryNewer() {
|
||||||
assertFalse(HttpCacheEntry.isNewer(null, null));
|
assertFalse(HttpCacheEntry.isNewer(null, null));
|
||||||
entry = makeEntry();
|
entry = makeEntry();
|
||||||
final HeaderGroup message = new HeaderGroup();
|
final HeaderGroup message = new HeaderGroup();
|
||||||
|
|
|
@ -52,7 +52,7 @@ import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestHttpCacheEntryFactory {
|
class TestHttpCacheEntryFactory {
|
||||||
|
|
||||||
private Instant requestDate;
|
private Instant requestDate;
|
||||||
private Instant responseDate;
|
private Instant responseDate;
|
||||||
|
@ -69,7 +69,7 @@ public class TestHttpCacheEntryFactory {
|
||||||
private HttpCacheEntryFactory impl;
|
private HttpCacheEntryFactory impl;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() {
|
||||||
requestDate = Instant.now().minusSeconds(1);
|
requestDate = Instant.now().minusSeconds(1);
|
||||||
responseDate = Instant.now();
|
responseDate = Instant.now();
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ public class TestHttpCacheEntryFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFilterHopByHopAndConnectionSpecificHeaders() {
|
void testFilterHopByHopAndConnectionSpecificHeaders() {
|
||||||
response.setHeaders(
|
response.setHeaders(
|
||||||
new BasicHeader(HttpHeaders.CONNECTION, "blah, blah, this, that"),
|
new BasicHeader(HttpHeaders.CONNECTION, "blah, blah, this, that"),
|
||||||
new BasicHeader("Blah", "huh?"),
|
new BasicHeader("Blah", "huh?"),
|
||||||
|
@ -106,7 +106,7 @@ public class TestHttpCacheEntryFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHeadersAreMergedCorrectly() {
|
void testHeadersAreMergedCorrectly() {
|
||||||
entry = HttpTestUtils.makeCacheEntry(
|
entry = HttpTestUtils.makeCacheEntry(
|
||||||
new BasicHeader("Date", DateUtils.formatStandardDate(responseDate)),
|
new BasicHeader("Date", DateUtils.formatStandardDate(responseDate)),
|
||||||
new BasicHeader("ETag", "\"etag\""));
|
new BasicHeader("ETag", "\"etag\""));
|
||||||
|
@ -118,7 +118,7 @@ public class TestHttpCacheEntryFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNewerHeadersReplaceExistingHeaders() {
|
void testNewerHeadersReplaceExistingHeaders() {
|
||||||
entry = HttpTestUtils.makeCacheEntry(
|
entry = HttpTestUtils.makeCacheEntry(
|
||||||
new BasicHeader("Date", DateUtils.formatStandardDate(requestDate)),
|
new BasicHeader("Date", DateUtils.formatStandardDate(requestDate)),
|
||||||
new BasicHeader("Cache-Control", "private"),
|
new BasicHeader("Cache-Control", "private"),
|
||||||
|
@ -139,7 +139,7 @@ public class TestHttpCacheEntryFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNewHeadersAreAddedByMerge() {
|
void testNewHeadersAreAddedByMerge() {
|
||||||
entry = HttpTestUtils.makeCacheEntry(
|
entry = HttpTestUtils.makeCacheEntry(
|
||||||
new BasicHeader("Date", DateUtils.formatStandardDate(requestDate)),
|
new BasicHeader("Date", DateUtils.formatStandardDate(requestDate)),
|
||||||
new BasicHeader("ETag", "\"etag\""));
|
new BasicHeader("ETag", "\"etag\""));
|
||||||
|
@ -156,7 +156,7 @@ public class TestHttpCacheEntryFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void entryWithMalformedDateIsStillUpdated() throws Exception {
|
void entryWithMalformedDateIsStillUpdated() {
|
||||||
entry = HttpTestUtils.makeCacheEntry(tenSecondsAgo, eightSecondsAgo,
|
entry = HttpTestUtils.makeCacheEntry(tenSecondsAgo, eightSecondsAgo,
|
||||||
new BasicHeader("ETag", "\"old\""),
|
new BasicHeader("ETag", "\"old\""),
|
||||||
new BasicHeader("Date", "bad-date"));
|
new BasicHeader("Date", "bad-date"));
|
||||||
|
@ -169,7 +169,7 @@ public class TestHttpCacheEntryFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void entryIsStillUpdatedByResponseWithMalformedDate() throws Exception {
|
void entryIsStillUpdatedByResponseWithMalformedDate() {
|
||||||
entry = HttpTestUtils.makeCacheEntry(tenSecondsAgo, eightSecondsAgo,
|
entry = HttpTestUtils.makeCacheEntry(tenSecondsAgo, eightSecondsAgo,
|
||||||
new BasicHeader("ETag", "\"old\""),
|
new BasicHeader("ETag", "\"old\""),
|
||||||
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
||||||
|
@ -182,14 +182,14 @@ public class TestHttpCacheEntryFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateCacheEntryReturnsDifferentEntryInstance() {
|
void testUpdateCacheEntryReturnsDifferentEntryInstance() {
|
||||||
entry = HttpTestUtils.makeCacheEntry();
|
entry = HttpTestUtils.makeCacheEntry();
|
||||||
final HttpCacheEntry newEntry = impl.createUpdated(requestDate, responseDate, host, request, response, entry);
|
final HttpCacheEntry newEntry = impl.createUpdated(requestDate, responseDate, host, request, response, entry);
|
||||||
Assertions.assertNotSame(newEntry, entry);
|
Assertions.assertNotSame(newEntry, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateRootVariantEntry() {
|
void testCreateRootVariantEntry() {
|
||||||
request.setHeaders(
|
request.setHeaders(
|
||||||
new BasicHeader("Keep-Alive", "timeout, max=20"),
|
new BasicHeader("Keep-Alive", "timeout, max=20"),
|
||||||
new BasicHeader("X-custom", "my stuff"),
|
new BasicHeader("X-custom", "my stuff"),
|
||||||
|
@ -241,7 +241,7 @@ public class TestHttpCacheEntryFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateResourceEntry() {
|
void testCreateResourceEntry() {
|
||||||
request.setHeaders(
|
request.setHeaders(
|
||||||
new BasicHeader("Keep-Alive", "timeout, max=20"),
|
new BasicHeader("Keep-Alive", "timeout, max=20"),
|
||||||
new BasicHeader("X-custom", "my stuff"),
|
new BasicHeader("X-custom", "my stuff"),
|
||||||
|
@ -285,7 +285,7 @@ public class TestHttpCacheEntryFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateUpdatedResourceEntry() {
|
void testCreateUpdatedResourceEntry() {
|
||||||
final Resource resource = HttpTestUtils.makeRandomResource(128);
|
final Resource resource = HttpTestUtils.makeRandomResource(128);
|
||||||
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(
|
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(
|
||||||
tenSecondsAgo,
|
tenSecondsAgo,
|
||||||
|
@ -347,7 +347,7 @@ public class TestHttpCacheEntryFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateNotModifiedIfResponseOlder() {
|
void testUpdateNotModifiedIfResponseOlder() {
|
||||||
entry = HttpTestUtils.makeCacheEntry(twoSecondsAgo, now,
|
entry = HttpTestUtils.makeCacheEntry(twoSecondsAgo, now,
|
||||||
new BasicHeader("Date", DateUtils.formatStandardDate(oneSecondAgo)),
|
new BasicHeader("Date", DateUtils.formatStandardDate(oneSecondAgo)),
|
||||||
new BasicHeader("ETag", "\"new-etag\""));
|
new BasicHeader("ETag", "\"new-etag\""));
|
||||||
|
@ -360,7 +360,7 @@ public class TestHttpCacheEntryFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateHasLatestRequestAndResponseDates() {
|
void testUpdateHasLatestRequestAndResponseDates() {
|
||||||
entry = HttpTestUtils.makeCacheEntry(tenSecondsAgo, eightSecondsAgo);
|
entry = HttpTestUtils.makeCacheEntry(tenSecondsAgo, eightSecondsAgo);
|
||||||
final HttpCacheEntry updated = impl.createUpdated(twoSecondsAgo, oneSecondAgo, host, request, response, entry);
|
final HttpCacheEntry updated = impl.createUpdated(twoSecondsAgo, oneSecondAgo, host, request, response, entry);
|
||||||
|
|
||||||
|
@ -369,7 +369,7 @@ public class TestHttpCacheEntryFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cannotUpdateFromANon304OriginResponse() throws Exception {
|
void cannotUpdateFromANon304OriginResponse() {
|
||||||
entry = HttpTestUtils.makeCacheEntry();
|
entry = HttpTestUtils.makeCacheEntry();
|
||||||
response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
|
response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
|
||||||
Assertions.assertThrows(IllegalArgumentException.class, () ->
|
Assertions.assertThrows(IllegalArgumentException.class, () ->
|
||||||
|
|
|
@ -33,12 +33,12 @@ import org.apache.hc.client5.http.cache.RequestCacheControl;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class CacheControlGeneratorTest {
|
class CacheControlGeneratorTest {
|
||||||
|
|
||||||
private final CacheControlHeaderGenerator generator = CacheControlHeaderGenerator.INSTANCE;
|
private final CacheControlHeaderGenerator generator = CacheControlHeaderGenerator.INSTANCE;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGenerateRequestCacheControlHeader() {
|
void testGenerateRequestCacheControlHeader() {
|
||||||
assertThat(generator.generate(
|
assertThat(generator.generate(
|
||||||
RequestCacheControl.builder()
|
RequestCacheControl.builder()
|
||||||
.setMaxAge(12)
|
.setMaxAge(12)
|
||||||
|
@ -77,7 +77,7 @@ public class CacheControlGeneratorTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGenerateRequestCacheControlHeaderNoDirectives() {
|
void testGenerateRequestCacheControlHeaderNoDirectives() {
|
||||||
final RequestCacheControl cacheControl = RequestCacheControl.builder()
|
final RequestCacheControl cacheControl = RequestCacheControl.builder()
|
||||||
.build();
|
.build();
|
||||||
Assertions.assertNull(generator.generate(cacheControl));
|
Assertions.assertNull(generator.generate(cacheControl));
|
||||||
|
|
|
@ -40,74 +40,74 @@ import org.apache.hc.core5.http.Header;
|
||||||
import org.apache.hc.core5.http.message.BasicHeader;
|
import org.apache.hc.core5.http.message.BasicHeader;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class CacheControlParserTest {
|
class CacheControlParserTest {
|
||||||
|
|
||||||
private final CacheControlHeaderParser parser = CacheControlHeaderParser.INSTANCE;
|
private final CacheControlHeaderParser parser = CacheControlHeaderParser.INSTANCE;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseMaxAgeZero() {
|
void testParseMaxAgeZero() {
|
||||||
final Header header = new BasicHeader("Cache-Control", "max-age=0 , this = stuff;");
|
final Header header = new BasicHeader("Cache-Control", "max-age=0 , this = stuff;");
|
||||||
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
||||||
assertEquals(0L, cacheControl.getMaxAge());
|
assertEquals(0L, cacheControl.getMaxAge());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseSMaxAge() {
|
void testParseSMaxAge() {
|
||||||
final Header header = new BasicHeader("Cache-Control", "s-maxage=3600");
|
final Header header = new BasicHeader("Cache-Control", "s-maxage=3600");
|
||||||
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
||||||
assertEquals(3600L, cacheControl.getSharedMaxAge());
|
assertEquals(3600L, cacheControl.getSharedMaxAge());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseInvalidCacheValue() {
|
void testParseInvalidCacheValue() {
|
||||||
final Header header = new BasicHeader("Cache-Control", "max-age=invalid");
|
final Header header = new BasicHeader("Cache-Control", "max-age=invalid");
|
||||||
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
||||||
assertEquals(0L, cacheControl.getMaxAge());
|
assertEquals(0L, cacheControl.getMaxAge());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseInvalidHeader() {
|
void testParseInvalidHeader() {
|
||||||
final Header header = new BasicHeader("Cache-Control", "max-age");
|
final Header header = new BasicHeader("Cache-Control", "max-age");
|
||||||
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
||||||
assertEquals(-1L, cacheControl.getMaxAge());
|
assertEquals(-1L, cacheControl.getMaxAge());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseNullHeader() {
|
void testParseNullHeader() {
|
||||||
final Header header = null;
|
final Header header = null;
|
||||||
assertThrows(NullPointerException.class, () -> parser.parseResponse(Collections.singletonList(header).iterator()));
|
assertThrows(NullPointerException.class, () -> parser.parseResponse(Collections.singletonList(header).iterator()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseEmptyHeader() {
|
void testParseEmptyHeader() {
|
||||||
final Header header = new BasicHeader("Cache-Control", "");
|
final Header header = new BasicHeader("Cache-Control", "");
|
||||||
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
||||||
assertEquals(-1L, cacheControl.getMaxAge());
|
assertEquals(-1L, cacheControl.getMaxAge());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseCookieEmptyValue() {
|
void testParseCookieEmptyValue() {
|
||||||
final Header header = new BasicHeader("Cache-Control", "max-age=,");
|
final Header header = new BasicHeader("Cache-Control", "max-age=,");
|
||||||
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
||||||
assertEquals(-1L, cacheControl.getMaxAge());
|
assertEquals(-1L, cacheControl.getMaxAge());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseNoCache() {
|
void testParseNoCache() {
|
||||||
final Header header = new BasicHeader(" Cache-Control", "no-cache");
|
final Header header = new BasicHeader(" Cache-Control", "no-cache");
|
||||||
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
||||||
assertEquals(-1L, cacheControl.getMaxAge());
|
assertEquals(-1L, cacheControl.getMaxAge());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseNoDirective() {
|
void testParseNoDirective() {
|
||||||
final Header header = new BasicHeader(" Cache-Control", "");
|
final Header header = new BasicHeader(" Cache-Control", "");
|
||||||
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
||||||
assertEquals(-1L, cacheControl.getMaxAge());
|
assertEquals(-1L, cacheControl.getMaxAge());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGarbage() {
|
void testGarbage() {
|
||||||
final Header header = new BasicHeader("Cache-Control", ",,= blah,");
|
final Header header = new BasicHeader("Cache-Control", ",,= blah,");
|
||||||
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
||||||
assertEquals(-1L, cacheControl.getMaxAge());
|
assertEquals(-1L, cacheControl.getMaxAge());
|
||||||
|
@ -115,7 +115,7 @@ public class CacheControlParserTest {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseMultipleDirectives() {
|
void testParseMultipleDirectives() {
|
||||||
final Header header = new BasicHeader("Cache-Control", "max-age=604800, stale-while-revalidate=86400, s-maxage=3600, must-revalidate, private");
|
final Header header = new BasicHeader("Cache-Control", "max-age=604800, stale-while-revalidate=86400, s-maxage=3600, must-revalidate, private");
|
||||||
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ public class CacheControlParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseMultipleDirectives2() {
|
void testParseMultipleDirectives2() {
|
||||||
final Header header = new BasicHeader("Cache-Control", "max-age=604800, stale-while-revalidate=86400, must-revalidate, private, s-maxage=3600");
|
final Header header = new BasicHeader("Cache-Control", "max-age=604800, stale-while-revalidate=86400, must-revalidate, private, s-maxage=3600");
|
||||||
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ public class CacheControlParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParsePublic() {
|
void testParsePublic() {
|
||||||
final Header header = new BasicHeader("Cache-Control", "public");
|
final Header header = new BasicHeader("Cache-Control", "public");
|
||||||
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ public class CacheControlParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParsePrivate() {
|
void testParsePrivate() {
|
||||||
final Header header = new BasicHeader("Cache-Control", "private");
|
final Header header = new BasicHeader("Cache-Control", "private");
|
||||||
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ public class CacheControlParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseNoStore() {
|
void testParseNoStore() {
|
||||||
final Header header = new BasicHeader("Cache-Control", "no-store");
|
final Header header = new BasicHeader("Cache-Control", "no-store");
|
||||||
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ public class CacheControlParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseStaleWhileRevalidate() {
|
void testParseStaleWhileRevalidate() {
|
||||||
final Header header = new BasicHeader("Cache-Control", "max-age=3600, stale-while-revalidate=120");
|
final Header header = new BasicHeader("Cache-Control", "max-age=3600, stale-while-revalidate=120");
|
||||||
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ public class CacheControlParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseNoCacheFields() {
|
void testParseNoCacheFields() {
|
||||||
final Header header = new BasicHeader("Cache-Control", "no-cache=\"Set-Cookie, Content-Language\", stale-while-revalidate=120");
|
final Header header = new BasicHeader("Cache-Control", "no-cache=\"Set-Cookie, Content-Language\", stale-while-revalidate=120");
|
||||||
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ public class CacheControlParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseNoCacheFieldsNoQuote() {
|
void testParseNoCacheFieldsNoQuote() {
|
||||||
final Header header = new BasicHeader("Cache-Control", "no-cache=Set-Cookie, Content-Language, stale-while-revalidate=120");
|
final Header header = new BasicHeader("Cache-Control", "no-cache=Set-Cookie, Content-Language, stale-while-revalidate=120");
|
||||||
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
||||||
|
|
||||||
|
@ -196,7 +196,7 @@ public class CacheControlParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseNoCacheFieldsMessy() {
|
void testParseNoCacheFieldsMessy() {
|
||||||
final Header header = new BasicHeader("Cache-Control", "no-cache=\" , , ,,, Set-Cookie , , Content-Language , \", stale-while-revalidate=120");
|
final Header header = new BasicHeader("Cache-Control", "no-cache=\" , , ,,, Set-Cookie , , Content-Language , \", stale-while-revalidate=120");
|
||||||
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ public class CacheControlParserTest {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseMultipleHeaders() {
|
void testParseMultipleHeaders() {
|
||||||
// Create headers
|
// Create headers
|
||||||
final Header header1 = new BasicHeader("Cache-Control", "max-age=3600, no-store");
|
final Header header1 = new BasicHeader("Cache-Control", "max-age=3600, no-store");
|
||||||
final Header header2 = new BasicHeader("Cache-Control", "private, must-revalidate");
|
final Header header2 = new BasicHeader("Cache-Control", "private, must-revalidate");
|
||||||
|
@ -230,7 +230,7 @@ public class CacheControlParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseRequestMultipleDirectives() {
|
void testParseRequestMultipleDirectives() {
|
||||||
final Header header = new BasicHeader("Cache-Control", "blah, max-age=1111, max-stale=2222, " +
|
final Header header = new BasicHeader("Cache-Control", "blah, max-age=1111, max-stale=2222, " +
|
||||||
"min-fresh=3333, no-cache, no-store, no-cache, no-stuff, only-if-cached, only-if-cached-or-maybe-not");
|
"min-fresh=3333, no-cache, no-store, no-cache, no-stuff, only-if-cached, only-if-cached-or-maybe-not");
|
||||||
final RequestCacheControl cacheControl = parser.parseRequest(Collections.singletonList(header).iterator());
|
final RequestCacheControl cacheControl = parser.parseRequest(Collections.singletonList(header).iterator());
|
||||||
|
@ -246,14 +246,14 @@ public class CacheControlParserTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseIsImmutable() {
|
void testParseIsImmutable() {
|
||||||
final Header header = new BasicHeader("Cache-Control", "max-age=0 , immutable");
|
final Header header = new BasicHeader("Cache-Control", "max-age=0 , immutable");
|
||||||
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
||||||
assertTrue(cacheControl.isImmutable());
|
assertTrue(cacheControl.isImmutable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseMultipleIsImmutable() {
|
void testParseMultipleIsImmutable() {
|
||||||
final Header header = new BasicHeader("Cache-Control", "immutable, nmax-age=0 , immutable");
|
final Header header = new BasicHeader("Cache-Control", "immutable, nmax-age=0 , immutable");
|
||||||
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
final ResponseCacheControl cacheControl = parser.parseResponse(Collections.singletonList(header).iterator());
|
||||||
assertTrue(cacheControl.isImmutable());
|
assertTrue(cacheControl.isImmutable());
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class ConsumableInputStream extends InputStream {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int read() throws IOException {
|
public int read() {
|
||||||
return buf.read();
|
return buf.read();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,17 +44,17 @@ class SimpleHttpCacheStorage implements HttpCacheStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void putEntry(final String key, final HttpCacheEntry entry) throws ResourceIOException {
|
public void putEntry(final String key, final HttpCacheEntry entry) {
|
||||||
map.put(key, entry);
|
map.put(key, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HttpCacheEntry getEntry(final String key) throws ResourceIOException {
|
public HttpCacheEntry getEntry(final String key) {
|
||||||
return map.get(key);
|
return map.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeEntry(final String key) throws ResourceIOException {
|
public void removeEntry(final String key) {
|
||||||
map.remove(key);
|
map.remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ import org.mockito.Mockito;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
public class TestAbstractSerializingAsyncCacheStorage {
|
class TestAbstractSerializingAsyncCacheStorage {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private Cancellable cancellable;
|
private Cancellable cancellable;
|
||||||
|
@ -80,7 +80,7 @@ public class TestAbstractSerializingAsyncCacheStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCachePut() throws Exception {
|
void testCachePut() throws Exception {
|
||||||
final String key = "foo";
|
final String key = "foo";
|
||||||
final HttpCacheEntry value = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry value = HttpTestUtils.makeCacheEntry();
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ public class TestAbstractSerializingAsyncCacheStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheGetNullEntry() throws Exception {
|
void testCacheGetNullEntry() {
|
||||||
final String key = "foo";
|
final String key = "foo";
|
||||||
|
|
||||||
Mockito.when(impl.digestToStorageKey(key)).thenReturn("bar");
|
Mockito.when(impl.digestToStorageKey(key)).thenReturn("bar");
|
||||||
|
@ -121,7 +121,7 @@ public class TestAbstractSerializingAsyncCacheStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheGet() throws Exception {
|
void testCacheGet() {
|
||||||
final String key = "foo";
|
final String key = "foo";
|
||||||
final HttpCacheEntry value = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry value = HttpTestUtils.makeCacheEntry();
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ public class TestAbstractSerializingAsyncCacheStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheGetKeyMismatch() throws Exception {
|
void testCacheGetKeyMismatch() {
|
||||||
final String key = "foo";
|
final String key = "foo";
|
||||||
final HttpCacheEntry value = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry value = HttpTestUtils.makeCacheEntry();
|
||||||
Mockito.when(impl.digestToStorageKey(key)).thenReturn("bar");
|
Mockito.when(impl.digestToStorageKey(key)).thenReturn("bar");
|
||||||
|
@ -159,7 +159,7 @@ public class TestAbstractSerializingAsyncCacheStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheRemove() throws Exception{
|
void testCacheRemove() {
|
||||||
final String key = "foo";
|
final String key = "foo";
|
||||||
|
|
||||||
Mockito.when(impl.digestToStorageKey(key)).thenReturn("bar");
|
Mockito.when(impl.digestToStorageKey(key)).thenReturn("bar");
|
||||||
|
@ -177,7 +177,7 @@ public class TestAbstractSerializingAsyncCacheStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheUpdateNullEntry() throws Exception {
|
void testCacheUpdateNullEntry() {
|
||||||
final String key = "foo";
|
final String key = "foo";
|
||||||
final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry();
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ public class TestAbstractSerializingAsyncCacheStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheCASUpdate() throws Exception {
|
void testCacheCASUpdate() throws Exception {
|
||||||
final String key = "foo";
|
final String key = "foo";
|
||||||
final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry();
|
||||||
final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry();
|
||||||
|
@ -238,7 +238,7 @@ public class TestAbstractSerializingAsyncCacheStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheCASUpdateKeyMismatch() throws Exception {
|
void testCacheCASUpdateKeyMismatch() throws Exception {
|
||||||
final String key = "foo";
|
final String key = "foo";
|
||||||
final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry();
|
||||||
final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry();
|
||||||
|
@ -274,7 +274,7 @@ public class TestAbstractSerializingAsyncCacheStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSingleCacheUpdateRetry() throws Exception {
|
void testSingleCacheUpdateRetry() throws Exception {
|
||||||
final String key = "foo";
|
final String key = "foo";
|
||||||
final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry();
|
||||||
final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry();
|
||||||
|
@ -312,7 +312,7 @@ public class TestAbstractSerializingAsyncCacheStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheUpdateFail() throws Exception {
|
void testCacheUpdateFail() throws Exception {
|
||||||
final String key = "foo";
|
final String key = "foo";
|
||||||
final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry();
|
||||||
final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry();
|
||||||
|
@ -351,7 +351,7 @@ public class TestAbstractSerializingAsyncCacheStorage {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testBulkGet() throws Exception {
|
void testBulkGet() {
|
||||||
final String key1 = "foo this";
|
final String key1 = "foo this";
|
||||||
final String key2 = "foo that";
|
final String key2 = "foo that";
|
||||||
final String storageKey1 = "bar this";
|
final String storageKey1 = "bar this";
|
||||||
|
@ -396,7 +396,7 @@ public class TestAbstractSerializingAsyncCacheStorage {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testBulkGetKeyMismatch() throws Exception {
|
void testBulkGetKeyMismatch() {
|
||||||
final String key1 = "foo this";
|
final String key1 = "foo this";
|
||||||
final String key2 = "foo that";
|
final String key2 = "foo that";
|
||||||
final String storageKey1 = "bar this";
|
final String storageKey1 = "bar this";
|
||||||
|
|
|
@ -51,7 +51,7 @@ import org.mockito.Mockito;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
@SuppressWarnings("boxing") // test code
|
@SuppressWarnings("boxing") // test code
|
||||||
public class TestAbstractSerializingCacheStorage {
|
class TestAbstractSerializingCacheStorage {
|
||||||
|
|
||||||
public static byte[] serialize(final String key, final HttpCacheEntry value) throws ResourceIOException {
|
public static byte[] serialize(final String key, final HttpCacheEntry value) throws ResourceIOException {
|
||||||
return HttpByteArrayCacheEntrySerializer.INSTANCE.serialize(new HttpCacheStorageEntry(key, value));
|
return HttpByteArrayCacheEntrySerializer.INSTANCE.serialize(new HttpCacheStorageEntry(key, value));
|
||||||
|
@ -67,7 +67,7 @@ public class TestAbstractSerializingCacheStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCachePut() throws Exception {
|
void testCachePut() throws Exception {
|
||||||
final String key = "foo";
|
final String key = "foo";
|
||||||
final HttpCacheEntry value = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry value = HttpTestUtils.makeCacheEntry();
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ public class TestAbstractSerializingCacheStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheGetNullEntry() throws Exception {
|
void testCacheGetNullEntry() throws Exception {
|
||||||
final String key = "foo";
|
final String key = "foo";
|
||||||
|
|
||||||
when(impl.digestToStorageKey(key)).thenReturn("bar");
|
when(impl.digestToStorageKey(key)).thenReturn("bar");
|
||||||
|
@ -95,7 +95,7 @@ public class TestAbstractSerializingCacheStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheGet() throws Exception {
|
void testCacheGet() throws Exception {
|
||||||
final String key = "foo";
|
final String key = "foo";
|
||||||
final HttpCacheEntry value = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry value = HttpTestUtils.makeCacheEntry();
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ public class TestAbstractSerializingCacheStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheGetKeyMismatch() throws Exception {
|
void testCacheGetKeyMismatch() throws Exception {
|
||||||
final String key = "foo";
|
final String key = "foo";
|
||||||
final HttpCacheEntry value = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry value = HttpTestUtils.makeCacheEntry();
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ public class TestAbstractSerializingCacheStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheRemove() throws Exception{
|
void testCacheRemove() throws Exception{
|
||||||
final String key = "foo";
|
final String key = "foo";
|
||||||
|
|
||||||
when(impl.digestToStorageKey(key)).thenReturn("bar");
|
when(impl.digestToStorageKey(key)).thenReturn("bar");
|
||||||
|
@ -135,7 +135,7 @@ public class TestAbstractSerializingCacheStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheUpdateNullEntry() throws Exception {
|
void testCacheUpdateNullEntry() throws Exception {
|
||||||
final String key = "foo";
|
final String key = "foo";
|
||||||
final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry();
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ public class TestAbstractSerializingCacheStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheCASUpdate() throws Exception {
|
void testCacheCASUpdate() throws Exception {
|
||||||
final String key = "foo";
|
final String key = "foo";
|
||||||
final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry();
|
||||||
final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry();
|
||||||
|
@ -170,7 +170,7 @@ public class TestAbstractSerializingCacheStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheCASUpdateKeyMismatch() throws Exception {
|
void testCacheCASUpdateKeyMismatch() throws Exception {
|
||||||
final String key = "foo";
|
final String key = "foo";
|
||||||
final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry();
|
||||||
final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry();
|
||||||
|
@ -191,7 +191,7 @@ public class TestAbstractSerializingCacheStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSingleCacheUpdateRetry() throws Exception {
|
void testSingleCacheUpdateRetry() throws Exception {
|
||||||
final String key = "foo";
|
final String key = "foo";
|
||||||
final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry();
|
||||||
final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry();
|
||||||
|
@ -209,7 +209,7 @@ public class TestAbstractSerializingCacheStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheUpdateFail() throws Exception {
|
void testCacheUpdateFail() throws Exception {
|
||||||
final String key = "foo";
|
final String key = "foo";
|
||||||
final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry existingValue = HttpTestUtils.makeCacheEntry();
|
||||||
final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry updatedValue = HttpTestUtils.makeCacheEntry();
|
||||||
|
@ -228,7 +228,7 @@ public class TestAbstractSerializingCacheStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBulkGet() throws Exception {
|
void testBulkGet() throws Exception {
|
||||||
final String key1 = "foo this";
|
final String key1 = "foo this";
|
||||||
final String key2 = "foo that";
|
final String key2 = "foo that";
|
||||||
final String storageKey1 = "bar this";
|
final String storageKey1 = "bar this";
|
||||||
|
@ -262,7 +262,7 @@ public class TestAbstractSerializingCacheStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBulkGetKeyMismatch() throws Exception {
|
void testBulkGetKeyMismatch() throws Exception {
|
||||||
final String key1 = "foo this";
|
final String key1 = "foo this";
|
||||||
final String key2 = "foo that";
|
final String key2 = "foo that";
|
||||||
final String storageKey1 = "bar this";
|
final String storageKey1 = "bar this";
|
||||||
|
|
|
@ -64,7 +64,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
public class TestBasicHttpAsyncCache {
|
class TestBasicHttpAsyncCache {
|
||||||
|
|
||||||
private HttpHost host;
|
private HttpHost host;
|
||||||
private Instant now;
|
private Instant now;
|
||||||
|
@ -73,7 +73,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
private BasicHttpAsyncCache impl;
|
private BasicHttpAsyncCache impl;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
host = new HttpHost("foo.example.com");
|
host = new HttpHost("foo.example.com");
|
||||||
now = Instant.now();
|
now = Instant.now();
|
||||||
tenSecondsAgo = now.minusSeconds(10);
|
tenSecondsAgo = now.minusSeconds(10);
|
||||||
|
@ -82,7 +82,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCacheEntryReturnsNullOnCacheMiss() throws Exception {
|
void testGetCacheEntryReturnsNullOnCacheMiss() throws Exception {
|
||||||
final HttpHost host = new HttpHost("foo.example.com");
|
final HttpHost host = new HttpHost("foo.example.com");
|
||||||
final HttpRequest request = new HttpGet("http://foo.example.com/bar");
|
final HttpRequest request = new HttpGet("http://foo.example.com/bar");
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCacheEntryFetchesFromCacheOnCacheHitIfNoVariants() throws Exception {
|
void testGetCacheEntryFetchesFromCacheOnCacheHitIfNoVariants() throws Exception {
|
||||||
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry();
|
||||||
assertFalse(entry.hasVariants());
|
assertFalse(entry.hasVariants());
|
||||||
final HttpHost host = new HttpHost("foo.example.com");
|
final HttpHost host = new HttpHost("foo.example.com");
|
||||||
|
@ -121,7 +121,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCacheEntryReturnsNullIfNoVariantInCache() throws Exception {
|
void testGetCacheEntryReturnsNullIfNoVariantInCache() throws Exception {
|
||||||
final HttpRequest origRequest = new HttpGet("http://foo.example.com/bar");
|
final HttpRequest origRequest = new HttpGet("http://foo.example.com/bar");
|
||||||
origRequest.setHeader("Accept-Encoding","gzip");
|
origRequest.setHeader("Accept-Encoding","gzip");
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCacheEntryReturnsVariantIfPresentInCache() throws Exception {
|
void testGetCacheEntryReturnsVariantIfPresentInCache() throws Exception {
|
||||||
final HttpRequest origRequest = new HttpGet("http://foo.example.com/bar");
|
final HttpRequest origRequest = new HttpGet("http://foo.example.com/bar");
|
||||||
origRequest.setHeader("Accept-Encoding","gzip");
|
origRequest.setHeader("Accept-Encoding","gzip");
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCacheEntryReturnsVariantWithMostRecentDateHeader() throws Exception {
|
void testGetCacheEntryReturnsVariantWithMostRecentDateHeader() throws Exception {
|
||||||
final HttpRequest origRequest = new HttpGet("http://foo.example.com/bar");
|
final HttpRequest origRequest = new HttpGet("http://foo.example.com/bar");
|
||||||
origRequest.setHeader("Accept-Encoding", "gzip");
|
origRequest.setHeader("Accept-Encoding", "gzip");
|
||||||
|
|
||||||
|
@ -237,7 +237,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetVariantsRootNoVariants() throws Exception {
|
void testGetVariantsRootNoVariants() throws Exception {
|
||||||
final HttpCacheEntry root = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry root = HttpTestUtils.makeCacheEntry();
|
||||||
|
|
||||||
final CountDownLatch latch1 = new CountDownLatch(1);
|
final CountDownLatch latch1 = new CountDownLatch(1);
|
||||||
|
@ -252,7 +252,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetVariantsRootNonExistentVariants() throws Exception {
|
void testGetVariantsRootNonExistentVariants() throws Exception {
|
||||||
final Set<String> varinats = new HashSet<>();
|
final Set<String> varinats = new HashSet<>();
|
||||||
varinats.add("variant1");
|
varinats.add("variant1");
|
||||||
varinats.add("variant2");
|
varinats.add("variant2");
|
||||||
|
@ -270,7 +270,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetVariantCacheEntriesReturnsAllVariants() throws Exception {
|
void testGetVariantCacheEntriesReturnsAllVariants() throws Exception {
|
||||||
final HttpHost host = new HttpHost("foo.example.com");
|
final HttpHost host = new HttpHost("foo.example.com");
|
||||||
final URI uri = new URI("http://foo.example.com/bar");
|
final URI uri = new URI("http://foo.example.com/bar");
|
||||||
final HttpRequest req1 = new HttpGet(uri);
|
final HttpRequest req1 = new HttpGet(uri);
|
||||||
|
@ -332,7 +332,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateCacheEntry() throws Exception {
|
void testUpdateCacheEntry() throws Exception {
|
||||||
final HttpHost host = new HttpHost("foo.example.com");
|
final HttpHost host = new HttpHost("foo.example.com");
|
||||||
final URI uri = new URI("http://foo.example.com/bar");
|
final URI uri = new URI("http://foo.example.com/bar");
|
||||||
final HttpRequest req1 = new HttpGet(uri);
|
final HttpRequest req1 = new HttpGet(uri);
|
||||||
|
@ -386,7 +386,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateVariantCacheEntry() throws Exception {
|
void testUpdateVariantCacheEntry() throws Exception {
|
||||||
final HttpHost host = new HttpHost("foo.example.com");
|
final HttpHost host = new HttpHost("foo.example.com");
|
||||||
final URI uri = new URI("http://foo.example.com/bar");
|
final URI uri = new URI("http://foo.example.com/bar");
|
||||||
final HttpRequest req1 = new HttpGet(uri);
|
final HttpRequest req1 = new HttpGet(uri);
|
||||||
|
@ -443,7 +443,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateCacheEntryTurnsVariant() throws Exception {
|
void testUpdateCacheEntryTurnsVariant() throws Exception {
|
||||||
final HttpHost host = new HttpHost("foo.example.com");
|
final HttpHost host = new HttpHost("foo.example.com");
|
||||||
final URI uri = new URI("http://foo.example.com/bar");
|
final URI uri = new URI("http://foo.example.com/bar");
|
||||||
final HttpRequest req1 = new HttpGet(uri);
|
final HttpRequest req1 = new HttpGet(uri);
|
||||||
|
@ -498,7 +498,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStoreFromNegotiatedVariant() throws Exception {
|
void testStoreFromNegotiatedVariant() throws Exception {
|
||||||
final HttpHost host = new HttpHost("foo.example.com");
|
final HttpHost host = new HttpHost("foo.example.com");
|
||||||
final URI uri = new URI("http://foo.example.com/bar");
|
final URI uri = new URI("http://foo.example.com/bar");
|
||||||
final HttpRequest req1 = new HttpGet(uri);
|
final HttpRequest req1 = new HttpGet(uri);
|
||||||
|
@ -552,7 +552,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidatesUnsafeRequests() throws Exception {
|
void testInvalidatesUnsafeRequests() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("POST", "/path");
|
final HttpRequest request = new BasicHttpRequest("POST", "/path");
|
||||||
final HttpResponse response = HttpTestUtils.make200Response();
|
final HttpResponse response = HttpTestUtils.make200Response();
|
||||||
|
|
||||||
|
@ -571,7 +571,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotInvalidateSafeRequests() throws Exception {
|
void testDoesNotInvalidateSafeRequests() throws Exception {
|
||||||
final HttpRequest request1 = new BasicHttpRequest("GET", "/");
|
final HttpRequest request1 = new BasicHttpRequest("GET", "/");
|
||||||
final HttpResponse response1 = HttpTestUtils.make200Response();
|
final HttpResponse response1 = HttpTestUtils.make200Response();
|
||||||
final CountDownLatch latch1 = new CountDownLatch(1);
|
final CountDownLatch latch1 = new CountDownLatch(1);
|
||||||
|
@ -594,7 +594,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidatesUnsafeRequestsWithVariants() throws Exception {
|
void testInvalidatesUnsafeRequestsWithVariants() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("POST", "/path");
|
final HttpRequest request = new BasicHttpRequest("POST", "/path");
|
||||||
final String rootKey = CacheKeyGenerator.INSTANCE.generateKey(host, request);
|
final String rootKey = CacheKeyGenerator.INSTANCE.generateKey(host, request);
|
||||||
final Set<String> variants = new HashSet<>();
|
final Set<String> variants = new HashSet<>();
|
||||||
|
@ -625,7 +625,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidateUriSpecifiedByContentLocationAndFresher() throws Exception {
|
void testInvalidateUriSpecifiedByContentLocationAndFresher() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
||||||
final String rootKey = CacheKeyGenerator.INSTANCE.generateKey(host, request);
|
final String rootKey = CacheKeyGenerator.INSTANCE.generateKey(host, request);
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
|
@ -657,7 +657,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidateUriSpecifiedByLocationAndFresher() throws Exception {
|
void testInvalidateUriSpecifiedByLocationAndFresher() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
||||||
final String rootKey = CacheKeyGenerator.INSTANCE.generateKey(host, request);
|
final String rootKey = CacheKeyGenerator.INSTANCE.generateKey(host, request);
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
|
@ -689,7 +689,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotInvalidateForUnsuccessfulResponse() throws Exception {
|
void testDoesNotInvalidateForUnsuccessfulResponse() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
.setHttpHost(host)
|
.setHttpHost(host)
|
||||||
|
@ -709,7 +709,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidateUriSpecifiedByContentLocationNonCanonical() throws Exception {
|
void testInvalidateUriSpecifiedByContentLocationNonCanonical() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
||||||
final String rootKey = CacheKeyGenerator.INSTANCE.generateKey(host, request);
|
final String rootKey = CacheKeyGenerator.INSTANCE.generateKey(host, request);
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
|
@ -744,7 +744,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidateUriSpecifiedByContentLocationRelative() throws Exception {
|
void testInvalidateUriSpecifiedByContentLocationRelative() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
||||||
final String rootKey = CacheKeyGenerator.INSTANCE.generateKey(host, request);
|
final String rootKey = CacheKeyGenerator.INSTANCE.generateKey(host, request);
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
|
@ -779,7 +779,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotInvalidateUriSpecifiedByContentLocationOtherOrigin() throws Exception {
|
void testDoesNotInvalidateUriSpecifiedByContentLocationOtherOrigin() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/");
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
.setHost("bar.example.com")
|
.setHost("bar.example.com")
|
||||||
|
@ -804,7 +804,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotInvalidateUriSpecifiedByContentLocationIfEtagsMatch() throws Exception {
|
void testDoesNotInvalidateUriSpecifiedByContentLocationIfEtagsMatch() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
.setHttpHost(host)
|
.setHttpHost(host)
|
||||||
|
@ -831,7 +831,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotInvalidateUriSpecifiedByContentLocationIfOlder() throws Exception {
|
void testDoesNotInvalidateUriSpecifiedByContentLocationIfOlder() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
.setHttpHost(host)
|
.setHttpHost(host)
|
||||||
|
@ -858,7 +858,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotInvalidateUriSpecifiedByContentLocationIfResponseHasNoEtag() throws Exception {
|
void testDoesNotInvalidateUriSpecifiedByContentLocationIfResponseHasNoEtag() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
.setHttpHost(host)
|
.setHttpHost(host)
|
||||||
|
@ -885,7 +885,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotInvalidateUriSpecifiedByContentLocationIfEntryHasNoEtag() throws Exception {
|
void testDoesNotInvalidateUriSpecifiedByContentLocationIfEntryHasNoEtag() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
.setHttpHost(host)
|
.setHttpHost(host)
|
||||||
|
@ -911,7 +911,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidatesUriSpecifiedByContentLocationIfResponseHasNoDate() throws Exception {
|
void testInvalidatesUriSpecifiedByContentLocationIfResponseHasNoDate() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
.setHttpHost(host)
|
.setHttpHost(host)
|
||||||
|
@ -938,7 +938,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidatesUriSpecifiedByContentLocationIfEntryHasNoDate() throws Exception {
|
void testInvalidatesUriSpecifiedByContentLocationIfEntryHasNoDate() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
.setHttpHost(host)
|
.setHttpHost(host)
|
||||||
|
@ -964,7 +964,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidatesUriSpecifiedByContentLocationIfResponseHasMalformedDate() throws Exception {
|
void testInvalidatesUriSpecifiedByContentLocationIfResponseHasMalformedDate() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
.setHttpHost(host)
|
.setHttpHost(host)
|
||||||
|
@ -991,7 +991,7 @@ public class TestBasicHttpAsyncCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidatesUriSpecifiedByContentLocationIfEntryHasMalformedDate() throws Exception {
|
void testInvalidatesUriSpecifiedByContentLocationIfEntryHasMalformedDate() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
.setHttpHost(host)
|
.setHttpHost(host)
|
||||||
|
|
|
@ -63,7 +63,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
public class TestBasicHttpCache {
|
class TestBasicHttpCache {
|
||||||
|
|
||||||
private HttpHost host;
|
private HttpHost host;
|
||||||
private Instant now;
|
private Instant now;
|
||||||
|
@ -72,7 +72,7 @@ public class TestBasicHttpCache {
|
||||||
private BasicHttpCache impl;
|
private BasicHttpCache impl;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() {
|
||||||
host = new HttpHost("foo.example.com");
|
host = new HttpHost("foo.example.com");
|
||||||
now = Instant.now();
|
now = Instant.now();
|
||||||
tenSecondsAgo = now.minusSeconds(10);
|
tenSecondsAgo = now.minusSeconds(10);
|
||||||
|
@ -81,7 +81,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCacheEntryReturnsNullOnCacheMiss() throws Exception {
|
void testGetCacheEntryReturnsNullOnCacheMiss() {
|
||||||
final HttpHost host = new HttpHost("foo.example.com");
|
final HttpHost host = new HttpHost("foo.example.com");
|
||||||
final HttpRequest request = new HttpGet("http://foo.example.com/bar");
|
final HttpRequest request = new HttpGet("http://foo.example.com/bar");
|
||||||
final CacheMatch result = impl.match(host, request);
|
final CacheMatch result = impl.match(host, request);
|
||||||
|
@ -89,7 +89,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCacheEntryFetchesFromCacheOnCacheHitIfNoVariants() throws Exception {
|
void testGetCacheEntryFetchesFromCacheOnCacheHitIfNoVariants() {
|
||||||
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry();
|
||||||
assertFalse(entry.hasVariants());
|
assertFalse(entry.hasVariants());
|
||||||
final HttpHost host = new HttpHost("foo.example.com");
|
final HttpHost host = new HttpHost("foo.example.com");
|
||||||
|
@ -106,7 +106,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCacheEntryReturnsNullIfNoVariantInCache() throws Exception {
|
void testGetCacheEntryReturnsNullIfNoVariantInCache() {
|
||||||
final HttpRequest origRequest = new HttpGet("http://foo.example.com/bar");
|
final HttpRequest origRequest = new HttpGet("http://foo.example.com/bar");
|
||||||
origRequest.setHeader("Accept-Encoding","gzip");
|
origRequest.setHeader("Accept-Encoding","gzip");
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCacheEntryReturnsVariantIfPresentInCache() throws Exception {
|
void testGetCacheEntryReturnsVariantIfPresentInCache() {
|
||||||
final HttpRequest origRequest = new HttpGet("http://foo.example.com/bar");
|
final HttpRequest origRequest = new HttpGet("http://foo.example.com/bar");
|
||||||
origRequest.setHeader("Accept-Encoding","gzip");
|
origRequest.setHeader("Accept-Encoding","gzip");
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCacheEntryReturnsVariantWithMostRecentDateHeader() throws Exception {
|
void testGetCacheEntryReturnsVariantWithMostRecentDateHeader() {
|
||||||
final HttpRequest origRequest = new HttpGet("http://foo.example.com/bar");
|
final HttpRequest origRequest = new HttpGet("http://foo.example.com/bar");
|
||||||
origRequest.setHeader("Accept-Encoding", "gzip");
|
origRequest.setHeader("Accept-Encoding", "gzip");
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetVariantsRootNoVariants() throws Exception {
|
void testGetVariantsRootNoVariants() {
|
||||||
final HttpCacheEntry root = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry root = HttpTestUtils.makeCacheEntry();
|
||||||
final List<CacheHit> variants = impl.getVariants(new CacheHit("root-key", root));
|
final List<CacheHit> variants = impl.getVariants(new CacheHit("root-key", root));
|
||||||
|
|
||||||
|
@ -198,7 +198,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetVariantsRootNonExistentVariants() throws Exception {
|
void testGetVariantsRootNonExistentVariants() {
|
||||||
final Set<String> varinats = new HashSet<>();
|
final Set<String> varinats = new HashSet<>();
|
||||||
varinats.add("variant1");
|
varinats.add("variant1");
|
||||||
varinats.add("variant2");
|
varinats.add("variant2");
|
||||||
|
@ -210,7 +210,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetVariantCacheEntriesReturnsAllVariants() throws Exception {
|
void testGetVariantCacheEntriesReturnsAllVariants() throws Exception {
|
||||||
final HttpHost host = new HttpHost("foo.example.com");
|
final HttpHost host = new HttpHost("foo.example.com");
|
||||||
final URI uri = new URI("http://foo.example.com/bar");
|
final URI uri = new URI("http://foo.example.com/bar");
|
||||||
final HttpRequest req1 = new HttpGet(uri);
|
final HttpRequest req1 = new HttpGet(uri);
|
||||||
|
@ -255,7 +255,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateCacheEntry() throws Exception {
|
void testUpdateCacheEntry() throws Exception {
|
||||||
final HttpHost host = new HttpHost("foo.example.com");
|
final HttpHost host = new HttpHost("foo.example.com");
|
||||||
final URI uri = new URI("http://foo.example.com/bar");
|
final URI uri = new URI("http://foo.example.com/bar");
|
||||||
final HttpRequest req1 = new HttpGet(uri);
|
final HttpRequest req1 = new HttpGet(uri);
|
||||||
|
@ -295,7 +295,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateVariantCacheEntry() throws Exception {
|
void testUpdateVariantCacheEntry() throws Exception {
|
||||||
final HttpHost host = new HttpHost("foo.example.com");
|
final HttpHost host = new HttpHost("foo.example.com");
|
||||||
final URI uri = new URI("http://foo.example.com/bar");
|
final URI uri = new URI("http://foo.example.com/bar");
|
||||||
final HttpRequest req1 = new HttpGet(uri);
|
final HttpRequest req1 = new HttpGet(uri);
|
||||||
|
@ -338,7 +338,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateCacheEntryTurnsVariant() throws Exception {
|
void testUpdateCacheEntryTurnsVariant() throws Exception {
|
||||||
final HttpHost host = new HttpHost("foo.example.com");
|
final HttpHost host = new HttpHost("foo.example.com");
|
||||||
final URI uri = new URI("http://foo.example.com/bar");
|
final URI uri = new URI("http://foo.example.com/bar");
|
||||||
final HttpRequest req1 = new HttpGet(uri);
|
final HttpRequest req1 = new HttpGet(uri);
|
||||||
|
@ -379,7 +379,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStoreFromNegotiatedVariant() throws Exception {
|
void testStoreFromNegotiatedVariant() throws Exception {
|
||||||
final HttpHost host = new HttpHost("foo.example.com");
|
final HttpHost host = new HttpHost("foo.example.com");
|
||||||
final URI uri = new URI("http://foo.example.com/bar");
|
final URI uri = new URI("http://foo.example.com/bar");
|
||||||
final HttpRequest req1 = new HttpGet(uri);
|
final HttpRequest req1 = new HttpGet(uri);
|
||||||
|
@ -420,7 +420,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidatesUnsafeRequests() throws Exception {
|
void testInvalidatesUnsafeRequests() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("POST","/path");
|
final HttpRequest request = new BasicHttpRequest("POST","/path");
|
||||||
final String key = CacheKeyGenerator.INSTANCE.generateKey(host, request);
|
final String key = CacheKeyGenerator.INSTANCE.generateKey(host, request);
|
||||||
|
|
||||||
|
@ -437,7 +437,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotInvalidateSafeRequests() throws Exception {
|
void testDoesNotInvalidateSafeRequests() {
|
||||||
final HttpRequest request1 = new BasicHttpRequest("GET","/");
|
final HttpRequest request1 = new BasicHttpRequest("GET","/");
|
||||||
final HttpResponse response1 = HttpTestUtils.make200Response();
|
final HttpResponse response1 = HttpTestUtils.make200Response();
|
||||||
|
|
||||||
|
@ -453,7 +453,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidatesUnsafeRequestsWithVariants() throws Exception {
|
void testInvalidatesUnsafeRequestsWithVariants() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("POST","/path");
|
final HttpRequest request = new BasicHttpRequest("POST","/path");
|
||||||
final String rootKey = CacheKeyGenerator.INSTANCE.generateKey(host, request);
|
final String rootKey = CacheKeyGenerator.INSTANCE.generateKey(host, request);
|
||||||
final Set<String> variants = new HashSet<>();
|
final Set<String> variants = new HashSet<>();
|
||||||
|
@ -481,7 +481,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidateUriSpecifiedByContentLocationAndFresher() throws Exception {
|
void testInvalidateUriSpecifiedByContentLocationAndFresher() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
||||||
final String rootKey = CacheKeyGenerator.INSTANCE.generateKey(host, request);
|
final String rootKey = CacheKeyGenerator.INSTANCE.generateKey(host, request);
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
|
@ -510,7 +510,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidateUriSpecifiedByLocationAndFresher() throws Exception {
|
void testInvalidateUriSpecifiedByLocationAndFresher() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
||||||
final String rootKey = CacheKeyGenerator.INSTANCE.generateKey(host, request);
|
final String rootKey = CacheKeyGenerator.INSTANCE.generateKey(host, request);
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
|
@ -539,7 +539,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotInvalidateForUnsuccessfulResponse() throws Exception {
|
void testDoesNotInvalidateForUnsuccessfulResponse() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
.setHttpHost(host)
|
.setHttpHost(host)
|
||||||
|
@ -556,7 +556,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidateUriSpecifiedByContentLocationNonCanonical() throws Exception {
|
void testInvalidateUriSpecifiedByContentLocationNonCanonical() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
||||||
final String rootKey = CacheKeyGenerator.INSTANCE.generateKey(host, request);
|
final String rootKey = CacheKeyGenerator.INSTANCE.generateKey(host, request);
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
|
@ -588,7 +588,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidateUriSpecifiedByContentLocationRelative() throws Exception {
|
void testInvalidateUriSpecifiedByContentLocationRelative() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
||||||
final String rootKey = CacheKeyGenerator.INSTANCE.generateKey(host, request);
|
final String rootKey = CacheKeyGenerator.INSTANCE.generateKey(host, request);
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
|
@ -620,7 +620,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotInvalidateUriSpecifiedByContentLocationOtherOrigin() throws Exception {
|
void testDoesNotInvalidateUriSpecifiedByContentLocationOtherOrigin() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/");
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
.setHost("bar.example.com")
|
.setHost("bar.example.com")
|
||||||
|
@ -642,7 +642,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotInvalidateUriSpecifiedByContentLocationIfEtagsMatch() throws Exception {
|
void testDoesNotInvalidateUriSpecifiedByContentLocationIfEtagsMatch() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
.setHttpHost(host)
|
.setHttpHost(host)
|
||||||
|
@ -666,7 +666,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotInvalidateUriSpecifiedByContentLocationIfOlder() throws Exception {
|
void testDoesNotInvalidateUriSpecifiedByContentLocationIfOlder() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
.setHttpHost(host)
|
.setHttpHost(host)
|
||||||
|
@ -690,7 +690,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotInvalidateUriSpecifiedByContentLocationIfResponseHasNoEtag() throws Exception {
|
void testDoesNotInvalidateUriSpecifiedByContentLocationIfResponseHasNoEtag() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
.setHttpHost(host)
|
.setHttpHost(host)
|
||||||
|
@ -714,7 +714,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotInvalidateUriSpecifiedByContentLocationIfEntryHasNoEtag() throws Exception {
|
void testDoesNotInvalidateUriSpecifiedByContentLocationIfEntryHasNoEtag() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
.setHttpHost(host)
|
.setHttpHost(host)
|
||||||
|
@ -737,7 +737,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidatesUriSpecifiedByContentLocationIfResponseHasNoDate() throws Exception {
|
void testInvalidatesUriSpecifiedByContentLocationIfResponseHasNoDate() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
.setHttpHost(host)
|
.setHttpHost(host)
|
||||||
|
@ -761,7 +761,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidatesUriSpecifiedByContentLocationIfEntryHasNoDate() throws Exception {
|
void testInvalidatesUriSpecifiedByContentLocationIfEntryHasNoDate() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
.setHttpHost(host)
|
.setHttpHost(host)
|
||||||
|
@ -784,7 +784,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidatesUriSpecifiedByContentLocationIfResponseHasMalformedDate() throws Exception {
|
void testInvalidatesUriSpecifiedByContentLocationIfResponseHasMalformedDate() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
.setHttpHost(host)
|
.setHttpHost(host)
|
||||||
|
@ -808,7 +808,7 @@ public class TestBasicHttpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidatesUriSpecifiedByContentLocationIfEntryHasMalformedDate() throws Exception {
|
void testInvalidatesUriSpecifiedByContentLocationIfEntryHasMalformedDate() throws Exception {
|
||||||
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
final HttpRequest request = new BasicHttpRequest("PUT", "/foo");
|
||||||
final URI contentUri = new URIBuilder()
|
final URI contentUri = new URIBuilder()
|
||||||
.setHttpHost(host)
|
.setHttpHost(host)
|
||||||
|
|
|
@ -52,192 +52,192 @@ import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public class TestByteArrayCacheEntrySerializer {
|
class TestByteArrayCacheEntrySerializer {
|
||||||
|
|
||||||
private ByteArrayCacheEntrySerializer impl;
|
private ByteArrayCacheEntrySerializer impl;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
impl = new ByteArrayCacheEntrySerializer();
|
impl = new ByteArrayCacheEntrySerializer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canSerializeEntriesWithVariantMapsDeprecatedConstructor() throws Exception {
|
void canSerializeEntriesWithVariantMapsDeprecatedConstructor() throws Exception {
|
||||||
readWriteVerify(makeCacheEntryDeprecatedConstructorWithVariantMap("somekey"));
|
readWriteVerify(makeCacheEntryDeprecatedConstructorWithVariantMap("somekey"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canSerializeEntriesWithVariantMapsAndInstant() throws Exception {
|
void canSerializeEntriesWithVariantMapsAndInstant() throws Exception {
|
||||||
readWriteVerify(makeCacheEntryWithVariantMap("somekey"));
|
readWriteVerify(makeCacheEntryWithVariantMap("somekey"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameStringTrue() {
|
void isAllowedClassNameStringTrue() {
|
||||||
assertIsAllowedClassNameTrue(String.class.getName());
|
assertIsAllowedClassNameTrue(String.class.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameStringArrayTrue() {
|
void isAllowedClassNameStringArrayTrue() {
|
||||||
assertIsAllowedClassNameTrue("[L" + String.class.getName());
|
assertIsAllowedClassNameTrue("[L" + String.class.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameStringArrayArrayTrue() {
|
void isAllowedClassNameStringArrayArrayTrue() {
|
||||||
assertIsAllowedClassNameTrue("[[L" + String.class.getName());
|
assertIsAllowedClassNameTrue("[[L" + String.class.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameDataTrue() {
|
void isAllowedClassNameDataTrue() {
|
||||||
assertIsAllowedClassNameTrue(Date.class.getName());
|
assertIsAllowedClassNameTrue(Date.class.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameInstantTrue() {
|
void isAllowedClassNameInstantTrue() {
|
||||||
assertIsAllowedClassNameTrue(Instant.class.getName());
|
assertIsAllowedClassNameTrue(Instant.class.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameStatusLineTrue() {
|
void isAllowedClassNameStatusLineTrue() {
|
||||||
assertIsAllowedClassNameTrue(StatusLine.class.getName());
|
assertIsAllowedClassNameTrue(StatusLine.class.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameResourceTrue() {
|
void isAllowedClassNameResourceTrue() {
|
||||||
assertIsAllowedClassNameTrue(Resource.class.getName());
|
assertIsAllowedClassNameTrue(Resource.class.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameByteArrayTrue() {
|
void isAllowedClassNameByteArrayTrue() {
|
||||||
assertIsAllowedClassNameTrue("[B");
|
assertIsAllowedClassNameTrue("[B");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameByteArrayArrayTrue() {
|
void isAllowedClassNameByteArrayArrayTrue() {
|
||||||
assertIsAllowedClassNameTrue("[[B");
|
assertIsAllowedClassNameTrue("[[B");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameCharArrayTrue() {
|
void isAllowedClassNameCharArrayTrue() {
|
||||||
assertIsAllowedClassNameTrue("[C");
|
assertIsAllowedClassNameTrue("[C");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameCharArrayArrayTrue() {
|
void isAllowedClassNameCharArrayArrayTrue() {
|
||||||
assertIsAllowedClassNameTrue("[[C");
|
assertIsAllowedClassNameTrue("[[C");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameDoubleArrayTrue() {
|
void isAllowedClassNameDoubleArrayTrue() {
|
||||||
assertIsAllowedClassNameTrue("[D");
|
assertIsAllowedClassNameTrue("[D");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameDoubleArrayArrayTrue() {
|
void isAllowedClassNameDoubleArrayArrayTrue() {
|
||||||
assertIsAllowedClassNameTrue("[[D");
|
assertIsAllowedClassNameTrue("[[D");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameFloatArrayTrue() {
|
void isAllowedClassNameFloatArrayTrue() {
|
||||||
assertIsAllowedClassNameTrue("[F");
|
assertIsAllowedClassNameTrue("[F");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameFloatArrayArrayTrue() {
|
void isAllowedClassNameFloatArrayArrayTrue() {
|
||||||
assertIsAllowedClassNameTrue("[[F");
|
assertIsAllowedClassNameTrue("[[F");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameIntArrayTrue() {
|
void isAllowedClassNameIntArrayTrue() {
|
||||||
assertIsAllowedClassNameTrue("[I");
|
assertIsAllowedClassNameTrue("[I");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameIntArrayArrayTrue() {
|
void isAllowedClassNameIntArrayArrayTrue() {
|
||||||
assertIsAllowedClassNameTrue("[[I");
|
assertIsAllowedClassNameTrue("[[I");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameLongArrayTrue() {
|
void isAllowedClassNameLongArrayTrue() {
|
||||||
assertIsAllowedClassNameTrue("[J");
|
assertIsAllowedClassNameTrue("[J");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameLongArrayArrayTrue() {
|
void isAllowedClassNameLongArrayArrayTrue() {
|
||||||
assertIsAllowedClassNameTrue("[[J");
|
assertIsAllowedClassNameTrue("[[J");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameShortArrayTrue() {
|
void isAllowedClassNameShortArrayTrue() {
|
||||||
assertIsAllowedClassNameTrue("[S");
|
assertIsAllowedClassNameTrue("[S");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameShortArrayArrayTrue() {
|
void isAllowedClassNameShortArrayArrayTrue() {
|
||||||
assertIsAllowedClassNameTrue("[[S");
|
assertIsAllowedClassNameTrue("[[S");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameCollectionsInvokerTransformerFalse() {
|
void isAllowedClassNameCollectionsInvokerTransformerFalse() {
|
||||||
assertIsAllowedClassNameFalse("org.apache.commons.collections.functors.InvokerTransformer");
|
assertIsAllowedClassNameFalse("org.apache.commons.collections.functors.InvokerTransformer");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameCollections4InvokerTransformerFalse() {
|
void isAllowedClassNameCollections4InvokerTransformerFalse() {
|
||||||
assertIsAllowedClassNameFalse("org.apache.commons.collections4.functors.InvokerTransformer");
|
assertIsAllowedClassNameFalse("org.apache.commons.collections4.functors.InvokerTransformer");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameCollectionsInstantiateTransformerFalse() {
|
void isAllowedClassNameCollectionsInstantiateTransformerFalse() {
|
||||||
assertIsAllowedClassNameFalse("org.apache.commons.collections.functors.InstantiateTransformer");
|
assertIsAllowedClassNameFalse("org.apache.commons.collections.functors.InstantiateTransformer");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameCollections4InstantiateTransformerFalse() {
|
void isAllowedClassNameCollections4InstantiateTransformerFalse() {
|
||||||
assertIsAllowedClassNameFalse("org.apache.commons.collections4.functors.InstantiateTransformer");
|
assertIsAllowedClassNameFalse("org.apache.commons.collections4.functors.InstantiateTransformer");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameGroovyConvertedClosureFalse() {
|
void isAllowedClassNameGroovyConvertedClosureFalse() {
|
||||||
assertIsAllowedClassNameFalse("org.codehaus.groovy.runtime.ConvertedClosure");
|
assertIsAllowedClassNameFalse("org.codehaus.groovy.runtime.ConvertedClosure");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameGroovyMethodClosureFalse() {
|
void isAllowedClassNameGroovyMethodClosureFalse() {
|
||||||
assertIsAllowedClassNameFalse("org.codehaus.groovy.runtime.MethodClosure");
|
assertIsAllowedClassNameFalse("org.codehaus.groovy.runtime.MethodClosure");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameSpringObjectFactoryFalse() {
|
void isAllowedClassNameSpringObjectFactoryFalse() {
|
||||||
assertIsAllowedClassNameFalse("org.springframework.beans.factory.ObjectFactory");
|
assertIsAllowedClassNameFalse("org.springframework.beans.factory.ObjectFactory");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameCalanTemplatesImplFalse() {
|
void isAllowedClassNameCalanTemplatesImplFalse() {
|
||||||
assertIsAllowedClassNameFalse("com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl");
|
assertIsAllowedClassNameFalse("com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameCalanTemplatesImplArrayFalse() {
|
void isAllowedClassNameCalanTemplatesImplArrayFalse() {
|
||||||
assertIsAllowedClassNameFalse("[Lcom.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl");
|
assertIsAllowedClassNameFalse("[Lcom.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameJavaRmiRegistryFalse() {
|
void isAllowedClassNameJavaRmiRegistryFalse() {
|
||||||
assertIsAllowedClassNameFalse("java.rmi.registry.Registry");
|
assertIsAllowedClassNameFalse("java.rmi.registry.Registry");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameJavaRmiServerRemoteObjectInvocationHandlerFalse() {
|
void isAllowedClassNameJavaRmiServerRemoteObjectInvocationHandlerFalse() {
|
||||||
assertIsAllowedClassNameFalse("java.rmi.server.RemoteObjectInvocationHandler");
|
assertIsAllowedClassNameFalse("java.rmi.server.RemoteObjectInvocationHandler");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameJavaxXmlTransformTemplatesFalse() {
|
void isAllowedClassNameJavaxXmlTransformTemplatesFalse() {
|
||||||
assertIsAllowedClassNameFalse("javax.xml.transform.Templates");
|
assertIsAllowedClassNameFalse("javax.xml.transform.Templates");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAllowedClassNameJavaxManagementMBeanServerInvocationHandlerFalse() {
|
void isAllowedClassNameJavaxManagementMBeanServerInvocationHandlerFalse() {
|
||||||
assertIsAllowedClassNameFalse("javax.management.MBeanServerInvocationHandler");
|
assertIsAllowedClassNameFalse("javax.management.MBeanServerInvocationHandler");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,17 +49,17 @@ import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@SuppressWarnings({"boxing","static-access"}) // this is test code
|
@SuppressWarnings({"boxing","static-access"}) // this is test code
|
||||||
public class TestCacheKeyGenerator {
|
class TestCacheKeyGenerator {
|
||||||
|
|
||||||
private CacheKeyGenerator extractor;
|
private CacheKeyGenerator extractor;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() {
|
||||||
extractor = CacheKeyGenerator.INSTANCE;
|
extractor = CacheKeyGenerator.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetRequestUri() {
|
void testGetRequestUri() {
|
||||||
Assertions.assertEquals("http://foo.example.com/stuff?huh",
|
Assertions.assertEquals("http://foo.example.com/stuff?huh",
|
||||||
CacheKeyGenerator.getRequestUri(
|
CacheKeyGenerator.getRequestUri(
|
||||||
new HttpHost("bar.example.com"),
|
new HttpHost("bar.example.com"),
|
||||||
|
@ -92,7 +92,7 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNormalizeRequestUri() throws URISyntaxException {
|
void testNormalizeRequestUri() throws URISyntaxException {
|
||||||
Assertions.assertEquals(URI.create("http://bar.example.com:80/stuff?huh"),
|
Assertions.assertEquals(URI.create("http://bar.example.com:80/stuff?huh"),
|
||||||
CacheKeyGenerator.normalize(URI.create("//bar.example.com/stuff?huh")));
|
CacheKeyGenerator.normalize(URI.create("//bar.example.com/stuff?huh")));
|
||||||
|
|
||||||
|
@ -107,14 +107,14 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExtractsUriFromAbsoluteUriInRequest() {
|
void testExtractsUriFromAbsoluteUriInRequest() {
|
||||||
final HttpHost host = new HttpHost("bar.example.com");
|
final HttpHost host = new HttpHost("bar.example.com");
|
||||||
final HttpRequest req = new HttpGet("http://foo.example.com/");
|
final HttpRequest req = new HttpGet("http://foo.example.com/");
|
||||||
Assertions.assertEquals("http://foo.example.com:80/", extractor.generateKey(host, req));
|
Assertions.assertEquals("http://foo.example.com:80/", extractor.generateKey(host, req));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetURIWithDefaultPortAndScheme() {
|
void testGetURIWithDefaultPortAndScheme() {
|
||||||
Assertions.assertEquals("http://www.comcast.net:80/", extractor.generateKey(
|
Assertions.assertEquals("http://www.comcast.net:80/", extractor.generateKey(
|
||||||
new HttpHost("www.comcast.net"),
|
new HttpHost("www.comcast.net"),
|
||||||
new BasicHttpRequest("GET", "/")));
|
new BasicHttpRequest("GET", "/")));
|
||||||
|
@ -125,7 +125,7 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetURIWithDifferentScheme() {
|
void testGetURIWithDifferentScheme() {
|
||||||
Assertions.assertEquals("https://www.comcast.net:443/", extractor.generateKey(
|
Assertions.assertEquals("https://www.comcast.net:443/", extractor.generateKey(
|
||||||
new HttpHost("https", "www.comcast.net", -1),
|
new HttpHost("https", "www.comcast.net", -1),
|
||||||
new BasicHttpRequest("GET", "/")));
|
new BasicHttpRequest("GET", "/")));
|
||||||
|
@ -136,7 +136,7 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetURIWithDifferentPort() {
|
void testGetURIWithDifferentPort() {
|
||||||
Assertions.assertEquals("http://www.comcast.net:8080/", extractor.generateKey(
|
Assertions.assertEquals("http://www.comcast.net:8080/", extractor.generateKey(
|
||||||
new HttpHost("www.comcast.net", 8080),
|
new HttpHost("www.comcast.net", 8080),
|
||||||
new BasicHttpRequest("GET", "/")));
|
new BasicHttpRequest("GET", "/")));
|
||||||
|
@ -147,7 +147,7 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetURIWithDifferentPortAndScheme() {
|
void testGetURIWithDifferentPortAndScheme() {
|
||||||
Assertions.assertEquals("https://www.comcast.net:8080/", extractor.generateKey(
|
Assertions.assertEquals("https://www.comcast.net:8080/", extractor.generateKey(
|
||||||
new HttpHost("https", "www.comcast.net", 8080),
|
new HttpHost("https", "www.comcast.net", 8080),
|
||||||
new BasicHttpRequest("GET", "/")));
|
new BasicHttpRequest("GET", "/")));
|
||||||
|
@ -158,7 +158,7 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyPortEquivalentToDefaultPortForHttp() {
|
void testEmptyPortEquivalentToDefaultPortForHttp() {
|
||||||
final HttpHost host1 = new HttpHost("foo.example.com:");
|
final HttpHost host1 = new HttpHost("foo.example.com:");
|
||||||
final HttpHost host2 = new HttpHost("foo.example.com:80");
|
final HttpHost host2 = new HttpHost("foo.example.com:80");
|
||||||
final HttpRequest req = new BasicHttpRequest("GET", "/");
|
final HttpRequest req = new BasicHttpRequest("GET", "/");
|
||||||
|
@ -166,7 +166,7 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyPortEquivalentToDefaultPortForHttps() {
|
void testEmptyPortEquivalentToDefaultPortForHttps() {
|
||||||
final HttpHost host1 = new HttpHost("https", "foo.example.com", -1);
|
final HttpHost host1 = new HttpHost("https", "foo.example.com", -1);
|
||||||
final HttpHost host2 = new HttpHost("https", "foo.example.com", 443);
|
final HttpHost host2 = new HttpHost("https", "foo.example.com", 443);
|
||||||
final HttpRequest req = new BasicHttpRequest("GET", "/");
|
final HttpRequest req = new BasicHttpRequest("GET", "/");
|
||||||
|
@ -176,7 +176,7 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyPortEquivalentToDefaultPortForHttpsAbsoluteURI() {
|
void testEmptyPortEquivalentToDefaultPortForHttpsAbsoluteURI() {
|
||||||
final HttpHost host = new HttpHost("https", "foo.example.com", -1);
|
final HttpHost host = new HttpHost("https", "foo.example.com", -1);
|
||||||
final HttpGet get1 = new HttpGet("https://bar.example.com:/");
|
final HttpGet get1 = new HttpGet("https://bar.example.com:/");
|
||||||
final HttpGet get2 = new HttpGet("https://bar.example.com:443/");
|
final HttpGet get2 = new HttpGet("https://bar.example.com:443/");
|
||||||
|
@ -186,7 +186,7 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotProvidedPortEquivalentToDefaultPortForHttpsAbsoluteURI() {
|
void testNotProvidedPortEquivalentToDefaultPortForHttpsAbsoluteURI() {
|
||||||
final HttpHost host = new HttpHost("https", "foo.example.com", -1);
|
final HttpHost host = new HttpHost("https", "foo.example.com", -1);
|
||||||
final HttpGet get1 = new HttpGet("https://bar.example.com/");
|
final HttpGet get1 = new HttpGet("https://bar.example.com/");
|
||||||
final HttpGet get2 = new HttpGet("https://bar.example.com:443/");
|
final HttpGet get2 = new HttpGet("https://bar.example.com:443/");
|
||||||
|
@ -196,7 +196,7 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotProvidedPortEquivalentToDefaultPortForHttp() {
|
void testNotProvidedPortEquivalentToDefaultPortForHttp() {
|
||||||
final HttpHost host1 = new HttpHost("foo.example.com");
|
final HttpHost host1 = new HttpHost("foo.example.com");
|
||||||
final HttpHost host2 = new HttpHost("foo.example.com:80");
|
final HttpHost host2 = new HttpHost("foo.example.com:80");
|
||||||
final HttpRequest req = new BasicHttpRequest("GET", "/");
|
final HttpRequest req = new BasicHttpRequest("GET", "/");
|
||||||
|
@ -204,7 +204,7 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHostNameComparisonsAreCaseInsensitive() {
|
void testHostNameComparisonsAreCaseInsensitive() {
|
||||||
final HttpHost host1 = new HttpHost("foo.example.com");
|
final HttpHost host1 = new HttpHost("foo.example.com");
|
||||||
final HttpHost host2 = new HttpHost("FOO.EXAMPLE.COM");
|
final HttpHost host2 = new HttpHost("FOO.EXAMPLE.COM");
|
||||||
final HttpRequest req = new BasicHttpRequest("GET", "/");
|
final HttpRequest req = new BasicHttpRequest("GET", "/");
|
||||||
|
@ -212,7 +212,7 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSchemeNameComparisonsAreCaseInsensitive() {
|
void testSchemeNameComparisonsAreCaseInsensitive() {
|
||||||
final HttpHost host1 = new HttpHost("http", "foo.example.com", -1);
|
final HttpHost host1 = new HttpHost("http", "foo.example.com", -1);
|
||||||
final HttpHost host2 = new HttpHost("HTTP", "foo.example.com", -1);
|
final HttpHost host2 = new HttpHost("HTTP", "foo.example.com", -1);
|
||||||
final HttpRequest req = new BasicHttpRequest("GET", "/");
|
final HttpRequest req = new BasicHttpRequest("GET", "/");
|
||||||
|
@ -220,7 +220,7 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyAbsPathIsEquivalentToSlash() {
|
void testEmptyAbsPathIsEquivalentToSlash() {
|
||||||
final HttpHost host = new HttpHost("foo.example.com");
|
final HttpHost host = new HttpHost("foo.example.com");
|
||||||
final HttpRequest req1 = new BasicHttpRequest("GET", "/");
|
final HttpRequest req1 = new BasicHttpRequest("GET", "/");
|
||||||
final HttpRequest req2 = new HttpGet("http://foo.example.com");
|
final HttpRequest req2 = new HttpGet("http://foo.example.com");
|
||||||
|
@ -228,7 +228,7 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExtraDotSegmentsAreIgnored() {
|
void testExtraDotSegmentsAreIgnored() {
|
||||||
final HttpHost host = new HttpHost("foo.example.com");
|
final HttpHost host = new HttpHost("foo.example.com");
|
||||||
final HttpRequest req1 = new BasicHttpRequest("GET", "/");
|
final HttpRequest req1 = new BasicHttpRequest("GET", "/");
|
||||||
final HttpRequest req2 = new HttpGet("http://foo.example.com/./");
|
final HttpRequest req2 = new HttpGet("http://foo.example.com/./");
|
||||||
|
@ -236,7 +236,7 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExtraDotDotSegmentsAreIgnored() {
|
void testExtraDotDotSegmentsAreIgnored() {
|
||||||
final HttpHost host = new HttpHost("foo.example.com");
|
final HttpHost host = new HttpHost("foo.example.com");
|
||||||
final HttpRequest req1 = new BasicHttpRequest("GET", "/");
|
final HttpRequest req1 = new BasicHttpRequest("GET", "/");
|
||||||
final HttpRequest req2 = new HttpGet("http://foo.example.com/.././../");
|
final HttpRequest req2 = new HttpGet("http://foo.example.com/.././../");
|
||||||
|
@ -244,7 +244,7 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIntermidateDotDotSegementsAreEquivalent() {
|
void testIntermidateDotDotSegementsAreEquivalent() {
|
||||||
final HttpHost host = new HttpHost("foo.example.com");
|
final HttpHost host = new HttpHost("foo.example.com");
|
||||||
final HttpRequest req1 = new BasicHttpRequest("GET", "/home.html");
|
final HttpRequest req1 = new BasicHttpRequest("GET", "/home.html");
|
||||||
final HttpRequest req2 = new BasicHttpRequest("GET", "/%7Esmith/../home.html");
|
final HttpRequest req2 = new BasicHttpRequest("GET", "/%7Esmith/../home.html");
|
||||||
|
@ -252,7 +252,7 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIntermidateEncodedDotDotSegementsAreEquivalent() {
|
void testIntermidateEncodedDotDotSegementsAreEquivalent() {
|
||||||
final HttpHost host = new HttpHost("foo.example.com");
|
final HttpHost host = new HttpHost("foo.example.com");
|
||||||
final HttpRequest req1 = new BasicHttpRequest("GET", "/home.html");
|
final HttpRequest req1 = new BasicHttpRequest("GET", "/home.html");
|
||||||
final HttpRequest req2 = new BasicHttpRequest("GET", "/%7Esmith/../home.html");
|
final HttpRequest req2 = new BasicHttpRequest("GET", "/%7Esmith/../home.html");
|
||||||
|
@ -260,7 +260,7 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIntermidateDotSegementsAreEquivalent() {
|
void testIntermidateDotSegementsAreEquivalent() {
|
||||||
final HttpHost host = new HttpHost("foo.example.com");
|
final HttpHost host = new HttpHost("foo.example.com");
|
||||||
final HttpRequest req1 = new BasicHttpRequest("GET", "/~smith/home.html");
|
final HttpRequest req1 = new BasicHttpRequest("GET", "/~smith/home.html");
|
||||||
final HttpRequest req2 = new BasicHttpRequest("GET", "/%7Esmith/./home.html");
|
final HttpRequest req2 = new BasicHttpRequest("GET", "/%7Esmith/./home.html");
|
||||||
|
@ -268,7 +268,7 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEquivalentPathEncodingsAreEquivalent() {
|
void testEquivalentPathEncodingsAreEquivalent() {
|
||||||
final HttpHost host = new HttpHost("foo.example.com");
|
final HttpHost host = new HttpHost("foo.example.com");
|
||||||
final HttpRequest req1 = new BasicHttpRequest("GET", "/~smith/home.html");
|
final HttpRequest req1 = new BasicHttpRequest("GET", "/~smith/home.html");
|
||||||
final HttpRequest req2 = new BasicHttpRequest("GET", "/%7Esmith/home.html");
|
final HttpRequest req2 = new BasicHttpRequest("GET", "/%7Esmith/home.html");
|
||||||
|
@ -276,7 +276,7 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEquivalentExtraPathEncodingsAreEquivalent() {
|
void testEquivalentExtraPathEncodingsAreEquivalent() {
|
||||||
final HttpHost host = new HttpHost("foo.example.com");
|
final HttpHost host = new HttpHost("foo.example.com");
|
||||||
final HttpRequest req1 = new BasicHttpRequest("GET", "/~smith/home.html");
|
final HttpRequest req1 = new BasicHttpRequest("GET", "/~smith/home.html");
|
||||||
final HttpRequest req2 = new BasicHttpRequest("GET", "/%7Esmith/home.html");
|
final HttpRequest req2 = new BasicHttpRequest("GET", "/%7Esmith/home.html");
|
||||||
|
@ -284,7 +284,7 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEquivalentExtraPathEncodingsWithPercentAreEquivalent() {
|
void testEquivalentExtraPathEncodingsWithPercentAreEquivalent() {
|
||||||
final HttpHost host = new HttpHost("foo.example.com");
|
final HttpHost host = new HttpHost("foo.example.com");
|
||||||
final HttpRequest req1 = new BasicHttpRequest("GET", "/~smith/home%20folder.html");
|
final HttpRequest req1 = new BasicHttpRequest("GET", "/~smith/home%20folder.html");
|
||||||
final HttpRequest req2 = new BasicHttpRequest("GET", "/%7Esmith/home%20folder.html");
|
final HttpRequest req2 = new BasicHttpRequest("GET", "/%7Esmith/home%20folder.html");
|
||||||
|
@ -292,7 +292,7 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetURIWithQueryParameters() {
|
void testGetURIWithQueryParameters() {
|
||||||
Assertions.assertEquals("http://www.comcast.net:80/?foo=bar", extractor.generateKey(
|
Assertions.assertEquals("http://www.comcast.net:80/?foo=bar", extractor.generateKey(
|
||||||
new HttpHost("http", "www.comcast.net", -1), new BasicHttpRequest("GET", "/?foo=bar")));
|
new HttpHost("http", "www.comcast.net", -1), new BasicHttpRequest("GET", "/?foo=bar")));
|
||||||
Assertions.assertEquals("http://www.fancast.com:80/full_episodes?foo=bar", extractor.generateKey(
|
Assertions.assertEquals("http://www.fancast.com:80/full_episodes?foo=bar", extractor.generateKey(
|
||||||
|
@ -305,7 +305,7 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNormalizeHeaderElements() {
|
void testNormalizeHeaderElements() {
|
||||||
final List<String> tokens = new ArrayList<>();
|
final List<String> tokens = new ArrayList<>();
|
||||||
CacheKeyGenerator.normalizeElements(headers(
|
CacheKeyGenerator.normalizeElements(headers(
|
||||||
new BasicHeader("Accept-Encoding", "gzip,zip,deflate")
|
new BasicHeader("Accept-Encoding", "gzip,zip,deflate")
|
||||||
|
@ -336,7 +336,7 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetVariantKey() {
|
void testGetVariantKey() {
|
||||||
final HttpRequest request = BasicRequestBuilder.get("/blah")
|
final HttpRequest request = BasicRequestBuilder.get("/blah")
|
||||||
.addHeader(HttpHeaders.USER_AGENT, "some-agent")
|
.addHeader(HttpHeaders.USER_AGENT, "some-agent")
|
||||||
.addHeader(HttpHeaders.ACCEPT_ENCODING, "gzip,zip")
|
.addHeader(HttpHeaders.ACCEPT_ENCODING, "gzip,zip")
|
||||||
|
@ -352,7 +352,7 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetVariantKeyInputNormalization() {
|
void testGetVariantKeyInputNormalization() {
|
||||||
final HttpRequest request = BasicRequestBuilder.get("/blah")
|
final HttpRequest request = BasicRequestBuilder.get("/blah")
|
||||||
.addHeader(HttpHeaders.USER_AGENT, "Some-Agent")
|
.addHeader(HttpHeaders.USER_AGENT, "Some-Agent")
|
||||||
.addHeader(HttpHeaders.ACCEPT_ENCODING, "gzip, ZIP,,")
|
.addHeader(HttpHeaders.ACCEPT_ENCODING, "gzip, ZIP,,")
|
||||||
|
@ -370,7 +370,7 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetVariantKeyInputNormalizationReservedChars() {
|
void testGetVariantKeyInputNormalizationReservedChars() {
|
||||||
final HttpRequest request = BasicRequestBuilder.get("/blah")
|
final HttpRequest request = BasicRequestBuilder.get("/blah")
|
||||||
.addHeader(HttpHeaders.USER_AGENT, "*===some-agent===*")
|
.addHeader(HttpHeaders.USER_AGENT, "*===some-agent===*")
|
||||||
.build();
|
.build();
|
||||||
|
@ -380,7 +380,7 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetVariantKeyInputNoMatchingHeaders() {
|
void testGetVariantKeyInputNoMatchingHeaders() {
|
||||||
final HttpRequest request = BasicRequestBuilder.get("/blah")
|
final HttpRequest request = BasicRequestBuilder.get("/blah")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
@ -389,7 +389,7 @@ public class TestCacheKeyGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetVariantKeyFromCachedResponse() {
|
void testGetVariantKeyFromCachedResponse() {
|
||||||
final HttpRequest request = BasicRequestBuilder.get("/blah")
|
final HttpRequest request = BasicRequestBuilder.get("/blah")
|
||||||
.addHeader("User-Agent", "agent1")
|
.addHeader("User-Agent", "agent1")
|
||||||
.addHeader("Accept-Encoding", "text/plain")
|
.addHeader("Accept-Encoding", "text/plain")
|
||||||
|
|
|
@ -42,7 +42,7 @@ import org.mockito.ArgumentMatchers;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
public class TestCacheRevalidatorBase {
|
class TestCacheRevalidatorBase {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private SchedulingStrategy mockSchedulingStrategy;
|
private SchedulingStrategy mockSchedulingStrategy;
|
||||||
|
@ -55,13 +55,13 @@ public class TestCacheRevalidatorBase {
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
MockitoAnnotations.openMocks(this);
|
MockitoAnnotations.openMocks(this);
|
||||||
impl = new CacheRevalidatorBase(mockScheduledExecutor, mockSchedulingStrategy);
|
impl = new CacheRevalidatorBase(mockScheduledExecutor, mockSchedulingStrategy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRevalidateCacheEntrySchedulesExecutionAndPopulatesIdentifier() {
|
void testRevalidateCacheEntrySchedulesExecutionAndPopulatesIdentifier() {
|
||||||
when(mockSchedulingStrategy.schedule(ArgumentMatchers.anyInt())).thenReturn(TimeValue.ofSeconds(1));
|
when(mockSchedulingStrategy.schedule(ArgumentMatchers.anyInt())).thenReturn(TimeValue.ofSeconds(1));
|
||||||
|
|
||||||
final String cacheKey = "blah";
|
final String cacheKey = "blah";
|
||||||
|
@ -74,7 +74,7 @@ public class TestCacheRevalidatorBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMarkCompleteRemovesIdentifier() {
|
void testMarkCompleteRemovesIdentifier() {
|
||||||
when(mockSchedulingStrategy.schedule(ArgumentMatchers.anyInt())).thenReturn(TimeValue.ofSeconds(3));
|
when(mockSchedulingStrategy.schedule(ArgumentMatchers.anyInt())).thenReturn(TimeValue.ofSeconds(3));
|
||||||
|
|
||||||
final String cacheKey = "blah";
|
final String cacheKey = "blah";
|
||||||
|
@ -92,7 +92,7 @@ public class TestCacheRevalidatorBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRevalidateCacheEntryDoesNotPopulateIdentifierOnRejectedExecutionException() {
|
void testRevalidateCacheEntryDoesNotPopulateIdentifierOnRejectedExecutionException() {
|
||||||
when(mockSchedulingStrategy.schedule(ArgumentMatchers.anyInt())).thenReturn(TimeValue.ofSeconds(2));
|
when(mockSchedulingStrategy.schedule(ArgumentMatchers.anyInt())).thenReturn(TimeValue.ofSeconds(2));
|
||||||
doThrow(new RejectedExecutionException()).when(mockScheduledExecutor).schedule(ArgumentMatchers.any(), ArgumentMatchers.any());
|
doThrow(new RejectedExecutionException()).when(mockScheduledExecutor).schedule(ArgumentMatchers.any(), ArgumentMatchers.any());
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ public class TestCacheRevalidatorBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRevalidateCacheEntryProperlyCollapsesRequest() {
|
void testRevalidateCacheEntryProperlyCollapsesRequest() {
|
||||||
when(mockSchedulingStrategy.schedule(ArgumentMatchers.anyInt())).thenReturn(TimeValue.ofSeconds(2));
|
when(mockSchedulingStrategy.schedule(ArgumentMatchers.anyInt())).thenReturn(TimeValue.ofSeconds(2));
|
||||||
|
|
||||||
final String cacheKey = "blah";
|
final String cacheKey = "blah";
|
||||||
|
@ -119,7 +119,7 @@ public class TestCacheRevalidatorBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testShutdown() throws Exception {
|
void testShutdown() throws Exception {
|
||||||
impl.close();
|
impl.close();
|
||||||
impl.awaitTermination(Timeout.ofMinutes(2));
|
impl.awaitTermination(Timeout.ofMinutes(2));
|
||||||
|
|
||||||
|
|
|
@ -33,10 +33,10 @@ import org.junit.jupiter.api.Test;
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link CacheSupport}.
|
* Unit tests for {@link CacheSupport}.
|
||||||
*/
|
*/
|
||||||
public class TestCacheSupport {
|
class TestCacheSupport {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseDeltaSeconds() throws Exception {
|
void testParseDeltaSeconds() {
|
||||||
Assertions.assertEquals(1234L, CacheSupport.deltaSeconds("1234"));
|
Assertions.assertEquals(1234L, CacheSupport.deltaSeconds("1234"));
|
||||||
Assertions.assertEquals(0L, CacheSupport.deltaSeconds("0"));
|
Assertions.assertEquals(0L, CacheSupport.deltaSeconds("0"));
|
||||||
Assertions.assertEquals(-1L, CacheSupport.deltaSeconds("-1"));
|
Assertions.assertEquals(-1L, CacheSupport.deltaSeconds("-1"));
|
||||||
|
|
|
@ -41,7 +41,7 @@ import org.apache.hc.core5.util.TimeValue;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestCacheValidityPolicy {
|
class TestCacheValidityPolicy {
|
||||||
|
|
||||||
private CacheValidityPolicy impl;
|
private CacheValidityPolicy impl;
|
||||||
private Instant now;
|
private Instant now;
|
||||||
|
@ -51,7 +51,7 @@ public class TestCacheValidityPolicy {
|
||||||
private Instant elevenSecondsAgo;
|
private Instant elevenSecondsAgo;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
impl = new CacheValidityPolicy();
|
impl = new CacheValidityPolicy();
|
||||||
now = Instant.now();
|
now = Instant.now();
|
||||||
oneSecondAgo = now.minusSeconds(1);
|
oneSecondAgo = now.minusSeconds(1);
|
||||||
|
@ -61,7 +61,7 @@ public class TestCacheValidityPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testApparentAgeIsMaxIntIfDateHeaderNotPresent() {
|
void testApparentAgeIsMaxIntIfDateHeaderNotPresent() {
|
||||||
final Header[] headers = {
|
final Header[] headers = {
|
||||||
new BasicHeader("Server", "MockServer/1.0")
|
new BasicHeader("Server", "MockServer/1.0")
|
||||||
};
|
};
|
||||||
|
@ -70,7 +70,7 @@ public class TestCacheValidityPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testApparentAgeIsResponseReceivedTimeLessDateHeader() {
|
void testApparentAgeIsResponseReceivedTimeLessDateHeader() {
|
||||||
final Header[] headers = new Header[] { new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)) };
|
final Header[] headers = new Header[] { new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)) };
|
||||||
|
|
||||||
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(now, sixSecondsAgo, headers);
|
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(now, sixSecondsAgo, headers);
|
||||||
|
@ -78,14 +78,14 @@ public class TestCacheValidityPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNegativeApparentAgeIsBroughtUpToZero() {
|
void testNegativeApparentAgeIsBroughtUpToZero() {
|
||||||
final Header[] headers = new Header[] { new BasicHeader("Date", DateUtils.formatStandardDate(sixSecondsAgo)) };
|
final Header[] headers = new Header[] { new BasicHeader("Date", DateUtils.formatStandardDate(sixSecondsAgo)) };
|
||||||
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(now, tenSecondsAgo, headers);
|
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(now, tenSecondsAgo, headers);
|
||||||
assertEquals(TimeValue.ofSeconds(0), impl.getApparentAge(entry));
|
assertEquals(TimeValue.ofSeconds(0), impl.getApparentAge(entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCorrectedReceivedAgeIsAgeHeaderIfLarger() {
|
void testCorrectedReceivedAgeIsAgeHeaderIfLarger() {
|
||||||
final Header[] headers = new Header[] { new BasicHeader("Age", "10"), };
|
final Header[] headers = new Header[] { new BasicHeader("Age", "10"), };
|
||||||
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(headers);
|
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(headers);
|
||||||
impl = new CacheValidityPolicy() {
|
impl = new CacheValidityPolicy() {
|
||||||
|
@ -98,20 +98,20 @@ public class TestCacheValidityPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCorrectedAgeValue() {
|
void testGetCorrectedAgeValue() {
|
||||||
final Header[] headers = new Header[] { new BasicHeader("Age", "6"), };
|
final Header[] headers = new Header[] { new BasicHeader("Age", "6"), };
|
||||||
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(headers);
|
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(headers);
|
||||||
assertEquals(TimeValue.ofSeconds(6), impl.getCorrectedAgeValue(entry));
|
assertEquals(TimeValue.ofSeconds(6), impl.getCorrectedAgeValue(entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponseDelayIsDifferenceBetweenResponseAndRequestTimes() {
|
void testResponseDelayIsDifferenceBetweenResponseAndRequestTimes() {
|
||||||
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(tenSecondsAgo, sixSecondsAgo);
|
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(tenSecondsAgo, sixSecondsAgo);
|
||||||
assertEquals(TimeValue.ofSeconds(4), impl.getResponseDelay(entry));
|
assertEquals(TimeValue.ofSeconds(4), impl.getResponseDelay(entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCorrectedInitialAgeIsCorrectedReceivedAgePlusResponseDelay() {
|
void testCorrectedInitialAgeIsCorrectedReceivedAgePlusResponseDelay() {
|
||||||
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry();
|
||||||
impl = new CacheValidityPolicy() {
|
impl = new CacheValidityPolicy() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -128,13 +128,13 @@ public class TestCacheValidityPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResidentTimeSecondsIsTimeSinceResponseTime() {
|
void testResidentTimeSecondsIsTimeSinceResponseTime() {
|
||||||
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(now, sixSecondsAgo);
|
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(now, sixSecondsAgo);
|
||||||
assertEquals(TimeValue.ofSeconds(6), impl.getResidentTime(entry, now));
|
assertEquals(TimeValue.ofSeconds(6), impl.getResidentTime(entry, now));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCurrentAgeIsCorrectedInitialAgePlusResidentTime() {
|
void testCurrentAgeIsCorrectedInitialAgePlusResidentTime() {
|
||||||
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry();
|
||||||
impl = new CacheValidityPolicy() {
|
impl = new CacheValidityPolicy() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -150,7 +150,7 @@ public class TestCacheValidityPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFreshnessLifetimeIsSMaxAgeIfPresent() {
|
void testFreshnessLifetimeIsSMaxAgeIfPresent() {
|
||||||
final ResponseCacheControl cacheControl = ResponseCacheControl.builder()
|
final ResponseCacheControl cacheControl = ResponseCacheControl.builder()
|
||||||
.setSharedMaxAge(10)
|
.setSharedMaxAge(10)
|
||||||
.setMaxAge(5)
|
.setMaxAge(5)
|
||||||
|
@ -160,7 +160,7 @@ public class TestCacheValidityPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSMaxAgeIsIgnoredWhenNotShared() {
|
void testSMaxAgeIsIgnoredWhenNotShared() {
|
||||||
final CacheConfig cacheConfig = CacheConfig.custom()
|
final CacheConfig cacheConfig = CacheConfig.custom()
|
||||||
.setSharedCache(false)
|
.setSharedCache(false)
|
||||||
.build();
|
.build();
|
||||||
|
@ -174,7 +174,7 @@ public class TestCacheValidityPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFreshnessLifetimeIsMaxAgeIfPresent() {
|
void testFreshnessLifetimeIsMaxAgeIfPresent() {
|
||||||
final ResponseCacheControl cacheControl = ResponseCacheControl.builder()
|
final ResponseCacheControl cacheControl = ResponseCacheControl.builder()
|
||||||
.setMaxAge(10)
|
.setMaxAge(10)
|
||||||
.build();
|
.build();
|
||||||
|
@ -183,7 +183,7 @@ public class TestCacheValidityPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFreshnessLifetimeUsesSharedMaxAgeInSharedCache() {
|
void testFreshnessLifetimeUsesSharedMaxAgeInSharedCache() {
|
||||||
// assuming impl represents a shared cache
|
// assuming impl represents a shared cache
|
||||||
final ResponseCacheControl cacheControl = ResponseCacheControl.builder()
|
final ResponseCacheControl cacheControl = ResponseCacheControl.builder()
|
||||||
.setMaxAge(10)
|
.setMaxAge(10)
|
||||||
|
@ -194,7 +194,7 @@ public class TestCacheValidityPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFreshnessLifetimeUsesMaxAgeWhenSharedMaxAgeNotPresent() {
|
void testFreshnessLifetimeUsesMaxAgeWhenSharedMaxAgeNotPresent() {
|
||||||
// assuming impl represents a shared cache
|
// assuming impl represents a shared cache
|
||||||
final ResponseCacheControl cacheControl = ResponseCacheControl.builder()
|
final ResponseCacheControl cacheControl = ResponseCacheControl.builder()
|
||||||
.setMaxAge(10)
|
.setMaxAge(10)
|
||||||
|
@ -204,7 +204,7 @@ public class TestCacheValidityPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFreshnessLifetimeIsMaxAgeEvenIfExpiresIsPresent() {
|
void testFreshnessLifetimeIsMaxAgeEvenIfExpiresIsPresent() {
|
||||||
final ResponseCacheControl cacheControl = ResponseCacheControl.builder()
|
final ResponseCacheControl cacheControl = ResponseCacheControl.builder()
|
||||||
.setMaxAge(10)
|
.setMaxAge(10)
|
||||||
.build();
|
.build();
|
||||||
|
@ -215,7 +215,7 @@ public class TestCacheValidityPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFreshnessLifetimeIsSMaxAgeEvenIfExpiresIsPresent() {
|
void testFreshnessLifetimeIsSMaxAgeEvenIfExpiresIsPresent() {
|
||||||
final ResponseCacheControl cacheControl = ResponseCacheControl.builder()
|
final ResponseCacheControl cacheControl = ResponseCacheControl.builder()
|
||||||
.setSharedMaxAge(10)
|
.setSharedMaxAge(10)
|
||||||
.build();
|
.build();
|
||||||
|
@ -226,7 +226,7 @@ public class TestCacheValidityPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFreshnessLifetimeIsFromExpiresHeaderIfNoMaxAge() {
|
void testFreshnessLifetimeIsFromExpiresHeaderIfNoMaxAge() {
|
||||||
final ResponseCacheControl cacheControl = ResponseCacheControl.builder()
|
final ResponseCacheControl cacheControl = ResponseCacheControl.builder()
|
||||||
.build();
|
.build();
|
||||||
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(
|
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(
|
||||||
|
@ -236,7 +236,7 @@ public class TestCacheValidityPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHeuristicFreshnessLifetime() {
|
void testHeuristicFreshnessLifetime() {
|
||||||
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(
|
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(
|
||||||
new BasicHeader("Date", DateUtils.formatStandardDate(oneSecondAgo)),
|
new BasicHeader("Date", DateUtils.formatStandardDate(oneSecondAgo)),
|
||||||
new BasicHeader("Last-Modified", DateUtils.formatStandardDate(elevenSecondsAgo)));
|
new BasicHeader("Last-Modified", DateUtils.formatStandardDate(elevenSecondsAgo)));
|
||||||
|
@ -244,14 +244,14 @@ public class TestCacheValidityPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHeuristicFreshnessLifetimeDefaultsProperly() {
|
void testHeuristicFreshnessLifetimeDefaultsProperly() {
|
||||||
final TimeValue defaultFreshness = TimeValue.ofSeconds(0);
|
final TimeValue defaultFreshness = TimeValue.ofSeconds(0);
|
||||||
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry();
|
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry();
|
||||||
assertEquals(defaultFreshness, impl.getHeuristicFreshnessLifetime(entry));
|
assertEquals(defaultFreshness, impl.getHeuristicFreshnessLifetime(entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHeuristicFreshnessLifetimeIsNonNegative() {
|
void testHeuristicFreshnessLifetimeIsNonNegative() {
|
||||||
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(
|
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(
|
||||||
new BasicHeader("Date", DateUtils.formatStandardDate(elevenSecondsAgo)),
|
new BasicHeader("Date", DateUtils.formatStandardDate(elevenSecondsAgo)),
|
||||||
new BasicHeader("Last-Modified", DateUtils.formatStandardDate(oneSecondAgo)));
|
new BasicHeader("Last-Modified", DateUtils.formatStandardDate(oneSecondAgo)));
|
||||||
|
@ -259,7 +259,7 @@ public class TestCacheValidityPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHeuristicFreshnessLifetimeCustomProperly() {
|
void testHeuristicFreshnessLifetimeCustomProperly() {
|
||||||
final CacheConfig cacheConfig = CacheConfig.custom().setHeuristicDefaultLifetime(TimeValue.ofSeconds(10))
|
final CacheConfig cacheConfig = CacheConfig.custom().setHeuristicDefaultLifetime(TimeValue.ofSeconds(10))
|
||||||
.setHeuristicCoefficient(0.5f).build();
|
.setHeuristicCoefficient(0.5f).build();
|
||||||
impl = new CacheValidityPolicy(cacheConfig);
|
impl = new CacheValidityPolicy(cacheConfig);
|
||||||
|
@ -269,7 +269,7 @@ public class TestCacheValidityPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNegativeAgeHeaderValueReturnsZero() {
|
void testNegativeAgeHeaderValueReturnsZero() {
|
||||||
final Header[] headers = new Header[] { new BasicHeader("Age", "-100") };
|
final Header[] headers = new Header[] { new BasicHeader("Age", "-100") };
|
||||||
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(headers);
|
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(headers);
|
||||||
// in seconds
|
// in seconds
|
||||||
|
@ -277,7 +277,7 @@ public class TestCacheValidityPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMalformedAgeHeaderValueReturnsMaxAge() {
|
void testMalformedAgeHeaderValueReturnsMaxAge() {
|
||||||
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(
|
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(
|
||||||
new BasicHeader("Age", "asdf"));
|
new BasicHeader("Age", "asdf"));
|
||||||
// in seconds
|
// in seconds
|
||||||
|
@ -285,7 +285,7 @@ public class TestCacheValidityPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMalformedAgeHeaderMultipleWellFormedAges() {
|
void testMalformedAgeHeaderMultipleWellFormedAges() {
|
||||||
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(
|
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(
|
||||||
new BasicHeader("Age", "123,456,789"));
|
new BasicHeader("Age", "123,456,789"));
|
||||||
// in seconds
|
// in seconds
|
||||||
|
@ -293,7 +293,7 @@ public class TestCacheValidityPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMalformedAgeHeaderMultiplesMalformedAges() {
|
void testMalformedAgeHeaderMultiplesMalformedAges() {
|
||||||
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(
|
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(
|
||||||
new BasicHeader("Age", "123 456 789"));
|
new BasicHeader("Age", "123 456 789"));
|
||||||
// in seconds
|
// in seconds
|
||||||
|
@ -301,7 +301,7 @@ public class TestCacheValidityPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMalformedAgeHeaderNegativeAge() {
|
void testMalformedAgeHeaderNegativeAge() {
|
||||||
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(
|
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(
|
||||||
new BasicHeader("Age", "-123"));
|
new BasicHeader("Age", "-123"));
|
||||||
// in seconds
|
// in seconds
|
||||||
|
@ -309,7 +309,7 @@ public class TestCacheValidityPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMalformedAgeHeaderOverflow() {
|
void testMalformedAgeHeaderOverflow() {
|
||||||
final String reallyOldAge = "1" + Long.MAX_VALUE;
|
final String reallyOldAge = "1" + Long.MAX_VALUE;
|
||||||
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(
|
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(
|
||||||
new BasicHeader("Age", reallyOldAge));
|
new BasicHeader("Age", reallyOldAge));
|
||||||
|
|
|
@ -32,17 +32,17 @@ import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestCacheableRequestPolicy {
|
class TestCacheableRequestPolicy {
|
||||||
|
|
||||||
private CacheableRequestPolicy policy;
|
private CacheableRequestPolicy policy;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() {
|
||||||
policy = new CacheableRequestPolicy();
|
policy = new CacheableRequestPolicy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsGetServableFromCache() {
|
void testIsGetServableFromCache() {
|
||||||
final BasicHttpRequest request = new BasicHttpRequest("GET", "someUri");
|
final BasicHttpRequest request = new BasicHttpRequest("GET", "someUri");
|
||||||
final RequestCacheControl cacheControl = RequestCacheControl.builder().build();
|
final RequestCacheControl cacheControl = RequestCacheControl.builder().build();
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ public class TestCacheableRequestPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsGetWithCacheControlServableFromCache() {
|
void testIsGetWithCacheControlServableFromCache() {
|
||||||
final BasicHttpRequest request = new BasicHttpRequest("GET", "someUri");
|
final BasicHttpRequest request = new BasicHttpRequest("GET", "someUri");
|
||||||
final RequestCacheControl cacheControl = RequestCacheControl.builder()
|
final RequestCacheControl cacheControl = RequestCacheControl.builder()
|
||||||
.setNoCache(true)
|
.setNoCache(true)
|
||||||
|
@ -67,7 +67,7 @@ public class TestCacheableRequestPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsHeadServableFromCache() {
|
void testIsHeadServableFromCache() {
|
||||||
final BasicHttpRequest request = new BasicHttpRequest("HEAD", "someUri");
|
final BasicHttpRequest request = new BasicHttpRequest("HEAD", "someUri");
|
||||||
final RequestCacheControl cacheControl = RequestCacheControl.builder().build();
|
final RequestCacheControl cacheControl = RequestCacheControl.builder().build();
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ public class TestCacheableRequestPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsHeadWithCacheControlServableFromCache() {
|
void testIsHeadWithCacheControlServableFromCache() {
|
||||||
final BasicHttpRequest request = new BasicHttpRequest("HEAD", "someUri");
|
final BasicHttpRequest request = new BasicHttpRequest("HEAD", "someUri");
|
||||||
final RequestCacheControl cacheControl = RequestCacheControl.builder()
|
final RequestCacheControl cacheControl = RequestCacheControl.builder()
|
||||||
.setNoCache(true)
|
.setNoCache(true)
|
||||||
|
@ -100,7 +100,7 @@ public class TestCacheableRequestPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsArbitraryMethodServableFromCache() {
|
void testIsArbitraryMethodServableFromCache() {
|
||||||
final BasicHttpRequest request = new BasicHttpRequest("TRACE", "someUri");
|
final BasicHttpRequest request = new BasicHttpRequest("TRACE", "someUri");
|
||||||
final RequestCacheControl cacheControl = RequestCacheControl.builder()
|
final RequestCacheControl cacheControl = RequestCacheControl.builder()
|
||||||
.build();
|
.build();
|
||||||
|
|
|
@ -44,7 +44,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@SuppressWarnings({"boxing","static-access"}) // test code
|
@SuppressWarnings({"boxing","static-access"}) // test code
|
||||||
public class TestCachedHttpResponseGenerator {
|
class TestCachedHttpResponseGenerator {
|
||||||
|
|
||||||
private HttpCacheEntry entry;
|
private HttpCacheEntry entry;
|
||||||
private ClassicHttpRequest request;
|
private ClassicHttpRequest request;
|
||||||
|
@ -52,7 +52,7 @@ public class TestCachedHttpResponseGenerator {
|
||||||
private CachedHttpResponseGenerator impl;
|
private CachedHttpResponseGenerator impl;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
entry = HttpTestUtils.makeCacheEntry();
|
entry = HttpTestUtils.makeCacheEntry();
|
||||||
request = HttpTestUtils.makeDefaultRequest();
|
request = HttpTestUtils.makeDefaultRequest();
|
||||||
mockValidityPolicy = mock(CacheValidityPolicy.class);
|
mockValidityPolicy = mock(CacheValidityPolicy.class);
|
||||||
|
@ -60,7 +60,7 @@ public class TestCachedHttpResponseGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponseHasContentLength() throws Exception {
|
void testResponseHasContentLength() throws Exception {
|
||||||
final byte[] buf = new byte[] { 1, 2, 3, 4, 5 };
|
final byte[] buf = new byte[] { 1, 2, 3, 4, 5 };
|
||||||
final HttpCacheEntry entry1 = HttpTestUtils.makeCacheEntry(buf);
|
final HttpCacheEntry entry1 = HttpTestUtils.makeCacheEntry(buf);
|
||||||
|
|
||||||
|
@ -73,14 +73,14 @@ public class TestCachedHttpResponseGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponseStatusCodeMatchesCacheEntry() throws Exception {
|
void testResponseStatusCodeMatchesCacheEntry() throws Exception {
|
||||||
final SimpleHttpResponse response = impl.generateResponse(request, entry);
|
final SimpleHttpResponse response = impl.generateResponse(request, entry);
|
||||||
|
|
||||||
Assertions.assertEquals(entry.getStatus(), response.getCode());
|
Assertions.assertEquals(entry.getStatus(), response.getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAgeHeaderIsPopulatedWithCurrentAgeOfCacheEntryIfNonZero() throws Exception {
|
void testAgeHeaderIsPopulatedWithCurrentAgeOfCacheEntryIfNonZero() throws Exception {
|
||||||
currentAge(TimeValue.ofSeconds(10L));
|
currentAge(TimeValue.ofSeconds(10L));
|
||||||
|
|
||||||
final SimpleHttpResponse response = impl.generateResponse(request, entry);
|
final SimpleHttpResponse response = impl.generateResponse(request, entry);
|
||||||
|
@ -93,7 +93,7 @@ public class TestCachedHttpResponseGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAgeHeaderIsNotPopulatedIfCurrentAgeOfCacheEntryIsZero() throws Exception {
|
void testAgeHeaderIsNotPopulatedIfCurrentAgeOfCacheEntryIsZero() throws Exception {
|
||||||
currentAge(TimeValue.ofSeconds(0L));
|
currentAge(TimeValue.ofSeconds(0L));
|
||||||
|
|
||||||
final SimpleHttpResponse response = impl.generateResponse(request, entry);
|
final SimpleHttpResponse response = impl.generateResponse(request, entry);
|
||||||
|
@ -105,7 +105,7 @@ public class TestCachedHttpResponseGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAgeHeaderIsPopulatedWithMaxAgeIfCurrentAgeTooBig() throws Exception {
|
void testAgeHeaderIsPopulatedWithMaxAgeIfCurrentAgeTooBig() throws Exception {
|
||||||
currentAge(TimeValue.ofSeconds(CacheSupport.MAX_AGE.toSeconds() + 1L));
|
currentAge(TimeValue.ofSeconds(CacheSupport.MAX_AGE.toSeconds() + 1L));
|
||||||
|
|
||||||
final SimpleHttpResponse response = impl.generateResponse(request, entry);
|
final SimpleHttpResponse response = impl.generateResponse(request, entry);
|
||||||
|
@ -124,14 +124,14 @@ public class TestCachedHttpResponseGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponseContainsEntityToServeGETRequestIfEntryContainsResource() throws Exception {
|
void testResponseContainsEntityToServeGETRequestIfEntryContainsResource() throws Exception {
|
||||||
final SimpleHttpResponse response = impl.generateResponse(request, entry);
|
final SimpleHttpResponse response = impl.generateResponse(request, entry);
|
||||||
|
|
||||||
Assertions.assertNotNull(response.getBody());
|
Assertions.assertNotNull(response.getBody());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponseDoesNotContainEntityToServeHEADRequestIfEntryContainsResource() throws Exception {
|
void testResponseDoesNotContainEntityToServeHEADRequestIfEntryContainsResource() throws Exception {
|
||||||
final ClassicHttpRequest headRequest = HttpTestUtils.makeDefaultHEADRequest();
|
final ClassicHttpRequest headRequest = HttpTestUtils.makeDefaultHEADRequest();
|
||||||
final SimpleHttpResponse response = impl.generateResponse(headRequest, entry);
|
final SimpleHttpResponse response = impl.generateResponse(headRequest, entry);
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestCachedResponseSuitabilityChecker {
|
class TestCachedResponseSuitabilityChecker {
|
||||||
|
|
||||||
private Instant now;
|
private Instant now;
|
||||||
private Instant elevenSecondsAgo;
|
private Instant elevenSecondsAgo;
|
||||||
|
@ -58,7 +58,7 @@ public class TestCachedResponseSuitabilityChecker {
|
||||||
private CachedResponseSuitabilityChecker impl;
|
private CachedResponseSuitabilityChecker impl;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
now = Instant.now();
|
now = Instant.now();
|
||||||
elevenSecondsAgo = now.minusSeconds(11);
|
elevenSecondsAgo = now.minusSeconds(11);
|
||||||
tenSecondsAgo = now.minusSeconds(10);
|
tenSecondsAgo = now.minusSeconds(10);
|
||||||
|
@ -104,7 +104,7 @@ public class TestCachedResponseSuitabilityChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRequestMethodMatch() {
|
void testRequestMethodMatch() {
|
||||||
request = new BasicHttpRequest("GET", "/foo");
|
request = new BasicHttpRequest("GET", "/foo");
|
||||||
entry = makeEntry(Method.GET, "/foo",
|
entry = makeEntry(Method.GET, "/foo",
|
||||||
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
||||||
|
@ -128,7 +128,7 @@ public class TestCachedResponseSuitabilityChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRequestUriMatch() {
|
void testRequestUriMatch() {
|
||||||
request = new BasicHttpRequest("GET", "/foo");
|
request = new BasicHttpRequest("GET", "/foo");
|
||||||
entry = makeEntry(Method.GET, "/foo",
|
entry = makeEntry(Method.GET, "/foo",
|
||||||
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
||||||
|
@ -156,7 +156,7 @@ public class TestCachedResponseSuitabilityChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRequestHeadersMatch() {
|
void testRequestHeadersMatch() {
|
||||||
request = BasicRequestBuilder.get("/foo").build();
|
request = BasicRequestBuilder.get("/foo").build();
|
||||||
entry = makeEntry(
|
entry = makeEntry(
|
||||||
Method.GET, "/foo",
|
Method.GET, "/foo",
|
||||||
|
@ -225,7 +225,7 @@ public class TestCachedResponseSuitabilityChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponseNoCache() {
|
void testResponseNoCache() {
|
||||||
entry = makeEntry(new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
entry = makeEntry(new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
||||||
responseCacheControl = ResponseCacheControl.builder()
|
responseCacheControl = ResponseCacheControl.builder()
|
||||||
.setNoCache(false)
|
.setNoCache(false)
|
||||||
|
@ -254,7 +254,7 @@ public class TestCachedResponseSuitabilityChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuitableIfCacheEntryIsFresh() {
|
void testSuitableIfCacheEntryIsFresh() {
|
||||||
entry = makeEntry(new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
entry = makeEntry(new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
||||||
responseCacheControl = ResponseCacheControl.builder()
|
responseCacheControl = ResponseCacheControl.builder()
|
||||||
.setMaxAge(3600)
|
.setMaxAge(3600)
|
||||||
|
@ -263,7 +263,7 @@ public class TestCachedResponseSuitabilityChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotSuitableIfCacheEntryIsNotFresh() {
|
void testNotSuitableIfCacheEntryIsNotFresh() {
|
||||||
entry = makeEntry(
|
entry = makeEntry(
|
||||||
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
||||||
responseCacheControl = ResponseCacheControl.builder()
|
responseCacheControl = ResponseCacheControl.builder()
|
||||||
|
@ -273,7 +273,7 @@ public class TestCachedResponseSuitabilityChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotSuitableIfRequestHasNoCache() {
|
void testNotSuitableIfRequestHasNoCache() {
|
||||||
requestCacheControl = RequestCacheControl.builder()
|
requestCacheControl = RequestCacheControl.builder()
|
||||||
.setNoCache(true)
|
.setNoCache(true)
|
||||||
.build();
|
.build();
|
||||||
|
@ -286,7 +286,7 @@ public class TestCachedResponseSuitabilityChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotSuitableIfAgeExceedsRequestMaxAge() {
|
void testNotSuitableIfAgeExceedsRequestMaxAge() {
|
||||||
requestCacheControl = RequestCacheControl.builder()
|
requestCacheControl = RequestCacheControl.builder()
|
||||||
.setMaxAge(10)
|
.setMaxAge(10)
|
||||||
.build();
|
.build();
|
||||||
|
@ -299,7 +299,7 @@ public class TestCachedResponseSuitabilityChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuitableIfFreshAndAgeIsUnderRequestMaxAge() {
|
void testSuitableIfFreshAndAgeIsUnderRequestMaxAge() {
|
||||||
requestCacheControl = RequestCacheControl.builder()
|
requestCacheControl = RequestCacheControl.builder()
|
||||||
.setMaxAge(15)
|
.setMaxAge(15)
|
||||||
.build();
|
.build();
|
||||||
|
@ -312,7 +312,7 @@ public class TestCachedResponseSuitabilityChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuitableIfFreshAndFreshnessLifetimeGreaterThanRequestMinFresh() {
|
void testSuitableIfFreshAndFreshnessLifetimeGreaterThanRequestMinFresh() {
|
||||||
requestCacheControl = RequestCacheControl.builder()
|
requestCacheControl = RequestCacheControl.builder()
|
||||||
.setMinFresh(10)
|
.setMinFresh(10)
|
||||||
.build();
|
.build();
|
||||||
|
@ -325,7 +325,7 @@ public class TestCachedResponseSuitabilityChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotSuitableIfFreshnessLifetimeLessThanRequestMinFresh() {
|
void testNotSuitableIfFreshnessLifetimeLessThanRequestMinFresh() {
|
||||||
requestCacheControl = RequestCacheControl.builder()
|
requestCacheControl = RequestCacheControl.builder()
|
||||||
.setMinFresh(10)
|
.setMinFresh(10)
|
||||||
.build();
|
.build();
|
||||||
|
@ -338,7 +338,7 @@ public class TestCachedResponseSuitabilityChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuitableEvenIfStaleButPermittedByRequestMaxStale() {
|
void testSuitableEvenIfStaleButPermittedByRequestMaxStale() {
|
||||||
requestCacheControl = RequestCacheControl.builder()
|
requestCacheControl = RequestCacheControl.builder()
|
||||||
.setMaxStale(10)
|
.setMaxStale(10)
|
||||||
.build();
|
.build();
|
||||||
|
@ -353,7 +353,7 @@ public class TestCachedResponseSuitabilityChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotSuitableIfStaleButTooStaleForRequestMaxStale() {
|
void testNotSuitableIfStaleButTooStaleForRequestMaxStale() {
|
||||||
requestCacheControl = RequestCacheControl.builder()
|
requestCacheControl = RequestCacheControl.builder()
|
||||||
.setMaxStale(2)
|
.setMaxStale(2)
|
||||||
.build();
|
.build();
|
||||||
|
@ -366,7 +366,7 @@ public class TestCachedResponseSuitabilityChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuitableIfCacheEntryIsHeuristicallyFreshEnough() {
|
void testSuitableIfCacheEntryIsHeuristicallyFreshEnough() {
|
||||||
final Instant oneSecondAgo = now.minusSeconds(1);
|
final Instant oneSecondAgo = now.minusSeconds(1);
|
||||||
final Instant twentyOneSecondsAgo = now.minusSeconds(21);
|
final Instant twentyOneSecondsAgo = now.minusSeconds(21);
|
||||||
|
|
||||||
|
@ -383,7 +383,7 @@ public class TestCachedResponseSuitabilityChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuitableIfCacheEntryIsHeuristicallyFreshEnoughByDefault() {
|
void testSuitableIfCacheEntryIsHeuristicallyFreshEnoughByDefault() {
|
||||||
entry = makeEntry(
|
entry = makeEntry(
|
||||||
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
||||||
|
|
||||||
|
@ -397,7 +397,7 @@ public class TestCachedResponseSuitabilityChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuitableIfRequestMethodisHEAD() {
|
void testSuitableIfRequestMethodisHEAD() {
|
||||||
final HttpRequest headRequest = new BasicHttpRequest("HEAD", "/foo");
|
final HttpRequest headRequest = new BasicHttpRequest("HEAD", "/foo");
|
||||||
entry = makeEntry(
|
entry = makeEntry(
|
||||||
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
||||||
|
@ -409,7 +409,7 @@ public class TestCachedResponseSuitabilityChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuitableForGETIfEntryDoesNotSpecifyARequestMethodButContainsEntity() {
|
void testSuitableForGETIfEntryDoesNotSpecifyARequestMethodButContainsEntity() {
|
||||||
impl = new CachedResponseSuitabilityChecker(CacheConfig.custom().build());
|
impl = new CachedResponseSuitabilityChecker(CacheConfig.custom().build());
|
||||||
entry = makeEntry(Method.GET, "/foo",
|
entry = makeEntry(Method.GET, "/foo",
|
||||||
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
||||||
|
@ -421,7 +421,7 @@ public class TestCachedResponseSuitabilityChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuitableForGETIfHeadResponseCachingEnabledAndEntryDoesNotSpecifyARequestMethodButContains204Response() {
|
void testSuitableForGETIfHeadResponseCachingEnabledAndEntryDoesNotSpecifyARequestMethodButContains204Response() {
|
||||||
impl = new CachedResponseSuitabilityChecker(CacheConfig.custom().build());
|
impl = new CachedResponseSuitabilityChecker(CacheConfig.custom().build());
|
||||||
entry = makeEntry(Method.GET, "/foo",
|
entry = makeEntry(Method.GET, "/foo",
|
||||||
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
||||||
|
@ -433,7 +433,7 @@ public class TestCachedResponseSuitabilityChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuitableForHEADIfHeadResponseCachingEnabledAndEntryDoesNotSpecifyARequestMethod() {
|
void testSuitableForHEADIfHeadResponseCachingEnabledAndEntryDoesNotSpecifyARequestMethod() {
|
||||||
final HttpRequest headRequest = new BasicHttpRequest("HEAD", "/foo");
|
final HttpRequest headRequest = new BasicHttpRequest("HEAD", "/foo");
|
||||||
impl = new CachedResponseSuitabilityChecker(CacheConfig.custom().build());
|
impl = new CachedResponseSuitabilityChecker(CacheConfig.custom().build());
|
||||||
final Header[] headers = {
|
final Header[] headers = {
|
||||||
|
@ -449,7 +449,7 @@ public class TestCachedResponseSuitabilityChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotSuitableIfGetRequestWithHeadCacheEntry() {
|
void testNotSuitableIfGetRequestWithHeadCacheEntry() {
|
||||||
// Prepare a cache entry with HEAD method
|
// Prepare a cache entry with HEAD method
|
||||||
entry = makeEntry(Method.HEAD, "/foo",
|
entry = makeEntry(Method.HEAD, "/foo",
|
||||||
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
||||||
|
@ -461,7 +461,7 @@ public class TestCachedResponseSuitabilityChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuitableIfErrorRequestCacheControl() {
|
void testSuitableIfErrorRequestCacheControl() {
|
||||||
// Prepare a cache entry with HEAD method
|
// Prepare a cache entry with HEAD method
|
||||||
entry = makeEntry(Method.GET, "/foo",
|
entry = makeEntry(Method.GET, "/foo",
|
||||||
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
||||||
|
@ -494,7 +494,7 @@ public class TestCachedResponseSuitabilityChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuitableIfErrorResponseCacheControl() {
|
void testSuitableIfErrorResponseCacheControl() {
|
||||||
// Prepare a cache entry with HEAD method
|
// Prepare a cache entry with HEAD method
|
||||||
entry = makeEntry(Method.GET, "/foo",
|
entry = makeEntry(Method.GET, "/foo",
|
||||||
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
||||||
|
@ -521,7 +521,7 @@ public class TestCachedResponseSuitabilityChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuitableIfErrorRequestCacheControlTakesPrecedenceOverResponseCacheControl() {
|
void testSuitableIfErrorRequestCacheControlTakesPrecedenceOverResponseCacheControl() {
|
||||||
// Prepare a cache entry with HEAD method
|
// Prepare a cache entry with HEAD method
|
||||||
entry = makeEntry(Method.GET, "/foo",
|
entry = makeEntry(Method.GET, "/foo",
|
||||||
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
||||||
|
@ -541,7 +541,7 @@ public class TestCachedResponseSuitabilityChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuitableIfErrorConfigDefault() {
|
void testSuitableIfErrorConfigDefault() {
|
||||||
// Prepare a cache entry with HEAD method
|
// Prepare a cache entry with HEAD method
|
||||||
entry = makeEntry(Method.GET, "/foo",
|
entry = makeEntry(Method.GET, "/foo",
|
||||||
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
|
||||||
|
|
|
@ -71,7 +71,7 @@ import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
public class TestCachingExecChain {
|
class TestCachingExecChain {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
ExecChain mockExecChain;
|
ExecChain mockExecChain;
|
||||||
|
@ -93,7 +93,7 @@ public class TestCachingExecChain {
|
||||||
ExecChain.Scope scope;
|
ExecChain.Scope scope;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
MockitoAnnotations.openMocks(this);
|
MockitoAnnotations.openMocks(this);
|
||||||
host = new HttpHost("foo.example.com", 80);
|
host = new HttpHost("foo.example.com", 80);
|
||||||
route = new HttpRoute(host);
|
route = new HttpRoute(host);
|
||||||
|
@ -115,7 +115,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheableResponsesGoIntoCache() throws Exception {
|
void testCacheableResponsesGoIntoCache() throws Exception {
|
||||||
final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
resp1.setHeader("Cache-Control", "max-age=3600");
|
resp1.setHeader("Cache-Control", "max-age=3600");
|
||||||
|
@ -133,7 +133,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOlderCacheableResponsesDoNotGoIntoCache() throws Exception {
|
void testOlderCacheableResponsesDoNotGoIntoCache() throws Exception {
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant fiveSecondsAgo = now.minusSeconds(5);
|
final Instant fiveSecondsAgo = now.minusSeconds(5);
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNewerCacheableResponsesReplaceExistingCacheEntry() throws Exception {
|
void testNewerCacheableResponsesReplaceExistingCacheEntry() throws Exception {
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant fiveSecondsAgo = now.minusSeconds(5);
|
final Instant fiveSecondsAgo = now.minusSeconds(5);
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNonCacheableResponseIsNotCachedAndIsReturnedAsIs() throws Exception {
|
void testNonCacheableResponseIsNotCachedAndIsReturnedAsIs() throws Exception {
|
||||||
final HttpCache cache = new BasicHttpCache(new HeapResourceFactory(), mockStorage);
|
final HttpCache cache = new BasicHttpCache(new HeapResourceFactory(), mockStorage);
|
||||||
impl = new CachingExec(cache, null, CacheConfig.DEFAULT);
|
impl = new CachingExec(cache, null, CacheConfig.DEFAULT);
|
||||||
|
|
||||||
|
@ -216,7 +216,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetsModuleGeneratedResponseContextForCacheOptionsResponse() throws Exception {
|
void testSetsModuleGeneratedResponseContextForCacheOptionsResponse() throws Exception {
|
||||||
final ClassicHttpRequest req = new BasicClassicHttpRequest("OPTIONS", "*");
|
final ClassicHttpRequest req = new BasicClassicHttpRequest("OPTIONS", "*");
|
||||||
req.setHeader("Max-Forwards", "0");
|
req.setHeader("Max-Forwards", "0");
|
||||||
|
|
||||||
|
@ -225,7 +225,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetsCacheMissContextIfRequestNotServableFromCache() throws Exception {
|
void testSetsCacheMissContextIfRequestNotServableFromCache() throws Exception {
|
||||||
final ClassicHttpRequest req = new HttpGet("http://foo.example.com/");
|
final ClassicHttpRequest req = new HttpGet("http://foo.example.com/");
|
||||||
req.setHeader("Cache-Control", "no-cache");
|
req.setHeader("Cache-Control", "no-cache");
|
||||||
final ClassicHttpResponse resp = new BasicClassicHttpResponse(HttpStatus.SC_NO_CONTENT, "No Content");
|
final ClassicHttpResponse resp = new BasicClassicHttpResponse(HttpStatus.SC_NO_CONTENT, "No Content");
|
||||||
|
@ -237,7 +237,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetsCacheHitContextIfRequestServedFromCache() throws Exception {
|
void testSetsCacheHitContextIfRequestServedFromCache() throws Exception {
|
||||||
final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
|
final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
|
||||||
final ClassicHttpRequest req2 = new HttpGet("http://foo.example.com/");
|
final ClassicHttpRequest req2 = new HttpGet("http://foo.example.com/");
|
||||||
final ClassicHttpResponse resp1 = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
|
final ClassicHttpResponse resp1 = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
|
||||||
|
@ -255,7 +255,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReturns304ForIfModifiedSinceHeaderIfRequestServedFromCache() throws Exception {
|
void testReturns304ForIfModifiedSinceHeaderIfRequestServedFromCache() throws Exception {
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant tenSecondsAgo = now.minusSeconds(10);
|
final Instant tenSecondsAgo = now.minusSeconds(10);
|
||||||
final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
|
final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
|
||||||
|
@ -277,7 +277,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReturns304ForIfModifiedSinceHeaderIf304ResponseInCache() throws Exception {
|
void testReturns304ForIfModifiedSinceHeaderIf304ResponseInCache() throws Exception {
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant oneHourAgo = now.minus(1, ChronoUnit.HOURS);
|
final Instant oneHourAgo = now.minus(1, ChronoUnit.HOURS);
|
||||||
final Instant inTenMinutes = now.plus(10, ChronoUnit.MINUTES);
|
final Instant inTenMinutes = now.plus(10, ChronoUnit.MINUTES);
|
||||||
|
@ -304,7 +304,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReturns304ForIfModifiedSinceHeaderIf304ResponseInCacheWithLastModified() throws Exception {
|
void testReturns304ForIfModifiedSinceHeaderIf304ResponseInCacheWithLastModified() throws Exception {
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant oneHourAgo = now.minus(1, ChronoUnit.HOURS);
|
final Instant oneHourAgo = now.minus(1, ChronoUnit.HOURS);
|
||||||
final Instant inTenMinutes = now.plus(10, ChronoUnit.MINUTES);
|
final Instant inTenMinutes = now.plus(10, ChronoUnit.MINUTES);
|
||||||
|
@ -330,7 +330,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReturns200ForIfModifiedSinceDateIsLess() throws Exception {
|
void testReturns200ForIfModifiedSinceDateIsLess() throws Exception {
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant tenSecondsAgo = now.minusSeconds(10);
|
final Instant tenSecondsAgo = now.minusSeconds(10);
|
||||||
final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
|
final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
|
||||||
|
@ -360,7 +360,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReturns200ForIfModifiedSinceDateIsInvalid() throws Exception {
|
void testReturns200ForIfModifiedSinceDateIsInvalid() throws Exception {
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant tenSecondsAfter = now.plusSeconds(10);
|
final Instant tenSecondsAfter = now.plusSeconds(10);
|
||||||
final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
|
final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
|
||||||
|
@ -387,7 +387,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReturns304ForIfNoneMatchHeaderIfRequestServedFromCache() throws Exception {
|
void testReturns304ForIfNoneMatchHeaderIfRequestServedFromCache() throws Exception {
|
||||||
final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
|
final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
|
||||||
final ClassicHttpRequest req2 = new HttpGet("http://foo.example.com/");
|
final ClassicHttpRequest req2 = new HttpGet("http://foo.example.com/");
|
||||||
req2.addHeader("If-None-Match", "*");
|
req2.addHeader("If-None-Match", "*");
|
||||||
|
@ -407,7 +407,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReturns200ForIfNoneMatchHeaderFails() throws Exception {
|
void testReturns200ForIfNoneMatchHeaderFails() throws Exception {
|
||||||
final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
|
final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
|
||||||
final ClassicHttpRequest req2 = new HttpGet("http://foo.example.com/");
|
final ClassicHttpRequest req2 = new HttpGet("http://foo.example.com/");
|
||||||
|
|
||||||
|
@ -433,7 +433,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReturns304ForIfNoneMatchHeaderAndIfModifiedSinceIfRequestServedFromCache() throws Exception {
|
void testReturns304ForIfNoneMatchHeaderAndIfModifiedSinceIfRequestServedFromCache() throws Exception {
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant tenSecondsAgo = now.minusSeconds(10);
|
final Instant tenSecondsAgo = now.minusSeconds(10);
|
||||||
final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
|
final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
|
||||||
|
@ -458,7 +458,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReturns200ForIfNoneMatchHeaderFailsIfModifiedSinceIgnored() throws Exception {
|
void testReturns200ForIfNoneMatchHeaderFailsIfModifiedSinceIgnored() throws Exception {
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant tenSecondsAgo = now.minusSeconds(10);
|
final Instant tenSecondsAgo = now.minusSeconds(10);
|
||||||
final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
|
final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
|
||||||
|
@ -481,7 +481,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReturns200ForOptionsFollowedByGetIfAuthorizationHeaderAndSharedCache() throws Exception {
|
void testReturns200ForOptionsFollowedByGetIfAuthorizationHeaderAndSharedCache() throws Exception {
|
||||||
impl = new CachingExec(cache, null, CacheConfig.custom().setSharedCache(true).build());
|
impl = new CachingExec(cache, null, CacheConfig.custom().setSharedCache(true).build());
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final ClassicHttpRequest req1 = new HttpOptions("http://foo.example.com/");
|
final ClassicHttpRequest req1 = new HttpOptions("http://foo.example.com/");
|
||||||
|
@ -512,7 +512,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetsValidatedContextIfRequestWasSuccessfullyValidated() throws Exception {
|
void testSetsValidatedContextIfRequestWasSuccessfullyValidated() throws Exception {
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant tenSecondsAgo = now.minusSeconds(10);
|
final Instant tenSecondsAgo = now.minusSeconds(10);
|
||||||
|
|
||||||
|
@ -543,7 +543,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetsModuleResponseContextIfValidationRequiredButFailed() throws Exception {
|
void testSetsModuleResponseContextIfValidationRequiredButFailed() throws Exception {
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant tenSecondsAgo = now.minusSeconds(10);
|
final Instant tenSecondsAgo = now.minusSeconds(10);
|
||||||
|
|
||||||
|
@ -569,7 +569,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetsModuleResponseContextIfValidationFailsButNotRequired() throws Exception {
|
void testSetsModuleResponseContextIfValidationFailsButNotRequired() throws Exception {
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant tenSecondsAgo = now.minusSeconds(10);
|
final Instant tenSecondsAgo = now.minusSeconds(10);
|
||||||
|
|
||||||
|
@ -594,7 +594,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReturns304ForIfNoneMatchPassesIfRequestServedFromOrigin() throws Exception {
|
void testReturns304ForIfNoneMatchPassesIfRequestServedFromOrigin() throws Exception {
|
||||||
|
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant tenSecondsAgo = now.minusSeconds(10);
|
final Instant tenSecondsAgo = now.minusSeconds(10);
|
||||||
|
@ -626,7 +626,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReturns200ForIfNoneMatchFailsIfRequestServedFromOrigin() throws Exception {
|
void testReturns200ForIfNoneMatchFailsIfRequestServedFromOrigin() throws Exception {
|
||||||
|
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant tenSecondsAgo = now.minusSeconds(10);
|
final Instant tenSecondsAgo = now.minusSeconds(10);
|
||||||
|
@ -660,7 +660,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReturns304ForIfModifiedSincePassesIfRequestServedFromOrigin() throws Exception {
|
void testReturns304ForIfModifiedSincePassesIfRequestServedFromOrigin() throws Exception {
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant tenSecondsAgo = now.minusSeconds(10);
|
final Instant tenSecondsAgo = now.minusSeconds(10);
|
||||||
|
|
||||||
|
@ -694,7 +694,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReturns200ForIfModifiedSinceFailsIfRequestServedFromOrigin() throws Exception {
|
void testReturns200ForIfModifiedSinceFailsIfRequestServedFromOrigin() throws Exception {
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant tenSecondsAgo = now.minusSeconds(10);
|
final Instant tenSecondsAgo = now.minusSeconds(10);
|
||||||
|
|
||||||
|
@ -730,7 +730,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVariantMissServerIfReturns304CacheReturns200() throws Exception {
|
void testVariantMissServerIfReturns304CacheReturns200() throws Exception {
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
|
|
||||||
final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com");
|
final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com");
|
||||||
|
@ -792,7 +792,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVariantsMissServerReturns304CacheReturns304() throws Exception {
|
void testVariantsMissServerReturns304CacheReturns304() throws Exception {
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
|
|
||||||
final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com");
|
final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com");
|
||||||
|
@ -853,7 +853,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSocketTimeoutExceptionIsNotSilentlyCatched() throws Exception {
|
void testSocketTimeoutExceptionIsNotSilentlyCatched() throws Exception {
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
|
|
||||||
final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com");
|
final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com");
|
||||||
|
@ -863,7 +863,7 @@ public class TestCachingExecChain {
|
||||||
private boolean closed;
|
private boolean closed;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() {
|
||||||
closed = true;
|
closed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -886,7 +886,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTooLargeResponsesAreNotCached() throws Exception {
|
void testTooLargeResponsesAreNotCached() throws Exception {
|
||||||
final HttpHost host = new HttpHost("foo.example.com");
|
final HttpHost host = new HttpHost("foo.example.com");
|
||||||
final ClassicHttpRequest request = new HttpGet("http://foo.example.com/bar");
|
final ClassicHttpRequest request = new HttpGet("http://foo.example.com/bar");
|
||||||
|
|
||||||
|
@ -908,7 +908,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSmallEnoughResponsesAreCached() throws Exception {
|
void testSmallEnoughResponsesAreCached() throws Exception {
|
||||||
final HttpCache mockCache = mock(HttpCache.class);
|
final HttpCache mockCache = mock(HttpCache.class);
|
||||||
impl = new CachingExec(mockCache, null, CacheConfig.DEFAULT);
|
impl = new CachingExec(mockCache, null, CacheConfig.DEFAULT);
|
||||||
|
|
||||||
|
@ -949,7 +949,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIfOnlyIfCachedAndNoCacheEntryBackendNotCalled() throws Exception {
|
void testIfOnlyIfCachedAndNoCacheEntryBackendNotCalled() throws Exception {
|
||||||
request.addHeader("Cache-Control", "only-if-cached");
|
request.addHeader("Cache-Control", "only-if-cached");
|
||||||
|
|
||||||
final ClassicHttpResponse resp = execute(request);
|
final ClassicHttpResponse resp = execute(request);
|
||||||
|
@ -958,7 +958,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCanCacheAResponseWithoutABody() throws Exception {
|
void testCanCacheAResponseWithoutABody() throws Exception {
|
||||||
final ClassicHttpResponse response = new BasicClassicHttpResponse(HttpStatus.SC_NO_CONTENT, "No Content");
|
final ClassicHttpResponse response = new BasicClassicHttpResponse(HttpStatus.SC_NO_CONTENT, "No Content");
|
||||||
response.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
|
response.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
|
||||||
response.setHeader("Cache-Control", "max-age=300");
|
response.setHeader("Cache-Control", "max-age=300");
|
||||||
|
@ -971,7 +971,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoEntityForIfNoneMatchRequestNotYetInCache() throws Exception {
|
void testNoEntityForIfNoneMatchRequestNotYetInCache() throws Exception {
|
||||||
|
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant tenSecondsAgo = now.minusSeconds(10);
|
final Instant tenSecondsAgo = now.minusSeconds(10);
|
||||||
|
@ -993,7 +993,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotModifiedResponseUpdatesCacheEntryWhenNoEntity() throws Exception {
|
void testNotModifiedResponseUpdatesCacheEntryWhenNoEntity() throws Exception {
|
||||||
|
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
|
|
||||||
|
@ -1027,7 +1027,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotModifiedResponseWithVaryUpdatesCacheEntryWhenNoEntity() throws Exception {
|
void testNotModifiedResponseWithVaryUpdatesCacheEntryWhenNoEntity() throws Exception {
|
||||||
|
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
|
|
||||||
|
@ -1064,7 +1064,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotSend304ForNonConditionalRequest() throws Exception {
|
void testDoesNotSend304ForNonConditionalRequest() throws Exception {
|
||||||
|
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant inOneMinute = now.plus(1, ChronoUnit.MINUTES);
|
final Instant inOneMinute = now.plus(1, ChronoUnit.MINUTES);
|
||||||
|
@ -1105,7 +1105,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUsesVirtualHostForCacheKey() throws Exception {
|
void testUsesVirtualHostForCacheKey() throws Exception {
|
||||||
final ClassicHttpResponse response = HttpTestUtils.make200Response();
|
final ClassicHttpResponse response = HttpTestUtils.make200Response();
|
||||||
response.setHeader("Cache-Control", "max-age=3600");
|
response.setHeader("Cache-Control", "max-age=3600");
|
||||||
Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(response);
|
Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(response);
|
||||||
|
@ -1125,7 +1125,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReturnssetStaleIfErrorNotEnabled() throws Exception {
|
void testReturnssetStaleIfErrorNotEnabled() throws Exception {
|
||||||
|
|
||||||
// Create the first request and response
|
// Create the first request and response
|
||||||
final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
|
final ClassicHttpRequest req1 = new HttpGet("http://foo.example.com/");
|
||||||
|
@ -1156,7 +1156,7 @@ public class TestCachingExecChain {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReturnssetStaleIfErrorEnabled() throws Exception {
|
void testReturnssetStaleIfErrorEnabled() throws Exception {
|
||||||
final CacheConfig customConfig = CacheConfig.custom()
|
final CacheConfig customConfig = CacheConfig.custom()
|
||||||
.setMaxCacheEntries(100)
|
.setMaxCacheEntries(100)
|
||||||
.setMaxObjectSize(1024)
|
.setMaxObjectSize(1024)
|
||||||
|
@ -1196,7 +1196,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotModifiedResponseUpdatesCacheEntry() throws Exception {
|
void testNotModifiedResponseUpdatesCacheEntry() throws Exception {
|
||||||
final HttpCache mockCache = mock(HttpCache.class);
|
final HttpCache mockCache = mock(HttpCache.class);
|
||||||
impl = new CachingExec(mockCache, null, CacheConfig.DEFAULT);
|
impl = new CachingExec(mockCache, null, CacheConfig.DEFAULT);
|
||||||
// Prepare request and host
|
// Prepare request and host
|
||||||
|
@ -1251,7 +1251,7 @@ public class TestCachingExecChain {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoCacheFieldsRevalidation() throws Exception {
|
void testNoCacheFieldsRevalidation() throws Exception {
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant fiveSecondsAgo = now.minusSeconds(5);
|
final Instant fiveSecondsAgo = now.minusSeconds(5);
|
||||||
|
|
||||||
|
|
|
@ -38,10 +38,10 @@ import org.apache.hc.core5.util.ByteArrayBuffer;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestCombinedEntity {
|
class TestCombinedEntity {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCombinedEntityBasics() throws Exception {
|
void testCombinedEntityBasics() throws Exception {
|
||||||
final HttpEntity httpEntity = mock(HttpEntity.class);
|
final HttpEntity httpEntity = mock(HttpEntity.class);
|
||||||
when(httpEntity.getContent()).thenReturn(
|
when(httpEntity.getContent()).thenReturn(
|
||||||
new ByteArrayInputStream(new byte[] { 6, 7, 8, 9, 10 }));
|
new ByteArrayInputStream(new byte[] { 6, 7, 8, 9, 10 }));
|
||||||
|
|
|
@ -51,19 +51,19 @@ import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestConditionalRequestBuilder {
|
class TestConditionalRequestBuilder {
|
||||||
|
|
||||||
private ConditionalRequestBuilder<HttpRequest> impl;
|
private ConditionalRequestBuilder<HttpRequest> impl;
|
||||||
private HttpRequest request;
|
private HttpRequest request;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() {
|
||||||
impl = new ConditionalRequestBuilder<>(request -> BasicRequestBuilder.copy(request).build());
|
impl = new ConditionalRequestBuilder<>(request -> BasicRequestBuilder.copy(request).build());
|
||||||
request = new BasicHttpRequest("GET", "/");
|
request = new BasicHttpRequest("GET", "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildConditionalRequestWithLastModified() {
|
void testBuildConditionalRequestWithLastModified() {
|
||||||
final String theMethod = "GET";
|
final String theMethod = "GET";
|
||||||
final String theUri = "/theuri";
|
final String theUri = "/theuri";
|
||||||
final String lastModified = "this is my last modified date";
|
final String lastModified = "this is my last modified date";
|
||||||
|
@ -91,8 +91,7 @@ public class TestConditionalRequestBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConditionalRequestForEntryWithLastModifiedAndEtagIncludesBothAsValidators()
|
void testConditionalRequestForEntryWithLastModifiedAndEtagIncludesBothAsValidators() {
|
||||||
throws Exception {
|
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant tenSecondsAgo = now.minusSeconds(10);
|
final Instant tenSecondsAgo = now.minusSeconds(10);
|
||||||
final Instant twentySecondsAgo = now.plusSeconds(20);
|
final Instant twentySecondsAgo = now.plusSeconds(20);
|
||||||
|
@ -114,7 +113,7 @@ public class TestConditionalRequestBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildConditionalRequestWithETag() {
|
void testBuildConditionalRequestWithETag() {
|
||||||
final String theMethod = "GET";
|
final String theMethod = "GET";
|
||||||
final String theUri = "/theuri";
|
final String theUri = "/theuri";
|
||||||
final String theETag = "\"this is my eTag\"";
|
final String theETag = "\"this is my eTag\"";
|
||||||
|
@ -146,7 +145,7 @@ public class TestConditionalRequestBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheEntryWithMustRevalidateDoesEndToEndRevalidation() throws Exception {
|
void testCacheEntryWithMustRevalidateDoesEndToEndRevalidation() {
|
||||||
final HttpRequest basicRequest = new BasicHttpRequest("GET","/");
|
final HttpRequest basicRequest = new BasicHttpRequest("GET","/");
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant elevenSecondsAgo = now.minusSeconds(11);
|
final Instant elevenSecondsAgo = now.minusSeconds(11);
|
||||||
|
@ -170,7 +169,7 @@ public class TestConditionalRequestBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheEntryWithProxyRevalidateDoesEndToEndRevalidation() throws Exception {
|
void testCacheEntryWithProxyRevalidateDoesEndToEndRevalidation() {
|
||||||
final HttpRequest basicRequest = new BasicHttpRequest("GET", "/");
|
final HttpRequest basicRequest = new BasicHttpRequest("GET", "/");
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant elevenSecondsAgo = now.minusSeconds(11);
|
final Instant elevenSecondsAgo = now.minusSeconds(11);
|
||||||
|
@ -194,15 +193,13 @@ public class TestConditionalRequestBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildUnconditionalRequestUsesGETMethod()
|
void testBuildUnconditionalRequestUsesGETMethod() {
|
||||||
throws Exception {
|
|
||||||
final HttpRequest result = impl.buildUnconditionalRequest(request);
|
final HttpRequest result = impl.buildUnconditionalRequest(request);
|
||||||
Assertions.assertEquals("GET", result.getMethod());
|
Assertions.assertEquals("GET", result.getMethod());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildUnconditionalRequestUsesRequestUri()
|
void testBuildUnconditionalRequestUsesRequestUri() {
|
||||||
throws Exception {
|
|
||||||
final String uri = "/theURI";
|
final String uri = "/theURI";
|
||||||
request = new BasicHttpRequest("GET", uri);
|
request = new BasicHttpRequest("GET", uri);
|
||||||
final HttpRequest result = impl.buildUnconditionalRequest(request);
|
final HttpRequest result = impl.buildUnconditionalRequest(request);
|
||||||
|
@ -210,56 +207,49 @@ public class TestConditionalRequestBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildUnconditionalRequestAddsCacheControlNoCache()
|
void testBuildUnconditionalRequestAddsCacheControlNoCache() {
|
||||||
throws Exception {
|
|
||||||
final HttpRequest result = impl.buildUnconditionalRequest(request);
|
final HttpRequest result = impl.buildUnconditionalRequest(request);
|
||||||
final RequestCacheControl requestCacheControl = CacheControlHeaderParser.INSTANCE.parse(result);
|
final RequestCacheControl requestCacheControl = CacheControlHeaderParser.INSTANCE.parse(result);
|
||||||
Assertions.assertTrue(requestCacheControl.isNoCache());
|
Assertions.assertTrue(requestCacheControl.isNoCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildUnconditionalRequestDoesNotUseIfRange()
|
void testBuildUnconditionalRequestDoesNotUseIfRange() {
|
||||||
throws Exception {
|
|
||||||
request.addHeader("If-Range","\"etag\"");
|
request.addHeader("If-Range","\"etag\"");
|
||||||
final HttpRequest result = impl.buildUnconditionalRequest(request);
|
final HttpRequest result = impl.buildUnconditionalRequest(request);
|
||||||
Assertions.assertNull(result.getFirstHeader("If-Range"));
|
Assertions.assertNull(result.getFirstHeader("If-Range"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildUnconditionalRequestDoesNotUseIfMatch()
|
void testBuildUnconditionalRequestDoesNotUseIfMatch() {
|
||||||
throws Exception {
|
|
||||||
request.addHeader("If-Match","\"etag\"");
|
request.addHeader("If-Match","\"etag\"");
|
||||||
final HttpRequest result = impl.buildUnconditionalRequest(request);
|
final HttpRequest result = impl.buildUnconditionalRequest(request);
|
||||||
Assertions.assertNull(result.getFirstHeader("If-Match"));
|
Assertions.assertNull(result.getFirstHeader("If-Match"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildUnconditionalRequestDoesNotUseIfNoneMatch()
|
void testBuildUnconditionalRequestDoesNotUseIfNoneMatch() {
|
||||||
throws Exception {
|
|
||||||
request.addHeader("If-None-Match","\"etag\"");
|
request.addHeader("If-None-Match","\"etag\"");
|
||||||
final HttpRequest result = impl.buildUnconditionalRequest(request);
|
final HttpRequest result = impl.buildUnconditionalRequest(request);
|
||||||
Assertions.assertNull(result.getFirstHeader("If-None-Match"));
|
Assertions.assertNull(result.getFirstHeader("If-None-Match"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildUnconditionalRequestDoesNotUseIfUnmodifiedSince()
|
void testBuildUnconditionalRequestDoesNotUseIfUnmodifiedSince() {
|
||||||
throws Exception {
|
|
||||||
request.addHeader("If-Unmodified-Since", DateUtils.formatStandardDate(Instant.now()));
|
request.addHeader("If-Unmodified-Since", DateUtils.formatStandardDate(Instant.now()));
|
||||||
final HttpRequest result = impl.buildUnconditionalRequest(request);
|
final HttpRequest result = impl.buildUnconditionalRequest(request);
|
||||||
Assertions.assertNull(result.getFirstHeader("If-Unmodified-Since"));
|
Assertions.assertNull(result.getFirstHeader("If-Unmodified-Since"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildUnconditionalRequestDoesNotUseIfModifiedSince()
|
void testBuildUnconditionalRequestDoesNotUseIfModifiedSince() {
|
||||||
throws Exception {
|
|
||||||
request.addHeader("If-Modified-Since", DateUtils.formatStandardDate(Instant.now()));
|
request.addHeader("If-Modified-Since", DateUtils.formatStandardDate(Instant.now()));
|
||||||
final HttpRequest result = impl.buildUnconditionalRequest(request);
|
final HttpRequest result = impl.buildUnconditionalRequest(request);
|
||||||
Assertions.assertNull(result.getFirstHeader("If-Modified-Since"));
|
Assertions.assertNull(result.getFirstHeader("If-Modified-Since"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildUnconditionalRequestCarriesOtherRequestHeaders()
|
void testBuildUnconditionalRequestCarriesOtherRequestHeaders() {
|
||||||
throws Exception {
|
|
||||||
request.addHeader("User-Agent","MyBrowser/1.0");
|
request.addHeader("User-Agent","MyBrowser/1.0");
|
||||||
final HttpRequest result = impl.buildUnconditionalRequest(request);
|
final HttpRequest result = impl.buildUnconditionalRequest(request);
|
||||||
Assertions.assertEquals("MyBrowser/1.0",
|
Assertions.assertEquals("MyBrowser/1.0",
|
||||||
|
@ -267,7 +257,7 @@ public class TestConditionalRequestBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildConditionalRequestFromVariants() throws Exception {
|
void testBuildConditionalRequestFromVariants() {
|
||||||
final ETag etag1 = new ETag("123");
|
final ETag etag1 = new ETag("123");
|
||||||
final ETag etag2 = new ETag("456");
|
final ETag etag2 = new ETag("456");
|
||||||
final ETag etag3 = new ETag("789");
|
final ETag etag3 = new ETag("789");
|
||||||
|
|
|
@ -33,17 +33,17 @@ import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestFileResourceFactory {
|
class TestFileResourceFactory {
|
||||||
|
|
||||||
CacheKeyGenerator keyGenerator;
|
CacheKeyGenerator keyGenerator;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
keyGenerator = new CacheKeyGenerator();
|
keyGenerator = new CacheKeyGenerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testViaValueLookup() throws Exception {
|
void testViaValueLookup() throws Exception {
|
||||||
final String requestId = keyGenerator.generateKey(new URI("http://localhost/stuff"));
|
final String requestId = keyGenerator.generateKey(new URI("http://localhost/stuff"));
|
||||||
|
|
||||||
Assertions.assertEquals(
|
Assertions.assertEquals(
|
||||||
|
|
|
@ -50,17 +50,17 @@ import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestHttpByteArrayCacheEntrySerializer {
|
class TestHttpByteArrayCacheEntrySerializer {
|
||||||
|
|
||||||
private HttpCacheEntrySerializer<byte[]> httpCacheEntrySerializer;
|
private HttpCacheEntrySerializer<byte[]> httpCacheEntrySerializer;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
httpCacheEntrySerializer = HttpByteArrayCacheEntrySerializer.INSTANCE;
|
httpCacheEntrySerializer = HttpByteArrayCacheEntrySerializer.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleSerializeAndDeserialize() throws Exception {
|
void testSimpleSerializeAndDeserialize() throws Exception {
|
||||||
final String content = "Hello World";
|
final String content = "Hello World";
|
||||||
final ContentType contentType = ContentType.TEXT_PLAIN.withCharset(StandardCharsets.UTF_8);
|
final ContentType contentType = ContentType.TEXT_PLAIN.withCharset(StandardCharsets.UTF_8);
|
||||||
final HttpCacheEntry cacheEntry = new HttpCacheEntry(Instant.now(), Instant.now(),
|
final HttpCacheEntry cacheEntry = new HttpCacheEntry(Instant.now(), Instant.now(),
|
||||||
|
@ -77,7 +77,7 @@ public class TestHttpByteArrayCacheEntrySerializer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerializeAndDeserializeLargeContent() throws Exception {
|
void testSerializeAndDeserializeLargeContent() throws Exception {
|
||||||
final ContentType contentType = ContentType.IMAGE_JPEG;
|
final ContentType contentType = ContentType.IMAGE_JPEG;
|
||||||
final HeapResource resource = load(getClass().getResource("/ApacheLogo.png"));
|
final HeapResource resource = load(getClass().getResource("/ApacheLogo.png"));
|
||||||
final HttpCacheEntry cacheEntry = new HttpCacheEntry(Instant.now(), Instant.now(),
|
final HttpCacheEntry cacheEntry = new HttpCacheEntry(Instant.now(), Instant.now(),
|
||||||
|
@ -97,7 +97,7 @@ public class TestHttpByteArrayCacheEntrySerializer {
|
||||||
* Deserialize a cache entry in a bad format, expecting an exception.
|
* Deserialize a cache entry in a bad format, expecting an exception.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidCacheEntry() throws Exception {
|
void testInvalidCacheEntry() throws Exception {
|
||||||
// This file is a JPEG not a cache entry, so should fail to deserialize
|
// This file is a JPEG not a cache entry, so should fail to deserialize
|
||||||
final HeapResource resource = load(getClass().getResource("/ApacheLogo.png"));
|
final HeapResource resource = load(getClass().getResource("/ApacheLogo.png"));
|
||||||
Assertions.assertThrows(ResourceIOException.class, () ->
|
Assertions.assertThrows(ResourceIOException.class, () ->
|
||||||
|
@ -108,7 +108,7 @@ public class TestHttpByteArrayCacheEntrySerializer {
|
||||||
* Deserialize truncated cache entries.
|
* Deserialize truncated cache entries.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testTruncatedCacheEntry() throws Exception {
|
void testTruncatedCacheEntry() {
|
||||||
final String content1 = HttpByteArrayCacheEntrySerializer.HC_CACHE_VERSION_LINE + "\n" +
|
final String content1 = HttpByteArrayCacheEntrySerializer.HC_CACHE_VERSION_LINE + "\n" +
|
||||||
"HC-Key: unique-cache-key\n" +
|
"HC-Key: unique-cache-key\n" +
|
||||||
"HC-Resource-Length: 11\n" +
|
"HC-Resource-Length: 11\n" +
|
||||||
|
@ -190,7 +190,7 @@ public class TestHttpByteArrayCacheEntrySerializer {
|
||||||
* Deserialize cache entries with a missing mandatory header.
|
* Deserialize cache entries with a missing mandatory header.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testMissingHeaderCacheEntry() throws Exception {
|
void testMissingHeaderCacheEntry() {
|
||||||
final String content1 = HttpByteArrayCacheEntrySerializer.HC_CACHE_VERSION_LINE + "\n" +
|
final String content1 = HttpByteArrayCacheEntrySerializer.HC_CACHE_VERSION_LINE + "\n" +
|
||||||
"HC-Key: unique-cache-key\n" +
|
"HC-Key: unique-cache-key\n" +
|
||||||
"HC-Resource-Length: 11\n" +
|
"HC-Resource-Length: 11\n" +
|
||||||
|
@ -230,7 +230,7 @@ public class TestHttpByteArrayCacheEntrySerializer {
|
||||||
* Deserialize cache entries with an invalid header value.
|
* Deserialize cache entries with an invalid header value.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidHeaderCacheEntry() throws Exception {
|
void testInvalidHeaderCacheEntry() {
|
||||||
final String content1 = HttpByteArrayCacheEntrySerializer.HC_CACHE_VERSION_LINE + "\n" +
|
final String content1 = HttpByteArrayCacheEntrySerializer.HC_CACHE_VERSION_LINE + "\n" +
|
||||||
"HC-Key: unique-cache-key\n" +
|
"HC-Key: unique-cache-key\n" +
|
||||||
"HC-Resource-Length: 11\n" +
|
"HC-Resource-Length: 11\n" +
|
||||||
|
@ -271,7 +271,7 @@ public class TestHttpByteArrayCacheEntrySerializer {
|
||||||
* Deserialize cache entries with an invalid request line.
|
* Deserialize cache entries with an invalid request line.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidRequestLineCacheEntry() throws Exception {
|
void testInvalidRequestLineCacheEntry() {
|
||||||
final String content1 = HttpByteArrayCacheEntrySerializer.HC_CACHE_VERSION_LINE + "\n" +
|
final String content1 = HttpByteArrayCacheEntrySerializer.HC_CACHE_VERSION_LINE + "\n" +
|
||||||
"HC-Key: unique-cache-key\n" +
|
"HC-Key: unique-cache-key\n" +
|
||||||
"HC-Resource-Length: 11\n" +
|
"HC-Resource-Length: 11\n" +
|
||||||
|
@ -295,7 +295,7 @@ public class TestHttpByteArrayCacheEntrySerializer {
|
||||||
* Deserialize cache entries with an invalid request line.
|
* Deserialize cache entries with an invalid request line.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidStatusLineCacheEntry() throws Exception {
|
void testInvalidStatusLineCacheEntry() {
|
||||||
final String content1 = HttpByteArrayCacheEntrySerializer.HC_CACHE_VERSION_LINE + "\n" +
|
final String content1 = HttpByteArrayCacheEntrySerializer.HC_CACHE_VERSION_LINE + "\n" +
|
||||||
"HC-Key: unique-cache-key\n" +
|
"HC-Key: unique-cache-key\n" +
|
||||||
"HC-Resource-Length: 11\n" +
|
"HC-Resource-Length: 11\n" +
|
||||||
|
@ -319,7 +319,7 @@ public class TestHttpByteArrayCacheEntrySerializer {
|
||||||
* Serialize and deserialize a cache entry with no headers.
|
* Serialize and deserialize a cache entry with no headers.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void noHeadersTest() throws Exception {
|
void noHeadersTest() throws Exception {
|
||||||
final String content = "Hello World";
|
final String content = "Hello World";
|
||||||
final ContentType contentType = ContentType.TEXT_PLAIN.withCharset(StandardCharsets.UTF_8);
|
final ContentType contentType = ContentType.TEXT_PLAIN.withCharset(StandardCharsets.UTF_8);
|
||||||
final HttpCacheEntry cacheEntry = new HttpCacheEntry(Instant.now(), Instant.now(),
|
final HttpCacheEntry cacheEntry = new HttpCacheEntry(Instant.now(), Instant.now(),
|
||||||
|
@ -339,7 +339,7 @@ public class TestHttpByteArrayCacheEntrySerializer {
|
||||||
* Serialize and deserialize a cache entry with an empty body.
|
* Serialize and deserialize a cache entry with an empty body.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void emptyBodyTest() throws Exception {
|
void emptyBodyTest() throws Exception {
|
||||||
final HttpCacheEntry cacheEntry = new HttpCacheEntry(Instant.now(), Instant.now(),
|
final HttpCacheEntry cacheEntry = new HttpCacheEntry(Instant.now(), Instant.now(),
|
||||||
"GET", "/stuff", HttpTestUtils.headers(),
|
"GET", "/stuff", HttpTestUtils.headers(),
|
||||||
HttpStatus.SC_OK, HttpTestUtils.headers(),
|
HttpStatus.SC_OK, HttpTestUtils.headers(),
|
||||||
|
@ -357,7 +357,7 @@ public class TestHttpByteArrayCacheEntrySerializer {
|
||||||
* Serialize and deserialize a cache entry with no body.
|
* Serialize and deserialize a cache entry with no body.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void noBodyTest() throws Exception {
|
void noBodyTest() throws Exception {
|
||||||
final HttpCacheEntry cacheEntry = new HttpCacheEntry(Instant.now(), Instant.now(),
|
final HttpCacheEntry cacheEntry = new HttpCacheEntry(Instant.now(), Instant.now(),
|
||||||
"GET", "/stuff", HttpTestUtils.headers(),
|
"GET", "/stuff", HttpTestUtils.headers(),
|
||||||
HttpStatus.SC_OK, HttpTestUtils.headers(),
|
HttpStatus.SC_OK, HttpTestUtils.headers(),
|
||||||
|
@ -375,7 +375,7 @@ public class TestHttpByteArrayCacheEntrySerializer {
|
||||||
* Serialize and deserialize a cache entry with a variant map.
|
* Serialize and deserialize a cache entry with a variant map.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleVariantMap() throws Exception {
|
void testSimpleVariantMap() throws Exception {
|
||||||
final String content = "Hello World";
|
final String content = "Hello World";
|
||||||
final ContentType contentType = ContentType.TEXT_PLAIN.withCharset(StandardCharsets.UTF_8);
|
final ContentType contentType = ContentType.TEXT_PLAIN.withCharset(StandardCharsets.UTF_8);
|
||||||
final Set<String> variants = new HashSet<>();
|
final Set<String> variants = new HashSet<>();
|
||||||
|
@ -398,7 +398,7 @@ public class TestHttpByteArrayCacheEntrySerializer {
|
||||||
* Deserialize cache entries with trailing garbage.
|
* Deserialize cache entries with trailing garbage.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testDeserializeCacheEntryWithTrailingGarbage() throws Exception {
|
void testDeserializeCacheEntryWithTrailingGarbage() {
|
||||||
final String content1 =HttpByteArrayCacheEntrySerializer.HC_CACHE_VERSION_LINE + "\n" +
|
final String content1 =HttpByteArrayCacheEntrySerializer.HC_CACHE_VERSION_LINE + "\n" +
|
||||||
"HC-Key: unique-cache-key\n" +
|
"HC-Key: unique-cache-key\n" +
|
||||||
"HC-Resource-Length: 11\n" +
|
"HC-Resource-Length: 11\n" +
|
||||||
|
|
|
@ -56,7 +56,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
public class TestHttpCacheJiraNumber1147 {
|
class TestHttpCacheJiraNumber1147 {
|
||||||
|
|
||||||
private File cacheDir;
|
private File cacheDir;
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ public class TestHttpCacheJiraNumber1147 {
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
cacheDir = File.createTempFile("cachedir", "");
|
cacheDir = File.createTempFile("cachedir", "");
|
||||||
if (cacheDir.exists()) {
|
if (cacheDir.exists()) {
|
||||||
cacheDir.delete();
|
cacheDir.delete();
|
||||||
|
@ -81,12 +81,12 @@ public class TestHttpCacheJiraNumber1147 {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void cleanUp() {
|
void cleanUp() {
|
||||||
removeCache();
|
removeCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIssue1147() throws Exception {
|
void testIssue1147() throws Exception {
|
||||||
final CacheConfig cacheConfig = CacheConfig.custom()
|
final CacheConfig cacheConfig = CacheConfig.custom()
|
||||||
.setSharedCache(true)
|
.setSharedCache(true)
|
||||||
.setMaxObjectSize(262144) //256kb
|
.setMaxObjectSize(262144) //256kb
|
||||||
|
|
|
@ -33,10 +33,10 @@ import org.apache.hc.client5.http.cache.HttpCacheEntry;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestInternalCacheStorage {
|
class TestInternalCacheStorage {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheBasics() {
|
void testCacheBasics() {
|
||||||
final InternalCacheStorage storage = new InternalCacheStorage();
|
final InternalCacheStorage storage = new InternalCacheStorage();
|
||||||
final String key1 = "some-key-1";
|
final String key1 = "some-key-1";
|
||||||
Assertions.assertNull(storage.get(key1));
|
Assertions.assertNull(storage.get(key1));
|
||||||
|
@ -61,7 +61,7 @@ public class TestInternalCacheStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheEviction() {
|
void testCacheEviction() {
|
||||||
final Queue<HttpCacheEntry> evictedEntries = new LinkedList<>();
|
final Queue<HttpCacheEntry> evictedEntries = new LinkedList<>();
|
||||||
final InternalCacheStorage storage = new InternalCacheStorage(2, e -> evictedEntries.add(e.getContent()));
|
final InternalCacheStorage storage = new InternalCacheStorage(2, e -> evictedEntries.add(e.getContent()));
|
||||||
final String key1 = "some-key-1";
|
final String key1 = "some-key-1";
|
||||||
|
|
|
@ -51,7 +51,7 @@ import org.mockito.MockitoAnnotations;
|
||||||
* This class tests behavior that is allowed (MAY) by the HTTP/1.1 protocol
|
* This class tests behavior that is allowed (MAY) by the HTTP/1.1 protocol
|
||||||
* specification and for which we have implemented the behavior in HTTP cache.
|
* specification and for which we have implemented the behavior in HTTP cache.
|
||||||
*/
|
*/
|
||||||
public class TestProtocolAllowedBehavior {
|
class TestProtocolAllowedBehavior {
|
||||||
|
|
||||||
static final int MAX_BYTES = 1024;
|
static final int MAX_BYTES = 1024;
|
||||||
static final int MAX_ENTRIES = 100;
|
static final int MAX_ENTRIES = 100;
|
||||||
|
@ -73,7 +73,7 @@ public class TestProtocolAllowedBehavior {
|
||||||
HttpCache cache;
|
HttpCache cache;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
MockitoAnnotations.openMocks(this);
|
MockitoAnnotations.openMocks(this);
|
||||||
host = new HttpHost("foo.example.com", 80);
|
host = new HttpHost("foo.example.com", 80);
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ public class TestProtocolAllowedBehavior {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNonSharedCacheMayCacheResponsesWithCacheControlPrivate() throws Exception {
|
void testNonSharedCacheMayCacheResponsesWithCacheControlPrivate() throws Exception {
|
||||||
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET","/");
|
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET","/");
|
||||||
originResponse.setHeader("Cache-Control","private,max-age=3600");
|
originResponse.setHeader("Cache-Control","private,max-age=3600");
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ import org.mockito.MockitoAnnotations;
|
||||||
* compliance with the HTTP/1.1 caching protocol (SHOULD, SHOULD NOT,
|
* compliance with the HTTP/1.1 caching protocol (SHOULD, SHOULD NOT,
|
||||||
* RECOMMENDED, and NOT RECOMMENDED behaviors).
|
* RECOMMENDED, and NOT RECOMMENDED behaviors).
|
||||||
*/
|
*/
|
||||||
public class TestProtocolRecommendations {
|
class TestProtocolRecommendations {
|
||||||
|
|
||||||
static final int MAX_BYTES = 1024;
|
static final int MAX_BYTES = 1024;
|
||||||
static final int MAX_ENTRIES = 100;
|
static final int MAX_ENTRIES = 100;
|
||||||
|
@ -92,7 +92,7 @@ public class TestProtocolRecommendations {
|
||||||
Instant twoMinutesAgo;
|
Instant twoMinutesAgo;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
MockitoAnnotations.openMocks(this);
|
MockitoAnnotations.openMocks(this);
|
||||||
host = new HttpHost("foo.example.com", 80);
|
host = new HttpHost("foo.example.com", 80);
|
||||||
|
|
||||||
|
@ -164,85 +164,85 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cacheGenerated304ForStrongEtagValidatorShouldNotContainAllow() throws Exception {
|
void cacheGenerated304ForStrongEtagValidatorShouldNotContainAllow() throws Exception {
|
||||||
cacheGenerated304ForStrongETagValidatorShouldNotContainEntityHeader(
|
cacheGenerated304ForStrongETagValidatorShouldNotContainEntityHeader(
|
||||||
"Allow", "GET,HEAD");
|
"Allow", "GET,HEAD");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cacheGenerated304ForStrongDateValidatorShouldNotContainAllow() throws Exception {
|
void cacheGenerated304ForStrongDateValidatorShouldNotContainAllow() throws Exception {
|
||||||
cacheGenerated304ForStrongDateValidatorShouldNotContainEntityHeader(
|
cacheGenerated304ForStrongDateValidatorShouldNotContainEntityHeader(
|
||||||
"Allow", "GET,HEAD");
|
"Allow", "GET,HEAD");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cacheGenerated304ForStrongEtagValidatorShouldNotContainContentEncoding() throws Exception {
|
void cacheGenerated304ForStrongEtagValidatorShouldNotContainContentEncoding() throws Exception {
|
||||||
cacheGenerated304ForStrongETagValidatorShouldNotContainEntityHeader(
|
cacheGenerated304ForStrongETagValidatorShouldNotContainEntityHeader(
|
||||||
"Content-Encoding", "gzip");
|
"Content-Encoding", "gzip");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cacheGenerated304ForStrongDateValidatorShouldNotContainContentEncoding() throws Exception {
|
void cacheGenerated304ForStrongDateValidatorShouldNotContainContentEncoding() throws Exception {
|
||||||
cacheGenerated304ForStrongDateValidatorShouldNotContainEntityHeader(
|
cacheGenerated304ForStrongDateValidatorShouldNotContainEntityHeader(
|
||||||
"Content-Encoding", "gzip");
|
"Content-Encoding", "gzip");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cacheGenerated304ForStrongEtagValidatorShouldNotContainContentLanguage() throws Exception {
|
void cacheGenerated304ForStrongEtagValidatorShouldNotContainContentLanguage() throws Exception {
|
||||||
cacheGenerated304ForStrongETagValidatorShouldNotContainEntityHeader(
|
cacheGenerated304ForStrongETagValidatorShouldNotContainEntityHeader(
|
||||||
"Content-Language", "en");
|
"Content-Language", "en");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cacheGenerated304ForStrongDateValidatorShouldNotContainContentLanguage() throws Exception {
|
void cacheGenerated304ForStrongDateValidatorShouldNotContainContentLanguage() throws Exception {
|
||||||
cacheGenerated304ForStrongDateValidatorShouldNotContainEntityHeader(
|
cacheGenerated304ForStrongDateValidatorShouldNotContainEntityHeader(
|
||||||
"Content-Language", "en");
|
"Content-Language", "en");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cacheGenerated304ForStrongValidatorShouldNotContainContentLength() throws Exception {
|
void cacheGenerated304ForStrongValidatorShouldNotContainContentLength() throws Exception {
|
||||||
cacheGenerated304ForStrongETagValidatorShouldNotContainEntityHeader(
|
cacheGenerated304ForStrongETagValidatorShouldNotContainEntityHeader(
|
||||||
"Content-Length", "128");
|
"Content-Length", "128");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cacheGenerated304ForStrongDateValidatorShouldNotContainContentLength() throws Exception {
|
void cacheGenerated304ForStrongDateValidatorShouldNotContainContentLength() throws Exception {
|
||||||
cacheGenerated304ForStrongDateValidatorShouldNotContainEntityHeader(
|
cacheGenerated304ForStrongDateValidatorShouldNotContainEntityHeader(
|
||||||
"Content-Length", "128");
|
"Content-Length", "128");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cacheGenerated304ForStrongValidatorShouldNotContainContentMD5() throws Exception {
|
void cacheGenerated304ForStrongValidatorShouldNotContainContentMD5() throws Exception {
|
||||||
cacheGenerated304ForStrongETagValidatorShouldNotContainEntityHeader(
|
cacheGenerated304ForStrongETagValidatorShouldNotContainEntityHeader(
|
||||||
"Content-MD5", "Q2hlY2sgSW50ZWdyaXR5IQ==");
|
"Content-MD5", "Q2hlY2sgSW50ZWdyaXR5IQ==");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cacheGenerated304ForStrongDateValidatorShouldNotContainContentMD5() throws Exception {
|
void cacheGenerated304ForStrongDateValidatorShouldNotContainContentMD5() throws Exception {
|
||||||
cacheGenerated304ForStrongDateValidatorShouldNotContainEntityHeader(
|
cacheGenerated304ForStrongDateValidatorShouldNotContainEntityHeader(
|
||||||
"Content-MD5", "Q2hlY2sgSW50ZWdyaXR5IQ==");
|
"Content-MD5", "Q2hlY2sgSW50ZWdyaXR5IQ==");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cacheGenerated304ForStrongEtagValidatorShouldNotContainContentType() throws Exception {
|
void cacheGenerated304ForStrongEtagValidatorShouldNotContainContentType() throws Exception {
|
||||||
cacheGenerated304ForStrongETagValidatorShouldNotContainEntityHeader(
|
cacheGenerated304ForStrongETagValidatorShouldNotContainEntityHeader(
|
||||||
"Content-Type", "text/html");
|
"Content-Type", "text/html");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cacheGenerated304ForStrongDateValidatorShouldNotContainContentType() throws Exception {
|
void cacheGenerated304ForStrongDateValidatorShouldNotContainContentType() throws Exception {
|
||||||
cacheGenerated304ForStrongDateValidatorShouldNotContainEntityHeader(
|
cacheGenerated304ForStrongDateValidatorShouldNotContainEntityHeader(
|
||||||
"Content-Type", "text/html");
|
"Content-Type", "text/html");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cacheGenerated304ForStrongEtagValidatorShouldNotContainLastModified() throws Exception {
|
void cacheGenerated304ForStrongEtagValidatorShouldNotContainLastModified() throws Exception {
|
||||||
cacheGenerated304ForStrongETagValidatorShouldNotContainEntityHeader(
|
cacheGenerated304ForStrongETagValidatorShouldNotContainEntityHeader(
|
||||||
"Last-Modified", DateUtils.formatStandardDate(tenSecondsAgo));
|
"Last-Modified", DateUtils.formatStandardDate(tenSecondsAgo));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cacheGenerated304ForStrongDateValidatorShouldNotContainLastModified() throws Exception {
|
void cacheGenerated304ForStrongDateValidatorShouldNotContainLastModified() throws Exception {
|
||||||
cacheGenerated304ForStrongDateValidatorShouldNotContainEntityHeader(
|
cacheGenerated304ForStrongDateValidatorShouldNotContainEntityHeader(
|
||||||
"Last-Modified", DateUtils.formatStandardDate(twoMinutesAgo));
|
"Last-Modified", DateUtils.formatStandardDate(twoMinutesAgo));
|
||||||
}
|
}
|
||||||
|
@ -277,21 +277,21 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotReturnStaleResponseIfClientExplicitlyRequestsFirstHandOneWithCacheControl() throws Exception {
|
void testDoesNotReturnStaleResponseIfClientExplicitlyRequestsFirstHandOneWithCacheControl() throws Exception {
|
||||||
final ClassicHttpRequest req = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req = new BasicClassicHttpRequest("GET", "/");
|
||||||
req.setHeader("Cache-Control","no-cache");
|
req.setHeader("Cache-Control","no-cache");
|
||||||
testDoesNotReturnStaleResponseOnError(req);
|
testDoesNotReturnStaleResponseOnError(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotReturnStaleResponseIfClientExplicitlyRequestsFreshWithMaxAge() throws Exception {
|
void testDoesNotReturnStaleResponseIfClientExplicitlyRequestsFreshWithMaxAge() throws Exception {
|
||||||
final ClassicHttpRequest req = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req = new BasicClassicHttpRequest("GET", "/");
|
||||||
req.setHeader("Cache-Control","max-age=0");
|
req.setHeader("Cache-Control","max-age=0");
|
||||||
testDoesNotReturnStaleResponseOnError(req);
|
testDoesNotReturnStaleResponseOnError(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotReturnStaleResponseIfClientExplicitlySpecifiesLargerMaxAge() throws Exception {
|
void testDoesNotReturnStaleResponseIfClientExplicitlySpecifiesLargerMaxAge() throws Exception {
|
||||||
final ClassicHttpRequest req = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req = new BasicClassicHttpRequest("GET", "/");
|
||||||
req.setHeader("Cache-Control","max-age=20");
|
req.setHeader("Cache-Control","max-age=20");
|
||||||
testDoesNotReturnStaleResponseOnError(req);
|
testDoesNotReturnStaleResponseOnError(req);
|
||||||
|
@ -299,7 +299,7 @@ public class TestProtocolRecommendations {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotReturnStaleResponseIfClientExplicitlyRequestsFreshWithMinFresh() throws Exception {
|
void testDoesNotReturnStaleResponseIfClientExplicitlyRequestsFreshWithMinFresh() throws Exception {
|
||||||
final ClassicHttpRequest req = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req = new BasicClassicHttpRequest("GET", "/");
|
||||||
req.setHeader("Cache-Control","min-fresh=2");
|
req.setHeader("Cache-Control","min-fresh=2");
|
||||||
|
|
||||||
|
@ -307,7 +307,7 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotReturnStaleResponseIfClientExplicitlyRequestsFreshWithMaxStale() throws Exception {
|
void testDoesNotReturnStaleResponseIfClientExplicitlyRequestsFreshWithMaxStale() throws Exception {
|
||||||
final ClassicHttpRequest req = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req = new BasicClassicHttpRequest("GET", "/");
|
||||||
req.setHeader("Cache-Control","max-stale=2");
|
req.setHeader("Cache-Control","max-stale=2");
|
||||||
|
|
||||||
|
@ -315,7 +315,7 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMayReturnStaleResponseIfClientExplicitlySpecifiesAcceptableMaxStale() throws Exception {
|
void testMayReturnStaleResponseIfClientExplicitlySpecifiesAcceptableMaxStale() throws Exception {
|
||||||
final ClassicHttpRequest req1 = requestToPopulateStaleCacheEntry();
|
final ClassicHttpRequest req1 = requestToPopulateStaleCacheEntry();
|
||||||
final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
|
||||||
req2.setHeader("Cache-Control","max-stale=20");
|
req2.setHeader("Cache-Control","max-stale=20");
|
||||||
|
@ -352,20 +352,20 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyAcceptRangesOnResponses() throws Exception {
|
void testDoesNotModifyAcceptRangesOnResponses() throws Exception {
|
||||||
final String headerName = "Accept-Ranges";
|
final String headerName = "Accept-Ranges";
|
||||||
originResponse.setHeader(headerName,"bytes");
|
originResponse.setHeader(headerName,"bytes");
|
||||||
testDoesNotModifyHeaderOnResponses(headerName);
|
testDoesNotModifyHeaderOnResponses(headerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyAuthorizationOnRequests() throws Exception {
|
void testDoesNotModifyAuthorizationOnRequests() throws Exception {
|
||||||
request.setHeader("Authorization", StandardAuthScheme.BASIC + " dXNlcjpwYXNzd2Q=");
|
request.setHeader("Authorization", StandardAuthScheme.BASIC + " dXNlcjpwYXNzd2Q=");
|
||||||
testDoesNotModifyHeaderOnRequests("Authorization");
|
testDoesNotModifyHeaderOnRequests("Authorization");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyContentLengthOnRequests() throws Exception {
|
void testDoesNotModifyContentLengthOnRequests() throws Exception {
|
||||||
final ClassicHttpRequest post = new BasicClassicHttpRequest("POST", "/");
|
final ClassicHttpRequest post = new BasicClassicHttpRequest("POST", "/");
|
||||||
post.setEntity(HttpTestUtils.makeBody(128));
|
post.setEntity(HttpTestUtils.makeBody(128));
|
||||||
post.setHeader("Content-Length","128");
|
post.setHeader("Content-Length","128");
|
||||||
|
@ -374,14 +374,14 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyContentLengthOnResponses() throws Exception {
|
void testDoesNotModifyContentLengthOnResponses() throws Exception {
|
||||||
originResponse.setEntity(HttpTestUtils.makeBody(128));
|
originResponse.setEntity(HttpTestUtils.makeBody(128));
|
||||||
originResponse.setHeader("Content-Length","128");
|
originResponse.setHeader("Content-Length","128");
|
||||||
testDoesNotModifyHeaderOnResponses("Content-Length");
|
testDoesNotModifyHeaderOnResponses("Content-Length");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyContentMD5OnRequests() throws Exception {
|
void testDoesNotModifyContentMD5OnRequests() throws Exception {
|
||||||
final ClassicHttpRequest post = new BasicClassicHttpRequest("POST", "/");
|
final ClassicHttpRequest post = new BasicClassicHttpRequest("POST", "/");
|
||||||
post.setEntity(HttpTestUtils.makeBody(128));
|
post.setEntity(HttpTestUtils.makeBody(128));
|
||||||
post.setHeader("Content-Length","128");
|
post.setHeader("Content-Length","128");
|
||||||
|
@ -391,14 +391,14 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyContentMD5OnResponses() throws Exception {
|
void testDoesNotModifyContentMD5OnResponses() throws Exception {
|
||||||
originResponse.setEntity(HttpTestUtils.makeBody(128));
|
originResponse.setEntity(HttpTestUtils.makeBody(128));
|
||||||
originResponse.setHeader("Content-MD5","Q2hlY2sgSW50ZWdyaXR5IQ==");
|
originResponse.setHeader("Content-MD5","Q2hlY2sgSW50ZWdyaXR5IQ==");
|
||||||
testDoesNotModifyHeaderOnResponses("Content-MD5");
|
testDoesNotModifyHeaderOnResponses("Content-MD5");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyContentRangeOnRequests() throws Exception {
|
void testDoesNotModifyContentRangeOnRequests() throws Exception {
|
||||||
final ClassicHttpRequest put = new BasicClassicHttpRequest("PUT", "/");
|
final ClassicHttpRequest put = new BasicClassicHttpRequest("PUT", "/");
|
||||||
put.setEntity(HttpTestUtils.makeBody(128));
|
put.setEntity(HttpTestUtils.makeBody(128));
|
||||||
put.setHeader("Content-Length","128");
|
put.setHeader("Content-Length","128");
|
||||||
|
@ -408,7 +408,7 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyContentRangeOnResponses() throws Exception {
|
void testDoesNotModifyContentRangeOnResponses() throws Exception {
|
||||||
request.setHeader("Range","bytes=0-128");
|
request.setHeader("Range","bytes=0-128");
|
||||||
originResponse.setCode(HttpStatus.SC_PARTIAL_CONTENT);
|
originResponse.setCode(HttpStatus.SC_PARTIAL_CONTENT);
|
||||||
originResponse.setReasonPhrase("Partial Content");
|
originResponse.setReasonPhrase("Partial Content");
|
||||||
|
@ -418,7 +418,7 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyContentTypeOnRequests() throws Exception {
|
void testDoesNotModifyContentTypeOnRequests() throws Exception {
|
||||||
final ClassicHttpRequest post = new BasicClassicHttpRequest("POST", "/");
|
final ClassicHttpRequest post = new BasicClassicHttpRequest("POST", "/");
|
||||||
post.setEntity(HttpTestUtils.makeBody(128));
|
post.setEntity(HttpTestUtils.makeBody(128));
|
||||||
post.setHeader("Content-Length","128");
|
post.setHeader("Content-Length","128");
|
||||||
|
@ -428,82 +428,82 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyContentTypeOnResponses() throws Exception {
|
void testDoesNotModifyContentTypeOnResponses() throws Exception {
|
||||||
originResponse.setHeader("Content-Type","application/octet-stream");
|
originResponse.setHeader("Content-Type","application/octet-stream");
|
||||||
testDoesNotModifyHeaderOnResponses("Content-Type");
|
testDoesNotModifyHeaderOnResponses("Content-Type");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyDateOnRequests() throws Exception {
|
void testDoesNotModifyDateOnRequests() throws Exception {
|
||||||
request.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
|
request.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
|
||||||
testDoesNotModifyHeaderOnRequests("Date");
|
testDoesNotModifyHeaderOnRequests("Date");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyDateOnResponses() throws Exception {
|
void testDoesNotModifyDateOnResponses() throws Exception {
|
||||||
originResponse.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
|
originResponse.setHeader("Date", DateUtils.formatStandardDate(Instant.now()));
|
||||||
testDoesNotModifyHeaderOnResponses("Date");
|
testDoesNotModifyHeaderOnResponses("Date");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyETagOnResponses() throws Exception {
|
void testDoesNotModifyETagOnResponses() throws Exception {
|
||||||
originResponse.setHeader("ETag", "\"random-etag\"");
|
originResponse.setHeader("ETag", "\"random-etag\"");
|
||||||
testDoesNotModifyHeaderOnResponses("ETag");
|
testDoesNotModifyHeaderOnResponses("ETag");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyExpiresOnResponses() throws Exception {
|
void testDoesNotModifyExpiresOnResponses() throws Exception {
|
||||||
originResponse.setHeader("Expires", DateUtils.formatStandardDate(Instant.now()));
|
originResponse.setHeader("Expires", DateUtils.formatStandardDate(Instant.now()));
|
||||||
testDoesNotModifyHeaderOnResponses("Expires");
|
testDoesNotModifyHeaderOnResponses("Expires");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyFromOnRequests() throws Exception {
|
void testDoesNotModifyFromOnRequests() throws Exception {
|
||||||
request.setHeader("From", "foo@example.com");
|
request.setHeader("From", "foo@example.com");
|
||||||
testDoesNotModifyHeaderOnRequests("From");
|
testDoesNotModifyHeaderOnRequests("From");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyIfMatchOnRequests() throws Exception {
|
void testDoesNotModifyIfMatchOnRequests() throws Exception {
|
||||||
request = new BasicClassicHttpRequest("DELETE", "/");
|
request = new BasicClassicHttpRequest("DELETE", "/");
|
||||||
request.setHeader("If-Match", "\"etag\"");
|
request.setHeader("If-Match", "\"etag\"");
|
||||||
testDoesNotModifyHeaderOnRequests("If-Match");
|
testDoesNotModifyHeaderOnRequests("If-Match");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyIfModifiedSinceOnRequests() throws Exception {
|
void testDoesNotModifyIfModifiedSinceOnRequests() throws Exception {
|
||||||
request.setHeader("If-Modified-Since", DateUtils.formatStandardDate(Instant.now()));
|
request.setHeader("If-Modified-Since", DateUtils.formatStandardDate(Instant.now()));
|
||||||
testDoesNotModifyHeaderOnRequests("If-Modified-Since");
|
testDoesNotModifyHeaderOnRequests("If-Modified-Since");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyIfNoneMatchOnRequests() throws Exception {
|
void testDoesNotModifyIfNoneMatchOnRequests() throws Exception {
|
||||||
request.setHeader("If-None-Match", "\"etag\"");
|
request.setHeader("If-None-Match", "\"etag\"");
|
||||||
testDoesNotModifyHeaderOnRequests("If-None-Match");
|
testDoesNotModifyHeaderOnRequests("If-None-Match");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyIfRangeOnRequests() throws Exception {
|
void testDoesNotModifyIfRangeOnRequests() throws Exception {
|
||||||
request.setHeader("Range","bytes=0-128");
|
request.setHeader("Range","bytes=0-128");
|
||||||
request.setHeader("If-Range", "\"etag\"");
|
request.setHeader("If-Range", "\"etag\"");
|
||||||
testDoesNotModifyHeaderOnRequests("If-Range");
|
testDoesNotModifyHeaderOnRequests("If-Range");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyIfUnmodifiedSinceOnRequests() throws Exception {
|
void testDoesNotModifyIfUnmodifiedSinceOnRequests() throws Exception {
|
||||||
request = new BasicClassicHttpRequest("DELETE", "/");
|
request = new BasicClassicHttpRequest("DELETE", "/");
|
||||||
request.setHeader("If-Unmodified-Since", DateUtils.formatStandardDate(Instant.now()));
|
request.setHeader("If-Unmodified-Since", DateUtils.formatStandardDate(Instant.now()));
|
||||||
testDoesNotModifyHeaderOnRequests("If-Unmodified-Since");
|
testDoesNotModifyHeaderOnRequests("If-Unmodified-Since");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyLastModifiedOnResponses() throws Exception {
|
void testDoesNotModifyLastModifiedOnResponses() throws Exception {
|
||||||
originResponse.setHeader("Last-Modified", DateUtils.formatStandardDate(Instant.now()));
|
originResponse.setHeader("Last-Modified", DateUtils.formatStandardDate(Instant.now()));
|
||||||
testDoesNotModifyHeaderOnResponses("Last-Modified");
|
testDoesNotModifyHeaderOnResponses("Last-Modified");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyLocationOnResponses() throws Exception {
|
void testDoesNotModifyLocationOnResponses() throws Exception {
|
||||||
originResponse.setCode(HttpStatus.SC_TEMPORARY_REDIRECT);
|
originResponse.setCode(HttpStatus.SC_TEMPORARY_REDIRECT);
|
||||||
originResponse.setReasonPhrase("Temporary Redirect");
|
originResponse.setReasonPhrase("Temporary Redirect");
|
||||||
originResponse.setHeader("Location", "http://foo.example.com/bar");
|
originResponse.setHeader("Location", "http://foo.example.com/bar");
|
||||||
|
@ -511,19 +511,19 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyRangeOnRequests() throws Exception {
|
void testDoesNotModifyRangeOnRequests() throws Exception {
|
||||||
request.setHeader("Range", "bytes=0-128");
|
request.setHeader("Range", "bytes=0-128");
|
||||||
testDoesNotModifyHeaderOnRequests("Range");
|
testDoesNotModifyHeaderOnRequests("Range");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyRefererOnRequests() throws Exception {
|
void testDoesNotModifyRefererOnRequests() throws Exception {
|
||||||
request.setHeader("Referer", "http://foo.example.com/bar");
|
request.setHeader("Referer", "http://foo.example.com/bar");
|
||||||
testDoesNotModifyHeaderOnRequests("Referer");
|
testDoesNotModifyHeaderOnRequests("Referer");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyRetryAfterOnResponses() throws Exception {
|
void testDoesNotModifyRetryAfterOnResponses() throws Exception {
|
||||||
originResponse.setCode(HttpStatus.SC_SERVICE_UNAVAILABLE);
|
originResponse.setCode(HttpStatus.SC_SERVICE_UNAVAILABLE);
|
||||||
originResponse.setReasonPhrase("Service Unavailable");
|
originResponse.setReasonPhrase("Service Unavailable");
|
||||||
originResponse.setHeader("Retry-After", "120");
|
originResponse.setHeader("Retry-After", "120");
|
||||||
|
@ -531,38 +531,38 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyServerOnResponses() throws Exception {
|
void testDoesNotModifyServerOnResponses() throws Exception {
|
||||||
originResponse.setHeader("Server", "SomeServer/1.0");
|
originResponse.setHeader("Server", "SomeServer/1.0");
|
||||||
testDoesNotModifyHeaderOnResponses("Server");
|
testDoesNotModifyHeaderOnResponses("Server");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyUserAgentOnRequests() throws Exception {
|
void testDoesNotModifyUserAgentOnRequests() throws Exception {
|
||||||
request.setHeader("User-Agent", "MyClient/1.0");
|
request.setHeader("User-Agent", "MyClient/1.0");
|
||||||
testDoesNotModifyHeaderOnRequests("User-Agent");
|
testDoesNotModifyHeaderOnRequests("User-Agent");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyVaryOnResponses() throws Exception {
|
void testDoesNotModifyVaryOnResponses() throws Exception {
|
||||||
request.setHeader("Accept-Encoding","identity");
|
request.setHeader("Accept-Encoding","identity");
|
||||||
originResponse.setHeader("Vary", "Accept-Encoding");
|
originResponse.setHeader("Vary", "Accept-Encoding");
|
||||||
testDoesNotModifyHeaderOnResponses("Vary");
|
testDoesNotModifyHeaderOnResponses("Vary");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyExtensionHeaderOnRequests() throws Exception {
|
void testDoesNotModifyExtensionHeaderOnRequests() throws Exception {
|
||||||
request.setHeader("X-Extension","x-value");
|
request.setHeader("X-Extension","x-value");
|
||||||
testDoesNotModifyHeaderOnRequests("X-Extension");
|
testDoesNotModifyHeaderOnRequests("X-Extension");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyExtensionHeaderOnResponses() throws Exception {
|
void testDoesNotModifyExtensionHeaderOnResponses() throws Exception {
|
||||||
originResponse.setHeader("X-Extension", "x-value");
|
originResponse.setHeader("X-Extension", "x-value");
|
||||||
testDoesNotModifyHeaderOnResponses("X-Extension");
|
testDoesNotModifyHeaderOnResponses("X-Extension");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUsesLastModifiedDateForCacheConditionalRequests() throws Exception {
|
void testUsesLastModifiedDateForCacheConditionalRequests() throws Exception {
|
||||||
final Instant twentySecondsAgo = now.plusSeconds(20);
|
final Instant twentySecondsAgo = now.plusSeconds(20);
|
||||||
final String lmDate = DateUtils.formatStandardDate(twentySecondsAgo);
|
final String lmDate = DateUtils.formatStandardDate(twentySecondsAgo);
|
||||||
|
|
||||||
|
@ -592,7 +592,7 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUsesBothLastModifiedAndETagForConditionalRequestsIfAvailable() throws Exception {
|
void testUsesBothLastModifiedAndETagForConditionalRequestsIfAvailable() throws Exception {
|
||||||
final Instant twentySecondsAgo = now.plusSeconds(20);
|
final Instant twentySecondsAgo = now.plusSeconds(20);
|
||||||
final String lmDate = DateUtils.formatStandardDate(twentySecondsAgo);
|
final String lmDate = DateUtils.formatStandardDate(twentySecondsAgo);
|
||||||
final String etag = "\"etag\"";
|
final String etag = "\"etag\"";
|
||||||
|
@ -625,7 +625,7 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRevalidatesCachedResponseWithExpirationInThePast() throws Exception {
|
void testRevalidatesCachedResponseWithExpirationInThePast() throws Exception {
|
||||||
final Instant oneSecondAgo = now.minusSeconds(1);
|
final Instant oneSecondAgo = now.minusSeconds(1);
|
||||||
final Instant oneSecondFromNow = now.plusSeconds(1);
|
final Instant oneSecondFromNow = now.plusSeconds(1);
|
||||||
final Instant twoSecondsFromNow = now.plusSeconds(2);
|
final Instant twoSecondsFromNow = now.plusSeconds(2);
|
||||||
|
@ -656,7 +656,7 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRetriesValidationThatResultsInAnOlderDated304Response() throws Exception {
|
void testRetriesValidationThatResultsInAnOlderDated304Response() throws Exception {
|
||||||
final Instant elevenSecondsAgo = now.minusSeconds(11);
|
final Instant elevenSecondsAgo = now.minusSeconds(11);
|
||||||
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
|
@ -708,7 +708,7 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSendsAllVariantEtagsInConditionalRequest() throws Exception {
|
void testSendsAllVariantEtagsInConditionalRequest() throws Exception {
|
||||||
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET","/");
|
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET","/");
|
||||||
req1.setHeader("User-Agent","agent1");
|
req1.setHeader("User-Agent","agent1");
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
|
@ -759,7 +759,7 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponseToExistingVariantsUpdatesEntry() throws Exception {
|
void testResponseToExistingVariantsUpdatesEntry() throws Exception {
|
||||||
|
|
||||||
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
||||||
req1.setHeader("User-Agent", "agent1");
|
req1.setHeader("User-Agent", "agent1");
|
||||||
|
@ -807,7 +807,7 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponseToExistingVariantsIsCachedForFutureResponses() throws Exception {
|
void testResponseToExistingVariantsIsCachedForFutureResponses() throws Exception {
|
||||||
|
|
||||||
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
||||||
req1.setHeader("User-Agent", "agent1");
|
req1.setHeader("User-Agent", "agent1");
|
||||||
|
@ -842,7 +842,7 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldInvalidateNonvariantCacheEntryForUnknownMethod() throws Exception {
|
void shouldInvalidateNonvariantCacheEntryForUnknownMethod() throws Exception {
|
||||||
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
resp1.setHeader("Cache-Control","max-age=3600");
|
resp1.setHeader("Cache-Control","max-age=3600");
|
||||||
|
@ -870,7 +870,7 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldInvalidateAllVariantsForUnknownMethod() throws Exception {
|
void shouldInvalidateAllVariantsForUnknownMethod() throws Exception {
|
||||||
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
||||||
req1.setHeader("User-Agent", "agent1");
|
req1.setHeader("User-Agent", "agent1");
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
|
@ -923,7 +923,7 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cacheShouldUpdateWithNewCacheableResponse() throws Exception {
|
void cacheShouldUpdateWithNewCacheableResponse() throws Exception {
|
||||||
final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
|
resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
|
||||||
|
@ -952,7 +952,7 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void expiresEqualToDateWithNoCacheControlIsNotCacheable() throws Exception {
|
void expiresEqualToDateWithNoCacheControlIsNotCacheable() throws Exception {
|
||||||
final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
resp1.setHeader("Date", DateUtils.formatStandardDate(now));
|
resp1.setHeader("Date", DateUtils.formatStandardDate(now));
|
||||||
|
@ -976,7 +976,7 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void expiresPriorToDateWithNoCacheControlIsNotCacheable() throws Exception {
|
void expiresPriorToDateWithNoCacheControlIsNotCacheable() throws Exception {
|
||||||
final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
resp1.setHeader("Date", DateUtils.formatStandardDate(now));
|
resp1.setHeader("Date", DateUtils.formatStandardDate(now));
|
||||||
|
@ -1000,7 +1000,7 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cacheMissResultsIn504WithOnlyIfCached() throws Exception {
|
void cacheMissResultsIn504WithOnlyIfCached() throws Exception {
|
||||||
final ClassicHttpRequest req = HttpTestUtils.makeDefaultRequest();
|
final ClassicHttpRequest req = HttpTestUtils.makeDefaultRequest();
|
||||||
req.setHeader("Cache-Control", "only-if-cached");
|
req.setHeader("Cache-Control", "only-if-cached");
|
||||||
|
|
||||||
|
@ -1010,7 +1010,7 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cacheHitOkWithOnlyIfCached() throws Exception {
|
void cacheHitOkWithOnlyIfCached() throws Exception {
|
||||||
final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
resp1.setHeader("Cache-Control","max-age=3600");
|
resp1.setHeader("Cache-Control","max-age=3600");
|
||||||
|
@ -1027,7 +1027,7 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void returns504ForStaleEntryWithOnlyIfCached() throws Exception {
|
void returns504ForStaleEntryWithOnlyIfCached() throws Exception {
|
||||||
final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
|
resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
|
||||||
|
@ -1045,7 +1045,7 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void returnsStaleCacheEntryWithOnlyIfCachedAndMaxStale() throws Exception {
|
void returnsStaleCacheEntryWithOnlyIfCachedAndMaxStale() throws Exception {
|
||||||
|
|
||||||
final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
|
@ -1064,7 +1064,7 @@ public class TestProtocolRecommendations {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void issues304EvenWithWeakETag() throws Exception {
|
void issues304EvenWithWeakETag() throws Exception {
|
||||||
final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
|
resp1.setHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo));
|
||||||
|
|
|
@ -72,7 +72,7 @@ import org.mockito.MockitoAnnotations;
|
||||||
* This test class captures functionality required to achieve conditional
|
* This test class captures functionality required to achieve conditional
|
||||||
* compliance with the HTTP/1.1 caching protocol (MUST and MUST NOT behaviors).
|
* compliance with the HTTP/1.1 caching protocol (MUST and MUST NOT behaviors).
|
||||||
*/
|
*/
|
||||||
public class TestProtocolRequirements {
|
class TestProtocolRequirements {
|
||||||
|
|
||||||
static final int MAX_BYTES = 1024;
|
static final int MAX_BYTES = 1024;
|
||||||
static final int MAX_ENTRIES = 100;
|
static final int MAX_ENTRIES = 100;
|
||||||
|
@ -95,7 +95,7 @@ public class TestProtocolRequirements {
|
||||||
HttpCache cache;
|
HttpCache cache;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
MockitoAnnotations.openMocks(this);
|
MockitoAnnotations.openMocks(this);
|
||||||
host = new HttpHost("foo.example.com", 80);
|
host = new HttpHost("foo.example.com", 80);
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheMissOnGETUsesOriginResponse() throws Exception {
|
void testCacheMissOnGETUsesOriginResponse() throws Exception {
|
||||||
|
|
||||||
Mockito.when(mockExecChain.proceed(RequestEquivalent.eq(request), Mockito.any())).thenReturn(originResponse);
|
Mockito.when(mockExecChain.proceed(RequestEquivalent.eq(request), Mockito.any())).thenReturn(originResponse);
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOrderOfMultipleAllowHeadersIsPreservedOnResponses() throws Exception {
|
void testOrderOfMultipleAllowHeadersIsPreservedOnResponses() throws Exception {
|
||||||
originResponse = new BasicClassicHttpResponse(405, "Method Not Allowed");
|
originResponse = new BasicClassicHttpResponse(405, "Method Not Allowed");
|
||||||
originResponse.addHeader("Allow", "HEAD");
|
originResponse.addHeader("Allow", "HEAD");
|
||||||
originResponse.addHeader("Allow", "DELETE");
|
originResponse.addHeader("Allow", "DELETE");
|
||||||
|
@ -157,35 +157,35 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOrderOfMultipleCacheControlHeadersIsPreservedOnResponses() throws Exception {
|
void testOrderOfMultipleCacheControlHeadersIsPreservedOnResponses() throws Exception {
|
||||||
originResponse.addHeader("Cache-Control", "max-age=0");
|
originResponse.addHeader("Cache-Control", "max-age=0");
|
||||||
originResponse.addHeader("Cache-Control", "no-store, must-revalidate");
|
originResponse.addHeader("Cache-Control", "no-store, must-revalidate");
|
||||||
testOrderOfMultipleHeadersIsPreservedOnResponses("Cache-Control");
|
testOrderOfMultipleHeadersIsPreservedOnResponses("Cache-Control");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOrderOfMultipleContentEncodingHeadersIsPreservedOnResponses() throws Exception {
|
void testOrderOfMultipleContentEncodingHeadersIsPreservedOnResponses() throws Exception {
|
||||||
originResponse.addHeader("Content-Encoding", "gzip");
|
originResponse.addHeader("Content-Encoding", "gzip");
|
||||||
originResponse.addHeader("Content-Encoding", "compress");
|
originResponse.addHeader("Content-Encoding", "compress");
|
||||||
testOrderOfMultipleHeadersIsPreservedOnResponses("Content-Encoding");
|
testOrderOfMultipleHeadersIsPreservedOnResponses("Content-Encoding");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOrderOfMultipleContentLanguageHeadersIsPreservedOnResponses() throws Exception {
|
void testOrderOfMultipleContentLanguageHeadersIsPreservedOnResponses() throws Exception {
|
||||||
originResponse.addHeader("Content-Language", "mi");
|
originResponse.addHeader("Content-Language", "mi");
|
||||||
originResponse.addHeader("Content-Language", "en");
|
originResponse.addHeader("Content-Language", "en");
|
||||||
testOrderOfMultipleHeadersIsPreservedOnResponses("Content-Language");
|
testOrderOfMultipleHeadersIsPreservedOnResponses("Content-Language");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOrderOfMultipleViaHeadersIsPreservedOnResponses() throws Exception {
|
void testOrderOfMultipleViaHeadersIsPreservedOnResponses() throws Exception {
|
||||||
originResponse.addHeader(HttpHeaders.VIA, "1.0 fred, 1.1 nowhere.com (Apache/1.1)");
|
originResponse.addHeader(HttpHeaders.VIA, "1.0 fred, 1.1 nowhere.com (Apache/1.1)");
|
||||||
originResponse.addHeader(HttpHeaders.VIA, "1.0 ricky, 1.1 mertz, 1.0 lucy");
|
originResponse.addHeader(HttpHeaders.VIA, "1.0 ricky, 1.1 mertz, 1.0 lucy");
|
||||||
testOrderOfMultipleHeadersIsPreservedOnResponses(HttpHeaders.VIA);
|
testOrderOfMultipleHeadersIsPreservedOnResponses(HttpHeaders.VIA);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOrderOfMultipleWWWAuthenticateHeadersIsPreservedOnResponses() throws Exception {
|
void testOrderOfMultipleWWWAuthenticateHeadersIsPreservedOnResponses() throws Exception {
|
||||||
originResponse.addHeader("WWW-Authenticate", "x-challenge-1");
|
originResponse.addHeader("WWW-Authenticate", "x-challenge-1");
|
||||||
originResponse.addHeader("WWW-Authenticate", "x-challenge-2");
|
originResponse.addHeader("WWW-Authenticate", "x-challenge-2");
|
||||||
testOrderOfMultipleHeadersIsPreservedOnResponses("WWW-Authenticate");
|
testOrderOfMultipleHeadersIsPreservedOnResponses("WWW-Authenticate");
|
||||||
|
@ -208,7 +208,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnknownResponseStatusCodesAreNotCached() throws Exception {
|
void testUnknownResponseStatusCodesAreNotCached() throws Exception {
|
||||||
for (int i = 100; i <= 199; i++) {
|
for (int i = 100; i <= 199; i++) {
|
||||||
testUnknownResponseStatusCodeIsNotCached(i);
|
testUnknownResponseStatusCodeIsNotCached(i);
|
||||||
}
|
}
|
||||||
|
@ -227,7 +227,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnknownHeadersOnRequestsAreForwarded() throws Exception {
|
void testUnknownHeadersOnRequestsAreForwarded() throws Exception {
|
||||||
request.addHeader("X-Unknown-Header", "blahblah");
|
request.addHeader("X-Unknown-Header", "blahblah");
|
||||||
Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(originResponse);
|
Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(originResponse);
|
||||||
|
|
||||||
|
@ -240,7 +240,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnknownHeadersOnResponsesAreForwarded() throws Exception {
|
void testUnknownHeadersOnResponsesAreForwarded() throws Exception {
|
||||||
originResponse.addHeader("X-Unknown-Header", "blahblah");
|
originResponse.addHeader("X-Unknown-Header", "blahblah");
|
||||||
Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(originResponse);
|
Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(originResponse);
|
||||||
|
|
||||||
|
@ -249,7 +249,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponsesToOPTIONSAreNotCacheable() throws Exception {
|
void testResponsesToOPTIONSAreNotCacheable() throws Exception {
|
||||||
request = new BasicClassicHttpRequest("OPTIONS", "/");
|
request = new BasicClassicHttpRequest("OPTIONS", "/");
|
||||||
originResponse.addHeader("Cache-Control", "max-age=3600");
|
originResponse.addHeader("Cache-Control", "max-age=3600");
|
||||||
|
|
||||||
|
@ -261,7 +261,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponsesToPOSTWithoutCacheControlOrExpiresAreNotCached() throws Exception {
|
void testResponsesToPOSTWithoutCacheControlOrExpiresAreNotCached() throws Exception {
|
||||||
|
|
||||||
final BasicClassicHttpRequest post = new BasicClassicHttpRequest("POST", "/");
|
final BasicClassicHttpRequest post = new BasicClassicHttpRequest("POST", "/");
|
||||||
post.setHeader("Content-Length", "128");
|
post.setHeader("Content-Length", "128");
|
||||||
|
@ -278,7 +278,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponsesToPUTsAreNotCached() throws Exception {
|
void testResponsesToPUTsAreNotCached() throws Exception {
|
||||||
|
|
||||||
final BasicClassicHttpRequest put = new BasicClassicHttpRequest("PUT", "/");
|
final BasicClassicHttpRequest put = new BasicClassicHttpRequest("PUT", "/");
|
||||||
put.setEntity(HttpTestUtils.makeBody(128));
|
put.setEntity(HttpTestUtils.makeBody(128));
|
||||||
|
@ -294,7 +294,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponsesToDELETEsAreNotCached() throws Exception {
|
void testResponsesToDELETEsAreNotCached() throws Exception {
|
||||||
|
|
||||||
request = new BasicClassicHttpRequest("DELETE", "/");
|
request = new BasicClassicHttpRequest("DELETE", "/");
|
||||||
originResponse.setHeader("Cache-Control", "max-age=3600");
|
originResponse.setHeader("Cache-Control", "max-age=3600");
|
||||||
|
@ -307,7 +307,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponsesToTRACEsAreNotCached() throws Exception {
|
void testResponsesToTRACEsAreNotCached() throws Exception {
|
||||||
|
|
||||||
request = new BasicClassicHttpRequest("TRACE", "/");
|
request = new BasicClassicHttpRequest("TRACE", "/");
|
||||||
originResponse.setHeader("Cache-Control", "max-age=3600");
|
originResponse.setHeader("Cache-Control", "max-age=3600");
|
||||||
|
@ -320,7 +320,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test304ResponseGeneratedFromCacheIncludesDateHeader() throws Exception {
|
void test304ResponseGeneratedFromCacheIncludesDateHeader() throws Exception {
|
||||||
|
|
||||||
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
||||||
originResponse.setHeader("Cache-Control", "max-age=3600");
|
originResponse.setHeader("Cache-Control", "max-age=3600");
|
||||||
|
@ -340,7 +340,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test304ResponseGeneratedFromCacheIncludesEtagIfOriginResponseDid() throws Exception {
|
void test304ResponseGeneratedFromCacheIncludesEtagIfOriginResponseDid() throws Exception {
|
||||||
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
||||||
originResponse.setHeader("Cache-Control", "max-age=3600");
|
originResponse.setHeader("Cache-Control", "max-age=3600");
|
||||||
originResponse.setHeader("ETag", "\"etag\"");
|
originResponse.setHeader("ETag", "\"etag\"");
|
||||||
|
@ -359,7 +359,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test304ResponseGeneratedFromCacheIncludesContentLocationIfOriginResponseDid() throws Exception {
|
void test304ResponseGeneratedFromCacheIncludesContentLocationIfOriginResponseDid() throws Exception {
|
||||||
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
||||||
originResponse.setHeader("Cache-Control", "max-age=3600");
|
originResponse.setHeader("Cache-Control", "max-age=3600");
|
||||||
originResponse.setHeader("Content-Location", "http://foo.example.com/other");
|
originResponse.setHeader("Content-Location", "http://foo.example.com/other");
|
||||||
|
@ -379,7 +379,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test304ResponseGeneratedFromCacheIncludesExpiresCacheControlAndOrVaryIfResponseMightDiffer() throws Exception {
|
void test304ResponseGeneratedFromCacheIncludesExpiresCacheControlAndOrVaryIfResponseMightDiffer() throws Exception {
|
||||||
|
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant inTwoHours = now.plus(2, ChronoUnit.HOURS);
|
final Instant inTwoHours = now.plus(2, ChronoUnit.HOURS);
|
||||||
|
@ -426,7 +426,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test304GeneratedFromCacheOnWeakValidatorDoesNotIncludeOtherEntityHeaders() throws Exception {
|
void test304GeneratedFromCacheOnWeakValidatorDoesNotIncludeOtherEntityHeaders() throws Exception {
|
||||||
|
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant oneHourAgo = now.minus(1, ChronoUnit.HOURS);
|
final Instant oneHourAgo = now.minus(1, ChronoUnit.HOURS);
|
||||||
|
@ -463,7 +463,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotModifiedOfNonCachedEntityShouldRevalidateWithUnconditionalGET() throws Exception {
|
void testNotModifiedOfNonCachedEntityShouldRevalidateWithUnconditionalGET() throws Exception {
|
||||||
|
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
|
|
||||||
|
@ -497,7 +497,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheEntryIsUpdatedWithNewFieldValuesIn304Response() throws Exception {
|
void testCacheEntryIsUpdatedWithNewFieldValuesIn304Response() throws Exception {
|
||||||
|
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant inFiveSeconds = now.plusSeconds(5);
|
final Instant inFiveSeconds = now.plusSeconds(5);
|
||||||
|
@ -539,7 +539,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMustReturnACacheEntryIfItCanRevalidateIt() throws Exception {
|
void testMustReturnACacheEntryIfItCanRevalidateIt() throws Exception {
|
||||||
|
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant tenSecondsAgo = now.minusSeconds(10);
|
final Instant tenSecondsAgo = now.minusSeconds(10);
|
||||||
|
@ -594,7 +594,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMustReturnAFreshEnoughCacheEntryIfItHasIt() throws Exception {
|
void testMustReturnAFreshEnoughCacheEntryIfItHasIt() throws Exception {
|
||||||
|
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant tenSecondsAgo = now.minusSeconds(10);
|
final Instant tenSecondsAgo = now.minusSeconds(10);
|
||||||
|
@ -624,7 +624,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAgeHeaderPopulatedFromCacheEntryCurrentAge() throws Exception {
|
void testAgeHeaderPopulatedFromCacheEntryCurrentAge() throws Exception {
|
||||||
|
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant tenSecondsAgo = now.minusSeconds(10);
|
final Instant tenSecondsAgo = now.minusSeconds(10);
|
||||||
|
@ -661,7 +661,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testKeepsMostRecentDateHeaderForFreshResponse() throws Exception {
|
void testKeepsMostRecentDateHeaderForFreshResponse() throws Exception {
|
||||||
|
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant inFiveSecond = now.plusSeconds(5);
|
final Instant inFiveSecond = now.plusSeconds(5);
|
||||||
|
@ -699,7 +699,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValidationMustUseETagIfProvidedByOriginServer() throws Exception {
|
void testValidationMustUseETagIfProvidedByOriginServer() throws Exception {
|
||||||
|
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant tenSecondsAgo = now.minusSeconds(10);
|
final Instant tenSecondsAgo = now.minusSeconds(10);
|
||||||
|
@ -744,7 +744,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConditionalRequestWhereNotAllValidatorsMatchCannotBeServedFromCache() throws Exception {
|
void testConditionalRequestWhereNotAllValidatorsMatchCannotBeServedFromCache() throws Exception {
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant tenSecondsAgo = now.minusSeconds(10);
|
final Instant tenSecondsAgo = now.minusSeconds(10);
|
||||||
final Instant twentySecondsAgo = now.plusSeconds(20);
|
final Instant twentySecondsAgo = now.plusSeconds(20);
|
||||||
|
@ -771,7 +771,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConditionalRequestWhereAllValidatorsMatchMayBeServedFromCache() throws Exception {
|
void testConditionalRequestWhereAllValidatorsMatchMayBeServedFromCache() throws Exception {
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant tenSecondsAgo = now.minusSeconds(10);
|
final Instant tenSecondsAgo = now.minusSeconds(10);
|
||||||
|
|
||||||
|
@ -797,7 +797,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheWithoutSupportForRangeAndContentRangeHeadersDoesNotCacheA206Response() throws Exception {
|
void testCacheWithoutSupportForRangeAndContentRangeHeadersDoesNotCacheA206Response() throws Exception {
|
||||||
final ClassicHttpRequest req = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req = new BasicClassicHttpRequest("GET", "/");
|
||||||
req.setHeader("Range", "bytes=0-50");
|
req.setHeader("Range", "bytes=0-50");
|
||||||
|
|
||||||
|
@ -814,7 +814,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test302ResponseWithoutExplicitCacheabilityIsNotReturnedFromCache() throws Exception {
|
void test302ResponseWithoutExplicitCacheabilityIsNotReturnedFromCache() throws Exception {
|
||||||
originResponse = new BasicClassicHttpResponse(302, "Temporary Redirect");
|
originResponse = new BasicClassicHttpResponse(302, "Temporary Redirect");
|
||||||
originResponse.setHeader("Location", "http://foo.example.com/other");
|
originResponse.setHeader("Location", "http://foo.example.com/other");
|
||||||
originResponse.removeHeaders("Expires");
|
originResponse.removeHeaders("Expires");
|
||||||
|
@ -840,24 +840,24 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyContentLocationHeaderFromOrigin() throws Exception {
|
void testDoesNotModifyContentLocationHeaderFromOrigin() throws Exception {
|
||||||
|
|
||||||
final String url = "http://foo.example.com/other";
|
final String url = "http://foo.example.com/other";
|
||||||
testDoesNotModifyHeaderFromOrigin("Content-Location", url);
|
testDoesNotModifyHeaderFromOrigin("Content-Location", url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyContentMD5HeaderFromOrigin() throws Exception {
|
void testDoesNotModifyContentMD5HeaderFromOrigin() throws Exception {
|
||||||
testDoesNotModifyHeaderFromOrigin("Content-MD5", "Q2hlY2sgSW50ZWdyaXR5IQ==");
|
testDoesNotModifyHeaderFromOrigin("Content-MD5", "Q2hlY2sgSW50ZWdyaXR5IQ==");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyEtagHeaderFromOrigin() throws Exception {
|
void testDoesNotModifyEtagHeaderFromOrigin() throws Exception {
|
||||||
testDoesNotModifyHeaderFromOrigin("Etag", "\"the-etag\"");
|
testDoesNotModifyHeaderFromOrigin("Etag", "\"the-etag\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyLastModifiedHeaderFromOrigin() throws Exception {
|
void testDoesNotModifyLastModifiedHeaderFromOrigin() throws Exception {
|
||||||
final String lm = DateUtils.formatStandardDate(Instant.now());
|
final String lm = DateUtils.formatStandardDate(Instant.now());
|
||||||
testDoesNotModifyHeaderFromOrigin("Last-Modified", lm);
|
testDoesNotModifyHeaderFromOrigin("Last-Modified", lm);
|
||||||
}
|
}
|
||||||
|
@ -873,22 +873,22 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotAddContentLocationToOriginResponse() throws Exception {
|
void testDoesNotAddContentLocationToOriginResponse() throws Exception {
|
||||||
testDoesNotAddHeaderToOriginResponse("Content-Location");
|
testDoesNotAddHeaderToOriginResponse("Content-Location");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotAddContentMD5ToOriginResponse() throws Exception {
|
void testDoesNotAddContentMD5ToOriginResponse() throws Exception {
|
||||||
testDoesNotAddHeaderToOriginResponse("Content-MD5");
|
testDoesNotAddHeaderToOriginResponse("Content-MD5");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotAddEtagToOriginResponse() throws Exception {
|
void testDoesNotAddEtagToOriginResponse() throws Exception {
|
||||||
testDoesNotAddHeaderToOriginResponse("ETag");
|
testDoesNotAddHeaderToOriginResponse("ETag");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotAddLastModifiedToOriginResponse() throws Exception {
|
void testDoesNotAddLastModifiedToOriginResponse() throws Exception {
|
||||||
testDoesNotAddHeaderToOriginResponse("Last-Modified");
|
testDoesNotAddHeaderToOriginResponse("Last-Modified");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -910,23 +910,23 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyContentLocationFromOriginOnCacheHit() throws Exception {
|
void testDoesNotModifyContentLocationFromOriginOnCacheHit() throws Exception {
|
||||||
final String url = "http://foo.example.com/other";
|
final String url = "http://foo.example.com/other";
|
||||||
testDoesNotModifyHeaderFromOriginOnCacheHit("Content-Location", url);
|
testDoesNotModifyHeaderFromOriginOnCacheHit("Content-Location", url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyContentMD5FromOriginOnCacheHit() throws Exception {
|
void testDoesNotModifyContentMD5FromOriginOnCacheHit() throws Exception {
|
||||||
testDoesNotModifyHeaderFromOriginOnCacheHit("Content-MD5", "Q2hlY2sgSW50ZWdyaXR5IQ==");
|
testDoesNotModifyHeaderFromOriginOnCacheHit("Content-MD5", "Q2hlY2sgSW50ZWdyaXR5IQ==");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyEtagFromOriginOnCacheHit() throws Exception {
|
void testDoesNotModifyEtagFromOriginOnCacheHit() throws Exception {
|
||||||
testDoesNotModifyHeaderFromOriginOnCacheHit("Etag", "\"the-etag\"");
|
testDoesNotModifyHeaderFromOriginOnCacheHit("Etag", "\"the-etag\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyLastModifiedFromOriginOnCacheHit() throws Exception {
|
void testDoesNotModifyLastModifiedFromOriginOnCacheHit() throws Exception {
|
||||||
final Instant tenSecondsAgo = Instant.now().minusSeconds(10);
|
final Instant tenSecondsAgo = Instant.now().minusSeconds(10);
|
||||||
testDoesNotModifyHeaderFromOriginOnCacheHit("Last-Modified", DateUtils.formatStandardDate(tenSecondsAgo));
|
testDoesNotModifyHeaderFromOriginOnCacheHit("Last-Modified", DateUtils.formatStandardDate(tenSecondsAgo));
|
||||||
}
|
}
|
||||||
|
@ -948,22 +948,22 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotAddContentLocationHeaderOnCacheHit() throws Exception {
|
void testDoesNotAddContentLocationHeaderOnCacheHit() throws Exception {
|
||||||
testDoesNotAddHeaderOnCacheHit("Content-Location");
|
testDoesNotAddHeaderOnCacheHit("Content-Location");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotAddContentMD5HeaderOnCacheHit() throws Exception {
|
void testDoesNotAddContentMD5HeaderOnCacheHit() throws Exception {
|
||||||
testDoesNotAddHeaderOnCacheHit("Content-MD5");
|
testDoesNotAddHeaderOnCacheHit("Content-MD5");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotAddETagHeaderOnCacheHit() throws Exception {
|
void testDoesNotAddETagHeaderOnCacheHit() throws Exception {
|
||||||
testDoesNotAddHeaderOnCacheHit("ETag");
|
testDoesNotAddHeaderOnCacheHit("ETag");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotAddLastModifiedHeaderOnCacheHit() throws Exception {
|
void testDoesNotAddLastModifiedHeaderOnCacheHit() throws Exception {
|
||||||
testDoesNotAddHeaderOnCacheHit("Last-Modified");
|
testDoesNotAddHeaderOnCacheHit("Last-Modified");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -983,23 +983,23 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyContentLocationHeaderOnRequest() throws Exception {
|
void testDoesNotModifyContentLocationHeaderOnRequest() throws Exception {
|
||||||
final String url = "http://foo.example.com/other";
|
final String url = "http://foo.example.com/other";
|
||||||
testDoesNotModifyHeaderOnRequest("Content-Location",url);
|
testDoesNotModifyHeaderOnRequest("Content-Location",url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyContentMD5HeaderOnRequest() throws Exception {
|
void testDoesNotModifyContentMD5HeaderOnRequest() throws Exception {
|
||||||
testDoesNotModifyHeaderOnRequest("Content-MD5", "Q2hlY2sgSW50ZWdyaXR5IQ==");
|
testDoesNotModifyHeaderOnRequest("Content-MD5", "Q2hlY2sgSW50ZWdyaXR5IQ==");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyETagHeaderOnRequest() throws Exception {
|
void testDoesNotModifyETagHeaderOnRequest() throws Exception {
|
||||||
testDoesNotModifyHeaderOnRequest("ETag","\"etag\"");
|
testDoesNotModifyHeaderOnRequest("ETag","\"etag\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyLastModifiedHeaderOnRequest() throws Exception {
|
void testDoesNotModifyLastModifiedHeaderOnRequest() throws Exception {
|
||||||
final Instant tenSecondsAgo = Instant.now().minusSeconds(10);
|
final Instant tenSecondsAgo = Instant.now().minusSeconds(10);
|
||||||
testDoesNotModifyHeaderOnRequest("Last-Modified", DateUtils.formatStandardDate(tenSecondsAgo));
|
testDoesNotModifyHeaderOnRequest("Last-Modified", DateUtils.formatStandardDate(tenSecondsAgo));
|
||||||
}
|
}
|
||||||
|
@ -1022,39 +1022,39 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotAddContentLocationToRequestIfNotPresent() throws Exception {
|
void testDoesNotAddContentLocationToRequestIfNotPresent() throws Exception {
|
||||||
testDoesNotAddHeaderToRequestIfNotPresent("Content-Location");
|
testDoesNotAddHeaderToRequestIfNotPresent("Content-Location");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotAddContentMD5ToRequestIfNotPresent() throws Exception {
|
void testDoesNotAddContentMD5ToRequestIfNotPresent() throws Exception {
|
||||||
testDoesNotAddHeaderToRequestIfNotPresent("Content-MD5");
|
testDoesNotAddHeaderToRequestIfNotPresent("Content-MD5");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotAddETagToRequestIfNotPresent() throws Exception {
|
void testDoesNotAddETagToRequestIfNotPresent() throws Exception {
|
||||||
testDoesNotAddHeaderToRequestIfNotPresent("ETag");
|
testDoesNotAddHeaderToRequestIfNotPresent("ETag");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotAddLastModifiedToRequestIfNotPresent() throws Exception {
|
void testDoesNotAddLastModifiedToRequestIfNotPresent() throws Exception {
|
||||||
testDoesNotAddHeaderToRequestIfNotPresent("Last-Modified");
|
testDoesNotAddHeaderToRequestIfNotPresent("Last-Modified");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyExpiresHeaderFromOrigin() throws Exception {
|
void testDoesNotModifyExpiresHeaderFromOrigin() throws Exception {
|
||||||
final Instant tenSecondsAgo = Instant.now().minusSeconds(10);
|
final Instant tenSecondsAgo = Instant.now().minusSeconds(10);
|
||||||
testDoesNotModifyHeaderFromOrigin("Expires", DateUtils.formatStandardDate(tenSecondsAgo));
|
testDoesNotModifyHeaderFromOrigin("Expires", DateUtils.formatStandardDate(tenSecondsAgo));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyExpiresHeaderFromOriginOnCacheHit() throws Exception {
|
void testDoesNotModifyExpiresHeaderFromOriginOnCacheHit() throws Exception {
|
||||||
final Instant inTenSeconds = Instant.now().plusSeconds(10);
|
final Instant inTenSeconds = Instant.now().plusSeconds(10);
|
||||||
testDoesNotModifyHeaderFromOriginOnCacheHit("Expires", DateUtils.formatStandardDate(inTenSeconds));
|
testDoesNotModifyHeaderFromOriginOnCacheHit("Expires", DateUtils.formatStandardDate(inTenSeconds));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExpiresHeaderMatchesDateIfAddedToOriginResponse() throws Exception {
|
void testExpiresHeaderMatchesDateIfAddedToOriginResponse() throws Exception {
|
||||||
originResponse.removeHeaders("Expires");
|
originResponse.removeHeaders("Expires");
|
||||||
|
|
||||||
Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(originResponse);
|
Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(originResponse);
|
||||||
|
@ -1080,12 +1080,12 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyContentEncodingHeaderFromOriginResponseWithNoTransform() throws Exception {
|
void testDoesNotModifyContentEncodingHeaderFromOriginResponseWithNoTransform() throws Exception {
|
||||||
testDoesNotModifyHeaderFromOriginResponseWithNoTransform("Content-Encoding","gzip");
|
testDoesNotModifyHeaderFromOriginResponseWithNoTransform("Content-Encoding","gzip");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyContentRangeHeaderFromOriginResponseWithNoTransform() throws Exception {
|
void testDoesNotModifyContentRangeHeaderFromOriginResponseWithNoTransform() throws Exception {
|
||||||
request.setHeader("If-Range","\"etag\"");
|
request.setHeader("If-Range","\"etag\"");
|
||||||
request.setHeader("Range","bytes=0-49");
|
request.setHeader("Range","bytes=0-49");
|
||||||
|
|
||||||
|
@ -1095,7 +1095,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyContentTypeHeaderFromOriginResponseWithNoTransform() throws Exception {
|
void testDoesNotModifyContentTypeHeaderFromOriginResponseWithNoTransform() throws Exception {
|
||||||
testDoesNotModifyHeaderFromOriginResponseWithNoTransform("Content-Type","text/html;charset=utf-8");
|
testDoesNotModifyHeaderFromOriginResponseWithNoTransform("Content-Type","text/html;charset=utf-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1115,85 +1115,85 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyContentEncodingHeaderOnCachedResponseWithNoTransform() throws Exception {
|
void testDoesNotModifyContentEncodingHeaderOnCachedResponseWithNoTransform() throws Exception {
|
||||||
testDoesNotModifyHeaderOnCachedResponseWithNoTransform("Content-Encoding","gzip");
|
testDoesNotModifyHeaderOnCachedResponseWithNoTransform("Content-Encoding","gzip");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyContentTypeHeaderOnCachedResponseWithNoTransform() throws Exception {
|
void testDoesNotModifyContentTypeHeaderOnCachedResponseWithNoTransform() throws Exception {
|
||||||
testDoesNotModifyHeaderOnCachedResponseWithNoTransform("Content-Type","text/html;charset=utf-8");
|
testDoesNotModifyHeaderOnCachedResponseWithNoTransform("Content-Type","text/html;charset=utf-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotAddContentEncodingHeaderToOriginResponseWithNoTransformIfNotPresent() throws Exception {
|
void testDoesNotAddContentEncodingHeaderToOriginResponseWithNoTransformIfNotPresent() throws Exception {
|
||||||
originResponse.addHeader("Cache-Control","no-transform");
|
originResponse.addHeader("Cache-Control","no-transform");
|
||||||
testDoesNotAddHeaderToOriginResponse("Content-Encoding");
|
testDoesNotAddHeaderToOriginResponse("Content-Encoding");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotAddContentRangeHeaderToOriginResponseWithNoTransformIfNotPresent() throws Exception {
|
void testDoesNotAddContentRangeHeaderToOriginResponseWithNoTransformIfNotPresent() throws Exception {
|
||||||
originResponse.addHeader("Cache-Control","no-transform");
|
originResponse.addHeader("Cache-Control","no-transform");
|
||||||
testDoesNotAddHeaderToOriginResponse("Content-Range");
|
testDoesNotAddHeaderToOriginResponse("Content-Range");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotAddContentTypeHeaderToOriginResponseWithNoTransformIfNotPresent() throws Exception {
|
void testDoesNotAddContentTypeHeaderToOriginResponseWithNoTransformIfNotPresent() throws Exception {
|
||||||
originResponse.addHeader("Cache-Control","no-transform");
|
originResponse.addHeader("Cache-Control","no-transform");
|
||||||
testDoesNotAddHeaderToOriginResponse("Content-Type");
|
testDoesNotAddHeaderToOriginResponse("Content-Type");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* no add on cache hit with no-transform */
|
/* no add on cache hit with no-transform */
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotAddContentEncodingHeaderToCachedResponseWithNoTransformIfNotPresent() throws Exception {
|
void testDoesNotAddContentEncodingHeaderToCachedResponseWithNoTransformIfNotPresent() throws Exception {
|
||||||
originResponse.addHeader("Cache-Control","no-transform");
|
originResponse.addHeader("Cache-Control","no-transform");
|
||||||
testDoesNotAddHeaderOnCacheHit("Content-Encoding");
|
testDoesNotAddHeaderOnCacheHit("Content-Encoding");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotAddContentRangeHeaderToCachedResponseWithNoTransformIfNotPresent() throws Exception {
|
void testDoesNotAddContentRangeHeaderToCachedResponseWithNoTransformIfNotPresent() throws Exception {
|
||||||
originResponse.addHeader("Cache-Control","no-transform");
|
originResponse.addHeader("Cache-Control","no-transform");
|
||||||
testDoesNotAddHeaderOnCacheHit("Content-Range");
|
testDoesNotAddHeaderOnCacheHit("Content-Range");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotAddContentTypeHeaderToCachedResponseWithNoTransformIfNotPresent() throws Exception {
|
void testDoesNotAddContentTypeHeaderToCachedResponseWithNoTransformIfNotPresent() throws Exception {
|
||||||
originResponse.addHeader("Cache-Control","no-transform");
|
originResponse.addHeader("Cache-Control","no-transform");
|
||||||
testDoesNotAddHeaderOnCacheHit("Content-Type");
|
testDoesNotAddHeaderOnCacheHit("Content-Type");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* no modify on request */
|
/* no modify on request */
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotAddContentEncodingToRequestIfNotPresent() throws Exception {
|
void testDoesNotAddContentEncodingToRequestIfNotPresent() throws Exception {
|
||||||
testDoesNotAddHeaderToRequestIfNotPresent("Content-Encoding");
|
testDoesNotAddHeaderToRequestIfNotPresent("Content-Encoding");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotAddContentRangeToRequestIfNotPresent() throws Exception {
|
void testDoesNotAddContentRangeToRequestIfNotPresent() throws Exception {
|
||||||
testDoesNotAddHeaderToRequestIfNotPresent("Content-Range");
|
testDoesNotAddHeaderToRequestIfNotPresent("Content-Range");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotAddContentTypeToRequestIfNotPresent() throws Exception {
|
void testDoesNotAddContentTypeToRequestIfNotPresent() throws Exception {
|
||||||
testDoesNotAddHeaderToRequestIfNotPresent("Content-Type");
|
testDoesNotAddHeaderToRequestIfNotPresent("Content-Type");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotAddContentEncodingHeaderToRequestIfNotPresent() throws Exception {
|
void testDoesNotAddContentEncodingHeaderToRequestIfNotPresent() throws Exception {
|
||||||
testDoesNotAddHeaderToRequestIfNotPresent("Content-Encoding");
|
testDoesNotAddHeaderToRequestIfNotPresent("Content-Encoding");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotAddContentRangeHeaderToRequestIfNotPresent() throws Exception {
|
void testDoesNotAddContentRangeHeaderToRequestIfNotPresent() throws Exception {
|
||||||
testDoesNotAddHeaderToRequestIfNotPresent("Content-Range");
|
testDoesNotAddHeaderToRequestIfNotPresent("Content-Range");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotAddContentTypeHeaderToRequestIfNotPresent() throws Exception {
|
void testDoesNotAddContentTypeHeaderToRequestIfNotPresent() throws Exception {
|
||||||
testDoesNotAddHeaderToRequestIfNotPresent("Content-Type");
|
testDoesNotAddHeaderToRequestIfNotPresent("Content-Type");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCachedEntityBodyIsUsedForResponseAfter304Validation() throws Exception {
|
void testCachedEntityBodyIsUsedForResponseAfter304Validation() throws Exception {
|
||||||
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
resp1.setHeader("Cache-Control","max-age=3600");
|
resp1.setHeader("Cache-Control","max-age=3600");
|
||||||
|
@ -1238,7 +1238,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponseIncludesCacheEntryEndToEndHeadersForResponseAfter304Validation() throws Exception {
|
void testResponseIncludesCacheEntryEndToEndHeadersForResponseAfter304Validation() throws Exception {
|
||||||
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
resp1.setHeader("Cache-Control","max-age=3600");
|
resp1.setHeader("Cache-Control","max-age=3600");
|
||||||
|
@ -1271,7 +1271,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdatedEndToEndHeadersFrom304ArePassedOnResponseAndUpdatedInCacheEntry() throws Exception {
|
void testUpdatedEndToEndHeadersFrom304ArePassedOnResponseAndUpdatedInCacheEntry() throws Exception {
|
||||||
|
|
||||||
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
|
@ -1317,7 +1317,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultiHeadersAreSuccessfullyReplacedOn304Validation() throws Exception {
|
void testMultiHeadersAreSuccessfullyReplacedOn304Validation() throws Exception {
|
||||||
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
resp1.addHeader("Cache-Control","max-age=3600");
|
resp1.addHeader("Cache-Control","max-age=3600");
|
||||||
|
@ -1348,7 +1348,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCannotUseVariantCacheEntryIfNotAllSelectingRequestHeadersMatch() throws Exception {
|
void testCannotUseVariantCacheEntryIfNotAllSelectingRequestHeadersMatch() throws Exception {
|
||||||
|
|
||||||
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
||||||
req1.setHeader("Accept-Encoding","gzip");
|
req1.setHeader("Accept-Encoding","gzip");
|
||||||
|
@ -1378,7 +1378,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCannotServeFromCacheForVaryStar() throws Exception {
|
void testCannotServeFromCacheForVaryStar() throws Exception {
|
||||||
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
||||||
|
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
|
@ -1405,7 +1405,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNonMatchingVariantCannotBeServedFromCacheUnlessConditionallyValidated() throws Exception {
|
void testNonMatchingVariantCannotBeServedFromCacheUnlessConditionallyValidated() throws Exception {
|
||||||
|
|
||||||
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
||||||
req1.setHeader("User-Agent","MyBrowser/1.0");
|
req1.setHeader("User-Agent","MyBrowser/1.0");
|
||||||
|
@ -1473,19 +1473,19 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPutToUriInvalidatesCacheForThatUri() throws Exception {
|
void testPutToUriInvalidatesCacheForThatUri() throws Exception {
|
||||||
final ClassicHttpRequest req = makeRequestWithBody("PUT","/");
|
final ClassicHttpRequest req = makeRequestWithBody("PUT","/");
|
||||||
testUnsafeOperationInvalidatesCacheForThatUri(req);
|
testUnsafeOperationInvalidatesCacheForThatUri(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteToUriInvalidatesCacheForThatUri() throws Exception {
|
void testDeleteToUriInvalidatesCacheForThatUri() throws Exception {
|
||||||
final ClassicHttpRequest req = new BasicClassicHttpRequest("DELETE","/");
|
final ClassicHttpRequest req = new BasicClassicHttpRequest("DELETE","/");
|
||||||
testUnsafeOperationInvalidatesCacheForThatUri(req);
|
testUnsafeOperationInvalidatesCacheForThatUri(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPostToUriInvalidatesCacheForThatUri() throws Exception {
|
void testPostToUriInvalidatesCacheForThatUri() throws Exception {
|
||||||
final ClassicHttpRequest req = makeRequestWithBody("POST","/");
|
final ClassicHttpRequest req = makeRequestWithBody("POST","/");
|
||||||
testUnsafeOperationInvalidatesCacheForThatUri(req);
|
testUnsafeOperationInvalidatesCacheForThatUri(req);
|
||||||
}
|
}
|
||||||
|
@ -1535,55 +1535,55 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPutInvalidatesCacheForThatUriInContentLocationHeader() throws Exception {
|
void testPutInvalidatesCacheForThatUriInContentLocationHeader() throws Exception {
|
||||||
final ClassicHttpRequest req2 = makeRequestWithBody("PUT","/");
|
final ClassicHttpRequest req2 = makeRequestWithBody("PUT","/");
|
||||||
testUnsafeMethodInvalidatesCacheForUriInContentLocationHeader(req2);
|
testUnsafeMethodInvalidatesCacheForUriInContentLocationHeader(req2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPutInvalidatesCacheForThatUriInLocationHeader() throws Exception {
|
void testPutInvalidatesCacheForThatUriInLocationHeader() throws Exception {
|
||||||
final ClassicHttpRequest req = makeRequestWithBody("PUT","/");
|
final ClassicHttpRequest req = makeRequestWithBody("PUT","/");
|
||||||
testUnsafeMethodInvalidatesCacheForUriInLocationHeader(req);
|
testUnsafeMethodInvalidatesCacheForUriInLocationHeader(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPutInvalidatesCacheForThatUriInRelativeContentLocationHeader() throws Exception {
|
void testPutInvalidatesCacheForThatUriInRelativeContentLocationHeader() throws Exception {
|
||||||
final ClassicHttpRequest req = makeRequestWithBody("PUT","/");
|
final ClassicHttpRequest req = makeRequestWithBody("PUT","/");
|
||||||
testUnsafeMethodInvalidatesCacheForRelativeUriInContentLocationHeader(req);
|
testUnsafeMethodInvalidatesCacheForRelativeUriInContentLocationHeader(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteInvalidatesCacheForThatUriInContentLocationHeader() throws Exception {
|
void testDeleteInvalidatesCacheForThatUriInContentLocationHeader() throws Exception {
|
||||||
final ClassicHttpRequest req = new BasicClassicHttpRequest("DELETE", "/");
|
final ClassicHttpRequest req = new BasicClassicHttpRequest("DELETE", "/");
|
||||||
testUnsafeMethodInvalidatesCacheForUriInContentLocationHeader(req);
|
testUnsafeMethodInvalidatesCacheForUriInContentLocationHeader(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteInvalidatesCacheForThatUriInRelativeContentLocationHeader() throws Exception {
|
void testDeleteInvalidatesCacheForThatUriInRelativeContentLocationHeader() throws Exception {
|
||||||
final ClassicHttpRequest req = new BasicClassicHttpRequest("DELETE", "/");
|
final ClassicHttpRequest req = new BasicClassicHttpRequest("DELETE", "/");
|
||||||
testUnsafeMethodInvalidatesCacheForRelativeUriInContentLocationHeader(req);
|
testUnsafeMethodInvalidatesCacheForRelativeUriInContentLocationHeader(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteInvalidatesCacheForThatUriInLocationHeader() throws Exception {
|
void testDeleteInvalidatesCacheForThatUriInLocationHeader() throws Exception {
|
||||||
final ClassicHttpRequest req = new BasicClassicHttpRequest("DELETE", "/");
|
final ClassicHttpRequest req = new BasicClassicHttpRequest("DELETE", "/");
|
||||||
testUnsafeMethodInvalidatesCacheForUriInLocationHeader(req);
|
testUnsafeMethodInvalidatesCacheForUriInLocationHeader(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPostInvalidatesCacheForThatUriInContentLocationHeader() throws Exception {
|
void testPostInvalidatesCacheForThatUriInContentLocationHeader() throws Exception {
|
||||||
final ClassicHttpRequest req = makeRequestWithBody("POST","/");
|
final ClassicHttpRequest req = makeRequestWithBody("POST","/");
|
||||||
testUnsafeMethodInvalidatesCacheForUriInContentLocationHeader(req);
|
testUnsafeMethodInvalidatesCacheForUriInContentLocationHeader(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPostInvalidatesCacheForThatUriInLocationHeader() throws Exception {
|
void testPostInvalidatesCacheForThatUriInLocationHeader() throws Exception {
|
||||||
final ClassicHttpRequest req = makeRequestWithBody("POST","/");
|
final ClassicHttpRequest req = makeRequestWithBody("POST","/");
|
||||||
testUnsafeMethodInvalidatesCacheForUriInLocationHeader(req);
|
testUnsafeMethodInvalidatesCacheForUriInLocationHeader(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPostInvalidatesCacheForRelativeUriInContentLocationHeader() throws Exception {
|
void testPostInvalidatesCacheForRelativeUriInContentLocationHeader() throws Exception {
|
||||||
final ClassicHttpRequest req = makeRequestWithBody("POST","/");
|
final ClassicHttpRequest req = makeRequestWithBody("POST","/");
|
||||||
testUnsafeMethodInvalidatesCacheForRelativeUriInContentLocationHeader(req);
|
testUnsafeMethodInvalidatesCacheForRelativeUriInContentLocationHeader(req);
|
||||||
}
|
}
|
||||||
|
@ -1597,13 +1597,13 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOPTIONSRequestsAreWrittenThroughToOrigin() throws Exception {
|
void testOPTIONSRequestsAreWrittenThroughToOrigin() throws Exception {
|
||||||
final ClassicHttpRequest req = new BasicClassicHttpRequest("OPTIONS","*");
|
final ClassicHttpRequest req = new BasicClassicHttpRequest("OPTIONS","*");
|
||||||
testRequestIsWrittenThroughToOrigin(req);
|
testRequestIsWrittenThroughToOrigin(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPOSTRequestsAreWrittenThroughToOrigin() throws Exception {
|
void testPOSTRequestsAreWrittenThroughToOrigin() throws Exception {
|
||||||
final ClassicHttpRequest req = new BasicClassicHttpRequest("POST","/");
|
final ClassicHttpRequest req = new BasicClassicHttpRequest("POST","/");
|
||||||
req.setEntity(HttpTestUtils.makeBody(128));
|
req.setEntity(HttpTestUtils.makeBody(128));
|
||||||
req.setHeader("Content-Length","128");
|
req.setHeader("Content-Length","128");
|
||||||
|
@ -1611,7 +1611,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPUTRequestsAreWrittenThroughToOrigin() throws Exception {
|
void testPUTRequestsAreWrittenThroughToOrigin() throws Exception {
|
||||||
final ClassicHttpRequest req = new BasicClassicHttpRequest("PUT","/");
|
final ClassicHttpRequest req = new BasicClassicHttpRequest("PUT","/");
|
||||||
req.setEntity(HttpTestUtils.makeBody(128));
|
req.setEntity(HttpTestUtils.makeBody(128));
|
||||||
req.setHeader("Content-Length","128");
|
req.setHeader("Content-Length","128");
|
||||||
|
@ -1619,31 +1619,31 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDELETERequestsAreWrittenThroughToOrigin() throws Exception {
|
void testDELETERequestsAreWrittenThroughToOrigin() throws Exception {
|
||||||
final ClassicHttpRequest req = new BasicClassicHttpRequest("DELETE", "/");
|
final ClassicHttpRequest req = new BasicClassicHttpRequest("DELETE", "/");
|
||||||
testRequestIsWrittenThroughToOrigin(req);
|
testRequestIsWrittenThroughToOrigin(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTRACERequestsAreWrittenThroughToOrigin() throws Exception {
|
void testTRACERequestsAreWrittenThroughToOrigin() throws Exception {
|
||||||
final ClassicHttpRequest req = new BasicClassicHttpRequest("TRACE","/");
|
final ClassicHttpRequest req = new BasicClassicHttpRequest("TRACE","/");
|
||||||
testRequestIsWrittenThroughToOrigin(req);
|
testRequestIsWrittenThroughToOrigin(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCONNECTRequestsAreWrittenThroughToOrigin() throws Exception {
|
void testCONNECTRequestsAreWrittenThroughToOrigin() throws Exception {
|
||||||
final ClassicHttpRequest req = new BasicClassicHttpRequest("CONNECT","/");
|
final ClassicHttpRequest req = new BasicClassicHttpRequest("CONNECT","/");
|
||||||
testRequestIsWrittenThroughToOrigin(req);
|
testRequestIsWrittenThroughToOrigin(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnknownMethodRequestsAreWrittenThroughToOrigin() throws Exception {
|
void testUnknownMethodRequestsAreWrittenThroughToOrigin() throws Exception {
|
||||||
final ClassicHttpRequest req = new BasicClassicHttpRequest("UNKNOWN","/");
|
final ClassicHttpRequest req = new BasicClassicHttpRequest("UNKNOWN","/");
|
||||||
testRequestIsWrittenThroughToOrigin(req);
|
testRequestIsWrittenThroughToOrigin(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransmitsAgeHeaderIfIncomingAgeHeaderTooBig() throws Exception {
|
void testTransmitsAgeHeaderIfIncomingAgeHeaderTooBig() throws Exception {
|
||||||
final String reallyOldAge = "1" + Long.MAX_VALUE;
|
final String reallyOldAge = "1" + Long.MAX_VALUE;
|
||||||
originResponse.setHeader("Age",reallyOldAge);
|
originResponse.setHeader("Age",reallyOldAge);
|
||||||
|
|
||||||
|
@ -1656,7 +1656,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyAllowHeaderWithUnknownMethods() throws Exception {
|
void testDoesNotModifyAllowHeaderWithUnknownMethods() throws Exception {
|
||||||
final String allowHeaderValue = "GET, HEAD, FOOBAR";
|
final String allowHeaderValue = "GET, HEAD, FOOBAR";
|
||||||
originResponse.setHeader("Allow",allowHeaderValue);
|
originResponse.setHeader("Allow",allowHeaderValue);
|
||||||
Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(originResponse);
|
Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(originResponse);
|
||||||
|
@ -1690,7 +1690,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSharedCacheMustNotNormallyCacheAuthorizedResponses() throws Exception {
|
void testSharedCacheMustNotNormallyCacheAuthorizedResponses() throws Exception {
|
||||||
final ClassicHttpResponse resp = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp = HttpTestUtils.make200Response();
|
||||||
resp.setHeader("Cache-Control","max-age=3600");
|
resp.setHeader("Cache-Control","max-age=3600");
|
||||||
resp.setHeader("ETag","\"etag\"");
|
resp.setHeader("ETag","\"etag\"");
|
||||||
|
@ -1698,7 +1698,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSharedCacheMayCacheAuthorizedResponsesWithSMaxAgeHeader() throws Exception {
|
void testSharedCacheMayCacheAuthorizedResponsesWithSMaxAgeHeader() throws Exception {
|
||||||
final ClassicHttpResponse resp = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp = HttpTestUtils.make200Response();
|
||||||
resp.setHeader("Cache-Control","s-maxage=3600");
|
resp.setHeader("Cache-Control","s-maxage=3600");
|
||||||
resp.setHeader("ETag","\"etag\"");
|
resp.setHeader("ETag","\"etag\"");
|
||||||
|
@ -1706,7 +1706,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSharedCacheMustRevalidateAuthorizedResponsesWhenSMaxAgeIsZero() throws Exception {
|
void testSharedCacheMustRevalidateAuthorizedResponsesWhenSMaxAgeIsZero() throws Exception {
|
||||||
final ClassicHttpResponse resp = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp = HttpTestUtils.make200Response();
|
||||||
resp.setHeader("Cache-Control","s-maxage=0");
|
resp.setHeader("Cache-Control","s-maxage=0");
|
||||||
resp.setHeader("ETag","\"etag\"");
|
resp.setHeader("ETag","\"etag\"");
|
||||||
|
@ -1714,7 +1714,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSharedCacheMayCacheAuthorizedResponsesWithMustRevalidate() throws Exception {
|
void testSharedCacheMayCacheAuthorizedResponsesWithMustRevalidate() throws Exception {
|
||||||
final ClassicHttpResponse resp = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp = HttpTestUtils.make200Response();
|
||||||
resp.setHeader("Cache-Control","must-revalidate");
|
resp.setHeader("Cache-Control","must-revalidate");
|
||||||
resp.setHeader("ETag","\"etag\"");
|
resp.setHeader("ETag","\"etag\"");
|
||||||
|
@ -1722,7 +1722,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSharedCacheMayCacheAuthorizedResponsesWithCacheControlPublic() throws Exception {
|
void testSharedCacheMayCacheAuthorizedResponsesWithCacheControlPublic() throws Exception {
|
||||||
final ClassicHttpResponse resp = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp = HttpTestUtils.make200Response();
|
||||||
resp.setHeader("Cache-Control","public");
|
resp.setHeader("Cache-Control","public");
|
||||||
testSharedCacheRevalidatesAuthorizedResponse(resp, 0, 1);
|
testSharedCacheRevalidatesAuthorizedResponse(resp, 0, 1);
|
||||||
|
@ -1763,7 +1763,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSharedCacheMustUseNewRequestHeadersWhenRevalidatingAuthorizedResponsesWithSMaxAge() throws Exception {
|
void testSharedCacheMustUseNewRequestHeadersWhenRevalidatingAuthorizedResponsesWithSMaxAge() throws Exception {
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant tenSecondsAgo = now.minusSeconds(10);
|
final Instant tenSecondsAgo = now.minusSeconds(10);
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
|
@ -1775,7 +1775,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSharedCacheMustUseNewRequestHeadersWhenRevalidatingAuthorizedResponsesWithMustRevalidate() throws Exception {
|
void testSharedCacheMustUseNewRequestHeadersWhenRevalidatingAuthorizedResponsesWithMustRevalidate() throws Exception {
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant tenSecondsAgo = now.minusSeconds(10);
|
final Instant tenSecondsAgo = now.minusSeconds(10);
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
|
@ -1814,7 +1814,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheIsNotUsedWhenRespondingToRequestWithCacheControlNoCache() throws Exception {
|
void testCacheIsNotUsedWhenRespondingToRequestWithCacheControlNoCache() throws Exception {
|
||||||
final ClassicHttpRequest req = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req = new BasicClassicHttpRequest("GET", "/");
|
||||||
req.setHeader("Cache-Control","no-cache");
|
req.setHeader("Cache-Control","no-cache");
|
||||||
testCacheIsNotUsedWhenRespondingToRequest(req);
|
testCacheIsNotUsedWhenRespondingToRequest(req);
|
||||||
|
@ -1856,7 +1856,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStaleEntryWithMustRevalidateIsNotUsedWithoutRevalidatingWithOrigin() throws Exception {
|
void testStaleEntryWithMustRevalidateIsNotUsedWithoutRevalidatingWithOrigin() throws Exception {
|
||||||
final ClassicHttpResponse response = HttpTestUtils.make200Response();
|
final ClassicHttpResponse response = HttpTestUtils.make200Response();
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant tenSecondsAgo = now.minusSeconds(10);
|
final Instant tenSecondsAgo = now.minusSeconds(10);
|
||||||
|
@ -1886,7 +1886,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGenerates504IfCannotRevalidateAMustRevalidateEntry() throws Exception {
|
void testGenerates504IfCannotRevalidateAMustRevalidateEntry() throws Exception {
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant tenSecondsAgo = now.minusSeconds(10);
|
final Instant tenSecondsAgo = now.minusSeconds(10);
|
||||||
|
@ -1898,7 +1898,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStaleEntryWithProxyRevalidateOnSharedCacheIsNotUsedWithoutRevalidatingWithOrigin() throws Exception {
|
void testStaleEntryWithProxyRevalidateOnSharedCacheIsNotUsedWithoutRevalidatingWithOrigin() throws Exception {
|
||||||
if (config.isSharedCache()) {
|
if (config.isSharedCache()) {
|
||||||
final ClassicHttpResponse response = HttpTestUtils.make200Response();
|
final ClassicHttpResponse response = HttpTestUtils.make200Response();
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
|
@ -1912,7 +1912,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGenerates504IfSharedCacheCannotRevalidateAProxyRevalidateEntry() throws Exception {
|
void testGenerates504IfSharedCacheCannotRevalidateAProxyRevalidateEntry() throws Exception {
|
||||||
if (config.isSharedCache()) {
|
if (config.isSharedCache()) {
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
|
@ -1926,7 +1926,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheControlPrivateIsNotCacheableBySharedCache() throws Exception {
|
void testCacheControlPrivateIsNotCacheableBySharedCache() throws Exception {
|
||||||
if (config.isSharedCache()) {
|
if (config.isSharedCache()) {
|
||||||
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
|
@ -1945,7 +1945,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheControlPrivateOnFieldIsNotReturnedBySharedCache() throws Exception {
|
void testCacheControlPrivateOnFieldIsNotReturnedBySharedCache() throws Exception {
|
||||||
if (config.isSharedCache()) {
|
if (config.isSharedCache()) {
|
||||||
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
|
@ -1970,7 +1970,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoCacheCannotSatisfyASubsequentRequestWithoutRevalidation() throws Exception {
|
void testNoCacheCannotSatisfyASubsequentRequestWithoutRevalidation() throws Exception {
|
||||||
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
resp1.setHeader("ETag","\"etag\"");
|
resp1.setHeader("ETag","\"etag\"");
|
||||||
|
@ -1992,7 +1992,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoCacheCannotSatisfyASubsequentRequestWithoutRevalidationEvenWithContraryIndications() throws Exception {
|
void testNoCacheCannotSatisfyASubsequentRequestWithoutRevalidationEvenWithContraryIndications() throws Exception {
|
||||||
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
resp1.setHeader("ETag","\"etag\"");
|
resp1.setHeader("ETag","\"etag\"");
|
||||||
|
@ -2013,7 +2013,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoCacheOnFieldIsNotReturnedWithoutRevalidation() throws Exception {
|
void testNoCacheOnFieldIsNotReturnedWithoutRevalidation() throws Exception {
|
||||||
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
resp1.setHeader("ETag","\"etag\"");
|
resp1.setHeader("ETag","\"etag\"");
|
||||||
|
@ -2044,7 +2044,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoStoreOnRequestIsNotStoredInCache() throws Exception {
|
void testNoStoreOnRequestIsNotStoredInCache() throws Exception {
|
||||||
request.setHeader("Cache-Control","no-store");
|
request.setHeader("Cache-Control","no-store");
|
||||||
Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(originResponse);
|
Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(originResponse);
|
||||||
|
|
||||||
|
@ -2054,7 +2054,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoStoreOnRequestIsNotStoredInCacheEvenIfResponseMarkedCacheable() throws Exception {
|
void testNoStoreOnRequestIsNotStoredInCacheEvenIfResponseMarkedCacheable() throws Exception {
|
||||||
request.setHeader("Cache-Control","no-store");
|
request.setHeader("Cache-Control","no-store");
|
||||||
originResponse.setHeader("Cache-Control","max-age=3600");
|
originResponse.setHeader("Cache-Control","max-age=3600");
|
||||||
Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(originResponse);
|
Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(originResponse);
|
||||||
|
@ -2065,7 +2065,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoStoreOnResponseIsNotStoredInCache() throws Exception {
|
void testNoStoreOnResponseIsNotStoredInCache() throws Exception {
|
||||||
originResponse.setHeader("Cache-Control","no-store");
|
originResponse.setHeader("Cache-Control","no-store");
|
||||||
Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(originResponse);
|
Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(originResponse);
|
||||||
|
|
||||||
|
@ -2075,7 +2075,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoStoreOnResponseIsNotStoredInCacheEvenWithContraryIndicators() throws Exception {
|
void testNoStoreOnResponseIsNotStoredInCacheEvenWithContraryIndicators() throws Exception {
|
||||||
originResponse.setHeader("Cache-Control","no-store,max-age=3600");
|
originResponse.setHeader("Cache-Control","no-store,max-age=3600");
|
||||||
Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(originResponse);
|
Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(originResponse);
|
||||||
|
|
||||||
|
@ -2085,7 +2085,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOrderOfMultipleContentEncodingHeaderValuesIsPreserved() throws Exception {
|
void testOrderOfMultipleContentEncodingHeaderValuesIsPreserved() throws Exception {
|
||||||
originResponse.addHeader("Content-Encoding","gzip");
|
originResponse.addHeader("Content-Encoding","gzip");
|
||||||
originResponse.addHeader("Content-Encoding","deflate");
|
originResponse.addHeader("Content-Encoding","deflate");
|
||||||
Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(originResponse);
|
Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(originResponse);
|
||||||
|
@ -2111,7 +2111,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOrderOfMultipleParametersInContentEncodingHeaderIsPreserved() throws Exception {
|
void testOrderOfMultipleParametersInContentEncodingHeaderIsPreserved() throws Exception {
|
||||||
originResponse.addHeader("Content-Encoding","gzip,deflate");
|
originResponse.addHeader("Content-Encoding","gzip,deflate");
|
||||||
Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(originResponse);
|
Mockito.when(mockExecChain.proceed(Mockito.any(), Mockito.any())).thenReturn(originResponse);
|
||||||
|
|
||||||
|
@ -2136,7 +2136,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCacheDoesNotAssumeContentLocationHeaderIndicatesAnotherCacheableResource() throws Exception {
|
void testCacheDoesNotAssumeContentLocationHeaderIndicatesAnotherCacheableResource() throws Exception {
|
||||||
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/foo");
|
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/foo");
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
resp1.setHeader("Cache-Control","public,max-age=3600");
|
resp1.setHeader("Cache-Control","public,max-age=3600");
|
||||||
|
@ -2157,7 +2157,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCachedResponsesWithMissingDateHeadersShouldBeAssignedOne() throws Exception {
|
void testCachedResponsesWithMissingDateHeadersShouldBeAssignedOne() throws Exception {
|
||||||
originResponse.removeHeaders("Date");
|
originResponse.removeHeaders("Date");
|
||||||
originResponse.setHeader("Cache-Control","public");
|
originResponse.setHeader("Cache-Control","public");
|
||||||
originResponse.setHeader("ETag","\"etag\"");
|
originResponse.setHeader("ETag","\"etag\"");
|
||||||
|
@ -2189,17 +2189,17 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMalformedExpiresHeaderIsTreatedAsStale() throws Exception {
|
void testMalformedExpiresHeaderIsTreatedAsStale() throws Exception {
|
||||||
testInvalidExpiresHeaderIsTreatedAsStale("garbage");
|
testInvalidExpiresHeaderIsTreatedAsStale("garbage");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExpiresZeroHeaderIsTreatedAsStale() throws Exception {
|
void testExpiresZeroHeaderIsTreatedAsStale() throws Exception {
|
||||||
testInvalidExpiresHeaderIsTreatedAsStale("0");
|
testInvalidExpiresHeaderIsTreatedAsStale("0");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExpiresHeaderEqualToDateHeaderIsTreatedAsStale() throws Exception {
|
void testExpiresHeaderEqualToDateHeaderIsTreatedAsStale() throws Exception {
|
||||||
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
|
||||||
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
|
||||||
resp1.setHeader("Cache-Control","public");
|
resp1.setHeader("Cache-Control","public");
|
||||||
|
@ -2219,7 +2219,7 @@ public class TestProtocolRequirements {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotModifyServerResponseHeader() throws Exception {
|
void testDoesNotModifyServerResponseHeader() throws Exception {
|
||||||
final String server = "MockServer/1.0";
|
final String server = "MockServer/1.0";
|
||||||
originResponse.setHeader("Server", server);
|
originResponse.setHeader("Server", server);
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ import org.mockito.MockitoAnnotations;
|
||||||
* describes the stale-if-error and stale-while-revalidate
|
* describes the stale-if-error and stale-while-revalidate
|
||||||
* Cache-Control extensions.
|
* Cache-Control extensions.
|
||||||
*/
|
*/
|
||||||
public class TestRFC5861Compliance {
|
class TestRFC5861Compliance {
|
||||||
|
|
||||||
static final int MAX_BYTES = 1024;
|
static final int MAX_BYTES = 1024;
|
||||||
static final int MAX_ENTRIES = 100;
|
static final int MAX_ENTRIES = 100;
|
||||||
|
@ -83,7 +83,7 @@ public class TestRFC5861Compliance {
|
||||||
ScheduledExecutorService executorService;
|
ScheduledExecutorService executorService;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
MockitoAnnotations.openMocks(this);
|
MockitoAnnotations.openMocks(this);
|
||||||
|
|
||||||
host = new HttpHost("foo.example.com", 80);
|
host = new HttpHost("foo.example.com", 80);
|
||||||
|
@ -113,7 +113,7 @@ public class TestRFC5861Compliance {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void cleanup() {
|
void cleanup() {
|
||||||
executorService.shutdownNow();
|
executorService.shutdownNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ public class TestRFC5861Compliance {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConsumesErrorResponseWhenServingStale()
|
void testConsumesErrorResponseWhenServingStale()
|
||||||
throws Exception{
|
throws Exception{
|
||||||
final Instant tenSecondsAgo = Instant.now().minusSeconds(10);
|
final Instant tenSecondsAgo = Instant.now().minusSeconds(10);
|
||||||
final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
||||||
|
@ -152,7 +152,7 @@ public class TestRFC5861Compliance {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStaleIfErrorInResponseYieldsToMustRevalidate()
|
void testStaleIfErrorInResponseYieldsToMustRevalidate()
|
||||||
throws Exception{
|
throws Exception{
|
||||||
final Instant tenSecondsAgo = Instant.now().minusSeconds(10);
|
final Instant tenSecondsAgo = Instant.now().minusSeconds(10);
|
||||||
final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
||||||
|
@ -174,7 +174,7 @@ public class TestRFC5861Compliance {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStaleIfErrorInResponseYieldsToProxyRevalidateForSharedCache()
|
void testStaleIfErrorInResponseYieldsToProxyRevalidateForSharedCache()
|
||||||
throws Exception{
|
throws Exception{
|
||||||
assertTrue(config.isSharedCache());
|
assertTrue(config.isSharedCache());
|
||||||
final Instant tenSecondsAgo = Instant.now().minusSeconds(10);
|
final Instant tenSecondsAgo = Instant.now().minusSeconds(10);
|
||||||
|
@ -197,7 +197,7 @@ public class TestRFC5861Compliance {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStaleIfErrorInResponseYieldsToExplicitFreshnessRequest()
|
void testStaleIfErrorInResponseYieldsToExplicitFreshnessRequest()
|
||||||
throws Exception{
|
throws Exception{
|
||||||
final Instant tenSecondsAgo = Instant.now().minusSeconds(10);
|
final Instant tenSecondsAgo = Instant.now().minusSeconds(10);
|
||||||
final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
||||||
|
@ -220,7 +220,7 @@ public class TestRFC5861Compliance {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStaleIfErrorInResponseIsFalseReturnsError()
|
void testStaleIfErrorInResponseIsFalseReturnsError()
|
||||||
throws Exception{
|
throws Exception{
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant tenSecondsAgo = now.minusSeconds(10);
|
final Instant tenSecondsAgo = now.minusSeconds(10);
|
||||||
|
@ -244,7 +244,7 @@ public class TestRFC5861Compliance {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStaleIfErrorInRequestIsFalseReturnsError()
|
void testStaleIfErrorInRequestIsFalseReturnsError()
|
||||||
throws Exception{
|
throws Exception{
|
||||||
final Instant now = Instant.now();
|
final Instant now = Instant.now();
|
||||||
final Instant tenSecondsAgo = now.minusSeconds(10);
|
final Instant tenSecondsAgo = now.minusSeconds(10);
|
||||||
|
|
|
@ -37,12 +37,12 @@ import org.apache.hc.core5.http.support.BasicResponseBuilder;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestResponseCacheConformance {
|
class TestResponseCacheConformance {
|
||||||
|
|
||||||
private ResponseCacheConformance impl;
|
private ResponseCacheConformance impl;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
impl = ResponseCacheConformance.INSTANCE;
|
impl = ResponseCacheConformance.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,31 +58,31 @@ public class TestResponseCacheConformance {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldStripContentEncodingFromOrigin304ResponseToStrongValidation() throws Exception {
|
void shouldStripContentEncodingFromOrigin304ResponseToStrongValidation() throws Exception {
|
||||||
shouldStripEntityHeaderFromOrigin304ResponseToStrongValidation(
|
shouldStripEntityHeaderFromOrigin304ResponseToStrongValidation(
|
||||||
"Content-Encoding", "gzip");
|
"Content-Encoding", "gzip");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldStripContentLanguageFromOrigin304ResponseToStrongValidation() throws Exception {
|
void shouldStripContentLanguageFromOrigin304ResponseToStrongValidation() throws Exception {
|
||||||
shouldStripEntityHeaderFromOrigin304ResponseToStrongValidation(
|
shouldStripEntityHeaderFromOrigin304ResponseToStrongValidation(
|
||||||
"Content-Language", "en");
|
"Content-Language", "en");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldStripContentLengthFromOrigin304ResponseToStrongValidation() throws Exception {
|
void shouldStripContentLengthFromOrigin304ResponseToStrongValidation() throws Exception {
|
||||||
shouldStripEntityHeaderFromOrigin304ResponseToStrongValidation(
|
shouldStripEntityHeaderFromOrigin304ResponseToStrongValidation(
|
||||||
"Content-Length", "128");
|
"Content-Length", "128");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldStripContentMD5FromOrigin304ResponseToStrongValidation() throws Exception {
|
void shouldStripContentMD5FromOrigin304ResponseToStrongValidation() throws Exception {
|
||||||
shouldStripEntityHeaderFromOrigin304ResponseToStrongValidation(
|
shouldStripEntityHeaderFromOrigin304ResponseToStrongValidation(
|
||||||
"Content-MD5", "Q2hlY2sgSW50ZWdyaXR5IQ==");
|
"Content-MD5", "Q2hlY2sgSW50ZWdyaXR5IQ==");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldStripContentTypeFromOrigin304ResponseToStrongValidation() throws Exception {
|
void shouldStripContentTypeFromOrigin304ResponseToStrongValidation() throws Exception {
|
||||||
shouldStripEntityHeaderFromOrigin304ResponseToStrongValidation(
|
shouldStripEntityHeaderFromOrigin304ResponseToStrongValidation(
|
||||||
"Content-Type", "text/html;charset=utf-8");
|
"Content-Type", "text/html;charset=utf-8");
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestResponseCachingPolicy {
|
class TestResponseCachingPolicy {
|
||||||
|
|
||||||
private ResponseCachingPolicy policy;
|
private ResponseCachingPolicy policy;
|
||||||
private HttpResponse response;
|
private HttpResponse response;
|
||||||
|
@ -64,7 +64,7 @@ public class TestResponseCachingPolicy {
|
||||||
private ResponseCacheControl responseCacheControl;
|
private ResponseCacheControl responseCacheControl;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() {
|
||||||
now = Instant.now();
|
now = Instant.now();
|
||||||
sixSecondsAgo = now.minusSeconds(6);
|
sixSecondsAgo = now.minusSeconds(6);
|
||||||
tenSecondsFromNow = now.plusSeconds(10);
|
tenSecondsFromNow = now.plusSeconds(10);
|
||||||
|
@ -78,21 +78,21 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCacheable() {
|
void testGetCacheable() {
|
||||||
policy = new ResponseCachingPolicy(true, false, false);
|
policy = new ResponseCachingPolicy(true, false, false);
|
||||||
request = new BasicHttpRequest(Method.GET, "/");
|
request = new BasicHttpRequest(Method.GET, "/");
|
||||||
Assertions.assertTrue(policy.isResponseCacheable(responseCacheControl, request, response));
|
Assertions.assertTrue(policy.isResponseCacheable(responseCacheControl, request, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHeadCacheable() {
|
void testHeadCacheable() {
|
||||||
policy = new ResponseCachingPolicy(true, false, false);
|
policy = new ResponseCachingPolicy(true, false, false);
|
||||||
request = new BasicHttpRequest(Method.HEAD, "/");
|
request = new BasicHttpRequest(Method.HEAD, "/");
|
||||||
Assertions.assertTrue(policy.isResponseCacheable(responseCacheControl, request, response));
|
Assertions.assertTrue(policy.isResponseCacheable(responseCacheControl, request, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testArbitraryMethodNotCacheable() {
|
void testArbitraryMethodNotCacheable() {
|
||||||
request = new BasicHttpRequest("PUT", "/");
|
request = new BasicHttpRequest("PUT", "/");
|
||||||
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
||||||
|
|
||||||
|
@ -101,14 +101,14 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponsesToRequestsWithAuthorizationHeadersAreNotCacheableBySharedCache() {
|
void testResponsesToRequestsWithAuthorizationHeadersAreNotCacheableBySharedCache() {
|
||||||
request = new BasicHttpRequest("GET","/");
|
request = new BasicHttpRequest("GET","/");
|
||||||
request.setHeader("Authorization", StandardAuthScheme.BASIC + " dXNlcjpwYXNzd2Q=");
|
request.setHeader("Authorization", StandardAuthScheme.BASIC + " dXNlcjpwYXNzd2Q=");
|
||||||
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponsesToRequestsWithAuthorizationHeadersAreCacheableByNonSharedCache() {
|
void testResponsesToRequestsWithAuthorizationHeadersAreCacheableByNonSharedCache() {
|
||||||
policy = new ResponseCachingPolicy(false, false, false);
|
policy = new ResponseCachingPolicy(false, false, false);
|
||||||
request = new BasicHttpRequest("GET","/");
|
request = new BasicHttpRequest("GET","/");
|
||||||
request.setHeader("Authorization", StandardAuthScheme.BASIC + " dXNlcjpwYXNzd2Q=");
|
request.setHeader("Authorization", StandardAuthScheme.BASIC + " dXNlcjpwYXNzd2Q=");
|
||||||
|
@ -116,7 +116,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAuthorizedResponsesWithSMaxAgeAreCacheable() {
|
void testAuthorizedResponsesWithSMaxAgeAreCacheable() {
|
||||||
request = new BasicHttpRequest("GET","/");
|
request = new BasicHttpRequest("GET","/");
|
||||||
request.setHeader("Authorization", StandardAuthScheme.BASIC + " dXNlcjpwYXNzd2Q=");
|
request.setHeader("Authorization", StandardAuthScheme.BASIC + " dXNlcjpwYXNzd2Q=");
|
||||||
responseCacheControl = ResponseCacheControl.builder()
|
responseCacheControl = ResponseCacheControl.builder()
|
||||||
|
@ -127,7 +127,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAuthorizedResponsesWithCacheControlPublicAreCacheable() {
|
void testAuthorizedResponsesWithCacheControlPublicAreCacheable() {
|
||||||
request = new BasicHttpRequest("GET","/");
|
request = new BasicHttpRequest("GET","/");
|
||||||
request.setHeader("Authorization", StandardAuthScheme.BASIC + " dXNlcjpwYXNzd2Q=");
|
request.setHeader("Authorization", StandardAuthScheme.BASIC + " dXNlcjpwYXNzd2Q=");
|
||||||
responseCacheControl = ResponseCacheControl.builder()
|
responseCacheControl = ResponseCacheControl.builder()
|
||||||
|
@ -137,7 +137,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAuthorizedResponsesWithCacheControlMaxAgeAreNotCacheable() {
|
void testAuthorizedResponsesWithCacheControlMaxAgeAreNotCacheable() {
|
||||||
request = new BasicHttpRequest("GET","/");
|
request = new BasicHttpRequest("GET","/");
|
||||||
request.setHeader("Authorization", StandardAuthScheme.BASIC + " dXNlcjpwYXNzd2Q=");
|
request.setHeader("Authorization", StandardAuthScheme.BASIC + " dXNlcjpwYXNzd2Q=");
|
||||||
responseCacheControl = ResponseCacheControl.builder()
|
responseCacheControl = ResponseCacheControl.builder()
|
||||||
|
@ -147,51 +147,51 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test203ResponseCodeIsCacheable() {
|
void test203ResponseCodeIsCacheable() {
|
||||||
response.setCode(HttpStatus.SC_NON_AUTHORITATIVE_INFORMATION);
|
response.setCode(HttpStatus.SC_NON_AUTHORITATIVE_INFORMATION);
|
||||||
Assertions.assertTrue(policy.isResponseCacheable(responseCacheControl, request, response));
|
Assertions.assertTrue(policy.isResponseCacheable(responseCacheControl, request, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test206ResponseCodeIsNotCacheable() {
|
void test206ResponseCodeIsNotCacheable() {
|
||||||
response.setCode(HttpStatus.SC_PARTIAL_CONTENT);
|
response.setCode(HttpStatus.SC_PARTIAL_CONTENT);
|
||||||
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test300ResponseCodeIsCacheable() {
|
void test300ResponseCodeIsCacheable() {
|
||||||
response.setCode(HttpStatus.SC_MULTIPLE_CHOICES);
|
response.setCode(HttpStatus.SC_MULTIPLE_CHOICES);
|
||||||
Assertions.assertTrue(policy.isResponseCacheable(responseCacheControl, request, response));
|
Assertions.assertTrue(policy.isResponseCacheable(responseCacheControl, request, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test301ResponseCodeIsCacheable() {
|
void test301ResponseCodeIsCacheable() {
|
||||||
response.setCode(HttpStatus.SC_MOVED_PERMANENTLY);
|
response.setCode(HttpStatus.SC_MOVED_PERMANENTLY);
|
||||||
Assertions.assertTrue(policy.isResponseCacheable(responseCacheControl, request, response));
|
Assertions.assertTrue(policy.isResponseCacheable(responseCacheControl, request, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test410ResponseCodeIsCacheable() {
|
void test410ResponseCodeIsCacheable() {
|
||||||
response.setCode(HttpStatus.SC_GONE);
|
response.setCode(HttpStatus.SC_GONE);
|
||||||
Assertions.assertTrue(policy.isResponseCacheable(responseCacheControl, request, response));
|
Assertions.assertTrue(policy.isResponseCacheable(responseCacheControl, request, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPlain302ResponseCodeIsNotCacheable() {
|
void testPlain302ResponseCodeIsNotCacheable() {
|
||||||
response.setCode(HttpStatus.SC_MOVED_TEMPORARILY);
|
response.setCode(HttpStatus.SC_MOVED_TEMPORARILY);
|
||||||
response.removeHeaders("Expires");
|
response.removeHeaders("Expires");
|
||||||
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPlain303ResponseCodeIsNotCacheableUnderDefaultBehavior() {
|
void testPlain303ResponseCodeIsNotCacheableUnderDefaultBehavior() {
|
||||||
response.setCode(HttpStatus.SC_SEE_OTHER);
|
response.setCode(HttpStatus.SC_SEE_OTHER);
|
||||||
response.removeHeaders("Expires");
|
response.removeHeaders("Expires");
|
||||||
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPlain303ResponseCodeIsNotCacheableEvenIf303CachingEnabled() {
|
void testPlain303ResponseCodeIsNotCacheableEvenIf303CachingEnabled() {
|
||||||
policy = new ResponseCachingPolicy(true, false, true);
|
policy = new ResponseCachingPolicy(true, false, true);
|
||||||
response.setCode(HttpStatus.SC_SEE_OTHER);
|
response.setCode(HttpStatus.SC_SEE_OTHER);
|
||||||
response.removeHeaders("Expires");
|
response.removeHeaders("Expires");
|
||||||
|
@ -200,14 +200,14 @@ public class TestResponseCachingPolicy {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPlain307ResponseCodeIsNotCacheable() {
|
void testPlain307ResponseCodeIsNotCacheable() {
|
||||||
response.setCode(HttpStatus.SC_TEMPORARY_REDIRECT);
|
response.setCode(HttpStatus.SC_TEMPORARY_REDIRECT);
|
||||||
response.removeHeaders("Expires");
|
response.removeHeaders("Expires");
|
||||||
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNon206WithExplicitExpiresIsCacheable() {
|
void testNon206WithExplicitExpiresIsCacheable() {
|
||||||
final int status = getRandomStatus();
|
final int status = getRandomStatus();
|
||||||
response.setCode(status);
|
response.setCode(status);
|
||||||
response.setHeader("Expires", DateUtils.formatStandardDate(Instant.now().plus(1, ChronoUnit.HOURS)));
|
response.setHeader("Expires", DateUtils.formatStandardDate(Instant.now().plus(1, ChronoUnit.HOURS)));
|
||||||
|
@ -215,7 +215,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNon206WithMaxAgeIsCacheable() {
|
void testNon206WithMaxAgeIsCacheable() {
|
||||||
final int status = getRandomStatus();
|
final int status = getRandomStatus();
|
||||||
response.setCode(status);
|
response.setCode(status);
|
||||||
responseCacheControl = ResponseCacheControl.builder()
|
responseCacheControl = ResponseCacheControl.builder()
|
||||||
|
@ -225,7 +225,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMissingCacheControlHeader() {
|
void testMissingCacheControlHeader() {
|
||||||
final int status = getRandomStatus();
|
final int status = getRandomStatus();
|
||||||
response.setCode(status);
|
response.setCode(status);
|
||||||
response.removeHeaders(HttpHeaders.CACHE_CONTROL);
|
response.removeHeaders(HttpHeaders.CACHE_CONTROL);
|
||||||
|
@ -233,7 +233,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNon206WithSMaxAgeIsCacheable() {
|
void testNon206WithSMaxAgeIsCacheable() {
|
||||||
final int status = getRandomStatus();
|
final int status = getRandomStatus();
|
||||||
response.setCode(status);
|
response.setCode(status);
|
||||||
responseCacheControl = ResponseCacheControl.builder()
|
responseCacheControl = ResponseCacheControl.builder()
|
||||||
|
@ -243,7 +243,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNon206WithMustRevalidateIsCacheable() {
|
void testNon206WithMustRevalidateIsCacheable() {
|
||||||
final int status = getRandomStatus();
|
final int status = getRandomStatus();
|
||||||
response.setCode(status);
|
response.setCode(status);
|
||||||
responseCacheControl = ResponseCacheControl.builder()
|
responseCacheControl = ResponseCacheControl.builder()
|
||||||
|
@ -253,7 +253,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNon206WithProxyRevalidateIsCacheable() {
|
void testNon206WithProxyRevalidateIsCacheable() {
|
||||||
final int status = getRandomStatus();
|
final int status = getRandomStatus();
|
||||||
response.setCode(status);
|
response.setCode(status);
|
||||||
responseCacheControl = ResponseCacheControl.builder()
|
responseCacheControl = ResponseCacheControl.builder()
|
||||||
|
@ -263,7 +263,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNon206WithPublicCacheControlIsCacheable() {
|
void testNon206WithPublicCacheControlIsCacheable() {
|
||||||
final int status = getRandomStatus();
|
final int status = getRandomStatus();
|
||||||
response.setCode(status);
|
response.setCode(status);
|
||||||
responseCacheControl = ResponseCacheControl.builder()
|
responseCacheControl = ResponseCacheControl.builder()
|
||||||
|
@ -273,7 +273,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNon206WithPrivateCacheControlIsNotCacheableBySharedCache() {
|
void testNon206WithPrivateCacheControlIsNotCacheableBySharedCache() {
|
||||||
final int status = getRandomStatus();
|
final int status = getRandomStatus();
|
||||||
response.setCode(status);
|
response.setCode(status);
|
||||||
responseCacheControl = ResponseCacheControl.builder()
|
responseCacheControl = ResponseCacheControl.builder()
|
||||||
|
@ -283,7 +283,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test200ResponseWithPrivateCacheControlIsCacheableByNonSharedCache() {
|
void test200ResponseWithPrivateCacheControlIsCacheableByNonSharedCache() {
|
||||||
policy = new ResponseCachingPolicy(false, false, false);
|
policy = new ResponseCachingPolicy(false, false, false);
|
||||||
response.setCode(HttpStatus.SC_OK);
|
response.setCode(HttpStatus.SC_OK);
|
||||||
responseCacheControl = ResponseCacheControl.builder()
|
responseCacheControl = ResponseCacheControl.builder()
|
||||||
|
@ -293,7 +293,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testControlNoCacheCacheable() {
|
void testControlNoCacheCacheable() {
|
||||||
responseCacheControl = ResponseCacheControl.builder()
|
responseCacheControl = ResponseCacheControl.builder()
|
||||||
.setNoCache(true)
|
.setNoCache(true)
|
||||||
.build();
|
.build();
|
||||||
|
@ -302,7 +302,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testControlNoStoreNotCacheable() {
|
void testControlNoStoreNotCacheable() {
|
||||||
responseCacheControl = ResponseCacheControl.builder()
|
responseCacheControl = ResponseCacheControl.builder()
|
||||||
.setNoStore(true)
|
.setNoStore(true)
|
||||||
.build();
|
.build();
|
||||||
|
@ -311,7 +311,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testControlNoStoreEmbeddedInListCacheable() {
|
void testControlNoStoreEmbeddedInListCacheable() {
|
||||||
responseCacheControl = ResponseCacheControl.builder()
|
responseCacheControl = ResponseCacheControl.builder()
|
||||||
.setCachePublic(true)
|
.setCachePublic(true)
|
||||||
.setNoStore(true)
|
.setNoStore(true)
|
||||||
|
@ -321,7 +321,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testControlNoCacheEmbeddedInListCacheable() {
|
void testControlNoCacheEmbeddedInListCacheable() {
|
||||||
responseCacheControl = ResponseCacheControl.builder()
|
responseCacheControl = ResponseCacheControl.builder()
|
||||||
.setCachePublic(true)
|
.setCachePublic(true)
|
||||||
.setNoCache(true)
|
.setNoCache(true)
|
||||||
|
@ -331,7 +331,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testControlNoCacheEmbeddedInListAfterFirstHeaderCacheable() {
|
void testControlNoCacheEmbeddedInListAfterFirstHeaderCacheable() {
|
||||||
responseCacheControl = ResponseCacheControl.builder()
|
responseCacheControl = ResponseCacheControl.builder()
|
||||||
.setMaxAge(20)
|
.setMaxAge(20)
|
||||||
.setCachePublic(true)
|
.setCachePublic(true)
|
||||||
|
@ -342,7 +342,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testControlNoStoreEmbeddedInListAfterFirstHeaderCacheable() {
|
void testControlNoStoreEmbeddedInListAfterFirstHeaderCacheable() {
|
||||||
responseCacheControl = ResponseCacheControl.builder()
|
responseCacheControl = ResponseCacheControl.builder()
|
||||||
.setMaxAge(20)
|
.setMaxAge(20)
|
||||||
.setCachePublic(true)
|
.setCachePublic(true)
|
||||||
|
@ -353,7 +353,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testControlAnyCacheControlCacheable() {
|
void testControlAnyCacheControlCacheable() {
|
||||||
responseCacheControl = ResponseCacheControl.builder()
|
responseCacheControl = ResponseCacheControl.builder()
|
||||||
.setMaxAge(10)
|
.setMaxAge(10)
|
||||||
.build();
|
.build();
|
||||||
|
@ -370,7 +370,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testControlWithout200Cacheable() {
|
void testControlWithout200Cacheable() {
|
||||||
HttpResponse response404 = new BasicHttpResponse(HttpStatus.SC_NOT_FOUND, "");
|
HttpResponse response404 = new BasicHttpResponse(HttpStatus.SC_NOT_FOUND, "");
|
||||||
|
|
||||||
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response404));
|
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response404));
|
||||||
|
@ -381,13 +381,13 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVaryStarIsNotCacheable() {
|
void testVaryStarIsNotCacheable() {
|
||||||
response.setHeader("Vary", "*");
|
response.setHeader("Vary", "*");
|
||||||
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVaryStarIsNotCacheableUsingSharedPublicCache() {
|
void testVaryStarIsNotCacheableUsingSharedPublicCache() {
|
||||||
policy = new ResponseCachingPolicy(true, false, false);
|
policy = new ResponseCachingPolicy(true, false, false);
|
||||||
|
|
||||||
request.setHeader("Authorization", StandardAuthScheme.BASIC + " QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
|
request.setHeader("Authorization", StandardAuthScheme.BASIC + " QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
|
||||||
|
@ -399,13 +399,13 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRequestWithVaryHeaderCacheable() {
|
void testRequestWithVaryHeaderCacheable() {
|
||||||
response.addHeader("Vary", "Accept-Encoding");
|
response.addHeader("Vary", "Accept-Encoding");
|
||||||
Assertions.assertTrue(policy.isResponseCacheable(responseCacheControl, request, response));
|
Assertions.assertTrue(policy.isResponseCacheable(responseCacheControl, request, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsArbitraryMethodCacheableUsingSharedPublicCache() {
|
void testIsArbitraryMethodCacheableUsingSharedPublicCache() {
|
||||||
policy = new ResponseCachingPolicy(true, false, false);
|
policy = new ResponseCachingPolicy(true, false, false);
|
||||||
|
|
||||||
request = new HttpOptions("http://foo.example.com/");
|
request = new HttpOptions("http://foo.example.com/");
|
||||||
|
@ -419,14 +419,14 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponsesWithMultipleAgeHeadersAreCacheable() {
|
void testResponsesWithMultipleAgeHeadersAreCacheable() {
|
||||||
response.addHeader("Age", "3");
|
response.addHeader("Age", "3");
|
||||||
response.addHeader("Age", "5");
|
response.addHeader("Age", "5");
|
||||||
Assertions.assertTrue(policy.isResponseCacheable(responseCacheControl, request, response));
|
Assertions.assertTrue(policy.isResponseCacheable(responseCacheControl, request, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponsesWithMultipleAgeHeadersAreNotCacheableUsingSharedPublicCache() {
|
void testResponsesWithMultipleAgeHeadersAreNotCacheableUsingSharedPublicCache() {
|
||||||
policy = new ResponseCachingPolicy(true, false, false);
|
policy = new ResponseCachingPolicy(true, false, false);
|
||||||
|
|
||||||
request.setHeader("Authorization", StandardAuthScheme.BASIC + " QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
|
request.setHeader("Authorization", StandardAuthScheme.BASIC + " QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
|
||||||
|
@ -439,14 +439,14 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponsesWithMultipleDateHeadersAreNotCacheable() {
|
void testResponsesWithMultipleDateHeadersAreNotCacheable() {
|
||||||
response.addHeader("Date", DateUtils.formatStandardDate(now));
|
response.addHeader("Date", DateUtils.formatStandardDate(now));
|
||||||
response.addHeader("Date", DateUtils.formatStandardDate(sixSecondsAgo));
|
response.addHeader("Date", DateUtils.formatStandardDate(sixSecondsAgo));
|
||||||
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponsesWithMultipleDateHeadersAreNotCacheableUsingSharedPublicCache() {
|
void testResponsesWithMultipleDateHeadersAreNotCacheableUsingSharedPublicCache() {
|
||||||
policy = new ResponseCachingPolicy(true, false, false);
|
policy = new ResponseCachingPolicy(true, false, false);
|
||||||
|
|
||||||
request.setHeader("Authorization", StandardAuthScheme.BASIC + " QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
|
request.setHeader("Authorization", StandardAuthScheme.BASIC + " QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
|
||||||
|
@ -459,13 +459,13 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponsesWithMalformedDateHeadersAreNotCacheable() {
|
void testResponsesWithMalformedDateHeadersAreNotCacheable() {
|
||||||
response.addHeader("Date", "garbage");
|
response.addHeader("Date", "garbage");
|
||||||
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponsesWithMalformedDateHeadersAreNotCacheableUsingSharedPublicCache() {
|
void testResponsesWithMalformedDateHeadersAreNotCacheableUsingSharedPublicCache() {
|
||||||
policy = new ResponseCachingPolicy(true, false, false);
|
policy = new ResponseCachingPolicy(true, false, false);
|
||||||
|
|
||||||
request.setHeader("Authorization", StandardAuthScheme.BASIC + " QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
|
request.setHeader("Authorization", StandardAuthScheme.BASIC + " QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
|
||||||
|
@ -477,14 +477,14 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponsesWithMultipleExpiresHeadersAreNotCacheable() {
|
void testResponsesWithMultipleExpiresHeadersAreNotCacheable() {
|
||||||
response.addHeader("Expires", DateUtils.formatStandardDate(now));
|
response.addHeader("Expires", DateUtils.formatStandardDate(now));
|
||||||
response.addHeader("Expires", DateUtils.formatStandardDate(sixSecondsAgo));
|
response.addHeader("Expires", DateUtils.formatStandardDate(sixSecondsAgo));
|
||||||
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponsesWithMultipleExpiresHeadersAreNotCacheableUsingSharedPublicCache() {
|
void testResponsesWithMultipleExpiresHeadersAreNotCacheableUsingSharedPublicCache() {
|
||||||
policy = new ResponseCachingPolicy(true, false, false);
|
policy = new ResponseCachingPolicy(true, false, false);
|
||||||
|
|
||||||
request.setHeader("Authorization", StandardAuthScheme.BASIC + " QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
|
request.setHeader("Authorization", StandardAuthScheme.BASIC + " QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
|
||||||
|
@ -497,39 +497,39 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponsesThatAreSmallEnoughAreCacheable() {
|
void testResponsesThatAreSmallEnoughAreCacheable() {
|
||||||
response.setHeader("Content-Length", "0");
|
response.setHeader("Content-Length", "0");
|
||||||
Assertions.assertTrue(policy.isResponseCacheable(responseCacheControl, request, response));
|
Assertions.assertTrue(policy.isResponseCacheable(responseCacheControl, request, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponsesToGETWithQueryParamsButNoExplicitCachingAreNotCacheable() {
|
void testResponsesToGETWithQueryParamsButNoExplicitCachingAreNotCacheable() {
|
||||||
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
||||||
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponsesToHEADWithQueryParamsButNoExplicitCachingAreNotCacheable() {
|
void testResponsesToHEADWithQueryParamsButNoExplicitCachingAreNotCacheable() {
|
||||||
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
||||||
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponsesToGETWithQueryParamsButNoExplicitCachingAreNotCacheableEvenWhen1_0QueryCachingDisabled() {
|
void testResponsesToGETWithQueryParamsButNoExplicitCachingAreNotCacheableEvenWhen1_0QueryCachingDisabled() {
|
||||||
policy = new ResponseCachingPolicy(true, true, false);
|
policy = new ResponseCachingPolicy(true, true, false);
|
||||||
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
||||||
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponsesToHEADWithQueryParamsButNoExplicitCachingAreNotCacheableEvenWhen1_0QueryCachingDisabled() {
|
void testResponsesToHEADWithQueryParamsButNoExplicitCachingAreNotCacheableEvenWhen1_0QueryCachingDisabled() {
|
||||||
policy = new ResponseCachingPolicy(true, true, false);
|
policy = new ResponseCachingPolicy(true, true, false);
|
||||||
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
||||||
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponsesToGETWithQueryParamsAndExplicitCachingAreCacheable() {
|
void testResponsesToGETWithQueryParamsAndExplicitCachingAreCacheable() {
|
||||||
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
||||||
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
||||||
response.setHeader("Expires", DateUtils.formatStandardDate(tenSecondsFromNow));
|
response.setHeader("Expires", DateUtils.formatStandardDate(tenSecondsFromNow));
|
||||||
|
@ -537,7 +537,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponsesToHEADWithQueryParamsAndExplicitCachingAreCacheable() {
|
void testResponsesToHEADWithQueryParamsAndExplicitCachingAreCacheable() {
|
||||||
policy = new ResponseCachingPolicy(true, false, false);
|
policy = new ResponseCachingPolicy(true, false, false);
|
||||||
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
||||||
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
||||||
|
@ -546,7 +546,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponsesToGETWithQueryParamsAndExplicitCachingAreCacheableEvenWhen1_0QueryCachingDisabled() {
|
void testResponsesToGETWithQueryParamsAndExplicitCachingAreCacheableEvenWhen1_0QueryCachingDisabled() {
|
||||||
policy = new ResponseCachingPolicy(true, true, false);
|
policy = new ResponseCachingPolicy(true, true, false);
|
||||||
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
||||||
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
||||||
|
@ -555,7 +555,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponsesToHEADWithQueryParamsAndExplicitCachingAreCacheableEvenWhen1_0QueryCachingDisabled() {
|
void testResponsesToHEADWithQueryParamsAndExplicitCachingAreCacheableEvenWhen1_0QueryCachingDisabled() {
|
||||||
policy = new ResponseCachingPolicy(true, true, false);
|
policy = new ResponseCachingPolicy(true, true, false);
|
||||||
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
||||||
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
||||||
|
@ -564,7 +564,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getsWithQueryParametersDirectlyFrom1_0OriginsAreNotCacheable() {
|
void getsWithQueryParametersDirectlyFrom1_0OriginsAreNotCacheable() {
|
||||||
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
||||||
response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
|
response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
|
||||||
response.setVersion(HttpVersion.HTTP_1_0);
|
response.setVersion(HttpVersion.HTTP_1_0);
|
||||||
|
@ -572,7 +572,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headsWithQueryParametersDirectlyFrom1_0OriginsAreNotCacheable() {
|
void headsWithQueryParametersDirectlyFrom1_0OriginsAreNotCacheable() {
|
||||||
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
||||||
response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
|
response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
|
||||||
response.setVersion(HttpVersion.HTTP_1_0);
|
response.setVersion(HttpVersion.HTTP_1_0);
|
||||||
|
@ -580,7 +580,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getsWithQueryParametersDirectlyFrom1_0OriginsAreNotCacheableEvenWithSetting() {
|
void getsWithQueryParametersDirectlyFrom1_0OriginsAreNotCacheableEvenWithSetting() {
|
||||||
policy = new ResponseCachingPolicy(true, true, false);
|
policy = new ResponseCachingPolicy(true, true, false);
|
||||||
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
||||||
response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
|
response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
|
||||||
|
@ -589,7 +589,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headsWithQueryParametersDirectlyFrom1_0OriginsAreNotCacheableEvenWithSetting() {
|
void headsWithQueryParametersDirectlyFrom1_0OriginsAreNotCacheableEvenWithSetting() {
|
||||||
policy = new ResponseCachingPolicy(true, true, false);
|
policy = new ResponseCachingPolicy(true, true, false);
|
||||||
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
||||||
response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
|
response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
|
||||||
|
@ -598,7 +598,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getsWithQueryParametersDirectlyFrom1_0OriginsAreCacheableWithExpires() {
|
void getsWithQueryParametersDirectlyFrom1_0OriginsAreCacheableWithExpires() {
|
||||||
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
||||||
response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
|
response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
|
||||||
response.setVersion(HttpVersion.HTTP_1_0);
|
response.setVersion(HttpVersion.HTTP_1_0);
|
||||||
|
@ -608,7 +608,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headsWithQueryParametersDirectlyFrom1_0OriginsAreCacheableWithExpires() {
|
void headsWithQueryParametersDirectlyFrom1_0OriginsAreCacheableWithExpires() {
|
||||||
policy = new ResponseCachingPolicy(true, false, false);
|
policy = new ResponseCachingPolicy(true, false, false);
|
||||||
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
||||||
response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
|
response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
|
||||||
|
@ -619,7 +619,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getsWithQueryParametersDirectlyFrom1_0OriginsCanBeNotCacheableEvenWithExpires() {
|
void getsWithQueryParametersDirectlyFrom1_0OriginsCanBeNotCacheableEvenWithExpires() {
|
||||||
policy = new ResponseCachingPolicy(true, true, false);
|
policy = new ResponseCachingPolicy(true, true, false);
|
||||||
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
||||||
response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
|
response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
|
||||||
|
@ -630,7 +630,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headsWithQueryParametersDirectlyFrom1_0OriginsCanBeNotCacheableEvenWithExpires() {
|
void headsWithQueryParametersDirectlyFrom1_0OriginsCanBeNotCacheableEvenWithExpires() {
|
||||||
policy = new ResponseCachingPolicy(true, true, false);
|
policy = new ResponseCachingPolicy(true, true, false);
|
||||||
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
||||||
response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
|
response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
|
||||||
|
@ -641,21 +641,21 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getsWithQueryParametersFrom1_0OriginsViaProxiesAreNotCacheable() {
|
void getsWithQueryParametersFrom1_0OriginsViaProxiesAreNotCacheable() {
|
||||||
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
||||||
response.setHeader(HttpHeaders.VIA, "1.0 someproxy");
|
response.setHeader(HttpHeaders.VIA, "1.0 someproxy");
|
||||||
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headsWithQueryParametersFrom1_0OriginsViaProxiesAreNotCacheable() {
|
void headsWithQueryParametersFrom1_0OriginsViaProxiesAreNotCacheable() {
|
||||||
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
||||||
response.setHeader(HttpHeaders.VIA, "1.0 someproxy");
|
response.setHeader(HttpHeaders.VIA, "1.0 someproxy");
|
||||||
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getsWithQueryParametersFrom1_0OriginsViaProxiesAreCacheableWithExpires() {
|
void getsWithQueryParametersFrom1_0OriginsViaProxiesAreCacheableWithExpires() {
|
||||||
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
||||||
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
||||||
response.setHeader("Expires", DateUtils.formatStandardDate(tenSecondsFromNow));
|
response.setHeader("Expires", DateUtils.formatStandardDate(tenSecondsFromNow));
|
||||||
|
@ -664,7 +664,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headsWithQueryParametersFrom1_0OriginsViaProxiesAreCacheableWithExpires() {
|
void headsWithQueryParametersFrom1_0OriginsViaProxiesAreCacheableWithExpires() {
|
||||||
policy = new ResponseCachingPolicy(true, false, false);
|
policy = new ResponseCachingPolicy(true, false, false);
|
||||||
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
||||||
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
||||||
|
@ -674,7 +674,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getsWithQueryParametersFrom1_0OriginsViaProxiesCanNotBeCacheableEvenWithExpires() {
|
void getsWithQueryParametersFrom1_0OriginsViaProxiesCanNotBeCacheableEvenWithExpires() {
|
||||||
policy = new ResponseCachingPolicy(true, true, true);
|
policy = new ResponseCachingPolicy(true, true, true);
|
||||||
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
||||||
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
||||||
|
@ -684,7 +684,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headsWithQueryParametersFrom1_0OriginsViaProxiesCanNotBeCacheableEvenWithExpires() {
|
void headsWithQueryParametersFrom1_0OriginsViaProxiesCanNotBeCacheableEvenWithExpires() {
|
||||||
policy = new ResponseCachingPolicy(true, true, true);
|
policy = new ResponseCachingPolicy(true, true, true);
|
||||||
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
||||||
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
||||||
|
@ -694,7 +694,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getsWithQueryParametersFrom1_0OriginsViaExplicitProxiesAreCacheableWithExpires() {
|
void getsWithQueryParametersFrom1_0OriginsViaExplicitProxiesAreCacheableWithExpires() {
|
||||||
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
||||||
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
||||||
response.setHeader("Expires", DateUtils.formatStandardDate(tenSecondsFromNow));
|
response.setHeader("Expires", DateUtils.formatStandardDate(tenSecondsFromNow));
|
||||||
|
@ -703,7 +703,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headsWithQueryParametersFrom1_0OriginsViaExplicitProxiesAreCacheableWithExpires() {
|
void headsWithQueryParametersFrom1_0OriginsViaExplicitProxiesAreCacheableWithExpires() {
|
||||||
policy = new ResponseCachingPolicy(true, false, false);
|
policy = new ResponseCachingPolicy(true, false, false);
|
||||||
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
||||||
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
||||||
|
@ -713,7 +713,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getsWithQueryParametersFrom1_0OriginsViaExplicitProxiesCanNotBeCacheableEvenWithExpires() {
|
void getsWithQueryParametersFrom1_0OriginsViaExplicitProxiesCanNotBeCacheableEvenWithExpires() {
|
||||||
policy = new ResponseCachingPolicy(true, true, true);
|
policy = new ResponseCachingPolicy(true, true, true);
|
||||||
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
||||||
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
||||||
|
@ -723,7 +723,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headsWithQueryParametersFrom1_0OriginsViaExplicitProxiesCanNotBeCacheableEvenWithExpires() {
|
void headsWithQueryParametersFrom1_0OriginsViaExplicitProxiesCanNotBeCacheableEvenWithExpires() {
|
||||||
policy = new ResponseCachingPolicy(true, true, true);
|
policy = new ResponseCachingPolicy(true, true, true);
|
||||||
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
||||||
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
||||||
|
@ -733,7 +733,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getsWithQueryParametersFrom1_1OriginsVia1_0ProxiesAreCacheableWithExpires() {
|
void getsWithQueryParametersFrom1_1OriginsVia1_0ProxiesAreCacheableWithExpires() {
|
||||||
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
request = new BasicHttpRequest("GET", "/foo?s=bar");
|
||||||
response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
|
response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
|
||||||
response.setVersion(HttpVersion.HTTP_1_0);
|
response.setVersion(HttpVersion.HTTP_1_0);
|
||||||
|
@ -744,7 +744,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headsWithQueryParametersFrom1_1OriginsVia1_0ProxiesAreCacheableWithExpires() {
|
void headsWithQueryParametersFrom1_1OriginsVia1_0ProxiesAreCacheableWithExpires() {
|
||||||
policy = new ResponseCachingPolicy(true, false, false);
|
policy = new ResponseCachingPolicy(true, false, false);
|
||||||
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
|
||||||
response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
|
response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
|
||||||
|
@ -757,21 +757,21 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notCacheableIfExpiresEqualsDateAndNoCacheControl() {
|
void notCacheableIfExpiresEqualsDateAndNoCacheControl() {
|
||||||
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
||||||
response.setHeader("Expires", DateUtils.formatStandardDate(now));
|
response.setHeader("Expires", DateUtils.formatStandardDate(now));
|
||||||
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notCacheableIfExpiresPrecedesDateAndNoCacheControl() {
|
void notCacheableIfExpiresPrecedesDateAndNoCacheControl() {
|
||||||
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
||||||
response.setHeader("Expires", DateUtils.formatStandardDate(sixSecondsAgo));
|
response.setHeader("Expires", DateUtils.formatStandardDate(sixSecondsAgo));
|
||||||
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
Assertions.assertFalse(policy.isResponseCacheable(responseCacheControl, request, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test302WithExplicitCachingHeaders() {
|
void test302WithExplicitCachingHeaders() {
|
||||||
response.setCode(HttpStatus.SC_MOVED_TEMPORARILY);
|
response.setCode(HttpStatus.SC_MOVED_TEMPORARILY);
|
||||||
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
||||||
responseCacheControl = ResponseCacheControl.builder()
|
responseCacheControl = ResponseCacheControl.builder()
|
||||||
|
@ -781,7 +781,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test303WithExplicitCachingHeadersWhenPermittedByConfig() {
|
void test303WithExplicitCachingHeadersWhenPermittedByConfig() {
|
||||||
// HTTPbis working group says ok if explicitly indicated by
|
// HTTPbis working group says ok if explicitly indicated by
|
||||||
// response headers
|
// response headers
|
||||||
policy = new ResponseCachingPolicy(true, false, true);
|
policy = new ResponseCachingPolicy(true, false, true);
|
||||||
|
@ -794,7 +794,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test307WithExplicitCachingHeaders() {
|
void test307WithExplicitCachingHeaders() {
|
||||||
response.setCode(HttpStatus.SC_TEMPORARY_REDIRECT);
|
response.setCode(HttpStatus.SC_TEMPORARY_REDIRECT);
|
||||||
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
||||||
responseCacheControl = ResponseCacheControl.builder()
|
responseCacheControl = ResponseCacheControl.builder()
|
||||||
|
@ -804,7 +804,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void otherStatusCodesAreCacheableWithExplicitCachingHeaders() {
|
void otherStatusCodesAreCacheableWithExplicitCachingHeaders() {
|
||||||
response.setCode(HttpStatus.SC_NOT_FOUND);
|
response.setCode(HttpStatus.SC_NOT_FOUND);
|
||||||
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
response.setHeader("Date", DateUtils.formatStandardDate(now));
|
||||||
responseCacheControl = ResponseCacheControl.builder()
|
responseCacheControl = ResponseCacheControl.builder()
|
||||||
|
@ -895,7 +895,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsResponseCacheable() {
|
void testIsResponseCacheable() {
|
||||||
request = new BasicHttpRequest("GET","/foo?s=bar");
|
request = new BasicHttpRequest("GET","/foo?s=bar");
|
||||||
// HTTPbis working group says ok if explicitly indicated by
|
// HTTPbis working group says ok if explicitly indicated by
|
||||||
// response headers
|
// response headers
|
||||||
|
@ -936,7 +936,7 @@ public class TestResponseCachingPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImmutableAndFreshResponseIsCacheable() {
|
void testImmutableAndFreshResponseIsCacheable() {
|
||||||
responseCacheControl = ResponseCacheControl.builder()
|
responseCacheControl = ResponseCacheControl.builder()
|
||||||
.setImmutable(true)
|
.setImmutable(true)
|
||||||
.setMaxAge(3600) // set this to a value that ensures the response is still fresh
|
.setMaxAge(3600) // set this to a value that ensures the response is still fresh
|
||||||
|
|
|
@ -34,17 +34,17 @@ import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestViaCacheGenerator {
|
class TestViaCacheGenerator {
|
||||||
|
|
||||||
private ViaCacheGenerator impl;
|
private ViaCacheGenerator impl;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
impl = new ViaCacheGenerator();
|
impl = new ViaCacheGenerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testViaValueGeneration() {
|
void testViaValueGeneration() {
|
||||||
Assertions.assertEquals("1.1 localhost (Apache-HttpClient/UNAVAILABLE (cache))",
|
Assertions.assertEquals("1.1 localhost (Apache-HttpClient/UNAVAILABLE (cache))",
|
||||||
impl.generateViaHeader(null, HttpVersion.DEFAULT));
|
impl.generateViaHeader(null, HttpVersion.DEFAULT));
|
||||||
Assertions.assertEquals("2.0 localhost (Apache-HttpClient/UNAVAILABLE (cache))",
|
Assertions.assertEquals("2.0 localhost (Apache-HttpClient/UNAVAILABLE (cache))",
|
||||||
|
@ -52,7 +52,7 @@ public class TestViaCacheGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testViaValueLookup() {
|
void testViaValueLookup() {
|
||||||
MatcherAssert.assertThat(impl.lookup(HttpVersion.DEFAULT),
|
MatcherAssert.assertThat(impl.lookup(HttpVersion.DEFAULT),
|
||||||
Matchers.startsWith("1.1 localhost (Apache-HttpClient/"));
|
Matchers.startsWith("1.1 localhost (Apache-HttpClient/"));
|
||||||
MatcherAssert.assertThat(impl.lookup(HttpVersion.HTTP_1_0),
|
MatcherAssert.assertThat(impl.lookup(HttpVersion.HTTP_1_0),
|
||||||
|
|
|
@ -33,7 +33,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|
||||||
public class TestPrefixKeyHashingScheme {
|
class TestPrefixKeyHashingScheme {
|
||||||
|
|
||||||
private static final String KEY = "key";
|
private static final String KEY = "key";
|
||||||
private static final String PREFIX = "prefix";
|
private static final String PREFIX = "prefix";
|
||||||
|
@ -41,7 +41,7 @@ public class TestPrefixKeyHashingScheme {
|
||||||
private KeyHashingScheme scheme;
|
private KeyHashingScheme scheme;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
scheme = storageKey -> {
|
scheme = storageKey -> {
|
||||||
assertEquals(KEY, storageKey);
|
assertEquals(KEY, storageKey);
|
||||||
return "hash";
|
return "hash";
|
||||||
|
@ -50,7 +50,7 @@ public class TestPrefixKeyHashingScheme {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addsPrefixToBackingScheme() {
|
void addsPrefixToBackingScheme() {
|
||||||
assertEquals("prefixhash", impl.hash(KEY));
|
assertEquals("prefixhash", impl.hash(KEY));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,10 +32,10 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|
||||||
public class TestSHA256HashingScheme {
|
class TestSHA256HashingScheme {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canHash() {
|
void canHash() {
|
||||||
final SHA256KeyHashingScheme impl = new SHA256KeyHashingScheme();
|
final SHA256KeyHashingScheme impl = new SHA256KeyHashingScheme();
|
||||||
final String result = impl.hash("hello, hashing world");
|
final String result = impl.hash("hello, hashing world");
|
||||||
assertTrue(result != null && !result.isEmpty());
|
assertTrue(result != null && !result.isEmpty());
|
||||||
|
|
|
@ -31,12 +31,12 @@ import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestExponentialBackingOffSchedulingStrategy {
|
class TestExponentialBackingOffSchedulingStrategy {
|
||||||
|
|
||||||
private ExponentialBackOffSchedulingStrategy impl;
|
private ExponentialBackOffSchedulingStrategy impl;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
impl = new ExponentialBackOffSchedulingStrategy(
|
impl = new ExponentialBackOffSchedulingStrategy(
|
||||||
ExponentialBackOffSchedulingStrategy.DEFAULT_BACK_OFF_RATE,
|
ExponentialBackOffSchedulingStrategy.DEFAULT_BACK_OFF_RATE,
|
||||||
ExponentialBackOffSchedulingStrategy.DEFAULT_INITIAL_EXPIRY,
|
ExponentialBackOffSchedulingStrategy.DEFAULT_INITIAL_EXPIRY,
|
||||||
|
@ -45,7 +45,7 @@ public class TestExponentialBackingOffSchedulingStrategy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSchedule() {
|
void testSchedule() {
|
||||||
Assertions.assertEquals(TimeValue.ofMilliseconds(0), impl.schedule(0));
|
Assertions.assertEquals(TimeValue.ofMilliseconds(0), impl.schedule(0));
|
||||||
Assertions.assertEquals(TimeValue.ofMilliseconds(6000), impl.schedule(1));
|
Assertions.assertEquals(TimeValue.ofMilliseconds(6000), impl.schedule(1));
|
||||||
Assertions.assertEquals(TimeValue.ofMilliseconds(60000), impl.schedule(2));
|
Assertions.assertEquals(TimeValue.ofMilliseconds(60000), impl.schedule(2));
|
||||||
|
|
|
@ -32,17 +32,17 @@ import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestImmediateSchedulingStrategy {
|
class TestImmediateSchedulingStrategy {
|
||||||
|
|
||||||
private SchedulingStrategy impl;
|
private SchedulingStrategy impl;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
impl = new ImmediateSchedulingStrategy();
|
impl = new ImmediateSchedulingStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSchedule() {
|
void testSchedule() {
|
||||||
Assertions.assertEquals(TimeValue.ZERO_MILLISECONDS, impl.schedule(0));
|
Assertions.assertEquals(TimeValue.ZERO_MILLISECONDS, impl.schedule(0));
|
||||||
Assertions.assertEquals(TimeValue.ZERO_MILLISECONDS, impl.schedule(1));
|
Assertions.assertEquals(TimeValue.ZERO_MILLISECONDS, impl.schedule(1));
|
||||||
Assertions.assertEquals(TimeValue.ZERO_MILLISECONDS, impl.schedule(Integer.MAX_VALUE));
|
Assertions.assertEquals(TimeValue.ZERO_MILLISECONDS, impl.schedule(Integer.MAX_VALUE));
|
||||||
|
|
|
@ -31,7 +31,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import org.hamcrest.CoreMatchers;
|
import org.hamcrest.CoreMatchers;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestConcurrentCountMap
|
class TestConcurrentCountMap
|
||||||
{
|
{
|
||||||
|
|
||||||
private static final String IDENTIFIER = "some-identifier";
|
private static final String IDENTIFIER = "some-identifier";
|
||||||
|
@ -39,7 +39,7 @@ public class TestConcurrentCountMap
|
||||||
private final ConcurrentCountMap<String> map = new ConcurrentCountMap<>();
|
private final ConcurrentCountMap<String> map = new ConcurrentCountMap<>();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasics() {
|
void testBasics() {
|
||||||
map.increaseCount(IDENTIFIER);
|
map.increaseCount(IDENTIFIER);
|
||||||
map.increaseCount(IDENTIFIER);
|
map.increaseCount(IDENTIFIER);
|
||||||
assertThat(map.getCount(IDENTIFIER), CoreMatchers.equalTo(2));
|
assertThat(map.getCount(IDENTIFIER), CoreMatchers.equalTo(2));
|
||||||
|
|
|
@ -37,12 +37,12 @@ import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.Arguments;
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
|
||||||
public class TestRequest {
|
class TestRequest {
|
||||||
|
|
||||||
private static final String URI_STRING_FIXTURE = "http://localhost";
|
private static final String URI_STRING_FIXTURE = "http://localhost";
|
||||||
private static final URI URI_FIXTURE = URI.create(URI_STRING_FIXTURE);
|
private static final URI URI_FIXTURE = URI.create(URI_STRING_FIXTURE);
|
||||||
|
|
||||||
public static Stream<Arguments> data() {
|
static Stream<Arguments> data() {
|
||||||
return Stream.of(
|
return Stream.of(
|
||||||
Arguments.of("delete", "DELETE"),
|
Arguments.of("delete", "DELETE"),
|
||||||
Arguments.of("get", "GET"),
|
Arguments.of("get", "GET"),
|
||||||
|
@ -57,7 +57,7 @@ public class TestRequest {
|
||||||
|
|
||||||
@ParameterizedTest(name = "{index}: {0} => {1}")
|
@ParameterizedTest(name = "{index}: {0} => {1}")
|
||||||
@MethodSource("data")
|
@MethodSource("data")
|
||||||
public void testCreateFromString(final String methodName, final String expectedMethod) throws Exception {
|
void testCreateFromString(final String methodName, final String expectedMethod) throws Exception {
|
||||||
final Method method = Request.class.getMethod(methodName, String.class);
|
final Method method = Request.class.getMethod(methodName, String.class);
|
||||||
final Request request = (Request) method.invoke(null, URI_STRING_FIXTURE);
|
final Request request = (Request) method.invoke(null, URI_STRING_FIXTURE);
|
||||||
final ClassicHttpRequest classicHttpRequest = request.getRequest();
|
final ClassicHttpRequest classicHttpRequest = request.getRequest();
|
||||||
|
@ -66,7 +66,7 @@ public class TestRequest {
|
||||||
|
|
||||||
@ParameterizedTest(name = "{index}: {0} => {1}")
|
@ParameterizedTest(name = "{index}: {0} => {1}")
|
||||||
@MethodSource("data")
|
@MethodSource("data")
|
||||||
public void testCreateFromURI(final String methodName, final String expectedMethod) throws Exception {
|
void testCreateFromURI(final String methodName, final String expectedMethod) throws Exception {
|
||||||
final Method method = Request.class.getMethod(methodName, URI.class);
|
final Method method = Request.class.getMethod(methodName, URI.class);
|
||||||
final Request request = (Request) method.invoke(null, URI_FIXTURE);
|
final Request request = (Request) method.invoke(null, URI_FIXTURE);
|
||||||
final ClassicHttpRequest classicHttpRequest = request.getRequest();
|
final ClassicHttpRequest classicHttpRequest = request.getRequest();
|
||||||
|
|
|
@ -76,14 +76,14 @@ import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
public abstract class AbstractHttpAsyncClientAuthenticationTest extends AbstractIntegrationTestBase {
|
abstract class AbstractHttpAsyncClientAuthenticationTest extends AbstractIntegrationTestBase {
|
||||||
|
|
||||||
public AbstractHttpAsyncClientAuthenticationTest(final URIScheme scheme, final ClientProtocolLevel clientProtocolLevel, final ServerProtocolLevel serverProtocolLevel) {
|
public AbstractHttpAsyncClientAuthenticationTest(final URIScheme scheme, final ClientProtocolLevel clientProtocolLevel, final ServerProtocolLevel serverProtocolLevel) {
|
||||||
super(scheme, clientProtocolLevel, serverProtocolLevel);
|
super(scheme, clientProtocolLevel, serverProtocolLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicAuthenticationNoCreds() throws Exception {
|
void testBasicAuthenticationNoCreds() throws Exception {
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
configureServer(bootstrap -> bootstrap.register("*", AsyncEchoHandler::new));
|
configureServer(bootstrap -> bootstrap.register("*", AsyncEchoHandler::new));
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ public abstract class AbstractHttpAsyncClientAuthenticationTest extends Abstract
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicAuthenticationFailure() throws Exception {
|
void testBasicAuthenticationFailure() throws Exception {
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
configureServer(bootstrap -> bootstrap.register("*", AsyncEchoHandler::new));
|
configureServer(bootstrap -> bootstrap.register("*", AsyncEchoHandler::new));
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ public abstract class AbstractHttpAsyncClientAuthenticationTest extends Abstract
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicAuthenticationSuccess() throws Exception {
|
void testBasicAuthenticationSuccess() throws Exception {
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
configureServer(bootstrap -> bootstrap.register("*", AsyncEchoHandler::new));
|
configureServer(bootstrap -> bootstrap.register("*", AsyncEchoHandler::new));
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ public abstract class AbstractHttpAsyncClientAuthenticationTest extends Abstract
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicAuthenticationWithEntitySuccess() throws Exception {
|
void testBasicAuthenticationWithEntitySuccess() throws Exception {
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
configureServer(bootstrap -> bootstrap.register("*", AsyncEchoHandler::new));
|
configureServer(bootstrap -> bootstrap.register("*", AsyncEchoHandler::new));
|
||||||
|
|
||||||
|
@ -183,7 +183,7 @@ public abstract class AbstractHttpAsyncClientAuthenticationTest extends Abstract
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicAuthenticationExpectationFailure() throws Exception {
|
void testBasicAuthenticationExpectationFailure() throws Exception {
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
configureServer(bootstrap -> bootstrap.register("*", AsyncEchoHandler::new));
|
configureServer(bootstrap -> bootstrap.register("*", AsyncEchoHandler::new));
|
||||||
|
|
||||||
|
@ -208,7 +208,7 @@ public abstract class AbstractHttpAsyncClientAuthenticationTest extends Abstract
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicAuthenticationExpectationSuccess() throws Exception {
|
void testBasicAuthenticationExpectationSuccess() throws Exception {
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
configureServer(bootstrap -> bootstrap.register("*", AsyncEchoHandler::new));
|
configureServer(bootstrap -> bootstrap.register("*", AsyncEchoHandler::new));
|
||||||
|
|
||||||
|
@ -235,7 +235,7 @@ public abstract class AbstractHttpAsyncClientAuthenticationTest extends Abstract
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicAuthenticationCredentialsCaching() throws Exception {
|
void testBasicAuthenticationCredentialsCaching() throws Exception {
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
configureServer(bootstrap -> bootstrap.register("*", AsyncEchoHandler::new));
|
configureServer(bootstrap -> bootstrap.register("*", AsyncEchoHandler::new));
|
||||||
|
|
||||||
|
@ -262,7 +262,7 @@ public abstract class AbstractHttpAsyncClientAuthenticationTest extends Abstract
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicAuthenticationCredentialsCachingByPathPrefix() throws Exception {
|
void testBasicAuthenticationCredentialsCachingByPathPrefix() throws Exception {
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
configureServer(bootstrap -> bootstrap.register("*", AsyncEchoHandler::new));
|
configureServer(bootstrap -> bootstrap.register("*", AsyncEchoHandler::new));
|
||||||
|
|
||||||
|
@ -327,7 +327,7 @@ public abstract class AbstractHttpAsyncClientAuthenticationTest extends Abstract
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAuthenticationUserinfoInRequestFailure() throws Exception {
|
void testAuthenticationUserinfoInRequestFailure() throws Exception {
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
configureServer(bootstrap -> bootstrap.register("*", AsyncEchoHandler::new));
|
configureServer(bootstrap -> bootstrap.register("*", AsyncEchoHandler::new));
|
||||||
|
|
||||||
|
@ -344,7 +344,7 @@ public abstract class AbstractHttpAsyncClientAuthenticationTest extends Abstract
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReauthentication() throws Exception {
|
void testReauthentication() throws Exception {
|
||||||
final Authenticator authenticator = new BasicTestAuthenticator("test:test", "test realm") {
|
final Authenticator authenticator = new BasicTestAuthenticator("test:test", "test realm") {
|
||||||
|
|
||||||
private final AtomicLong count = new AtomicLong(0);
|
private final AtomicLong count = new AtomicLong(0);
|
||||||
|
@ -413,7 +413,7 @@ public abstract class AbstractHttpAsyncClientAuthenticationTest extends Abstract
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAuthenticationFallback() throws Exception {
|
void testAuthenticationFallback() throws Exception {
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("*", AsyncEchoHandler::new)
|
.register("*", AsyncEchoHandler::new)
|
||||||
|
@ -448,7 +448,7 @@ public abstract class AbstractHttpAsyncClientAuthenticationTest extends Abstract
|
||||||
private final static String CHARS = "0123456789abcdef";
|
private final static String CHARS = "0123456789abcdef";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBearerTokenAuthentication() throws Exception {
|
void testBearerTokenAuthentication() throws Exception {
|
||||||
final SecureRandom secureRandom = SecureRandom.getInstanceStrong();
|
final SecureRandom secureRandom = SecureRandom.getInstanceStrong();
|
||||||
secureRandom.setSeed(System.currentTimeMillis());
|
secureRandom.setSeed(System.currentTimeMillis());
|
||||||
final StringBuilder buf = new StringBuilder();
|
final StringBuilder buf = new StringBuilder();
|
||||||
|
|
|
@ -58,14 +58,14 @@ import org.apache.hc.core5.http.nio.support.BasicResponseConsumer;
|
||||||
import org.hamcrest.CoreMatchers;
|
import org.hamcrest.CoreMatchers;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public abstract class AbstractHttpAsyncFundamentalsTest extends AbstractIntegrationTestBase {
|
abstract class AbstractHttpAsyncFundamentalsTest extends AbstractIntegrationTestBase {
|
||||||
|
|
||||||
protected AbstractHttpAsyncFundamentalsTest(final URIScheme scheme, final ClientProtocolLevel clientProtocolLevel, final ServerProtocolLevel serverProtocolLevel) {
|
protected AbstractHttpAsyncFundamentalsTest(final URIScheme scheme, final ClientProtocolLevel clientProtocolLevel, final ServerProtocolLevel serverProtocolLevel) {
|
||||||
super(scheme, clientProtocolLevel, serverProtocolLevel);
|
super(scheme, clientProtocolLevel, serverProtocolLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSequentialGetRequests() throws Exception {
|
void testSequentialGetRequests() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap.register("/random/*", AsyncRandomHandler::new));
|
configureServer(bootstrap -> bootstrap.register("/random/*", AsyncRandomHandler::new));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ public abstract class AbstractHttpAsyncFundamentalsTest extends AbstractIntegrat
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSequentialHeadRequests() throws Exception {
|
void testSequentialHeadRequests() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap.register("/random/*", AsyncRandomHandler::new));
|
configureServer(bootstrap -> bootstrap.register("/random/*", AsyncRandomHandler::new));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
final TestAsyncClient client = startClient();
|
final TestAsyncClient client = startClient();
|
||||||
|
@ -106,7 +106,7 @@ public abstract class AbstractHttpAsyncFundamentalsTest extends AbstractIntegrat
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSequentialPostRequests() throws Exception {
|
void testSequentialPostRequests() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap.register("/echo/*", AsyncEchoHandler::new));
|
configureServer(bootstrap -> bootstrap.register("/echo/*", AsyncEchoHandler::new));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
final TestAsyncClient client = startClient();
|
final TestAsyncClient client = startClient();
|
||||||
|
@ -128,7 +128,7 @@ public abstract class AbstractHttpAsyncFundamentalsTest extends AbstractIntegrat
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConcurrentPostRequests() throws Exception {
|
void testConcurrentPostRequests() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap.register("/echo/*", AsyncEchoHandler::new));
|
configureServer(bootstrap -> bootstrap.register("/echo/*", AsyncEchoHandler::new));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
final TestAsyncClient client = startClient();
|
final TestAsyncClient client = startClient();
|
||||||
|
@ -159,7 +159,7 @@ public abstract class AbstractHttpAsyncFundamentalsTest extends AbstractIntegrat
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRequestExecutionFromCallback() throws Exception {
|
void testRequestExecutionFromCallback() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap.register("/random/*", AsyncRandomHandler::new));
|
configureServer(bootstrap -> bootstrap.register("/random/*", AsyncRandomHandler::new));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
final TestAsyncClient client = startClient();
|
final TestAsyncClient client = startClient();
|
||||||
|
@ -226,7 +226,7 @@ public abstract class AbstractHttpAsyncFundamentalsTest extends AbstractIntegrat
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBadRequest() throws Exception {
|
void testBadRequest() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap.register("/random/*", AsyncRandomHandler::new));
|
configureServer(bootstrap -> bootstrap.register("/random/*", AsyncRandomHandler::new));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
final TestAsyncClient client = startClient();
|
final TestAsyncClient client = startClient();
|
||||||
|
|
|
@ -66,14 +66,14 @@ import org.hamcrest.CoreMatchers;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public abstract class AbstractHttpAsyncRedirectsTest extends AbstractIntegrationTestBase {
|
abstract class AbstractHttpAsyncRedirectsTest extends AbstractIntegrationTestBase {
|
||||||
|
|
||||||
public AbstractHttpAsyncRedirectsTest(final URIScheme scheme, final ClientProtocolLevel clientProtocolLevel, final ServerProtocolLevel serverProtocolLevel) {
|
public AbstractHttpAsyncRedirectsTest(final URIScheme scheme, final ClientProtocolLevel clientProtocolLevel, final ServerProtocolLevel serverProtocolLevel) {
|
||||||
super(scheme, clientProtocolLevel, serverProtocolLevel);
|
super(scheme, clientProtocolLevel, serverProtocolLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicRedirect300() throws Exception {
|
void testBasicRedirect300() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/random/*", AsyncRandomHandler::new)
|
.register("/random/*", AsyncRandomHandler::new)
|
||||||
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
||||||
|
@ -99,7 +99,7 @@ public abstract class AbstractHttpAsyncRedirectsTest extends AbstractIntegration
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicRedirect301() throws Exception {
|
void testBasicRedirect301() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/random/*", AsyncRandomHandler::new)
|
.register("/random/*", AsyncRandomHandler::new)
|
||||||
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
||||||
|
@ -126,7 +126,7 @@ public abstract class AbstractHttpAsyncRedirectsTest extends AbstractIntegration
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicRedirect302() throws Exception {
|
void testBasicRedirect302() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/random/*", AsyncRandomHandler::new)
|
.register("/random/*", AsyncRandomHandler::new)
|
||||||
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
||||||
|
@ -153,7 +153,7 @@ public abstract class AbstractHttpAsyncRedirectsTest extends AbstractIntegration
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicRedirect302NoLocation() throws Exception {
|
void testBasicRedirect302NoLocation() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/random/*", AsyncRandomHandler::new)
|
.register("/random/*", AsyncRandomHandler::new)
|
||||||
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
||||||
|
@ -185,7 +185,7 @@ public abstract class AbstractHttpAsyncRedirectsTest extends AbstractIntegration
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicRedirect303() throws Exception {
|
void testBasicRedirect303() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/random/*", AsyncRandomHandler::new)
|
.register("/random/*", AsyncRandomHandler::new)
|
||||||
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
||||||
|
@ -213,14 +213,14 @@ public abstract class AbstractHttpAsyncRedirectsTest extends AbstractIntegration
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicRedirect304() throws Exception {
|
void testBasicRedirect304() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/random/*", AsyncRandomHandler::new)
|
.register("/random/*", AsyncRandomHandler::new)
|
||||||
.register("/oldlocation/*", () -> new AbstractSimpleServerExchangeHandler() {
|
.register("/oldlocation/*", () -> new AbstractSimpleServerExchangeHandler() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SimpleHttpResponse handle(final SimpleHttpRequest request,
|
protected SimpleHttpResponse handle(final SimpleHttpRequest request,
|
||||||
final HttpCoreContext context) throws HttpException {
|
final HttpCoreContext context) {
|
||||||
return SimpleHttpResponse.create(HttpStatus.SC_NOT_MODIFIED, (String) null);
|
return SimpleHttpResponse.create(HttpStatus.SC_NOT_MODIFIED, (String) null);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
@ -244,14 +244,14 @@ public abstract class AbstractHttpAsyncRedirectsTest extends AbstractIntegration
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicRedirect305() throws Exception {
|
void testBasicRedirect305() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/random/*", AsyncRandomHandler::new)
|
.register("/random/*", AsyncRandomHandler::new)
|
||||||
.register("/oldlocation/*", () -> new AbstractSimpleServerExchangeHandler() {
|
.register("/oldlocation/*", () -> new AbstractSimpleServerExchangeHandler() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SimpleHttpResponse handle(final SimpleHttpRequest request,
|
protected SimpleHttpResponse handle(final SimpleHttpRequest request,
|
||||||
final HttpCoreContext context) throws HttpException {
|
final HttpCoreContext context) {
|
||||||
return SimpleHttpResponse.create(HttpStatus.SC_USE_PROXY, (String) null);
|
return SimpleHttpResponse.create(HttpStatus.SC_USE_PROXY, (String) null);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
@ -275,7 +275,7 @@ public abstract class AbstractHttpAsyncRedirectsTest extends AbstractIntegration
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicRedirect307() throws Exception {
|
void testBasicRedirect307() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/random/*", AsyncRandomHandler::new)
|
.register("/random/*", AsyncRandomHandler::new)
|
||||||
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
||||||
|
@ -302,7 +302,7 @@ public abstract class AbstractHttpAsyncRedirectsTest extends AbstractIntegration
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMaxRedirectCheck() throws Exception {
|
void testMaxRedirectCheck() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/random/*", AsyncRandomHandler::new)
|
.register("/random/*", AsyncRandomHandler::new)
|
||||||
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
||||||
|
@ -328,7 +328,7 @@ public abstract class AbstractHttpAsyncRedirectsTest extends AbstractIntegration
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCircularRedirect() throws Exception {
|
void testCircularRedirect() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/random/*", AsyncRandomHandler::new)
|
.register("/random/*", AsyncRandomHandler::new)
|
||||||
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
||||||
|
@ -355,7 +355,7 @@ public abstract class AbstractHttpAsyncRedirectsTest extends AbstractIntegration
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPostRedirect() throws Exception {
|
void testPostRedirect() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/echo/*", AsyncEchoHandler::new)
|
.register("/echo/*", AsyncEchoHandler::new)
|
||||||
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
||||||
|
@ -383,7 +383,7 @@ public abstract class AbstractHttpAsyncRedirectsTest extends AbstractIntegration
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPostRedirectSeeOther() throws Exception {
|
void testPostRedirectSeeOther() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/echo/*", AsyncEchoHandler::new)
|
.register("/echo/*", AsyncEchoHandler::new)
|
||||||
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
||||||
|
@ -411,7 +411,7 @@ public abstract class AbstractHttpAsyncRedirectsTest extends AbstractIntegration
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelativeRedirect() throws Exception {
|
void testRelativeRedirect() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/random/*", AsyncRandomHandler::new)
|
.register("/random/*", AsyncRandomHandler::new)
|
||||||
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
||||||
|
@ -446,7 +446,7 @@ public abstract class AbstractHttpAsyncRedirectsTest extends AbstractIntegration
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelativeRedirect2() throws Exception {
|
void testRelativeRedirect2() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/random/*", AsyncRandomHandler::new)
|
.register("/random/*", AsyncRandomHandler::new)
|
||||||
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
||||||
|
@ -481,7 +481,7 @@ public abstract class AbstractHttpAsyncRedirectsTest extends AbstractIntegration
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRejectBogusRedirectLocation() throws Exception {
|
void testRejectBogusRedirectLocation() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/random/*", AsyncRandomHandler::new)
|
.register("/random/*", AsyncRandomHandler::new)
|
||||||
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
||||||
|
@ -510,7 +510,7 @@ public abstract class AbstractHttpAsyncRedirectsTest extends AbstractIntegration
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRejectInvalidRedirectLocation() throws Exception {
|
void testRejectInvalidRedirectLocation() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/random/*", AsyncRandomHandler::new)
|
.register("/random/*", AsyncRandomHandler::new)
|
||||||
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
||||||
|
@ -538,7 +538,7 @@ public abstract class AbstractHttpAsyncRedirectsTest extends AbstractIntegration
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRedirectWithCookie() throws Exception {
|
void testRedirectWithCookie() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/random/*", AsyncRandomHandler::new)
|
.register("/random/*", AsyncRandomHandler::new)
|
||||||
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
||||||
|
@ -576,7 +576,7 @@ public abstract class AbstractHttpAsyncRedirectsTest extends AbstractIntegration
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCrossSiteRedirect() throws Exception {
|
void testCrossSiteRedirect() throws Exception {
|
||||||
final URIScheme scheme = scheme();
|
final URIScheme scheme = scheme();
|
||||||
final TestAsyncServer secondServer = new TestAsyncServerBootstrap(scheme(), getServerProtocolLevel())
|
final TestAsyncServer secondServer = new TestAsyncServerBootstrap(scheme(), getServerProtocolLevel())
|
||||||
.register("/random/*", AsyncRandomHandler::new)
|
.register("/random/*", AsyncRandomHandler::new)
|
||||||
|
|
|
@ -77,7 +77,7 @@ import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.Timeout;
|
import org.junit.jupiter.api.Timeout;
|
||||||
import org.reactivestreams.Publisher;
|
import org.reactivestreams.Publisher;
|
||||||
|
|
||||||
public abstract class AbstractHttpReactiveFundamentalsTest extends AbstractIntegrationTestBase {
|
abstract class AbstractHttpReactiveFundamentalsTest extends AbstractIntegrationTestBase {
|
||||||
|
|
||||||
public AbstractHttpReactiveFundamentalsTest(final URIScheme scheme, final ClientProtocolLevel clientProtocolLevel, final ServerProtocolLevel serverProtocolLevel) {
|
public AbstractHttpReactiveFundamentalsTest(final URIScheme scheme, final ClientProtocolLevel clientProtocolLevel, final ServerProtocolLevel serverProtocolLevel) {
|
||||||
super(scheme, clientProtocolLevel, serverProtocolLevel);
|
super(scheme, clientProtocolLevel, serverProtocolLevel);
|
||||||
|
@ -271,7 +271,7 @@ public abstract class AbstractHttpReactiveFundamentalsTest extends AbstractInteg
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBadRequest() throws Exception {
|
void testBadRequest() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap.register("/random/*", () ->
|
configureServer(bootstrap -> bootstrap.register("/random/*", () ->
|
||||||
new ReactiveServerExchangeHandler(new ReactiveRandomProcessor())));
|
new ReactiveServerExchangeHandler(new ReactiveRandomProcessor())));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
|
|
@ -42,7 +42,7 @@ import org.apache.hc.core5.http.URIScheme;
|
||||||
import org.apache.hc.core5.util.Timeout;
|
import org.apache.hc.core5.util.Timeout;
|
||||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
public abstract class AbstractIntegrationTestBase {
|
abstract class AbstractIntegrationTestBase {
|
||||||
|
|
||||||
public static final Timeout TIMEOUT = Timeout.ofMinutes(1);
|
public static final Timeout TIMEOUT = Timeout.ofMinutes(1);
|
||||||
|
|
||||||
|
|
|
@ -31,13 +31,13 @@ import org.apache.hc.core5.http.URIScheme;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Nested;
|
import org.junit.jupiter.api.Nested;
|
||||||
|
|
||||||
public class HttpIntegrationTests {
|
class HttpIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Fundamentals (HTTP/1.1)")
|
@DisplayName("Fundamentals (HTTP/1.1)")
|
||||||
public class Http1 extends TestHttp1Async {
|
class Http1 extends TestHttp1Async {
|
||||||
|
|
||||||
public Http1() throws Exception {
|
public Http1() {
|
||||||
super(URIScheme.HTTP);
|
super(URIScheme.HTTP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,9 +45,9 @@ public class HttpIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Fundamentals (HTTP/1.1, TLS)")
|
@DisplayName("Fundamentals (HTTP/1.1, TLS)")
|
||||||
public class Http1Tls extends TestHttp1Async {
|
class Http1Tls extends TestHttp1Async {
|
||||||
|
|
||||||
public Http1Tls() throws Exception {
|
public Http1Tls() {
|
||||||
super(URIScheme.HTTPS);
|
super(URIScheme.HTTPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,9 +55,9 @@ public class HttpIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Fundamentals (HTTP/2)")
|
@DisplayName("Fundamentals (HTTP/2)")
|
||||||
public class H2 extends TestH2Async {
|
class H2 extends TestH2Async {
|
||||||
|
|
||||||
public H2() throws Exception {
|
public H2() {
|
||||||
super(URIScheme.HTTP);
|
super(URIScheme.HTTP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,9 +65,9 @@ public class HttpIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Fundamentals (HTTP/2, TLS)")
|
@DisplayName("Fundamentals (HTTP/2, TLS)")
|
||||||
public class H2Tls extends TestH2Async {
|
class H2Tls extends TestH2Async {
|
||||||
|
|
||||||
public H2Tls() throws Exception {
|
public H2Tls() {
|
||||||
super(URIScheme.HTTPS);
|
super(URIScheme.HTTPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,9 +75,9 @@ public class HttpIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Request re-execution (HTTP/1.1)")
|
@DisplayName("Request re-execution (HTTP/1.1)")
|
||||||
public class Http1RequestReExecution extends TestHttp1RequestReExecution {
|
class Http1RequestReExecution extends TestHttp1RequestReExecution {
|
||||||
|
|
||||||
public Http1RequestReExecution() throws Exception {
|
public Http1RequestReExecution() {
|
||||||
super(URIScheme.HTTP);
|
super(URIScheme.HTTP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,9 +85,9 @@ public class HttpIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Request re-execution (HTTP/1.1, TLS)")
|
@DisplayName("Request re-execution (HTTP/1.1, TLS)")
|
||||||
public class Http1RequestReExecutionTls extends TestHttp1RequestReExecution {
|
class Http1RequestReExecutionTls extends TestHttp1RequestReExecution {
|
||||||
|
|
||||||
public Http1RequestReExecutionTls() throws Exception {
|
public Http1RequestReExecutionTls() {
|
||||||
super(URIScheme.HTTPS);
|
super(URIScheme.HTTPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,9 +95,9 @@ public class HttpIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("HTTP protocol policy (HTTP/1.1)")
|
@DisplayName("HTTP protocol policy (HTTP/1.1)")
|
||||||
public class Http1ProtocolPolicy extends TestHttpAsyncProtocolPolicy {
|
class Http1ProtocolPolicy extends TestHttpAsyncProtocolPolicy {
|
||||||
|
|
||||||
public Http1ProtocolPolicy() throws Exception {
|
public Http1ProtocolPolicy() {
|
||||||
super(URIScheme.HTTP, HttpVersion.HTTP_1_1);
|
super(URIScheme.HTTP, HttpVersion.HTTP_1_1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,9 +105,9 @@ public class HttpIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("HTTP protocol policy (HTTP/1.1, TLS)")
|
@DisplayName("HTTP protocol policy (HTTP/1.1, TLS)")
|
||||||
public class Http1ProtocolPolicyTls extends TestHttpAsyncProtocolPolicy {
|
class Http1ProtocolPolicyTls extends TestHttpAsyncProtocolPolicy {
|
||||||
|
|
||||||
public Http1ProtocolPolicyTls() throws Exception {
|
public Http1ProtocolPolicyTls() {
|
||||||
super(URIScheme.HTTPS, HttpVersion.HTTP_1_1);
|
super(URIScheme.HTTPS, HttpVersion.HTTP_1_1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,9 +115,9 @@ public class HttpIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("HTTP protocol policy (HTTP/2)")
|
@DisplayName("HTTP protocol policy (HTTP/2)")
|
||||||
public class H2ProtocolPolicy extends TestHttpAsyncProtocolPolicy {
|
class H2ProtocolPolicy extends TestHttpAsyncProtocolPolicy {
|
||||||
|
|
||||||
public H2ProtocolPolicy() throws Exception {
|
public H2ProtocolPolicy() {
|
||||||
super(URIScheme.HTTP, HttpVersion.HTTP_2);
|
super(URIScheme.HTTP, HttpVersion.HTTP_2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,9 +125,9 @@ public class HttpIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("HTTP protocol policy (HTTP/2, TLS)")
|
@DisplayName("HTTP protocol policy (HTTP/2, TLS)")
|
||||||
public class H2ProtocolPolicyTls extends TestHttpAsyncProtocolPolicy {
|
class H2ProtocolPolicyTls extends TestHttpAsyncProtocolPolicy {
|
||||||
|
|
||||||
public H2ProtocolPolicyTls() throws Exception {
|
public H2ProtocolPolicyTls() {
|
||||||
super(URIScheme.HTTPS, HttpVersion.HTTP_2);
|
super(URIScheme.HTTPS, HttpVersion.HTTP_2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,9 +135,9 @@ public class HttpIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Redirects (HTTP/1.1)")
|
@DisplayName("Redirects (HTTP/1.1)")
|
||||||
public class RedirectsHttp1 extends TestHttp1AsyncRedirects {
|
class RedirectsHttp1 extends TestHttp1AsyncRedirects {
|
||||||
|
|
||||||
public RedirectsHttp1() throws Exception {
|
public RedirectsHttp1() {
|
||||||
super(URIScheme.HTTP);
|
super(URIScheme.HTTP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,9 +145,9 @@ public class HttpIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Redirects (HTTP/1.1, TLS)")
|
@DisplayName("Redirects (HTTP/1.1, TLS)")
|
||||||
public class RedirectsHttp1Tls extends TestHttp1AsyncRedirects {
|
class RedirectsHttp1Tls extends TestHttp1AsyncRedirects {
|
||||||
|
|
||||||
public RedirectsHttp1Tls() throws Exception {
|
public RedirectsHttp1Tls() {
|
||||||
super(URIScheme.HTTPS);
|
super(URIScheme.HTTPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,9 +155,9 @@ public class HttpIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Redirects (HTTP/2)")
|
@DisplayName("Redirects (HTTP/2)")
|
||||||
public class RedirectsH2 extends TestH2AsyncRedirect {
|
class RedirectsH2 extends TestH2AsyncRedirect {
|
||||||
|
|
||||||
public RedirectsH2() throws Exception {
|
public RedirectsH2() {
|
||||||
super(URIScheme.HTTP);
|
super(URIScheme.HTTP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,9 +165,9 @@ public class HttpIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Redirects (HTTP/2, TLS)")
|
@DisplayName("Redirects (HTTP/2, TLS)")
|
||||||
public class RedirectsH2Tls extends TestH2AsyncRedirect {
|
class RedirectsH2Tls extends TestH2AsyncRedirect {
|
||||||
|
|
||||||
public RedirectsH2Tls() throws Exception {
|
public RedirectsH2Tls() {
|
||||||
super(URIScheme.HTTPS);
|
super(URIScheme.HTTPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ public class HttpIntegrationTests {
|
||||||
|
|
||||||
// @Nested
|
// @Nested
|
||||||
// @DisplayName("Client authentication (HTTP/1.1)")
|
// @DisplayName("Client authentication (HTTP/1.1)")
|
||||||
// public class AuthenticationHttp1 extends TestHttp1ClientAuthentication {
|
// class AuthenticationHttp1 extends TestHttp1ClientAuthentication {
|
||||||
//
|
//
|
||||||
// public AuthenticationHttp1() throws Exception {
|
// public AuthenticationHttp1() throws Exception {
|
||||||
// super(URIScheme.HTTP);
|
// super(URIScheme.HTTP);
|
||||||
|
@ -185,7 +185,7 @@ public class HttpIntegrationTests {
|
||||||
//
|
//
|
||||||
// @Nested
|
// @Nested
|
||||||
// @DisplayName("Client authentication (HTTP/1.1, TLS)")
|
// @DisplayName("Client authentication (HTTP/1.1, TLS)")
|
||||||
// public class AuthenticationHttp1Tls extends TestHttp1ClientAuthentication {
|
// class AuthenticationHttp1Tls extends TestHttp1ClientAuthentication {
|
||||||
//
|
//
|
||||||
// public AuthenticationHttp1Tls() throws Exception {
|
// public AuthenticationHttp1Tls() throws Exception {
|
||||||
// super(URIScheme.HTTPS);
|
// super(URIScheme.HTTPS);
|
||||||
|
@ -195,7 +195,7 @@ public class HttpIntegrationTests {
|
||||||
|
|
||||||
// @Nested
|
// @Nested
|
||||||
// @DisplayName("Client authentication (HTTP/2)")
|
// @DisplayName("Client authentication (HTTP/2)")
|
||||||
// public class AuthenticationH2 extends TestH2ClientAuthentication {
|
// class AuthenticationH2 extends TestH2ClientAuthentication {
|
||||||
//
|
//
|
||||||
// public AuthenticationH2() throws Exception {
|
// public AuthenticationH2() throws Exception {
|
||||||
// super(URIScheme.HTTP);
|
// super(URIScheme.HTTP);
|
||||||
|
@ -205,7 +205,7 @@ public class HttpIntegrationTests {
|
||||||
//
|
//
|
||||||
// @Nested
|
// @Nested
|
||||||
// @DisplayName("Client authentication (HTTP/2, TLS)")
|
// @DisplayName("Client authentication (HTTP/2, TLS)")
|
||||||
// public class AuthenticationH2Tls extends TestH2ClientAuthentication {
|
// class AuthenticationH2Tls extends TestH2ClientAuthentication {
|
||||||
//
|
//
|
||||||
// public AuthenticationH2Tls() throws Exception {
|
// public AuthenticationH2Tls() throws Exception {
|
||||||
// super(URIScheme.HTTPS);
|
// super(URIScheme.HTTPS);
|
||||||
|
|
|
@ -30,13 +30,13 @@ import org.apache.hc.core5.http.URIScheme;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Nested;
|
import org.junit.jupiter.api.Nested;
|
||||||
|
|
||||||
public class HttpMinimalIntegrationTests {
|
class HttpMinimalIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Fundamentals (HTTP/1.1)")
|
@DisplayName("Fundamentals (HTTP/1.1)")
|
||||||
public class Http1 extends TestHttp1AsyncMinimal {
|
class Http1 extends TestHttp1AsyncMinimal {
|
||||||
|
|
||||||
public Http1() throws Exception {
|
public Http1() {
|
||||||
super(URIScheme.HTTP);
|
super(URIScheme.HTTP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,9 +44,9 @@ public class HttpMinimalIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Fundamentals (HTTP/1.1, TLS)")
|
@DisplayName("Fundamentals (HTTP/1.1, TLS)")
|
||||||
public class Http1Tls extends TestHttp1AsyncMinimal {
|
class Http1Tls extends TestHttp1AsyncMinimal {
|
||||||
|
|
||||||
public Http1Tls() throws Exception {
|
public Http1Tls() {
|
||||||
super(URIScheme.HTTPS);
|
super(URIScheme.HTTPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,9 +54,9 @@ public class HttpMinimalIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Fundamentals (HTTP/2)")
|
@DisplayName("Fundamentals (HTTP/2)")
|
||||||
public class H2 extends TestH2AsyncMinimal {
|
class H2 extends TestH2AsyncMinimal {
|
||||||
|
|
||||||
public H2() throws Exception {
|
public H2() {
|
||||||
super(URIScheme.HTTP);
|
super(URIScheme.HTTP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,9 +64,9 @@ public class HttpMinimalIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Fundamentals (HTTP/2, TLS)")
|
@DisplayName("Fundamentals (HTTP/2, TLS)")
|
||||||
public class H2Tls extends TestH2AsyncMinimal {
|
class H2Tls extends TestH2AsyncMinimal {
|
||||||
|
|
||||||
public H2Tls() throws Exception {
|
public H2Tls() {
|
||||||
super(URIScheme.HTTPS);
|
super(URIScheme.HTTPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,13 +30,13 @@ import org.apache.hc.core5.http.URIScheme;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Nested;
|
import org.junit.jupiter.api.Nested;
|
||||||
|
|
||||||
public class ReactiveIntegrationTests {
|
class ReactiveIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Fundamentals (HTTP/1.1)")
|
@DisplayName("Fundamentals (HTTP/1.1)")
|
||||||
public class Http1 extends TestHttp1Reactive {
|
class Http1 extends TestHttp1Reactive {
|
||||||
|
|
||||||
public Http1() throws Exception {
|
public Http1() {
|
||||||
super(URIScheme.HTTP);
|
super(URIScheme.HTTP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,9 +44,9 @@ public class ReactiveIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Fundamentals (HTTP/1.1, TLS)")
|
@DisplayName("Fundamentals (HTTP/1.1, TLS)")
|
||||||
public class Http1Tls extends TestHttp1Reactive {
|
class Http1Tls extends TestHttp1Reactive {
|
||||||
|
|
||||||
public Http1Tls() throws Exception {
|
public Http1Tls() {
|
||||||
super(URIScheme.HTTPS);
|
super(URIScheme.HTTPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,9 +54,9 @@ public class ReactiveIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Fundamentals (HTTP/2)")
|
@DisplayName("Fundamentals (HTTP/2)")
|
||||||
public class H2 extends TestH2Reactive {
|
class H2 extends TestH2Reactive {
|
||||||
|
|
||||||
public H2() throws Exception {
|
public H2() {
|
||||||
super(URIScheme.HTTP);
|
super(URIScheme.HTTP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,9 +64,9 @@ public class ReactiveIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Fundamentals (HTTP/2, TLS)")
|
@DisplayName("Fundamentals (HTTP/2, TLS)")
|
||||||
public class H2Tls extends TestH2Reactive {
|
class H2Tls extends TestH2Reactive {
|
||||||
|
|
||||||
public H2Tls() throws Exception {
|
public H2Tls() {
|
||||||
super(URIScheme.HTTPS);
|
super(URIScheme.HTTPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,13 +30,13 @@ import org.apache.hc.core5.http.URIScheme;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Nested;
|
import org.junit.jupiter.api.Nested;
|
||||||
|
|
||||||
public class ReactiveMinimalIntegrationTests {
|
class ReactiveMinimalIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Fundamentals (HTTP/1.1)")
|
@DisplayName("Fundamentals (HTTP/1.1)")
|
||||||
public class Http1 extends TestHttp1ReactiveMinimal {
|
class Http1 extends TestHttp1ReactiveMinimal {
|
||||||
|
|
||||||
public Http1() throws Exception {
|
public Http1() {
|
||||||
super(URIScheme.HTTP);
|
super(URIScheme.HTTP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,9 +44,9 @@ public class ReactiveMinimalIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Fundamentals (HTTP/1.1, TLS)")
|
@DisplayName("Fundamentals (HTTP/1.1, TLS)")
|
||||||
public class Http1Tls extends TestHttp1ReactiveMinimal {
|
class Http1Tls extends TestHttp1ReactiveMinimal {
|
||||||
|
|
||||||
public Http1Tls() throws Exception {
|
public Http1Tls() {
|
||||||
super(URIScheme.HTTPS);
|
super(URIScheme.HTTPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,9 +54,9 @@ public class ReactiveMinimalIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Fundamentals (HTTP/2)")
|
@DisplayName("Fundamentals (HTTP/2)")
|
||||||
public class H2 extends TestH2ReactiveMinimal {
|
class H2 extends TestH2ReactiveMinimal {
|
||||||
|
|
||||||
public H2() throws Exception {
|
public H2() {
|
||||||
super(URIScheme.HTTP);
|
super(URIScheme.HTTP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,9 +64,9 @@ public class ReactiveMinimalIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Fundamentals (HTTP/2, TLS)")
|
@DisplayName("Fundamentals (HTTP/2, TLS)")
|
||||||
public class H2Tls extends TestH2ReactiveMinimal {
|
class H2Tls extends TestH2ReactiveMinimal {
|
||||||
|
|
||||||
public H2Tls() throws Exception {
|
public H2Tls() {
|
||||||
super(URIScheme.HTTPS);
|
super(URIScheme.HTTPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ import org.apache.hc.client5.testing.extension.async.ClientProtocolLevel;
|
||||||
import org.apache.hc.client5.testing.extension.async.ServerProtocolLevel;
|
import org.apache.hc.client5.testing.extension.async.ServerProtocolLevel;
|
||||||
import org.apache.hc.core5.http.URIScheme;
|
import org.apache.hc.core5.http.URIScheme;
|
||||||
|
|
||||||
public abstract class TestH2Async extends AbstractHttpAsyncFundamentalsTest {
|
abstract class TestH2Async extends AbstractHttpAsyncFundamentalsTest {
|
||||||
|
|
||||||
public TestH2Async(final URIScheme scheme) {
|
public TestH2Async(final URIScheme scheme) {
|
||||||
super(scheme, ClientProtocolLevel.H2_ONLY, ServerProtocolLevel.H2_ONLY);
|
super(scheme, ClientProtocolLevel.H2_ONLY, ServerProtocolLevel.H2_ONLY);
|
||||||
|
|
|
@ -30,7 +30,7 @@ import org.apache.hc.client5.testing.extension.async.ClientProtocolLevel;
|
||||||
import org.apache.hc.client5.testing.extension.async.ServerProtocolLevel;
|
import org.apache.hc.client5.testing.extension.async.ServerProtocolLevel;
|
||||||
import org.apache.hc.core5.http.URIScheme;
|
import org.apache.hc.core5.http.URIScheme;
|
||||||
|
|
||||||
public abstract class TestH2AsyncMinimal extends AbstractHttpAsyncFundamentalsTest {
|
abstract class TestH2AsyncMinimal extends AbstractHttpAsyncFundamentalsTest {
|
||||||
|
|
||||||
public TestH2AsyncMinimal(final URIScheme scheme) {
|
public TestH2AsyncMinimal(final URIScheme scheme) {
|
||||||
super(scheme, ClientProtocolLevel.MINIMAL_H2_ONLY, ServerProtocolLevel.H2_ONLY);
|
super(scheme, ClientProtocolLevel.MINIMAL_H2_ONLY, ServerProtocolLevel.H2_ONLY);
|
||||||
|
|
|
@ -30,7 +30,7 @@ import org.apache.hc.client5.testing.extension.async.ClientProtocolLevel;
|
||||||
import org.apache.hc.client5.testing.extension.async.ServerProtocolLevel;
|
import org.apache.hc.client5.testing.extension.async.ServerProtocolLevel;
|
||||||
import org.apache.hc.core5.http.URIScheme;
|
import org.apache.hc.core5.http.URIScheme;
|
||||||
|
|
||||||
public abstract class TestH2AsyncRedirect extends AbstractHttpAsyncRedirectsTest {
|
abstract class TestH2AsyncRedirect extends AbstractHttpAsyncRedirectsTest {
|
||||||
|
|
||||||
public TestH2AsyncRedirect(final URIScheme scheme) {
|
public TestH2AsyncRedirect(final URIScheme scheme) {
|
||||||
super(scheme, ClientProtocolLevel.H2_ONLY, ServerProtocolLevel.H2_ONLY);
|
super(scheme, ClientProtocolLevel.H2_ONLY, ServerProtocolLevel.H2_ONLY);
|
||||||
|
|
|
@ -30,7 +30,7 @@ import org.apache.hc.client5.testing.extension.async.ClientProtocolLevel;
|
||||||
import org.apache.hc.client5.testing.extension.async.ServerProtocolLevel;
|
import org.apache.hc.client5.testing.extension.async.ServerProtocolLevel;
|
||||||
import org.apache.hc.core5.http.URIScheme;
|
import org.apache.hc.core5.http.URIScheme;
|
||||||
|
|
||||||
public abstract class TestH2ClientAuthentication extends AbstractHttpAsyncClientAuthenticationTest {
|
abstract class TestH2ClientAuthentication extends AbstractHttpAsyncClientAuthenticationTest {
|
||||||
|
|
||||||
public TestH2ClientAuthentication(final URIScheme scheme) {
|
public TestH2ClientAuthentication(final URIScheme scheme) {
|
||||||
super(scheme, ClientProtocolLevel.H2_ONLY, ServerProtocolLevel.H2_ONLY);
|
super(scheme, ClientProtocolLevel.H2_ONLY, ServerProtocolLevel.H2_ONLY);
|
||||||
|
|
|
@ -30,7 +30,7 @@ import org.apache.hc.client5.testing.extension.async.ClientProtocolLevel;
|
||||||
import org.apache.hc.client5.testing.extension.async.ServerProtocolLevel;
|
import org.apache.hc.client5.testing.extension.async.ServerProtocolLevel;
|
||||||
import org.apache.hc.core5.http.URIScheme;
|
import org.apache.hc.core5.http.URIScheme;
|
||||||
|
|
||||||
public abstract class TestH2Reactive extends AbstractHttpReactiveFundamentalsTest {
|
abstract class TestH2Reactive extends AbstractHttpReactiveFundamentalsTest {
|
||||||
|
|
||||||
public TestH2Reactive(final URIScheme scheme) {
|
public TestH2Reactive(final URIScheme scheme) {
|
||||||
super(scheme, ClientProtocolLevel.H2_ONLY, ServerProtocolLevel.H2_ONLY);
|
super(scheme, ClientProtocolLevel.H2_ONLY, ServerProtocolLevel.H2_ONLY);
|
||||||
|
|
|
@ -30,7 +30,7 @@ import org.apache.hc.client5.testing.extension.async.ClientProtocolLevel;
|
||||||
import org.apache.hc.client5.testing.extension.async.ServerProtocolLevel;
|
import org.apache.hc.client5.testing.extension.async.ServerProtocolLevel;
|
||||||
import org.apache.hc.core5.http.URIScheme;
|
import org.apache.hc.core5.http.URIScheme;
|
||||||
|
|
||||||
public abstract class TestH2ReactiveMinimal extends AbstractHttpReactiveFundamentalsTest {
|
abstract class TestH2ReactiveMinimal extends AbstractHttpReactiveFundamentalsTest {
|
||||||
|
|
||||||
public TestH2ReactiveMinimal(final URIScheme scheme) {
|
public TestH2ReactiveMinimal(final URIScheme scheme) {
|
||||||
super(scheme, ClientProtocolLevel.MINIMAL_H2_ONLY, ServerProtocolLevel.H2_ONLY);
|
super(scheme, ClientProtocolLevel.MINIMAL_H2_ONLY, ServerProtocolLevel.H2_ONLY);
|
||||||
|
|
|
@ -52,7 +52,7 @@ import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.ValueSource;
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
|
|
||||||
public abstract class TestHttp1Async extends AbstractHttpAsyncFundamentalsTest {
|
abstract class TestHttp1Async extends AbstractHttpAsyncFundamentalsTest {
|
||||||
|
|
||||||
public TestHttp1Async(final URIScheme scheme) {
|
public TestHttp1Async(final URIScheme scheme) {
|
||||||
super(scheme, ClientProtocolLevel.STANDARD, ServerProtocolLevel.STANDARD);
|
super(scheme, ClientProtocolLevel.STANDARD, ServerProtocolLevel.STANDARD);
|
||||||
|
@ -86,7 +86,7 @@ public abstract class TestHttp1Async extends AbstractHttpAsyncFundamentalsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSharedPool() throws Exception {
|
void testSharedPool() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap.register("/random/*", AsyncRandomHandler::new));
|
configureServer(bootstrap -> bootstrap.register("/random/*", AsyncRandomHandler::new));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ public abstract class TestHttp1Async extends AbstractHttpAsyncFundamentalsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRequestCancellation() throws Exception {
|
void testRequestCancellation() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap.register("/random/*", AsyncRandomHandler::new));
|
configureServer(bootstrap -> bootstrap.register("/random/*", AsyncRandomHandler::new));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
|
||||||
|
|
|
@ -52,14 +52,14 @@ import org.apache.hc.core5.http.nio.support.BasicResponseConsumer;
|
||||||
import org.hamcrest.CoreMatchers;
|
import org.hamcrest.CoreMatchers;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public abstract class TestHttp1AsyncMinimal extends AbstractHttpAsyncFundamentalsTest {
|
abstract class TestHttp1AsyncMinimal extends AbstractHttpAsyncFundamentalsTest {
|
||||||
|
|
||||||
public TestHttp1AsyncMinimal(final URIScheme scheme) {
|
public TestHttp1AsyncMinimal(final URIScheme scheme) {
|
||||||
super(scheme, ClientProtocolLevel.MINIMAL, ServerProtocolLevel.STANDARD);
|
super(scheme, ClientProtocolLevel.MINIMAL, ServerProtocolLevel.STANDARD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConcurrentPostRequestsSameEndpoint() throws Exception {
|
void testConcurrentPostRequestsSameEndpoint() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap.register("/echo/*", AsyncEchoHandler::new));
|
configureServer(bootstrap -> bootstrap.register("/echo/*", AsyncEchoHandler::new));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
|
||||||
|
|
|
@ -52,14 +52,14 @@ import org.junit.jupiter.api.Test;
|
||||||
/**
|
/**
|
||||||
* Redirection test cases.
|
* Redirection test cases.
|
||||||
*/
|
*/
|
||||||
public abstract class TestHttp1AsyncRedirects extends AbstractHttpAsyncRedirectsTest {
|
abstract class TestHttp1AsyncRedirects extends AbstractHttpAsyncRedirectsTest {
|
||||||
|
|
||||||
public TestHttp1AsyncRedirects(final URIScheme scheme) {
|
public TestHttp1AsyncRedirects(final URIScheme scheme) {
|
||||||
super(scheme, ClientProtocolLevel.STANDARD, ServerProtocolLevel.STANDARD);
|
super(scheme, ClientProtocolLevel.STANDARD, ServerProtocolLevel.STANDARD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicRedirect300NoKeepAlive() throws Exception {
|
void testBasicRedirect300NoKeepAlive() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/random/*", AsyncRandomHandler::new)
|
.register("/random/*", AsyncRandomHandler::new)
|
||||||
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
||||||
|
@ -85,7 +85,7 @@ public abstract class TestHttp1AsyncRedirects extends AbstractHttpAsyncRedirects
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicRedirect301NoKeepAlive() throws Exception {
|
void testBasicRedirect301NoKeepAlive() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/random/*", AsyncRandomHandler::new)
|
.register("/random/*", AsyncRandomHandler::new)
|
||||||
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
||||||
|
@ -112,7 +112,7 @@ public abstract class TestHttp1AsyncRedirects extends AbstractHttpAsyncRedirects
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultHeadersRedirect() throws Exception {
|
void testDefaultHeadersRedirect() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/random/*", AsyncRandomHandler::new)
|
.register("/random/*", AsyncRandomHandler::new)
|
||||||
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
.setExchangeHandlerDecorator(exchangeHandler -> new RedirectingAsyncDecorator(
|
||||||
|
|
|
@ -50,20 +50,20 @@ import org.apache.hc.core5.net.URIAuthority;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestHttp1AsyncStatefulConnManagement extends AbstractIntegrationTestBase {
|
class TestHttp1AsyncStatefulConnManagement extends AbstractIntegrationTestBase {
|
||||||
|
|
||||||
public TestHttp1AsyncStatefulConnManagement() {
|
public TestHttp1AsyncStatefulConnManagement() {
|
||||||
super(URIScheme.HTTP, ClientProtocolLevel.STANDARD, ServerProtocolLevel.STANDARD);
|
super(URIScheme.HTTP, ClientProtocolLevel.STANDARD, ServerProtocolLevel.STANDARD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStatefulConnections() throws Exception {
|
void testStatefulConnections() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap.register("*", () -> new AbstractSimpleServerExchangeHandler() {
|
configureServer(bootstrap -> bootstrap.register("*", () -> new AbstractSimpleServerExchangeHandler() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SimpleHttpResponse handle(
|
protected SimpleHttpResponse handle(
|
||||||
final SimpleHttpRequest request,
|
final SimpleHttpRequest request,
|
||||||
final HttpCoreContext context) throws HttpException {
|
final HttpCoreContext context) {
|
||||||
final SimpleHttpResponse response = new SimpleHttpResponse(HttpStatus.SC_OK);
|
final SimpleHttpResponse response = new SimpleHttpResponse(HttpStatus.SC_OK);
|
||||||
response.setBody("Whatever", ContentType.TEXT_PLAIN);
|
response.setBody("Whatever", ContentType.TEXT_PLAIN);
|
||||||
return response;
|
return response;
|
||||||
|
@ -173,13 +173,13 @@ public class TestHttp1AsyncStatefulConnManagement extends AbstractIntegrationTes
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRouteSpecificPoolRecylcing() throws Exception {
|
void testRouteSpecificPoolRecylcing() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap.register("*", () -> new AbstractSimpleServerExchangeHandler() {
|
configureServer(bootstrap -> bootstrap.register("*", () -> new AbstractSimpleServerExchangeHandler() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SimpleHttpResponse handle(
|
protected SimpleHttpResponse handle(
|
||||||
final SimpleHttpRequest request,
|
final SimpleHttpRequest request,
|
||||||
final HttpCoreContext context) throws HttpException {
|
final HttpCoreContext context) {
|
||||||
final SimpleHttpResponse response = new SimpleHttpResponse(HttpStatus.SC_OK);
|
final SimpleHttpResponse response = new SimpleHttpResponse(HttpStatus.SC_OK);
|
||||||
response.setBody("Whatever", ContentType.TEXT_PLAIN);
|
response.setBody("Whatever", ContentType.TEXT_PLAIN);
|
||||||
return response;
|
return response;
|
||||||
|
|
|
@ -49,14 +49,14 @@ import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
public abstract class TestHttp1ClientAuthentication extends AbstractHttpAsyncClientAuthenticationTest {
|
abstract class TestHttp1ClientAuthentication extends AbstractHttpAsyncClientAuthenticationTest {
|
||||||
|
|
||||||
public TestHttp1ClientAuthentication(final URIScheme scheme) {
|
public TestHttp1ClientAuthentication(final URIScheme scheme) {
|
||||||
super(scheme, ClientProtocolLevel.STANDARD, ServerProtocolLevel.STANDARD);
|
super(scheme, ClientProtocolLevel.STANDARD, ServerProtocolLevel.STANDARD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicAuthenticationSuccessNonPersistentConnection() throws Exception {
|
void testBasicAuthenticationSuccessNonPersistentConnection() throws Exception {
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("*", AsyncEchoHandler::new)
|
.register("*", AsyncEchoHandler::new)
|
||||||
|
|
|
@ -57,7 +57,7 @@ import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.ValueSource;
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
import org.reactivestreams.Publisher;
|
import org.reactivestreams.Publisher;
|
||||||
|
|
||||||
public abstract class TestHttp1Reactive extends AbstractHttpReactiveFundamentalsTest {
|
abstract class TestHttp1Reactive extends AbstractHttpReactiveFundamentalsTest {
|
||||||
|
|
||||||
public TestHttp1Reactive(final URIScheme scheme) {
|
public TestHttp1Reactive(final URIScheme scheme) {
|
||||||
super(scheme, ClientProtocolLevel.STANDARD, ServerProtocolLevel.STANDARD);
|
super(scheme, ClientProtocolLevel.STANDARD, ServerProtocolLevel.STANDARD);
|
||||||
|
|
|
@ -54,14 +54,14 @@ import org.apache.hc.core5.testing.reactive.ReactiveEchoProcessor;
|
||||||
import org.hamcrest.CoreMatchers;
|
import org.hamcrest.CoreMatchers;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public abstract class TestHttp1ReactiveMinimal extends AbstractHttpReactiveFundamentalsTest {
|
abstract class TestHttp1ReactiveMinimal extends AbstractHttpReactiveFundamentalsTest {
|
||||||
|
|
||||||
public TestHttp1ReactiveMinimal(final URIScheme scheme) {
|
public TestHttp1ReactiveMinimal(final URIScheme scheme) {
|
||||||
super(scheme, ClientProtocolLevel.MINIMAL, ServerProtocolLevel.STANDARD);
|
super(scheme, ClientProtocolLevel.MINIMAL, ServerProtocolLevel.STANDARD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConcurrentPostRequestsSameEndpoint() throws Exception {
|
void testConcurrentPostRequestsSameEndpoint() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap.register("/echo/*", () ->
|
configureServer(bootstrap -> bootstrap.register("/echo/*", () ->
|
||||||
new ReactiveServerExchangeHandler(new ReactiveEchoProcessor())));
|
new ReactiveServerExchangeHandler(new ReactiveEchoProcessor())));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
|
|
@ -47,14 +47,14 @@ import org.hamcrest.CoreMatchers;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public abstract class TestHttp1RequestReExecution extends AbstractIntegrationTestBase {
|
abstract class TestHttp1RequestReExecution extends AbstractIntegrationTestBase {
|
||||||
|
|
||||||
public TestHttp1RequestReExecution(final URIScheme scheme) {
|
public TestHttp1RequestReExecution(final URIScheme scheme) {
|
||||||
super(scheme, ClientProtocolLevel.STANDARD, ServerProtocolLevel.STANDARD);
|
super(scheme, ClientProtocolLevel.STANDARD, ServerProtocolLevel.STANDARD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
void setup() {
|
||||||
final Resolver<HttpRequest, TimeValue> serviceAvailabilityResolver = new Resolver<HttpRequest, TimeValue>() {
|
final Resolver<HttpRequest, TimeValue> serviceAvailabilityResolver = new Resolver<HttpRequest, TimeValue>() {
|
||||||
|
|
||||||
private final AtomicInteger count = new AtomicInteger(0);
|
private final AtomicInteger count = new AtomicInteger(0);
|
||||||
|
@ -72,7 +72,7 @@ public abstract class TestHttp1RequestReExecution extends AbstractIntegrationTes
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGiveUpAfterOneRetry() throws Exception {
|
void testGiveUpAfterOneRetry() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap.register("/random/*", AsyncRandomHandler::new));
|
configureServer(bootstrap -> bootstrap.register("/random/*", AsyncRandomHandler::new));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ public abstract class TestHttp1RequestReExecution extends AbstractIntegrationTes
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoNotGiveUpEasily() throws Exception {
|
void testDoNotGiveUpEasily() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap.register("/random/*", AsyncRandomHandler::new));
|
configureServer(bootstrap -> bootstrap.register("/random/*", AsyncRandomHandler::new));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
|
||||||
|
|
|
@ -44,14 +44,14 @@ import org.apache.hc.core5.ssl.SSLContexts;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestHttpAsyncMinimalTlsHandshake extends AbstractIntegrationTestBase {
|
class TestHttpAsyncMinimalTlsHandshake extends AbstractIntegrationTestBase {
|
||||||
|
|
||||||
public TestHttpAsyncMinimalTlsHandshake() {
|
public TestHttpAsyncMinimalTlsHandshake() {
|
||||||
super(URIScheme.HTTPS, ClientProtocolLevel.MINIMAL, ServerProtocolLevel.STANDARD);
|
super(URIScheme.HTTPS, ClientProtocolLevel.MINIMAL, ServerProtocolLevel.STANDARD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccessfulTlsHandshake() throws Exception {
|
void testSuccessfulTlsHandshake() throws Exception {
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
|
||||||
final int maxConnNo = 2;
|
final int maxConnNo = 2;
|
||||||
|
@ -69,7 +69,7 @@ public class TestHttpAsyncMinimalTlsHandshake extends AbstractIntegrationTestBas
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTlsHandshakeFailure() throws Exception {
|
void testTlsHandshakeFailure() throws Exception {
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
|
||||||
configureClient(builder ->
|
configureClient(builder ->
|
||||||
|
|
|
@ -45,7 +45,7 @@ import org.apache.hc.core5.http2.HttpVersionPolicy;
|
||||||
import org.hamcrest.CoreMatchers;
|
import org.hamcrest.CoreMatchers;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public abstract class TestHttpAsyncProtocolPolicy extends AbstractIntegrationTestBase {
|
abstract class TestHttpAsyncProtocolPolicy extends AbstractIntegrationTestBase {
|
||||||
|
|
||||||
private final HttpVersion version;
|
private final HttpVersion version;
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ public abstract class TestHttpAsyncProtocolPolicy extends AbstractIntegrationTes
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRequestContext() throws Exception {
|
void testRequestContext() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap.register("/random/*", AsyncRandomHandler::new));
|
configureServer(bootstrap -> bootstrap.register("/random/*", AsyncRandomHandler::new));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ public class TestAsyncResources implements AfterEachCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterEach(final ExtensionContext extensionContext) throws Exception {
|
public void afterEach(final ExtensionContext extensionContext) {
|
||||||
LOG.debug("Shutting down test server");
|
LOG.debug("Shutting down test server");
|
||||||
if (client != null) {
|
if (client != null) {
|
||||||
client.close(CloseMode.GRACEFUL);
|
client.close(CloseMode.GRACEFUL);
|
||||||
|
|
|
@ -70,7 +70,7 @@ public class TestClientResources implements AfterEachCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterEach(final ExtensionContext extensionContext) throws Exception {
|
public void afterEach(final ExtensionContext extensionContext) {
|
||||||
LOG.debug("Shutting down test server");
|
LOG.debug("Shutting down test server");
|
||||||
|
|
||||||
if (client != null) {
|
if (client != null) {
|
||||||
|
|
|
@ -51,7 +51,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
public class TestFluent {
|
class TestFluent {
|
||||||
|
|
||||||
public static final Timeout TIMEOUT = Timeout.ofMinutes(1);
|
public static final Timeout TIMEOUT = Timeout.ofMinutes(1);
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ public class TestFluent {
|
||||||
private TestClientResources testResources = new TestClientResources(URIScheme.HTTP, ClientProtocolLevel.STANDARD, TIMEOUT);
|
private TestClientResources testResources = new TestClientResources(URIScheme.HTTP, ClientProtocolLevel.STANDARD, TIMEOUT);
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() {
|
||||||
testResources.configureServer(bootstrap -> bootstrap
|
testResources.configureServer(bootstrap -> bootstrap
|
||||||
.register("/", (request, response, context) ->
|
.register("/", (request, response, context) ->
|
||||||
response.setEntity(new StringEntity("All is well", ContentType.TEXT_PLAIN)))
|
response.setEntity(new StringEntity("All is well", ContentType.TEXT_PLAIN)))
|
||||||
|
@ -99,7 +99,7 @@ public class TestFluent {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetRequest() throws Exception {
|
void testGetRequest() throws Exception {
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
final String baseURL = "http://localhost:" + target.getPort();
|
final String baseURL = "http://localhost:" + target.getPort();
|
||||||
final String message = Request.get(baseURL + "/").execute().returnContent().asString();
|
final String message = Request.get(baseURL + "/").execute().returnContent().asString();
|
||||||
|
@ -107,7 +107,7 @@ public class TestFluent {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetRequestByName() throws Exception {
|
void testGetRequestByName() throws Exception {
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
final String baseURL = "http://localhost:" + target.getPort();
|
final String baseURL = "http://localhost:" + target.getPort();
|
||||||
final String message = Request.create("GET", baseURL + "/").execute().returnContent().asString();
|
final String message = Request.create("GET", baseURL + "/").execute().returnContent().asString();
|
||||||
|
@ -115,7 +115,7 @@ public class TestFluent {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetRequestByNameWithURI() throws Exception {
|
void testGetRequestByNameWithURI() throws Exception {
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
final String baseURL = "http://localhost:" + target.getPort();
|
final String baseURL = "http://localhost:" + target.getPort();
|
||||||
final String message = Request.create("GET", new URI(baseURL + "/")).execute().returnContent().asString();
|
final String message = Request.create("GET", new URI(baseURL + "/")).execute().returnContent().asString();
|
||||||
|
@ -123,7 +123,7 @@ public class TestFluent {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetRequestFailure() throws Exception {
|
void testGetRequestFailure() throws Exception {
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
final String baseURL = "http://localhost:" + target.getPort();
|
final String baseURL = "http://localhost:" + target.getPort();
|
||||||
Assertions.assertThrows(ClientProtocolException.class, () ->
|
Assertions.assertThrows(ClientProtocolException.class, () ->
|
||||||
|
@ -131,7 +131,7 @@ public class TestFluent {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPostRequest() throws Exception {
|
void testPostRequest() throws Exception {
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
final String baseURL = "http://localhost:" + target.getPort();
|
final String baseURL = "http://localhost:" + target.getPort();
|
||||||
final String message1 = Request.post(baseURL + "/echo")
|
final String message1 = Request.post(baseURL + "/echo")
|
||||||
|
@ -145,7 +145,7 @@ public class TestFluent {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testContentAsStringWithCharset() throws Exception {
|
void testContentAsStringWithCharset() throws Exception {
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
final String baseURL = "http://localhost:" + target.getPort();
|
final String baseURL = "http://localhost:" + target.getPort();
|
||||||
final Content content = Request.post(baseURL + "/echo").bodyByteArray("Ü".getBytes(StandardCharsets.UTF_8)).execute()
|
final Content content = Request.post(baseURL + "/echo").bodyByteArray("Ü".getBytes(StandardCharsets.UTF_8)).execute()
|
||||||
|
@ -156,7 +156,7 @@ public class TestFluent {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConnectionRelease() throws Exception {
|
void testConnectionRelease() throws Exception {
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
final String baseURL = "http://localhost:" + target.getPort();
|
final String baseURL = "http://localhost:" + target.getPort();
|
||||||
for (int i = 0; i < 20; i++) {
|
for (int i = 0; i < 20; i++) {
|
||||||
|
@ -182,7 +182,7 @@ public class TestFluent {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLargeResponse() throws Exception {
|
void testLargeResponse() throws Exception {
|
||||||
|
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
final String baseURL = "http://localhost:" + target.getPort();
|
final String baseURL = "http://localhost:" + target.getPort();
|
||||||
|
@ -192,7 +192,7 @@ public class TestFluent {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLargeResponseError() throws Exception {
|
void testLargeResponseError() throws Exception {
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
final String baseURL = "http://localhost:" + target.getPort();
|
final String baseURL = "http://localhost:" + target.getPort();
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ import org.apache.hc.core5.http.URIScheme;
|
||||||
import org.apache.hc.core5.util.Timeout;
|
import org.apache.hc.core5.util.Timeout;
|
||||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
public abstract class AbstractIntegrationTestBase {
|
abstract class AbstractIntegrationTestBase {
|
||||||
|
|
||||||
public static final Timeout TIMEOUT = Timeout.ofMinutes(1);
|
public static final Timeout TIMEOUT = Timeout.ofMinutes(1);
|
||||||
|
|
||||||
|
|
|
@ -30,13 +30,13 @@ import org.apache.hc.core5.http.URIScheme;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Nested;
|
import org.junit.jupiter.api.Nested;
|
||||||
|
|
||||||
public class HttpIntegrationTests {
|
class HttpIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Request execution (HTTP/1.1)")
|
@DisplayName("Request execution (HTTP/1.1)")
|
||||||
public class RequestExecution extends TestClientRequestExecution {
|
class RequestExecution extends TestClientRequestExecution {
|
||||||
|
|
||||||
public RequestExecution() throws Exception {
|
public RequestExecution() {
|
||||||
super(URIScheme.HTTP);
|
super(URIScheme.HTTP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,9 +44,9 @@ public class HttpIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Request execution (HTTP/1.1, TLS)")
|
@DisplayName("Request execution (HTTP/1.1, TLS)")
|
||||||
public class RequestExecutionTls extends TestClientRequestExecution {
|
class RequestExecutionTls extends TestClientRequestExecution {
|
||||||
|
|
||||||
public RequestExecutionTls() throws Exception {
|
public RequestExecutionTls() {
|
||||||
super(URIScheme.HTTPS);
|
super(URIScheme.HTTPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,9 +54,9 @@ public class HttpIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Authentication (HTTP/1.1)")
|
@DisplayName("Authentication (HTTP/1.1)")
|
||||||
public class Authentication extends TestClientAuthentication {
|
class Authentication extends TestClientAuthentication {
|
||||||
|
|
||||||
public Authentication() throws Exception {
|
public Authentication() {
|
||||||
super(URIScheme.HTTP);
|
super(URIScheme.HTTP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,9 +64,9 @@ public class HttpIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Authentication (HTTP/1.1, TLS)")
|
@DisplayName("Authentication (HTTP/1.1, TLS)")
|
||||||
public class AuthenticationTls extends TestClientAuthentication {
|
class AuthenticationTls extends TestClientAuthentication {
|
||||||
|
|
||||||
public AuthenticationTls() throws Exception {
|
public AuthenticationTls() {
|
||||||
super(URIScheme.HTTPS);
|
super(URIScheme.HTTPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,9 +74,9 @@ public class HttpIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Content coding (HTTP/1.1)")
|
@DisplayName("Content coding (HTTP/1.1)")
|
||||||
public class ContentCoding extends TestContentCodings {
|
class ContentCoding extends TestContentCodings {
|
||||||
|
|
||||||
public ContentCoding() throws Exception {
|
public ContentCoding() {
|
||||||
super(URIScheme.HTTP);
|
super(URIScheme.HTTP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,9 +84,9 @@ public class HttpIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Content coding (HTTP/1.1, TLS)")
|
@DisplayName("Content coding (HTTP/1.1, TLS)")
|
||||||
public class ContentCodingTls extends TestContentCodings {
|
class ContentCodingTls extends TestContentCodings {
|
||||||
|
|
||||||
public ContentCodingTls() throws Exception {
|
public ContentCodingTls() {
|
||||||
super(URIScheme.HTTPS);
|
super(URIScheme.HTTPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,9 +94,9 @@ public class HttpIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Redirects (HTTP/1.1)")
|
@DisplayName("Redirects (HTTP/1.1)")
|
||||||
public class Redirects extends TestRedirects {
|
class Redirects extends TestRedirects {
|
||||||
|
|
||||||
public Redirects() throws Exception {
|
public Redirects() {
|
||||||
super(URIScheme.HTTP);
|
super(URIScheme.HTTP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,9 +104,9 @@ public class HttpIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Redirects (HTTP/1.1, TLS)")
|
@DisplayName("Redirects (HTTP/1.1, TLS)")
|
||||||
public class RedirectsTls extends TestRedirects {
|
class RedirectsTls extends TestRedirects {
|
||||||
|
|
||||||
public RedirectsTls() throws Exception {
|
public RedirectsTls() {
|
||||||
super(URIScheme.HTTPS);
|
super(URIScheme.HTTPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,13 +30,13 @@ import org.apache.hc.core5.http.URIScheme;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Nested;
|
import org.junit.jupiter.api.Nested;
|
||||||
|
|
||||||
public class HttpMinimalIntegrationTests {
|
class HttpMinimalIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Request execution (HTTP/1.1)")
|
@DisplayName("Request execution (HTTP/1.1)")
|
||||||
public class RequestExecution extends TestMinimalClientRequestExecution {
|
class RequestExecution extends TestMinimalClientRequestExecution {
|
||||||
|
|
||||||
public RequestExecution() throws Exception {
|
public RequestExecution() {
|
||||||
super(URIScheme.HTTP);
|
super(URIScheme.HTTP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,9 +44,9 @@ public class HttpMinimalIntegrationTests {
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Request execution (HTTP/1.1, TLS)")
|
@DisplayName("Request execution (HTTP/1.1, TLS)")
|
||||||
public class RequestExecutionTls extends TestMinimalClientRequestExecution {
|
class RequestExecutionTls extends TestMinimalClientRequestExecution {
|
||||||
|
|
||||||
public RequestExecutionTls() throws Exception {
|
public RequestExecutionTls() {
|
||||||
super(URIScheme.HTTPS);
|
super(URIScheme.HTTPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,14 +37,14 @@ import org.apache.hc.core5.http.io.entity.EntityUtils;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestBasicConnectionManager extends AbstractIntegrationTestBase {
|
class TestBasicConnectionManager extends AbstractIntegrationTestBase {
|
||||||
|
|
||||||
public TestBasicConnectionManager() {
|
public TestBasicConnectionManager() {
|
||||||
super(URIScheme.HTTP, ClientProtocolLevel.STANDARD);
|
super(URIScheme.HTTP, ClientProtocolLevel.STANDARD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasics() throws Exception {
|
void testBasics() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/random/*", new RandomHandler()));
|
.register("/random/*", new RandomHandler()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
@ -62,7 +62,7 @@ public class TestBasicConnectionManager extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConnectionStillInUse() throws Exception {
|
void testConnectionStillInUse() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/random/*", new RandomHandler()));
|
.register("/random/*", new RandomHandler()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
|
|
@ -94,14 +94,14 @@ import org.mockito.Mockito;
|
||||||
/**
|
/**
|
||||||
* Unit tests for automatic client authentication.
|
* Unit tests for automatic client authentication.
|
||||||
*/
|
*/
|
||||||
public abstract class TestClientAuthentication extends AbstractIntegrationTestBase {
|
abstract class TestClientAuthentication extends AbstractIntegrationTestBase {
|
||||||
|
|
||||||
protected TestClientAuthentication(final URIScheme scheme) {
|
protected TestClientAuthentication(final URIScheme scheme) {
|
||||||
super(scheme, ClientProtocolLevel.STANDARD);
|
super(scheme, ClientProtocolLevel.STANDARD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void configureServerWithBasicAuth(final Authenticator authenticator,
|
public void configureServerWithBasicAuth(final Authenticator authenticator,
|
||||||
final Consumer<TestServerBootstrap> serverCustomizer) throws IOException {
|
final Consumer<TestServerBootstrap> serverCustomizer) {
|
||||||
configureServer(bootstrap -> {
|
configureServer(bootstrap -> {
|
||||||
bootstrap.setExchangeHandlerDecorator(requestHandler ->
|
bootstrap.setExchangeHandlerDecorator(requestHandler ->
|
||||||
new AuthenticatingDecorator(requestHandler, authenticator));
|
new AuthenticatingDecorator(requestHandler, authenticator));
|
||||||
|
@ -109,14 +109,14 @@ public abstract class TestClientAuthentication extends AbstractIntegrationTestBa
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void configureServerWithBasicAuth(final Consumer<TestServerBootstrap> serverCustomizer) throws IOException {
|
public void configureServerWithBasicAuth(final Consumer<TestServerBootstrap> serverCustomizer) {
|
||||||
configureServerWithBasicAuth(
|
configureServerWithBasicAuth(
|
||||||
new BasicTestAuthenticator("test:test", "test realm"),
|
new BasicTestAuthenticator("test:test", "test realm"),
|
||||||
serverCustomizer);
|
serverCustomizer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicAuthenticationNoCreds() throws Exception {
|
void testBasicAuthenticationNoCreds() throws Exception {
|
||||||
configureServerWithBasicAuth(bootstrap -> bootstrap
|
configureServerWithBasicAuth(bootstrap -> bootstrap
|
||||||
.register("*", new EchoHandler()));
|
.register("*", new EchoHandler()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
@ -140,7 +140,7 @@ public abstract class TestClientAuthentication extends AbstractIntegrationTestBa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicAuthenticationFailure() throws Exception {
|
void testBasicAuthenticationFailure() throws Exception {
|
||||||
configureServerWithBasicAuth(bootstrap -> bootstrap
|
configureServerWithBasicAuth(bootstrap -> bootstrap
|
||||||
.register("*", new EchoHandler()));
|
.register("*", new EchoHandler()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
@ -166,7 +166,7 @@ public abstract class TestClientAuthentication extends AbstractIntegrationTestBa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicAuthenticationSuccess() throws Exception {
|
void testBasicAuthenticationSuccess() throws Exception {
|
||||||
configureServerWithBasicAuth(bootstrap -> bootstrap
|
configureServerWithBasicAuth(bootstrap -> bootstrap
|
||||||
.register("*", new EchoHandler()));
|
.register("*", new EchoHandler()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
@ -191,7 +191,7 @@ public abstract class TestClientAuthentication extends AbstractIntegrationTestBa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicAuthenticationSuccessOnNonRepeatablePutExpectContinue() throws Exception {
|
void testBasicAuthenticationSuccessOnNonRepeatablePutExpectContinue() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("*", new EchoHandler()));
|
.register("*", new EchoHandler()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
@ -222,7 +222,7 @@ public abstract class TestClientAuthentication extends AbstractIntegrationTestBa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicAuthenticationFailureOnNonRepeatablePutDontExpectContinue() throws Exception {
|
void testBasicAuthenticationFailureOnNonRepeatablePutDontExpectContinue() throws Exception {
|
||||||
configureServerWithBasicAuth(bootstrap -> bootstrap
|
configureServerWithBasicAuth(bootstrap -> bootstrap
|
||||||
.register("*", new EchoHandler()));
|
.register("*", new EchoHandler()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
@ -253,7 +253,7 @@ public abstract class TestClientAuthentication extends AbstractIntegrationTestBa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicAuthenticationSuccessOnRepeatablePost() throws Exception {
|
void testBasicAuthenticationSuccessOnRepeatablePost() throws Exception {
|
||||||
configureServerWithBasicAuth(bootstrap -> bootstrap
|
configureServerWithBasicAuth(bootstrap -> bootstrap
|
||||||
.register("*", new EchoHandler()));
|
.register("*", new EchoHandler()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
@ -281,7 +281,7 @@ public abstract class TestClientAuthentication extends AbstractIntegrationTestBa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicAuthenticationFailureOnNonRepeatablePost() throws Exception {
|
void testBasicAuthenticationFailureOnNonRepeatablePost() throws Exception {
|
||||||
configureServerWithBasicAuth(bootstrap -> bootstrap
|
configureServerWithBasicAuth(bootstrap -> bootstrap
|
||||||
.register("*", new EchoHandler()));
|
.register("*", new EchoHandler()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
@ -312,7 +312,7 @@ public abstract class TestClientAuthentication extends AbstractIntegrationTestBa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicAuthenticationCredentialsCaching() throws Exception {
|
void testBasicAuthenticationCredentialsCaching() throws Exception {
|
||||||
configureServerWithBasicAuth(bootstrap -> bootstrap
|
configureServerWithBasicAuth(bootstrap -> bootstrap
|
||||||
.register("*", new EchoHandler()));
|
.register("*", new EchoHandler()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
@ -350,7 +350,7 @@ public abstract class TestClientAuthentication extends AbstractIntegrationTestBa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicAuthenticationCredentialsCachingByPathPrefix() throws Exception {
|
void testBasicAuthenticationCredentialsCachingByPathPrefix() throws Exception {
|
||||||
configureServerWithBasicAuth(bootstrap -> bootstrap
|
configureServerWithBasicAuth(bootstrap -> bootstrap
|
||||||
.register("*", new EchoHandler()));
|
.register("*", new EchoHandler()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
@ -415,7 +415,7 @@ public abstract class TestClientAuthentication extends AbstractIntegrationTestBa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAuthenticationCredentialsCachingReAuthenticationOnDifferentRealm() throws Exception {
|
void testAuthenticationCredentialsCachingReAuthenticationOnDifferentRealm() throws Exception {
|
||||||
configureServerWithBasicAuth(new Authenticator() {
|
configureServerWithBasicAuth(new Authenticator() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -492,7 +492,7 @@ public abstract class TestClientAuthentication extends AbstractIntegrationTestBa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAuthenticationUserinfoInRequest() throws Exception {
|
void testAuthenticationUserinfoInRequest() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("*", new EchoHandler()));
|
.register("*", new EchoHandler()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
@ -505,7 +505,7 @@ public abstract class TestClientAuthentication extends AbstractIntegrationTestBa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPreemptiveAuthentication() throws Exception {
|
void testPreemptiveAuthentication() throws Exception {
|
||||||
final Authenticator authenticator = Mockito.spy(new BasicTestAuthenticator("test:test", "test realm"));
|
final Authenticator authenticator = Mockito.spy(new BasicTestAuthenticator("test:test", "test realm"));
|
||||||
configureServerWithBasicAuth(authenticator,
|
configureServerWithBasicAuth(authenticator,
|
||||||
bootstrap -> bootstrap
|
bootstrap -> bootstrap
|
||||||
|
@ -534,7 +534,7 @@ public abstract class TestClientAuthentication extends AbstractIntegrationTestBa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPreemptiveAuthenticationFailure() throws Exception {
|
void testPreemptiveAuthenticationFailure() throws Exception {
|
||||||
final Authenticator authenticator = Mockito.spy(new BasicTestAuthenticator("test:test", "test realm"));
|
final Authenticator authenticator = Mockito.spy(new BasicTestAuthenticator("test:test", "test realm"));
|
||||||
configureServerWithBasicAuth(authenticator,
|
configureServerWithBasicAuth(authenticator,
|
||||||
bootstrap -> bootstrap
|
bootstrap -> bootstrap
|
||||||
|
@ -569,7 +569,7 @@ public abstract class TestClientAuthentication extends AbstractIntegrationTestBa
|
||||||
public void handle(
|
public void handle(
|
||||||
final ClassicHttpRequest request,
|
final ClassicHttpRequest request,
|
||||||
final ClassicHttpResponse response,
|
final ClassicHttpResponse response,
|
||||||
final HttpContext context) throws HttpException, IOException {
|
final HttpContext context) {
|
||||||
final String creds = (String) context.getAttribute("creds");
|
final String creds = (String) context.getAttribute("creds");
|
||||||
if (creds == null || !creds.equals("test:test")) {
|
if (creds == null || !creds.equals("test:test")) {
|
||||||
response.setCode(HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED);
|
response.setCode(HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED);
|
||||||
|
@ -583,7 +583,7 @@ public abstract class TestClientAuthentication extends AbstractIntegrationTestBa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAuthenticationTargetAsProxy() throws Exception {
|
void testAuthenticationTargetAsProxy() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("*", new ProxyAuthHandler()));
|
.register("*", new ProxyAuthHandler()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
@ -604,7 +604,7 @@ public abstract class TestClientAuthentication extends AbstractIntegrationTestBa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConnectionCloseAfterAuthenticationSuccess() throws Exception {
|
void testConnectionCloseAfterAuthenticationSuccess() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.setExchangeHandlerDecorator(requestHandler ->
|
.setExchangeHandlerDecorator(requestHandler ->
|
||||||
new AuthenticatingDecorator(requestHandler, new BasicTestAuthenticator("test:test", "test realm")) {
|
new AuthenticatingDecorator(requestHandler, new BasicTestAuthenticator("test:test", "test realm")) {
|
||||||
|
@ -640,7 +640,7 @@ public abstract class TestClientAuthentication extends AbstractIntegrationTestBa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReauthentication() throws Exception {
|
void testReauthentication() throws Exception {
|
||||||
final BasicSchemeFactory myBasicAuthSchemeFactory = new BasicSchemeFactory() {
|
final BasicSchemeFactory myBasicAuthSchemeFactory = new BasicSchemeFactory() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -720,7 +720,7 @@ public abstract class TestClientAuthentication extends AbstractIntegrationTestBa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAuthenticationFallback() throws Exception {
|
void testAuthenticationFallback() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.setExchangeHandlerDecorator(requestHandler ->
|
.setExchangeHandlerDecorator(requestHandler ->
|
||||||
new AuthenticatingDecorator(requestHandler, new BasicTestAuthenticator("test:test", "test realm")) {
|
new AuthenticatingDecorator(requestHandler, new BasicTestAuthenticator("test:test", "test realm")) {
|
||||||
|
@ -759,7 +759,7 @@ public abstract class TestClientAuthentication extends AbstractIntegrationTestBa
|
||||||
private final static String CHARS = "0123456789abcdef";
|
private final static String CHARS = "0123456789abcdef";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBearerTokenAuthentication() throws Exception {
|
void testBearerTokenAuthentication() throws Exception {
|
||||||
final SecureRandom secureRandom = SecureRandom.getInstanceStrong();
|
final SecureRandom secureRandom = SecureRandom.getInstanceStrong();
|
||||||
secureRandom.setSeed(System.currentTimeMillis());
|
secureRandom.setSeed(System.currentTimeMillis());
|
||||||
final StringBuilder buf = new StringBuilder();
|
final StringBuilder buf = new StringBuilder();
|
||||||
|
|
|
@ -71,7 +71,7 @@ import org.junit.jupiter.api.Test;
|
||||||
/**
|
/**
|
||||||
* Client protocol handling tests.
|
* Client protocol handling tests.
|
||||||
*/
|
*/
|
||||||
public abstract class TestClientRequestExecution extends AbstractIntegrationTestBase {
|
abstract class TestClientRequestExecution extends AbstractIntegrationTestBase {
|
||||||
|
|
||||||
public TestClientRequestExecution(final URIScheme scheme) {
|
public TestClientRequestExecution(final URIScheme scheme) {
|
||||||
super(scheme, ClientProtocolLevel.STANDARD);
|
super(scheme, ClientProtocolLevel.STANDARD);
|
||||||
|
@ -87,7 +87,7 @@ public abstract class TestClientRequestExecution extends AbstractIntegrationTest
|
||||||
public void handle(
|
public void handle(
|
||||||
final ClassicHttpRequest request,
|
final ClassicHttpRequest request,
|
||||||
final ClassicHttpResponse response,
|
final ClassicHttpResponse response,
|
||||||
final HttpContext context) throws HttpException, IOException {
|
final HttpContext context) {
|
||||||
response.setCode(HttpStatus.SC_OK);
|
response.setCode(HttpStatus.SC_OK);
|
||||||
final StringEntity entity = new StringEntity("Whatever");
|
final StringEntity entity = new StringEntity("Whatever");
|
||||||
response.setEntity(entity);
|
response.setEntity(entity);
|
||||||
|
@ -131,7 +131,7 @@ public abstract class TestClientRequestExecution extends AbstractIntegrationTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAutoGeneratedHeaders() throws Exception {
|
void testAutoGeneratedHeaders() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap.register("*", new SimpleService()));
|
configureServer(bootstrap -> bootstrap.register("*", new SimpleService()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ public abstract class TestClientRequestExecution extends AbstractIntegrationTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNonRepeatableEntity() throws Exception {
|
void testNonRepeatableEntity() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap.register("*", new SimpleService()));
|
configureServer(bootstrap -> bootstrap.register("*", new SimpleService()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
|
||||||
|
@ -242,7 +242,7 @@ public abstract class TestClientRequestExecution extends AbstractIntegrationTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNonCompliantURI() throws Exception {
|
void testNonCompliantURI() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap.register("*", new SimpleService()));
|
configureServer(bootstrap -> bootstrap.register("*", new SimpleService()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
|
||||||
|
@ -262,7 +262,7 @@ public abstract class TestClientRequestExecution extends AbstractIntegrationTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelativeRequestURIWithFragment() throws Exception {
|
void testRelativeRequestURIWithFragment() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap.register("*", new SimpleService()));
|
configureServer(bootstrap -> bootstrap.register("*", new SimpleService()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
|
||||||
|
@ -282,7 +282,7 @@ public abstract class TestClientRequestExecution extends AbstractIntegrationTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAbsoluteRequestURIWithFragment() throws Exception {
|
void testAbsoluteRequestURIWithFragment() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap.register("*", new SimpleService()));
|
configureServer(bootstrap -> bootstrap.register("*", new SimpleService()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ import org.junit.jupiter.api.Test;
|
||||||
* Tests for {@code PoolingHttpClientConnectionManager} that do require a server
|
* Tests for {@code PoolingHttpClientConnectionManager} that do require a server
|
||||||
* to communicate with.
|
* to communicate with.
|
||||||
*/
|
*/
|
||||||
public class TestConnectionManagement extends AbstractIntegrationTestBase {
|
class TestConnectionManagement extends AbstractIntegrationTestBase {
|
||||||
|
|
||||||
public TestConnectionManagement() {
|
public TestConnectionManagement() {
|
||||||
super(URIScheme.HTTP, ClientProtocolLevel.STANDARD);
|
super(URIScheme.HTTP, ClientProtocolLevel.STANDARD);
|
||||||
|
@ -76,7 +76,7 @@ public class TestConnectionManagement extends AbstractIntegrationTestBase {
|
||||||
ConnectionEndpoint.RequestExecutor exec;
|
ConnectionEndpoint.RequestExecutor exec;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
void setup() {
|
||||||
exec = new ConnectionEndpoint.RequestExecutor() {
|
exec = new ConnectionEndpoint.RequestExecutor() {
|
||||||
|
|
||||||
final HttpRequestExecutor requestExecutor = new HttpRequestExecutor();
|
final HttpRequestExecutor requestExecutor = new HttpRequestExecutor();
|
||||||
|
@ -99,7 +99,7 @@ public class TestConnectionManagement extends AbstractIntegrationTestBase {
|
||||||
* Tests releasing and re-using a connection after a response is read.
|
* Tests releasing and re-using a connection after a response is read.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testReleaseConnection() throws Exception {
|
void testReleaseConnection() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/random/*", new RandomHandler()));
|
.register("/random/*", new RandomHandler()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
@ -162,7 +162,7 @@ public class TestConnectionManagement extends AbstractIntegrationTestBase {
|
||||||
* Tests releasing with time limits.
|
* Tests releasing with time limits.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testReleaseConnectionWithTimeLimits() throws Exception {
|
void testReleaseConnectionWithTimeLimits() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/random/*", new RandomHandler()));
|
.register("/random/*", new RandomHandler()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
@ -233,7 +233,7 @@ public class TestConnectionManagement extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCloseExpiredIdleConnections() throws Exception {
|
void testCloseExpiredIdleConnections() throws Exception {
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
final TestClient client = client();
|
final TestClient client = client();
|
||||||
final PoolingHttpClientConnectionManager connManager = client.getConnectionManager();
|
final PoolingHttpClientConnectionManager connManager = client.getConnectionManager();
|
||||||
|
@ -273,7 +273,7 @@ public class TestConnectionManagement extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCloseExpiredTTLConnections() throws Exception {
|
void testCloseExpiredTTLConnections() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/random/*", new RandomHandler()));
|
.register("/random/*", new RandomHandler()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
|
|
@ -59,14 +59,14 @@ import org.apache.hc.core5.http.protocol.HttpContext;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestConnectionReuse extends AbstractIntegrationTestBase {
|
class TestConnectionReuse extends AbstractIntegrationTestBase {
|
||||||
|
|
||||||
public TestConnectionReuse() {
|
public TestConnectionReuse() {
|
||||||
super(URIScheme.HTTP, ClientProtocolLevel.STANDARD);
|
super(URIScheme.HTTP, ClientProtocolLevel.STANDARD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReuseOfPersistentConnections() throws Exception {
|
void testReuseOfPersistentConnections() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/random/*", new RandomHandler()));
|
.register("/random/*", new RandomHandler()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
@ -103,7 +103,7 @@ public class TestConnectionReuse extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReuseOfPersistentConnectionsWithStreamedRequestAndResponse() throws Exception {
|
void testReuseOfPersistentConnectionsWithStreamedRequestAndResponse() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/random/*", new RandomHandler()));
|
.register("/random/*", new RandomHandler()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
@ -150,14 +150,14 @@ public class TestConnectionReuse extends AbstractIntegrationTestBase {
|
||||||
public void process(
|
public void process(
|
||||||
final HttpResponse response,
|
final HttpResponse response,
|
||||||
final EntityDetails entityDetails,
|
final EntityDetails entityDetails,
|
||||||
final HttpContext context) throws HttpException, IOException {
|
final HttpContext context) {
|
||||||
response.setHeader(HttpHeaders.CONNECTION, HeaderElements.CLOSE);
|
response.setHeader(HttpHeaders.CONNECTION, HeaderElements.CLOSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReuseOfClosedConnections() throws Exception {
|
void testReuseOfClosedConnections() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.setHttpProcessor(HttpProcessors.customServer(null)
|
.setHttpProcessor(HttpProcessors.customServer(null)
|
||||||
.add(new AlwaysCloseConn())
|
.add(new AlwaysCloseConn())
|
||||||
|
@ -196,7 +196,7 @@ public class TestConnectionReuse extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReuseOfAbortedConnections() throws Exception {
|
void testReuseOfAbortedConnections() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/random/*", new RandomHandler()));
|
.register("/random/*", new RandomHandler()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
@ -233,7 +233,7 @@ public class TestConnectionReuse extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testKeepAliveHeaderRespected() throws Exception {
|
void testKeepAliveHeaderRespected() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.setHttpProcessor(HttpProcessors.customServer(null)
|
.setHttpProcessor(HttpProcessors.customServer(null)
|
||||||
.add(new ResponseKeepAlive())
|
.add(new ResponseKeepAlive())
|
||||||
|
@ -350,7 +350,7 @@ public class TestConnectionReuse extends AbstractIntegrationTestBase {
|
||||||
public void process(
|
public void process(
|
||||||
final HttpResponse response,
|
final HttpResponse response,
|
||||||
final EntityDetails entityDetails,
|
final EntityDetails entityDetails,
|
||||||
final HttpContext context) throws HttpException, IOException {
|
final HttpContext context) {
|
||||||
final Header connection = response.getFirstHeader(HttpHeaders.CONNECTION);
|
final Header connection = response.getFirstHeader(HttpHeaders.CONNECTION);
|
||||||
if(connection != null) {
|
if(connection != null) {
|
||||||
if(!connection.getValue().equalsIgnoreCase("Close")) {
|
if(!connection.getValue().equalsIgnoreCase("Close")) {
|
||||||
|
|
|
@ -68,7 +68,7 @@ import org.junit.jupiter.api.Test;
|
||||||
* require no intervention from the user of HttpClient, but we still want to let clients do their
|
* require no intervention from the user of HttpClient, but we still want to let clients do their
|
||||||
* own thing if they so wish.
|
* own thing if they so wish.
|
||||||
*/
|
*/
|
||||||
public abstract class TestContentCodings extends AbstractIntegrationTestBase {
|
abstract class TestContentCodings extends AbstractIntegrationTestBase {
|
||||||
|
|
||||||
protected TestContentCodings(final URIScheme scheme) {
|
protected TestContentCodings(final URIScheme scheme) {
|
||||||
super(scheme, ClientProtocolLevel.STANDARD);
|
super(scheme, ClientProtocolLevel.STANDARD);
|
||||||
|
@ -82,7 +82,7 @@ public abstract class TestContentCodings extends AbstractIntegrationTestBase {
|
||||||
* if there was a problem
|
* if there was a problem
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testResponseWithNoContent() throws Exception {
|
void testResponseWithNoContent() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("*", new HttpRequestHandler() {
|
.register("*", new HttpRequestHandler() {
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ public abstract class TestContentCodings extends AbstractIntegrationTestBase {
|
||||||
public void handle(
|
public void handle(
|
||||||
final ClassicHttpRequest request,
|
final ClassicHttpRequest request,
|
||||||
final ClassicHttpResponse response,
|
final ClassicHttpResponse response,
|
||||||
final HttpContext context) throws HttpException, IOException {
|
final HttpContext context) {
|
||||||
response.setCode(HttpStatus.SC_NO_CONTENT);
|
response.setCode(HttpStatus.SC_NO_CONTENT);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
@ -117,7 +117,7 @@ public abstract class TestContentCodings extends AbstractIntegrationTestBase {
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testDeflateSupportForServerReturningRfc1950Stream() throws Exception {
|
void testDeflateSupportForServerReturningRfc1950Stream() throws Exception {
|
||||||
final String entityText = "Hello, this is some plain text coming back.";
|
final String entityText = "Hello, this is some plain text coming back.";
|
||||||
|
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
|
@ -142,7 +142,7 @@ public abstract class TestContentCodings extends AbstractIntegrationTestBase {
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testDeflateSupportForServerReturningRfc1951Stream() throws Exception {
|
void testDeflateSupportForServerReturningRfc1951Stream() throws Exception {
|
||||||
final String entityText = "Hello, this is some plain text coming back.";
|
final String entityText = "Hello, this is some plain text coming back.";
|
||||||
|
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
|
@ -166,7 +166,7 @@ public abstract class TestContentCodings extends AbstractIntegrationTestBase {
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGzipSupport() throws Exception {
|
void testGzipSupport() throws Exception {
|
||||||
final String entityText = "Hello, this is some plain text coming back.";
|
final String entityText = "Hello, this is some plain text coming back.";
|
||||||
|
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
|
@ -191,7 +191,7 @@ public abstract class TestContentCodings extends AbstractIntegrationTestBase {
|
||||||
* if there was a problem
|
* if there was a problem
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testThreadSafetyOfContentCodings() throws Exception {
|
void testThreadSafetyOfContentCodings() throws Exception {
|
||||||
final String entityText = "Hello, this is some plain text coming back.";
|
final String entityText = "Hello, this is some plain text coming back.";
|
||||||
|
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
|
@ -241,7 +241,7 @@ public abstract class TestContentCodings extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHttpEntityWriteToForGzip() throws Exception {
|
void testHttpEntityWriteToForGzip() throws Exception {
|
||||||
final String entityText = "Hello, this is some plain text coming back.";
|
final String entityText = "Hello, this is some plain text coming back.";
|
||||||
|
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
|
@ -262,7 +262,7 @@ public abstract class TestContentCodings extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHttpEntityWriteToForDeflate() throws Exception {
|
void testHttpEntityWriteToForDeflate() throws Exception {
|
||||||
final String entityText = "Hello, this is some plain text coming back.";
|
final String entityText = "Hello, this is some plain text coming back.";
|
||||||
|
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
|
@ -282,7 +282,7 @@ public abstract class TestContentCodings extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void gzipResponsesWorkWithBasicResponseHandler() throws Exception {
|
void gzipResponsesWorkWithBasicResponseHandler() throws Exception {
|
||||||
final String entityText = "Hello, this is some plain text coming back.";
|
final String entityText = "Hello, this is some plain text coming back.";
|
||||||
|
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
|
@ -298,7 +298,7 @@ public abstract class TestContentCodings extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void deflateResponsesWorkWithBasicResponseHandler() throws Exception {
|
void deflateResponsesWorkWithBasicResponseHandler() throws Exception {
|
||||||
final String entityText = "Hello, this is some plain text coming back.";
|
final String entityText = "Hello, this is some plain text coming back.";
|
||||||
|
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
|
@ -336,7 +336,7 @@ public abstract class TestContentCodings extends AbstractIntegrationTestBase {
|
||||||
public void handle(
|
public void handle(
|
||||||
final ClassicHttpRequest request,
|
final ClassicHttpRequest request,
|
||||||
final ClassicHttpResponse response,
|
final ClassicHttpResponse response,
|
||||||
final HttpContext context) throws HttpException, IOException {
|
final HttpContext context) {
|
||||||
response.setEntity(new StringEntity(entityText));
|
response.setEntity(new StringEntity(entityText));
|
||||||
response.addHeader("Content-Type", "text/plain");
|
response.addHeader("Content-Type", "text/plain");
|
||||||
final Iterator<HeaderElement> it = MessageSupport.iterate(request, "Accept-Encoding");
|
final Iterator<HeaderElement> it = MessageSupport.iterate(request, "Accept-Encoding");
|
||||||
|
@ -384,7 +384,7 @@ public abstract class TestContentCodings extends AbstractIntegrationTestBase {
|
||||||
public void handle(
|
public void handle(
|
||||||
final ClassicHttpRequest request,
|
final ClassicHttpRequest request,
|
||||||
final ClassicHttpResponse response,
|
final ClassicHttpResponse response,
|
||||||
final HttpContext context) throws HttpException, IOException {
|
final HttpContext context) throws IOException {
|
||||||
response.setEntity(new StringEntity(entityText));
|
response.setEntity(new StringEntity(entityText));
|
||||||
response.addHeader("Content-Type", "text/plain");
|
response.addHeader("Content-Type", "text/plain");
|
||||||
response.addHeader("Content-Type", "text/plain");
|
response.addHeader("Content-Type", "text/plain");
|
||||||
|
|
|
@ -50,19 +50,19 @@ import org.junit.jupiter.api.Test;
|
||||||
/**
|
/**
|
||||||
* This class tests cookie matching when using Virtual Host.
|
* This class tests cookie matching when using Virtual Host.
|
||||||
*/
|
*/
|
||||||
public class TestCookieVirtualHost {
|
class TestCookieVirtualHost {
|
||||||
|
|
||||||
private HttpServer server;
|
private HttpServer server;
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void shutDown() throws Exception {
|
void shutDown() {
|
||||||
if (this.server != null) {
|
if (this.server != null) {
|
||||||
this.server.close(CloseMode.GRACEFUL);
|
this.server.close(CloseMode.GRACEFUL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCookieMatchingWithVirtualHosts() throws Exception {
|
void testCookieMatchingWithVirtualHosts() throws Exception {
|
||||||
server = ServerBootstrap.bootstrap()
|
server = ServerBootstrap.bootstrap()
|
||||||
.register("app.mydomain.fr", "*", (request, response, context) -> {
|
.register("app.mydomain.fr", "*", (request, response, context) -> {
|
||||||
|
|
||||||
|
|
|
@ -68,12 +68,12 @@ import org.junit.jupiter.api.Test;
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link DefaultClientTlsStrategy}.
|
* Unit tests for {@link DefaultClientTlsStrategy}.
|
||||||
*/
|
*/
|
||||||
public class TestDefaultClientTlsStrategy {
|
class TestDefaultClientTlsStrategy {
|
||||||
|
|
||||||
private HttpServer server;
|
private HttpServer server;
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void shutDown() throws Exception {
|
void shutDown() {
|
||||||
if (this.server != null) {
|
if (this.server != null) {
|
||||||
this.server.close(CloseMode.GRACEFUL);
|
this.server.close(CloseMode.GRACEFUL);
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ public class TestDefaultClientTlsStrategy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicSSL() throws Exception {
|
void testBasicSSL() throws Exception {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
this.server = ServerBootstrap.bootstrap()
|
this.server = ServerBootstrap.bootstrap()
|
||||||
.setSslContext(SSLTestContexts.createServerSSLContext())
|
.setSslContext(SSLTestContexts.createServerSSLContext())
|
||||||
|
@ -126,7 +126,7 @@ public class TestDefaultClientTlsStrategy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicDefaultHostnameVerifier() throws Exception {
|
void testBasicDefaultHostnameVerifier() throws Exception {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
this.server = ServerBootstrap.bootstrap()
|
this.server = ServerBootstrap.bootstrap()
|
||||||
.setSslContext(SSLTestContexts.createServerSSLContext())
|
.setSslContext(SSLTestContexts.createServerSSLContext())
|
||||||
|
@ -153,7 +153,7 @@ public class TestDefaultClientTlsStrategy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClientAuthSSL() throws Exception {
|
void testClientAuthSSL() throws Exception {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
this.server = ServerBootstrap.bootstrap()
|
this.server = ServerBootstrap.bootstrap()
|
||||||
.setSslContext(SSLTestContexts.createServerSSLContext())
|
.setSslContext(SSLTestContexts.createServerSSLContext())
|
||||||
|
@ -183,7 +183,7 @@ public class TestDefaultClientTlsStrategy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClientAuthSSLFailure() throws Exception {
|
void testClientAuthSSLFailure() throws Exception {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
this.server = ServerBootstrap.bootstrap()
|
this.server = ServerBootstrap.bootstrap()
|
||||||
.setSslContext(SSLTestContexts.createServerSSLContext())
|
.setSslContext(SSLTestContexts.createServerSSLContext())
|
||||||
|
@ -217,7 +217,7 @@ public class TestDefaultClientTlsStrategy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSSLTrustVerification() throws Exception {
|
void testSSLTrustVerification() throws Exception {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
this.server = ServerBootstrap.bootstrap()
|
this.server = ServerBootstrap.bootstrap()
|
||||||
.setSslContext(SSLTestContexts.createServerSSLContext())
|
.setSslContext(SSLTestContexts.createServerSSLContext())
|
||||||
|
@ -245,13 +245,13 @@ public class TestDefaultClientTlsStrategy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSSLTrustVerificationOverrideWithCustom() throws Exception {
|
void testSSLTrustVerificationOverrideWithCustom() throws Exception {
|
||||||
final TrustStrategy trustStrategy = (chain, authType) -> chain.length == 1;
|
final TrustStrategy trustStrategy = (chain, authType) -> chain.length == 1;
|
||||||
testSSLTrustVerificationOverride(trustStrategy);
|
testSSLTrustVerificationOverride(trustStrategy);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testSSLTrustVerificationOverride(final TrustStrategy trustStrategy)
|
private void testSSLTrustVerificationOverride(final TrustStrategy trustStrategy)
|
||||||
throws Exception, IOException, NoSuchAlgorithmException, KeyManagementException, KeyStoreException {
|
throws Exception {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
this.server = ServerBootstrap.bootstrap()
|
this.server = ServerBootstrap.bootstrap()
|
||||||
.setSslContext(SSLTestContexts.createServerSSLContext())
|
.setSslContext(SSLTestContexts.createServerSSLContext())
|
||||||
|
@ -284,7 +284,7 @@ public class TestDefaultClientTlsStrategy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSSLDisabledByDefault() throws Exception {
|
void testSSLDisabledByDefault() throws Exception {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
this.server = ServerBootstrap.bootstrap()
|
this.server = ServerBootstrap.bootstrap()
|
||||||
.setSslContext(SSLTestContexts.createServerSSLContext())
|
.setSslContext(SSLTestContexts.createServerSSLContext())
|
||||||
|
@ -310,7 +310,7 @@ public class TestDefaultClientTlsStrategy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWeakCiphersDisabledByDefault() {
|
void testWeakCiphersDisabledByDefault() {
|
||||||
final String[] weakCiphersSuites = {
|
final String[] weakCiphersSuites = {
|
||||||
"SSL_RSA_WITH_RC4_128_SHA",
|
"SSL_RSA_WITH_RC4_128_SHA",
|
||||||
"SSL_RSA_WITH_3DES_EDE_CBC_SHA",
|
"SSL_RSA_WITH_3DES_EDE_CBC_SHA",
|
||||||
|
@ -362,7 +362,7 @@ public class TestDefaultClientTlsStrategy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHostnameVerificationClient() throws Exception {
|
void testHostnameVerificationClient() throws Exception {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
this.server = ServerBootstrap.bootstrap()
|
this.server = ServerBootstrap.bootstrap()
|
||||||
.setSslContext(SSLTestContexts.createServerSSLContext())
|
.setSslContext(SSLTestContexts.createServerSSLContext())
|
||||||
|
@ -424,7 +424,7 @@ public class TestDefaultClientTlsStrategy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHostnameVerificationBuiltIn() throws Exception {
|
void testHostnameVerificationBuiltIn() throws Exception {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
this.server = ServerBootstrap.bootstrap()
|
this.server = ServerBootstrap.bootstrap()
|
||||||
.setSslContext(SSLTestContexts.createServerSSLContext())
|
.setSslContext(SSLTestContexts.createServerSSLContext())
|
||||||
|
|
|
@ -61,7 +61,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@SuppressWarnings("boxing") // test code
|
@SuppressWarnings("boxing") // test code
|
||||||
public class TestFutureRequestExecutionService {
|
class TestFutureRequestExecutionService {
|
||||||
|
|
||||||
private HttpServer localServer;
|
private HttpServer localServer;
|
||||||
private String uri;
|
private String uri;
|
||||||
|
@ -70,7 +70,7 @@ public class TestFutureRequestExecutionService {
|
||||||
private final AtomicBoolean blocked = new AtomicBoolean(false);
|
private final AtomicBoolean blocked = new AtomicBoolean(false);
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void before() throws Exception {
|
void before() throws Exception {
|
||||||
this.localServer = ServerBootstrap.bootstrap()
|
this.localServer = ServerBootstrap.bootstrap()
|
||||||
.setCanonicalHostName("localhost")
|
.setCanonicalHostName("localhost")
|
||||||
.register("/wait", (request, response, context) -> {
|
.register("/wait", (request, response, context) -> {
|
||||||
|
@ -97,21 +97,21 @@ public class TestFutureRequestExecutionService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void after() throws Exception {
|
void after() throws Exception {
|
||||||
blocked.set(false); // any remaining requests should unblock
|
blocked.set(false); // any remaining requests should unblock
|
||||||
this.localServer.stop();
|
this.localServer.stop();
|
||||||
httpAsyncClientWithFuture.close();
|
httpAsyncClientWithFuture.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldExecuteSingleCall() throws InterruptedException, ExecutionException {
|
void shouldExecuteSingleCall() throws InterruptedException, ExecutionException {
|
||||||
final FutureTask<Boolean> task = httpAsyncClientWithFuture.execute(
|
final FutureTask<Boolean> task = httpAsyncClientWithFuture.execute(
|
||||||
new HttpGet(uri), HttpClientContext.create(), new OkidokiHandler());
|
new HttpGet(uri), HttpClientContext.create(), new OkidokiHandler());
|
||||||
Assertions.assertTrue(task.get(), "request should have returned OK");
|
Assertions.assertTrue(task.get(), "request should have returned OK");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCancel() throws InterruptedException, ExecutionException {
|
void shouldCancel() {
|
||||||
final FutureTask<Boolean> task = httpAsyncClientWithFuture.execute(
|
final FutureTask<Boolean> task = httpAsyncClientWithFuture.execute(
|
||||||
new HttpGet(uri), HttpClientContext.create(), new OkidokiHandler());
|
new HttpGet(uri), HttpClientContext.create(), new OkidokiHandler());
|
||||||
task.cancel(true);
|
task.cancel(true);
|
||||||
|
@ -122,7 +122,7 @@ public class TestFutureRequestExecutionService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldTimeout() throws InterruptedException, ExecutionException, TimeoutException {
|
void shouldTimeout() {
|
||||||
blocked.set(true);
|
blocked.set(true);
|
||||||
final FutureTask<Boolean> task = httpAsyncClientWithFuture.execute(
|
final FutureTask<Boolean> task = httpAsyncClientWithFuture.execute(
|
||||||
new HttpGet(uri), HttpClientContext.create(), new OkidokiHandler());
|
new HttpGet(uri), HttpClientContext.create(), new OkidokiHandler());
|
||||||
|
@ -131,7 +131,7 @@ public class TestFutureRequestExecutionService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldExecuteMultipleCalls() throws Exception {
|
void shouldExecuteMultipleCalls() throws Exception {
|
||||||
final int reqNo = 100;
|
final int reqNo = 100;
|
||||||
final Queue<Future<Boolean>> tasks = new LinkedList<>();
|
final Queue<Future<Boolean>> tasks = new LinkedList<>();
|
||||||
for(int i = 0; i < reqNo; i++) {
|
for(int i = 0; i < reqNo; i++) {
|
||||||
|
@ -147,7 +147,7 @@ public class TestFutureRequestExecutionService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldExecuteMultipleCallsAndCallback() throws Exception {
|
void shouldExecuteMultipleCallsAndCallback() throws Exception {
|
||||||
final int reqNo = 100;
|
final int reqNo = 100;
|
||||||
final Queue<Future<Boolean>> tasks = new LinkedList<>();
|
final Queue<Future<Boolean>> tasks = new LinkedList<>();
|
||||||
final CountDownLatch latch = new CountDownLatch(reqNo);
|
final CountDownLatch latch = new CountDownLatch(reqNo);
|
||||||
|
@ -194,7 +194,7 @@ public class TestFutureRequestExecutionService {
|
||||||
private final class OkidokiHandler implements HttpClientResponseHandler<Boolean> {
|
private final class OkidokiHandler implements HttpClientResponseHandler<Boolean> {
|
||||||
@Override
|
@Override
|
||||||
public Boolean handleResponse(
|
public Boolean handleResponse(
|
||||||
final ClassicHttpResponse response) throws IOException {
|
final ClassicHttpResponse response) {
|
||||||
return response.getCode() == 200;
|
return response.getCode() == 200;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,14 +40,14 @@ import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@SuppressWarnings("boxing") // test code
|
@SuppressWarnings("boxing") // test code
|
||||||
public class TestHttpClientBuilderInterceptors extends AbstractIntegrationTestBase {
|
class TestHttpClientBuilderInterceptors extends AbstractIntegrationTestBase {
|
||||||
|
|
||||||
public TestHttpClientBuilderInterceptors() {
|
public TestHttpClientBuilderInterceptors() {
|
||||||
super(URIScheme.HTTP, ClientProtocolLevel.STANDARD);
|
super(URIScheme.HTTP, ClientProtocolLevel.STANDARD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void before() throws Exception {
|
void before() {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/test", (request, response, context) -> {
|
.register("/test", (request, response, context) -> {
|
||||||
final Header testInterceptorHeader = request.getHeader("X-Test-Interceptor");
|
final Header testInterceptorHeader = request.getHeader("X-Test-Interceptor");
|
||||||
|
@ -64,7 +64,7 @@ public class TestHttpClientBuilderInterceptors extends AbstractIntegrationTestBa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddExecInterceptorLastShouldBeExecuted() throws Exception {
|
void testAddExecInterceptorLastShouldBeExecuted() throws Exception {
|
||||||
final HttpHost httpHost = startServer();
|
final HttpHost httpHost = startServer();
|
||||||
final TestClient client = client();
|
final TestClient client = client();
|
||||||
final ClassicHttpRequest request = new HttpPost("/test");
|
final ClassicHttpRequest request = new HttpPost("/test");
|
||||||
|
|
|
@ -43,14 +43,14 @@ import org.apache.hc.core5.http.io.entity.EntityUtils;
|
||||||
import org.apache.hc.core5.util.TimeValue;
|
import org.apache.hc.core5.util.TimeValue;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestIdleConnectionEviction extends AbstractIntegrationTestBase {
|
class TestIdleConnectionEviction extends AbstractIntegrationTestBase {
|
||||||
|
|
||||||
public TestIdleConnectionEviction() {
|
public TestIdleConnectionEviction() {
|
||||||
super(URIScheme.HTTP, ClientProtocolLevel.STANDARD);
|
super(URIScheme.HTTP, ClientProtocolLevel.STANDARD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIdleConnectionEviction() throws Exception {
|
void testIdleConnectionEviction() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/random/*", new RandomHandler()));
|
.register("/random/*", new RandomHandler()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
|
|
@ -48,12 +48,12 @@ import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestMalformedServerResponse {
|
class TestMalformedServerResponse {
|
||||||
|
|
||||||
private HttpServer server;
|
private HttpServer server;
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void shutDown() throws Exception {
|
void shutDown() {
|
||||||
if (this.server != null) {
|
if (this.server != null) {
|
||||||
this.server.close(CloseMode.GRACEFUL);
|
this.server.close(CloseMode.GRACEFUL);
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ public class TestMalformedServerResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoContentResponseWithGarbage() throws Exception {
|
void testNoContentResponseWithGarbage() throws Exception {
|
||||||
server = ServerBootstrap.bootstrap()
|
server = ServerBootstrap.bootstrap()
|
||||||
.setCanonicalHostName("localhost")
|
.setCanonicalHostName("localhost")
|
||||||
.setConnectionFactory(new BrokenServerConnectionFactory())
|
.setConnectionFactory(new BrokenServerConnectionFactory())
|
||||||
|
|
|
@ -53,7 +53,7 @@ import org.junit.jupiter.api.Test;
|
||||||
/**
|
/**
|
||||||
* Client protocol handling tests.
|
* Client protocol handling tests.
|
||||||
*/
|
*/
|
||||||
public abstract class TestMinimalClientRequestExecution extends AbstractIntegrationTestBase {
|
abstract class TestMinimalClientRequestExecution extends AbstractIntegrationTestBase {
|
||||||
|
|
||||||
protected TestMinimalClientRequestExecution(final URIScheme scheme) {
|
protected TestMinimalClientRequestExecution(final URIScheme scheme) {
|
||||||
super(scheme, ClientProtocolLevel.MINIMAL);
|
super(scheme, ClientProtocolLevel.MINIMAL);
|
||||||
|
@ -69,7 +69,7 @@ public abstract class TestMinimalClientRequestExecution extends AbstractIntegrat
|
||||||
public void handle(
|
public void handle(
|
||||||
final ClassicHttpRequest request,
|
final ClassicHttpRequest request,
|
||||||
final ClassicHttpResponse response,
|
final ClassicHttpResponse response,
|
||||||
final HttpContext context) throws HttpException, IOException {
|
final HttpContext context) {
|
||||||
response.setCode(HttpStatus.SC_OK);
|
response.setCode(HttpStatus.SC_OK);
|
||||||
final StringEntity entity = new StringEntity("Whatever");
|
final StringEntity entity = new StringEntity("Whatever");
|
||||||
response.setEntity(entity);
|
response.setEntity(entity);
|
||||||
|
@ -77,7 +77,7 @@ public abstract class TestMinimalClientRequestExecution extends AbstractIntegrat
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNonCompliantURIWithContext() throws Exception {
|
void testNonCompliantURIWithContext() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap.register("*", new SimpleService()));
|
configureServer(bootstrap -> bootstrap.register("*", new SimpleService()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ public abstract class TestMinimalClientRequestExecution extends AbstractIntegrat
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNonCompliantURIWithoutContext() throws Exception {
|
void testNonCompliantURIWithoutContext() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap.register("*", new SimpleService()));
|
configureServer(bootstrap -> bootstrap.register("*", new SimpleService()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
|
||||||
|
|
|
@ -75,14 +75,14 @@ import org.junit.jupiter.api.Test;
|
||||||
/**
|
/**
|
||||||
* Redirection test cases.
|
* Redirection test cases.
|
||||||
*/
|
*/
|
||||||
public abstract class TestRedirects extends AbstractIntegrationTestBase {
|
abstract class TestRedirects extends AbstractIntegrationTestBase {
|
||||||
|
|
||||||
protected TestRedirects(final URIScheme scheme) {
|
protected TestRedirects(final URIScheme scheme) {
|
||||||
super(scheme, ClientProtocolLevel.STANDARD);
|
super(scheme, ClientProtocolLevel.STANDARD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicRedirect300() throws Exception {
|
void testBasicRedirect300() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
||||||
requestHandler,
|
requestHandler,
|
||||||
|
@ -110,7 +110,7 @@ public abstract class TestRedirects extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicRedirect300NoKeepAlive() throws Exception {
|
void testBasicRedirect300NoKeepAlive() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
||||||
requestHandler,
|
requestHandler,
|
||||||
|
@ -140,7 +140,7 @@ public abstract class TestRedirects extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicRedirect301() throws Exception {
|
void testBasicRedirect301() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
||||||
requestHandler,
|
requestHandler,
|
||||||
|
@ -172,7 +172,7 @@ public abstract class TestRedirects extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicRedirect302() throws Exception {
|
void testBasicRedirect302() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
||||||
requestHandler,
|
requestHandler,
|
||||||
|
@ -198,7 +198,7 @@ public abstract class TestRedirects extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicRedirect302NoLocation() throws Exception {
|
void testBasicRedirect302NoLocation() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
||||||
requestHandler,
|
requestHandler,
|
||||||
|
@ -229,7 +229,7 @@ public abstract class TestRedirects extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicRedirect303() throws Exception {
|
void testBasicRedirect303() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
||||||
requestHandler,
|
requestHandler,
|
||||||
|
@ -254,7 +254,7 @@ public abstract class TestRedirects extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicRedirect304() throws Exception {
|
void testBasicRedirect304() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/oldlocation/*", (request, response, context) -> {
|
.register("/oldlocation/*", (request, response, context) -> {
|
||||||
response.setCode(HttpStatus.SC_NOT_MODIFIED);
|
response.setCode(HttpStatus.SC_NOT_MODIFIED);
|
||||||
|
@ -284,7 +284,7 @@ public abstract class TestRedirects extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicRedirect305() throws Exception {
|
void testBasicRedirect305() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("/oldlocation/*", (request, response, context) -> {
|
.register("/oldlocation/*", (request, response, context) -> {
|
||||||
response.setCode(HttpStatus.SC_USE_PROXY);
|
response.setCode(HttpStatus.SC_USE_PROXY);
|
||||||
|
@ -314,7 +314,7 @@ public abstract class TestRedirects extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicRedirect307() throws Exception {
|
void testBasicRedirect307() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
||||||
requestHandler,
|
requestHandler,
|
||||||
|
@ -339,7 +339,7 @@ public abstract class TestRedirects extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMaxRedirectCheck() throws Exception {
|
void testMaxRedirectCheck() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
||||||
requestHandler,
|
requestHandler,
|
||||||
|
@ -362,7 +362,7 @@ public abstract class TestRedirects extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCircularRedirect() throws Exception {
|
void testCircularRedirect() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
||||||
requestHandler,
|
requestHandler,
|
||||||
|
@ -385,7 +385,7 @@ public abstract class TestRedirects extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPostRedirectSeeOther() throws Exception {
|
void testPostRedirectSeeOther() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
||||||
requestHandler,
|
requestHandler,
|
||||||
|
@ -412,7 +412,7 @@ public abstract class TestRedirects extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelativeRedirect() throws Exception {
|
void testRelativeRedirect() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
||||||
requestHandler,
|
requestHandler,
|
||||||
|
@ -444,7 +444,7 @@ public abstract class TestRedirects extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelativeRedirect2() throws Exception {
|
void testRelativeRedirect2() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
||||||
requestHandler,
|
requestHandler,
|
||||||
|
@ -476,7 +476,7 @@ public abstract class TestRedirects extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRejectBogusRedirectLocation() throws Exception {
|
void testRejectBogusRedirectLocation() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
||||||
requestHandler,
|
requestHandler,
|
||||||
|
@ -500,7 +500,7 @@ public abstract class TestRedirects extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRejectInvalidRedirectLocation() throws Exception {
|
void testRejectInvalidRedirectLocation() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
||||||
requestHandler,
|
requestHandler,
|
||||||
|
@ -524,7 +524,7 @@ public abstract class TestRedirects extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRedirectWithCookie() throws Exception {
|
void testRedirectWithCookie() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
.setExchangeHandlerDecorator(requestHandler -> new RedirectingDecorator(
|
||||||
requestHandler,
|
requestHandler,
|
||||||
|
@ -561,7 +561,7 @@ public abstract class TestRedirects extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultHeadersRedirect() throws Exception {
|
void testDefaultHeadersRedirect() throws Exception {
|
||||||
configureClient(builder -> builder
|
configureClient(builder -> builder
|
||||||
.setDefaultHeaders(Collections.singletonList(new BasicHeader(HttpHeaders.USER_AGENT, "my-test-client")))
|
.setDefaultHeaders(Collections.singletonList(new BasicHeader(HttpHeaders.USER_AGENT, "my-test-client")))
|
||||||
);
|
);
|
||||||
|
@ -593,7 +593,7 @@ public abstract class TestRedirects extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCompressionHeaderRedirect() throws Exception {
|
void testCompressionHeaderRedirect() throws Exception {
|
||||||
final Queue<String> values = new ConcurrentLinkedQueue<>();
|
final Queue<String> values = new ConcurrentLinkedQueue<>();
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.setExchangeHandlerDecorator(new Decorator<HttpServerRequestHandler>() {
|
.setExchangeHandlerDecorator(new Decorator<HttpServerRequestHandler>() {
|
||||||
|
|
|
@ -53,7 +53,7 @@ import org.junit.jupiter.api.Test;
|
||||||
/**
|
/**
|
||||||
* Test cases for state-ful connections.
|
* Test cases for state-ful connections.
|
||||||
*/
|
*/
|
||||||
public class TestStatefulConnManagement extends AbstractIntegrationTestBase {
|
class TestStatefulConnManagement extends AbstractIntegrationTestBase {
|
||||||
|
|
||||||
public static final Timeout LONG_TIMEOUT = Timeout.ofMinutes(3);
|
public static final Timeout LONG_TIMEOUT = Timeout.ofMinutes(3);
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ public class TestStatefulConnManagement extends AbstractIntegrationTestBase {
|
||||||
public void handle(
|
public void handle(
|
||||||
final ClassicHttpRequest request,
|
final ClassicHttpRequest request,
|
||||||
final ClassicHttpResponse response,
|
final ClassicHttpResponse response,
|
||||||
final HttpContext context) throws HttpException, IOException {
|
final HttpContext context) {
|
||||||
response.setCode(HttpStatus.SC_OK);
|
response.setCode(HttpStatus.SC_OK);
|
||||||
final StringEntity entity = new StringEntity("Whatever");
|
final StringEntity entity = new StringEntity("Whatever");
|
||||||
response.setEntity(entity);
|
response.setEntity(entity);
|
||||||
|
@ -79,7 +79,7 @@ public class TestStatefulConnManagement extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStatefulConnections() throws Exception {
|
void testStatefulConnections() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
configureServer(bootstrap -> bootstrap
|
||||||
.register("*", new SimpleService()));
|
.register("*", new SimpleService()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
@ -193,7 +193,7 @@ public class TestStatefulConnManagement extends AbstractIntegrationTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRouteSpecificPoolRecylcing() throws Exception {
|
void testRouteSpecificPoolRecylcing() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap.register("*", new SimpleService()));
|
configureServer(bootstrap -> bootstrap.register("*", new SimpleService()));
|
||||||
final HttpHost target = startServer();
|
final HttpHost target = startServer();
|
||||||
|
|
||||||
|
|
|
@ -38,23 +38,23 @@ import org.junit.jupiter.api.Test;
|
||||||
* Unit tests for exceptions.
|
* Unit tests for exceptions.
|
||||||
* Trivial, but it looks better in the Clover reports.
|
* Trivial, but it looks better in the Clover reports.
|
||||||
*/
|
*/
|
||||||
public class ConnectExceptionSupportTest {
|
class ConnectExceptionSupportTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConnectTimeoutExceptionFromNullMessageAndHost() {
|
void testConnectTimeoutExceptionFromNullMessageAndHost() {
|
||||||
final ConnectTimeoutException ctx = ConnectExceptionSupport.createConnectTimeoutException(null, null);
|
final ConnectTimeoutException ctx = ConnectExceptionSupport.createConnectTimeoutException(null, null);
|
||||||
Assertions.assertEquals("Connect to remote endpoint timed out", ctx.getMessage());
|
Assertions.assertEquals("Connect to remote endpoint timed out", ctx.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConnectTimeoutExceptionFromCause() {
|
void testConnectTimeoutExceptionFromCause() {
|
||||||
final IOException cause = new IOException("something awful");
|
final IOException cause = new IOException("something awful");
|
||||||
final ConnectTimeoutException ctx = ConnectExceptionSupport.createConnectTimeoutException(cause, null);
|
final ConnectTimeoutException ctx = ConnectExceptionSupport.createConnectTimeoutException(cause, null);
|
||||||
Assertions.assertEquals("Connect to remote endpoint failed: something awful", ctx.getMessage());
|
Assertions.assertEquals("Connect to remote endpoint failed: something awful", ctx.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConnectTimeoutExceptionFromCauseAndHost() {
|
void testConnectTimeoutExceptionFromCauseAndHost() {
|
||||||
final HttpHost target = new HttpHost("localhost");
|
final HttpHost target = new HttpHost("localhost");
|
||||||
final IOException cause = new IOException();
|
final IOException cause = new IOException();
|
||||||
final ConnectTimeoutException ctx = ConnectExceptionSupport.createConnectTimeoutException(cause, target);
|
final ConnectTimeoutException ctx = ConnectExceptionSupport.createConnectTimeoutException(cause, target);
|
||||||
|
@ -62,7 +62,7 @@ public class ConnectExceptionSupportTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConnectTimeoutExceptionFromCauseHostAndRemoteAddress() throws Exception {
|
void testConnectTimeoutExceptionFromCauseHostAndRemoteAddress() throws Exception {
|
||||||
final HttpHost target = new HttpHost("localhost");
|
final HttpHost target = new HttpHost("localhost");
|
||||||
final InetAddress remoteAddress = InetAddress.getByAddress(new byte[] {1,2,3,4});
|
final InetAddress remoteAddress = InetAddress.getByAddress(new byte[] {1,2,3,4});
|
||||||
final IOException cause = new IOException();
|
final IOException cause = new IOException();
|
||||||
|
@ -71,21 +71,21 @@ public class ConnectExceptionSupportTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHttpHostConnectExceptionFromNullCause() {
|
void testHttpHostConnectExceptionFromNullCause() {
|
||||||
final HttpHostConnectException ctx = ConnectExceptionSupport.createHttpHostConnectException(null, null,
|
final HttpHostConnectException ctx = ConnectExceptionSupport.createHttpHostConnectException(null, null,
|
||||||
(InetAddress [])null);
|
(InetAddress [])null);
|
||||||
Assertions.assertEquals("Connect to remote endpoint refused", ctx.getMessage());
|
Assertions.assertEquals("Connect to remote endpoint refused", ctx.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHttpHostConnectExceptionFromCause() {
|
void testHttpHostConnectExceptionFromCause() {
|
||||||
final IOException cause = new IOException("something awful");
|
final IOException cause = new IOException("something awful");
|
||||||
final HttpHostConnectException ctx = ConnectExceptionSupport.createHttpHostConnectException(cause, null);
|
final HttpHostConnectException ctx = ConnectExceptionSupport.createHttpHostConnectException(cause, null);
|
||||||
Assertions.assertEquals("Connect to remote endpoint failed: something awful", ctx.getMessage());
|
Assertions.assertEquals("Connect to remote endpoint failed: something awful", ctx.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHttpHostConnectExceptionFromCauseAndHost() {
|
void testHttpHostConnectExceptionFromCauseAndHost() {
|
||||||
final HttpHost target = new HttpHost("localhost");
|
final HttpHost target = new HttpHost("localhost");
|
||||||
final IOException cause = new IOException();
|
final IOException cause = new IOException();
|
||||||
final HttpHostConnectException ctx = ConnectExceptionSupport.createHttpHostConnectException(cause, target);
|
final HttpHostConnectException ctx = ConnectExceptionSupport.createHttpHostConnectException(cause, target);
|
||||||
|
@ -93,7 +93,7 @@ public class ConnectExceptionSupportTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHttpHostConnectExceptionFromCauseHostAndRemoteAddress() throws Exception {
|
void testHttpHostConnectExceptionFromCauseHostAndRemoteAddress() throws Exception {
|
||||||
final HttpHost target = new HttpHost("localhost");
|
final HttpHost target = new HttpHost("localhost");
|
||||||
final InetAddress remoteAddress1 = InetAddress.getByAddress(new byte[] {1,2,3,4});
|
final InetAddress remoteAddress1 = InetAddress.getByAddress(new byte[] {1,2,3,4});
|
||||||
final InetAddress remoteAddress2 = InetAddress.getByAddress(new byte[] {5,6,7,8});
|
final InetAddress remoteAddress2 = InetAddress.getByAddress(new byte[] {5,6,7,8});
|
||||||
|
|
|
@ -34,7 +34,7 @@ import java.net.UnknownHostException;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class SystemDefaultDnsResolverTest {
|
class SystemDefaultDnsResolverTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void resolve() throws UnknownHostException {
|
void resolve() throws UnknownHostException {
|
||||||
|
|
|
@ -41,7 +41,7 @@ import org.junit.jupiter.api.Test;
|
||||||
/**
|
/**
|
||||||
* Tests for {@link HttpRoute}.
|
* Tests for {@link HttpRoute}.
|
||||||
*/
|
*/
|
||||||
public class TestHttpRoute {
|
class TestHttpRoute {
|
||||||
|
|
||||||
// a selection of constants for generating routes
|
// a selection of constants for generating routes
|
||||||
public final static
|
public final static
|
||||||
|
@ -83,7 +83,7 @@ public class TestHttpRoute {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCstrFullRoute() {
|
void testCstrFullRoute() {
|
||||||
// create a route with all arguments and check the details
|
// create a route with all arguments and check the details
|
||||||
final HttpHost[] chain3 = { PROXY1, PROXY2, PROXY3 };
|
final HttpHost[] chain3 = { PROXY1, PROXY2, PROXY3 };
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ public class TestHttpRoute {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCstrFullFlags() {
|
void testCstrFullFlags() {
|
||||||
// tests the flag parameters in the full-blown constructor
|
// tests the flag parameters in the full-blown constructor
|
||||||
|
|
||||||
final HttpHost[] chain3 = { PROXY1, PROXY2, PROXY3 };
|
final HttpHost[] chain3 = { PROXY1, PROXY2, PROXY3 };
|
||||||
|
@ -174,7 +174,7 @@ public class TestHttpRoute {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidArguments() {
|
void testInvalidArguments() {
|
||||||
final HttpHost[] chain1 = { PROXY1 };
|
final HttpHost[] chain1 = { PROXY1 };
|
||||||
|
|
||||||
// for reference: this one should succeed
|
// for reference: this one should succeed
|
||||||
|
@ -189,7 +189,7 @@ public class TestHttpRoute {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNullEnums() {
|
void testNullEnums() {
|
||||||
|
|
||||||
// tests the default values for the enum parameters
|
// tests the default values for the enum parameters
|
||||||
// also covers the accessors for the enum attributes
|
// also covers the accessors for the enum attributes
|
||||||
|
@ -205,7 +205,7 @@ public class TestHttpRoute {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEqualsHashcodeClone() throws CloneNotSupportedException {
|
void testEqualsHashcodeClone() throws CloneNotSupportedException {
|
||||||
final HttpHost[] chain0 = { };
|
final HttpHost[] chain0 = { };
|
||||||
final HttpHost[] chain1 = { PROXY1 };
|
final HttpHost[] chain1 = { PROXY1 };
|
||||||
final HttpHost[] chain3 = { PROXY1, PROXY2, PROXY3 };
|
final HttpHost[] chain3 = { PROXY1, PROXY2, PROXY3 };
|
||||||
|
@ -337,7 +337,7 @@ public class TestHttpRoute {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHopping() {
|
void testHopping() {
|
||||||
// test getHopCount() and getHopTarget() with different proxy chains
|
// test getHopCount() and getHopTarget() with different proxy chains
|
||||||
final HttpHost[] proxies = null;
|
final HttpHost[] proxies = null;
|
||||||
final HttpRoute route = new HttpRoute(TARGET1, null, proxies, true,
|
final HttpRoute route = new HttpRoute(TARGET1, null, proxies, true,
|
||||||
|
@ -369,7 +369,7 @@ public class TestHttpRoute {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCstr1() {
|
void testCstr1() {
|
||||||
final HttpRoute route = new HttpRoute(TARGET2);
|
final HttpRoute route = new HttpRoute(TARGET2);
|
||||||
final HttpRoute should = new HttpRoute
|
final HttpRoute should = new HttpRoute
|
||||||
(TARGET2, null, (HttpHost[]) null, false,
|
(TARGET2, null, (HttpHost[]) null, false,
|
||||||
|
@ -378,7 +378,7 @@ public class TestHttpRoute {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCstr3() {
|
void testCstr3() {
|
||||||
// test convenience constructor with 3 arguments
|
// test convenience constructor with 3 arguments
|
||||||
HttpRoute route = new HttpRoute(TARGET2, LOCAL61, false);
|
HttpRoute route = new HttpRoute(TARGET2, LOCAL61, false);
|
||||||
HttpRoute should = new HttpRoute
|
HttpRoute should = new HttpRoute
|
||||||
|
@ -394,7 +394,7 @@ public class TestHttpRoute {
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@Test
|
@Test
|
||||||
public void testCstr4() {
|
void testCstr4() {
|
||||||
// test convenience constructor with 4 arguments
|
// test convenience constructor with 4 arguments
|
||||||
HttpRoute route = new HttpRoute(TARGET2, null, PROXY2, false);
|
HttpRoute route = new HttpRoute(TARGET2, null, PROXY2, false);
|
||||||
HttpRoute should = new HttpRoute
|
HttpRoute should = new HttpRoute
|
||||||
|
@ -414,7 +414,7 @@ public class TestHttpRoute {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCstr6() {
|
void testCstr6() {
|
||||||
// test convenience constructor with 6 arguments
|
// test convenience constructor with 6 arguments
|
||||||
HttpRoute route = new HttpRoute
|
HttpRoute route = new HttpRoute
|
||||||
(TARGET2, null, PROXY2, true,
|
(TARGET2, null, PROXY2, true,
|
||||||
|
@ -436,7 +436,7 @@ public class TestHttpRoute {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImmutable() throws CloneNotSupportedException {
|
void testImmutable() throws CloneNotSupportedException {
|
||||||
|
|
||||||
final HttpHost[] proxies = new HttpHost[]{ PROXY1, PROXY2, PROXY3 };
|
final HttpHost[] proxies = new HttpHost[]{ PROXY1, PROXY2, PROXY3 };
|
||||||
final HttpRoute route1 = new HttpRoute(TARGET1, null, proxies, false,
|
final HttpRoute route1 = new HttpRoute(TARGET1, null, proxies, false,
|
||||||
|
|
|
@ -50,10 +50,10 @@ import org.junit.jupiter.api.Test;
|
||||||
/**
|
/**
|
||||||
* Simple tests for {@link SimpleResponseBuilder} and {@link SimpleRequestBuilder}.
|
* Simple tests for {@link SimpleResponseBuilder} and {@link SimpleRequestBuilder}.
|
||||||
*/
|
*/
|
||||||
public class TestSimpleMessageBuilders {
|
class TestSimpleMessageBuilders {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponseBasics() throws Exception {
|
void testResponseBasics() {
|
||||||
final SimpleResponseBuilder builder = SimpleResponseBuilder.create(200);
|
final SimpleResponseBuilder builder = SimpleResponseBuilder.create(200);
|
||||||
Assertions.assertEquals(200, builder.getStatus());
|
Assertions.assertEquals(200, builder.getStatus());
|
||||||
Assertions.assertNull(builder.getHeaders());
|
Assertions.assertNull(builder.getHeaders());
|
||||||
|
@ -111,7 +111,7 @@ public class TestSimpleMessageBuilders {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRequestBasics() throws Exception {
|
void testRequestBasics() throws Exception {
|
||||||
final SimpleRequestBuilder builder = SimpleRequestBuilder.get();
|
final SimpleRequestBuilder builder = SimpleRequestBuilder.get();
|
||||||
Assertions.assertEquals(URI.create("/"), builder.getUri());
|
Assertions.assertEquals(URI.create("/"), builder.getUri());
|
||||||
Assertions.assertEquals("GET", builder.getMethod());
|
Assertions.assertEquals("GET", builder.getMethod());
|
||||||
|
@ -205,7 +205,7 @@ public class TestSimpleMessageBuilders {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponseCopy() throws Exception {
|
void testResponseCopy() {
|
||||||
final SimpleHttpResponse response = SimpleHttpResponse.create(400);
|
final SimpleHttpResponse response = SimpleHttpResponse.create(400);
|
||||||
response.addHeader("h1", "v1");
|
response.addHeader("h1", "v1");
|
||||||
response.addHeader("h1", "v2");
|
response.addHeader("h1", "v2");
|
||||||
|
@ -220,7 +220,7 @@ public class TestSimpleMessageBuilders {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRequestCopy() throws Exception {
|
void testRequestCopy() {
|
||||||
final SimpleHttpRequest request = SimpleHttpRequest.create(Method.GET, URI.create("https://host:3456/stuff?blah")) ;
|
final SimpleHttpRequest request = SimpleHttpRequest.create(Method.GET, URI.create("https://host:3456/stuff?blah")) ;
|
||||||
request.addHeader("h1", "v1");
|
request.addHeader("h1", "v1");
|
||||||
request.addHeader("h1", "v2");
|
request.addHeader("h1", "v2");
|
||||||
|
@ -238,7 +238,7 @@ public class TestSimpleMessageBuilders {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetParameters() throws Exception {
|
void testGetParameters() {
|
||||||
final SimpleRequestBuilder builder = SimpleRequestBuilder.get(URI.create("https://host:3456/stuff?p0=p0"));
|
final SimpleRequestBuilder builder = SimpleRequestBuilder.get(URI.create("https://host:3456/stuff?p0=p0"));
|
||||||
builder.addParameter("p1", "v1");
|
builder.addParameter("p1", "v1");
|
||||||
builder.addParameters(new BasicNameValuePair("p2", "v2"), new BasicNameValuePair("p3", "v3"));
|
builder.addParameters(new BasicNameValuePair("p2", "v2"), new BasicNameValuePair("p3", "v3"));
|
||||||
|
@ -256,7 +256,7 @@ public class TestSimpleMessageBuilders {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPostParameters() throws Exception {
|
void testPostParameters() {
|
||||||
final SimpleRequestBuilder builder = SimpleRequestBuilder.post(URI.create("https://host:3456/stuff?p0=p0"));
|
final SimpleRequestBuilder builder = SimpleRequestBuilder.post(URI.create("https://host:3456/stuff?p0=p0"));
|
||||||
builder.addParameter("p1", "v1");
|
builder.addParameter("p1", "v1");
|
||||||
builder.addParameters(new BasicNameValuePair("p2", "v2"), new BasicNameValuePair("p3", "v3"));
|
builder.addParameters(new BasicNameValuePair("p2", "v2"), new BasicNameValuePair("p3", "v3"));
|
||||||
|
|
|
@ -33,10 +33,10 @@ import org.apache.hc.core5.http.message.BasicNameValuePair;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestAuthChallenge {
|
class TestAuthChallenge {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAuthChallengeWithValue() {
|
void testAuthChallengeWithValue() {
|
||||||
final AuthChallenge authChallenge = new AuthChallenge(ChallengeType.TARGET, StandardAuthScheme.BASIC, "blah", null);
|
final AuthChallenge authChallenge = new AuthChallenge(ChallengeType.TARGET, StandardAuthScheme.BASIC, "blah", null);
|
||||||
Assertions.assertEquals(StandardAuthScheme.BASIC, authChallenge.getSchemeName());
|
Assertions.assertEquals(StandardAuthScheme.BASIC, authChallenge.getSchemeName());
|
||||||
Assertions.assertEquals("blah", authChallenge.getValue());
|
Assertions.assertEquals("blah", authChallenge.getValue());
|
||||||
|
@ -45,7 +45,7 @@ public class TestAuthChallenge {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAuthChallengeWithParams() {
|
void testAuthChallengeWithParams() {
|
||||||
final AuthChallenge authChallenge = new AuthChallenge(ChallengeType.TARGET, StandardAuthScheme.BASIC, null,
|
final AuthChallenge authChallenge = new AuthChallenge(ChallengeType.TARGET, StandardAuthScheme.BASIC, null,
|
||||||
Arrays.asList(new BasicNameValuePair("blah", "this"), new BasicNameValuePair("blah", "that")));
|
Arrays.asList(new BasicNameValuePair("blah", "this"), new BasicNameValuePair("blah", "that")));
|
||||||
Assertions.assertEquals(StandardAuthScheme.BASIC, authChallenge.getSchemeName());
|
Assertions.assertEquals(StandardAuthScheme.BASIC, authChallenge.getSchemeName());
|
||||||
|
|
|
@ -33,10 +33,10 @@ import org.junit.jupiter.api.Test;
|
||||||
/**
|
/**
|
||||||
* Tests for {@link org.apache.hc.client5.http.auth.AuthScope}.
|
* Tests for {@link org.apache.hc.client5.http.auth.AuthScope}.
|
||||||
*/
|
*/
|
||||||
public class TestAuthScope {
|
class TestAuthScope {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasics() {
|
void testBasics() {
|
||||||
final AuthScope authscope = new AuthScope("http", "somehost", 80, "somerealm", "SomeScheme");
|
final AuthScope authscope = new AuthScope("http", "somehost", 80, "somerealm", "SomeScheme");
|
||||||
Assertions.assertEquals("SOMESCHEME", authscope.getSchemeName());
|
Assertions.assertEquals("SOMESCHEME", authscope.getSchemeName());
|
||||||
Assertions.assertEquals("http", authscope.getProtocol());
|
Assertions.assertEquals("http", authscope.getProtocol());
|
||||||
|
@ -47,7 +47,7 @@ public class TestAuthScope {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testByOrigin() {
|
void testByOrigin() {
|
||||||
final HttpHost host = new HttpHost("http", "somehost", 8080);
|
final HttpHost host = new HttpHost("http", "somehost", 8080);
|
||||||
final AuthScope authscope = new AuthScope(host);
|
final AuthScope authscope = new AuthScope(host);
|
||||||
Assertions.assertNull(authscope.getSchemeName());
|
Assertions.assertNull(authscope.getSchemeName());
|
||||||
|
@ -59,7 +59,7 @@ public class TestAuthScope {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMixedCaseHostname() {
|
void testMixedCaseHostname() {
|
||||||
final AuthScope authscope = new AuthScope("SomeHost", 80);
|
final AuthScope authscope = new AuthScope("SomeHost", 80);
|
||||||
Assertions.assertNull(authscope.getSchemeName());
|
Assertions.assertNull(authscope.getSchemeName());
|
||||||
Assertions.assertEquals("somehost", authscope.getHost());
|
Assertions.assertEquals("somehost", authscope.getHost());
|
||||||
|
@ -69,14 +69,14 @@ public class TestAuthScope {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testByOriginMixedCaseHostname() throws Exception {
|
void testByOriginMixedCaseHostname() {
|
||||||
final HttpHost host = new HttpHost("http", "SomeHost", 8080);
|
final HttpHost host = new HttpHost("http", "SomeHost", 8080);
|
||||||
final AuthScope authscope = new AuthScope(host);
|
final AuthScope authscope = new AuthScope(host);
|
||||||
Assertions.assertEquals("somehost", authscope.getHost());
|
Assertions.assertEquals("somehost", authscope.getHost());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicsAllOptional() {
|
void testBasicsAllOptional() {
|
||||||
final AuthScope authscope = new AuthScope(null, null, -1, null, null);
|
final AuthScope authscope = new AuthScope(null, null, -1, null, null);
|
||||||
Assertions.assertNull(authscope.getSchemeName());
|
Assertions.assertNull(authscope.getSchemeName());
|
||||||
Assertions.assertNull(authscope.getHost());
|
Assertions.assertNull(authscope.getHost());
|
||||||
|
@ -86,7 +86,7 @@ public class TestAuthScope {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testScopeMatching() {
|
void testScopeMatching() {
|
||||||
final AuthScope authscope1 = new AuthScope("http", "somehost", 80, "somerealm", "somescheme");
|
final AuthScope authscope1 = new AuthScope("http", "somehost", 80, "somerealm", "somescheme");
|
||||||
final AuthScope authscope2 = new AuthScope("http", "someotherhost", 80, "somerealm", "somescheme");
|
final AuthScope authscope2 = new AuthScope("http", "someotherhost", 80, "somerealm", "somescheme");
|
||||||
Assertions.assertTrue(authscope1.match(authscope2) < 0);
|
Assertions.assertTrue(authscope1.match(authscope2) < 0);
|
||||||
|
@ -117,7 +117,7 @@ public class TestAuthScope {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEquals() {
|
void testEquals() {
|
||||||
final AuthScope authscope1 = new AuthScope("http", "somehost", 80, "somerealm", "somescheme");
|
final AuthScope authscope1 = new AuthScope("http", "somehost", 80, "somerealm", "somescheme");
|
||||||
final AuthScope authscope2 = new AuthScope("http", "someotherhost", 80, "somerealm", "somescheme");
|
final AuthScope authscope2 = new AuthScope("http", "someotherhost", 80, "somerealm", "somescheme");
|
||||||
final AuthScope authscope3 = new AuthScope("http", "somehost", 80, "somerealm", "somescheme");
|
final AuthScope authscope3 = new AuthScope("http", "somehost", 80, "somerealm", "somescheme");
|
||||||
|
@ -137,7 +137,7 @@ public class TestAuthScope {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHash() {
|
void testHash() {
|
||||||
final AuthScope authscope1 = new AuthScope("http", "somehost", 80, "somerealm", "somescheme");
|
final AuthScope authscope1 = new AuthScope("http", "somehost", 80, "somerealm", "somescheme");
|
||||||
final AuthScope authscope2 = new AuthScope("http", "someotherhost", 80, "somerealm", "somescheme");
|
final AuthScope authscope2 = new AuthScope("http", "someotherhost", 80, "somerealm", "somescheme");
|
||||||
final AuthScope authscope3 = new AuthScope("http", "somehost", 80, "somerealm", "somescheme");
|
final AuthScope authscope3 = new AuthScope("http", "somehost", 80, "somerealm", "somescheme");
|
||||||
|
|
|
@ -36,10 +36,10 @@ import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public class TestCredentials {
|
class TestCredentials {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUsernamePasswordCredentialsBasics() {
|
void testUsernamePasswordCredentialsBasics() {
|
||||||
final UsernamePasswordCredentials creds1 = new UsernamePasswordCredentials(
|
final UsernamePasswordCredentials creds1 = new UsernamePasswordCredentials(
|
||||||
"name","pwd".toCharArray());
|
"name","pwd".toCharArray());
|
||||||
Assertions.assertEquals("name", creds1.getUserName());
|
Assertions.assertEquals("name", creds1.getUserName());
|
||||||
|
@ -57,7 +57,7 @@ public class TestCredentials {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNTCredentialsBasics() {
|
void testNTCredentialsBasics() {
|
||||||
final NTCredentials creds1 = new NTCredentials(
|
final NTCredentials creds1 = new NTCredentials(
|
||||||
"name","pwd".toCharArray(), "localhost", "domain");
|
"name","pwd".toCharArray(), "localhost", "domain");
|
||||||
Assertions.assertEquals("name", creds1.getUserName());
|
Assertions.assertEquals("name", creds1.getUserName());
|
||||||
|
@ -77,7 +77,7 @@ public class TestCredentials {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUsernamePasswordCredentialsHashCode() {
|
void testUsernamePasswordCredentialsHashCode() {
|
||||||
final UsernamePasswordCredentials creds1 = new UsernamePasswordCredentials(
|
final UsernamePasswordCredentials creds1 = new UsernamePasswordCredentials(
|
||||||
"name","pwd".toCharArray());
|
"name","pwd".toCharArray());
|
||||||
final UsernamePasswordCredentials creds2 = new UsernamePasswordCredentials(
|
final UsernamePasswordCredentials creds2 = new UsernamePasswordCredentials(
|
||||||
|
@ -91,7 +91,7 @@ public class TestCredentials {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUsernamePasswordCredentialsEquals() {
|
void testUsernamePasswordCredentialsEquals() {
|
||||||
final UsernamePasswordCredentials creds1 = new UsernamePasswordCredentials(
|
final UsernamePasswordCredentials creds1 = new UsernamePasswordCredentials(
|
||||||
"name","pwd".toCharArray());
|
"name","pwd".toCharArray());
|
||||||
final UsernamePasswordCredentials creds2 = new UsernamePasswordCredentials(
|
final UsernamePasswordCredentials creds2 = new UsernamePasswordCredentials(
|
||||||
|
@ -105,13 +105,13 @@ public class TestCredentials {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void tesBearerTokenBasics() {
|
void tesBearerTokenBasics() {
|
||||||
final BearerToken creds1 = new BearerToken("token of some sort");
|
final BearerToken creds1 = new BearerToken("token of some sort");
|
||||||
Assertions.assertEquals("token of some sort", creds1.getToken());
|
Assertions.assertEquals("token of some sort", creds1.getToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBearerTokenHashCode() {
|
void testBearerTokenHashCode() {
|
||||||
final BearerToken creds1 = new BearerToken("token of some sort");
|
final BearerToken creds1 = new BearerToken("token of some sort");
|
||||||
final BearerToken creds2 = new BearerToken("another token of some sort");
|
final BearerToken creds2 = new BearerToken("another token of some sort");
|
||||||
final BearerToken creds3 = new BearerToken("token of some sort");
|
final BearerToken creds3 = new BearerToken("token of some sort");
|
||||||
|
@ -122,7 +122,7 @@ public class TestCredentials {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBearerTokenEquals() {
|
void testBearerTokenEquals() {
|
||||||
final BearerToken creds1 = new BearerToken("token of some sort");
|
final BearerToken creds1 = new BearerToken("token of some sort");
|
||||||
final BearerToken creds2 = new BearerToken("another token of some sort");
|
final BearerToken creds2 = new BearerToken("another token of some sort");
|
||||||
final BearerToken creds3 = new BearerToken("token of some sort");
|
final BearerToken creds3 = new BearerToken("token of some sort");
|
||||||
|
@ -133,7 +133,7 @@ public class TestCredentials {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNTCredentialsHashCode() {
|
void testNTCredentialsHashCode() {
|
||||||
final NTCredentials creds1 = new NTCredentials(
|
final NTCredentials creds1 = new NTCredentials(
|
||||||
"name","pwd".toCharArray(), "somehost", "domain");
|
"name","pwd".toCharArray(), "somehost", "domain");
|
||||||
final NTCredentials creds2 = new NTCredentials(
|
final NTCredentials creds2 = new NTCredentials(
|
||||||
|
@ -165,7 +165,7 @@ public class TestCredentials {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNTCredentialsEquals() {
|
void testNTCredentialsEquals() {
|
||||||
final NTCredentials creds1 = new NTCredentials(
|
final NTCredentials creds1 = new NTCredentials(
|
||||||
"name","pwd".toCharArray(), "somehost", "domain");
|
"name","pwd".toCharArray(), "somehost", "domain");
|
||||||
final NTCredentials creds2 = new NTCredentials(
|
final NTCredentials creds2 = new NTCredentials(
|
||||||
|
@ -198,7 +198,7 @@ public class TestCredentials {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUsernamePasswordCredentialsSerialization() throws Exception {
|
void testUsernamePasswordCredentialsSerialization() throws Exception {
|
||||||
final UsernamePasswordCredentials orig = new UsernamePasswordCredentials("name","pwd".toCharArray());
|
final UsernamePasswordCredentials orig = new UsernamePasswordCredentials("name","pwd".toCharArray());
|
||||||
final ByteArrayOutputStream outbuffer = new ByteArrayOutputStream();
|
final ByteArrayOutputStream outbuffer = new ByteArrayOutputStream();
|
||||||
final ObjectOutputStream outStream = new ObjectOutputStream(outbuffer);
|
final ObjectOutputStream outStream = new ObjectOutputStream(outbuffer);
|
||||||
|
@ -212,7 +212,7 @@ public class TestCredentials {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNTCredentialsSerialization() throws Exception {
|
void testNTCredentialsSerialization() throws Exception {
|
||||||
final NTCredentials orig = new NTCredentials("name","pwd".toCharArray(), "somehost", "domain");
|
final NTCredentials orig = new NTCredentials("name","pwd".toCharArray(), "somehost", "domain");
|
||||||
final ByteArrayOutputStream outbuffer = new ByteArrayOutputStream();
|
final ByteArrayOutputStream outbuffer = new ByteArrayOutputStream();
|
||||||
final ObjectOutputStream outStream = new ObjectOutputStream(outbuffer);
|
final ObjectOutputStream outStream = new ObjectOutputStream(outbuffer);
|
||||||
|
|
|
@ -33,10 +33,10 @@ import org.apache.hc.core5.http.message.BasicHttpResponse;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestHttpOptions {
|
class TestHttpOptions {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultipleAllows() {
|
void testMultipleAllows() {
|
||||||
final BasicHttpResponse resp = new BasicHttpResponse(200, "test reason");
|
final BasicHttpResponse resp = new BasicHttpResponse(200, "test reason");
|
||||||
resp.addHeader("Allow", "POST");
|
resp.addHeader("Allow", "POST");
|
||||||
resp.addHeader("Allow", "GET");
|
resp.addHeader("Allow", "GET");
|
||||||
|
|
|
@ -47,54 +47,54 @@ import org.apache.hc.core5.http.message.BasicHttpResponse;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestHttpRequestBase {
|
class TestHttpRequestBase {
|
||||||
|
|
||||||
private static final String HOT_URL = "http://host/path";
|
private static final String HOT_URL = "http://host/path";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicGetMethodProperties() throws Exception {
|
void testBasicGetMethodProperties() throws Exception {
|
||||||
final HttpGet httpget = new HttpGet(HOT_URL);
|
final HttpGet httpget = new HttpGet(HOT_URL);
|
||||||
Assertions.assertEquals("GET", httpget.getMethod());
|
Assertions.assertEquals("GET", httpget.getMethod());
|
||||||
Assertions.assertEquals(new URI(HOT_URL), httpget.getUri());
|
Assertions.assertEquals(new URI(HOT_URL), httpget.getUri());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicHttpPostMethodProperties() throws Exception {
|
void testBasicHttpPostMethodProperties() throws Exception {
|
||||||
final HttpPost HttpPost = new HttpPost(HOT_URL);
|
final HttpPost HttpPost = new HttpPost(HOT_URL);
|
||||||
Assertions.assertEquals("POST", HttpPost.getMethod());
|
Assertions.assertEquals("POST", HttpPost.getMethod());
|
||||||
Assertions.assertEquals(new URI(HOT_URL), HttpPost.getUri());
|
Assertions.assertEquals(new URI(HOT_URL), HttpPost.getUri());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicHttpHeadMethodProperties() throws Exception {
|
void testBasicHttpHeadMethodProperties() throws Exception {
|
||||||
final HttpHead httpHead = new HttpHead(HOT_URL);
|
final HttpHead httpHead = new HttpHead(HOT_URL);
|
||||||
Assertions.assertEquals("HEAD", httpHead.getMethod());
|
Assertions.assertEquals("HEAD", httpHead.getMethod());
|
||||||
Assertions.assertEquals(new URI(HOT_URL), httpHead.getUri());
|
Assertions.assertEquals(new URI(HOT_URL), httpHead.getUri());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicHttpOptionMethodProperties() throws Exception {
|
void testBasicHttpOptionMethodProperties() throws Exception {
|
||||||
final HttpOptions httpOption = new HttpOptions(HOT_URL);
|
final HttpOptions httpOption = new HttpOptions(HOT_URL);
|
||||||
Assertions.assertEquals("OPTIONS", httpOption.getMethod());
|
Assertions.assertEquals("OPTIONS", httpOption.getMethod());
|
||||||
Assertions.assertEquals(new URI(HOT_URL), httpOption.getUri());
|
Assertions.assertEquals(new URI(HOT_URL), httpOption.getUri());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicHttpPatchMethodProperties() throws Exception {
|
void testBasicHttpPatchMethodProperties() throws Exception {
|
||||||
final HttpPatch httpPatch = new HttpPatch(HOT_URL);
|
final HttpPatch httpPatch = new HttpPatch(HOT_URL);
|
||||||
Assertions.assertEquals("PATCH", httpPatch.getMethod());
|
Assertions.assertEquals("PATCH", httpPatch.getMethod());
|
||||||
Assertions.assertEquals(new URI(HOT_URL), httpPatch.getUri());
|
Assertions.assertEquals(new URI(HOT_URL), httpPatch.getUri());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicHttpPutMethodProperties() throws Exception {
|
void testBasicHttpPutMethodProperties() throws Exception {
|
||||||
final HttpPut httpPut = new HttpPut(HOT_URL);
|
final HttpPut httpPut = new HttpPut(HOT_URL);
|
||||||
Assertions.assertEquals("PUT", httpPut.getMethod());
|
Assertions.assertEquals("PUT", httpPut.getMethod());
|
||||||
Assertions.assertEquals(new URI(HOT_URL), httpPut.getUri());
|
Assertions.assertEquals(new URI(HOT_URL), httpPut.getUri());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicHttpTraceMethodProperties() throws Exception {
|
void testBasicHttpTraceMethodProperties() throws Exception {
|
||||||
final HttpTrace httpTrace = new HttpTrace(HOT_URL);
|
final HttpTrace httpTrace = new HttpTrace(HOT_URL);
|
||||||
Assertions.assertEquals("TRACE", httpTrace.getMethod());
|
Assertions.assertEquals("TRACE", httpTrace.getMethod());
|
||||||
Assertions.assertEquals(new URI(HOT_URL), httpTrace.getUri());
|
Assertions.assertEquals(new URI(HOT_URL), httpTrace.getUri());
|
||||||
|
@ -102,7 +102,7 @@ public class TestHttpRequestBase {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicHttpDeleteMethodProperties() throws Exception {
|
void testBasicHttpDeleteMethodProperties() throws Exception {
|
||||||
final HttpDelete httpDelete = new HttpDelete(HOT_URL);
|
final HttpDelete httpDelete = new HttpDelete(HOT_URL);
|
||||||
Assertions.assertEquals("DELETE", httpDelete.getMethod());
|
Assertions.assertEquals("DELETE", httpDelete.getMethod());
|
||||||
Assertions.assertEquals(new URI(HOT_URL), httpDelete.getUri());
|
Assertions.assertEquals(new URI(HOT_URL), httpDelete.getUri());
|
||||||
|
@ -110,64 +110,64 @@ public class TestHttpRequestBase {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetMethodEmptyURI() throws Exception {
|
void testGetMethodEmptyURI() throws Exception {
|
||||||
final HttpGet httpget = new HttpGet("");
|
final HttpGet httpget = new HttpGet("");
|
||||||
Assertions.assertEquals(new URI("/"), httpget.getUri());
|
Assertions.assertEquals(new URI("/"), httpget.getUri());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPostMethodEmptyURI() throws Exception {
|
void testPostMethodEmptyURI() throws Exception {
|
||||||
final HttpPost HttpPost = new HttpPost("");
|
final HttpPost HttpPost = new HttpPost("");
|
||||||
Assertions.assertEquals(new URI("/"), HttpPost.getUri());
|
Assertions.assertEquals(new URI("/"), HttpPost.getUri());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHeadMethodEmptyURI() throws Exception {
|
void testHeadMethodEmptyURI() throws Exception {
|
||||||
final HttpHead httpHead = new HttpHead("");
|
final HttpHead httpHead = new HttpHead("");
|
||||||
Assertions.assertEquals(new URI("/"), httpHead.getUri());
|
Assertions.assertEquals(new URI("/"), httpHead.getUri());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOptionMethodEmptyURI() throws Exception {
|
void testOptionMethodEmptyURI() throws Exception {
|
||||||
final HttpOptions httpOption = new HttpOptions("");
|
final HttpOptions httpOption = new HttpOptions("");
|
||||||
Assertions.assertEquals(new URI("/"), httpOption.getUri());
|
Assertions.assertEquals(new URI("/"), httpOption.getUri());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPatchMethodEmptyURI() throws Exception {
|
void testPatchMethodEmptyURI() throws Exception {
|
||||||
final HttpPatch httpPatch = new HttpPatch("");
|
final HttpPatch httpPatch = new HttpPatch("");
|
||||||
Assertions.assertEquals(new URI("/"), httpPatch.getUri());
|
Assertions.assertEquals(new URI("/"), httpPatch.getUri());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPutMethodEmptyURI() throws Exception {
|
void testPutMethodEmptyURI() throws Exception {
|
||||||
final HttpPut httpPut = new HttpPut("");
|
final HttpPut httpPut = new HttpPut("");
|
||||||
Assertions.assertEquals(new URI("/"), httpPut.getUri());
|
Assertions.assertEquals(new URI("/"), httpPut.getUri());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTraceMethodEmptyURI() throws Exception {
|
void testTraceMethodEmptyURI() throws Exception {
|
||||||
final HttpTrace httpTrace = new HttpTrace("");
|
final HttpTrace httpTrace = new HttpTrace("");
|
||||||
Assertions.assertEquals(new URI("/"), httpTrace.getUri());
|
Assertions.assertEquals(new URI("/"), httpTrace.getUri());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteMethodEmptyURI() throws Exception {
|
void testDeleteMethodEmptyURI() throws Exception {
|
||||||
final HttpDelete httpDelete = new HttpDelete("");
|
final HttpDelete httpDelete = new HttpDelete("");
|
||||||
Assertions.assertEquals(new URI("/"), httpDelete.getUri());
|
Assertions.assertEquals(new URI("/"), httpDelete.getUri());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTraceMethodSetEntity() {
|
void testTraceMethodSetEntity() {
|
||||||
final HttpTrace httpTrace = new HttpTrace(HOT_URL);
|
final HttpTrace httpTrace = new HttpTrace(HOT_URL);
|
||||||
final HttpEntity entity = EntityBuilder.create().setText("stuff").build();
|
final HttpEntity entity = EntityBuilder.create().setText("stuff").build();
|
||||||
assertThrows(IllegalStateException.class, () -> httpTrace.setEntity(entity));
|
assertThrows(IllegalStateException.class, () -> httpTrace.setEntity(entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOptionMethodGetAllowedMethods() {
|
void testOptionMethodGetAllowedMethods() {
|
||||||
final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
|
final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
|
||||||
response.addHeader("Allow", "GET, HEAD");
|
response.addHeader("Allow", "GET, HEAD");
|
||||||
response.addHeader("Allow", "DELETE");
|
response.addHeader("Allow", "DELETE");
|
||||||
|
|
|
@ -30,10 +30,10 @@ package org.apache.hc.client5.http.classic.methods;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestHttpTrace {
|
class TestHttpTrace {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHttpTraceSetEntity() {
|
void testHttpTraceSetEntity() {
|
||||||
final HttpTrace httpTrace = new HttpTrace("/path");
|
final HttpTrace httpTrace = new HttpTrace("/path");
|
||||||
Assertions.assertThrows(IllegalStateException.class, () ->
|
Assertions.assertThrows(IllegalStateException.class, () ->
|
||||||
httpTrace.setEntity(null));
|
httpTrace.setEntity(null));
|
||||||
|
|
|
@ -37,16 +37,16 @@ import org.apache.hc.core5.util.Timeout;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestRequestConfig {
|
class TestRequestConfig {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasics() {
|
void testBasics() {
|
||||||
final RequestConfig config = RequestConfig.custom().build();
|
final RequestConfig config = RequestConfig.custom().build();
|
||||||
config.toString();
|
config.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDefaults() {
|
void testDefaults() {
|
||||||
final RequestConfig config = RequestConfig.DEFAULT;
|
final RequestConfig config = RequestConfig.DEFAULT;
|
||||||
Assertions.assertEquals(Timeout.ofMinutes(3), config.getConnectionRequestTimeout());
|
Assertions.assertEquals(Timeout.ofMinutes(3), config.getConnectionRequestTimeout());
|
||||||
Assertions.assertFalse(config.isExpectContinueEnabled());
|
Assertions.assertFalse(config.isExpectContinueEnabled());
|
||||||
|
@ -61,7 +61,7 @@ public class TestRequestConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildAndCopy() throws Exception {
|
void testBuildAndCopy() {
|
||||||
final RequestConfig config0 = RequestConfig.custom()
|
final RequestConfig config0 = RequestConfig.custom()
|
||||||
.setConnectionRequestTimeout(44, TimeUnit.MILLISECONDS)
|
.setConnectionRequestTimeout(44, TimeUnit.MILLISECONDS)
|
||||||
.setExpectContinueEnabled(true)
|
.setExpectContinueEnabled(true)
|
||||||
|
|
|
@ -33,10 +33,10 @@ import org.junit.jupiter.api.Test;
|
||||||
/**
|
/**
|
||||||
* Test cases for {@link CookieOrigin}.
|
* Test cases for {@link CookieOrigin}.
|
||||||
*/
|
*/
|
||||||
public class TestCookieOrigin {
|
class TestCookieOrigin {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructor() {
|
void testConstructor() {
|
||||||
final CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "/", false);
|
final CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "/", false);
|
||||||
Assertions.assertEquals("www.apache.org", origin.getHost());
|
Assertions.assertEquals("www.apache.org", origin.getHost());
|
||||||
Assertions.assertEquals(80, origin.getPort());
|
Assertions.assertEquals(80, origin.getPort());
|
||||||
|
@ -45,31 +45,31 @@ public class TestCookieOrigin {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNullHost() {
|
void testNullHost() {
|
||||||
Assertions.assertThrows(NullPointerException.class, () ->
|
Assertions.assertThrows(NullPointerException.class, () ->
|
||||||
new CookieOrigin(null, 80, "/", false));
|
new CookieOrigin(null, 80, "/", false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyHost() {
|
void testEmptyHost() {
|
||||||
Assertions.assertThrows(IllegalArgumentException.class, () ->
|
Assertions.assertThrows(IllegalArgumentException.class, () ->
|
||||||
new CookieOrigin(" ", 80, "/", false));
|
new CookieOrigin(" ", 80, "/", false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNegativePort() {
|
void testNegativePort() {
|
||||||
Assertions.assertThrows(IllegalArgumentException.class, () ->
|
Assertions.assertThrows(IllegalArgumentException.class, () ->
|
||||||
new CookieOrigin("www.apache.org", -80, "/", false));
|
new CookieOrigin("www.apache.org", -80, "/", false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNullPath() {
|
void testNullPath() {
|
||||||
Assertions.assertThrows(NullPointerException.class, () ->
|
Assertions.assertThrows(NullPointerException.class, () ->
|
||||||
new CookieOrigin("www.apache.org", 80, null, false));
|
new CookieOrigin("www.apache.org", 80, null, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyPath() {
|
void testEmptyPath() {
|
||||||
final CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "", false);
|
final CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "", false);
|
||||||
Assertions.assertEquals("www.apache.org", origin.getHost());
|
Assertions.assertEquals("www.apache.org", origin.getHost());
|
||||||
Assertions.assertEquals(80, origin.getPort());
|
Assertions.assertEquals(80, origin.getPort());
|
||||||
|
|
|
@ -36,10 +36,10 @@ import org.junit.jupiter.api.Test;
|
||||||
/**
|
/**
|
||||||
* Test cases for {@link CookiePathComparator}.
|
* Test cases for {@link CookiePathComparator}.
|
||||||
*/
|
*/
|
||||||
public class TestCookiePathComparator {
|
class TestCookiePathComparator {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnequality1() {
|
void testUnequality1() {
|
||||||
final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
|
final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
|
||||||
cookie1.setPath("/a/b/");
|
cookie1.setPath("/a/b/");
|
||||||
final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
|
final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
|
||||||
|
@ -50,7 +50,7 @@ public class TestCookiePathComparator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnequality2() {
|
void testUnequality2() {
|
||||||
final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
|
final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
|
||||||
cookie1.setPath("/a/b");
|
cookie1.setPath("/a/b");
|
||||||
final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
|
final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
|
||||||
|
@ -61,7 +61,7 @@ public class TestCookiePathComparator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEquality1() {
|
void testEquality1() {
|
||||||
final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
|
final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
|
||||||
cookie1.setPath("/a");
|
cookie1.setPath("/a");
|
||||||
final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
|
final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
|
||||||
|
@ -72,7 +72,7 @@ public class TestCookiePathComparator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEquality2() {
|
void testEquality2() {
|
||||||
final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
|
final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
|
||||||
cookie1.setPath("/a/");
|
cookie1.setPath("/a/");
|
||||||
final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
|
final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
|
||||||
|
@ -83,7 +83,7 @@ public class TestCookiePathComparator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEquality3() {
|
void testEquality3() {
|
||||||
final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
|
final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
|
||||||
cookie1.setPath(null);
|
cookie1.setPath(null);
|
||||||
final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
|
final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
|
||||||
|
@ -94,7 +94,7 @@ public class TestCookiePathComparator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEquality4() {
|
void testEquality4() {
|
||||||
final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
|
final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
|
||||||
cookie1.setPath("/this");
|
cookie1.setPath("/this");
|
||||||
final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
|
final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
|
||||||
|
|
|
@ -38,17 +38,17 @@ import org.junit.jupiter.api.Test;
|
||||||
/**
|
/**
|
||||||
* Test cases for {@link org.apache.hc.client5.http.cookie.CookiePriorityComparator}.
|
* Test cases for {@link org.apache.hc.client5.http.cookie.CookiePriorityComparator}.
|
||||||
*/
|
*/
|
||||||
public class TestCookiePriorityComparator {
|
class TestCookiePriorityComparator {
|
||||||
|
|
||||||
private Comparator<Cookie> comparator;
|
private Comparator<Cookie> comparator;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
void setup() {
|
||||||
comparator = CookiePriorityComparator.INSTANCE;
|
comparator = CookiePriorityComparator.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnequality() {
|
void testUnequality() {
|
||||||
final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
|
final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
|
||||||
cookie1.setPath("/a/b/");
|
cookie1.setPath("/a/b/");
|
||||||
final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
|
final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
|
||||||
|
@ -58,7 +58,7 @@ public class TestCookiePriorityComparator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEquality() {
|
void testEquality() {
|
||||||
final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
|
final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
|
||||||
cookie1.setPath("/a");
|
cookie1.setPath("/a");
|
||||||
final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
|
final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
|
||||||
|
@ -68,7 +68,7 @@ public class TestCookiePriorityComparator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnequalityTrailingSlash() {
|
void testUnequalityTrailingSlash() {
|
||||||
final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
|
final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
|
||||||
cookie1.setPath("/a/");
|
cookie1.setPath("/a/");
|
||||||
final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
|
final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
|
||||||
|
@ -78,7 +78,7 @@ public class TestCookiePriorityComparator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEqualityNullPath() {
|
void testEqualityNullPath() {
|
||||||
final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
|
final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
|
||||||
cookie1.setPath(null);
|
cookie1.setPath(null);
|
||||||
final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
|
final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
|
||||||
|
@ -88,7 +88,7 @@ public class TestCookiePriorityComparator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEqualitySameLength() {
|
void testEqualitySameLength() {
|
||||||
final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
|
final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
|
||||||
cookie1.setPath("/this");
|
cookie1.setPath("/this");
|
||||||
final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
|
final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
|
||||||
|
@ -98,7 +98,7 @@ public class TestCookiePriorityComparator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnequalityCreationDate() {
|
void testUnequalityCreationDate() {
|
||||||
final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
|
final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
|
||||||
cookie1.setPath("/blah");
|
cookie1.setPath("/blah");
|
||||||
cookie1.setCreationDate(Instant.now().minusMillis(200000));
|
cookie1.setCreationDate(Instant.now().minusMillis(200000));
|
||||||
|
|
|
@ -33,7 +33,7 @@ import org.apache.hc.core5.http.io.entity.EntityUtils;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestBrotli {
|
class TestBrotli {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Brotli decompression test implemented by request with specified response encoding br
|
* Brotli decompression test implemented by request with specified response encoding br
|
||||||
|
@ -41,7 +41,7 @@ public class TestBrotli {
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testDecompressionWithBrotli() throws Exception {
|
void testDecompressionWithBrotli() throws Exception {
|
||||||
|
|
||||||
final byte[] bytes = new byte[] {33, 44, 0, 4, 116, 101, 115, 116, 32, 98, 114, 111, 116, 108, 105, 10, 3};
|
final byte[] bytes = new byte[] {33, 44, 0, 4, 116, 101, 115, 116, 32, 98, 114, 111, 116, 108, 105, 10, 3};
|
||||||
|
|
||||||
|
|
|
@ -43,10 +43,10 @@ import org.apache.hc.core5.http.io.entity.StringEntity;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestDecompressingEntity {
|
class TestDecompressingEntity {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNonStreaming() throws Exception {
|
void testNonStreaming() throws Exception {
|
||||||
final CRC32 crc32 = new CRC32();
|
final CRC32 crc32 = new CRC32();
|
||||||
final StringEntity wrapped = new StringEntity("1234567890", StandardCharsets.US_ASCII);
|
final StringEntity wrapped = new StringEntity("1234567890", StandardCharsets.US_ASCII);
|
||||||
final ChecksumEntity entity = new ChecksumEntity(wrapped, crc32);
|
final ChecksumEntity entity = new ChecksumEntity(wrapped, crc32);
|
||||||
|
@ -60,7 +60,7 @@ public class TestDecompressingEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStreaming() throws Exception {
|
void testStreaming() throws Exception {
|
||||||
final CRC32 crc32 = new CRC32();
|
final CRC32 crc32 = new CRC32();
|
||||||
final ByteArrayInputStream in = new ByteArrayInputStream("1234567890".getBytes(StandardCharsets.US_ASCII));
|
final ByteArrayInputStream in = new ByteArrayInputStream("1234567890".getBytes(StandardCharsets.US_ASCII));
|
||||||
final InputStreamEntity wrapped = new InputStreamEntity(in, -1, ContentType.DEFAULT_TEXT);
|
final InputStreamEntity wrapped = new InputStreamEntity(in, -1, ContentType.DEFAULT_TEXT);
|
||||||
|
@ -77,7 +77,7 @@ public class TestDecompressingEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWriteToStream() throws Exception {
|
void testWriteToStream() throws Exception {
|
||||||
final CRC32 crc32 = new CRC32();
|
final CRC32 crc32 = new CRC32();
|
||||||
final StringEntity wrapped = new StringEntity("1234567890", StandardCharsets.US_ASCII);
|
final StringEntity wrapped = new StringEntity("1234567890", StandardCharsets.US_ASCII);
|
||||||
try (final ChecksumEntity entity = new ChecksumEntity(wrapped, crc32)) {
|
try (final ChecksumEntity entity = new ChecksumEntity(wrapped, crc32)) {
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue