2017-05-23 19:34:51 +00:00
|
|
|
package code.setup
|
2014-11-28 15:18:18 +00:00
|
|
|
|
2018-12-19 07:40:47 +00:00
|
|
|
import java.util.Date
|
2018-02-16 08:53:09 +00:00
|
|
|
|
2014-11-28 15:18:18 +00:00
|
|
|
import bootstrap.liftweb.ToSchemify
|
2018-02-16 08:53:09 +00:00
|
|
|
import code.api.util.APIUtil
|
2018-12-19 07:40:47 +00:00
|
|
|
import code.api.util.ErrorMessages._
|
2017-05-23 19:34:51 +00:00
|
|
|
import code.entitlement.Entitlement
|
2019-03-03 02:41:59 +00:00
|
|
|
import code.metadata.counterparties.Counterparties
|
2014-11-28 15:18:18 +00:00
|
|
|
import code.model._
|
2016-05-13 16:38:40 +00:00
|
|
|
import code.model.dataAccess._
|
2017-03-23 10:55:41 +00:00
|
|
|
import code.transaction.MappedTransaction
|
2018-12-19 07:40:47 +00:00
|
|
|
import code.transactionrequests.MappedTransactionRequest
|
2019-03-03 02:41:59 +00:00
|
|
|
import com.openbankproject.commons.model._
|
2016-06-17 23:38:40 +00:00
|
|
|
import net.liftweb.common.Box
|
2017-03-17 15:49:58 +00:00
|
|
|
import net.liftweb.mapper.{By, MetaMapper}
|
2014-11-28 15:18:18 +00:00
|
|
|
import net.liftweb.util.Helpers._
|
|
|
|
|
|
|
|
|
|
import scala.util.Random
|
|
|
|
|
|
2015-04-16 17:03:14 +00:00
|
|
|
trait LocalMappedConnectorTestSetup extends TestConnectorSetupWithStandardPermissions {
|
|
|
|
|
//TODO: replace all these helpers with connector agnostic methods like createRandomBank
|
|
|
|
|
// that call Connector.createBank etc.
|
2017-08-10 06:12:01 +00:00
|
|
|
// (same in LocalRecordConnectorTestSetup)
|
2015-04-16 17:03:14 +00:00
|
|
|
// Tests should simply use the currently selected connector
|
2014-11-28 15:18:18 +00:00
|
|
|
override protected def createBank(id : String) : Bank = {
|
2015-05-31 22:42:07 +00:00
|
|
|
MappedBank.create
|
|
|
|
|
.fullBankName(randomString(5))
|
|
|
|
|
.shortBankName(randomString(5))
|
|
|
|
|
.permalink(id)
|
2017-04-04 10:40:48 +00:00
|
|
|
.national_identifier(randomString(5))
|
|
|
|
|
.mBankRoutingScheme(randomString(5))
|
|
|
|
|
.mBankRoutingAddress(randomString(5))
|
|
|
|
|
.saveMe
|
2014-11-28 15:18:18 +00:00
|
|
|
}
|
|
|
|
|
|
2020-04-08 11:10:47 +00:00
|
|
|
override protected def createCounterparty(bankId: String, accountId: String, isBeneficiary: Boolean, createdByUserId:String): CounterpartyTrait = {
|
2017-12-13 08:49:04 +00:00
|
|
|
Counterparties.counterparties.vend.createCounterparty(
|
|
|
|
|
createdByUserId = createdByUserId,
|
2017-03-17 15:49:58 +00:00
|
|
|
thisBankId = bankId,
|
|
|
|
|
thisAccountId = accountId,
|
|
|
|
|
thisViewId = "",
|
2018-10-09 10:02:16 +00:00
|
|
|
name = APIUtil.generateUUID(),
|
2020-05-05 14:15:52 +00:00
|
|
|
otherAccountRoutingScheme = "OBP",
|
2018-03-14 11:22:57 +00:00
|
|
|
otherAccountRoutingAddress = accountId,
|
2020-05-05 14:15:52 +00:00
|
|
|
otherBankRoutingScheme = "OBP",
|
2017-03-17 15:49:58 +00:00
|
|
|
otherBankRoutingAddress = bankId,
|
2020-05-05 14:15:52 +00:00
|
|
|
otherBranchRoutingScheme ="OBP",
|
2017-03-20 13:26:12 +00:00
|
|
|
otherBranchRoutingAddress ="Berlin",
|
2017-10-16 13:09:52 +00:00
|
|
|
isBeneficiary = isBeneficiary,
|
2018-03-14 11:22:57 +00:00
|
|
|
otherAccountSecondaryRoutingScheme ="IBAN",
|
|
|
|
|
otherAccountSecondaryRoutingAddress ="DE89 3704 0044 0532 0130 00",
|
2017-10-16 13:09:52 +00:00
|
|
|
description = "String",
|
|
|
|
|
bespoke = Nil
|
2018-01-31 15:03:46 +00:00
|
|
|
).openOrThrowException(attemptedToOpenAnEmptyBox)
|
2016-11-22 19:11:45 +00:00
|
|
|
}
|
|
|
|
|
|
2014-11-28 15:18:18 +00:00
|
|
|
override protected def createAccount(bankId: BankId, accountId : AccountId, currency : String) : BankAccount = {
|
|
|
|
|
MappedBankAccount.create
|
|
|
|
|
.bank(bankId.value)
|
2019-07-11 07:57:14 +00:00
|
|
|
.accountIban(randomString(20))//Added the Iban for test accounts
|
2014-11-28 15:18:18 +00:00
|
|
|
.theAccountId(accountId.value)
|
2019-10-26 23:25:47 +00:00
|
|
|
.accountCurrency(currency.toUpperCase)
|
2017-02-28 12:15:38 +00:00
|
|
|
.accountBalance(900000000)
|
2014-11-28 15:18:18 +00:00
|
|
|
.holder(randomString(4))
|
|
|
|
|
.accountNumber(randomString(4))
|
2017-04-04 10:40:48 +00:00
|
|
|
.accountLabel(randomString(4))
|
|
|
|
|
.mAccountRoutingScheme(randomString(4))
|
|
|
|
|
.mAccountRoutingAddress(randomString(4))
|
|
|
|
|
.mBranchId(randomString(4))
|
|
|
|
|
.saveMe
|
2014-11-28 15:18:18 +00:00
|
|
|
}
|
|
|
|
|
|
2017-03-03 10:19:24 +00:00
|
|
|
override protected def updateAccountCurrency(bankId: BankId, accountId : AccountId, currency : String) : BankAccount = {
|
2019-10-26 23:25:47 +00:00
|
|
|
MappedBankAccount.find(By(MappedBankAccount.bank, bankId.value), By(MappedBankAccount.theAccountId, accountId.value)).openOrThrowException(attemptedToOpenAnEmptyBox).accountCurrency(currency.toUpperCase).saveMe()
|
2017-03-03 10:19:24 +00:00
|
|
|
}
|
|
|
|
|
|
2016-06-17 23:38:40 +00:00
|
|
|
def addEntitlement(bankId: String, userId: String, roleName: String): Box[Entitlement] = {
|
|
|
|
|
// Return a Box so we can handle errors later.
|
2017-05-03 09:45:38 +00:00
|
|
|
Entitlement.entitlement.vend.addEntitlement(bankId, userId, roleName)
|
2016-06-17 23:38:40 +00:00
|
|
|
}
|
|
|
|
|
|
2014-11-28 15:18:18 +00:00
|
|
|
override protected def createTransaction(account: BankAccount, startDate: Date, finishDate: Date) = {
|
|
|
|
|
//ugly
|
|
|
|
|
val mappedBankAccount = account.asInstanceOf[MappedBankAccount]
|
|
|
|
|
|
|
|
|
|
val accountBalanceBefore = mappedBankAccount.accountBalance.get
|
|
|
|
|
val transactionAmount = Random.nextInt(1000).toLong
|
|
|
|
|
val accountBalanceAfter = accountBalanceBefore + transactionAmount
|
|
|
|
|
|
|
|
|
|
mappedBankAccount.accountBalance(accountBalanceAfter).save
|
|
|
|
|
|
|
|
|
|
MappedTransaction.create
|
|
|
|
|
.bank(account.bankId.value)
|
|
|
|
|
.account(account.accountId.value)
|
|
|
|
|
.transactionType(randomString(5))
|
|
|
|
|
.tStartDate(startDate)
|
|
|
|
|
.tFinishDate(finishDate)
|
|
|
|
|
.currency(account.currency)
|
|
|
|
|
.amount(transactionAmount)
|
|
|
|
|
.newAccountBalance(accountBalanceAfter)
|
|
|
|
|
.description(randomString(5))
|
|
|
|
|
.counterpartyAccountHolder(randomString(5))
|
|
|
|
|
.counterpartyAccountKind(randomString(5))
|
|
|
|
|
.counterpartyAccountNumber(randomString(5))
|
|
|
|
|
.counterpartyBankName(randomString(5))
|
|
|
|
|
.counterpartyIban(randomString(5))
|
|
|
|
|
.counterpartyNationalId(randomString(5))
|
2017-12-06 08:33:16 +00:00
|
|
|
.CPOtherAccountRoutingScheme(randomString(5))
|
|
|
|
|
.CPOtherAccountRoutingAddress(randomString(5))
|
|
|
|
|
.CPOtherAccountSecondaryRoutingScheme(randomString(5))
|
|
|
|
|
.CPOtherAccountSecondaryRoutingAddress(randomString(5))
|
|
|
|
|
.CPOtherBankRoutingScheme(randomString(5))
|
|
|
|
|
.CPOtherBankRoutingAddress(randomString(5))
|
2014-11-28 15:18:18 +00:00
|
|
|
.saveMe
|
2016-05-13 16:38:40 +00:00
|
|
|
.toTransaction.orNull
|
2014-11-28 15:18:18 +00:00
|
|
|
}
|
|
|
|
|
|
2018-04-10 13:34:22 +00:00
|
|
|
override protected def createTransactionRequest(account: BankAccount) = {
|
|
|
|
|
|
|
|
|
|
MappedTransactionRequest.create
|
2018-10-09 10:02:16 +00:00
|
|
|
.mTransactionRequestId(APIUtil.generateUUID())
|
2018-04-10 13:34:22 +00:00
|
|
|
.mType("SANDBOX_TAN")
|
|
|
|
|
.mFrom_BankId(account.bankId.value)
|
|
|
|
|
.mFrom_AccountId(account.accountId.value)
|
|
|
|
|
.mTo_BankId(randomString(5))
|
|
|
|
|
.mTo_AccountId(randomString(5))
|
|
|
|
|
.mBody_Value_Currency(account.currency)
|
2018-04-11 16:11:42 +00:00
|
|
|
.mBody_Value_Amount("10")
|
2018-04-10 13:34:22 +00:00
|
|
|
.mBody_Description("This is a description..")
|
|
|
|
|
.mStatus("COMPLETED")
|
|
|
|
|
.mStartDate(now)
|
|
|
|
|
.mEndDate(now)
|
|
|
|
|
.saveMe
|
2018-04-11 16:11:42 +00:00
|
|
|
|
|
|
|
|
MappedTransactionRequest.create
|
2018-10-09 10:02:16 +00:00
|
|
|
.mTransactionRequestId(APIUtil.generateUUID())
|
2018-04-11 16:11:42 +00:00
|
|
|
.mType("SANDBOX_TAN")
|
|
|
|
|
.mFrom_BankId(account.bankId.value)
|
|
|
|
|
.mFrom_AccountId(account.accountId.value)
|
|
|
|
|
.mTo_BankId(randomString(5))
|
|
|
|
|
.mTo_AccountId(randomString(5))
|
|
|
|
|
.mBody_Value_Currency(account.currency)
|
|
|
|
|
.mBody_Value_Amount("1001")
|
|
|
|
|
.mBody_Description("This is a description..")
|
|
|
|
|
.mStatus("INITIATED")
|
|
|
|
|
.mStartDate(now)
|
|
|
|
|
.mEndDate(now)
|
|
|
|
|
.saveMe
|
2018-04-10 13:34:22 +00:00
|
|
|
}
|
|
|
|
|
|
2014-11-28 15:18:18 +00:00
|
|
|
override protected def wipeTestData() = {
|
|
|
|
|
//returns true if the model should not be wiped after each test
|
|
|
|
|
def exclusion(m : MetaMapper[_]) = {
|
2017-02-09 13:34:42 +00:00
|
|
|
m == Nonce || m == Token || m == Consumer || m == AuthUser || m == ResourceUser
|
2014-11-28 15:18:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//empty the relational db tables after each test
|
|
|
|
|
ToSchemify.models.filterNot(exclusion).foreach(_.bulkDelete_!!())
|
2018-12-19 07:40:47 +00:00
|
|
|
ToSchemify.modelsRemotedata.filterNot(exclusion).foreach(_.bulkDelete_!!())
|
2014-11-28 15:18:18 +00:00
|
|
|
}
|
|
|
|
|
}
|