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 BaseURLParseTest extends TestCase { 16 17 protected JUnitEventSink sink; 18 protected JSpiderConfiguration config; 19 20 23 public BaseURLParseTest ( ) { 24 super ( "BaseURLParseTest "); 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 public void testWithFileReference ( ) throws Exception { 48 49 URL url = new URL ( "http://" + TestingConstants.HOST + "/testcases/specific/parse/testBaseURLParse.php" ); 50 51 JSpider jspider = new JSpider ( url ); 52 jspider.start ( ); 53 54 testEventCount(net.javacoding.jspider.api.event.engine.SpideringStartedEvent.class,1); 55 testEventCount(net.javacoding.jspider.api.event.engine.SpideringSummaryEvent.class,1); 56 testEventCount(net.javacoding.jspider.api.event.engine.SpideringStoppedEvent.class,1); 57 58 testEventCount(net.javacoding.jspider.api.event.site.SiteDiscoveredEvent.class,1); 59 testEventCount(net.javacoding.jspider.api.event.site.RobotsTXTMissingEvent.class,0); 60 testEventCount(net.javacoding.jspider.api.event.site.RobotsTXTFetchedEvent.class,1); 61 testEventCount(net.javacoding.jspider.api.event.site.RobotsTXTFetchErrorEvent.class,0); 62 63 testEventCount(net.javacoding.jspider.api.event.resource.ResourceDiscoveredEvent.class,4); 64 testEventCount(net.javacoding.jspider.api.event.resource.ResourceFetchedEvent.class,4); 65 testEventCount(net.javacoding.jspider.api.event.resource.ResourceFetchErrorEvent.class,0); 66 testEventCount(net.javacoding.jspider.api.event.resource.ResourceForbiddenEvent.class,0); 67 testEventCount(net.javacoding.jspider.api.event.resource.ResourceIgnoredForFetchingEvent.class,0); 68 testEventCount(net.javacoding.jspider.api.event.resource.ResourceIgnoredForParsingEvent.class,0); 69 testEventCount(net.javacoding.jspider.api.event.resource.ResourceReferenceDiscoveredEvent.class,2); 70 testEventCount(net.javacoding.jspider.api.event.resource.ResourceParsedEvent.class,3); 71 testEventCount(net.javacoding.jspider.api.event.resource.MalformedBaseURLFoundEvent.class,0); 72 } 73 74 75 public void testWithFolderReferenceAndSlash ( ) throws Exception { 76 77 URL url = new URL ( "http://" + TestingConstants.HOST + "/testcases/specific/parse/testBaseURLParseNoFile.php" ); 78 79 JSpider jspider = new JSpider ( url ); 80 jspider.start ( ); 81 82 testEventCount(net.javacoding.jspider.api.event.engine.SpideringStartedEvent.class,1); 83 testEventCount(net.javacoding.jspider.api.event.engine.SpideringSummaryEvent.class,1); 84 testEventCount(net.javacoding.jspider.api.event.engine.SpideringStoppedEvent.class,1); 85 86 testEventCount(net.javacoding.jspider.api.event.site.SiteDiscoveredEvent.class,1); 87 testEventCount(net.javacoding.jspider.api.event.site.RobotsTXTMissingEvent.class,0); 88 testEventCount(net.javacoding.jspider.api.event.site.RobotsTXTFetchedEvent.class,1); 89 testEventCount(net.javacoding.jspider.api.event.site.RobotsTXTFetchErrorEvent.class,0); 90 91 testEventCount(net.javacoding.jspider.api.event.resource.ResourceDiscoveredEvent.class,4); 92 testEventCount(net.javacoding.jspider.api.event.resource.ResourceFetchedEvent.class,4); 93 testEventCount(net.javacoding.jspider.api.event.resource.ResourceFetchErrorEvent.class,0); 94 testEventCount(net.javacoding.jspider.api.event.resource.ResourceForbiddenEvent.class,0); 95 testEventCount(net.javacoding.jspider.api.event.resource.ResourceIgnoredForFetchingEvent.class,0); 96 testEventCount(net.javacoding.jspider.api.event.resource.ResourceIgnoredForParsingEvent.class,0); 97 testEventCount(net.javacoding.jspider.api.event.resource.ResourceReferenceDiscoveredEvent.class,2); 98 testEventCount(net.javacoding.jspider.api.event.resource.ResourceParsedEvent.class,3); 99 testEventCount(net.javacoding.jspider.api.event.resource.MalformedBaseURLFoundEvent.class,0); 100 } 101 102 public void testWithFolderReferenceNoSlash ( ) throws Exception { 103 104 URL url = new URL ( "http://" + TestingConstants.HOST + "/testcases/specific/parse/testBaseURLParseNoSlash.php" ); 105 106 JSpider jspider = new JSpider ( url ); 107 jspider.start ( ); 108 109 testEventCount(net.javacoding.jspider.api.event.engine.SpideringStartedEvent.class,1); 110 testEventCount(net.javacoding.jspider.api.event.engine.SpideringSummaryEvent.class,1); 111 testEventCount(net.javacoding.jspider.api.event.engine.SpideringStoppedEvent.class,1); 112 113 testEventCount(net.javacoding.jspider.api.event.site.SiteDiscoveredEvent.class,1); 114 testEventCount(net.javacoding.jspider.api.event.site.RobotsTXTMissingEvent.class,0); 115 testEventCount(net.javacoding.jspider.api.event.site.RobotsTXTFetchedEvent.class,1); 116 testEventCount(net.javacoding.jspider.api.event.site.RobotsTXTFetchErrorEvent.class,0); 117 118 testEventCount(net.javacoding.jspider.api.event.resource.ResourceDiscoveredEvent.class,5); 119 testEventCount(net.javacoding.jspider.api.event.resource.ResourceFetchedEvent.class,5); 120 testEventCount(net.javacoding.jspider.api.event.resource.ResourceFetchErrorEvent.class,0); 121 testEventCount(net.javacoding.jspider.api.event.resource.ResourceForbiddenEvent.class,0); 122 testEventCount(net.javacoding.jspider.api.event.resource.ResourceIgnoredForFetchingEvent.class,0); 123 testEventCount(net.javacoding.jspider.api.event.resource.ResourceIgnoredForParsingEvent.class,0); 124 testEventCount(net.javacoding.jspider.api.event.resource.ResourceReferenceDiscoveredEvent.class,4); 125 testEventCount(net.javacoding.jspider.api.event.resource.ResourceParsedEvent.class,4); 126 testEventCount(net.javacoding.jspider.api.event.resource.MalformedBaseURLFoundEvent.class,0); 127 } 128 129 public void testMalformed ( ) throws Exception { 130 131 URL url = new URL ( "http://" + TestingConstants.HOST + "/testcases/specific/parse/testMalformedBaseURLParse.php" ); 132 133 JSpider jspider = new JSpider ( url ); 134 jspider.start ( ); 135 136 testEventCount(net.javacoding.jspider.api.event.engine.SpideringStartedEvent.class,1); 137 testEventCount(net.javacoding.jspider.api.event.engine.SpideringSummaryEvent.class,1); 138 testEventCount(net.javacoding.jspider.api.event.engine.SpideringStoppedEvent.class,1); 139 140 testEventCount(net.javacoding.jspider.api.event.site.SiteDiscoveredEvent.class,1); 141 testEventCount(net.javacoding.jspider.api.event.site.RobotsTXTMissingEvent.class,0); 142 testEventCount(net.javacoding.jspider.api.event.site.RobotsTXTFetchedEvent.class,1); 143 testEventCount(net.javacoding.jspider.api.event.site.RobotsTXTFetchErrorEvent.class,0); 144 145 testEventCount(net.javacoding.jspider.api.event.resource.ResourceDiscoveredEvent.class,3); 146 testEventCount(net.javacoding.jspider.api.event.resource.ResourceFetchedEvent.class,2); 147 testEventCount(net.javacoding.jspider.api.event.resource.ResourceFetchErrorEvent.class,1); 148 testEventCount(net.javacoding.jspider.api.event.resource.ResourceForbiddenEvent.class,0); 149 testEventCount(net.javacoding.jspider.api.event.resource.ResourceIgnoredForFetchingEvent.class,0); 150 testEventCount(net.javacoding.jspider.api.event.resource.ResourceIgnoredForParsingEvent.class,0); 151 testEventCount(net.javacoding.jspider.api.event.resource.ResourceReferenceDiscoveredEvent.class,1); 152 testEventCount(net.javacoding.jspider.api.event.resource.ResourceParsedEvent.class,1); 153 testEventCount(net.javacoding.jspider.api.event.resource.MalformedBaseURLFoundEvent.class,1); 154 } 155 156 157 protected void testEventCount ( Class eventClass, int expectedCount ) { 158 assertEquals(eventClass.getName(), expectedCount, sink.getEventCount(eventClass)); 159 } 160 161 } 162 | Popular Tags |