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

搜索引擎

开发平台:

Java

  1. package net.javacoding.jspider.mod.rule;
  2. import junit.framework.TestCase;
  3. import net.javacoding.jspider.spi.Rule;
  4. import net.javacoding.jspider.api.model.Decision;
  5. import java.net.URL;
  6. /**
  7.  * $Id: NoURLParamsRuleTest.java,v 1.1 2003/04/07 15:51:06 vanrogu Exp $
  8.  */
  9. public class NoURLParamsRuleTest extends TestCase {
  10.     protected Rule rule;
  11.     public NoURLParamsRuleTest ( ) {
  12.       super ( "NoURLParamsRuleTest" );
  13.     }
  14.     protected void setUp() throws Exception {
  15.         rule = new NoURLParamsRule();
  16.     }
  17.     public void testNoParams ( ) throws Exception {
  18.         String urlString = "http://j-spider.sourceforge.net/index.html";
  19.         int expected = Decision.RULE_ACCEPT;
  20.         applyTest ( urlString, expected);
  21.     }
  22.     public void testRootNoParams ( ) throws Exception {
  23.         String urlString = "http://j-spider.sourceforge.net";
  24.         int expected = Decision.RULE_ACCEPT;
  25.         applyTest ( urlString, expected);
  26.     }
  27.     public void testRootNoParamsWithSlash ( ) throws Exception {
  28.         String urlString = "http://j-spider.sourceforge.net/";
  29.         int expected = Decision.RULE_ACCEPT;
  30.         applyTest ( urlString, expected);
  31.     }
  32.     public void testSingleParam ( ) throws Exception {
  33.         String urlString = "http://j-spider.sourceforge.net/index.html?param=value";
  34.         int expected = Decision.RULE_IGNORE;
  35.         applyTest ( urlString, expected);
  36.     }
  37.     public void testDoubleParam ( ) throws Exception {
  38.         String urlString = "http://j-spider.sourceforge.net/index.html?param=value&param2=value2";
  39.         int expected = Decision.RULE_IGNORE;
  40.         applyTest ( urlString, expected);
  41.     }
  42.     public void testQuestionMarkOnly ( ) throws Exception {
  43.         String urlString = "http://j-spider.sourceforge.net/index.html?";
  44.         int expected = Decision.RULE_ACCEPT;
  45.         applyTest ( urlString, expected);
  46.     }
  47.     public void testQuestionMarkOnlyOnFolder ( ) throws Exception {
  48.         String urlString = "http://j-spider.sourceforge.net/test?";
  49.         int expected = Decision.RULE_ACCEPT;
  50.         applyTest ( urlString, expected);
  51.     }
  52.     public void testQuestionMarkOnlyOnFolderWithSlash ( ) throws Exception {
  53.         String urlString = "http://j-spider.sourceforge.net/test/?";
  54.         int expected = Decision.RULE_ACCEPT;
  55.         applyTest ( urlString, expected);
  56.     }
  57.     public void applyTest ( String urlString, int expected ) throws Exception {
  58.         URL url = new URL(urlString);
  59.         Decision decision = rule.apply(null,null,url);
  60.         assertEquals("decision not as expected", expected, decision.getDecision());
  61.     }
  62. }