    001    /*****************************************************************************
    002     * Copyright (C) NanoContainer Organization. All rights reserved.            *
    003     * ------------------------------------------------------------------------- *
    004     * The software in this package is published under the terms of the BSD      *
    005     * style license a copy of which has been included with this distribution in *
    006     * the LICENSE.txt file.                                                     *
    007     *                                                                           *
    008     * Original code by Aslak Hellesoy and Paul Hammant                          *
    009     *****************************************************************************/
    010
    011    package org.nanocontainer.script.xml;
    012
    013    import org.nanocontainer.integrationkit.PicoCompositionException;
    014    import org.nanocontainer.script.AbstractScriptedContainerBuilderTestCase;
    015    import org.nanocontainer.testmodel.DefaultWebServerConfig;
    016    import org.picocontainer.ComponentAdapter;
    017    import org.picocontainer.PicoContainer;
    018    import org.picocontainer.PicoException;
    019    import org.picocontainer.PicoVerificationException;
    020    import org.picocontainer.PicoVisitor;
    021    import org.picocontainer.defaults.DefaultPicoContainer;
    022    import org.xml.sax.SAXException;
    023
    024    import javax.xml.parsers.ParserConfigurationException;
    025    import java.io.IOException;
    026    import java.io.Reader;
    027    import java.io.StringReader;
    028    import java.util.Collection;
    029    import java.util.List;
    030
    031    /**
    032     * @author Maarten Grootendorst
    033     * @version $Revision: 1731 $
    034     */
    035
    036    // TODO to rename?
    037    public class NonMutablePicoContainerContainerTestCase extends AbstractScriptedContainerBuilderTestCase {
    038
    039        private class TestPicoContainer implements PicoContainer {
    040            public Object getComponentInstance(Object componentKey) {
    041                return null;
    042            }
    043
    044            public Object getComponentInstanceOfType(Class componentType) {
    045                return null;
    046            }
    047
    048            public List getComponentInstances() {
    049                return null;
    050            }
    051
    052            public PicoContainer getParent() {
    053                return null;
    054            }
    055
    056            public ComponentAdapter getComponentAdapter(Object componentKey) {
    057                return null;
    058            }
    059
    060            public ComponentAdapter getComponentAdapterOfType(Class componentType) {
    061                return null;
    062            }
    063
    064            public Collection getComponentAdapters() {
    065                return null;
    066            }
    067
    068            /**
    069         * @deprecated since 1.1 - Use new VerifyingVisitor().traverse(this)
    070             */
    071           public void verify() throws PicoVerificationException {
    072            }
    073
    074            public void addOrderedComponentAdapter(ComponentAdapter componentAdapter) {
    075            }
    076
    077            public List getComponentInstancesOfType(Class type) throws PicoException {
    078                return null;
    079            }
    080
    081            public void accept(PicoVisitor containerVisitor) {
    082            }
    083
    084            public List getComponentAdaptersOfType(Class componentType) {
    085                return null;
    086            }
    087
    088            public void start() {
    089            }
    090
    091            public void stop() {
    092            }
    093
    094            public void dispose() {
    095            }
    096
    097        }
    098
    099        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    }