1 10 package org.nanocontainer.script.jython; 11 12 import org.nanocontainer.integrationkit.PicoCompositionException; 13 import org.nanocontainer.script.AbstractScriptedContainerBuilderTestCase; 14 import org.nanocontainer.testmodel.WebServer; 15 import org.nanocontainer.testmodel.WebServerImpl; 16 import org.picocontainer.PicoContainer; 17 import org.picocontainer.defaults.DefaultPicoContainer; 18 import org.picocontainer.defaults.UnsatisfiableDependenciesException; 19 20 import java.io.IOException ; 21 import java.io.Reader ; 22 import java.io.StringReader ; 23 24 28 public class JythonContainerBuilderTestCase extends AbstractScriptedContainerBuilderTestCase { 29 30 public void testSimpleConfigurationIsPossible() { 31 Reader script = new StringReader ("from org.nanocontainer.testmodel import *\n" + 32 "pico = DefaultNanoPicoContainer()\n" + 33 "pico.registerComponentImplementation(WebServerImpl)\n" + 34 "pico.registerComponentImplementation(DefaultWebServerConfig)\n"); 35 36 PicoContainer pico = buildContainer(new JythonContainerBuilder(script, getClass().getClassLoader()), null, "SOME_SCOPE"); 37 assertNotNull(pico.getComponentInstanceOfType(WebServer.class)); 38 } 39 40 public void testDependenciesAreUnsatisfiableByChildContainers() throws IOException , ClassNotFoundException , PicoCompositionException { 41 try { 42 Reader script = new StringReader ("" + 43 "from org.nanocontainer.testmodel import *\n" + 44 "pico = DefaultNanoPicoContainer()\n" + 45 "pico.registerComponentImplementation(WebServerImpl)\n" + 46 "childContainer = DefaultNanoPicoContainer(pico)\n" + 47 "childContainer.registerComponentImplementation(DefaultWebServerConfig)\n"); 48 PicoContainer pico = buildContainer(new JythonContainerBuilder(script, getClass().getClassLoader()), null, "SOME_SCOPE"); 49 pico.getComponentInstanceOfType(WebServer.class); 50 fail(); 51 } catch (UnsatisfiableDependenciesException expected) { 52 } 53 } 54 55 public void testDependenciesAreSatisfiableByParentContainer() throws IOException , ClassNotFoundException , PicoCompositionException { 56 Reader script = new StringReader ("" + 57 "from org.nanocontainer.testmodel import *\n" + 58 "pico = DefaultNanoPicoContainer()\n" + 59 "pico.registerComponentImplementation(DefaultWebServerConfig)\n" + 60 "child = pico.makeChildContainer()\n" + 61 "child.registerComponentImplementation(WebServerImpl)\n" + 62 "pico.registerComponentInstance('wayOfPassingSomethingToTestEnv', child.getComponentInstance(WebServerImpl))"); 63 PicoContainer pico = buildContainer(new JythonContainerBuilder(script, getClass().getClassLoader()), null, "SOME_SCOPE"); 64 WebServerImpl wsi = (WebServerImpl) pico.getComponentInstance("wayOfPassingSomethingToTestEnv"); 65 assertNotNull(wsi); 66 } 67 68 public void testContainerCanBeBuiltWithParent() { 69 Reader script = new StringReader ("" + 70 "pico = DefaultNanoPicoContainer(parent)\n"); 71 PicoContainer parent = new DefaultPicoContainer(); 72 PicoContainer pico = buildContainer(new JythonContainerBuilder(script, getClass().getClassLoader()), parent, "SOME_SCOPE"); 73 assertNotSame(parent, pico.getParent()); 75 } 76 77 } 78 | Popular Tags |