Package org.qi4j.api.unitofwork

Examples of org.qi4j.api.unitofwork.UnitOfWork


    @Test
    public void givenEntityWithPropertyConstraintsWhenInstantiatedThenPropertiesWork()
        throws Exception
    {
        UnitOfWork unitOfWork = module.newUnitOfWork();
        try
        {
            EntityBuilder<PersonEntity> builder = unitOfWork.newEntityBuilder( PersonEntity.class );
            PersonEntity personEntity = builder.instance();
            personEntity.givenName().set( "Rickard" );
            personEntity.familyName().set( "Öberg" );
            personEntity = builder.newInstance();

            personEntity.givenName().set( "Niclas" );
            personEntity.familyName().set( "Hedhman" );

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


    @Test( expected = ConstraintViolationException.class )
    public void givenEntityWithNonOptionPropertyWhenInstantiatedThenException()
        throws Exception
    {
        UnitOfWork unitOfWork = module.newUnitOfWork();
        try
        {
            PersonEntity person = unitOfWork.newEntity( PersonEntity.class );

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

    @Test
    public void givenEntityIsCreatedAndUnitOfWorkIsNotCompletedWhenEntityIsRemoveThenSuccessfulRemoval()
        throws Exception
    {
        UnitOfWork uow = module.newUnitOfWork();
        EntityBuilder<TestEntity> builder = uow.newEntityBuilder( TestEntity.class, "123" );
        builder.instance().test().set( "habba" );
        TestEntity test = builder.newInstance();
        uow.remove( test );
        uow.complete();
    }
View Full Code Here

    @Test
    public void givenStandardPidRegulatorWhenNoChangeInInputExpectOutputToGoTowardsMinimum()
        throws Exception
    {
        UnitOfWork uow = module.newUnitOfWork();
        PidRegulator regulator = null;
        try
        {
            regulator = createPidRegulator( uow );
        }
        finally
        {
            if( regulator != null )
            {
                uow.remove( regulator );
            }
            // TODO: This problem is related to that uow.remove() has a bug.
            // If the Entity is both created and removed in the same session, then the remove() should simply remove
            // the entity from the internal UoW holding area, and not set the REMOVED status.

            // Probably that UnitOfWorkInstance.remove() should also call instanceCache.remove(), but the question is
            // then what is an InstanceKey vs EntityReference
            uow.complete();
        }
    }
View Full Code Here

    }

    @Test
    public void entityBuilderAssociationTypeIsNotNull()
    {
        UnitOfWork uow = module.newUnitOfWork();
        try
        {
            EntityBuilder<Item> builder = uow.newEntityBuilder( Item.class );
            assertEquals( ItemType.class, qi4j.api().getEntityDescriptor( builder.instance()).state().getAssociationByName( "typeOfItem" ).type() );
        }
        finally
        {
            uow.discard();
        }
    }
View Full Code Here

    }

    @Test
    public final void testImmutableEntityProperty()
    {
        UnitOfWork uow = module.newUnitOfWork();
        try
        {
            EntityBuilder<LocationEntity> builder = uow.newEntityBuilder( LocationEntity.class );
            builder.instance().name().set( "Rickard" );
            Location location = builder.newInstance();

            try
            {
                location.name().set( "Niclas" );
                Assert.fail( "Should be immutable" );
            }
            catch( IllegalStateException e )
            {
                // Ok
            }
        }
        finally
        {
            uow.discard();
        }
    }
View Full Code Here

    @Test
    public void givenEntityInOneUnitOfWorkWhenCurrentUnitOfWorkHasChangedThenUnitOfWorkInjectionInEntityPointsToCorrectUow()
        throws Exception
    {
        Usecase usecase = UsecaseBuilder.newUsecase( "usecase1" );
        UnitOfWork uow = module.newUnitOfWork( usecase );
        try
        {
            Trial trial = uow.newEntity( Trial.class, "123" );
            trial.doSomething();
            uow.complete();
            uow = module.newUnitOfWork( usecase );
            usecase = UsecaseBuilder.newUsecase( "usecase2" );
            UnitOfWork uow2 = module.newUnitOfWork( usecase );
            trial = uow.get( trial );
            trial.doSomething();
            assertEquals( "123", ( (EntityComposite) trial ).identity().get() );
            assertEquals( "usecase1", trial.usecaseName() );
            uow2.discard();
        }
        catch( Throwable ex )
        {
            ex.printStackTrace();
        }
View Full Code Here

    @Test( expected = ConstraintViolationException.class )
    public void givenEntityWithNonOptionPropertyWhenInstantiatedThenException()
        throws Exception
    {
        UnitOfWork unitOfWork = module.newUnitOfWork();
        try
        {
            PersonEntity person = unitOfWork.newEntity( PersonEntity.class );

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

    @Test
    public void testThatServiceAndStructureInjectionWorkForValueWhenEntityRetrievedFromStore()
        throws Exception
    {
        UnitOfWork uow = null;
        try
        {
            ValueBuilder<Some> builder = module.newValueBuilder( Some.class );
            builder.prototype().data().set( "Niclas" );
            Some value = builder.newInstance();

            uow = module.newUnitOfWork();
            EntityBuilder<Niclas> eb = uow.newEntityBuilder( Niclas.class );
            eb.instance().value().set( value );
            Niclas niclas1 = eb.newInstance();
            String id = niclas1.identity().get();
            uow.complete();

            uow = module.newUnitOfWork();
            Niclas niclas2 = uow.get( Niclas.class, id );
            Some someValue = niclas2.value().get();
            Assert.assertEquals( someValue.data().get(), "Niclas" );
            Assert.assertNotNull( someValue.module() );
            Assert.assertNotNull( someValue.service() );
        }
        finally
        {
            if( uow != null )
            {
                uow.discard();
            }
        }
    }
View Full Code Here

    @Test
    public void testAssemblyMixinsEntity()
        throws UnitOfWorkCompletionException
    {
        UnitOfWork uow = module.newUnitOfWork();
        FooEntity entity = uow.newEntity( FooEntity.class, "123" );
        uow.complete();

        uow = module.newUnitOfWork();
        Foo foo = uow.get( Foo.class, "123" );

        try
        {
            assertThat( "Custom mixin has executed", foo.test( "Foo", 42 ), equalTo( "Foo 42" ) );
        }
        finally
        {
            uow.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.