public class AccessPointTest
extends junit.framework.TestCase
AccessPoint.
TODO: this unit test is too complex. it is because AccessPoint class has too
much responsibility and many execution paths. some good refactoring of
AccessPoint class would help.| Modifier and Type | Class and Description |
|---|---|
static class |
AccessPointTest.CaptureSearchMatcher |
static class |
AccessPointTest.CaptureSearchResultMatcher
test CaptureSearchResult equality by file and offset.
|
| Modifier and Type | Field and Description |
|---|---|
static String |
STATIC_PREFIX |
static String |
WEB_PREFIX |
| Constructor and Description |
|---|
AccessPointTest() |
| Modifier and Type | Method and Description |
|---|---|
static Resource |
createSelfRedirectResource(String url,
String timestamp) |
static Resource |
createTest502Resource() |
static Resource |
createTestHtmlResource(String timestamp,
byte[] payloadBytes) |
static Resource |
createTestHtmlResource(String uri,
String timestamp,
byte[] payloadBytes) |
static Resource |
createTestHtmlResource(String uri,
String timestamp,
byte[] payloadBytes,
boolean compressed) |
static Resource |
createTestRevisitResource(String timestamp,
int len,
boolean withHeader)
Create a test revisit record referring unknown capture of content-length
len. |
static Resource |
createTestRevisitResource(String timestamp,
Resource revisited,
boolean withHeader)
Create a test revisit record referring Resource
revisited. |
static WaybackRequest |
eqCaptureSearchRequest(String url,
String replayTimestamp) |
static CaptureSearchResult |
eqCaptureSearchResult(CaptureSearchResult expected) |
protected void |
expectRedirect(String expectedRedirectURI)
Setup expectation that
handleReplay redirects to
expectedRedirectURI. |
protected void |
expectRendering(CaptureSearchResult capture,
Resource headersResource,
Resource payloadResource,
CaptureSearchResults results)
Setup expectation that
capture is rendered. |
protected void |
expectUrlIndexQuery()
setup expected call to
ResourceIndex.query(WaybackRequest),
returning empty UrlSearchResults. |
void |
setCaptureQueryRequest(String requestUrl,
String replayTimestamp)
create new WaybackRequest set up as capture query request for URL
requestUrl, at time . |
void |
setReplayRequest(String requestUrl,
String replayTimestamp)
create new WaybackRequest set up as replay request for
requestUrl
at replayTimestamp. created object is set to #wbRequest. |
protected void |
setUp() |
protected CaptureSearchResults |
setupCaptures(int closestIndex,
Resource... resources)
setup mocks with
resources. |
static CaptureSearchResults |
setupCaptures(ResourceIndex resourceIndex,
ResourceStore resourceStore,
int closestIndex,
Resource... resources)
given a sequence of
WarcResources,
build CaptureSearchResults, filled with CaptureSearchResult
instances, which have auto-generated unique filename and offset of 0. |
protected void |
setupRequestStub(String contextPath,
String uri,
String contextPathPrefix)
setup HttpServletRequest stubs
|
void |
setUrlQueryRequest(String requestUrl,
String replayTimestamp)
create new WaybackRequest set up as URL query request for URL
requestUrl at time replayTimestamp. created object is set
to wbRequest. |
void |
testBounceToReplayPrefix()
if bounceToReplayPrefix is true, replay request is redirected to other
access point.
|
void |
testDispatchLocal()
static AccessPoint - configured with
accessPointPath=
${wayback.staticPrefix}
serveStatic=true
bounceToReplayPrefix=true
bounceToQueryPrefix=true
when RequestParser.parse(HttpServletRequest, AccessPoint) returns
null, request is forwarded to dispatchLocal() for rendering static
resources. |
void |
testHandleReplay_noMultipleErrors()
Test of internal behavior.
|
void |
testHandleRequest_CaptureSearchResults() |
void |
testHandleRequest_MissingRevisitPayload()
handleReplay() is supposed to throw
ResourceNotAvailableException when it cannot find a replay-able
capture for a request. |
void |
testHandleRequest_queryCollapseTimeSpecified() |
void |
testHandleRequest_queryCollapseTimeUnspecified() |
void |
testHandleRequest_Replay_1()
test basic behavior 1.
|
void |
testHandleRequest_Replay_2()
basic replay test part 2. there's a capture whose capture date matches
the request.
|
void |
testHandleRequest_Replay_Embedded()
if closest is not HTTP-success AND replaying embedded context (CSS,
JavaScript, images, etc.), use next closest with successful response, or
for lower priority, a redirect, instead. unless such capture is of the
same timestamp as the replay request, redirect to the capture found.
|
void |
testHandleRequest_Replay_OldARCRevisit()
old-style ARC revisit (no mimetype, filename is '-')
|
void |
testHandleRequest_Replay_OldWARCRevisit()
old-style WARC revisit (no HTTP status line and header, Content-Length in
WARC header is zero). it shall replay HTTP status line, headers and
content from previous matching capture.
|
void |
testHandleRequest_Replay_Revisit()
test of revisit. closest capture is a revisit.
|
void |
testHandleRequest_UrlSearchResults() |
void |
testHandlerRequest_queryCollapseTimeForReplayQuery() |
void |
testMemento_dispatchLocal()
test for local static resource when enableMemento=true. expectations:
do-not-negotiate Link header is set.
|
void |
testMemento_replay_exactCapture()
test of Memento-furnished response to URL-M (Memento).
|
void |
testMemento_replay_nearbyCapture()
Test of Memento-furnished response to replay request for non-archived
timestamp.
|
void |
testMementoTimegate()
Test of Memento-furnished response to Timegate (URI-G).
|
void |
testMementoTimemap()
test of Memento Timemap request.
|
protected static boolean |
validTimestamp(String ts)
checks if
ts has expected format (YYYYmmddHHMMSS) |
countTestCases, createResult, getName, run, run, runBare, runTest, setName, tearDown, toStringassertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, failpublic static final String WEB_PREFIX
public static final String STATIC_PREFIX
protected void setupRequestStub(String contextPath, String uri, String contextPathPrefix)
contextPath - servlet context path. typically "/"uri - servlet URI. typically "/"contextPathPrefix - protected void setUp()
throws Exception
setUp in class junit.framework.TestCaseExceptionpublic static Resource createTestHtmlResource(String uri, String timestamp, byte[] payloadBytes) throws IOException
IOExceptionpublic static Resource createTestHtmlResource(String uri, String timestamp, byte[] payloadBytes, boolean compressed) throws IOException
IOExceptionpublic static Resource createTestHtmlResource(String timestamp, byte[] payloadBytes) throws IOException
IOExceptionpublic static Resource createTestRevisitResource(String timestamp, int len, boolean withHeader) throws IOException
len. This is meant for pathological case. Use
createTestRevisitResource(String, int, boolean) for regular case.timestamp - 14-digit timestamp of capturelen - original content-lengthwithHeader - false for omitting HTTP header (simulates old
revisit record).IOException - for unexpected I/O failure while buiding payloadpublic static Resource createTestRevisitResource(String timestamp, Resource revisited, boolean withHeader) throws IOException
revisited.timestamp - CDX-style 14digit timestamprevisited - Capture being revisited (must be a WarcResource
or ClassCastException will be the result)withHeader - true unless you want to emulate old implementation
where revisit record had no HTTP headers.IOException - for unexpected I/O error building payloadprotected static boolean validTimestamp(String ts)
ts has expected format (YYYYmmddHHMMSS)ts - timestamp string to checkprotected CaptureSearchResults setupCaptures(int closestIndex, Resource... resources) throws Exception
resources.
setupCaptures(ResourceIndex, ResourceStore, int, Resource...)replay so as to return closest from getClosest.resourceIndex so as to return results from query(wbRequest)
Note: wbRequest must be set up before calling this method, or
ResourceIndex will not return expected search result set.
closestIndex - zero-based index into resourcesresources - resourcesExceptionpublic static CaptureSearchResults setupCaptures(ResourceIndex resourceIndex, ResourceStore resourceStore, int closestIndex, Resource... resources) throws Exception
WarcResources,
AccessPointTest.CaptureSearchResultMatcher).closestIndex >= 0, set corresponding
CaptureSearchResult's closest flag.
It's left as caller's responsibility to setup ResourceIndex.query(WaybackRequest) mock
to return CaptureSearchResults returned by this method.
resourceIndex - ResourceIndex mockresourceStore - ResourceStore mock, can be nullclosestIndex - 0-based index of resource to be marked as
closestresources - sequence of WarcResourcesExceptionpublic void setReplayRequest(String requestUrl, String replayTimestamp)
requestUrl
at replayTimestamp. created object is set to #wbRequest.wbRequest - requestUrl - replayTimestamp - protected void expectRendering(CaptureSearchResult capture, Resource headersResource, Resource payloadResource, CaptureSearchResults results) throws javax.servlet.ServletException, IOException, WaybackException
capture is rendered.
capture - CaptureSearchResult to be renderedheadersResource - Resource from which HTTP headers are read
(revisit)payloadResource - Resource from which HTTP payload is read
(revisited)results - capture search results from which capture is
pickedWaybackExceptionIOExceptionjavax.servlet.ServletExceptionprotected void expectRedirect(String expectedRedirectURI)
handleReplay redirects to
expectedRedirectURI.expectedRedirectURI - protected void expectUrlIndexQuery()
throws Exception
ResourceIndex.query(WaybackRequest),
returning empty UrlSearchResults.
This is sufficient for most cases, as AccessPoint is not concerned with UrlSearchResult, but simply passes it to query renderer.
Note: set up wbRequest before calling this method.
Exception - declared, but will never be thrownpublic void testHandleRequest_Replay_1()
throws Exception
testBounceToReplayPrefix()Exceptionpublic void testHandleRequest_Replay_2()
throws Exception
Exceptionpublic static CaptureSearchResult eqCaptureSearchResult(CaptureSearchResult expected)
public static WaybackRequest eqCaptureSearchRequest(String url, String replayTimestamp)
public void testHandleRequest_Replay_Revisit()
throws Exception
Exceptionpublic void testHandleReplay_noMultipleErrors()
throws Exception
Exceptionpublic static Resource createSelfRedirectResource(String url, String timestamp) throws IOException
IOExceptionpublic void testHandleRequest_MissingRevisitPayload()
throws Exception
handleReplay() is supposed to throw
ResourceNotAvailableException when it cannot find a replay-able
capture for a request. This is a test for one of such "capture not found"
case: revisited record cannot found in the capture search results, and
only other non-revisit resource available is a self-redirect. This is
rather a corner case. handlReplay() shall throw
ResourceNotAvailableException.Exceptionpublic void testHandleRequest_Replay_OldWARCRevisit()
throws Exception
Exceptionpublic void testHandleRequest_Replay_OldARCRevisit()
throws Exception
Exceptionpublic static final Resource createTest502Resource() throws IOException
IOExceptionpublic void testHandleRequest_Replay_Embedded()
throws Exception
Exceptionpublic final void setCaptureQueryRequest(String requestUrl, String replayTimestamp)
requestUrl, at time .requestUrl - replayTimestamp - public void testHandleRequest_CaptureSearchResults()
throws Exception
Exceptionpublic void setUrlQueryRequest(String requestUrl, String replayTimestamp)
requestUrl at time replayTimestamp. created object is set
to wbRequest.requestUrl - replayTimestamp - public void testHandleRequest_UrlSearchResults()
throws Exception
Exceptionpublic void testHandleRequest_queryCollapseTimeUnspecified()
throws Exception
Exceptionpublic void testHandleRequest_queryCollapseTimeSpecified()
throws Exception
Exceptionpublic void testHandlerRequest_queryCollapseTimeForReplayQuery()
throws Exception
Exceptionpublic void testBounceToReplayPrefix()
throws Exception
Exceptionpublic void testDispatchLocal()
throws Exception
${wayback.staticPrefix}RequestParser.parse(HttpServletRequest, AccessPoint) returns
null, request is forwarded to dispatchLocal() for rendering static
resources.Exceptionpublic void testMemento_replay_exactCapture()
throws Exception
Exceptionpublic void testMemento_replay_nearbyCapture()
throws Exception
Exceptionpublic void testMementoTimegate()
throws Exception
Exceptionpublic void testMementoTimemap()
throws Exception
Actual rendering is done by a separate bean implementing
MementoHandler. So what we test here is that AccessPoint is
correctly routing Timemap request to MementoHandler.
ExceptionCopyright © 2005–2015 IIPC. All rights reserved.