01: package net.javacoding.jspider.mod.rule;
02:
03: import junit.framework.TestCase;
04: import net.javacoding.jspider.spi.Rule;
05: import net.javacoding.jspider.api.model.Decision;
06:
07: import java.net.URL;
08:
09: /**
10: * $Id: NoURLParamsRuleTest.java,v 1.1 2003/04/07 15:51:06 vanrogu Exp $
11: */
12: public class NoURLParamsRuleTest extends TestCase {
13:
14: protected Rule rule;
15:
16: public NoURLParamsRuleTest() {
17: super ("NoURLParamsRuleTest");
18: }
19:
20: protected void setUp() throws Exception {
21: rule = new NoURLParamsRule();
22: }
23:
24: public void testNoParams() throws Exception {
25: String urlString = "http://j-spider.sourceforge.net/index.html";
26: int expected = Decision.RULE_ACCEPT;
27:
28: applyTest(urlString, expected);
29: }
30:
31: public void testRootNoParams() throws Exception {
32: String urlString = "http://j-spider.sourceforge.net";
33: int expected = Decision.RULE_ACCEPT;
34:
35: applyTest(urlString, expected);
36: }
37:
38: public void testRootNoParamsWithSlash() throws Exception {
39: String urlString = "http://j-spider.sourceforge.net/";
40: int expected = Decision.RULE_ACCEPT;
41:
42: applyTest(urlString, expected);
43: }
44:
45: public void testSingleParam() throws Exception {
46: String urlString = "http://j-spider.sourceforge.net/index.html?param=value";
47: int expected = Decision.RULE_IGNORE;
48:
49: applyTest(urlString, expected);
50: }
51:
52: public void testDoubleParam() throws Exception {
53: String urlString = "http://j-spider.sourceforge.net/index.html?param=value¶m2=value2";
54: int expected = Decision.RULE_IGNORE;
55:
56: applyTest(urlString, expected);
57: }
58:
59: public void testQuestionMarkOnly() throws Exception {
60: String urlString = "http://j-spider.sourceforge.net/index.html?";
61: int expected = Decision.RULE_ACCEPT;
62:
63: applyTest(urlString, expected);
64: }
65:
66: public void testQuestionMarkOnlyOnFolder() throws Exception {
67: String urlString = "http://j-spider.sourceforge.net/test?";
68: int expected = Decision.RULE_ACCEPT;
69:
70: applyTest(urlString, expected);
71: }
72:
73: public void testQuestionMarkOnlyOnFolderWithSlash()
74: throws Exception {
75: String urlString = "http://j-spider.sourceforge.net/test/?";
76: int expected = Decision.RULE_ACCEPT;
77:
78: applyTest(urlString, expected);
79: }
80:
81: public void applyTest(String urlString, int expected)
82: throws Exception {
83: URL url = new URL(urlString);
84: Decision decision = rule.apply(null, null, url);
85: assertEquals("decision not as expected", expected, decision
86: .getDecision());
87: }
88:
89: }
|