Search in sources :

Example 96 with UnitOfWork

use of org.qi4j.api.unitofwork.UnitOfWork 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 97 with UnitOfWork

use of org.qi4j.api.unitofwork.UnitOfWork 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 98 with UnitOfWork

use of org.qi4j.api.unitofwork.UnitOfWork 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 99 with UnitOfWork

use of org.qi4j.api.unitofwork.UnitOfWork in project qi4j-sdk by Qi4j.

the class StandardAlarmModelTest method createAlarm.

private AlarmPoint createAlarm(String name) {
    UnitOfWork uow = module.currentUnitOfWork();
    EntityBuilder<AlarmPoint> builder = uow.newEntityBuilder(AlarmPoint.class);
    builder.instance().category().set(createCategory("StandardModelTest"));
    AlarmPoint.AlarmState state = builder.instanceFor(AlarmPoint.AlarmState.class);
    state.currentStatus().set(createStatus(AlarmPoint.STATUS_NORMAL));
    state.description().set("Test Description");
    state.systemName().set(name);
    return builder.newInstance();
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork)

Example 100 with UnitOfWork

use of org.qi4j.api.unitofwork.UnitOfWork in project qi4j-sdk by Qi4j.

the class StandardAlarmModelTest method tearDown.

@Override
public void tearDown() throws Exception {
    UnitOfWork uow = module.currentUnitOfWork();
    if (uow != null) {
        uow.discard();
    }
    super.tearDown();
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork)

Aggregations

UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)332 Test (org.junit.Test)232 AbstractQi4jTest (org.qi4j.test.AbstractQi4jTest)108 Before (org.junit.Before)21 AssemblyException (org.qi4j.bootstrap.AssemblyException)21 UnitOfWorkCompletionException (org.qi4j.api.unitofwork.UnitOfWorkCompletionException)18 Delivery (org.qi4j.sample.dcicargo.sample_a.data.shipping.delivery.Delivery)17 HandlingEventsEntity (org.qi4j.sample.dcicargo.sample_a.data.entity.HandlingEventsEntity)15 PersonEntity (org.qi4j.library.conversion.values.TestModel.PersonEntity)13 CargoAggregateRoot (org.qi4j.sample.dcicargo.sample_b.data.aggregateroot.CargoAggregateRoot)13 IOException (java.io.IOException)12 ConcurrentEntityModificationException (org.qi4j.api.unitofwork.ConcurrentEntityModificationException)12 ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)12 Cargos (org.qi4j.sample.dcicargo.sample_a.data.shipping.cargo.Cargos)12 HandlingEvent (org.qi4j.sample.dcicargo.sample_a.data.shipping.handling.HandlingEvent)12 Location (org.qi4j.sample.dcicargo.sample_a.data.shipping.location.Location)11 HandlingEventAggregateRoot (org.qi4j.sample.dcicargo.sample_b.data.aggregateroot.HandlingEventAggregateRoot)11 Date (java.util.Date)10 BalanceData (org.qi4j.dci.moneytransfer.domain.data.BalanceData)10 File (java.io.File)8