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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations