2014-11-28 15:18:18 +00:00
|
|
|
package code.api
|
|
|
|
|
|
2016-11-28 16:23:29 +00:00
|
|
|
import java.util.{Date, UUID}
|
2017-02-27 15:56:14 +00:00
|
|
|
import java.beans.Introspector
|
2016-05-13 16:38:40 +00:00
|
|
|
|
2014-11-28 15:18:18 +00:00
|
|
|
import bootstrap.liftweb.ToSchemify
|
2017-02-27 15:56:14 +00:00
|
|
|
import code.accountholder.AccountHolders
|
2014-11-28 15:18:18 +00:00
|
|
|
import code.model._
|
2016-05-13 16:38:40 +00:00
|
|
|
import code.model.dataAccess._
|
2016-06-17 23:38:40 +00:00
|
|
|
import net.liftweb.common.Box
|
2014-11-28 15:18:18 +00:00
|
|
|
import net.liftweb.mapper.MetaMapper
|
2017-02-23 13:16:36 +00:00
|
|
|
import net.liftweb.util.Props
|
2017-02-28 07:47:47 +00:00
|
|
|
import net.liftweb.mapper.{MappedString, MetaMapper}
|
2014-11-28 15:18:18 +00:00
|
|
|
import net.liftweb.util.Helpers._
|
2016-06-25 11:42:14 +00:00
|
|
|
import code.entitlement.{Entitlement, MappedEntitlement}
|
2016-11-29 14:13:20 +00:00
|
|
|
import code.metadata.counterparties.{CounterpartyTrait, MappedCounterparty, MappedCounterpartyMetadata}
|
2016-06-25 11:42:14 +00:00
|
|
|
import code.transaction.MappedTransaction
|
2017-02-27 15:56:14 +00:00
|
|
|
import code.views.Views
|
2014-11-28 15:18:18 +00:00
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
// (same in LocalConnectorTestSetup)
|
|
|
|
|
// 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)
|
|
|
|
|
.national_identifier(randomString(5)).saveMe
|
2014-11-28 15:18:18 +00:00
|
|
|
}
|
|
|
|
|
|
2017-03-02 16:56:51 +00:00
|
|
|
override protected def createCounterparty(bankId: String, accountId: String, accountRoutingAddress: String, otherAccountRoutingScheme: String, isBeneficiary: Boolean, counterpartyId: String): CounterpartyTrait = {
|
2016-11-28 16:23:29 +00:00
|
|
|
MappedCounterparty.create.
|
2016-12-08 22:30:04 +00:00
|
|
|
mCounterPartyId(counterpartyId).
|
2016-11-29 14:13:20 +00:00
|
|
|
mName(UUID.randomUUID().toString).
|
2016-12-27 13:15:41 +00:00
|
|
|
mOtherAccountRoutingAddress(accountRoutingAddress).
|
2017-02-28 07:47:47 +00:00
|
|
|
mOtherAccountRoutingAddress(accountId).
|
2017-03-02 16:56:51 +00:00
|
|
|
mOtherAccountRoutingScheme(otherAccountRoutingScheme).
|
|
|
|
|
mOtherBankRoutingScheme("OBP").
|
2017-02-28 07:47:47 +00:00
|
|
|
mOtherBankRoutingAddress(bankId).
|
2016-11-29 14:13:20 +00:00
|
|
|
mIsBeneficiary(isBeneficiary).
|
2017-02-22 15:29:04 +00:00
|
|
|
saveMe
|
2016-11-22 19:11:45 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-31 22:42:07 +00:00
|
|
|
// TODO: Should return an option or box so can test if the insert succeeded
|
|
|
|
|
// or if it failed due to unique exception etc. However, we'll need to modify / lift callers so they can handle an Option
|
|
|
|
|
// override protected def createBank(id : String) : Option[Bank] = {
|
|
|
|
|
// val newBankOpt : Option[Bank] = try {
|
|
|
|
|
// Some(MappedBank.create
|
|
|
|
|
// .fullBankName(randomString(5))
|
|
|
|
|
// .shortBankName(randomString(5))
|
|
|
|
|
// .permalink(id)
|
|
|
|
|
// .national_identifier(randomString(5)).saveMe)
|
|
|
|
|
// } catch {
|
|
|
|
|
// case se : SQLException => None
|
|
|
|
|
// }
|
|
|
|
|
// newBankOpt
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-11-28 15:18:18 +00:00
|
|
|
override protected def createAccount(bankId: BankId, accountId : AccountId, currency : String) : BankAccount = {
|
|
|
|
|
MappedBankAccount.create
|
|
|
|
|
.bank(bankId.value)
|
|
|
|
|
.theAccountId(accountId.value)
|
|
|
|
|
.accountCurrency(currency)
|
2017-02-28 12:15:38 +00:00
|
|
|
.accountBalance(900000000)
|
2014-11-28 15:18:18 +00:00
|
|
|
.holder(randomString(4))
|
|
|
|
|
.accountNumber(randomString(4))
|
|
|
|
|
.accountLabel(randomString(4)).saveMe
|
|
|
|
|
}
|
|
|
|
|
|
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.
|
|
|
|
|
val addEntitlement = MappedEntitlement.create
|
|
|
|
|
.mBankId(bankId)
|
|
|
|
|
.mUserId(userId)
|
|
|
|
|
.mRoleName(roleName)
|
|
|
|
|
.saveMe()
|
|
|
|
|
Some(addEntitlement)
|
|
|
|
|
}
|
|
|
|
|
|
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))
|
|
|
|
|
.saveMe
|
2016-05-13 16:38:40 +00:00
|
|
|
.toTransaction.orNull
|
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_!!())
|
2017-02-23 13:16:36 +00:00
|
|
|
if (!Props.getBool("enable_remotedata", false)) {
|
|
|
|
|
ToSchemify.modelsRemotedata.filterNot(exclusion).foreach(_.bulkDelete_!!())
|
2017-02-27 15:56:14 +00:00
|
|
|
} else {
|
|
|
|
|
Views.views.vend.bulkDeleteAllPermissionsAndViews()
|
|
|
|
|
AccountHolders.accountHolders.vend.bulkDeleteAllAccountHolders()
|
2017-02-23 13:16:36 +00:00
|
|
|
}
|
2014-11-28 15:18:18 +00:00
|
|
|
}
|
|
|
|
|
}
|