Search in sources :

Example 31 with UnitOfWork

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

the class EntityVisibilityTest method givenFromEntityWhenAccessingAboveModuleVisibleExpectException.

@Test(expected = EntityTypeNotFoundException.class)
public void givenFromEntityWhenAccessingAboveModuleVisibleExpectException() {
    UnitOfWork unitOfWork = module.newUnitOfWork();
    try {
        FromEntity entity = unitOfWork.newEntity(FromEntity.class, "123");
        entity.aboveModuleVisible();
    } finally {
        if (unitOfWork.isOpen()) {
            unitOfWork.discard();
        }
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) Test(org.junit.Test)

Example 32 with UnitOfWork

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);
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 33 with UnitOfWork

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);
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 34 with UnitOfWork

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

the class Qi382Test method givenCreationOfTwoEntitiesWhenAssigningOneToOtherExpectCompletionToSucceed.

@Test
public void givenCreationOfTwoEntitiesWhenAssigningOneToOtherExpectCompletionToSucceed() throws UnitOfWorkCompletionException {
    try (UnitOfWork unitOfWork = module.newUnitOfWork()) {
        Car car = unitOfWork.newEntity(Car.class, "Ferrari");
        unitOfWork.complete();
    }
    try (UnitOfWork unitOfWork = module.newUnitOfWork()) {
        Car car = unitOfWork.get(Car.class, "Ferrari");
        assertThat(car, notNullValue());
        Person p = unitOfWork.get(Person.class, "Niclas");
        assertThat(p, notNullValue());
        assertThat(p.car().get(), equalTo(car));
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 35 with UnitOfWork

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

the class IssueTest method givenEntityWithComplexConstrainedPropertyWhenInvalidPropertyValueSetThenThrowException.

@Test
public void givenEntityWithComplexConstrainedPropertyWhenInvalidPropertyValueSetThenThrowException() {
    UnitOfWork uow = module.newUnitOfWork();
    try {
        TestCase testCase = uow.newEntity(TestCase.class);
        testCase.otherProperty().set("");
        uow.complete();
        fail("Should not be allowed to set invalid property value");
    } catch (Exception e) {
        uow.discard();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) AssemblyException(org.qi4j.bootstrap.AssemblyException) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

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