Search in sources :

Example 1 with BalanceData

use of org.qi4j.dci.moneytransfer.domain.data.BalanceData in project qi4j-sdk by Qi4j.

the class TransferMoneyTest method transferHalfOfMoneyFromSavingsToChecking.

@Test
public void transferHalfOfMoneyFromSavingsToChecking() throws Exception {
    UnitOfWork uow = assembler.module().newUnitOfWork(UsecaseBuilder.newUsecase("Transfer from savings to checking"));
    try {
        // Select source and destination
        BalanceData source = uow.get(BalanceData.class, SAVINGS_ACCOUNT_ID);
        BalanceData destination = uow.get(BalanceData.class, CHECKING_ACCOUNT_ID);
        // Instantiate context and execute enactments with that context
        TransferMoneyContext context = new TransferMoneyContext();
        context.bind(source, destination);
        // Query for half the balance
        final Integer amountToTransfer = context.availableFunds() / 2;
        // Transfer from savings to checking
        context.transfer(amountToTransfer);
    } finally {
        uow.discard();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) BalanceData(org.qi4j.dci.moneytransfer.domain.data.BalanceData) TransferMoneyContext(org.qi4j.dci.moneytransfer.context.TransferMoneyContext) Test(org.junit.Test)

Example 2 with BalanceData

use of org.qi4j.dci.moneytransfer.domain.data.BalanceData in project qi4j-sdk by Qi4j.

the class TransferMoneyTest method transferTwiceOfMoneyFromSavingsToChecking.

@Test(expected = IllegalArgumentException.class)
public void transferTwiceOfMoneyFromSavingsToChecking() throws Exception {
    UnitOfWork uow = assembler.module().newUnitOfWork(UsecaseBuilder.newUsecase("Transfer from savings to checking"));
    try {
        // Select source and destination
        BalanceData source = uow.get(BalanceData.class, SAVINGS_ACCOUNT_ID);
        BalanceData destination = uow.get(BalanceData.class, CHECKING_ACCOUNT_ID);
        // Instantiate context and execute enactments with that context
        TransferMoneyContext context = new TransferMoneyContext();
        context.bind(source, destination);
        // Query for double the balance
        final Integer amountToTransfer = context.availableFunds() * 2;
        // Transfer from savings to checking
        context.transfer(amountToTransfer);
    } finally {
        uow.discard();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) BalanceData(org.qi4j.dci.moneytransfer.domain.data.BalanceData) TransferMoneyContext(org.qi4j.dci.moneytransfer.context.TransferMoneyContext) Test(org.junit.Test)

Example 3 with BalanceData

use of org.qi4j.dci.moneytransfer.domain.data.BalanceData in project qi4j-sdk by Qi4j.

the class TransferMoneyTest2 method payAllBills.

@Test
public void payAllBills() throws Exception {
    UnitOfWork uow = module.newUnitOfWork(newUsecase("Pay all bills from checking to creditors"));
    try {
        BalanceData source = uow.get(BalanceData.class, CHECKING_ACCOUNT_ID);
        PayBillsContext2 context = module.newObject(PayBillsContext2.class);
        context.bind(source).payBills();
    } finally {
        uow.discard();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) BalanceData(org.qi4j.dci.moneytransfer.domain.data.BalanceData) PayBillsContext2(org.qi4j.dci.moneytransfer.context.PayBillsContext2) Test(org.junit.Test)

Example 4 with BalanceData

use of org.qi4j.dci.moneytransfer.domain.data.BalanceData in project qi4j-sdk by Qi4j.

the class TransferMoneyTest method bootstrapData.

private static void bootstrapData(SingletonAssembler assembler) throws Exception {
    UnitOfWork uow = assembler.module().newUnitOfWork(newUsecase("Bootstrap data"));
    try {
        SavingsAccountEntity savingsAccount = uow.newEntity(SavingsAccountEntity.class, SAVINGS_ACCOUNT_ID);
        savingsAccount.increasedBalance(1000);
        CheckingAccountEntity checkingAccount = uow.newEntity(CheckingAccountEntity.class, CHECKING_ACCOUNT_ID);
        checkingAccount.increasedBalance(200);
        // Create some creditor debt
        BalanceData bakerAccount = uow.newEntity(CreditorRolemap.class, CREDITOR_ID1);
        bakerAccount.decreasedBalance(50);
        BalanceData butcherAccount = uow.newEntity(CreditorRolemap.class, CREDITOR_ID2);
        butcherAccount.decreasedBalance(90);
        // Save
        uow.complete();
    } finally {
        uow.discard();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) SavingsAccountEntity(org.qi4j.dci.moneytransfer.domain.entity.SavingsAccountEntity) BalanceData(org.qi4j.dci.moneytransfer.domain.data.BalanceData) CheckingAccountEntity(org.qi4j.dci.moneytransfer.domain.entity.CheckingAccountEntity)

Example 5 with BalanceData

use of org.qi4j.dci.moneytransfer.domain.data.BalanceData in project qi4j-sdk by Qi4j.

the class TransferMoneyTest method payAllBills.

@Test
public void payAllBills() throws Exception {
    UnitOfWork uow = assembler.module().newUnitOfWork(newUsecase("Pay all bills from checking to creditors"));
    try {
        BalanceData source = uow.get(BalanceData.class, CHECKING_ACCOUNT_ID);
        PayBillsContext context = new PayBillsContext();
        context.bind(source).payBills();
    } finally {
        uow.discard();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) BalanceData(org.qi4j.dci.moneytransfer.domain.data.BalanceData) PayBillsContext(org.qi4j.dci.moneytransfer.context.PayBillsContext) Test(org.junit.Test)

Aggregations

UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)8 BalanceData (org.qi4j.dci.moneytransfer.domain.data.BalanceData)8 Test (org.junit.Test)6 TransferMoneyContext (org.qi4j.dci.moneytransfer.context.TransferMoneyContext)2 TransferMoneyContext2 (org.qi4j.dci.moneytransfer.context.TransferMoneyContext2)2 CheckingAccountEntity (org.qi4j.dci.moneytransfer.domain.entity.CheckingAccountEntity)2 SavingsAccountEntity (org.qi4j.dci.moneytransfer.domain.entity.SavingsAccountEntity)2 PayBillsContext (org.qi4j.dci.moneytransfer.context.PayBillsContext)1 PayBillsContext2 (org.qi4j.dci.moneytransfer.context.PayBillsContext2)1