Fixed that most parameters of account info (HIUPD) are optional and therefore may not set

This commit is contained in:
dankl 2019-10-13 02:58:30 +02:00 committed by dankito
parent c20bf13c5c
commit 94ccfd2e09
3 changed files with 43 additions and 8 deletions

View File

@ -158,14 +158,14 @@ open class ResponseParser @JvmOverloads constructor(
val bankCountryCode = parseInt(accountDetails[2])
val bankCode = parseString(accountDetails[3])
val iban = parseStringToNullIfEmpty(dataElementGroups[2])
val iban = parseStringToNullIfEmpty(dataElementGroups[2]) // optional
val customerId = parseString(dataElementGroups[3])
val accountType = parseCodeEnum(dataElementGroups[4], AccountTypeCode.values()).type
val currency = parseString(dataElementGroups[5])
val accountType = parseNullableCodeEnum(dataElementGroups[4], AccountTypeCode.values())?.type
val currency = parseStringToNullIfEmpty(dataElementGroups[5])
val accountHolderName1 = parseString(dataElementGroups[6])
val accountHolderName2 = parseStringToNullIfEmpty(dataElementGroups[7])
val productName = parseStringToNullIfEmpty(dataElementGroups[8])
val limit = parseStringToNullIfEmpty(dataElementGroups[9]) // TODO: parse limit
val accountHolderName2 = if (dataElementGroups.size > 7) parseStringToNullIfEmpty(dataElementGroups[7]) else null
val productName = if (dataElementGroups.size > 8) parseStringToNullIfEmpty(dataElementGroups[8]) else null
val limit = if (dataElementGroups.size > 9) parseStringToNullIfEmpty(dataElementGroups[9]) else null // TODO: parse limit
// TODO: parse allowed jobs
// TODO: parse extension
@ -362,6 +362,14 @@ open class ResponseParser @JvmOverloads constructor(
return allValues.first { it.code == code }
}
protected open fun <T : ICodeEnum> parseNullableCodeEnum(code: String, allValues: Array<T>): T? {
try {
return parseCodeEnum(code, allValues)
} catch (ignored: Exception) { }
return null
}
protected open fun getDataElements(dataElementGroup: String): List<String> {
return splitIntoPartsAndUnmask(dataElementGroup, Separators.DataElementsSeparator)

View File

@ -8,8 +8,8 @@ open class AccountInfo(
val bankCode: String,
val iban: String?,
val customerId: String,
val accountType: AccountType,
val currency: String, // TODO: may parse to a value object
val accountType: AccountType?,
val currency: String?, // TODO: may parse to a value object
val accountHolderName1: String,
val accountHolderName2: String?,
val productName: String?,

View File

@ -214,6 +214,33 @@ class ResponseParserTest : FinTsTestBase() {
?: run { Assert.fail("No segment of type AccountInfo found in ${result.receivedSegments}") }
}
@Test
fun parseAccountInfo_OptionalFieldsNotSet() {
// when
val result = underTest.parse("HIUPD:74:6:3+9999999999::280:10070000++9999999999+++anonym")
// then
assertSuccessfullyParsedSegment(result, InstituteSegmentId.AccountInfo, 74, 6, 3)
result.getFirstSegmentById<AccountInfo>(InstituteSegmentId.AccountInfo)?.let { segment ->
assertThat(segment.accountNumber).isEqualTo("9999999999")
assertThat(segment.subAccountAttribute).isNull()
assertThat(segment.bankCountryCode).isEqualTo(280)
assertThat(segment.bankCode).isEqualTo("10070000")
assertThat(segment.iban).isNull()
assertThat(segment.customerId).isEqualTo("9999999999")
assertThat(segment.accountType).isNull()
assertThat(segment.currency).isNull()
assertThat(segment.accountHolderName1).isEqualTo("anonym")
assertThat(segment.accountHolderName2).isNull()
assertThat(segment.productName).isNull()
assertThat(segment.accountLimit).isNull()
assertThat(segment.extension).isNull()
}
?: run { Assert.fail("No segment of type AccountInfo found in ${result.receivedSegments}") }
}
@Test
fun parseTanInfo() {