Search in sources :

Example 86 with UnitOfWork

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

the class AbstractIssueTest method newQi4jAccount.

/**
     * Creates a new qi4j account.
     *
     * @return The new account identity.
     *
     * @throws org.qi4j.api.unitofwork.UnitOfWorkCompletionException
     *          Thrown if creational fail.
     */
protected final String newQi4jAccount() throws UnitOfWorkCompletionException {
    UnitOfWork work = module.newUnitOfWork();
    EntityBuilder<AccountComposite> entityBuilder = work.newEntityBuilder(AccountComposite.class);
    AccountComposite accountComposite = entityBuilder.instance();
    accountComposite.name().set(DEFAULT_ACCOUNT_NAME);
    accountComposite = entityBuilder.newInstance();
    String identity = accountComposite.identity().get();
    work.complete();
    return identity;
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork)

Example 87 with UnitOfWork

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

the class IssueTest method testUnitOfWorkWithUnitOfWorkInitialized.

@Test
public final void testUnitOfWorkWithUnitOfWorkInitialized() throws Throwable {
    // Bootstrap the account
    String id = newQi4jAccount();
    // Make sure there's no unit of work
    assertFalse(module.isUnitOfWorkActive());
    UnitOfWork parentUnitOfWork = module.newUnitOfWork();
    AccountComposite account = accountService.getAccountById(id);
    assertNotNull(account);
    UnitOfWork currentUnitOfWork = module.currentUnitOfWork();
    assertEquals(parentUnitOfWork, currentUnitOfWork);
    assertTrue(currentUnitOfWork.isOpen());
    // Close the parent unit of work
    parentUnitOfWork.complete();
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) AccountComposite(org.qi4j.index.rdf.qi64.AccountComposite) Test(org.junit.Test) AbstractIssueTest(org.qi4j.index.rdf.qi64.AbstractIssueTest)

Example 88 with UnitOfWork

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

the class IssueTest method testUnitOfWorkInitialized.

@Test
public final void testUnitOfWorkInitialized() throws Throwable {
    // Bootstrap the account
    String id = newQi4jAccount();
    // Make sure there's no unit of work
    assertFalse(module.isUnitOfWorkActive());
    UnitOfWork parentUnitOfWork = module.newUnitOfWork();
    AccountComposite account = accountService.getAccountById(id);
    assertNotNull(account);
    UnitOfWork currentUnitOfWork = module.currentUnitOfWork();
    assertEquals(parentUnitOfWork, currentUnitOfWork);
    assertTrue(currentUnitOfWork.isOpen());
    // Close the parent unit of work
    parentUnitOfWork.complete();
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) AccountComposite(org.qi4j.index.rdf.qi64.AccountComposite) Test(org.junit.Test) AbstractIssueTest(org.qi4j.index.rdf.qi64.AbstractIssueTest)

Example 89 with UnitOfWork

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

the class Qi66IssueTest method testCompleteAfterFind.

@Test
public final void testCompleteAfterFind() throws Exception {
    String accountIdentity = newQi4jAccount();
    UnitOfWork work = module.newUnitOfWork();
    AccountComposite account = work.get(AccountComposite.class, accountIdentity);
    assertNotNull(account);
    try {
        work.complete();
    } catch (Throwable e) {
        e.printStackTrace();
        fail("No exception can be thrown.");
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 90 with UnitOfWork

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

the class ContainsAllTest method performContainsAllStringsTest.

private ExampleEntity performContainsAllStringsTest(Set<String> entityStrings, Set<String> queryableStrings) throws Exception {
    UnitOfWork creatingUOW = this.module.newUnitOfWork();
    String[] entityStringsArray = new String[entityStrings.size()];
    createEntityWithStrings(creatingUOW, this.module, entityStrings.toArray(entityStringsArray));
    creatingUOW.complete();
    UnitOfWork queryingUOW = this.module.newUnitOfWork();
    try {
        String[] queryableStringsArray = new String[queryableStrings.size()];
        ExampleEntity entity = this.findEntity(queryableStrings.toArray(queryableStringsArray));
        return entity;
    } finally {
        queryingUOW.discard();
    }
}
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