1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package org.archive.crawler.extractor;
27
28 import java.util.List;
29
30 import org.archive.net.UURI;
31
32 import junit.framework.TestCase;
33
34 /***
35 * Test ExtractorURI
36 *
37 * @author gojomo
38 */
39 public class ExtractorURITest extends TestCase {
40
41 public void testFullQuery() {
42 String queryStringUri = "http://www.example2.com";
43 innerTestQueryString(queryStringUri,queryStringUri);
44 }
45
46 public void testFullQueryEncoded() {
47 String queryStringUri = "http%3A//www.example2.com/";
48 String expectedUri = "http://www.example2.com/";
49 innerTestQueryString(queryStringUri,expectedUri);
50 }
51
52 public void testFullQueryEncodedComplex() {
53 String queryStringUri = "http%3A//www.example2.com/foo%3Fbar%3Dbz%26red%3Dblue";
54 String expectedUri = "http://www.example2.com/foo?bar=bz&red=blue";
55 innerTestQueryString(queryStringUri,expectedUri);
56 }
57
58 private void innerTestQueryString(String queryStringUri, String expectedUri) {
59 UURI uuri = UURI.from(
60 "http://www.example.com/foo?"+queryStringUri);
61 innerTestForPresence(uuri, expectedUri);
62 }
63
64 private void innerTestForPresence(UURI uuri, String expectedUri) {
65 List<String> results = ExtractorURI.extractQueryStringLinks(uuri);
66 assertTrue(
67 "URI not found: "+expectedUri,
68 results.contains(expectedUri));
69 }
70
71 public void testParameterComplex() {
72 String parameterUri = "http%3A//www.example2.com/foo%3Fbar%3Dbz%26red%3Dblue";
73 String expectedUri = "http://www.example2.com/foo?bar=bz&red=blue";
74 UURI uuri = UURI.from(
75 "http://www.example.com/foo?uri="+parameterUri+"&foo=bar");
76 innerTestForPresence(uuri,expectedUri);
77 }
78 }