Package org.apache.tapestry.ioc

Examples of org.apache.tapestry.ioc.ObjectCreator


        train_isDebugEnabled(logger, false);

        replay();

        ObjectCreator sc = new ServiceBuilderMethodInvoker(resources, CREATOR_DESCRIPTION,
                                                           findMethod(fixture, "buildWithUnorderedConfiguration"));

        Object actual = sc.createObject();

        assertSame(actual, fixture._fie);

        verify();
    }
View Full Code Here


        train_isDebugEnabled(logger, false);

        replay();

        ObjectCreator sc = new ServiceBuilderMethodInvoker(resources, CREATOR_DESCRIPTION, method);

        try
        {
            sc.createObject();
            unreachable();
        }
        catch (RuntimeException ex)
        {
            Assert.assertEquals(ex.getMessage(), "Builder method " + CREATOR_DESCRIPTION
View Full Code Here

        train_isDebugEnabled(logger, false);

        replay();

        ObjectCreator sc = new ServiceBuilderMethodInvoker(resources, CREATOR_DESCRIPTION, method);

        try
        {
            sc.createObject();
            unreachable();
        }
        catch (RuntimeException ex)
        {
            assertEquals(ex.getMessage(), "Error invoking service builder method "
View Full Code Here

        train_isDebugEnabled(logger, false);

        replay();

        ObjectCreator sc = new ServiceBuilderMethodInvoker(resources, CREATOR_DESCRIPTION, method);

        Object actual = sc.createObject();

        verify();

        assertSame(actual, fixture._fie);
    }
View Full Code Here

    @Test
    public void ensure_only_called_once() throws Exception
    {
        Logger logger = mockLogger();
        ObjectCreatorSource source = mockObjectCreatorSource();
        ObjectCreator delegate = mockObjectCreator();
        Object service = new Object();

        ServiceDef def = new ServiceDefImpl(Runnable.class, "Bar", null, "singleton", false, source);

        train_createObject(delegate, service);

        train_getDescription(source, SOURCE_DESCRIPTION);

        replay();

        ObjectCreator wrapper = new RecursiveServiceCreationCheckWrapper(def, delegate, logger);

        assertSame(wrapper.createObject(), service);

        try
        {
            wrapper.createObject();
            unreachable();
        }
        catch (IllegalStateException ex)
        {
            assertMessageContains(
View Full Code Here

    public void reporting_of_construction_failure() throws Exception
    {
        RuntimeException failure = new RuntimeException("Just cranky.");
        Logger logger = mockLogger();
        ObjectCreatorSource source = mockObjectCreatorSource();
        ObjectCreator delegate = mockObjectCreator();
        Object service = new Object();

        ServiceDef def = new ServiceDefImpl(Runnable.class, "Bar", null, "singleton", false, source);

        expect(delegate.createObject()).andThrow(failure);

        logger.error("Construction of service Bar failed: Just cranky.", failure);

        replay();

        ObjectCreator wrapper = new RecursiveServiceCreationCheckWrapper(def, delegate, logger);

        try
        {
            wrapper.createObject();
            unreachable();
        }
        catch (RuntimeException ex)
        {
            assertSame(ex, failure);
        }

        verify();

        // Now test that the locked flag is not set and that the object may still be created.

        train_createObject(delegate, service);

        replay();

        assertSame(service, wrapper.createObject());

        verify();

    }
View Full Code Here

{
    @Test
    public void test()
    {
        ServiceResources resources = mockServiceResources();
        ObjectCreator creator = mockObjectCreator();
        Object expected = new Object();

        train_createObject(creator, expected);

        replay();
View Full Code Here

    private static final String SERVICE_ID = "foo.bar.Baz";

    @Test
    public void no_decorators()
    {
        ObjectCreator core = mockObjectCreator();
        Module module = mockModule();
        Object coreObject = new Object();
        List<ServiceDecorator> decorators = newList();

        train_createObject(core, coreObject);

        train_findDecoratorsForService(module, SERVICE_ID, decorators);

        replay();

        ObjectCreator isb = new InterceptorStackBuilder(module, SERVICE_ID, core);

        Object intercepted = isb.createObject();

        assertSame(intercepted, coreObject);

        verify();
    }
View Full Code Here

    }

    @Test
    public void decorator_returns_null_interceptor()
    {
        ObjectCreator core = mockObjectCreator();
        Module module = mockModule();
        Object coreObject = new Object();
        ServiceDecorator decorator = mockServiceDecorator();

        List<ServiceDecorator> decorators = asList(decorator);

        train_createObject(core, coreObject);

        train_findDecoratorsForService(module, SERVICE_ID, decorators);

        train_createInterceptor(decorator, coreObject, null);

        replay();

        ObjectCreator isb = new InterceptorStackBuilder(module, SERVICE_ID, core);

        Object intercepted = isb.createObject();

        assertSame(intercepted, coreObject);

        verify();
    }
View Full Code Here

    }

    @Test
    public void decorator_orderering()
    {
        ObjectCreator core = mockObjectCreator();
        Module module = mockModule();
        Object coreObject = new Object();
        Object interceptor1 = new Object();
        Object interceptor2 = new Object();
        ServiceDecorator decorator1 = mockServiceDecorator();
        ServiceDecorator decorator2 = mockServiceDecorator();

        List<ServiceDecorator> decorators = asList(decorator1, decorator2);

        train_createObject(core, coreObject);

        train_findDecoratorsForService(module, SERVICE_ID, decorators);

        // Notice: reverse order!

        train_createInterceptor(decorator2, coreObject, interceptor2);
        train_createInterceptor(decorator1, interceptor2, interceptor1);

        replay();

        ObjectCreator isb = new InterceptorStackBuilder(module, SERVICE_ID, core);

        Object intercepted = isb.createObject();

        assertSame(intercepted, interceptor1);

        verify();
    }
View Full Code Here

TOP

Related Classes of org.apache.tapestry.ioc.ObjectCreator

Copyright © 2018 www.massapicom. 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.