1 package net.javacoding.jspider.mod.rule; 2 3 import junit.framework.TestCase; 4 import net.javacoding.jspider.spi.Rule; 5 import net.javacoding.jspider.api.model.Decision; 6 7 import java.net.URL ; 8 9 12 public class NoURLParamsRuleTest extends TestCase { 13 14 protected Rule rule; 15 16 public NoURLParamsRuleTest ( ) { 17 super ( "NoURLParamsRuleTest" ); 18 } 19 20 protected void setUp() throws Exception { 21 rule = new NoURLParamsRule(); 22 } 23 24 public void testNoParams ( ) throws Exception { 25 String urlString = "http://j-spider.sourceforge.net/index.html"; 26 int expected = Decision.RULE_ACCEPT; 27 28 applyTest ( urlString, expected); 29 } 30 31 public void testRootNoParams ( ) throws Exception { 32 String urlString = "http://j-spider.sourceforge.net"; 33 int expected = Decision.RULE_ACCEPT; 34 35 applyTest ( urlString, expected); 36 } 37 38 public void testRootNoParamsWithSlash ( ) throws Exception { 39 String urlString = "http://j-spider.sourceforge.net/"; 40 int expected = Decision.RULE_ACCEPT; 41 42 applyTest ( urlString, expected); 43 } 44 45 public void testSingleParam ( ) throws Exception { 46 String urlString = "http://j-spider.sourceforge.net/index.html?param=value"; 47 int expected = Decision.RULE_IGNORE; 48 49 applyTest ( urlString, expected); 50 } 51 52 public void testDoubleParam ( ) throws Exception { 53 String urlString = "http://j-spider.sourceforge.net/index.html?param=value¶m2=value2"; 54 int expected = Decision.RULE_IGNORE; 55 56 applyTest ( urlString, expected); 57 } 58 59 public void testQuestionMarkOnly ( ) throws Exception { 60 String urlString = "http://j-spider.sourceforge.net/index.html?"; 61 int expected = Decision.RULE_ACCEPT; 62 63 applyTest ( urlString, expected); 64 } 65 66 public void testQuestionMarkOnlyOnFolder ( ) throws Exception { 67 String urlString = "http://j-spider.sourceforge.net/test?"; 68 int expected = Decision.RULE_ACCEPT; 69 70 applyTest ( urlString, expected); 71 } 72 73 public void testQuestionMarkOnlyOnFolderWithSlash ( ) throws Exception { 74 String urlString = "http://j-spider.sourceforge.net/test/?"; 75 int expected = Decision.RULE_ACCEPT; 76 77 applyTest ( urlString, expected); 78 } 79 80 public void applyTest ( String urlString, int expected ) throws Exception { 81 URL url = new URL (urlString); 82 Decision decision = rule.apply(null,null,url); 83 assertEquals("decision not as expected", expected, decision.getDecision()); 84 } 85 86 } 87 | Popular Tags |