domainscopetest.java

来自「一个搜索引擎,希望对大家有用」· Java 代码 · 共 148 行

JAVA
148
字号
/* * TestDomianScope * * $Id: DomainScopeTest.java,v 1.6 2005/07/18 17:29:53 stack-sf Exp $ * * Created on May 17, 2004 * * Copyright (C) 2004 Internet Archive. * * This file is part of the Heritrix web crawler (crawler.archive.org). * * Heritrix is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * any later version. * * Heritrix is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU Lesser Public License for more details. * * You should have received a copy of the GNU Lesser Public License * along with Heritrix; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */package org.archive.crawler.scope;import java.util.ArrayList;import java.util.Iterator;import junit.framework.TestCase;import org.apache.commons.httpclient.URIException;import org.archive.net.UURIFactory;/** * Test the domain scope focus filter. * * @author Igor Ranitovic */public class DomainScopeTest extends TestCase {    private ArrayList testSeeds;    private ArrayList urlsInScope;    private ArrayList urlsOutOfScope;    private TestUnitDomainScope dc;    /**     * Since testing only focus filter overwrite all other filter to return     * false.     *     * Also override seedsIterator so the test seeds are used.     */    private class TestUnitDomainScope extends DomainScope {        public TestUnitDomainScope(String name) {            super(name);        }                /* Force test seeds to be used.          * @see org.archive.crawler.framework.CrawlScope#seedsIterator()         */        public Iterator seedsIterator() {            return testSeeds.iterator();        }                protected boolean additionalFocusAccepts(Object o) {            return false;        }        protected boolean transitiveAccepts(Object o) {            return false;        }        protected boolean excludeAccepts(Object o) {            return false;        }    }    public void setUp() throws URIException {        testSeeds = new ArrayList();        urlsInScope = new ArrayList();        urlsOutOfScope = new ArrayList();        dc = new TestUnitDomainScope("TESTCASE");        // Add seeds        addURL(testSeeds, "http://www.a.com/");        addURL(testSeeds, "http://b.com/");        addURL(testSeeds, "http://www11.c.com");        addURL(testSeeds, "http://www.x.y.z.com/index.html");        addURL(testSeeds, "http://www.1.com/index.html");        addURL(testSeeds, "http://www.a_b.com/index.html");        // Add urls in domain scope        addURL(urlsInScope, "http://www.a.com/");        addURL(urlsInScope, "http://www1.a.com/");        addURL(urlsInScope, "http://a.com/");        addURL(urlsInScope, "http://a.a.com/");        addURL(urlsInScope, "http://www.b.com/");        addURL(urlsInScope, "http://www1.b.com/");        addURL(urlsInScope, "http://b.com/");        addURL(urlsInScope, "http://b.b.com/");        addURL(urlsInScope, "http://www.c.com/");        addURL(urlsInScope, "http://www1.c.com/");        addURL(urlsInScope, "http://c.com/");        addURL(urlsInScope, "http://c.c.com/");        addURL(urlsInScope, "http://www.x.y.z.com/");        addURL(urlsInScope, "http://www1.x.y.z.com/");        addURL(urlsInScope, "http://x.y.z.com/");        addURL(urlsInScope, "http://xyz.x.y.z.com/");        addURL(urlsInScope, "http://1.com/index.html");        addURL(urlsInScope, "http://a_b.com/index.html");        // Add urls out of scope        addURL(urlsOutOfScope, "http://a.co");        addURL(urlsOutOfScope, "http://a.comm");        addURL(urlsOutOfScope, "http://aa.com");        addURL(urlsOutOfScope, "http://z.com");        addURL(urlsOutOfScope, "http://y.z.com");    }    public void addURL(ArrayList list, String url) throws URIException {        list.add(UURIFactory.getInstance(url));    }    public void testInScope() throws URIException {        for (Iterator i = this.urlsInScope.iterator(); i.hasNext();) {            Object url = i.next();            assertTrue("Should be in domain scope: " + url, dc.accepts(url));        }    }    public void testOutOfScope() throws URIException {        for (Iterator i = this.urlsOutOfScope.iterator(); i.hasNext();) {            Object url = i.next();            assertFalse(                "Should not be in domain scope: " + url,                dc.accepts(url));        }    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?