Package org.qi4j.api.unitofwork

Examples of org.qi4j.api.unitofwork.UnitOfWork


    @Test
    public void givenEntityWithImmutableManyAssociationWhenBuildingThenNoException()
        throws Exception
    {
        UnitOfWork unitOfWork = module.newUnitOfWork();
        try
        {
            EntityBuilder<PersonEntity> builder = unitOfWork.newEntityBuilder( PersonEntity.class );
            PersonEntity person1 = builder.instance();
            person1 = builder.newInstance();

            builder = unitOfWork.newEntityBuilder( PersonEntity.class );
            PersonEntity person2 = builder.instance();
            person2.colleagues().add( 0, person1 );
            person2 = builder.newInstance();
        }
        finally
        {
            unitOfWork.discard();
        }
    }
View Full Code Here


    @Test( expected = IllegalStateException.class )
    public void givenEntityWithImmutableManyAssociationWhenChangingValueThenThrowException()
        throws Exception
    {
        UnitOfWork unitOfWork = module.newUnitOfWork();
        try
        {
            EntityBuilder<PersonEntity> builder = unitOfWork.newEntityBuilder( PersonEntity.class );
            PersonEntity person1 = builder.instance();
            person1 = builder.newInstance();

            builder = unitOfWork.newEntityBuilder( PersonEntity.class );
            PersonEntity person2 = builder.instance();
            person2 = builder.newInstance();

            person1.colleagues().add( 0, person2 );

            unitOfWork.complete();
        }
        finally
        {
            unitOfWork.discard();
        }
    }
View Full Code Here

    @Test
    public void testGetModuleOfComposite()
        throws Exception
    {
        UnitOfWork unitOfWork = module.newUnitOfWork();
        TestEntity testEntity = unitOfWork.newEntity( TestEntity.class );

        api.getModule( testEntity );

        unitOfWork.discard();

        api.getModule( module.newValue( TestValue.class ) );

        api.getModule( module.newTransient( TestTransient.class ) );
View Full Code Here

    @Test
    public void givenEntityWhenGettingStateThenGetCorrectState()
        throws Exception
    {
        UnitOfWork unitOfWork = module.newUnitOfWork();
        TestEntity testEntity;
        try
        {
            EntityBuilder<TestEntity> builder = unitOfWork.newEntityBuilder( TestEntity.class );

            testEntity = builder.newInstance();

            AssociationStateHolder state = spi.getState( testEntity );

            validateState( state, spi.getEntityDescriptor( testEntity ) );

            unitOfWork.complete();
        }
        finally
        {
            unitOfWork.discard();
        }

        UnitOfWork uow = module.newUnitOfWork();
        try
        {
            testEntity = uow.get( testEntity );
            validateState( spi.getState( testEntity ), spi.getEntityDescriptor( testEntity ) );
            uow.complete();
        }
        finally
        {
            uow.discard();
        }
    }
View Full Code Here

    public void whenConfiguredThenSayHelloWorks()
        throws Exception
    {
        module.injectTo( this );

        UnitOfWork unit = module.newUnitOfWork();
        EntityBuilder<HelloWorldConfiguration> entityBuilder = unit.newEntityBuilder( HelloWorldConfiguration.class, service
            .identity() );
        HelloWorldConfiguration config = entityBuilder.instance();
        config.phrase().set( "Hey" );
        config.name().set( "Universe" );
        entityBuilder.newInstance();
        unit.complete();

        assertThat( "result is correct", service.get().sayHello(), equalTo( "Hey Universe" ) );
    }
View Full Code Here

    }

    @Test
    public void testNestedUnitOfWork()
    {
        UnitOfWork uow = module.newUnitOfWork();
        Some some = module.newTransient( Some.class );
        some.doStuff();
        uow.discard();
    }
View Full Code Here

        module.injectTo( this );

        HelloWorldConfiguration config;

        {
            UnitOfWork unit = module.newUnitOfWork();
            EntityBuilder<HelloWorldConfiguration> entityBuilder = unit.newEntityBuilder( HelloWorldConfiguration.class, service
                .identity() );
            config = entityBuilder.instance();
            config.phrase().set( "Hello" );
            config.name().set( "World" );
            config = entityBuilder.newInstance();
            unit.complete();
        }

        assertThat( "result is correct", service.get().sayHello(), equalTo( "Hello World" ) );

        {
            UnitOfWork unit = module.newUnitOfWork();
            config = unit.get( config );
            config.phrase().set( "Hey" );
            config.name().set( "Universe" );
            unit.complete();
        }

        assertThat( "new configuration is not used", service.get().sayHello(), equalTo( "Hello World" ) );

        service.get().refresh();
