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;
}
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();
}
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();
}
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.");
}
}
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();
}
}
Aggregations