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

搜索引擎

开发平台:

Java

  1. /**
  2.  * $Id: ExternallyReferencedOnlyRuleTest.java,v 1.4 2003/04/11 16:37:09 vanrogu Exp $
  3.  */
  4. package net.javacoding.jspider.mod.rule;
  5. import junit.framework.TestCase;
  6. import net.javacoding.jspider.api.model.Decision;
  7. import net.javacoding.jspider.api.model.Site;
  8. import net.javacoding.jspider.core.SpiderContext;
  9. import net.javacoding.jspider.core.model.SiteInternal;
  10. import net.javacoding.jspider.spi.Rule;
  11. import net.javacoding.jspider.mockobjects.SimpleSpiderContext;
  12. import net.javacoding.jspider.mod.rule.ExternallyReferencedOnlyRule;
  13. import java.net.URL;
  14. public class ExternallyReferencedOnlyRuleTest extends TestCase {
  15.     protected Rule rule;
  16.     protected SpiderContext context;
  17.     protected Site jspiderSite;
  18.     protected Site otherSite;
  19.     public ExternallyReferencedOnlyRuleTest ( ) {
  20.         super ( "ExternallyReferencedOnlyRuleTest" );
  21.     }
  22.     protected void setUp() throws Exception {
  23.         rule = new ExternallyReferencedOnlyRule();
  24.         URL jspiderUrl = new URL ( "http://j-spider.sourceforge.net");
  25.         jspiderSite = new SiteInternal(0, null, jspiderUrl);
  26.         URL otherUrl = new URL ( "http://www.javacoding.net");
  27.         otherSite = new SiteInternal(0, null, otherUrl);
  28.         context = new SimpleSpiderContext(jspiderUrl);
  29.     }
  30.     public void testBaseSiteInternal ( ) throws Exception {
  31.         URL url = new URL ( "http://j-spider.sourceforge.net/some/doc.html");
  32.         Decision decision = rule.apply(context, jspiderSite, url);
  33.         assertEquals("resource within same site not ignored", Decision.RULE_IGNORE, decision.getDecision());
  34.     }
  35.     public void testBaseSiteExternal ( ) throws Exception {
  36.         URL url = new URL ( "http://j-spider.sourceforge.net/some/doc.html");
  37.         Decision decision = rule.apply(context, otherSite, url);
  38.         assertEquals("resource within other site not accepted", Decision.RULE_ACCEPT, decision.getDecision());
  39.     }
  40.     public void testNonBaseSiteInternal ( ) throws Exception {
  41.         URL url = new URL ( "http://www.javacoding.net/some/doc.html");
  42.         Decision decision = rule.apply(context, otherSite, url);
  43.         assertEquals("resource within same site not ignored", Decision.RULE_IGNORE, decision.getDecision());
  44.     }
  45.     public void testNonBaseSiteExternal ( ) throws Exception {
  46.         URL url = new URL ( "http://www.javacoding.net/some/doc.html");
  47.         Decision decision = rule.apply(context, jspiderSite, url);
  48.         assertEquals("resource within other site not accepted", Decision.RULE_ACCEPT, decision.getDecision());
  49.     }
  50.     public void testNullSiteURL ( ) throws Exception {
  51.         URL url = new URL ( "http://www.javacoding.net/some/doc.html");
  52.         Decision decision = rule.apply(context, null, url);
  53.         assertEquals("resource reffed from 'null' site not DONTCARE", Decision.RULE_DONTCARE, decision.getDecision());
  54.     }
  55. }