01: package net.javacoding.jspider.mod.rule;
02:
03: import junit.framework.TestCase;
04: import net.javacoding.jspider.mockobjects.OverridingPropertySet;
05: import net.javacoding.jspider.spi.Rule;
06: import net.javacoding.jspider.api.model.Decision;
07:
08: import java.net.URL;
09:
10: /**
11: * $Id: ForbiddenPathRuleTest.java,v 1.1 2003/04/07 15:51:05 vanrogu Exp $
12: */
13: public class ForbiddenPathRuleTest extends TestCase {
14:
15: OverridingPropertySet config;
16:
17: public ForbiddenPathRuleTest() {
18: super ("ForbiddenPathRuleTest");
19: }
20:
21: protected void setUp() throws Exception {
22: config = new OverridingPropertySet(null);
23: }
24:
25: public void testSimple() throws Exception {
26: String path = "/forbidden";
27: String urlString = "http://j-spider.sourceforge.net/test/index.html";
28: int expected = Decision.RULE_DONTCARE;
29: applyTest(path, urlString, expected);
30: }
31:
32: public void testForbidden() throws Exception {
33: String path = "/forbidden";
34: String urlString = "http://j-spider.sourceforge.net/forbidden/index.html";
35: int expected = Decision.RULE_FORBIDDEN;
36: applyTest(path, urlString, expected);
37: }
38:
39: public void testForbiddenRoot() throws Exception {
40: String path = "/";
41: String urlString = "http://j-spider.sourceforge.net/forbidden/index.html";
42: int expected = Decision.RULE_FORBIDDEN;
43: applyTest(path, urlString, expected);
44: }
45:
46: public void testForbiddenRootHomePage() throws Exception {
47: String path = "/";
48: String urlString = "http://j-spider.sourceforge.net";
49: int expected = Decision.RULE_FORBIDDEN;
50: applyTest(path, urlString, expected);
51: }
52:
53: public void testForbiddenRootHomePageWithSlash() throws Exception {
54: String path = "/";
55: String urlString = "http://j-spider.sourceforge.net/";
56: int expected = Decision.RULE_FORBIDDEN;
57: applyTest(path, urlString, expected);
58: }
59:
60: public void applyTest(String path, String urlString, int expected)
61: throws Exception {
62: URL url = new URL(urlString);
63: config.setValue(ForbiddenPathRule.PATH, path);
64: Rule rule = new ForbiddenPathRule(config);
65: Decision decision = rule.apply(null, null, url);
66: assertEquals("wrong decision taken on url", expected, decision
67: .getDecision());
68: }
69:
70: }
|