KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hivemind > test > config > TestConversion


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 java.util.List JavaDoc;
18
19 import org.apache.hivemind.Registry;
20 import org.apache.hivemind.ServiceImplementationFactory;
21 import org.apache.hivemind.xml.XmlTestCase;
22
23 /**
24  * Tests for the <conversion> and <map> elements
25  * within a module deployment descriptor.
26  *
27  * TODO: test {@link org.apache.hivemind.parse.ConversionDescriptor#setParentMethodName(String)}.
28  *
29  * @author Howard Lewis Ship
30  */

31 public class TestConversion extends XmlTestCase
32 {
33     public void testBasics() throws Exception JavaDoc
34     {
35         Registry r = buildFrameworkRegistry("Basics.xml");
36
37         List JavaDoc l = (List JavaDoc) r.getConfiguration("hivemind.test.config.Basics");
38
39         assertEquals(1, l.size());
40
41         DataItem d = (DataItem) l.get(0);
42
43         assertEquals("builder", d.getName());
44         assertEquals(5, d.getCount());
45
46         ServiceImplementationFactory builderFactory =
47             (ServiceImplementationFactory) r.getService(
48                 "hivemind.BuilderFactory",
49                 ServiceImplementationFactory.class);
50
51         assertSame(builderFactory, d.getFactory());
52     }
53
54     public void testParentMethod() throws Exception JavaDoc
55     {
56         Registry r = buildFrameworkRegistry("ConversionParentMethod.xml");
57
58         List JavaDoc l = (List JavaDoc) r.getConfiguration("hivemind.test.config.ConversionParentMethod");
59
60         assertEquals(1, l.size());
61
62         DataItem d = (DataItem) l.get(0);
63
64         assertEquals("builder", d.getName());
65         assertEquals(5, d.getCount());
66
67         ServiceImplementationFactory builderFactory =
68             (ServiceImplementationFactory) r.getService(
69                 "hivemind.BuilderFactory",
70                 ServiceImplementationFactory.class);
71
72         assertSame(builderFactory, d.getFactory());
73     }
74
75     public void testPropertyNameDefaultsToAttributeName() throws Exception JavaDoc
76     {
77         Registry r = buildFrameworkRegistry("Basics2.xml");
78
79         List JavaDoc l = (List JavaDoc) r.getConfiguration("hivemind.test.config.Basics2");
80
81         assertEquals(1, l.size());
82
83         DataItem d = (DataItem) l.get(0);
84
85         assertEquals("underworld", d.getName());
86         assertEquals(18, d.getCount());
87
88         ServiceImplementationFactory builderFactory =
89             (ServiceImplementationFactory) r.getService(
90                 "hivemind.BuilderFactory",
91                 ServiceImplementationFactory.class);
92
93         assertSame(builderFactory, d.getFactory());
94     }
95
96     public void testComplexAttributeName() throws Exception JavaDoc
97     {
98         Registry r = buildFrameworkRegistry("ComplexAttributeName.xml");
99
100         List JavaDoc l = (List JavaDoc) r.getConfiguration("hivemind.test.config.ComplexAttributeName");
101
102         assertEquals(1, l.size());
103
104         ComplexNameItem cni = (ComplexNameItem) l.get(0);
105
106         assertEquals("fred", cni.getComplexAttributeName());
107     }
108
109     public void testExtraAttributeNames() throws Exception JavaDoc
110     {
111         interceptLogging();
112
113         Registry r = buildFrameworkRegistry("ExtraAttributeNames.xml");
114
115         assertLoggedMessagePattern(
116             "Mappings for unknown attribute\\(s\\) \\[extra\\] "
117                 + "\\(for element data-item\\) have been ignored\\.");
118
119         List JavaDoc l = (List JavaDoc) r.getConfiguration("hivemind.test.config.ExtraAttributeNames");
120
121         assertEquals(1, l.size());
122
123         DataItem d = (DataItem) l.get(0);
124
125         assertEquals("lamb", d.getName());
126         assertEquals(95, d.getCount());
127
128         ServiceImplementationFactory builderFactory =
129             (ServiceImplementationFactory) r.getService(
130                 "hivemind.BuilderFactory",
131                 ServiceImplementationFactory.class);
132
133         assertSame(builderFactory, d.getFactory());
134     }
135
136     public void testDuplicateAttribute() throws Exception JavaDoc
137     {
138         interceptLogging();
139
140         Registry r = buildFrameworkRegistry("DuplicateAttribute.xml");
141
142         assertLoggedMessagePattern(
143             "Mapping for attribute item-name conflicts with a previous "
144                 + "mapping \\(at .*\\) and has been ignored\\.");
145
146         List JavaDoc l = (List JavaDoc) r.getConfiguration("hivemind.test.config.DuplicateAttribute");
147
148         assertEquals(1, l.size());
149
150         DataItem d = (DataItem) l.get(0);
151
152         assertEquals("wesley", d.getName());
153         assertEquals(15, d.getCount());
154
155         ServiceImplementationFactory builderFactory =
156             (ServiceImplementationFactory) r.getService(
157                 "hivemind.BuilderFactory",
158                 ServiceImplementationFactory.class);
159
160         assertSame(builderFactory, d.getFactory());
161     }
162 }
163
Popular Tags