001: /* OverrideTest
002: *
003: * $Id: OverrideTest.java 2168 2004-05-28 22:33:09Z stack-sf $
004: *
005: * Created on Feb 20, 2004
006: *
007: * Copyright (C) 2004 Internet Archive.
008: *
009: * This file is part of the Heritrix web crawler (crawler.archive.org).
010: *
011: * Heritrix is free software; you can redistribute it and/or modify it under the
012: * terms of the GNU Lesser Public License as published by the Free Software
013: * Foundation; either version 2.1 of the License, or any later version.
014: *
015: * Heritrix is distributed in the hope that it will be useful, but WITHOUT ANY
016: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
017: * A PARTICULAR PURPOSE. See the GNU Lesser Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser Public License along with
020: * Heritrix; if not, write to the Free Software Foundation, Inc., 59 Temple
021: * Place, Suite 330, Boston, MA 02111-1307 USA
022: */
023: package org.archive.crawler.settings;
024:
025: import javax.management.AttributeNotFoundException;
026: import javax.management.InvalidAttributeValueException;
027: import javax.management.MBeanException;
028: import javax.management.ReflectionException;
029:
030: import org.archive.crawler.datamodel.CrawlOrder;
031: import org.archive.crawler.framework.Processor;
032:
033: /**
034: * Test the concept of overrides.
035: *
036: * As this test is testing a concept, it involves more than one class to be
037: * tested. Thus the name of this test doesn't match a class name.
038: *
039: * @author John Erik Halse
040: *
041: */
042: public class OverrideTest extends SettingsFrameworkTestCase {
043:
044: /*
045: * @see SettingsFrameworkTestCase#setUp()
046: */
047: protected void setUp() throws Exception {
048: super .setUp();
049: }
050:
051: /*
052: * @see SettingsFrameworkTestCase#tearDown()
053: */
054: protected void tearDown() throws Exception {
055: super .tearDown();
056: }
057:
058: public void testOverridingOfGlobalAttribute()
059: throws AttributeNotFoundException, MBeanException,
060: ReflectionException, InvalidAttributeValueException {
061:
062: final String MODULE_NAME = "module1";
063: ModuleType module1 = new ModuleType(MODULE_NAME);
064: ModuleType module2 = new Processor(MODULE_NAME, "Descr");
065:
066: // Set up override
067: MapType headers = (MapType) getSettingsHandler().getOrder()
068: .getAttribute(CrawlOrder.ATTR_HTTP_HEADERS);
069: headers.addElement(getGlobalSettings(), module1);
070: headers.setAttribute(getPerDomainSettings(), module2);
071:
072: // Read back values to see if we get the right ones
073: ModuleType getMod;
074: getMod = (ModuleType) headers.getAttribute(getGlobalSettings(),
075: MODULE_NAME);
076: assertSame("Wrong global value", module1, getMod);
077: assertEquals("Wrong class type", module1.getClass().getName(),
078: headers.getAttributeInfo(getGlobalSettings(),
079: MODULE_NAME).getType());
080:
081: getMod = (ModuleType) headers.getAttribute(
082: getPerDomainSettings(), MODULE_NAME);
083: assertSame("Wrong domain value", module2, getMod);
084: assertEquals("Wrong class type", module2.getClass().getName(),
085: headers.getAttributeInfo(getPerDomainSettings(),
086: MODULE_NAME).getType());
087:
088: getMod = (ModuleType) headers.getAttribute(
089: getPerHostSettings(), MODULE_NAME);
090: assertSame("Wrong host value", module2, getMod);
091: assertEquals("Wrong class type", module2.getClass().getName(),
092: headers.getAttributeInfo(getPerHostSettings(),
093: MODULE_NAME).getType());
094: }
095:
096: public void testOverridingOfNonGlobalAttribute()
097: throws AttributeNotFoundException, MBeanException,
098: ReflectionException, InvalidAttributeValueException {
099: final String MODULE_NAME = "module1";
100: ModuleType module1 = new ModuleType(MODULE_NAME);
101: ModuleType module2 = new Processor(MODULE_NAME, "Descr");
102:
103: // Set up override
104: MapType headers = (MapType) getSettingsHandler().getOrder()
105: .getAttribute(CrawlOrder.ATTR_HTTP_HEADERS);
106: headers.addElement(getPerDomainSettings(), module1);
107: headers.setAttribute(getPerHostSettings(), module2);
108:
109: // Read back values to see if we get the right ones
110: ModuleType getMod;
111: try {
112: getMod = (ModuleType) headers.getAttribute(
113: getGlobalSettings(), MODULE_NAME);
114: fail("Global value should not exist");
115: } catch (AttributeNotFoundException e) {
116: // OK! this should throw an exception;
117: }
118:
119: getMod = (ModuleType) headers.getAttribute(
120: getPerDomainSettings(), MODULE_NAME);
121: assertSame("Wrong domain value", module1, getMod);
122: assertEquals("Wrong class type", module1.getClass().getName(),
123: headers.getAttributeInfo(getPerDomainSettings(),
124: MODULE_NAME).getType());
125:
126: getMod = (ModuleType) headers.getAttribute(
127: getPerHostSettings(), MODULE_NAME);
128: assertSame("Wrong host value", module2, getMod);
129: assertEquals("Wrong class type", module2.getClass().getName(),
130: headers.getAttributeInfo(getPerHostSettings(),
131: MODULE_NAME).getType());
132: }
133:
134: }
|