Source code: hivemind/test/config/TestConversion.java
1 // Copyright 2004, 2005 The Apache Software Foundation
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package hivemind.test.config;
16
17 import hivemind.test.FrameworkTestCase;
18
19 import java.util.List;
20
21 import org.apache.hivemind.Registry;
22 import org.apache.hivemind.ServiceImplementationFactory;
23
24 /**
25 * Tests for the <conversion> and <map> elements
26 * within a module deployment descriptor.
27 *
28 * TODO: test {@link org.apache.hivemind.parse.ConversionDescriptor#setParentMethodName(String)}.
29 *
30 * @author Howard Lewis Ship
31 */
32 public class TestConversion extends FrameworkTestCase
33 {
34 public void testBasics() throws Exception
35 {
36 Registry r = buildFrameworkRegistry("Basics.xml");
37
38 List l = r.getConfiguration("hivemind.test.config.Basics");
39
40 assertEquals(1, l.size());
41
42 DataItem d = (DataItem) l.get(0);
43
44 assertEquals("builder", d.getName());
45 assertEquals(5, d.getCount());
46
47 ServiceImplementationFactory builderFactory =
48 (ServiceImplementationFactory) r.getService(
49 "hivemind.BuilderFactory",
50 ServiceImplementationFactory.class);
51
52 assertSame(builderFactory, d.getFactory());
53 }
54
55 public void testParentMethod() throws Exception
56 {
57 Registry r = buildFrameworkRegistry("ConversionParentMethod.xml");
58
59 List l = r.getConfiguration("hivemind.test.config.ConversionParentMethod");
60
61 assertEquals(1, l.size());
62
63 DataItem d = (DataItem) l.get(0);
64
65 assertEquals("builder", d.getName());
66 assertEquals(5, d.getCount());
67
68 ServiceImplementationFactory builderFactory =
69 (ServiceImplementationFactory) r.getService(
70 "hivemind.BuilderFactory",
71 ServiceImplementationFactory.class);
72
73 assertSame(builderFactory, d.getFactory());
74 }
75
76 public void testPropertyNameDefaultsToAttributeName() throws Exception
77 {
78 Registry r = buildFrameworkRegistry("Basics2.xml");
79
80 List l = r.getConfiguration("hivemind.test.config.Basics2");
81
82 assertEquals(1, l.size());
83
84 DataItem d = (DataItem) l.get(0);
85
86 assertEquals("underworld", d.getName());
87 assertEquals(18, d.getCount());
88
89 ServiceImplementationFactory builderFactory =
90 (ServiceImplementationFactory) r.getService(
91 "hivemind.BuilderFactory",
92 ServiceImplementationFactory.class);
93
94 assertSame(builderFactory, d.getFactory());
95 }
96
97 public void testComplexAttributeName() throws Exception
98 {
99 Registry r = buildFrameworkRegistry("ComplexAttributeName.xml");
100
101 List l = r.getConfiguration("hivemind.test.config.ComplexAttributeName");
102
103 assertEquals(1, l.size());
104
105 ComplexNameItem cni = (ComplexNameItem) l.get(0);
106
107 assertEquals("fred", cni.getComplexAttributeName());
108 }
109
110 public void testExtraAttributeNames() throws Exception
111 {
112 interceptLogging();
113
114 Registry r = buildFrameworkRegistry("ExtraAttributeNames.xml");
115
116 assertLoggedMessagePattern(
117 "Mappings for unknown attribute\\(s\\) \\[extra\\] "
118 + "\\(for element data-item\\) have been ignored\\.");
119
120 List l = r.getConfiguration("hivemind.test.config.ExtraAttributeNames");
121
122 assertEquals(1, l.size());
123
124 DataItem d = (DataItem) l.get(0);
125
126 assertEquals("lamb", d.getName());
127 assertEquals(95, d.getCount());
128
129 ServiceImplementationFactory builderFactory =
130 (ServiceImplementationFactory) r.getService(
131 "hivemind.BuilderFactory",
132 ServiceImplementationFactory.class);
133
134 assertSame(builderFactory, d.getFactory());
135 }
136
137 public void testDuplicateAttribute() throws Exception
138 {
139 interceptLogging();
140
141 Registry r = buildFrameworkRegistry("DuplicateAttribute.xml");
142
143 assertLoggedMessagePattern(
144 "Mapping for attribute item-name conflicts with a previous "
145 + "mapping \\(at .*\\) and has been ignored\\.");
146
147 List l = r.getConfiguration("hivemind.test.config.DuplicateAttribute");
148
149 assertEquals(1, l.size());
150
151 DataItem d = (DataItem) l.get(0);
152
153 assertEquals("wesley", d.getName());
154 assertEquals(15, d.getCount());
155
156 ServiceImplementationFactory builderFactory =
157 (ServiceImplementationFactory) r.getService(
158 "hivemind.BuilderFactory",
159 ServiceImplementationFactory.class);
160
161 assertSame(builderFactory, d.getFactory());
162 }
163 }