Moved FinTsClientTestBase back to JVM tests and adjusted to new method signatures
This commit is contained in:
parent
a7130c94b1
commit
dbc30abe2b
|
@ -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 countDownLatch = CountDownLatch(1)
|
||||||
|
|
||||||
|
underTest.addAccountAsync(Bank, Customer) { // retrieve basic data, e.g. accounts
|
||||||
val account = Customer.accounts.firstOrNull { it.supportsFeature(AccountFeature.RetrieveAccountTransactions) }
|
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()
|
expect(account).withRepresentation("We need at least one account that supports retrieving account transactions (${CustomerSegmentId.AccountTransactionsMt940.id})").notToBeNull()
|
||||||
|
|
||||||
// when
|
// when
|
||||||
|
|
||||||
// some banks support retrieving account transactions of last 90 days without TAN
|
// some banks support retrieving account transactions of last 90 days without TAN
|
||||||
val result = underTest.tryGetTransactionsOfLast90DaysWithoutTan(Bank, Customer, account!!)
|
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,8 +214,10 @@ 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)
|
||||||
|
|
||||||
|
underTest.addAccountAsync(Bank, Customer) { // retrieve basic data, e.g. accounts
|
||||||
// we need at least one account that supports cash transfer
|
// we need at least one account that supports cash transfer
|
||||||
val account = Customer.accounts.firstOrNull { it.supportsFeature(AccountFeature.TransferMoney) }
|
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()
|
expect(account).withRepresentation("We need at least one account that supports cash transfer (${CustomerSegmentId.SepaBankTransfer.id})").notToBeNull()
|
||||||
|
@ -227,11 +231,20 @@ open class FinTsClientTestBase {
|
||||||
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
underTest.doBankTransfer(BankTransferData, Bank, Customer, account) { result ->
|
underTest.doBankTransferAsync(BankTransferData, Bank, Customer, account) { result ->
|
||||||
|
response.set(result)
|
||||||
|
countDownLatch.countDown()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// then
|
// then
|
||||||
|
countDownLatch.await(30, TimeUnit.SECONDS)
|
||||||
|
val result = response.get()
|
||||||
|
|
||||||
expect(result.isSuccessful).isTrue()
|
expect(result.isSuccessful).isTrue()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue