Package org.qi4j.bootstrap

Examples of org.qi4j.bootstrap.SingletonAssembler


    @Test
    public void newInstanceForRegisteredObjectPerformance()
        throws ActivationException, AssemblyException
    {
        SingletonAssembler assembler = new SingletonAssembler()
        {
            @Override
            public void assemble( ModuleAssembly module )
                throws AssemblyException
            {
                module.objects( AnyObject.class );
            }
        };
        ObjectFactory objectFactory = assembler.module();
        for( int i = 0; i < 10; i++ )
        {
            testPerformance( objectFactory );
        }
    }
View Full Code Here


    @Before
    public void setUp()
        throws Exception
    {
        SingletonAssembler assembly = new SingletonAssembler()
        {
            @Override
            public void assemble( ModuleAssembly module )
                throws AssemblyException
            {
                module.transients( HelloWorldComposite.class );
            }
        };
        TransientBuilderFactory builderFactory = assembly.module();
        TransientBuilder<HelloWorldComposite> builder = builderFactory.newTransientBuilder( HelloWorldComposite.class );
        builder.prototype().name().set( "Hello" );
        builder.prototype().phrase().set( "World" );
        helloWorld = builder.newInstance();
    }
View Full Code Here

    {
        // Set up version 1
        String id;
        StringInputOutput data_v1 = new StringInputOutput();
        {
            SingletonAssembler v1 = new SingletonAssembler()
            {
                @Override
                public void assemble( ModuleAssembly module )
                    throws AssemblyException
                {
                    MigrationTest.this.assemble( module );
                    module.layer().application().setVersion( "1.0" );
                }
            };

            UnitOfWork uow = v1.module().newUnitOfWork();
            TestEntity1_0 entity = uow.newEntity( TestEntity1_0.class );
            entity.foo().set( "Some value" );
            entity.fooManyAssoc().add( entity );
            entity.fooAssoc().set( entity );
            id = entity.identity().get();
            uow.complete();

            BackupRestore backupRestore = v1.module()
                .findService( BackupRestore.class )
                .get();
            backupRestore.backup().transferTo( data_v1 );
        }

        // Set up version 1.1
        StringInputOutput data_v1_1 = new StringInputOutput();
        {
            SingletonAssembler v1_1 = new SingletonAssembler()
            {
                @Override
                public void assemble( ModuleAssembly module )
                    throws AssemblyException
                {
                    MigrationTest.this.assemble( module );
                    module.layer().application().setVersion( "1.1" );
                }
            };

            BackupRestore testData = v1_1.module().findService( BackupRestore.class ).get();
            data_v1.transferTo( testData.restore() );

            UnitOfWork uow = v1_1.module().newUnitOfWork();
            TestEntity1_1 entity = uow.get( TestEntity1_1.class, id );
            assertThat( "Property has been renamed", entity.newFoo().get(), CoreMatchers.equalTo( "Some value" ) );
            assertThat( "ManyAssociation has been renamed", entity.newFooManyAssoc().count(), CoreMatchers.equalTo( 1 ) );
            assertThat( "Association has been renamed", entity.newFooAssoc().get(), CoreMatchers.equalTo( entity ) );
            uow.complete();

            testData.backup().transferTo( data_v1_1 );
        }

        // Set up version 2.0
        {
            SingletonAssembler v2_0 = new SingletonAssembler()
            {
                @Override
                public void assemble( ModuleAssembly module )
                    throws AssemblyException
                {
                    MigrationTest.this.assemble( module );
                    module.layer().application().setVersion( "2.0" );
                }
            };

            BackupRestore testData = v2_0.module().findService( BackupRestore.class ).get();

            // Test migration from 1.0 -> 2.0
            {
                data_v1.transferTo( testData.restore() );
                UnitOfWork uow = v2_0.module().newUnitOfWork();
                TestEntity2_0 entity = uow.get( TestEntity2_0.class, id );
                assertThat( "Property has been created", entity.bar().get(), CoreMatchers.equalTo( "Some value" ) );
                assertThat( "Custom Property has been created", entity.customBar().get(), CoreMatchers.equalTo( "Hello Some value" ) );
                assertThat( "ManyAssociation has been renamed", entity.newFooManyAssoc().count(), CoreMatchers.equalTo( 1 ) );
                assertThat( "Association has been renamed", entity.newFooAssoc().get(), CoreMatchers.equalTo( entity ) );
                uow.complete();
            }
        }

        // Set up version 3.0
        {
            SingletonAssembler v3_0 = new SingletonAssembler()
            {
                @Override
                public void assemble( ModuleAssembly module )
                    throws AssemblyException
                {
                    MigrationTest.this.assemble( module );
                    module.layer().application().setVersion( "3.0" );
                }
            };

            BackupRestore testData = v3_0.module().findService( BackupRestore.class ).get();
            data_v1_1.transferTo( testData.restore() );

            // Test migration from 1.0 -> 3.0
            {
                data_v1.transferTo( testData.restore() );
                UnitOfWork uow = v3_0.module().newUnitOfWork();
                org.qi4j.migration.moved.TestEntity2_0 entity = uow.get( org.qi4j.migration.moved.TestEntity2_0.class, id );
                uow.complete();
            }
        }
    }
