001: package net.javacoding.jspider.mod.rule;
002:
003: import net.javacoding.jspider.api.model.Decision;
004: import net.javacoding.jspider.mockobjects.OverridingPropertySet;
005: import net.javacoding.jspider.spi.Rule;
006: import net.javacoding.jspider.core.util.config.ConfigurationFactory;
007:
008: import java.net.URL;
009:
010: import junit.framework.TestCase;
011:
012: /**
013: * $Id: MaxNumberOfURLParamsRuleTest.java,v 1.1 2003/04/07 15:51:05 vanrogu Exp $
014: */
015: public class MaxNumberOfURLParamsRuleTest extends TestCase {
016:
017: protected OverridingPropertySet config;
018:
019: public MaxNumberOfURLParamsRuleTest() {
020: super ("MaxNumberOfURLParamsRuleTest");
021: }
022:
023: protected void setUp() throws Exception {
024: ConfigurationFactory
025: .getConfiguration(ConfigurationFactory.CONFIG_UNITTEST);
026: config = new OverridingPropertySet(null);
027: }
028:
029: public void testNoParams() throws Exception {
030: String urlString = "http://j-spider.sourceforge.net";
031: int max = 10;
032: int expected = Decision.RULE_ACCEPT;
033:
034: applyTest(max, urlString, expected);
035: }
036:
037: public void testQuestionMarkOneAllowed() throws Exception {
038: String urlString = "http://j-spider.sourceforge.net?";
039: int max = 1;
040: int expected = Decision.RULE_ACCEPT;
041:
042: applyTest(max, urlString, expected);
043: }
044:
045: public void testFileWithQuestionMarkOneAllowed() throws Exception {
046: String urlString = "http://j-spider.sourceforge.net/index.html?";
047: int max = 1;
048: int expected = Decision.RULE_ACCEPT;
049:
050: applyTest(max, urlString, expected);
051: }
052:
053: public void testQuestionMarkZeroAllowed() throws Exception {
054: String urlString = "http://j-spider.sourceforge.net?";
055: int max = 0;
056: int expected = Decision.RULE_ACCEPT;
057:
058: applyTest(max, urlString, expected);
059: }
060:
061: public void testFileWithQuestionMarkZeroAllowed() throws Exception {
062: String urlString = "http://j-spider.sourceforge.net/index.html?";
063: int max = 0;
064: int expected = Decision.RULE_ACCEPT;
065:
066: applyTest(max, urlString, expected);
067: }
068:
069: public void testNoParamsZeroAllowed() throws Exception {
070: String urlString = "http://j-spider.sourceforge.net";
071: int max = 0;
072: int expected = Decision.RULE_ACCEPT;
073:
074: applyTest(max, urlString, expected);
075: }
076:
077: public void testSingleParam() throws Exception {
078: String urlString = "http://j-spider.sourceforge.net/index.html?param=value";
079: int max = 10;
080: int expected = Decision.RULE_ACCEPT;
081:
082: applyTest(max, urlString, expected);
083: }
084:
085: public void testSingleParamOneAllowed() throws Exception {
086: String urlString = "http://j-spider.sourceforge.net/index.html?param=value";
087: int max = 1;
088: int expected = Decision.RULE_ACCEPT;
089:
090: applyTest(max, urlString, expected);
091: }
092:
093: public void testSingleParamZeroAllowed() throws Exception {
094: String urlString = "http://j-spider.sourceforge.net/index.html?param=value";
095: int max = 0;
096: int expected = Decision.RULE_IGNORE;
097:
098: applyTest(max, urlString, expected);
099: }
100:
101: public void testWithParams() throws Exception {
102: String urlString = "http://j-spider.sourceforge.net/index.html?param=value¶m2=value2";
103: int max = 10;
104: int expected = Decision.RULE_ACCEPT;
105:
106: applyTest(max, urlString, expected);
107: }
108:
109: public void testWithParamsOnBoundary() throws Exception {
110: String urlString = "http://j-spider.sourceforge.net/index.html?param=value¶m2=value2";
111: int max = 2;
112: int expected = Decision.RULE_ACCEPT;
113:
114: applyTest(max, urlString, expected);
115: }
116:
117: public void testWithParamsViolation() throws Exception {
118: String urlString = "http://j-spider.sourceforge.net/index.html?param=value¶m2=value2¶m3=value3";
119: int max = 2;
120: int expected = Decision.RULE_IGNORE;
121:
122: applyTest(max, urlString, expected);
123: }
124:
125: public void applyTest(int max, String urlString, int expected)
126: throws Exception {
127: config.setValue(MaxNumberOfURLParamsRule.MAX, new Integer(max));
128: URL url = new URL(urlString);
129: Rule rule = new MaxNumberOfURLParamsRule(config);
130: Decision decision = rule.apply(null, null, url);
131: assertEquals("decision not as expected", expected, decision
132: .getDecision());
133: }
134:
135: }
|