KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > javacoding > jspider > mod > rule > BaseSiteOnlyRuleTest


1 /**
2  * $Id: BaseSiteOnlyRuleTest.java,v 1.4 2003/04/11 16:37:09 vanrogu Exp $
3  */

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 JavaDoc;
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 JavaDoc {
29         rule = new BaseSiteOnlyRule();
30         URL JavaDoc jspiderUrl = new URL JavaDoc ( "http://j-spider.sourceforge.net");
31         jspiderSite = new SiteInternal(0, null, jspiderUrl);
32         URL JavaDoc otherUrl = new URL JavaDoc ( "http://www.javacoding.net");
33         otherSite = new SiteInternal(0, null, otherUrl);
34         context = new SimpleSpiderContext(jspiderUrl);
35     }
36
37     public void testBaseSite ( ) throws Exception JavaDoc {
38         URL JavaDoc url = new URL JavaDoc ( "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 JavaDoc {
44         URL JavaDoc url = new URL JavaDoc ( "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 JavaDoc {
50         URL JavaDoc url = new URL JavaDoc ( "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 JavaDoc {
56         URL JavaDoc url = new URL JavaDoc ( "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