Search in sources :

Example 21 with UnitOfWork

use of org.qi4j.api.unitofwork.UnitOfWork in project qi4j-sdk by Qi4j.

the class EntityVisibilityTest method givenFromEntityWhenAccessingAboveLayerVisibleExpectException.

@Test(expected = EntityTypeNotFoundException.class)
public void givenFromEntityWhenAccessingAboveLayerVisibleExpectException() {
    UnitOfWork unitOfWork = module.newUnitOfWork();
    try {
        FromEntity entity = unitOfWork.newEntity(FromEntity.class, "123");
        entity.aboveLayerVisible();
    } finally {
        if (unitOfWork.isOpen()) {
            unitOfWork.discard();
        }
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) Test(org.junit.Test)

Example 22 with UnitOfWork

use of org.qi4j.api.unitofwork.UnitOfWork in project qi4j-sdk by Qi4j.

the class ImmutableAssociationTest method givenEntityWithImmutableAssociationWhenChangingValueThenThrowException.

@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();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 23 with UnitOfWork

use of org.qi4j.api.unitofwork.UnitOfWork in project qi4j-sdk by Qi4j.

the class ImmutableAssociationTest method givenEntityWithImmutableManyAssociationWhenChangingValueThenThrowException.

@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();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 24 with UnitOfWork

use of org.qi4j.api.unitofwork.UnitOfWork in project qi4j-sdk by Qi4j.

the class ImmutableAssociationTest method givenEntityWithImmutableManyAssociationWhenBuildingThenNoException.

@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();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 25 with UnitOfWork

use of org.qi4j.api.unitofwork.UnitOfWork in project qi4j-sdk by Qi4j.

the class ImmutableAssociationTest method givenEntityWithImmutableAssociationWhenBuildingThenNoException.

@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();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Aggregations

UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)332 Test (org.junit.Test)232 AbstractQi4jTest (org.qi4j.test.AbstractQi4jTest)108 Before (org.junit.Before)21 AssemblyException (org.qi4j.bootstrap.AssemblyException)21 UnitOfWorkCompletionException (org.qi4j.api.unitofwork.UnitOfWorkCompletionException)18 Delivery (org.qi4j.sample.dcicargo.sample_a.data.shipping.delivery.Delivery)17 HandlingEventsEntity (org.qi4j.sample.dcicargo.sample_a.data.entity.HandlingEventsEntity)15 PersonEntity (org.qi4j.library.conversion.values.TestModel.PersonEntity)13 CargoAggregateRoot (org.qi4j.sample.dcicargo.sample_b.data.aggregateroot.CargoAggregateRoot)13 IOException (java.io.IOException)12 ConcurrentEntityModificationException (org.qi4j.api.unitofwork.ConcurrentEntityModificationException)12 ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)12 Cargos (org.qi4j.sample.dcicargo.sample_a.data.shipping.cargo.Cargos)12 HandlingEvent (org.qi4j.sample.dcicargo.sample_a.data.shipping.handling.HandlingEvent)12 Location (org.qi4j.sample.dcicargo.sample_a.data.shipping.location.Location)11 HandlingEventAggregateRoot (org.qi4j.sample.dcicargo.sample_b.data.aggregateroot.HandlingEventAggregateRoot)11 Date (java.util.Date)10 BalanceData (org.qi4j.dci.moneytransfer.domain.data.BalanceData)10 File (java.io.File)8