View Full Code Here

    @Test
    public void whenEntityHasLifecycleWhenInstantiatedThenInvokeCreate()
        throws UnitOfWorkCompletionException
    {
        UnitOfWork unitOfWork = module.newUnitOfWork();
        try
        {
            EntityBuilder<TestEntity> builder = unitOfWork.newEntityBuilder( TestEntity.class );
            builder.newInstance();
            unitOfWork.complete();
        }
        finally
        {
            unitOfWork.discard();
        }

        assertThat( "Lifecycle.create() was invoked", create, CoreMatchers.equalTo( true ) );
    }
View Full Code Here

    @Test
    public void whenEntityHasLifecycleWhenRemovedThenInvokeRemove()
        throws UnitOfWorkCompletionException
    {
        UnitOfWork unitOfWork = module.newUnitOfWork();
        try
        {
            EntityBuilder<TestEntity> builder = unitOfWork.newEntityBuilder( TestEntity.class );
            TestEntity testEntity = builder.newInstance();
            unitOfWork.remove( testEntity );
            unitOfWork.complete();
        }
        finally
        {
            unitOfWork.discard();
        }

        assertThat( "Lifecycle.remove() was invoked", remove, CoreMatchers.equalTo( true ) );
    }
View Full Code Here

    {
        CompanyEntity companyEntity;
        PersonEntity personEntity, personEntity2;
        EmployeeEntity employeeEntity, employeeEntity2;
        {
            UnitOfWork unitOfWork = module.newUnitOfWork();
            try
            {
                {
                    EntityBuilder<PersonEntity> builder = unitOfWork.newEntityBuilder( PersonEntity.class );
                    personEntity = builder.instance();
                    personEntity.name().set( "Rickard" );
                    personEntity = builder.newInstance();
                }

                {
                    EntityBuilder<PersonEntity> builder = unitOfWork.newEntityBuilder( PersonEntity.class );
                    personEntity2 = builder.instance();
                    personEntity2.name().set( "Niclas" );
                    builder.newInstance();
                }

                {
                    EntityBuilder<EmployeeEntity> builder = unitOfWork.newEntityBuilder( EmployeeEntity.class );
                    employeeEntity = builder.instance();
                    employeeEntity.person().set( personEntity );
                    employeeEntity.salary().set( 50000 );
                    employeeEntity.title().set( "Director" );
                    employeeEntity = builder.newInstance();
                }

                {
                    EntityBuilder<EmployeeEntity> builder = unitOfWork.newEntityBuilder( EmployeeEntity.class );
                    employeeEntity2 = builder.instance();
                    employeeEntity2.person().set( personEntity );
                    employeeEntity2.salary().set( 40000 );
                    employeeEntity2.title().set( "Developer" );
                    employeeEntity2 = builder.newInstance();
                }

                {
                    EntityBuilder<CompanyEntity> builder = unitOfWork.newEntityBuilder( CompanyEntity.class );
                    companyEntity = builder.instance();
                    companyEntity.director().set( employeeEntity );
                    companyEntity.employees().add( 0, employeeEntity );
                    companyEntity.employees().add( 0, employeeEntity2 );
                    companyEntity = builder.newInstance();
                }

                unitOfWork.complete();
            }
            finally
            {
                unitOfWork.discard();
            }
        }

        {
            UnitOfWork unitOfWork = module.newUnitOfWork();
            try
            {
                companyEntity = unitOfWork.get( companyEntity );
                unitOfWork.remove( companyEntity );

                unitOfWork.complete();
            }
            finally
            {
                unitOfWork.discard();
            }
        }

        {
            UnitOfWork unitOfWork = module.newUnitOfWork();
            try
            {
                unitOfWork.get( employeeEntity );

                fail( "Should not work" );

                unitOfWork.complete();
            }
            catch( NoSuchEntityException e )
            {
                unitOfWork.discard();
            }
        }

        {
            UnitOfWork unitOfWork = module.newUnitOfWork();
            try
            {
                unitOfWork.get( employeeEntity2 );
                fail( "Should not work" );

                unitOfWork.complete();
            }
            catch( NoSuchEntityException e )
            {
                unitOfWork.discard();
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.qi4j.api.unitofwork.UnitOfWork

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.