Search in sources :

Example 1 with PersonValue4

use of org.qi4j.library.conversion.values.TestModel.PersonValue4 in project qi4j-sdk by Qi4j.

the class ValueToEntityTest method givenQualifiedValueNotFromSameInterfaceWhenCreatingEntityExpectNonOptionalException.

@Test(expected = ConstraintViolationException.class)
public void givenQualifiedValueNotFromSameInterfaceWhenCreatingEntityExpectNonOptionalException() throws UnitOfWorkCompletionException {
    ValueBuilder<PersonValue4> builder = module.newValueBuilder(PersonValue4.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));
    PersonValue4 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);
        uow.complete();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) PersonValue4(org.qi4j.library.conversion.values.TestModel.PersonValue4) PersonEntity(org.qi4j.library.conversion.values.TestModel.PersonEntity) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 2 with PersonValue4

use of org.qi4j.library.conversion.values.TestModel.PersonValue4 in project qi4j-sdk by Qi4j.

the class ValueToEntityTest method givenQualifiedValueNotFromSameInterfaceWhenUpdatingEntityExpectPropsNotUpdated.

@Test
public void givenQualifiedValueNotFromSameInterfaceWhenUpdatingEntityExpectPropsNotUpdated() throws UnitOfWorkCompletionException {
    String rickyIdentity;
    try (UnitOfWork uow = module.newUnitOfWork(newUsecase("CreateRickySlaghoopleWithTypo"))) {
        PersonEntity ricky = createPerson(uow, "Ricky", "Slaghople", someBirthDate);
        ricky.spouse().set(uow.get(PersonEntity.class, ednaIdentity));
        ricky.children().add(uow.get(PersonEntity.class, zekeIdentity));
        rickyIdentity = ricky.identity().get();
        assertThat(ricky.spouse().get(), notNullValue());
        assertThat(ricky.children().count(), is(1));
        uow.complete();
    }
    ValueBuilder<PersonValue4> builder = module.newValueBuilder(PersonValue4.class);
    builder.prototype().firstName().set("Ricky");
    builder.prototype().lastName().set("Slaghoople");
    builder.prototype().dateOfBirth().set(someBirthDate);
    PersonValue4 newStateValue = builder.newInstance();
    try (UnitOfWork uow = module.newUnitOfWork(newUsecase("UpdateRickySlaghoopleWontWork"))) {
        PersonEntity ricky = uow.get(PersonEntity.class, rickyIdentity);
        ValueToEntity conversion = module.findService(ValueToEntity.class).get();
        conversion.update(ricky, newStateValue);
        assertThat(ricky.lastName(), equalTo("Slaghople"));
        assertThat(ricky.spouse().get(), nullValue());
        assertThat(ricky.children().count(), is(0));
        uow.complete();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) PersonValue4(org.qi4j.library.conversion.values.TestModel.PersonValue4) PersonEntity(org.qi4j.library.conversion.values.TestModel.PersonEntity) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 3 with PersonValue4

use of org.qi4j.library.conversion.values.TestModel.PersonValue4 in project qi4j-sdk by Qi4j.

the class EntityToValueTest method givenQualifiedValueNotFromSameInterfaceWhenConvertingEntityExpectNonOptionalException.

@Test(expected = ConstraintViolationException.class)
public void givenQualifiedValueNotFromSameInterfaceWhenConvertingEntityExpectNonOptionalException() throws UnitOfWorkCompletionException {
    UnitOfWork uow = module.newUnitOfWork();
    try {
        PersonEntity niclas = setupPersonEntities(uow);
        ServiceReference<EntityToValueService> reference = module.findService(EntityToValueService.class);
        EntityToValueService service = reference.get();
        PersonValue4 niclasValue = service.convert(PersonValue4.class, niclas);
        uow.complete();
    } finally {
        uow.discard();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) PersonValue4(org.qi4j.library.conversion.values.TestModel.PersonValue4) PersonEntity(org.qi4j.library.conversion.values.TestModel.PersonEntity) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)3 PersonEntity (org.qi4j.library.conversion.values.TestModel.PersonEntity)3 PersonValue4 (org.qi4j.library.conversion.values.TestModel.PersonValue4)3 AbstractQi4jTest (org.qi4j.test.AbstractQi4jTest)3