use of org.qi4j.api.unitofwork.UnitOfWork in project qi4j-sdk by Qi4j.
the class EntityVisibilityTest method givenFromEntityWhenAccessingAboveModuleVisibleExpectException.
@Test(expected = EntityTypeNotFoundException.class)
public void givenFromEntityWhenAccessingAboveModuleVisibleExpectException() {
UnitOfWork unitOfWork = module.newUnitOfWork();
try {
FromEntity entity = unitOfWork.newEntity(FromEntity.class, "123");
entity.aboveModuleVisible();
} finally {
if (unitOfWork.isOpen()) {
unitOfWork.discard();
}
}
}
use of org.qi4j.api.unitofwork.UnitOfWork in project qi4j-sdk by Qi4j.
the class InterfaceCollisionWithRelatedReturnTypesTest method shouldBeAbleToSetLeadToTheSalesTeam.
@Test
public void shouldBeAbleToSetLeadToTheSalesTeam() {
try (UnitOfWork uow = module.newUnitOfWork()) {
SalesTeam startUp = uow.newEntity(SalesTeam.class);
Employee niclas = uow.newEntity(Employee.class);
startUp.lead().set(niclas);
}
}
use of org.qi4j.api.unitofwork.UnitOfWork in project qi4j-sdk by Qi4j.
the class InterfaceCollisionWithRelatedReturnTypesTest method shouldBeAbleToAddEmployeesToTheResearchTeam.
@Test
public void shouldBeAbleToAddEmployeesToTheResearchTeam() {
try (UnitOfWork uow = module.newUnitOfWork()) {
ResearchTeam startUp = uow.newEntity(ResearchTeam.class);
Employee niclas = uow.newEntity(Employee.class);
startUp.employees().add(niclas);
}
}
use of org.qi4j.api.unitofwork.UnitOfWork in project qi4j-sdk by Qi4j.
the class Qi382Test method givenCreationOfTwoEntitiesWhenAssigningOneToOtherExpectCompletionToSucceed.
@Test
public void givenCreationOfTwoEntitiesWhenAssigningOneToOtherExpectCompletionToSucceed() throws UnitOfWorkCompletionException {
try (UnitOfWork unitOfWork = module.newUnitOfWork()) {
Car car = unitOfWork.newEntity(Car.class, "Ferrari");
unitOfWork.complete();
}
try (UnitOfWork unitOfWork = module.newUnitOfWork()) {
Car car = unitOfWork.get(Car.class, "Ferrari");
assertThat(car, notNullValue());
Person p = unitOfWork.get(Person.class, "Niclas");
assertThat(p, notNullValue());
assertThat(p.car().get(), equalTo(car));
}
}
use of org.qi4j.api.unitofwork.UnitOfWork in project qi4j-sdk by Qi4j.
the class IssueTest method givenEntityWithComplexConstrainedPropertyWhenInvalidPropertyValueSetThenThrowException.
@Test
public void givenEntityWithComplexConstrainedPropertyWhenInvalidPropertyValueSetThenThrowException() {
UnitOfWork uow = module.newUnitOfWork();
try {
TestCase testCase = uow.newEntity(TestCase.class);
testCase.otherProperty().set("");
uow.complete();
fail("Should not be allowed to set invalid property value");
} catch (Exception e) {
uow.discard();
}
}
Aggregations