View Full Code Here

    @Before
    public void setUp()
        throws Exception
    {
        SingletonAssembler assembly = new SingletonAssembler()
        {
            @Override
            public void assemble( ModuleAssembly module )
                throws AssemblyException
            {
                module.transients( HelloWorldComposite.class );
            }
        };
        helloWorld = assembly.module().newTransientBuilder( HelloWorldComposite.class ).newInstance();
    }
View Full Code Here

    @Before
    public void setUp()
        throws Exception
    {
        SingletonAssembler assembly = new SingletonAssembler()
        {
            @Override
            public void assemble( ModuleAssembly module )
                throws AssemblyException
            {
                module.transients( HelloWorldComposite.class );
            }
        };
        helloWorld = assembly.module().newTransientBuilder( HelloWorldComposite.class ).newInstance();
    }
View Full Code Here

    public void testSingleModuleSingleService()
        throws Exception
    {
        final List<ActivationEvent> events = new ArrayList<>();

        new SingletonAssembler()
        {
            @Override
            public void assemble( ModuleAssembly module )
                throws AssemblyException
            {
View Full Code Here

    public void testSingleModuleSingleImportedService()
            throws Exception
    {
        final List<ActivationEvent> events = new ArrayList<>();

        new SingletonAssembler()
        {
            @Override
            public void assemble( ModuleAssembly module )
                throws AssemblyException
            {
View Full Code Here

    public void testSingleModuleSingleLazyService()
            throws Exception
    {
        final List<ActivationEvent> events = new ArrayList<>();

        SingletonAssembler assembler = new SingletonAssembler()
        {

            @Override
            public void assemble( ModuleAssembly module )
                    throws AssemblyException
            {
                module.services( TestServiceComposite.class );
            }

            @Override
            protected void beforeActivation( Application application )
            {
                application.registerActivationEventListener( new EventsRecorder( events ) );
            }

        };
        Application application = assembler.application();
        application.passivate();

        Iterator<ActivationEvent> it = events.iterator();

        // Activation
        assertEvent( it.next(), ACTIVATING, "Application" );
        assertEvent( it.next(), ACTIVATING, "Layer" );
        assertEvent( it.next(), ACTIVATING, "Module" );
        // Lazy Service NOT activated
        assertEvent( it.next(), ACTIVATED, "Module" );
        assertEvent( it.next(), ACTIVATED, "Layer" );
        assertEvent( it.next(), ACTIVATED, "Application" );

        // Passivation
        assertEvent( it.next(), PASSIVATING, "Application" );
        assertEvent( it.next(), PASSIVATING, "Layer" );
        assertEvent( it.next(), PASSIVATING, "Module" );
        // Lazy Service NOT passivated
        assertEvent( it.next(), PASSIVATED, "Module" );
        assertEvent( it.next(), PASSIVATED, "Layer" );
        assertEvent( it.next(), PASSIVATED, "Application" );

        assertFalse( it.hasNext() );

        events.clear();
        application.activate();
        Module module = assembler.module();
        module.findService( TestService.class ).get().test();
        application.passivate();

        for( ActivationEvent event : events ) {
            System.out.println( event );
View Full Code Here

public class Main
{

    public static void main(String[] args) throws Exception
    {
        SingletonAssembler singleton = new SingletonAssembler()
        {
            @Override
// START SNIPPET: assemble
            public void assemble(ModuleAssembly module) throws AssemblyException
            {
View Full Code Here

        };
    }

    public static void simple(String[] args) throws Exception
    {
        SingletonAssembler singleton = new SingletonAssembler()
        {
            @Override
// START SNIPPET: simple
            public void assemble(ModuleAssembly module) throws AssemblyException
            {
View Full Code Here

TOP

Related Classes of org.qi4j.bootstrap.SingletonAssembler

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.