KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.javacoding.jspider.mod.rule;
2
3 import junit.framework.TestCase;
4 import net.javacoding.jspider.mockobjects.OverridingPropertySet;
5 import net.javacoding.jspider.spi.Rule;
6 import net.javacoding.jspider.api.model.Decision;
7
8 import java.net.URL JavaDoc;
9
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 JavaDoc {
22         config = new OverridingPropertySet(null);
23     }
24
25     public void testSimple ( ) throws Exception JavaDoc {
26         String JavaDoc path="/forbidden";
27         String JavaDoc 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 JavaDoc {
33         String JavaDoc path="/forbidden";
34         String JavaDoc 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 JavaDoc {
40         String JavaDoc path="/";
41         String JavaDoc 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 JavaDoc {
47         String JavaDoc path="/";
48         String JavaDoc 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 JavaDoc {
54         String JavaDoc path="/";
55         String JavaDoc urlString="http://j-spider.sourceforge.net/";
56         int expected = Decision.RULE_FORBIDDEN;
57         applyTest(path, urlString, expected);
58     }
59
60     public void applyTest ( String JavaDoc path, String JavaDoc urlString, int expected ) throws Exception JavaDoc {
61         URL JavaDoc url = new URL JavaDoc(urlString);
62         config.setValue(ForbiddenPathRule.PATH, path);
63         Rule rule = new ForbiddenPathRule(config) ;
64         Decision decision = rule.apply(null, null, url);
65         assertEquals("wrong decision taken on url", expected, decision.getDecision() );
66     }
67
68 }
69
Popular Tags