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 ; 9 10 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 { 22 config = new OverridingPropertySet(null); 23 } 24 25 public void testSimple ( ) throws Exception { 26 String path="/forbidden"; 27 String 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 { 33 String path="/forbidden"; 34 String 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 { 40 String path="/"; 41 String 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 { 47 String path="/"; 48 String 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 { 54 String path="/"; 55 String urlString="http://j-spider.sourceforge.net/"; 56 int expected = Decision.RULE_FORBIDDEN; 57 applyTest(path, urlString, expected); 58 } 59 60 public void applyTest ( String path, String urlString, int expected ) throws Exception { 61 URL url = new URL (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 |