use of org.qi4j.library.conversion.values.TestModel.PersonEntity in project qi4j-sdk by Qi4j.
the class EntityToValueTest method givenUnqualifiedValue2WhenConvertingEntityExpectCorrectMapping.
@Test
public void givenUnqualifiedValue2WhenConvertingEntityExpectCorrectMapping() throws UnitOfWorkCompletionException {
UnitOfWork uow = module.newUnitOfWork();
try {
PersonEntity niclas = setupPersonEntities(uow);
ServiceReference<EntityToValueService> reference = module.findService(EntityToValueService.class);
EntityToValueService service = reference.get();
PersonValue3 niclasValue = service.convert(PersonValue3.class, niclas);
assertEquals("Niclas", niclasValue.firstName().get());
assertEquals("Hedhman", niclasValue.lastName().get());
assertEquals("id:Lis", niclasValue.spouse().get());
assertEquals("id:Eric", niclasValue.children().get().get(0));
uow.complete();
} finally {
uow.discard();
}
}
use of org.qi4j.library.conversion.values.TestModel.PersonEntity in project qi4j-sdk by Qi4j.
the class EntityToValueTest method whenConvertingEntityToValueExpectCorrectValues.
@Test
public void whenConvertingEntityToValueExpectCorrectValues() throws UnitOfWorkCompletionException {
UnitOfWork uow = module.newUnitOfWork();
try {
PersonEntity entity = setupPersonEntities(uow);
// START SNIPPET: conversion
EntityToValueService conversion = module.findService(EntityToValueService.class).get();
PersonValue value = conversion.convert(PersonValue.class, entity);
// END SNIPPET: conversion
assertEquals("Niclas", value.firstName().get());
assertEquals("Hedhman", value.lastName().get());
assertEquals("id:Lis", value.spouse().get());
assertEquals("id:Eric", value.children().get().get(0));
uow.complete();
} finally {
uow.discard();
}
}
use of org.qi4j.library.conversion.values.TestModel.PersonEntity in project qi4j-sdk by Qi4j.
the class ValueToEntityTest method givenUnqualifiedValueWhenCreatingEntityExpectCorrectEntity.
@Test
public void givenUnqualifiedValueWhenCreatingEntityExpectCorrectEntity() throws UnitOfWorkCompletionException {
ValueBuilder<PersonValue2> builder = module.newValueBuilder(PersonValue2.class);
builder.prototype().firstName().set("Ed");
builder.prototype().lastName().set("Flintstone");
builder.prototype().dateOfBirth().set(someBirthDate);
builder.prototype().spouse().set(ednaIdentity);
builder.prototype().children().set(Arrays.asList(zekeIdentity, fredIdentity));
PersonValue2 edValue = builder.newInstance();
try (UnitOfWork uow = module.newUnitOfWork(newUsecase("CreatingEntityFromUnqualifiedValue"))) {
ValueToEntity conversion = module.findService(ValueToEntity.class).get();
PersonEntity edEntity = conversion.create(PersonEntity.class, "id:Ed", edValue);
assertThat(edEntity.identity().get(), equalTo("id:Ed"));
assertThat(edEntity.firstName(), equalTo("Ed"));
assertThat(edEntity.lastName(), equalTo("Flintstone"));
assertThat(edEntity.spouse().get().firstName(), equalTo("Edna"));
assertThat(Iterables.count(Iterables.filter(new Specification<PersonEntity>() {
@Override
public boolean satisfiedBy(PersonEntity child) {
return "Zeke".equals(child.firstName()) || "Fred".equals(child.firstName());
}
}, edEntity.children())), is(2L));
uow.complete();
}
}
use of org.qi4j.library.conversion.values.TestModel.PersonEntity in project qi4j-sdk by Qi4j.
the class ValueToEntityTest method givenUnqualifiedValue2WhenCreatingEntityExpectCorrectEntity.
@Test
public void givenUnqualifiedValue2WhenCreatingEntityExpectCorrectEntity() throws UnitOfWorkCompletionException {
ValueBuilder<PersonValue3> builder = module.newValueBuilder(PersonValue3.class);
builder.prototype().firstName().set("Ed");
builder.prototype().lastName().set("Flintstone");
builder.prototype().dateOfBirth().set(someBirthDate);
builder.prototype().spouse().set(ednaIdentity);
builder.prototype().children().set(Arrays.asList(zekeIdentity, fredIdentity));
PersonValue3 edValue = builder.newInstance();
try (UnitOfWork uow = module.newUnitOfWork(newUsecase("CreatingEntityFromUnqualifiedValue"))) {
ValueToEntity conversion = module.findService(ValueToEntity.class).get();
PersonEntity edEntity = conversion.create(PersonEntity.class, "id:Ed", edValue);
assertThat(edEntity.identity().get(), equalTo("id:Ed"));
assertThat(edEntity.firstName(), equalTo("Ed"));
assertThat(edEntity.lastName(), equalTo("Flintstone"));
assertThat(edEntity.spouse().get().firstName(), equalTo("Edna"));
assertThat(Iterables.count(Iterables.filter(new Specification<PersonEntity>() {
@Override
public boolean satisfiedBy(PersonEntity child) {
return "Zeke".equals(child.firstName()) || "Fred".equals(child.firstName());
}
}, edEntity.children())), is(2L));
uow.complete();
}
}
Aggregations