Skip to content

Commit

Permalink
added comments to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wasabrot committed May 4, 2024
1 parent 57a8a49 commit 15d30fe
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
# sudo docker run -v $HOME/ebics:/root/ebics ebics -cp "ebics-cli.jar:lib/*" org.kopi.ebics.client.EbicsClient --sta -o /root/ebics/out sta.txt

FROM gradle:6-jdk11 AS build
# with local java and using sdkman
# sdk use java 11.0.23-tem && sdk use java 11.0.23-tem

# build ebics-client jar and server jars;
RUN ls -la; mkdir /app;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class EbicsApplicationTests {

@Test
public void contextLoads() {
// log.debug("ebics.textproxy:{}",TESTPROXY);
// Simple test if spring context are loading
log.debug("Ebics spring context loaded");
}
}
13 changes: 10 additions & 3 deletions src/test/java/io/element36/cash36/ebics/EbicsControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,35 @@
import io.element36.cash36.ebics.dto.StatementDTO;

/**
* Test API call getPayments/ on the controler
*
* gradle -x checkstyleMain test --tests io.element36.cash36.ebics.EbicsControllerTest.testGetStatusReport
*/

@RunWith(SpringRunner.class)
@SpringBootTest
public class EbicsControllerTest {


// the service to be tested
@Autowired EbicsController controller;

@Test
public void testGetPayments() throws Exception {

// testing the getPayments() method of a Spring MVC controller named EbicsController

ResponseEntity<List<StatementDTO>> payments = controller.getPayments();
assertThat(payments).isNotNull();
assertThat(payments.getBody()).isNotNull();

// chedk if payments are found
assertThat(payments.getBody().size()).isGreaterThan(0);

for (StatementDTO item : payments.getBody()) {
System.out.println("-----------------------");
// print the statement
TestTool.pp(item);
}
// test content
// test content
TestTool.testProxyStatements(payments.getBody());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@
@RunWith(SpringRunner.class)
@SpringBootTest(properties = {"ebics.mode=disabled", "ebics.outputDir=./out"})
@ActiveProfiles("prod")
/**
* This test is meant to run only in PROD configurations, which real bank backends.
*/
public class EbicsPaymentServiceProdTests {

// Access to service where we can trigger payments
@Autowired EbicsPaymentService ebicsPaymentService;

/**
* Make a test payment through the payment service.
*
*/
@Test
public void makePayment() throws Exception {
// String makePayment(String msgId, String pmtInfId, String sourceIban, String sourceBic,
Expand All @@ -32,6 +40,7 @@ public void makePayment() throws Exception {
// values taken from
// https://www.iban.com/structure

// execute a payment and read the response.
TxResponse txResponse =
ebicsPaymentService.makePayment(
"4711",
Expand All @@ -54,15 +63,24 @@ public void makePayment() throws Exception {
false);

System.out.println(txResponse);
// now we want to get hands of the actual Ebics PAIN document, which was
// sent by the bank backend, not only the JSON "business object"
String fileName=txResponse.getEbicsDocumentPath().trim();
String content=TestTool.readLineByLineJava8(fileName);
//System.out.println("Payment File content:\n:"+content);

// we replace timestamps to that we can compare the Ebics XML response.
// Everything should be like we defined in MSG; but of course the timestamps
// are different. So we replace them to make a String comparison.

content=TestTool.findAndReplaceTagContent("CreDtTm", "2021-07-16T14:43:03", content);
content=TestTool.findAndReplaceTagContent("ReqdExctnDt", "2021-07-16", content);
org.assertj.core.api.Assertions.assertThat(content).isEqualTo(TestTool.PAIN1);
}

@Test
/**
* Trigger a payment and check the PAIN-XML (payment instruction) generated by the payment service.
*/
public void simulatePayment() throws Exception {
// String makePayment(String msgId, String pmtInfId, String sourceIban, String sourceBic,
// BigDecimal amount,
Expand Down Expand Up @@ -100,6 +118,11 @@ public void simulatePayment() throws Exception {
String fileName=txResponse.getEbicsDocumentPath();
String content=TestTool.readLineByLineJava8(fileName);
System.out.println("Payment File content:\n:"+content);

// we replace timestamps to that we can compare the Ebics XML response.
// Everything should be like we defined in MSG; but of course the timestamps
// are different. So we replace them to make a String comparison.

content=TestTool.findAndReplaceTagContent("CreDtTm", "2021-07-16T15:12:31", content);
content=TestTool.findAndReplaceTagContent("ReqdExctnDt", "2021-07-16", content);
org.assertj.core.api.Assertions.assertThat(content).isEqualTo(TestTool.PAIN2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
@SpringBootTest
public class EbicsPaymentServiceTests {

// Service to be tested
@Autowired EbicsPaymentService ebicsPaymentService;

@Test
/**
* Test the payment call which triggers an OUTGOING payment (incoming done by simulatePayment below)
*/
public void makePayment() throws Exception {
// String makePayment(String msgId, String pmtInfId, String sourceIban, String sourceBic,
// BigDecimal amount,
Expand All @@ -30,6 +34,8 @@ public void makePayment() throws Exception {
// values taken from
// https://www.iban.com/structure


// execute a payment via the configured service, get the response.
TxResponse txResponse =
ebicsPaymentService.makePayment(
"4711",
Expand All @@ -55,12 +61,20 @@ public void makePayment() throws Exception {
String fileName=txResponse.getEbicsDocumentPath().trim();
String content=TestTool.readLineByLineJava8(fileName);
//System.out.println("Payment File content:\n:"+content);

// we replace timestamps to that we can compare the Ebics XML response.
// Everything should be like we defined in MSG; but of course the timestamps
// are different. So we replace them to make a String comparison

content=TestTool.findAndReplaceTagContent("CreDtTm", "2021-07-16T14:43:03", content);
content=TestTool.findAndReplaceTagContent("ReqdExctnDt", "2021-07-16", content);
org.assertj.core.api.Assertions.assertThat(content).isEqualTo(TestTool.PAIN1);
}

@Test
/**
* Test the simulate Payment service call, which simulates in INCOMING payment.
*/
public void simulatePayment() throws Exception {
// String makePayment(String msgId, String pmtInfId, String sourceIban, String sourceBic,
// BigDecimal amount,
Expand Down Expand Up @@ -98,6 +112,11 @@ public void simulatePayment() throws Exception {
String fileName=txResponse.getEbicsDocumentPath();
String content=TestTool.readLineByLineJava8(fileName);
System.out.println("Payment File content:\n:"+content);

// we replace timestamps to that we can compare the Ebics XML response.
// Everything should be like we defined in MSG; but of course the timestamps
// are different. So we replace them to make a String comparison

content=TestTool.findAndReplaceTagContent("CreDtTm", "2021-07-16T15:12:31", content);
content=TestTool.findAndReplaceTagContent("ReqdExctnDt", "2021-07-16", content);
org.assertj.core.api.Assertions.assertThat(content).isEqualTo(TestTool.PAIN2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,23 @@

@RunWith(SpringRunner.class)
@SpringBootTest
/**
* Call StatusReport (z01 document) from the banking backend.
*/
public class EbicsPaymentStatusServiceTest {

// the service to be tested
@Autowired EbicsPaymentStatusService ebicsPaymentStatusService;

@Test
public void getStatus() {
// Get Status of our payments, and print it. Its informative
// because we do not rely on status messages, but
// for debugging purpuse is might be interesting to
// see the status of each transaction.
List<PaymentStatusReportDTO> transactions = ebicsPaymentStatusService.getStatusReport();
for (PaymentStatusReportDTO tx : transactions) {
// print message id
System.out.println("msg-id: " + tx.getMsgId());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,30 @@

@RunWith(SpringRunner.class)
@SpringBootTest
/**
* Reads daily statement of a bank, according to EBICS specification.
* Means that if you call Service once, the backend will mark
* the statements you received. Next time the service is called it
* will only get new data if there are new transactions.
*/
public class EbicsStatementServiceTest {

// the service to be tested
@Autowired EbicsStatementService ebicsStatementService;

@Test
public void testReadBankStatement() throws Exception {
// get all non-fetched bank statements, print how many we found
List<StatementDTO> statement = ebicsStatementService.getBankStatement();
pp("no. statements: ", statement.size());

assertThat(statement.size()).isBetween(1, 3);
boolean reachedIn = false;
boolean reachedOut = false;
// go into each statement report
for (StatementDTO account : statement) {
// print the information and check if there
// are incoming and outgoing transactions, otherwise fail.
pp(
"account: ",
account.getBalanceCL(),
Expand Down Expand Up @@ -57,6 +68,8 @@ public void testReadBankStatement() throws Exception {
reachedOut = true;
}
}

// check for in and outgoing transactions were found
assertThat(reachedIn).isTrue();
assertThat(reachedOut).isTrue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,31 @@

@RunWith(SpringRunner.class)
@SpringBootTest
/**
* We generate Ids on the backend; lets test the algo.
*/
public class GeneratePaymentIdTest {

// service to be tested
@Autowired GeneratePaymentIds paymentIds;

@Test
public void testMsgId() throws Exception {
// Create a new message Id; test the null/default behaviour
String id = paymentIds.getMsgId(null, null);
pp("tx-id" + id);
assertThat(id).isNotNull();
// compliant with Ebics standard
assertThat(id.length()).isBetween(10, 250);
}

@Test
public void testPmtInfId() throws Exception {
// generate a payment id.
String id = paymentIds.getPmtInfId(null, null);
pp("tx-id" + id);
assertThat(id).isNotNull();
// should be OK with ebics standard.
assertThat(id.length()).isBetween(1, 250);
}
}
17 changes: 15 additions & 2 deletions src/test/java/io/element36/cash36/ebics/PaymentStatusTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,49 @@
@RunWith(SpringRunner.class)
@SpringBootTest(properties = {"ebics.mode=proxy"})
public class PaymentStatusTest {

// for storing test data
private static final String TMP_DIR = System.getProperty("java.io.tmpdir") + "/";

// the service to be tested
@Autowired PaymentStatus paymentStatus;


@Test
/**
* We test the paymeentStatus backend with test data of MSG (PAIN file below).
*/
public void testLoad() throws Exception {

// we need to convert the variable to a format which is
// typical for ebics and can be processed by the service

File tempFile = File.createTempFile(TMP_DIR + "test", ".xml");

// Writes a string to the above temporary file

Files.write(tempFile.toPath(), MSG.getBytes(StandardCharsets.UTF_8));
// zip it
File zipFile = File.createTempFile(TMP_DIR + "test", ".zip");

FileOutputStream fos = new FileOutputStream(zipFile);
ZipOutputStream zos = new ZipOutputStream(fos);

// add tempFile to zip
zos.putNextEntry(new ZipEntry(tempFile.getName()));

// convert tmepFile to bytes
byte[] bytes = Files.readAllBytes(Paths.get(tempFile.getAbsolutePath()));
zos.write(bytes, 0, bytes.length);
zos.closeEntry();
zos.close();

// call the paymentStatus with the ZipFile
List<PaymentStatusReportDTO> status = paymentStatus.process(zipFile);
assertThat(status.size()).isEqualTo(1);
}

// MSG is a message, actually a PAIN file (payment instruction) - which
// is sent to bank backend to trigger a payment. Later this payment (transaction) is
// visible in the bank statement.
static final String MSG =
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
+ " <Document xmlns=\"http://www.six-interbank-clearing.com/de/pain.002.001.03.ch.02.xsd\">\n"
Expand Down
Loading

0 comments on commit 15d30fe

Please sign in to comment.