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

搜索引擎

开发平台:

Java

  1. package net.javacoding.jspider.mod.rule;
  2. import junit.framework.TestCase;
  3. import net.javacoding.jspider.mockobjects.OverridingPropertySet;
  4. import net.javacoding.jspider.spi.Rule;
  5. import net.javacoding.jspider.api.model.Decision;
  6. import java.net.URL;
  7. /**
  8.  * $Id: ForbiddenPathRuleTest.java,v 1.1 2003/04/07 15:51:05 vanrogu Exp $
  9.  */
  10. public class ForbiddenPathRuleTest extends TestCase {
  11.     OverridingPropertySet config;
  12.     public ForbiddenPathRuleTest ( ) {
  13.         super ( "ForbiddenPathRuleTest" );
  14.     }
  15.     protected void setUp() throws Exception {
  16.         config = new OverridingPropertySet(null);
  17.     }
  18.     public void testSimple ( ) throws Exception {
  19.         String path="/forbidden";
  20.         String urlString="http://j-spider.sourceforge.net/test/index.html";
  21.         int expected = Decision.RULE_DONTCARE;
  22.         applyTest(path, urlString, expected);
  23.     }
  24.     public void testForbidden ( ) throws Exception {
  25.         String path="/forbidden";
  26.         String urlString="http://j-spider.sourceforge.net/forbidden/index.html";
  27.         int expected = Decision.RULE_FORBIDDEN;
  28.         applyTest(path, urlString, expected);
  29.     }
  30.     public void testForbiddenRoot ( ) throws Exception {
  31.         String path="/";
  32.         String urlString="http://j-spider.sourceforge.net/forbidden/index.html";
  33.         int expected = Decision.RULE_FORBIDDEN;
  34.         applyTest(path, urlString, expected);
  35.     }
  36.     public void testForbiddenRootHomePage ( ) throws Exception {
  37.         String path="/";
  38.         String urlString="http://j-spider.sourceforge.net";
  39.         int expected = Decision.RULE_FORBIDDEN;
  40.         applyTest(path, urlString, expected);
  41.     }
  42.     public void testForbiddenRootHomePageWithSlash ( ) throws Exception {
  43.         String path="/";
  44.         String urlString="http://j-spider.sourceforge.net/";
  45.         int expected = Decision.RULE_FORBIDDEN;
  46.         applyTest(path, urlString, expected);
  47.     }
  48.     public void applyTest ( String path, String urlString, int expected ) throws Exception {
  49.         URL url = new URL(urlString);
  50.         config.setValue(ForbiddenPathRule.PATH, path);
  51.         Rule rule = new ForbiddenPathRule(config) ;
  52.         Decision decision = rule.apply(null, null, url);
  53.         assertEquals("wrong decision taken on url", expected, decision.getDecision() );
  54.     }
  55. }