use of org.qi4j.api.unitofwork.UnitOfWork in project qi4j-sdk by Qi4j.
the class InterfaceCollisionWithRelatedReturnTypesTest method shouldBeAbleToSetLeadToTheResearchTeam.
@Test
public void shouldBeAbleToSetLeadToTheResearchTeam() {
try (UnitOfWork uow = module.newUnitOfWork()) {
ResearchTeam startUp = uow.newEntity(ResearchTeam.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 shouldBeAbleToSetNameToTheCompany.
@Test
public void shouldBeAbleToSetNameToTheCompany() throws UnitOfWorkCompletionException {
String identity;
try (UnitOfWork uow = module.newUnitOfWork()) {
Company startUp = uow.newEntity(Company.class);
startUp.name().set("Acme");
identity = ((Identity) startUp).identity().get();
uow.complete();
}
try (UnitOfWork uow = module.newUnitOfWork()) {
Company startUp = uow.get(Company.class, identity);
assertThat(startUp.name().get(), equalTo("Acme"));
SalesTeam sales = uow.get(SalesTeam.class, identity);
assertThat(sales.name().get(), equalTo("Acme"));
ResearchTeam research = uow.get(ResearchTeam.class, identity);
assertThat(research.name().get(), equalTo("Acme"));
}
}
use of org.qi4j.api.unitofwork.UnitOfWork in project qi4j-sdk by Qi4j.
the class OptionalTest method givenOptionalAssociationWhenOptionalSetThenNoException.
@Test
public void givenOptionalAssociationWhenOptionalSetThenNoException() throws Exception {
UnitOfWork unitOfWork = module.newUnitOfWork();
try {
TestComposite4 ref = unitOfWork.newEntity(TestComposite4.class);
EntityBuilder<TestComposite3> builder = unitOfWork.newEntityBuilder(TestComposite3.class);
builder.instance().mandatoryAssociation().set(ref);
builder.instance().optionalAssociation().set(ref);
TestComposite3 testComposite3 = builder.newInstance();
unitOfWork.complete();
} finally {
unitOfWork.discard();
}
}
use of org.qi4j.api.unitofwork.UnitOfWork in project qi4j-sdk by Qi4j.
the class AppliesToOrConditionQI241Test method testMultiConcernsBoth.
@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();
}
}
use of org.qi4j.api.unitofwork.UnitOfWork in project qi4j-sdk by Qi4j.
the class AssociationEqualityTest method givenValuesOfTheSameTypeAndSameStateWhenTestingAssociationDescriptorEqualityExpectEquals.
//
// ----------------------------:: AssociationDescriptor equality tests ::-------------------------------------------
//
@Test
public void givenValuesOfTheSameTypeAndSameStateWhenTestingAssociationDescriptorEqualityExpectEquals() {
UnitOfWork uow = module.newUnitOfWork();
try {
AnEntity anEntity = uow.newEntity(AnEntity.class);
SomeWithAssociations some = buildSomeWithAssociation(anEntity);
AssociationDescriptor someAssocDesc = qi4j.api().associationDescriptorFor(some.anEntity());
AssociationDescriptor someManyAssocDesc = qi4j.api().associationDescriptorFor(some.manyEntities());
SomeWithAssociations some2 = buildSomeWithAssociation(anEntity);
AssociationDescriptor some2AssocDesc = qi4j.api().associationDescriptorFor(some2.anEntity());
AssociationDescriptor some2ManyAssocDesc = qi4j.api().associationDescriptorFor(some2.manyEntities());
assertThat("AssociationDescriptor equal", someAssocDesc, equalTo(some2AssocDesc));
assertThat("AssociationDescriptor hashcode equal", someAssocDesc.hashCode(), equalTo(some2AssocDesc.hashCode()));
assertThat("ManyAssociationDescriptor equal", someManyAssocDesc, equalTo(some2ManyAssocDesc));
assertThat("ManyAssociationDescriptor hashcode equal", someManyAssocDesc.hashCode(), equalTo(some2ManyAssocDesc.hashCode()));
} finally {
uow.discard();
}
}
Aggregations