Search in sources :

Example 1 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 2 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 3 with UnitOfWork

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

the class EntityBuilderWithStateTest method test.

@Test
public void test() throws UnitOfWorkCompletionException {
    final String associatedIdentity;
    try (UnitOfWork uow = module.newUnitOfWork()) {
        EntityBuilder<SomeEntity> builder = uow.newEntityBuilder(SomeEntity.class);
        builder.instance().prop().set("Associated");
        SomeEntity entity = builder.newInstance();
        associatedIdentity = entity.identity().get();
        uow.complete();
    }
    try (UnitOfWork uow = module.newUnitOfWork()) {
        SomeEntity entity = uow.newEntityBuilderWithState(SomeEntity.class, new Function<PropertyDescriptor, Object>() {

            @Override
            public Object map(PropertyDescriptor descriptor) {
                if ("prop".equals(descriptor.qualifiedName().name())) {
                    return "Foo";
                }
                return null;
            }
        }, new Function<AssociationDescriptor, EntityReference>() {

            @Override
            public EntityReference map(AssociationDescriptor descriptor) {
                if ("ass".equals(descriptor.qualifiedName().name())) {
                    return EntityReference.parseEntityReference(associatedIdentity);
                }
                return null;
            }
        }, new Function<AssociationDescriptor, Iterable<EntityReference>>() {

            @Override
            public Iterable<EntityReference> map(AssociationDescriptor descriptor) {
                if ("manyAss".equals(descriptor.qualifiedName().name())) {
                    return Arrays.asList(EntityReference.parseEntityReference(associatedIdentity));
                }
                return null;
            }
        }, new Function<AssociationDescriptor, Map<String, EntityReference>>() {

            @Override
            public Map<String, EntityReference> map(AssociationDescriptor descriptor) {
                if ("namedAss".equals(descriptor.qualifiedName().name())) {
                    return Collections.singletonMap("foo", EntityReference.parseEntityReference(associatedIdentity));
                }
                return null;
            }
        }).newInstance();
        assertThat(entity.prop().get(), equalTo("Foo"));
        assertThat(entity.ass().get().identity().get(), equalTo(associatedIdentity));
        assertThat(entity.manyAss().get(0).identity().get(), equalTo(associatedIdentity));
        assertThat(entity.namedAss().get("foo").identity().get(), equalTo(associatedIdentity));
        uow.complete();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) Function(org.qi4j.functional.Function) PropertyDescriptor(org.qi4j.api.property.PropertyDescriptor) EntityReference(org.qi4j.api.entity.EntityReference) AssociationDescriptor(org.qi4j.api.association.AssociationDescriptor) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 4 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 5 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)

Aggregations

UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)340 Test (org.junit.Test)235 AbstractQi4jTest (org.qi4j.test.AbstractQi4jTest)111 UnitOfWorkCompletionException (org.qi4j.api.unitofwork.UnitOfWorkCompletionException)22 AssemblyException (org.qi4j.bootstrap.AssemblyException)21 Before (org.junit.Before)20 Delivery (org.qi4j.sample.dcicargo.sample_a.data.shipping.delivery.Delivery)17 ConcurrentEntityModificationException (org.qi4j.api.unitofwork.ConcurrentEntityModificationException)15 HandlingEventsEntity (org.qi4j.sample.dcicargo.sample_a.data.entity.HandlingEventsEntity)15 IOException (java.io.IOException)14 CargoAggregateRoot (org.qi4j.sample.dcicargo.sample_b.data.aggregateroot.CargoAggregateRoot)13 ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)12 HandlingEvent (org.qi4j.sample.dcicargo.sample_a.data.shipping.handling.HandlingEvent)12 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 Cargos (org.qi4j.sample.dcicargo.sample_a.data.shipping.cargo.Cargos)9 File (java.io.File)8 ArrayList (java.util.ArrayList)8 Assembler (org.qi4j.bootstrap.Assembler)8