01: /**
02: * $Id: InternallyReferencedOnlyRuleTest.java,v 1.4 2003/04/11 16:37:10 vanrogu Exp $
03: */package net.javacoding.jspider.mod.rule;
04:
05: import junit.framework.TestCase;
06: import net.javacoding.jspider.api.model.Decision;
07: import net.javacoding.jspider.api.model.Site;
08: import net.javacoding.jspider.core.SpiderContext;
09: import net.javacoding.jspider.core.model.SiteInternal;
10: import net.javacoding.jspider.spi.Rule;
11: import net.javacoding.jspider.mockobjects.SimpleSpiderContext;
12: import net.javacoding.jspider.mod.rule.InternallyReferencedOnlyRule;
13:
14: import java.net.URL;
15:
16: public class InternallyReferencedOnlyRuleTest extends TestCase {
17:
18: protected Rule rule;
19: protected SpiderContext context;
20: protected Site jspiderSite;
21: protected Site otherSite;
22:
23: public InternallyReferencedOnlyRuleTest() {
24: super ("InternallyReferencedOnlyRuleTest");
25: }
26:
27: protected void setUp() throws Exception {
28: rule = new InternallyReferencedOnlyRule();
29: URL jspiderUrl = new URL("http://j-spider.sourceforge.net");
30: jspiderSite = new SiteInternal(0, null, jspiderUrl);
31: URL otherUrl = new URL("http://www.javacoding.net");
32: otherSite = new SiteInternal(0, null, otherUrl);
33: context = new SimpleSpiderContext(jspiderUrl);
34: }
35:
36: public void testBaseSiteInternal() throws Exception {
37: URL url = new URL(
38: "http://j-spider.sourceforge.net/some/doc.html");
39: Decision decision = rule.apply(context, jspiderSite, url);
40: assertEquals("resource within same site not accepted",
41: Decision.RULE_ACCEPT, decision.getDecision());
42: }
43:
44: public void testBaseSiteExternal() throws Exception {
45: URL url = new URL(
46: "http://j-spider.sourceforge.net/some/doc.html");
47: Decision decision = rule.apply(context, otherSite, url);
48: assertEquals("resource within other site not ignored",
49: Decision.RULE_IGNORE, decision.getDecision());
50: }
51:
52: public void testNonBaseSiteInternal() throws Exception {
53: URL url = new URL("http://www.javacoding.net/some/doc.html");
54: Decision decision = rule.apply(context, otherSite, url);
55: assertEquals("resource within same site not accepted",
56: Decision.RULE_ACCEPT, decision.getDecision());
57: }
58:
59: public void testNonBaseSiteExternal() throws Exception {
60: URL url = new URL("http://www.javacoding.net/some/doc.html");
61: Decision decision = rule.apply(context, jspiderSite, url);
62: assertEquals("resource within other site not ignored",
63: Decision.RULE_IGNORE, decision.getDecision());
64: }
65:
66: public void testNullSiteURL() throws Exception {
67: URL url = new URL("http://www.javacoding.net/some/doc.html");
68: Decision decision = rule.apply(context, null, url);
69: assertEquals("resource reffed from 'null' site not DONTCARE",
70: Decision.RULE_DONTCARE, decision.getDecision());
71: }
72:
73: }
|