1 package net.javacoding.jspider.mod.rule; 2 3 import net.javacoding.jspider.api.model.Decision; 4 import net.javacoding.jspider.mockobjects.OverridingPropertySet; 5 import net.javacoding.jspider.spi.Rule; 6 import net.javacoding.jspider.core.util.config.ConfigurationFactory; 7 8 import java.net.URL ; 9 10 import junit.framework.TestCase; 11 12 15 public class MaxNumberOfURLParamsRuleTest extends TestCase { 16 17 protected OverridingPropertySet config; 18 19 public MaxNumberOfURLParamsRuleTest ( ) { 20 super ( "MaxNumberOfURLParamsRuleTest" ); 21 } 22 23 protected void setUp() throws Exception { 24 ConfigurationFactory.getConfiguration(ConfigurationFactory.CONFIG_UNITTEST); 25 config = new OverridingPropertySet ( null ); 26 } 27 28 public void testNoParams ( ) throws Exception { 29 String urlString = "http://j-spider.sourceforge.net"; 30 int max = 10; 31 int expected = Decision.RULE_ACCEPT; 32 33 applyTest ( max, urlString, expected ); 34 } 35 36 public void testQuestionMarkOneAllowed ( ) throws Exception { 37 String urlString = "http://j-spider.sourceforge.net?"; 38 int max = 1; 39 int expected = Decision.RULE_ACCEPT; 40 41 applyTest ( max, urlString, expected ); 42 } 43 44 public void testFileWithQuestionMarkOneAllowed ( ) throws Exception { 45 String urlString = "http://j-spider.sourceforge.net/index.html?"; 46 int max = 1; 47 int expected = Decision.RULE_ACCEPT; 48 49 applyTest ( max, urlString, expected ); 50 } 51 52 public void testQuestionMarkZeroAllowed ( ) throws Exception { 53 String urlString = "http://j-spider.sourceforge.net?"; 54 int max = 0; 55 int expected = Decision.RULE_ACCEPT; 56 57 applyTest ( max, urlString, expected ); 58 } 59 60 public void testFileWithQuestionMarkZeroAllowed ( ) throws Exception { 61 String urlString = "http://j-spider.sourceforge.net/index.html?"; 62 int max = 0; 63 int expected = Decision.RULE_ACCEPT; 64 65 applyTest ( max, urlString, expected ); 66 } 67 68 public void testNoParamsZeroAllowed ( ) throws Exception { 69 String urlString = "http://j-spider.sourceforge.net"; 70 int max = 0; 71 int expected = Decision.RULE_ACCEPT; 72 73 applyTest ( max, urlString, expected ); 74 } 75 76 public void testSingleParam ( ) throws Exception { 77 String urlString = "http://j-spider.sourceforge.net/index.html?param=value"; 78 int max = 10; 79 int expected = Decision.RULE_ACCEPT; 80 81 applyTest ( max, urlString, expected ); 82 } 83 84 public void testSingleParamOneAllowed ( ) throws Exception { 85 String urlString = "http://j-spider.sourceforge.net/index.html?param=value"; 86 int max = 1; 87 int expected = Decision.RULE_ACCEPT; 88 89 applyTest ( max, urlString, expected ); 90 } 91 92 public void testSingleParamZeroAllowed ( ) throws Exception { 93 String urlString = "http://j-spider.sourceforge.net/index.html?param=value"; 94 int max = 0; 95 int expected = Decision.RULE_IGNORE; 96 97 applyTest ( max, urlString, expected ); 98 } 99 100 public void testWithParams ( ) throws Exception { 101 String urlString = "http://j-spider.sourceforge.net/index.html?param=value¶m2=value2"; 102 int max = 10; 103 int expected = Decision.RULE_ACCEPT; 104 105 applyTest ( max, urlString, expected ); 106 } 107 108 public void testWithParamsOnBoundary ( ) throws Exception { 109 String urlString = "http://j-spider.sourceforge.net/index.html?param=value¶m2=value2"; 110 int max = 2; 111 int expected = Decision.RULE_ACCEPT; 112 113 applyTest ( max, urlString, expected ); 114 } 115 116 public void testWithParamsViolation ( ) throws Exception { 117 String urlString = "http://j-spider.sourceforge.net/index.html?param=value¶m2=value2¶m3=value3"; 118 int max = 2; 119 int expected = Decision.RULE_IGNORE; 120 121 applyTest ( max, urlString, expected ); 122 } 123 124 125 public void applyTest ( int max, String urlString, int expected ) throws Exception { 126 config.setValue(MaxNumberOfURLParamsRule.MAX, new Integer (max)); 127 URL url = new URL ( urlString ); 128 Rule rule = new MaxNumberOfURLParamsRule(config); 129 Decision decision = rule.apply(null, null, url); 130 assertEquals("decision not as expected", expected, decision.getDecision()); 131 } 132 133 } 134 | Popular Tags |