Search in sources :

Example 6 with UnitOfWork

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

the class InterfaceCollisionWithRelatedReturnTypesTest method shouldBeAbleToSetLeadToTheResearchTeam.

@Test
public void shouldBeAbleToSetLeadToTheResearchTeam() {
    try (UnitOfWork uow = module.newUnitOfWork()) {
        ResearchTeam startUp = uow.newEntity(ResearchTeam.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 7 with UnitOfWork

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

the class InterfaceCollisionWithRelatedReturnTypesTest method shouldBeAbleToSetNameToTheCompany.

@Test
public void shouldBeAbleToSetNameToTheCompany() throws UnitOfWorkCompletionException {
    String identity;
    try (UnitOfWork uow = module.newUnitOfWork()) {
        Company startUp = uow.newEntity(Company.class);
        startUp.name().set("Acme");
        identity = ((Identity) startUp).identity().get();
        uow.complete();
    }
    try (UnitOfWork uow = module.newUnitOfWork()) {
        Company startUp = uow.get(Company.class, identity);
        assertThat(startUp.name().get(), equalTo("Acme"));
        SalesTeam sales = uow.get(SalesTeam.class, identity);
        assertThat(sales.name().get(), equalTo("Acme"));
        ResearchTeam research = uow.get(ResearchTeam.class, identity);
        assertThat(research.name().get(), equalTo("Acme"));
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) Identity(org.qi4j.api.entity.Identity) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 8 with UnitOfWork

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

the class OptionalTest method givenOptionalAssociationWhenOptionalSetThenNoException.

@Test
public void givenOptionalAssociationWhenOptionalSetThenNoException() throws Exception {
    UnitOfWork unitOfWork = module.newUnitOfWork();
    try {
        TestComposite4 ref = unitOfWork.newEntity(TestComposite4.class);
        EntityBuilder<TestComposite3> builder = unitOfWork.newEntityBuilder(TestComposite3.class);
        builder.instance().mandatoryAssociation().set(ref);
        builder.instance().optionalAssociation().set(ref);
        TestComposite3 testComposite3 = builder.newInstance();
        unitOfWork.complete();
    } finally {
        unitOfWork.discard();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 9 with UnitOfWork

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

the class AppliesToOrConditionQI241Test method testMultiConcernsBoth.

@Test
public void testMultiConcernsBoth() {
    UnitOfWork uow = module.newUnitOfWork();
    try {
        ServiceReference<SomeServiceCompositeWithTwoAnnotations> refWithTwo = module.findService(SomeServiceCompositeWithTwoAnnotations.class);
        SomeServiceCompositeWithTwoAnnotations someWithTwo = refWithTwo.get();
        someWithTwo.doStuff();
        assertTrue("AppliesTo did not match with two annotations", someWithTwo.concernHasBeenPlayed());
    } finally {
        uow.discard();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 10 with UnitOfWork

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

the class AssociationEqualityTest method givenValuesOfTheSameTypeAndSameStateWhenTestingAssociationDescriptorEqualityExpectEquals.

//
// ----------------------------:: AssociationDescriptor equality tests ::-------------------------------------------
//
@Test
public void givenValuesOfTheSameTypeAndSameStateWhenTestingAssociationDescriptorEqualityExpectEquals() {
    UnitOfWork uow = module.newUnitOfWork();
    try {
        AnEntity anEntity = uow.newEntity(AnEntity.class);
        SomeWithAssociations some = buildSomeWithAssociation(anEntity);
        AssociationDescriptor someAssocDesc = qi4j.api().associationDescriptorFor(some.anEntity());
        AssociationDescriptor someManyAssocDesc = qi4j.api().associationDescriptorFor(some.manyEntities());
        SomeWithAssociations some2 = buildSomeWithAssociation(anEntity);
        AssociationDescriptor some2AssocDesc = qi4j.api().associationDescriptorFor(some2.anEntity());
        AssociationDescriptor some2ManyAssocDesc = qi4j.api().associationDescriptorFor(some2.manyEntities());
        assertThat("AssociationDescriptor equal", someAssocDesc, equalTo(some2AssocDesc));
        assertThat("AssociationDescriptor hashcode equal", someAssocDesc.hashCode(), equalTo(some2AssocDesc.hashCode()));
        assertThat("ManyAssociationDescriptor equal", someManyAssocDesc, equalTo(some2ManyAssocDesc));
        assertThat("ManyAssociationDescriptor hashcode equal", someManyAssocDesc.hashCode(), equalTo(some2ManyAssocDesc.hashCode()));
    } finally {
        uow.discard();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) AssociationDescriptor(org.qi4j.api.association.AssociationDescriptor) 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