Search in sources :

Example 66 with UnitOfWork

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

the class AutoCloseableUoWTest method givenWrongAutoCloseableUoWWhenTryWithResourceExpectSuccess.

@Test(expected = ConstraintViolationException.class)
public void givenWrongAutoCloseableUoWWhenTryWithResourceExpectSuccess() throws UnitOfWorkCompletionException {
    try (UnitOfWork uow = module.newUnitOfWork()) {
        uow.newEntity(TestEntity.class);
        uow.complete();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 67 with UnitOfWork

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

the class RemovalTest method givenEntityCreatedWhenRemovingEntityBeforeCompletingUowThenFindNewEntityShouldNotExist.

@Test
public void givenEntityCreatedWhenRemovingEntityBeforeCompletingUowThenFindNewEntityShouldNotExist() throws Exception {
    UnitOfWork uow = module.newUnitOfWork();
    try {
        EntityBuilder<Abc> builder = uow.newEntityBuilder(Abc.class, "123");
        builder.instance().name().set("Niclas");
        Abc abc = builder.newInstance();
        uow.remove(abc);
        uow.complete();
        uow = module.newUnitOfWork();
        uow.get(Abc.class, "123");
        fail("This '123' entity should not exist.");
    } catch (NoSuchEntityException e) {
    // Expected.
    } finally {
        uow.discard();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) NoSuchEntityException(org.qi4j.api.unitofwork.NoSuchEntityException) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 68 with UnitOfWork

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

the class RemovalTest method givenDetachedEntityWhenRemovingEntityThenFindNewEntityShouldNotExist.

@Test
public void givenDetachedEntityWhenRemovingEntityThenFindNewEntityShouldNotExist() throws Exception {
    UnitOfWork uow = module.newUnitOfWork();
    try {
        EntityBuilder<Abc> builder = uow.newEntityBuilder(Abc.class, "123");
        builder.instance().name().set("Niclas");
        Abc abc = builder.newInstance();
        uow.complete();
        uow = module.newUnitOfWork();
        // Attach the detached entity to 'uow' session.
        abc = uow.get(abc);
        uow.remove(abc);
        uow.complete();
        uow = module.newUnitOfWork();
        uow.get(Abc.class, "123");
        fail("This '123' entity should not exist.");
    } catch (NoSuchEntityException e) {
    // Expected.
    } finally {
        uow.discard();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) NoSuchEntityException(org.qi4j.api.unitofwork.NoSuchEntityException) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 69 with UnitOfWork

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

the class RemovalTest method givenUnitOfWorkHasBeenCreateWhenCreatingNewEntityThenFindNewEntityWithGet.

@Test
public void givenUnitOfWorkHasBeenCreateWhenCreatingNewEntityThenFindNewEntityWithGet() throws Exception {
    UnitOfWork uow = module.newUnitOfWork();
    try {
        EntityBuilder<Abc> builder = uow.newEntityBuilder(Abc.class, "123");
        builder.instance().name().set("Niclas");
        builder.newInstance();
        uow.complete();
        uow = module.newUnitOfWork();
        Abc abc = uow.get(Abc.class, "123");
        assertEquals("Niclas", abc.name().get());
    } finally {
        uow.discard();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 70 with UnitOfWork

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

the class RemovalTest method givenEntityCreatedWhenRemovingEntityThenFindNewEntityShouldNotExist.

@Test
public void givenEntityCreatedWhenRemovingEntityThenFindNewEntityShouldNotExist() throws Exception {
    UnitOfWork uow = module.newUnitOfWork();
    try {
        EntityBuilder<Abc> builder = uow.newEntityBuilder(Abc.class, "123");
        builder.instance().name().set("Niclas");
        builder.newInstance();
        uow.complete();
        uow = module.newUnitOfWork();
        Abc abc = uow.get(Abc.class, "123");
        assertEquals("Niclas", abc.name().get());
        uow.remove(abc);
        uow.complete();
        uow = module.newUnitOfWork();
        uow.get(Abc.class, "123");
        fail("This '123' entity should not exist.");
    } catch (NoSuchEntityException e) {
    // Expected.
    } finally {
        uow.discard();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) NoSuchEntityException(org.qi4j.api.unitofwork.NoSuchEntityException) 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