MaxNumberOfURLParamsRuleTest.java
上传用户:qing5858
上传日期:2015-10-27
资源大小:6056k
文件大小:4k
源码类别:

搜索引擎

开发平台:

Java

  1. package net.javacoding.jspider.mod.rule;
  2. import net.javacoding.jspider.api.model.Decision;
  3. import net.javacoding.jspider.mockobjects.OverridingPropertySet;
  4. import net.javacoding.jspider.spi.Rule;
  5. import net.javacoding.jspider.core.util.config.ConfigurationFactory;
  6. import java.net.URL;
  7. import junit.framework.TestCase;
  8. /**
  9.  * $Id: MaxNumberOfURLParamsRuleTest.java,v 1.1 2003/04/07 15:51:05 vanrogu Exp $
  10.  */
  11. public class MaxNumberOfURLParamsRuleTest extends TestCase {
  12.     protected OverridingPropertySet config;
  13.     public MaxNumberOfURLParamsRuleTest ( ) {
  14.         super ( "MaxNumberOfURLParamsRuleTest" );
  15.     }
  16.     protected void setUp() throws Exception {
  17.         ConfigurationFactory.getConfiguration(ConfigurationFactory.CONFIG_UNITTEST);
  18.         config = new OverridingPropertySet ( null );
  19.     }
  20.     public void testNoParams ( ) throws Exception {
  21.         String urlString = "http://j-spider.sourceforge.net";
  22.         int max = 10;
  23.         int expected = Decision.RULE_ACCEPT;
  24.         applyTest ( max, urlString, expected );
  25.     }
  26.     public void testQuestionMarkOneAllowed ( ) throws Exception {
  27.         String urlString = "http://j-spider.sourceforge.net?";
  28.         int max = 1;
  29.         int expected = Decision.RULE_ACCEPT;
  30.         applyTest ( max, urlString, expected );
  31.     }
  32.     public void testFileWithQuestionMarkOneAllowed ( ) throws Exception {
  33.         String urlString = "http://j-spider.sourceforge.net/index.html?";
  34.         int max = 1;
  35.         int expected = Decision.RULE_ACCEPT;
  36.         applyTest ( max, urlString, expected );
  37.     }
  38.     public void testQuestionMarkZeroAllowed ( ) throws Exception {
  39.         String urlString = "http://j-spider.sourceforge.net?";
  40.         int max = 0;
  41.         int expected = Decision.RULE_ACCEPT;
  42.         applyTest ( max, urlString, expected );
  43.     }
  44.     public void testFileWithQuestionMarkZeroAllowed ( ) throws Exception {
  45.         String urlString = "http://j-spider.sourceforge.net/index.html?";
  46.         int max = 0;
  47.         int expected = Decision.RULE_ACCEPT;
  48.         applyTest ( max, urlString, expected );
  49.     }
  50.     public void testNoParamsZeroAllowed ( ) throws Exception {
  51.         String urlString = "http://j-spider.sourceforge.net";
  52.         int max = 0;
  53.         int expected = Decision.RULE_ACCEPT;
  54.         applyTest ( max, urlString, expected );
  55.     }
  56.     public void testSingleParam ( ) throws Exception {
  57.         String urlString = "http://j-spider.sourceforge.net/index.html?param=value";
  58.         int max = 10;
  59.         int expected = Decision.RULE_ACCEPT;
  60.         applyTest ( max, urlString, expected );
  61.     }
  62.     public void testSingleParamOneAllowed ( ) throws Exception {
  63.         String urlString = "http://j-spider.sourceforge.net/index.html?param=value";
  64.         int max = 1;
  65.         int expected = Decision.RULE_ACCEPT;
  66.         applyTest ( max, urlString, expected );
  67.     }
  68.     public void testSingleParamZeroAllowed ( ) throws Exception {
  69.         String urlString = "http://j-spider.sourceforge.net/index.html?param=value";
  70.         int max = 0;
  71.         int expected = Decision.RULE_IGNORE;
  72.         applyTest ( max, urlString, expected );
  73.     }
  74.     public void testWithParams ( ) throws Exception {
  75.         String urlString = "http://j-spider.sourceforge.net/index.html?param=value&param2=value2";
  76.         int max = 10;
  77.         int expected = Decision.RULE_ACCEPT;
  78.         applyTest ( max, urlString, expected );
  79.     }
  80.     public void testWithParamsOnBoundary ( ) throws Exception {
  81.         String urlString = "http://j-spider.sourceforge.net/index.html?param=value&param2=value2";
  82.         int max = 2;
  83.         int expected = Decision.RULE_ACCEPT;
  84.         applyTest ( max, urlString, expected );
  85.     }
  86.     public void testWithParamsViolation ( ) throws Exception {
  87.         String urlString = "http://j-spider.sourceforge.net/index.html?param=value&param2=value2&param3=value3";
  88.         int max = 2;
  89.         int expected = Decision.RULE_IGNORE;
  90.         applyTest ( max, urlString, expected );
  91.     }
  92.     public void applyTest ( int max, String urlString, int expected ) throws Exception {
  93.         config.setValue(MaxNumberOfURLParamsRule.MAX, new Integer(max));
  94.         URL url = new URL ( urlString );
  95.         Rule rule = new MaxNumberOfURLParamsRule(config);
  96.         Decision decision = rule.apply(null, null, url);
  97.         assertEquals("decision not as expected", expected, decision.getDecision());
  98.     }
  99. }