Search in sources :

Example 1 with PersonEntity

use of org.qi4j.library.conversion.values.TestModel.PersonEntity 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 PersonEntity

use of org.qi4j.library.conversion.values.TestModel.PersonEntity 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 PersonEntity

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

the class ValueToEntityTest method givenUnqualifiedValueWhenUpdatingEntityExpectCorrectEntity.

@Test
public void givenUnqualifiedValueWhenUpdatingEntityExpectCorrectEntity() 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<PersonValue2> builder = module.newValueBuilder(PersonValue2.class);
    builder.prototype().firstName().set("Ricky");
    builder.prototype().lastName().set("Slaghoople");
    builder.prototype().dateOfBirth().set(someBirthDate);
    PersonValue2 newStateValue = builder.newInstance();
    try (UnitOfWork uow = module.newUnitOfWork(newUsecase("UpdateRickySlaghoople"))) {
        PersonEntity ricky = uow.get(PersonEntity.class, rickyIdentity);
        ValueToEntity conversion = module.findService(ValueToEntity.class).get();
        conversion.update(ricky, newStateValue);
        assertThat(ricky.lastName(), equalTo("Slaghoople"));
        assertThat(ricky.spouse().get(), nullValue());
        assertThat(ricky.children().count(), is(0));
        uow.complete();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) PersonEntity(org.qi4j.library.conversion.values.TestModel.PersonEntity) PersonValue2(org.qi4j.library.conversion.values.TestModel.PersonValue2) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 4 with PersonEntity

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

the class ValueToEntityTest method givenQualifiedValueWhenCreatingEntityExpectCorrectEntity.

@Test
public void givenQualifiedValueWhenCreatingEntityExpectCorrectEntity() throws UnitOfWorkCompletionException {
    ValueBuilder<PersonValue> builder = module.newValueBuilder(PersonValue.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));
    PersonValue edValue = builder.newInstance();
    try (UnitOfWork uow = module.newUnitOfWork(newUsecase("CreatingEntityFromQualifiedValue"))) {
        // START SNIPPET: creation
        ValueToEntity conversion = module.findService(ValueToEntity.class).get();
        PersonEntity edEntity = conversion.create(PersonEntity.class, edValue);
        // END SNIPPET: creation
        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();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) PersonValue(org.qi4j.library.conversion.values.TestModel.PersonValue) PersonEntity(org.qi4j.library.conversion.values.TestModel.PersonEntity) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 5 with PersonEntity

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

the class ValueToEntityTest method givenUnqualifiedValue2WhenUpdatingEntityExpectCorrectEntity.

@Test
public void givenUnqualifiedValue2WhenUpdatingEntityExpectCorrectEntity() 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<PersonValue3> builder = module.newValueBuilder(PersonValue3.class);
    builder.prototype().firstName().set("Ricky");
    builder.prototype().lastName().set("Slaghoople");
    builder.prototype().dateOfBirth().set(someBirthDate);
    PersonValue3 newStateValue = builder.newInstance();
    try (UnitOfWork uow = module.newUnitOfWork(newUsecase("UpdateRickySlaghoople"))) {
        PersonEntity ricky = uow.get(PersonEntity.class, rickyIdentity);
        ValueToEntity conversion = module.findService(ValueToEntity.class).get();
        conversion.update(ricky, newStateValue);
        assertThat(ricky.lastName(), equalTo("Slaghoople"));
        assertThat(ricky.spouse().get(), nullValue());
        assertThat(ricky.children().count(), is(0));
        uow.complete();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) PersonEntity(org.qi4j.library.conversion.values.TestModel.PersonEntity) PersonValue3(org.qi4j.library.conversion.values.TestModel.PersonValue3) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Aggregations

PersonEntity (org.qi4j.library.conversion.values.TestModel.PersonEntity)14 Test (org.junit.Test)13 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)13 AbstractQi4jTest (org.qi4j.test.AbstractQi4jTest)13 PersonValue (org.qi4j.library.conversion.values.TestModel.PersonValue)4 PersonValue2 (org.qi4j.library.conversion.values.TestModel.PersonValue2)3 PersonValue3 (org.qi4j.library.conversion.values.TestModel.PersonValue3)3 PersonValue4 (org.qi4j.library.conversion.values.TestModel.PersonValue4)3