⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 credentialstoretest.java

📁 最强的爬虫工程
💻 JAVA
字号:
/* CredentialStoreTest * * Created on Apr 1, 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.datamodel;import java.lang.reflect.InvocationTargetException;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import java.util.logging.Logger;import javax.management.AttributeNotFoundException;import javax.management.InvalidAttributeValueException;import javax.management.MBeanException;import javax.management.ReflectionException;import org.archive.crawler.datamodel.credential.Credential;import org.archive.crawler.settings.CrawlerSettings;import org.archive.crawler.settings.SettingsFrameworkTestCase;/** * Test add, edit, delete from credential store. * * @author stack * @version $Revision: 1.8 $, $Date: 2004/05/28 22:32:59 $ */public class CredentialStoreTest extends SettingsFrameworkTestCase {    protected static Logger logger =        Logger.getLogger("org.archive.crawler.datamodel.CredentialTest");    final public void testCredentials()        throws InvalidAttributeValueException, IllegalArgumentException,        InvocationTargetException, AttributeNotFoundException, MBeanException,        ReflectionException {        CredentialStore store = (CredentialStore)this.settingsHandler.            getOrder().getAttribute(CredentialStore.ATTR_NAME);        writeCrendentials(store, this.getGlobalSettings(), "global");        writeCrendentials(store, this.getPerDomainSettings(), "domain");        writeCrendentials(store, this.getPerHostSettings(), "host");        List types = CredentialStore.getCredentialTypes();        List globalNames = checkContextNames(store.iterator(            this.getGlobalSettings()), types.size());        checkContextNames(store.iterator(this.getPerDomainSettings()),            types.size() * 2 /*This should be global + domain*/);        checkContextNames(store.iterator(this.getPerHostSettings()),            types.size() * 3 /*This should be global + domain + host*/);        for (Iterator i = globalNames.iterator();                i.hasNext();) {            store.remove(this.getGlobalSettings(),(String)i.next());        }        // Should be only host and domain objects at deepest scope.        checkContextNames(store.iterator(this.getPerHostSettings()),           types.size() * 2);    }    private List checkContextNames(Iterator i, int size) {        List names = new ArrayList(size);        for (; i.hasNext();) {            String name = ((Credential)i.next()).getName();            names.add(name);        }        logger.info("Added: " + names.toString());        assertTrue("Not enough names, size " + size, size == names.size());        return names;    }    private void writeCrendentials(CredentialStore store, CrawlerSettings context,                String prefix)        throws InvalidAttributeValueException, AttributeNotFoundException,        IllegalArgumentException, InvocationTargetException {        List types = CredentialStore.getCredentialTypes();        for (Iterator i = types.iterator(); i.hasNext();) {            Class cl = (Class)i.next();            Credential c = store.create(context, prefix + "." + cl.getName(),                cl);            assertNotNull("Failed create of " + cl, c);            logger.info("Created " + c.getName());        }        List names = new ArrayList(types.size());        for (Iterator i = store.iterator(null); i.hasNext();) {            names.add(((Credential)i.next()).getName());        }        getSettingsHandler().writeSettingsObject(context);    }}

⌨️ 快捷键说明

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