Package org.qi4j.api.unitofwork

Examples of org.qi4j.api.unitofwork.UnitOfWork


    @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( "Default mixin has executed", foo.test( "Foo", 42 ), equalTo( "Foo 42" ) );
        }
        finally
        {
            uow.discard();
        }
    }
View Full Code Here


{
    @Test
    public void givenSubclassedEntityWhenRequestingSuperclassExpectResolutionToWork()
        throws Exception
    {
        UnitOfWork uow = module.newUnitOfWork();
        try
        {
            EntityBuilder<Rst> builder3 = uow.newEntityBuilder( Rst.class, "123" );
            EntityBuilder<Def> builder2 = uow.newEntityBuilder( Def.class, "456" );
            EntityBuilder<Abc> builder1 = uow.newEntityBuilder( Abc.class, "789" );
        }
        finally
        {
            uow.discard();
        }
    }
View Full Code Here

    }

    @Test
    public void testAssociation()
    {
        UnitOfWork unitOfWork = module.newUnitOfWork();

        try
        {
            Company company = unitOfWork.newEntity( Company.class );
            Assert.assertEquals( "Company Name Default", "A Company", company.name().get() );

            {
                EntityBuilder<Company> builder = unitOfWork.newEntityBuilder( Company.class );
                final Company companyPrototype = builder.instance();
                companyPrototype.name().set( "JayWay" );
                company = builder.newInstance();
                Assert.assertEquals( "Company Name ", "JayWay", company.name().get() );
            }

            company.name().set( "Jayway" );
            Assert.assertEquals( "Company Name ", "Jayway", company.name().get() );

            System.out.println( "Name is:" + company.name().get() );

            EntityBuilder<Person> builder = unitOfWork.newEntityBuilder( Person.class );
            builder.instance().name().set( "Rickard" );
            Person rickard = builder.newInstance();

            builder = unitOfWork.newEntityBuilder( Person.class );
            builder.instance().name().set( "Niclas" );
            builder.instance().friend().set( rickard );
            Person niclas = builder.newInstance();

            niclas.members().add( rickard );

            company.employees().add( 0, rickard );

            for( Employer employer : rickard.employers() )
            {
                System.out.println( ( (Nameable) employer ).name() );
            }

            Assert.assertEquals( niclas.friend().get(), rickard );
            Assert.assertEquals( niclas.members().get(0), rickard );
        }
        finally
        {
            unitOfWork.discard();
        }
    }
View Full Code Here

    }

    @Test
    public void whenQuerableIsFalseOnPropertyThenExpectException()
    {
        UnitOfWork unitOfWork = module.newUnitOfWork();
        try
        {
            QueryBuilder<Abc> builder = module.newQueryBuilder( Abc.class );
            Abc proto = templateFor( Abc.class );
            builder.where( eq( proto.isValid(), Boolean.TRUE ) );
            Assert.fail( "Exception was expected." );
        }
        catch( QueryException e )
        {
            // expected!!
        }
        finally
        {
            unitOfWork.discard();
        }
    }
View Full Code Here

    }

    @Test
    public void testQueryIterable()
    {
        UnitOfWork unitOfWork = module.newUnitOfWork();
        try
        {
            module.newQueryBuilder( Abc2.class );
            Assert.fail( "Exception was expected." );
        }
        catch( QueryException e )
        {
            // expected!!
        }
        finally
        {
            unitOfWork.discard();
        }
    }
View Full Code Here

    }

    @Test
    public void testMultiConcerns1()
    {
        UnitOfWork uow = module.newUnitOfWork();

        try
        {
            ServiceReference<SomeServiceCompositeWithFirstAnnotation> refWithFirst = module.findService(
                SomeServiceCompositeWithFirstAnnotation.class );
            SomeServiceCompositeWithFirstAnnotation someWithFirst = refWithFirst.get();
            someWithFirst.doStuff();
            assertTrue( "AppliesTo did not match with first annotation", someWithFirst.concernHasBeenPlayed() );
        }
        finally
        {
            uow.discard();
        }
    }
View Full Code Here

    }

    @Test
    public void testMultiConcerns2()
    {
        UnitOfWork uow = module.newUnitOfWork();

        try
        {
            ServiceReference<SomeServiceCompositeWithSecondAnnotation> refWithSecond = module.findService(
                SomeServiceCompositeWithSecondAnnotation.class );
            SomeServiceCompositeWithSecondAnnotation someWithSecond = refWithSecond.get();
            someWithSecond.doStuff();
            assertTrue( "AppliesTo did not match with second annotation", someWithSecond.concernHasBeenPlayed() );
        }
        finally
        {
            uow.discard();
        }
    }
View Full Code Here

    }

    @Test
    public void testMultiConcernsBoth()
    {
        UnitOfWork uow = module.newUnitOfWork();

        try
        {
            ServiceReference<SomeServiceCompositeWithTwoAnnotations> refWithTwo = module.findService(
                SomeServiceCompositeWithTwoAnnotations.class );
            SomeServiceCompositeWithTwoAnnotations someWithTwo = refWithTwo.get();
            someWithTwo.doStuff();
            assertTrue( "AppliesTo did not match with two annotations", someWithTwo.concernHasBeenPlayed() );
        }
        finally
        {
            uow.discard();
        }
    }
View Full Code Here

    @Test
    public void givenEntityWithImmutableAssociationWhenBuildingThenNoException()
        throws Exception
    {
        UnitOfWork unitOfWork = module.newUnitOfWork();
        try
        {
            PersonEntity father = unitOfWork.newEntity( PersonEntity.class );

            EntityBuilder<PersonEntity> builder = unitOfWork.newEntityBuilder( PersonEntity.class );
            PersonEntity instance = builder.instance();
            instance.father().set( father );
            PersonEntity child = builder.newInstance();
        }
        finally
        {
            unitOfWork.discard();
        }
    }
View Full Code Here

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

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

            child.father().set( father );

            unitOfWork.complete();
        }
        finally
        {
            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.