KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hivemind > test > rules > TestConfigurationTranslator


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.rules;
16
17 import hivemind.test.config.impl.Datum;
18
19 import java.util.List JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import org.apache.hivemind.Registry;
23 import org.apache.hivemind.internal.Module;
24 import org.apache.hivemind.schema.rules.ConfigurationTranslator;
25 import org.apache.hivemind.xml.XmlTestCase;
26
27 /**
28  * Tests for {@link org.apache.hivemind.schema.rules.ConfigurationTranslator}.
29  *
30  * @author Howard Lewis Ship
31  */

32 public class TestConfigurationTranslator extends XmlTestCase
33 {
34
35     public void testNull()
36     {
37         Module m = (Module) newMock(Module.class);
38
39         replayControls();
40         ConfigurationTranslator t = new ConfigurationTranslator();
41
42         assertNull(t.translate(m, null, null, null));
43
44         verifyControls();
45     }
46
47     public void testConfigurationTranslator() throws Exception JavaDoc
48     {
49         Registry r = buildFrameworkRegistry("ConfigurationTranslator.xml");
50
51         DatumHolder h = (DatumHolder) r.getService(
52                 "hivemind.test.rules.ExtensionPointTranslator",
53                 DatumHolder.class);
54         List JavaDoc l1 = h.getDatums();
55         List JavaDoc l2 = (List JavaDoc) r.getConfiguration("hivemind.test.rules.EP");
56
57         assertSame(l2, l1);
58     }
59
60     public void testFailure() throws Exception JavaDoc
61     {
62         Registry r = buildFrameworkRegistry("ConfigurationTranslator.xml");
63
64         interceptLogging("hivemind.test.rules");
65
66         DatumHolder h = (DatumHolder) r
67                 .getService("hivemind.test.rules.Failure", DatumHolder.class);
68
69         // Force creation of service, and thus the error.
70

71         h.getDatums();
72
73         assertLoggedMessagePattern("Configuration point hivemind\\.test\\.rules\\.missing does not exist\\.");
74
75         assertNull(h.getDatums());
76     }
77
78     public void testMappedConfigurationTranslator() throws Exception JavaDoc
79     {
80         Registry r = buildFrameworkRegistry("ConfigurationTranslator.xml");
81
82         MappedDatumHolder h = (MappedDatumHolder) r.getService(
83                 "hivemind.test.rules.MappedExtensionPointTranslator",
84                 MappedDatumHolder.class);
85         Map JavaDoc m1 = h.getDatums();
86
87         assertEquals(2, m1.size());
88         assertEquals("value1", ((Datum) m1.get("key1")).getValue());
89         assertEquals("value2", ((Datum) m1.get("key2")).getValue());
90     }
91 }
Popular Tags