01: /*
02: * Copyright 2005 by Lars Torunski
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: *
16: */
17: package com.torunski.crawler;
18:
19: import com.torunski.crawler.filter.ServerFilter;
20: import com.torunski.crawler.model.MaxIterationsModel;
21:
22: import junit.framework.Test;
23: import junit.framework.TestCase;
24: import junit.framework.TestSuite;
25:
26: /**
27: * Test the crawler
28: *
29: * @author Lars Torunski
30: * @version $Revision: 1.5 $
31: */
32: public class TestCrawler extends TestCase {
33:
34: /**
35: * Constructor
36: * @param str The test name (required by JUnit)
37: */
38: public TestCrawler(String str) {
39: super (str);
40: }
41:
42: /**
43: * This methods returns the name of this test class to JUnit
44: * @return The name of this class
45: */
46: public static Test suite() {
47: return new TestSuite(TestCrawler.class);
48: }
49:
50: private static final String SERVER = "http://www.heise.de";
51:
52: private static final String START = "/";
53:
54: private Crawler crawler;
55:
56: protected void setUp() {
57: // Construct the objects required for the tests
58: crawler = new Crawler();
59: crawler.setModel(new MaxIterationsModel(3));
60: crawler.setLinkFilter(new ServerFilter(SERVER));
61: }
62:
63: /**
64: * Test the implementation
65: */
66: public void testCrawler() {
67: // start crawler
68: crawler.start(SERVER, START);
69:
70: // Assert the counters
71: assertTrue("At least one page should be visted.", crawler
72: .getModel().getVisitedURIs().size() >= 1);
73: assertTrue("The site contains no links.", crawler.getModel()
74: .getToVisitURIs().size() > 0);
75: }
76: }
|