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
27 package org.smartcrawler.retriever;
28 import junit.framework.*;
29 import org.apache.commons.httpclient.HostConfiguration;
30 import org.smartcrawler.common.Context;
31 import org.smartcrawler.common.Link;
32 import org.smartcrawler.common.SCLogger;
33
34
35 /***
36 *
37 *
38 * @author <a href="mailto:pozzad@alice.it">Davide Pozza</a>
39 * @version <tt>$Revision: 1.4 $</tt>
40 */
41 public class HttpCallRetrieverTest extends TestCase {
42
43 static {
44 SCLogger.initialize();
45 }
46
47 /***
48 *
49 * @param testName
50 */
51 public HttpCallRetrieverTest(String testName) {
52 super(testName);
53 }
54
55 /***
56 *
57 * @throws java.lang.Exception
58 */
59 protected void setUp() throws Exception {
60 }
61
62 /***
63 *
64 * @throws java.lang.Exception
65 */
66 protected void tearDown() throws Exception {
67 }
68
69 /***
70 *
71 * @return
72 */
73 public static Test suite() {
74 TestSuite suite = new TestSuite(HttpCallRetrieverTest.class);
75
76 return suite;
77 }
78
79 /***
80 * Test of execute method, of class org.smartcrawler.retriever.HttpCallRetriever.
81 */
82 public void testExecute() {
83 System.out.println("testExecute");
84 Link link = null;
85 try {
86 link = new Link("smartcrawler.sourceforge.net/test/testpage.html");
87 } catch (Exception e) {}
88 Context config = new Context();
89 config.setInitialLink(link);
90 Retriever r = new HttpCallRetriever();
91 Call call = new HttpCall(link);
92 Response res = r.execute(call);
93 assertTrue(res.isFound());
94
95
96 }
97
98 /***
99 * Test of getRedirLink method, of class org.smartcrawler.retriever.HttpCallRetriever.
100 */
101 public void testGetRedirLink() {
102 System.out.println("testGetRedirLink");
103 Link link = null;
104 try {
105 link = new Link("www.alice.it");
106 } catch (Exception e) {}
107 Context config = new Context();
108 config.setInitialLink(link);
109 Retriever r = new HttpCallRetriever();
110
111 Call call = new HttpCall(link);
112 Response res = r.execute(call);
113 assertTrue(res.isRedirected());
114 }
115
116 /***
117 * Test of getContent method, of class org.smartcrawler.retriever.HttpCallRetriever.
118 */
119 public void testGetContent() {
120 System.out.println("testGetContent");
121 Link link = null;
122 try {
123 link = new Link("smartcrawler.sourceforge.net/test/testpage.html");
124 } catch (Exception e) {}
125 Context config = new Context();
126 config.setInitialLink(link);
127 Retriever r = new HttpCallRetriever();
128 Call call = new HttpCall(link);
129 Response res = r.execute(call);
130 Content c = res.getContent();
131 assertTrue(
132 c != null &&
133 c.getBuffer().length > 0 &&
134 c.getLink().equals(link) &&
135 c.getContentType() != null
136 );
137 }
138
139 /***
140 * Test of createHostConfiguration method, of class org.smartcrawler.retriever.HttpCallRetriever.
141 */
142 public void testCreateHostConfiguration() {
143 System.out.println("testCreateHostConfiguration");
144 Link link = null;
145 try {
146 link = new Link("smartcrawler.sourceforge.net");
147 } catch (Exception e) {}
148 Call call = new HttpCall(link);
149 Context config = new Context();
150 config.setInitialLink(link);
151 HttpCallRetriever r = new HttpCallRetriever();
152
153 HostConfiguration actual = r.createHostConfiguration(call);
154
155 HostConfiguration expected = new HostConfiguration();
156 expected.setHost("smartcrawler.sourceforge.net", 80, "http");
157
158 assertEquals("HttpCallRetriever.createHostConfiguration(call)",
159 expected, actual);
160 }
161
162 }