1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.archive.crawler.settings;
24
25 import javax.management.AttributeNotFoundException;
26 import javax.management.InvalidAttributeValueException;
27 import javax.management.MBeanException;
28 import javax.management.ReflectionException;
29
30 import org.archive.crawler.datamodel.CrawlOrder;
31 import org.archive.crawler.framework.Processor;
32
33 /***
34 * Test the concept of overrides.
35 *
36 * As this test is testing a concept, it involves more than one class to be
37 * tested. Thus the name of this test doesn't match a class name.
38 *
39 * @author John Erik Halse
40 *
41 */
42 public class OverrideTest extends SettingsFrameworkTestCase {
43
44
45
46
47 protected void setUp() throws Exception {
48 super.setUp();
49 }
50
51
52
53
54 protected void tearDown() throws Exception {
55 super.tearDown();
56 }
57
58 public void testOverridingOfGlobalAttribute()
59 throws AttributeNotFoundException, MBeanException,
60 ReflectionException, InvalidAttributeValueException {
61
62 final String MODULE_NAME = "module1";
63 ModuleType module1 = new ModuleType(MODULE_NAME);
64 ModuleType module2 = new Processor(MODULE_NAME, "Descr");
65
66
67 MapType headers = (MapType) getSettingsHandler().getOrder()
68 .getAttribute(CrawlOrder.ATTR_HTTP_HEADERS);
69 headers.addElement(getGlobalSettings(), module1);
70 headers.setAttribute(getPerDomainSettings(), module2);
71
72
73 ModuleType getMod;
74 getMod = (ModuleType) headers.getAttribute(getGlobalSettings(),
75 MODULE_NAME);
76 assertSame("Wrong global value", module1, getMod);
77 assertEquals("Wrong class type", module1.getClass().getName(), headers
78 .getAttributeInfo(getGlobalSettings(), MODULE_NAME).getType());
79
80 getMod = (ModuleType) headers.getAttribute(getPerDomainSettings(),
81 MODULE_NAME);
82 assertSame("Wrong domain value", module2, getMod);
83 assertEquals("Wrong class type", module2.getClass().getName(), headers
84 .getAttributeInfo(getPerDomainSettings(), MODULE_NAME)
85 .getType());
86
87 getMod = (ModuleType) headers.getAttribute(getPerHostSettings(),
88 MODULE_NAME);
89 assertSame("Wrong host value", module2, getMod);
90 assertEquals("Wrong class type", module2.getClass().getName(), headers
91 .getAttributeInfo(getPerHostSettings(), MODULE_NAME).getType());
92 }
93
94 public void testOverridingOfNonGlobalAttribute()
95 throws AttributeNotFoundException, MBeanException,
96 ReflectionException, InvalidAttributeValueException {
97 final String MODULE_NAME = "module1";
98 ModuleType module1 = new ModuleType(MODULE_NAME);
99 ModuleType module2 = new Processor(MODULE_NAME, "Descr");
100
101
102 MapType headers = (MapType) getSettingsHandler().getOrder()
103 .getAttribute(CrawlOrder.ATTR_HTTP_HEADERS);
104 headers.addElement(getPerDomainSettings(), module1);
105 headers.setAttribute(getPerHostSettings(), module2);
106
107
108 ModuleType getMod;
109 try {
110 getMod = (ModuleType) headers.getAttribute(getGlobalSettings(),
111 MODULE_NAME);
112 fail("Global value should not exist");
113 } catch (AttributeNotFoundException e) {
114
115 }
116
117 getMod = (ModuleType) headers.getAttribute(getPerDomainSettings(),
118 MODULE_NAME);
119 assertSame("Wrong domain value", module1, getMod);
120 assertEquals("Wrong class type", module1.getClass().getName(), headers
121 .getAttributeInfo(getPerDomainSettings(), MODULE_NAME)
122 .getType());
123
124 getMod = (ModuleType) headers.getAttribute(getPerHostSettings(),
125 MODULE_NAME);
126 assertSame("Wrong host value", module2, getMod);
127 assertEquals("Wrong class type", module2.getClass().getName(), headers
128 .getAttributeInfo(getPerHostSettings(), MODULE_NAME).getType());
129 }
130
131 }