Added DialogEnde und MessageBuilder.createDialogEndMessage()

This commit is contained in:
dankl 2019-10-05 17:20:49 +02:00 committed by dankito
parent d90ec3a888
commit bf70706f9c
4 changed files with 86 additions and 16 deletions

View File

@ -36,26 +36,39 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg
*
* Bei anonymen Dialogen werden Nachrichten weder signiert, noch können sie verschlüsselt und komprimiert werden.
*/
open fun createAnonymousDialogInitMessage(bank: BankData, product: ProductData): String {
/**
* Wenn eine Synchronisierung der Kundensystem-ID durchgeführt wird, ist als Identifizierung der Partei 0 einzustellen.
*/
open fun createAnonymousDialogInitMessage(bank: BankData, product: ProductData, dialogData: DialogData): String {
val customer = CustomerData.Anonymous
return createMessage(false, false, bank, customer, DialogData.DialogInitDialogData, listOf(
return createMessage(false, false, bank, customer, dialogData, listOf(
IdentifikationsSegment(generator.resetSegmentNumber(1), bank, customer),
Verarbeitungsvorbereitung(generator.getNextSegmentNumber(), bank, customer, product)
))
}
open fun createDialogInitMessage(bank: BankData, customer: CustomerData, product: ProductData): String {
open fun createAnonymousDialogEndMessage(bank: BankData, dialogData: DialogData): String {
return createMessage(true, true, bank, customer, DialogData.DialogInitDialogData, listOf(
val customer = CustomerData.Anonymous
return createMessage(false, false, bank, customer, dialogData, listOf(
Dialogende(generator.resetSegmentNumber(1), dialogData)
))
}
open fun createDialogInitMessage(bank: BankData, customer: CustomerData, product: ProductData, dialogData: DialogData): String {
return createMessage(true, true, bank, customer, dialogData, listOf(
IdentifikationsSegment(generator.resetSegmentNumber(2), bank, customer),
Verarbeitungsvorbereitung(generator.getNextSegmentNumber(), bank, customer, product),
ZweiSchrittTanEinreichung(generator.getNextSegmentNumber(), TanProcess.TanProcess4, "HKIDN")
ZweiSchrittTanEinreichung(generator.getNextSegmentNumber(), TanProcess.TanProcess4, "HKIDN") // TODO: make job reference referencable, don't hard code
))
}
open fun createDialogEndMessage(bank: BankData, customer: CustomerData, dialogData: DialogData): String {
return createMessage(true, true, bank, customer, dialogData, listOf(
Dialogende(generator.resetSegmentNumber(2), dialogData)
))
}

View File

@ -0,0 +1,17 @@
package net.dankito.fints.messages.segmente.implementierte
import net.dankito.fints.messages.Existenzstatus
import net.dankito.fints.messages.datenelemente.implementierte.DialogId
import net.dankito.fints.messages.datenelementgruppen.implementierte.Segmentkopf
import net.dankito.fints.messages.segmente.Segment
import net.dankito.fints.model.DialogData
class Dialogende(
segmentNumber: Int,
dialogData: DialogData
) : Segment(listOf(
Segmentkopf("HKEND", 1, segmentNumber),
DialogId(dialogData.dialogId)
), Existenzstatus.Mandatory)

View File

@ -4,6 +4,7 @@ import net.dankito.fints.messages.datenelemente.abgeleiteteformate.Laenderkennze
import net.dankito.fints.messages.datenelemente.implementierte.Dialogsprache
import net.dankito.fints.messages.datenelemente.implementierte.signatur.Sicherheitsfunktion
import net.dankito.fints.model.*
import java.util.*
abstract class FinTsTestBase {
@ -37,6 +38,10 @@ abstract class FinTsTestBase {
}
protected open fun createDialogId(): String {
return UUID.randomUUID().toString().replace("-", "")
}
protected open fun normalizeBinaryData(message: String): String {
return message.replace(0.toChar(), ' ')
}

View File

@ -1,6 +1,7 @@
package net.dankito.fints.messages
import net.dankito.fints.FinTsTestBase
import net.dankito.fints.model.DialogData
import net.dankito.fints.util.FinTsUtils
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
@ -23,11 +24,8 @@ class MessageBuilderTest : FinTsTestBase() {
@Test
fun createAnonymousDialogInitMessage() {
// given
val underTest = underTest.createAnonymousDialogInitMessage(Bank, Product)
// when
val result = underTest.format()
val result = underTest.createAnonymousDialogInitMessage(Bank, Product, DialogData.DialogInitDialogData)
// then
assertThat(result).isEqualTo(
@ -39,13 +37,29 @@ class MessageBuilderTest : FinTsTestBase() {
}
@Test
fun createDialogInitMessage() {
fun createAnonymousDialogEndMessage() {
// given
val underTest = underTest.createDialogInitMessage(Bank, Customer, Product)
val dialogId = createDialogId()
val dialogData = DialogData(dialogId)
// when
val result = underTest.format()
val result = underTest.createAnonymousDialogEndMessage(Bank, dialogData)
// then
assertThat(normalizeBinaryData(result)).isEqualTo(normalizeBinaryData(
"HNHBK:1:3+000000000086+300+$dialogId+1'" +
"HKEND:2:1+$dialogId'" +
"HNHBS:3:1+1'"
))
}
@Test
fun createDialogInitMessage() {
// when
val result = underTest.createDialogInitMessage(Bank, Customer, Product, DialogData.DialogInitDialogData)
// then
assertThat(normalizeBinaryData(result)).isEqualTo(normalizeBinaryData(
@ -60,4 +74,25 @@ class MessageBuilderTest : FinTsTestBase() {
))
}
@Test
fun createDialogEndMessage() {
// given
val dialogId = createDialogId()
val dialogData = DialogData(dialogId)
// when
val result = underTest.createDialogEndMessage(Bank, Customer, dialogData)
// then
assertThat(normalizeBinaryData(result)).isEqualTo(normalizeBinaryData(
"HNHBK:1:3+000000000340+300+$dialogId+1'" +
"HNVSK:998:3+PIN:2+998+1+1::0+1:$Date:$Time+2:16:14:@8@ :5:1+280:$BankCode:$CustomerId:V:0:0+0'" +
"HNVSD:999:1+@177@" + "HNSHK:2:4+PIN:2+${SecurityFunction.code}+$ControlReference+1+1+1::0+1+1:$Date:$Time+1:999:1+6:10:16+280:$BankCode:$CustomerId:S:0:0'" +
"HNSHA:3:2+$ControlReference++$Pin''" +
"HKEND:4:1+$dialogId'" +
"HNHBS:5:1+1'"
))
}
}