KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * $Id: InternallyReferencedOnlyRuleTest.java,v 1.4 2003/04/11 16:37:10 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.InternallyReferencedOnlyRule;
14
15 import java.net.URL JavaDoc;
16
17 public class InternallyReferencedOnlyRuleTest extends TestCase {
18
19     protected Rule rule;
20     protected SpiderContext context;
21     protected Site jspiderSite;
22     protected Site otherSite;
23
24     public InternallyReferencedOnlyRuleTest ( ) {
25         super ( "InternallyReferencedOnlyRuleTest" );
26     }
27
28     protected void setUp() throws Exception JavaDoc {
29         rule = new InternallyReferencedOnlyRule();
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 testBaseSiteInternal ( ) 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 testBaseSiteExternal ( ) 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 other site not ignored", Decision.RULE_IGNORE, decision.getDecision());
47     }
48
49     public void testNonBaseSiteInternal ( ) throws Exception JavaDoc {
50         URL JavaDoc url = new URL JavaDoc ( "http://www.javacoding.net/some/doc.html");
51         Decision decision = rule.apply(context, otherSite, url);
52         assertEquals("resource within same site not accepted", Decision.RULE_ACCEPT, decision.getDecision());
53     }
54
55     public void testNonBaseSiteExternal ( ) 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 other site not ignored", Decision.RULE_IGNORE, decision.getDecision());
59     }
60
61     public void testNullSiteURL ( ) throws Exception JavaDoc {
62         URL JavaDoc url = new URL JavaDoc ( "http://www.javacoding.net/some/doc.html");
63         Decision decision = rule.apply(context, null, url);
64         assertEquals("resource reffed from 'null' site not DONTCARE", Decision.RULE_DONTCARE, decision.getDecision());
65     }
66
67 }
68
Popular Tags