Package org.picocontainer

Examples of org.picocontainer.MutablePicoContainer.registerComponentInstance()


            String className = (String) classValue;
            key = key == null ? className : key;
            parentContainer.registerComponentImplementation(key, className, parameterArray);
        } else if (instance != null) {
            key = key == null ? instance.getClass() : key;
            pico.registerComponentInstance(key, instance);
        } else {
            throw new NanoContainerMarkupException("Must specify a class attribute for a component as a class name (string) or Class. Attributes:" + attributes);
        }

        return this.getNodeName();
View Full Code Here


        ObjectReference parentRef = new SimpleReference();
        MutablePicoContainer parent = new DefaultPicoContainer();

        Mock parentStartable = mock(Startable.class);
        parent.registerComponentInstance(parentStartable.proxy());
        parentRef.set(parent);

        ObjectReference childRef = new SimpleReference();

        builder.buildContainer(childRef, parentRef, null, true);
View Full Code Here

public class DefaultContainerRecorderTestCase extends TestCase {
    public void testInvocationsCanBeRecordedAndReplayedOnADifferentContainerInstance() throws Exception {
        ContainerRecorder recorder = new DefaultContainerRecorder(new DefaultNanoPicoContainer());
        MutablePicoContainer recorded = recorder.getContainerProxy();

        recorded.registerComponentInstance("fruit", "apple");
        recorded.registerComponentInstance("int", new Integer(239));
        recorded.registerComponentImplementation("thing",
                ThingThatTakesParamsInConstructor.class,
                new Parameter[]{
                    ComponentParameter.DEFAULT,
View Full Code Here

    public void testInvocationsCanBeRecordedAndReplayedOnADifferentContainerInstance() throws Exception {
        ContainerRecorder recorder = new DefaultContainerRecorder(new DefaultNanoPicoContainer());
        MutablePicoContainer recorded = recorder.getContainerProxy();

        recorded.registerComponentInstance("fruit", "apple");
        recorded.registerComponentInstance("int", new Integer(239));
        recorded.registerComponentImplementation("thing",
                ThingThatTakesParamsInConstructor.class,
                new Parameter[]{
                    ComponentParameter.DEFAULT,
                    ComponentParameter.DEFAULT,
View Full Code Here

    }

    public void testRecorderWorksAfterSerialization() throws IOException, ClassNotFoundException, IllegalAccessException, InvocationTargetException {
        ContainerRecorder recorder = new DefaultContainerRecorder(new DefaultPicoContainer());
        MutablePicoContainer recorded = recorder.getContainerProxy();
        recorded.registerComponentInstance("fruit", "apple");

        ContainerRecorder serializedRecorder = (ContainerRecorder) serializeAndDeserialize(recorder);
        MutablePicoContainer slave = new DefaultPicoContainer();
        serializedRecorder.replay(slave);
        assertEquals("apple", slave.getComponentInstance("fruit"));
View Full Code Here

*/
public class GroovyScriptGeneratorTestCase extends TestCase {
    public void testShouldWriteAGroovyScriptThatAllowsToRecreateASimilarContainer() {
        MutablePicoContainer pico = new DefaultPicoContainer();
        pico.registerComponentImplementation(ArrayList.class);
        pico.registerComponentInstance("Hello", "World");

        GroovyScriptGenerator groovyScriptGenerator = new GroovyScriptGenerator();
        String script = groovyScriptGenerator.generateScript(pico);

        GroovyContainerBuilder groovyContainerBuilder = new GroovyContainerBuilder(new StringReader(script), getClass().getClassLoader());
View Full Code Here

    }
   
   
    private ContainerBuilder createContainerBuilder(Class containerBuilder, String script) {
        MutablePicoContainer pico = new DefaultPicoContainer();
        pico.registerComponentInstance(new StringReader(script));
        pico.registerComponentInstance(getClass().getClassLoader());
        pico.registerComponentImplementation(containerBuilder);
        return (ContainerBuilder)pico.getComponentInstanceOfType(ContainerBuilder.class);
    }
View Full Code Here

   
   
    private ContainerBuilder createContainerBuilder(Class containerBuilder, String script) {
        MutablePicoContainer pico = new DefaultPicoContainer();
        pico.registerComponentInstance(new StringReader(script));
        pico.registerComponentInstance(getClass().getClassLoader());
        pico.registerComponentImplementation(containerBuilder);
        return (ContainerBuilder)pico.getComponentInstanceOfType(ContainerBuilder.class);
    }

    public void testSessionDestroyedMethodIsIgnored() {
View Full Code Here

        actionFactory.getAction(request, mapping1, servlet);
    }

    public void testGetActionWhenActionsContainerAlreadyExists() {
        MutablePicoContainer requestContainer = new DefaultPicoContainer();
        requestContainer.registerComponentInstance(TestService.class, service);
        MutablePicoContainer actionsContainer = new DefaultPicoContainer(requestContainer);

        requestMock.stubs().method("getAttribute").with(eq(KeyConstants.ACTIONS_CONTAINER)).will(
                returnValue(actionsContainer));
View Full Code Here

        assertSame(servlet, action2.getServlet());
    }

    public void testRequestContainerExists() {
        MutablePicoContainer requestContainer = new DefaultPicoContainer();
        requestContainer.registerComponentInstance(TestService.class, service);

        requestMock.expects(once()).method("getAttribute").with(eq(KeyConstants.ACTIONS_CONTAINER)).will(
                returnValue(null));
        requestMock.expects(once()).method("getAttribute").with(eq(KeyConstants.REQUEST_CONTAINER)).will(
                returnValue(requestContainer));
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.