mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 15:27:01 +00:00
Switch connector implementation to LocalMappedConnector and switch the tests to test against it
This commit is contained in:
parent
4eb62378af
commit
0c9dd81cfa
@ -15,7 +15,7 @@ object Connector extends SimpleInjector {
|
||||
|
||||
val connector = new Inject(buildOne _) {}
|
||||
|
||||
def buildOne: Connector = LocalConnector
|
||||
def buildOne: Connector = LocalMappedConnector
|
||||
|
||||
}
|
||||
|
||||
|
||||
72
src/test/scala/code/api/LocalMappedConnectorTestSetup.scala
Normal file
72
src/test/scala/code/api/LocalMappedConnectorTestSetup.scala
Normal file
@ -0,0 +1,72 @@
|
||||
package code.api
|
||||
|
||||
import java.util.Date
|
||||
import bootstrap.liftweb.ToSchemify
|
||||
import code.model.dataAccess._
|
||||
import code.model._
|
||||
import net.liftweb.mapper.MetaMapper
|
||||
import net.liftweb.util.Helpers._
|
||||
|
||||
import scala.util.Random
|
||||
|
||||
trait LocalMappedConnectorTestSetup extends LocalConnectorTestSetup {
|
||||
|
||||
override protected def createBank(id : String) : Bank = {
|
||||
MappedBank.create
|
||||
.fullBankName(randomString(5))
|
||||
.shortBankName(randomString(5))
|
||||
.permalink(id)
|
||||
.national_identifier(randomString(5)).saveMe
|
||||
}
|
||||
|
||||
override protected def createAccount(bankId: BankId, accountId : AccountId, currency : String) : BankAccount = {
|
||||
MappedBankAccount.create
|
||||
.bank(bankId.value)
|
||||
.theAccountId(accountId.value)
|
||||
.accountCurrency(currency)
|
||||
.accountBalance(10000)
|
||||
.holder(randomString(4))
|
||||
.accountNumber(randomString(4))
|
||||
.accountLabel(randomString(4)).saveMe
|
||||
}
|
||||
|
||||
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
|
||||
.toTransaction.openOrThrowException("Test setup issue: could not create Transaction")
|
||||
}
|
||||
|
||||
override protected def wipeTestData() = {
|
||||
//returns true if the model should not be wiped after each test
|
||||
def exclusion(m : MetaMapper[_]) = {
|
||||
m == Nonce || m == Token || m == Consumer || m == OBPUser || m == APIUser
|
||||
}
|
||||
|
||||
//empty the relational db tables after each test
|
||||
ToSchemify.models.filterNot(exclusion).foreach(_.bulkDelete_!!())
|
||||
}
|
||||
}
|
||||
@ -33,7 +33,7 @@ Berlin 13359, Germany
|
||||
package code.api.test
|
||||
|
||||
import code.TestServer
|
||||
import code.api.LocalConnectorTestSetup
|
||||
import code.api.{LocalMappedConnectorTestSetup, LocalConnectorTestSetup}
|
||||
import org.scalatest._
|
||||
import dispatch._
|
||||
import net.liftweb.json.{Serialization, NoTypeHints}
|
||||
@ -42,7 +42,7 @@ import net.liftweb.common._
|
||||
trait ServerSetup extends FeatureSpec with SendServerRequests
|
||||
with BeforeAndAfterEach with GivenWhenThen
|
||||
with BeforeAndAfterAll
|
||||
with ShouldMatchers with Loggable with LocalConnectorTestSetup {
|
||||
with ShouldMatchers with Loggable with LocalMappedConnectorTestSetup {
|
||||
|
||||
var server = TestServer
|
||||
implicit val formats = Serialization.formats(NoTypeHints)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user