1 4 package net.javacoding.jspider.mod.rule; 5 6 import junit.framework.TestCase; 7 import net.javacoding.jspider.api.model.Decision; 8 import net.javacoding.jspider.api.model.Site; 9 import net.javacoding.jspider.core.SpiderContext; 10 import net.javacoding.jspider.core.model.SiteInternal; 11 import net.javacoding.jspider.spi.Rule; 12 import net.javacoding.jspider.mockobjects.SimpleSpiderContext; 13 import net.javacoding.jspider.mod.rule.BaseSiteOnlyRule; 14 15 import java.net.URL ; 16 17 public class BaseSiteOnlyRuleTest extends TestCase { 18 19 protected Rule rule; 20 protected SpiderContext context; 21 protected Site jspiderSite; 22 protected Site otherSite; 23 24 public BaseSiteOnlyRuleTest ( ) { 25 super ( "BaseSiteOnlyRuleTest" ); 26 } 27 28 protected void setUp() throws Exception { 29 rule = new BaseSiteOnlyRule(); 30 URL jspiderUrl = new URL ( "http://j-spider.sourceforge.net"); 31 jspiderSite = new SiteInternal(0, null, jspiderUrl); 32 URL otherUrl = new URL ( "http://www.javacoding.net"); 33 otherSite = new SiteInternal(0, null, otherUrl); 34 context = new SimpleSpiderContext(jspiderUrl); 35 } 36 37 public void testBaseSite ( ) throws Exception { 38 URL url = new URL ( "http://j-spider.sourceforge.net/some/doc.html"); 39 Decision decision = rule.apply(context, jspiderSite, url); 40 assertEquals("resource within same site not accepted", Decision.RULE_ACCEPT, decision.getDecision()); 41 } 42 43 public void testBaseSiteOtherContext ( ) throws Exception { 44 URL url = new URL ( "http://j-spider.sourceforge.net/some/doc.html"); 45 Decision decision = rule.apply(context, otherSite, url); 46 assertEquals("resource within same site not accepted", Decision.RULE_ACCEPT, decision.getDecision()); 47 } 48 49 public void testOtherSite ( ) throws Exception { 50 URL url = new URL ( "http://www.javacoding.net/some/doc.html"); 51 Decision decision = rule.apply(context, jspiderSite, url); 52 assertEquals("resource within same site not ignored", Decision.RULE_IGNORE, decision.getDecision()); 53 } 54 55 public void testOtherSiteOtherContext ( ) throws Exception { 56 URL url = new URL ( "http://www.javacoding.net/some/doc.html"); 57 Decision decision = rule.apply(context, jspiderSite, url); 58 assertEquals("resource within same site not ignored", Decision.RULE_IGNORE, decision.getDecision()); 59 } 60 61 } 62 | Popular Tags |