* @throws BetterRequestException
*/
public void testParseString() throws Exception {
BaseRequestParser wrapped = new ArchivalUrlRequestParser();
ReplayRequestParser p = new ReplayRequestParser(wrapped);
WaybackRequest r;
AccessPoint ap = null;
r = p.parse("",ap);
assertNull("Should not parse empty string", r);
r = p.parse("20070101000000/foo.com",ap);
assertNotNull("Should parse legit request sans scheme", r);
assertEquals("parsed request Url",r.getRequestUrl(),"http://foo.com");
assertEquals("Parsed timestamp","20070101000000",r.getReplayTimestamp());
r = p.parse("20070101000000/foo.com/",ap);
assertEquals("parsed request Url, maintaining trailing slash",
"http://foo.com/",r.getRequestUrl());
r = p.parse("200701010000/foo.com",ap);
assertEquals("parsed partial date",
"http://foo.com",r.getRequestUrl());
assertEquals("Parsed partial timestamp to earliest",
"20070101000000",r.getReplayTimestamp());
r = p.parse("20070101000000/http://foo.com",ap);
assertEquals("parsed request Url with scheme",
"http://foo.com",r.getRequestUrl());
r = p.parse("20070101000000/http://foo.com/",ap);
assertEquals("parsed request Url with scheme and trailing slash",
"http://foo.com/",r.getRequestUrl());
r = p.parse("20070101000000/ftp://foo.com/",ap);
assertEquals("parsed request Url with ftp scheme",
"ftp://foo.com/",r.getRequestUrl());
r = p.parse("20070101000000/https://foo.com/",ap);
assertEquals("parsed request Url with https scheme",
"https://foo.com/",r.getRequestUrl());
r = p.parse("20070101000000js_/http://foo.com/",ap);
assertEquals("parsed request Url with js_ flag",
"http://foo.com/",r.getRequestUrl());
assertTrue("parsed js_ flag",r.isJSContext());
assertFalse("css not set",r.isCSSContext());
r = p.parse("20070101000000cs_/http://foo.com/",ap);
assertEquals("parsed request Url with cs_ flag",
"http://foo.com/",r.getRequestUrl());
assertTrue("parsed cs_ flag",r.isCSSContext());
assertFalse("js not set",r.isJSContext());
r = p.parse("20070101000000cs_js_/http://foo.com/",ap);
assertEquals("parsed request Url with cs_ and js_ flags",
"http://foo.com/",r.getRequestUrl());
assertTrue("parsed cs_ flag",r.isCSSContext());
assertTrue("parsed js_ flag",r.isJSContext());
r = p.parse("20070101000000js_cs_/http://foo.com/",ap);
assertEquals("parsed request Url with cs_ and js_ flags, backvards",
"http://foo.com/",r.getRequestUrl());
assertTrue("parsed cs_ flag",r.isCSSContext());
assertTrue("parsed js_ flag",r.isJSContext());
r = p.parse("20070101000000un_/http://foo.com/",ap);
assertEquals("parsed request Url with unknown flag",
"http://foo.com/",r.getRequestUrl());
assertFalse("no cs_ flag",r.isCSSContext());
assertFalse("no js_ flag",r.isJSContext());
r = p.parse("20070101000000un_js_cs_/http://foo.com/",ap);
assertEquals("parsed request Url with falgs and unknown flag",
"http://foo.com/",r.getRequestUrl());
assertTrue("parsed cs_ flag",r.isCSSContext());
assertTrue("parsed js_ flag",r.isJSContext());
r = p.parse("20070101000000js_cs_un_/http://foo.com/",ap);
assertEquals("parsed request Url with falgs and unknown flag at end",
"http://foo.com/",r.getRequestUrl());
assertTrue("parsed cs_ flag",r.isCSSContext());
assertTrue("parsed js_ flag",r.isJSContext());
r = p.parse("20070101000000un_js_cs_un_/http://foo.com/",ap);
assertEquals("parsed request Url with falgs and unknown flags",
"http://foo.com/",r.getRequestUrl());
assertTrue("parsed cs_ flag",r.isCSSContext());
assertTrue("parsed js_ flag",r.isJSContext());
}