KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.javacoding.jspider.mod.rule;
2
3 import net.javacoding.jspider.api.model.Decision;
4 import net.javacoding.jspider.mockobjects.OverridingPropertySet;
5 import net.javacoding.jspider.spi.Rule;
6 import net.javacoding.jspider.core.util.config.ConfigurationFactory;
7
8 import java.net.URL JavaDoc;
9
10 import junit.framework.TestCase;
11
12 /**
13  * $Id: MaxNumberOfURLParamsRuleTest.java,v 1.1 2003/04/07 15:51:05 vanrogu Exp $
14  */

15 public class MaxNumberOfURLParamsRuleTest extends TestCase {
16
17     protected OverridingPropertySet config;
18
19     public MaxNumberOfURLParamsRuleTest ( ) {
20         super ( "MaxNumberOfURLParamsRuleTest" );
21     }
22
23     protected void setUp() throws Exception JavaDoc {
24         ConfigurationFactory.getConfiguration(ConfigurationFactory.CONFIG_UNITTEST);
25         config = new OverridingPropertySet ( null );
26     }
27
28     public void testNoParams ( ) throws Exception JavaDoc {
29         String JavaDoc urlString = "http://j-spider.sourceforge.net";
30         int max = 10;
31         int expected = Decision.RULE_ACCEPT;
32
33         applyTest ( max, urlString, expected );
34     }
35
36     public void testQuestionMarkOneAllowed ( ) throws Exception JavaDoc {
37         String JavaDoc urlString = "http://j-spider.sourceforge.net?";
38         int max = 1;
39         int expected = Decision.RULE_ACCEPT;
40
41         applyTest ( max, urlString, expected );
42     }
43
44     public void testFileWithQuestionMarkOneAllowed ( ) throws Exception JavaDoc {
45         String JavaDoc urlString = "http://j-spider.sourceforge.net/index.html?";
46         int max = 1;
47         int expected = Decision.RULE_ACCEPT;
48
49         applyTest ( max, urlString, expected );
50     }
51
52     public void testQuestionMarkZeroAllowed ( ) throws Exception JavaDoc {
53         String JavaDoc urlString = "http://j-spider.sourceforge.net?";
54         int max = 0;
55         int expected = Decision.RULE_ACCEPT;
56
57         applyTest ( max, urlString, expected );
58     }
59
60     public void testFileWithQuestionMarkZeroAllowed ( ) throws Exception JavaDoc {
61         String JavaDoc urlString = "http://j-spider.sourceforge.net/index.html?";
62         int max = 0;
63         int expected = Decision.RULE_ACCEPT;
64
65         applyTest ( max, urlString, expected );
66     }
67
68     public void testNoParamsZeroAllowed ( ) throws Exception JavaDoc {
69         String JavaDoc urlString = "http://j-spider.sourceforge.net";
70         int max = 0;
71         int expected = Decision.RULE_ACCEPT;
72
73         applyTest ( max, urlString, expected );
74     }
75
76     public void testSingleParam ( ) throws Exception JavaDoc {
77         String JavaDoc urlString = "http://j-spider.sourceforge.net/index.html?param=value";
78         int max = 10;
79         int expected = Decision.RULE_ACCEPT;
80
81         applyTest ( max, urlString, expected );
82     }
83
84     public void testSingleParamOneAllowed ( ) throws Exception JavaDoc {
85         String JavaDoc urlString = "http://j-spider.sourceforge.net/index.html?param=value";
86         int max = 1;
87         int expected = Decision.RULE_ACCEPT;
88
89         applyTest ( max, urlString, expected );
90     }
91
92     public void testSingleParamZeroAllowed ( ) throws Exception JavaDoc {
93         String JavaDoc urlString = "http://j-spider.sourceforge.net/index.html?param=value";
94         int max = 0;
95         int expected = Decision.RULE_IGNORE;
96
97         applyTest ( max, urlString, expected );
98     }
99
100     public void testWithParams ( ) throws Exception JavaDoc {
101         String JavaDoc urlString = "http://j-spider.sourceforge.net/index.html?param=value&param2=value2";
102         int max = 10;
103         int expected = Decision.RULE_ACCEPT;
104
105         applyTest ( max, urlString, expected );
106     }
107
108     public void testWithParamsOnBoundary ( ) throws Exception JavaDoc {
109         String JavaDoc urlString = "http://j-spider.sourceforge.net/index.html?param=value&param2=value2";
110         int max = 2;
111         int expected = Decision.RULE_ACCEPT;
112
113         applyTest ( max, urlString, expected );
114     }
115
116     public void testWithParamsViolation ( ) throws Exception JavaDoc {
117         String JavaDoc urlString = "http://j-spider.sourceforge.net/index.html?param=value&param2=value2&param3=value3";
118         int max = 2;
119         int expected = Decision.RULE_IGNORE;
120
121         applyTest ( max, urlString, expected );
122     }
123
124
125     public void applyTest ( int max, String JavaDoc urlString, int expected ) throws Exception JavaDoc {
126         config.setValue(MaxNumberOfURLParamsRule.MAX, new Integer JavaDoc(max));
127         URL JavaDoc url = new URL JavaDoc ( urlString );
128         Rule rule = new MaxNumberOfURLParamsRule(config);
129         Decision decision = rule.apply(null, null, url);
130         assertEquals("decision not as expected", expected, decision.getDecision());
131     }
132
133 }
134
Popular Tags