KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nanocontainer > script > xml > NonMutablePicoContainerContainerTestCase


1 /*****************************************************************************
2  * Copyright (C) NanoContainer Organization. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  * *
8  * Original code by Aslak Hellesoy and Paul Hammant *
9  *****************************************************************************/

10
11 package org.nanocontainer.script.xml;
12
13 import org.nanocontainer.integrationkit.PicoCompositionException;
14 import org.nanocontainer.script.AbstractScriptedContainerBuilderTestCase;
15 import org.nanocontainer.testmodel.DefaultWebServerConfig;
16 import org.picocontainer.ComponentAdapter;
17 import org.picocontainer.PicoContainer;
18 import org.picocontainer.PicoException;
19 import org.picocontainer.PicoVerificationException;
20 import org.picocontainer.PicoVisitor;
21 import org.picocontainer.defaults.DefaultPicoContainer;
22 import org.xml.sax.SAXException JavaDoc;
23
24 import javax.xml.parsers.ParserConfigurationException JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.io.Reader JavaDoc;
27 import java.io.StringReader JavaDoc;
28 import java.util.Collection JavaDoc;
29 import java.util.List JavaDoc;
30
31 /**
32  * @author Maarten Grootendorst
33  * @version $Revision: 1731 $
34  */

35
36 // TODO to rename?
37
public class NonMutablePicoContainerContainerTestCase extends AbstractScriptedContainerBuilderTestCase {
38
39     private class TestPicoContainer implements PicoContainer {
40         public Object JavaDoc getComponentInstance(Object JavaDoc componentKey) {
41             return null;
42         }
43
44         public Object JavaDoc getComponentInstanceOfType(Class JavaDoc componentType) {
45             return null;
46         }
47
48         public List JavaDoc getComponentInstances() {
49             return null;
50         }
51
52         public PicoContainer getParent() {
53             return null;
54         }
55
56         public ComponentAdapter getComponentAdapter(Object JavaDoc componentKey) {
57             return null;
58         }
59
60         public ComponentAdapter getComponentAdapterOfType(Class JavaDoc componentType) {
61             return null;
62         }
63
64         public Collection JavaDoc getComponentAdapters() {
65             return null;
66         }
67
68         /**
69      * @deprecated since 1.1 - Use new VerifyingVisitor().traverse(this)
70          */

71        public void verify() throws PicoVerificationException {
72         }
73
74         public void addOrderedComponentAdapter(ComponentAdapter componentAdapter) {
75         }
76
77         public List JavaDoc getComponentInstancesOfType(Class JavaDoc type) throws PicoException {
78             return null;
79         }
80
81         public void accept(PicoVisitor containerVisitor) {
82         }
83
84         public List JavaDoc getComponentAdaptersOfType(Class JavaDoc componentType) {
85             return null;
86         }
87
88         public void start() {
89         }
90
91         public void stop() {
92         }
93
94         public void dispose() {
95         }
96
97     }
98
99     public void testCreateSimpleContainerWithPicoContainer() throws ParserConfigurationException JavaDoc, SAXException JavaDoc, IOException JavaDoc, ClassNotFoundException JavaDoc, PicoCompositionException {
100         Reader JavaDoc script = new StringReader JavaDoc("" +
101                 "<container>" +
102                 " <component-implementation class='org.nanocontainer.testmodel.DefaultWebServerConfig'/>" +
103                 " <component-implementation key='org.nanocontainer.testmodel.WebServer' class='org.nanocontainer.testmodel.WebServerImpl'/>" +
104                 "</container>");
105
106         PicoContainer pico = buildContainer(new XMLContainerBuilder(script, getClass().getClassLoader()), new TestPicoContainer(), "SOME_SCOPE");
107         assertEquals(2, pico.getComponentInstances().size());
108         assertNotNull(pico.getComponentInstance(DefaultWebServerConfig.class));
109     }
110
111     public void testCreateSimpleContainerWithMutablePicoContainer() throws ParserConfigurationException JavaDoc, SAXException JavaDoc, IOException JavaDoc, ClassNotFoundException JavaDoc, PicoCompositionException {
112         Reader JavaDoc script = new StringReader JavaDoc("" +
113                 "<container>" +
114                 " <component-implementation class='org.nanocontainer.testmodel.DefaultWebServerConfig'/>" +
115                 " <component-implementation key='org.nanocontainer.testmodel.WebServer' class='org.nanocontainer.testmodel.WebServerImpl'/>" +
116                 "</container>");
117
118         PicoContainer pico = buildContainer(new XMLContainerBuilder(script, getClass().getClassLoader()), new DefaultPicoContainer(), "SOME_SCOPE");
119         assertEquals(2, pico.getComponentInstances().size());
120         assertNotNull(pico.getComponentInstance(DefaultWebServerConfig.class));
121         assertNotNull(pico.getParent());
122
123     }
124 }
125
Popular Tags