1 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 ; 23 24 import javax.xml.parsers.ParserConfigurationException ; 25 import java.io.IOException ; 26 import java.io.Reader ; 27 import java.io.StringReader ; 28 import java.util.Collection ; 29 import java.util.List ; 30 31 35 36 public class NonMutablePicoContainerContainerTestCase extends AbstractScriptedContainerBuilderTestCase { 38 39 private class TestPicoContainer implements PicoContainer { 40 public Object getComponentInstance(Object componentKey) { 41 return null; 42 } 43 44 public Object getComponentInstanceOfType(Class componentType) { 45 return null; 46 } 47 48 public List getComponentInstances() { 49 return null; 50 } 51 52 public PicoContainer getParent() { 53 return null; 54 } 55 56 public ComponentAdapter getComponentAdapter(Object componentKey) { 57 return null; 58 } 59 60 public ComponentAdapter getComponentAdapterOfType(Class componentType) { 61 return null; 62 } 63 64 public Collection getComponentAdapters() { 65 return null; 66 } 67 68 71 public void verify() throws PicoVerificationException { 72 } 73 74 public void addOrderedComponentAdapter(ComponentAdapter componentAdapter) { 75 } 76 77 public List getComponentInstancesOfType(Class type) throws PicoException { 78 return null; 79 } 80 81 public void accept(PicoVisitor containerVisitor) { 82 } 83 84 public List getComponentAdaptersOfType(Class 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 , SAXException , IOException , ClassNotFoundException , PicoCompositionException { 100 Reader script = new StringReader ("" + 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 , SAXException , IOException , ClassNotFoundException , PicoCompositionException { 112 Reader script = new StringReader ("" + 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 |