Search in sources :

Example 11 with UnitOfWork

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

the class AssociationEqualityTest method givenValuesOfTheSameTypeAndDifferentStateWhenTestingAssociationEqualityExpectNotEquals.

@Test
public void givenValuesOfTheSameTypeAndDifferentStateWhenTestingAssociationEqualityExpectNotEquals() {
    UnitOfWork uow = module.newUnitOfWork();
    try {
        SomeWithAssociations some = buildSomeWithAssociation(uow.newEntity(AnEntity.class));
        SomeWithAssociations some2 = buildSomeWithAssociation(uow.newEntity(AnEntity.class));
        assertThat("Association not equal", some.anEntity(), not(equalTo(some2.anEntity())));
        assertThat("Association hashcode not equal", some.anEntity().hashCode(), not(equalTo(some2.anEntity().hashCode())));
        assertThat("ManyAssociation not equal", some.manyEntities(), not(equalTo(some2.manyEntities())));
        assertThat("ManyAssociation hashcode not equal", some.manyEntities().hashCode(), not(equalTo(some2.manyEntities().hashCode())));
    } finally {
        uow.discard();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 12 with UnitOfWork

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

the class AssociationEqualityTest method givenValuesOfDifferentTypesAndSameStateWhenTestingAssociationEqualityExpectNotEquals.

@Test
public void givenValuesOfDifferentTypesAndSameStateWhenTestingAssociationEqualityExpectNotEquals() {
    UnitOfWork uow = module.newUnitOfWork();
    try {
        AnEntity anEntity = uow.newEntity(AnEntity.class);
        SomeWithAssociations some = buildSomeWithAssociation(anEntity);
        OtherWithAssociations other = buildOtherWithAssociation(anEntity);
        assertThat("Association not equal", some.anEntity(), not(equalTo(other.anEntity())));
        assertThat("Association hashcode not equal", some.anEntity().hashCode(), not(equalTo(other.anEntity().hashCode())));
        assertThat("ManyAssociation not equal", some.manyEntities(), not(equalTo(other.manyEntities())));
        assertThat("ManyAssociation hashcode not equal", some.manyEntities().hashCode(), not(equalTo(other.manyEntities().hashCode())));
    } finally {
        uow.discard();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 13 with UnitOfWork

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

the class AssociationEqualityTest method givenValuesOfTheSameTypeAndSameStateWhenTestingAssociationEqualityExpectEquals.

//
// ----------------------------------:: Association equality tests ::-----------------------------------------------
//
@Test
public void givenValuesOfTheSameTypeAndSameStateWhenTestingAssociationEqualityExpectEquals() {
    UnitOfWork uow = module.newUnitOfWork();
    try {
        AnEntity anEntity = uow.newEntity(AnEntity.class);
        SomeWithAssociations some = buildSomeWithAssociation(anEntity);
        SomeWithAssociations some2 = buildSomeWithAssociation(anEntity);
        assertThat("Association equal", some.anEntity(), equalTo(some2.anEntity()));
        assertThat("Association hashcode equal", some.anEntity().hashCode(), equalTo(some2.anEntity().hashCode()));
        assertThat("ManyAssociation equal", some.manyEntities(), equalTo(some2.manyEntities()));
        assertThat("ManyAssociation hashcode equal", some.manyEntities().hashCode(), equalTo(some2.manyEntities().hashCode()));
    } finally {
        uow.discard();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 14 with UnitOfWork

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

the class GenericConcernTest method testNestedUnitOfWork.

@Test
public void testNestedUnitOfWork() {
    UnitOfWork uow = module.newUnitOfWork();
    Some some = module.newTransient(Some.class);
    some.doStuff();
    uow.discard();
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 15 with UnitOfWork

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

the class Qi4jAPITest method testGetModuleOfComposite.

@Test
public void testGetModuleOfComposite() throws Exception {
    UnitOfWork unitOfWork = module.newUnitOfWork();
    TestEntity testEntity = unitOfWork.newEntity(TestEntity.class);
    api.moduleOf(testEntity);
    unitOfWork.discard();
    api.moduleOf(module.newValue(TestValue.class));
    api.moduleOf(module.newTransient(TestTransient.class));
    api.moduleOf(module.findService(TestService.class).get());
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) 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