01: // Copyright 2006, 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // 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 org.apache.tapestry.ioc;
16:
17: import java.util.Arrays;
18: import java.util.List;
19: import java.util.jar.Manifest;
20:
21: import org.apache.tapestry.ioc.test.IOCTestCase;
22: import org.testng.annotations.Test;
23:
24: public class RegistryBuilderTest extends IOCTestCase {
25: @Test
26: public void sub_module() {
27: RegistryBuilder builder = new RegistryBuilder();
28:
29: builder.add(MasterModule.class);
30:
31: Registry r = builder.build();
32:
33: // Borrowed from IntegrationTest, this will only work if both FredModule and BarneyModule
34: // are loaded.
35:
36: NameListHolder service = r.getService("UnorderedNames",
37: NameListHolder.class);
38:
39: List<String> names = service.getNames();
40:
41: assertEquals(names, Arrays.asList("Beta", "Gamma",
42: "UnorderedNames"));
43: }
44:
45: @Test
46: public void manifest() {
47: RegistryBuilder builder = new RegistryBuilder();
48:
49: String value = String.format("%s, %s, %s", FredModule.class
50: .getName(), BarneyModule.class.getName(),
51: RegistryBuilderTestModule.class.getName());
52:
53: Manifest mf = new Manifest();
54:
55: mf.getMainAttributes().putValue(
56: IOCConstants.MODULE_BUILDER_MANIFEST_ENTRY_NAME, value);
57:
58: // A package private method. Add in the two modules as if they were listed in the manifest.
59:
60: IOCUtilities.addModulesInManifest(builder, mf);
61:
62: Registry registry = builder.build();
63:
64: Square service = registry.getService(Square.class);
65:
66: assertEquals(service.square(4), 16l);
67:
68: // This proves that the IOC works, the service builder method was invoked, that the
69: // ClassFactory service was accessed and used.
70:
71: assertEquals(service.toString(),
72: "<Proxy for Square(org.apache.tapestry.ioc.Square)>");
73: }
74: }
|