01: /*****************************************************************************
02: * Copyright (C) NanoContainer Organization. All rights reserved. *
03: * ------------------------------------------------------------------------- *
04: * The software in this package is published under the terms of the BSD *
05: * style license a copy of which has been included with this distribution in *
06: * the LICENSE.txt file. *
07: * *
08: * Original code by Paul Hammant *
09: *****************************************************************************/package org.nanocontainer.reflection;
10:
11: import org.nanocontainer.NanoPicoContainer;
12: import org.picocontainer.MutablePicoContainer;
13: import org.picocontainer.PicoContainer;
14: import org.picocontainer.tck.AbstractPicoContainerTestCase;
15:
16: /**
17: * @author Paul Hammant
18: * @version $Revision: 2962 $
19: */
20: public class DefaultNanoPicoContainerTestCase extends
21: AbstractPicoContainerTestCase {
22:
23: protected MutablePicoContainer createPicoContainer(
24: PicoContainer parent) {
25: return new DefaultNanoPicoContainer(this .getClass()
26: .getClassLoader(), parent);
27: }
28:
29: // TODO - go to a Nano TCK?
30: public void testNamedChildContainerIsAccessible() {
31: StringBuffer sb = new StringBuffer();
32: final NanoPicoContainer parent = (NanoPicoContainer) createPicoContainer(null);
33: parent.registerComponentInstance(sb);
34: final NanoPicoContainer child = (NanoPicoContainer) parent
35: .makeChildContainer("foo");
36: child.registerComponentImplementation(
37: LifeCycleMonitoring.class, LifeCycleMonitoring.class);
38: LifeCycleMonitoring o = (LifeCycleMonitoring) parent
39: .getComponentInstance("foo/*"
40: + LifeCycleMonitoring.class.getName());
41: assertNotNull(o);
42: }
43:
44: // TODO - go to a Nano TCK?
45: public void testNamedChildContainerIsAccessibleForStringKeys() {
46: StringBuffer sb = new StringBuffer();
47: final NanoPicoContainer parent = (NanoPicoContainer) createPicoContainer(null);
48: parent.registerComponentInstance(sb);
49: final MutablePicoContainer child = parent
50: .makeChildContainer("foo");
51: child.registerComponentImplementation("lcm",
52: LifeCycleMonitoring.class);
53: Object o = parent.getComponentInstance("foo/lcm");
54: assertNotNull(o);
55: assertTrue(sb.toString().indexOf("-instantiated") != -1);
56: }
57:
58: // TODO - go to a Nano TCK?
59: public void testNamedChildContainerIsAccessibleForClassKeys() {
60: StringBuffer sb = new StringBuffer();
61: final NanoPicoContainer parent = (NanoPicoContainer) createPicoContainer(null);
62: parent.registerComponentInstance(sb);
63: final MutablePicoContainer child = parent
64: .makeChildContainer("foo");
65: child.registerComponentImplementation(
66: LifeCycleMonitoring.class, LifeCycleMonitoring.class);
67: Object o = parent.getComponentInstance("foo/*"
68: + LifeCycleMonitoring.class.getName());
69: assertNotNull(o);
70: assertTrue(sb.toString().indexOf("-instantiated") != -1);
71: }
72:
73: public void testMakeRemoveChildContainer() {
74: final NanoPicoContainer parent = (NanoPicoContainer) createPicoContainer(null);
75: parent.registerComponentInstance("java.lang.String",
76: "This is a test");
77: MutablePicoContainer pico = parent.makeChildContainer();
78: // Verify they are indeed wired together.
79: assertNotNull(pico.getComponentInstance("java.lang.String"));
80: boolean result = parent.removeChildContainer(pico);
81: assertTrue(result);
82: }
83:
84: // test methods inherited. This container is otherwise fully compliant.
85:
86: }
|