KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > javacoding > jspider > functional > specific > parse > ParseTest


1 package net.javacoding.jspider.functional.specific.parse;
2
3 import junit.framework.TestCase;
4 import net.javacoding.jspider.JSpider;
5 import net.javacoding.jspider.functional.TestingConstants;
6 import net.javacoding.jspider.core.util.config.ConfigurationFactory;
7 import net.javacoding.jspider.core.util.config.JSpiderConfiguration;
8 import net.javacoding.jspider.mockobjects.plugin.JUnitEventSink;
9
10 import java.net.URL JavaDoc;
11
12 /**
13  * $Id: ParseTest.java,v 1.7 2003/04/11 16:37:09 vanrogu Exp $
14  */

15 public class ParseTest extends TestCase {
16
17     protected JUnitEventSink sink;
18     protected JSpiderConfiguration config;
19
20     /**
21      * Public constructor giving a name to the test.
22      */

23     public ParseTest ( ) {
24         super ( "ParseTest ");
25     }
26
27     /**
28      * JUnit's overridden setUp method
29      * @throws java.lang.Exception in case something fails during setup
30      */

31     protected void setUp() throws Exception JavaDoc {
32         System.err.println("setUp");
33         config = ConfigurationFactory.getConfiguration(ConfigurationFactory.CONFIG_UNITTEST);
34         sink = JUnitEventSink.getInstance();
35     }
36
37     /**
38      * JUnit's overridden tearDown method
39      * @throws java.lang.Exception in case something fails during tearDown
40      */

41     protected void tearDown() throws Exception JavaDoc {
42         System.err.println("tearDown");
43         ConfigurationFactory.cleanConfiguration();
44         sink.reset();
45     }
46
47     /**
48      * Test a simple parse.
49      */

50     public void testSimpleParse ( ) throws Exception JavaDoc {
51
52         URL JavaDoc url = new URL JavaDoc ( "http://" + TestingConstants.HOST + "/testcases/specific/parse/testSimpleParse.html" );
53
54         JSpider jspider = new JSpider ( url );
55         jspider.start ( );
56
57         testEventCount(net.javacoding.jspider.api.event.engine.SpideringStartedEvent.class,1);
58         testEventCount(net.javacoding.jspider.api.event.engine.SpideringSummaryEvent.class,1);
59         testEventCount(net.javacoding.jspider.api.event.engine.SpideringStoppedEvent.class,1);
60
61         testEventCount(net.javacoding.jspider.api.event.site.SiteDiscoveredEvent.class,1);
62         testEventCount(net.javacoding.jspider.api.event.site.RobotsTXTMissingEvent.class,0);
63         testEventCount(net.javacoding.jspider.api.event.site.RobotsTXTFetchedEvent.class,1);
64         testEventCount(net.javacoding.jspider.api.event.site.RobotsTXTFetchErrorEvent.class,0);
65
66         testEventCount(net.javacoding.jspider.api.event.resource.ResourceDiscoveredEvent.class,2);
67         testEventCount(net.javacoding.jspider.api.event.resource.ResourceFetchedEvent.class,2);
68         testEventCount(net.javacoding.jspider.api.event.resource.ResourceFetchErrorEvent.class,0);
69         testEventCount(net.javacoding.jspider.api.event.resource.ResourceForbiddenEvent.class,0);
70         testEventCount(net.javacoding.jspider.api.event.resource.ResourceIgnoredForFetchingEvent.class,0);
71         testEventCount(net.javacoding.jspider.api.event.resource.ResourceIgnoredForParsingEvent.class,0);
72         testEventCount(net.javacoding.jspider.api.event.resource.ResourceReferenceDiscoveredEvent.class,6);
73         testEventCount(net.javacoding.jspider.api.event.resource.ResourceParsedEvent.class,1);
74     }
75
76     public void testSimpleParseWithEMailAddresses ( ) throws Exception JavaDoc {
77
78         URL JavaDoc url = new URL JavaDoc ( "http://" + TestingConstants.HOST + "/testcases/specific/parse/testSimpleParseWithEMailAddresses.html" );
79
80         JSpider jspider = new JSpider ( url );
81         jspider.start ( );
82
83         testEventCount(net.javacoding.jspider.api.event.engine.SpideringStartedEvent.class,1);
84         testEventCount(net.javacoding.jspider.api.event.engine.SpideringSummaryEvent.class,1);
85         testEventCount(net.javacoding.jspider.api.event.engine.SpideringStoppedEvent.class,1);
86
87         testEventCount(net.javacoding.jspider.api.event.site.SiteDiscoveredEvent.class,1);
88         testEventCount(net.javacoding.jspider.api.event.site.RobotsTXTMissingEvent.class,0);
89         testEventCount(net.javacoding.jspider.api.event.site.RobotsTXTFetchedEvent.class,1);
90         testEventCount(net.javacoding.jspider.api.event.site.RobotsTXTFetchErrorEvent.class,0);
91
92         testEventCount(net.javacoding.jspider.api.event.resource.ResourceDiscoveredEvent.class,2);
93         testEventCount(net.javacoding.jspider.api.event.resource.ResourceFetchedEvent.class,2);
94         testEventCount(net.javacoding.jspider.api.event.resource.ResourceFetchErrorEvent.class,0);
95         testEventCount(net.javacoding.jspider.api.event.resource.ResourceForbiddenEvent.class,0);
96         testEventCount(net.javacoding.jspider.api.event.resource.ResourceIgnoredForFetchingEvent.class,0);
97         testEventCount(net.javacoding.jspider.api.event.resource.ResourceIgnoredForParsingEvent.class,0);
98         testEventCount(net.javacoding.jspider.api.event.resource.ResourceReferenceDiscoveredEvent.class,0);
99         testEventCount(net.javacoding.jspider.api.event.resource.ResourceParsedEvent.class,1);
100
101         testEventCount(net.javacoding.jspider.api.event.resource.EMailAddressDiscoveredEvent.class,2);
102         testEventCount(net.javacoding.jspider.api.event.resource.EMailAddressReferenceDiscoveredEvent.class,3);
103     }
104
105     /**
106      * Tests parsing of malformed "a href" constructs.
107      */

108     public void testMalformedParse ( ) throws Exception JavaDoc {
109
110         URL JavaDoc url = new URL JavaDoc ( "http://" + TestingConstants.HOST + "/testcases/specific/parse/testMalformedParse.html" );
111
112         JSpider jspider = new JSpider ( url );
113         jspider.start ( );
114
115         testEventCount(net.javacoding.jspider.api.event.engine.SpideringStartedEvent.class,1);
116         testEventCount(net.javacoding.jspider.api.event.engine.SpideringSummaryEvent.class,1);
117         testEventCount(net.javacoding.jspider.api.event.engine.SpideringStoppedEvent.class,1);
118
119         testEventCount(net.javacoding.jspider.api.event.site.SiteDiscoveredEvent.class,1);
120         testEventCount(net.javacoding.jspider.api.event.site.RobotsTXTMissingEvent.class,0);
121         testEventCount(net.javacoding.jspider.api.event.site.RobotsTXTFetchedEvent.class,1);
122         testEventCount(net.javacoding.jspider.api.event.site.RobotsTXTFetchErrorEvent.class,0);
123
124         testEventCount(net.javacoding.jspider.api.event.resource.ResourceDiscoveredEvent.class,2);
125         testEventCount(net.javacoding.jspider.api.event.resource.ResourceFetchedEvent.class,2);
126         testEventCount(net.javacoding.jspider.api.event.resource.ResourceFetchErrorEvent.class,0);
127         testEventCount(net.javacoding.jspider.api.event.resource.ResourceForbiddenEvent.class,0);
128         testEventCount(net.javacoding.jspider.api.event.resource.ResourceIgnoredForFetchingEvent.class,0);
129         testEventCount(net.javacoding.jspider.api.event.resource.ResourceIgnoredForParsingEvent.class,0);
130         testEventCount(net.javacoding.jspider.api.event.resource.ResourceReferenceDiscoveredEvent.class,11);
131         testEventCount(net.javacoding.jspider.api.event.resource.ResourceParsedEvent.class,1);
132     }
133
134     protected void testEventCount ( Class JavaDoc eventClass, int expectedCount ) {
135         assertEquals(eventClass.getName(), expectedCount, sink.getEventCount(eventClass));
136     }
137
138 }
139
Popular Tags