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 ; 11 12 15 public class ParseTest extends TestCase { 16 17 protected JUnitEventSink sink; 18 protected JSpiderConfiguration config; 19 20 23 public ParseTest ( ) { 24 super ( "ParseTest "); 25 } 26 27 31 protected void setUp() throws Exception { 32 System.err.println("setUp"); 33 config = ConfigurationFactory.getConfiguration(ConfigurationFactory.CONFIG_UNITTEST); 34 sink = JUnitEventSink.getInstance(); 35 } 36 37 41 protected void tearDown() throws Exception { 42 System.err.println("tearDown"); 43 ConfigurationFactory.cleanConfiguration(); 44 sink.reset(); 45 } 46 47 50 public void testSimpleParse ( ) throws Exception { 51 52 URL url = new URL ( "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 { 77 78 URL url = new URL ( "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 108 public void testMalformedParse ( ) throws Exception { 109 110 URL url = new URL ( "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 eventClass, int expectedCount ) { 135 assertEquals(eventClass.getName(), expectedCount, sink.getEventCount(eventClass)); 136 } 137 138 } 139 | Popular Tags |