TerminalApiClientIntegrationTest.kt (3441B)
1 // This file is part of taler-cashless2ecash. 2 // Copyright (C) 2024 Joel Häberli 3 // 4 // taler-cashless2ecash is free software: you can redistribute it and/or modify it 5 // under the terms of the GNU Affero General Public License as published 6 // by the Free Software Foundation, either version 3 of the License, 7 // or (at your option) any later version. 8 // 9 // taler-cashless2ecash is distributed in the hope that it will be useful, but 10 // WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 // Affero General Public License for more details. 13 // 14 // You should have received a copy of the GNU Affero General Public License 15 // along with this program. If not, see <http://www.gnu.org/licenses/>. 16 // 17 // SPDX-License-Identifier: AGPL3.0-or-later 18 19 package ch.bfh.habej2.wallee_c2ec 20 21 import ch.bfh.habej2.wallee_c2ec.client.taler.TerminalClientImplementation 22 import ch.bfh.habej2.wallee_c2ec.client.taler.config.TalerTerminalConfig 23 import ch.bfh.habej2.wallee_c2ec.client.taler.encoding.CyptoUtils.encodeCrock 24 import ch.bfh.habej2.wallee_c2ec.client.taler.encoding.CyptoUtilsTest 25 import ch.bfh.habej2.wallee_c2ec.client.taler.model.TerminalWithdrawalConfirmationRequest 26 import ch.bfh.habej2.wallee_c2ec.client.taler.model.TerminalWithdrawalSetup 27 import ch.bfh.habej2.wallee_c2ec.withdrawal.ManageActivity 28 import org.junit.Assert.assertTrue 29 import org.junit.Test 30 31 class TerminalApiClientIntegrationTest { 32 33 private val config = TalerTerminalConfig( 34 "TEST Exchange", 35 "http://taler-c2ec.ti.bfh.ch", 36 "Simulation-1", 37 "Gofobz8XYEX0H3rts4+w3K7bU68wSP2N5Y36FBe4/f8=" 38 ) 39 40 private val config2 = TalerTerminalConfig( 41 "CHF Exchange", 42 "https://terminals.chf.taler.net", 43 "Simulation-1", 44 "Gofobz8XYEX0H3rts4+w3K7bU68wSP2N5Y36FBe4/f8=" 45 ) 46 47 private val client = TerminalClientImplementation(config2) 48 49 private var currency = "" 50 private var wopid = "" 51 52 private val sleepMs = 1000L 53 private val longPollMs = 3000L 54 55 @Test 56 fun flow() { 57 // load config 58 client.terminalsConfig { 59 assertTrue(it.isPresent) 60 currency = it.get().currency 61 println("loaded config. currency=$currency") 62 } 63 64 Thread.sleep(sleepMs) 65 66 // setup withdrawal 67 client.setupWithdrawal(TerminalWithdrawalSetup( 68 encodeCrock(CyptoUtilsTest().rand32Bytes()), 69 "CHF:21.30" 70 )) { 71 assertTrue(it.isPresent) 72 wopid = it.get().withdrawalId 73 println("setup withdrawal. wopid=$wopid") 74 } 75 76 Thread.sleep(sleepMs) 77 78 // send check request 79 client.sendConfirmationRequest(wopid, TerminalWithdrawalConfirmationRequest("TEST-$wopid", "CHF:21.30")) { 80 assertTrue(it) 81 println("payment is attested. result=$it") 82 } 83 84 // load status 85 client.retrieveWithdrawalStatus(wopid, longPollMs.toInt()) { 86 assertTrue(it.isPresent) 87 println("status retrieved. status=${it.get().status}") 88 } 89 90 Thread.sleep(longPollMs+1000) 91 } 92 93 @Test 94 fun simulateRegistration() { 95 96 // ATD2GW6ZNJ5FQ8B6R890C4G13RN3RZTQ1P6VT2ZT5V04AP7DG9K0 97 wopid = ""; 98 ManageActivity.simulateParameterRegistration( 99 "https://taler-c2ec.ti.bfh.ch/taler-integration", 100 wopid 101 ) 102 } 103 }