Moved FinTsClientTestBase back to JVM tests and adjusted to new method signatures

This commit is contained in:
dankito 2020-09-07 19:54:36 +02:00
parent a7130c94b1
commit dbc30abe2b
1 changed files with 62 additions and 49 deletions

View File

@ -6,7 +6,6 @@ import net.dankito.banking.bankfinder.InMemoryBankFinder
import net.dankito.banking.fints.callback.FinTsClientCallback import net.dankito.banking.fints.callback.FinTsClientCallback
import net.dankito.banking.fints.extensions.isTrue import net.dankito.banking.fints.extensions.isTrue
import net.dankito.banking.fints.extensions.isFalse import net.dankito.banking.fints.extensions.isFalse
import net.dankito.banking.fints.messages.datenelemente.abgeleiteteformate.Laenderkennzeichen
import net.dankito.banking.fints.messages.datenelemente.implementierte.Dialogsprache import net.dankito.banking.fints.messages.datenelemente.implementierte.Dialogsprache
import net.dankito.banking.fints.messages.datenelemente.implementierte.KundensystemStatus import net.dankito.banking.fints.messages.datenelemente.implementierte.KundensystemStatus
import net.dankito.banking.fints.messages.datenelemente.implementierte.KundensystemStatusWerte import net.dankito.banking.fints.messages.datenelemente.implementierte.KundensystemStatusWerte
@ -16,22 +15,23 @@ import net.dankito.banking.fints.messages.datenelemente.implementierte.tan.TanMe
import net.dankito.banking.fints.messages.datenelemente.implementierte.tan.TanMediumKlasse import net.dankito.banking.fints.messages.datenelemente.implementierte.tan.TanMediumKlasse
import net.dankito.banking.fints.messages.segmente.id.CustomerSegmentId import net.dankito.banking.fints.messages.segmente.id.CustomerSegmentId
import net.dankito.banking.fints.model.* import net.dankito.banking.fints.model.*
import net.dankito.banking.mapper.BankDataMapper import net.dankito.banking.fints.response.client.AddAccountResponse
import net.dankito.banking.bankfinder.BankInfo
import net.dankito.banking.fints.response.client.FinTsClientResponse import net.dankito.banking.fints.response.client.FinTsClientResponse
import net.dankito.banking.fints.util.IBase64Service import net.dankito.banking.fints.response.client.GetTransactionsResponse
import net.dankito.banking.fints.util.IThreadPool
import net.dankito.banking.fints.util.PureKotlinBase64Service import net.dankito.banking.fints.util.PureKotlinBase64Service
import net.dankito.banking.fints.webclient.KtorWebClient import net.dankito.banking.fints.webclient.KtorWebClient
import net.dankito.utils.multiplatform.Date import net.dankito.utils.multiplatform.Date
import net.dankito.utils.multiplatform.DateFormatter import net.dankito.utils.multiplatform.DateFormatter
import net.dankito.utils.multiplatform.UUID import net.dankito.utils.multiplatform.UUID
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicReference
import kotlin.test.DefaultAsserter.fail import kotlin.test.DefaultAsserter.fail
import kotlin.test.Ignore import kotlin.test.Ignore
import kotlin.test.Test import kotlin.test.Test
@Ignore // not an automatic test, supply your settings below //@Ignore // not an automatic test, supply your settings below
open class FinTsClientTestBase { open class FinTsClientTestBase {
companion object { companion object {
@ -65,20 +65,14 @@ open class FinTsClientTestBase {
} }
private val underTest = object : FinTsClient(callback, KtorWebClient(), PureKotlinBase64Service()) { private val underTest = FinTsClient(callback, KtorWebClient(), PureKotlinBase64Service())
fun testSynchronizeCustomerSystemId(bank: BankData, customer: CustomerData): FinTsClientResponse {
return synchronizeCustomerSystemId(bank, customer)
}
}
private val BankDataAnonymous = BankData("10070000", Laenderkennzeichen.Germany, "https://fints.deutsche-bank.de/", "DEUTDEBBXXX") private val BankDataAnonymous = BankData("10070000","https://fints.deutsche-bank.de/", "DEUTDEBBXXX")
// TODO: add your settings here: // TODO: add your settings here:
private val bankInfo = InMemoryBankFinder().findBankByBankCode("<your bank code (BLZ) here>").first() private val bankInfo = InMemoryBankFinder().findBankByBankCode("<your bank code (BLZ) here>").first()
private val Bank = BankDataMapper().mapFromBankInfo(bankInfo) private val Bank = BankData(bankInfo.bankCode, bankInfo.pinTanAddress ?: "", bankInfo.bic, bankInfo.name)
private val Customer = CustomerData("<your customer id (Kontonummer) here>", "<your PIN here>") private val Customer = CustomerData("<your customer id (Kontonummer) here>", "<your PIN here>")
@ -103,10 +97,22 @@ open class FinTsClientTestBase {
@Test @Test
fun addAccount() { fun addAccount() {
// given
val response = AtomicReference<AddAccountResponse>()
val countDownLatch = CountDownLatch(1)
// when // when
val result = underTest.addAccount(Bank, Customer) underTest.addAccountAsync(Bank, Customer) {
response.set(it)
countDownLatch.countDown()
}
// then // then
countDownLatch.await(30, TimeUnit.SECONDS)
val result = response.get()
expect(result.isSuccessful).isTrue() expect(result.isSuccessful).isTrue()
expect(didAskUserForTanProcedure).isFalse() expect(didAskUserForTanProcedure).isFalse()
@ -127,36 +133,32 @@ open class FinTsClientTestBase {
} }
@Test
fun synchronizeCustomerSystemId() {
// when
val result = underTest.testSynchronizeCustomerSystemId(Bank, Customer)
// then
expect(result.isSuccessful).isTrue()
expect(Customer.customerSystemId).notToBe(KundensystemStatus.SynchronizingCustomerSystemId.code) // customer system id is now set
expect(Customer.selectedLanguage).notToBe(Dialogsprache.Default) // language is set now
expect(Customer.customerSystemStatus).toBe(KundensystemStatusWerte.Benoetigt) // customerSystemStatus is set now
}
@ExperimentalWithOptions @ExperimentalWithOptions
@Test @Test
fun getTransactions() { fun getTransactions() {
// given // given
underTest.addAccount(Bank, Customer) // retrieve basic data, e.g. accounts val response = AtomicReference<GetTransactionsResponse>()
val account = Customer.accounts.firstOrNull { it.supportsFeature(AccountFeature.RetrieveAccountTransactions) } val countDownLatch = CountDownLatch(1)
expect(account).withRepresentation("We need at least one account that supports retrieving account transactions (${CustomerSegmentId.AccountTransactionsMt940.id})").notToBeNull()
// when underTest.addAccountAsync(Bank, Customer) { // retrieve basic data, e.g. accounts
val account = Customer.accounts.firstOrNull { it.supportsFeature(AccountFeature.RetrieveAccountTransactions) }
expect(account).withRepresentation("We need at least one account that supports retrieving account transactions (${CustomerSegmentId.AccountTransactionsMt940.id})").notToBeNull()
// some banks support retrieving account transactions of last 90 days without TAN // when
val result = underTest.tryGetTransactionsOfLast90DaysWithoutTan(Bank, Customer, account!!)
// some banks support retrieving account transactions of last 90 days without TAN
underTest.tryGetTransactionsOfLast90DaysWithoutTan(Bank, Customer, account!!) {
response.set(it)
countDownLatch.countDown()
}
}
// then // then
countDownLatch.await(30, TimeUnit.SECONDS)
val result = response.get()
expect(result.isSuccessful).isTrue() expect(result.isSuccessful).isTrue()
expect(result.bookedTransactions).isNotEmpty() expect(result.bookedTransactions).isNotEmpty()
} }
@ -212,26 +214,37 @@ open class FinTsClientTestBase {
fun testBankTransfer() { fun testBankTransfer() {
// given // given
underTest.addAccount(Bank, Customer) // retrieve basic data, e.g. accounts val response = AtomicReference<FinTsClientResponse>()
val countDownLatch = CountDownLatch(1)
// we need at least one account that supports cash transfer underTest.addAccountAsync(Bank, Customer) { // retrieve basic data, e.g. accounts
val account = Customer.accounts.firstOrNull { it.supportsFeature(AccountFeature.TransferMoney) } // we need at least one account that supports cash transfer
expect(account).withRepresentation("We need at least one account that supports cash transfer (${CustomerSegmentId.SepaBankTransfer.id})").notToBeNull() val account = Customer.accounts.firstOrNull { it.supportsFeature(AccountFeature.TransferMoney) }
expect(account).withRepresentation("We need at least one account that supports cash transfer (${CustomerSegmentId.SepaBankTransfer.id})").notToBeNull()
// IBAN should be set // IBAN should be set
expect(account?.iban).withRepresentation("Account IBAN must be set").notToBeNull() expect(account?.iban).withRepresentation("Account IBAN must be set").notToBeNull()
// transfer 1 cent to yourself. Transferring money to oneself also doesn't require to enter a TAN according to PSD2 // transfer 1 cent to yourself. Transferring money to oneself also doesn't require to enter a TAN according to PSD2
val BankTransferData = BankTransferData(Customer.name, account?.iban!!, Bank.bic, Money(Amount("0,01"), "EUR"), val BankTransferData = BankTransferData(Customer.name, account?.iban!!, Bank.bic, Money(Amount("0,01"), "EUR"),
"${DateTimeFormatForUniqueBankTransferUsage.format(Date())} Test transaction ${UUID.random()}") "${DateTimeFormatForUniqueBankTransferUsage.format(Date())} Test transaction ${UUID.random()}")
// when // when
underTest.doBankTransfer(BankTransferData, Bank, Customer, account) { result -> underTest.doBankTransferAsync(BankTransferData, Bank, Customer, account) { result ->
response.set(result)
countDownLatch.countDown()
}
// then
expect(result.isSuccessful).isTrue()
} }
// then
countDownLatch.await(30, TimeUnit.SECONDS)
val result = response.get()
expect(result.isSuccessful).isTrue()
} }
} }