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 EntityBuilderWithStateTest method test.
@Test
public void test() throws UnitOfWorkCompletionException {
final String associatedIdentity;
try (UnitOfWork uow = module.newUnitOfWork()) {
EntityBuilder<SomeEntity> builder = uow.newEntityBuilder(SomeEntity.class);
builder.instance().prop().set("Associated");
SomeEntity entity = builder.newInstance();
associatedIdentity = entity.identity().get();
uow.complete();
}
try (UnitOfWork uow = module.newUnitOfWork()) {
SomeEntity entity = uow.newEntityBuilderWithState(SomeEntity.class, new Function<PropertyDescriptor, Object>() {
@Override
public Object map(PropertyDescriptor descriptor) {
if ("prop".equals(descriptor.qualifiedName().name())) {
return "Foo";
}
return null;
}
}, new Function<AssociationDescriptor, EntityReference>() {
@Override
public EntityReference map(AssociationDescriptor descriptor) {
if ("ass".equals(descriptor.qualifiedName().name())) {
return EntityReference.parseEntityReference(associatedIdentity);
}
return null;
}
}, new Function<AssociationDescriptor, Iterable<EntityReference>>() {
@Override
public Iterable<EntityReference> map(AssociationDescriptor descriptor) {
if ("manyAss".equals(descriptor.qualifiedName().name())) {
return Arrays.asList(EntityReference.parseEntityReference(associatedIdentity));
}
return null;
}
}, new Function<AssociationDescriptor, Map<String, EntityReference>>() {
@Override
public Map<String, EntityReference> map(AssociationDescriptor descriptor) {
if ("namedAss".equals(descriptor.qualifiedName().name())) {
return Collections.singletonMap("foo", EntityReference.parseEntityReference(associatedIdentity));
}
return null;
}
}).newInstance();
assertThat(entity.prop().get(), equalTo("Foo"));
assertThat(entity.ass().get().identity().get(), equalTo(associatedIdentity));
assertThat(entity.manyAss().get(0).identity().get(), equalTo(associatedIdentity));
assertThat(entity.namedAss().get("foo").identity().get(), equalTo(associatedIdentity));
uow.complete();
}
}
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);
}
}
Aggregations