001: package net.javacoding.jspider.mod.rule;
002:
003: import junit.framework.TestCase;
004: import net.javacoding.jspider.spi.Rule;
005: import net.javacoding.jspider.mockobjects.OverridingPropertySet;
006: import net.javacoding.jspider.api.model.Decision;
007:
008: import java.net.URL;
009:
010: /**
011: * $Id: BoundedDepthRuleTest.java,v 1.1 2003/04/07 15:51:05 vanrogu Exp $
012: */
013: public class BoundedDepthRuleTest extends TestCase {
014:
015: OverridingPropertySet config;
016:
017: public BoundedDepthRuleTest() {
018: super ("BoundedDepthRuleTest");
019: }
020:
021: protected void setUp() throws Exception {
022: config = new OverridingPropertySet(null);
023: }
024:
025: public void testSimple() throws Exception {
026: int min = 0;
027: int max = 0;
028: String urlString = "http://j-spider.sourceforge.net/test.html";
029: int expected = Decision.RULE_ACCEPT;
030:
031: applyTest(min, max, urlString, expected);
032: }
033:
034: public void testMaxOK() throws Exception {
035: int min = 0;
036: int max = 3;
037: String urlString = "http://j-spider.sourceforge.net/test/abc/index.html";
038: int expected = Decision.RULE_ACCEPT;
039:
040: applyTest(min, max, urlString, expected);
041: }
042:
043: public void testMaxOnBoundary() throws Exception {
044: int min = 0;
045: int max = 2;
046: String urlString = "http://j-spider.sourceforge.net/test/abc/index.html";
047: int expected = Decision.RULE_ACCEPT;
048:
049: applyTest(min, max, urlString, expected);
050: }
051:
052: public void testMaxError() throws Exception {
053: int min = 0;
054: int max = 1;
055: String urlString = "http://j-spider.sourceforge.net/test/abc/index.html";
056: int expected = Decision.RULE_IGNORE;
057:
058: applyTest(min, max, urlString, expected);
059: }
060:
061: public void testMinOK() throws Exception {
062: int min = 2;
063: int max = 999;
064: String urlString = "http://j-spider.sourceforge.net/test/abc/def/index.html";
065: int expected = Decision.RULE_ACCEPT;
066:
067: applyTest(min, max, urlString, expected);
068: }
069:
070: public void testMinOnBoundary() throws Exception {
071: int min = 3;
072: int max = 999;
073: String urlString = "http://j-spider.sourceforge.net/test/abc/def/index.html";
074: int expected = Decision.RULE_ACCEPT;
075:
076: applyTest(min, max, urlString, expected);
077: }
078:
079: public void testBothOnBoundary() throws Exception {
080: int min = 3;
081: int max = 3;
082: String urlString = "http://j-spider.sourceforge.net/test/abc/def/index.html";
083: int expected = Decision.RULE_ACCEPT;
084:
085: applyTest(min, max, urlString, expected);
086: }
087:
088: public void testMinError() throws Exception {
089: int min = 4;
090: int max = 999;
091: String urlString = "http://j-spider.sourceforge.net/test/abc/def/index.html";
092: int expected = Decision.RULE_IGNORE;
093:
094: applyTest(min, max, urlString, expected);
095: }
096:
097: public void applyTest(int min, int max, String urlString,
098: int expected) throws Exception {
099: URL url = new URL(urlString);
100: config.setValue(BoundedDepthRule.MIN_DEPTH, new Integer(min));
101: config.setValue(BoundedDepthRule.MAX_DEPTH, new Integer(max));
102: Rule rule = new BoundedDepthRule(config);
103: Decision decision = rule.apply(null, null, url);
104: assertEquals("wrong decision taken on url", expected, decision
105: .getDecision());
106: }
107:
108: }
|