Skip to content

Commit 081eb48

Browse files
committed
Add tests for BalancePlatformWebhooksTest
1 parent a2d39c6 commit 081eb48

4 files changed

Lines changed: 274 additions & 0 deletions

File tree

src/test/java/com/adyen/webhooks/BalancePlatformWebhooksTest.java

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.adyen.model.transferwebhooks.TransferWebhooksHandler;
2929
import com.adyen.util.HMACValidator;
3030
import java.security.SignatureException;
31+
import java.time.OffsetDateTime;
3132
import java.util.Optional;
3233
import org.junit.jupiter.api.Assertions;
3334
import org.junit.jupiter.api.Test;
@@ -619,6 +620,11 @@ public void testMandateCreatedNotificationRequest() {
619620
assertEquals(Mandate.StatusEnum.APPROVED, request.getData().getMandate().getStatus());
620621
assertEquals(Mandate.TypeEnum.BACS, request.getData().getMandate().getType());
621622

623+
// createdAt and updatedAt are now deserialized as OffsetDateTime
624+
OffsetDateTime expectedDate = OffsetDateTime.parse("2025-09-04T13:40:41.581Z");
625+
assertEquals(expectedDate, request.getData().getMandate().getCreatedAt());
626+
assertEquals(expectedDate, request.getData().getMandate().getUpdatedAt());
627+
622628
assertNotNull(request.getData().getMandate().getCounterparty());
623629
assertNotNull(request.getData().getMandate().getCounterparty().getAccountHolder());
624630
assertEquals(
@@ -638,4 +644,173 @@ public void testMandateCreatedNotificationRequest() {
638644
assertEquals("405081", ukLocalAccountId.getSortCode());
639645
assertEquals(UKLocalMandateAccountIdentification.TypeEnum.UKLOCAL, ukLocalAccountId.getType());
640646
}
647+
648+
@Test
649+
public void testMandateNotificationWithInvalidDates() {
650+
String json =
651+
"{\"data\":{\"balancePlatform\":\"YOUR_BALANCE_PLATFORM\",\"mandate\":{"
652+
+ "\"id\":\"MNDT000000000000000000000001\",\"status\":\"approved\",\"type\":\"bacs\","
653+
+ "\"createdAt\":\"not-a-date\",\"updatedAt\":\"not-a-date\"}},"
654+
+ "\"environment\":\"test\",\"type\":\"balancePlatform.mandate.created\"}";
655+
656+
ConfigurationWebhooksHandler handler = new ConfigurationWebhooksHandler(json);
657+
// createdAt/updatedAt are now OffsetDateTime, an invalid date fails deserialization
658+
assertFalse(handler.getMandateNotificationRequest().isPresent());
659+
}
660+
661+
@Test
662+
public void testMandateNotificationWithUnknownAccountIdentificationType() {
663+
String json =
664+
"{\"data\":{\"balancePlatform\":\"YOUR_BALANCE_PLATFORM\",\"mandate\":{"
665+
+ "\"id\":\"MNDT000000000000000000000001\",\"status\":\"approved\",\"type\":\"bacs\","
666+
+ "\"counterparty\":{\"accountIdentification\":{\"type\":\"unknownType\"}}}},"
667+
+ "\"environment\":\"test\",\"type\":\"balancePlatform.mandate.created\"}";
668+
669+
ConfigurationWebhooksHandler handler = new ConfigurationWebhooksHandler(json);
670+
// an unknown account identification discriminator type fails deserialization
671+
assertFalse(handler.getMandateNotificationRequest().isPresent());
672+
}
673+
674+
@Test
675+
public void testPaymentInstrumentIbanAdditionalBankAccountIdentification() {
676+
String json =
677+
getFileContents(
678+
"mocks/balancePlatform-webhooks/configuration-paymentInstrument-created.json");
679+
680+
ConfigurationWebhooksHandler handler = new ConfigurationWebhooksHandler(json);
681+
Optional<PaymentNotificationRequest> optionalRequest = handler.getPaymentNotificationRequest();
682+
assertTrue(optionalRequest.isPresent());
683+
684+
PaymentNotificationRequest request = optionalRequest.get();
685+
assertEquals(
686+
PaymentNotificationRequest.TypeEnum.BALANCEPLATFORM_PAYMENTINSTRUMENT_CREATED,
687+
request.getType());
688+
assertEquals("test", request.getEnvironment());
689+
690+
PaymentInstrument paymentInstrument = request.getData().getPaymentInstrument();
691+
assertNotNull(paymentInstrument);
692+
assertEquals("PI00000000000000000001", paymentInstrument.getId());
693+
assertNotNull(paymentInstrument.getAdditionalBankAccountIdentifications());
694+
assertEquals(1, paymentInstrument.getAdditionalBankAccountIdentifications().size());
695+
696+
// the discriminator (type=iban) resolves to IbanAccountIdentification
697+
IbanAccountIdentification ibanAccountIdentification =
698+
paymentInstrument
699+
.getAdditionalBankAccountIdentifications()
700+
.get(0)
701+
.getIbanAccountIdentification();
702+
assertNotNull(ibanAccountIdentification);
703+
assertEquals("NL11ADYB00000000", ibanAccountIdentification.getIban());
704+
assertEquals(IbanAccountIdentification.TypeEnum.IBAN, ibanAccountIdentification.getType());
705+
}
706+
707+
@Test
708+
public void testPaymentInstrumentUnknownAdditionalBankAccountIdentificationType() {
709+
String json =
710+
"{\"data\":{\"balancePlatform\":\"YOUR_BALANCE_PLATFORM\",\"paymentInstrument\":{"
711+
+ "\"id\":\"PI00000000000000000001\",\"balanceAccountId\":\"BA00000000000000000001\","
712+
+ "\"issuingCountryCode\":\"NL\",\"status\":\"active\",\"type\":\"bankAccount\","
713+
+ "\"additionalBankAccountIdentifications\":[{\"type\":\"unknownType\"}]}},"
714+
+ "\"environment\":\"test\",\"type\":\"balancePlatform.paymentInstrument.created\"}";
715+
716+
ConfigurationWebhooksHandler handler = new ConfigurationWebhooksHandler(json);
717+
// an unknown additional bank account identification discriminator type fails deserialization
718+
assertFalse(handler.getPaymentNotificationRequest().isPresent());
719+
}
720+
721+
@Test
722+
public void testTopUpConfigurationCreatedNotificationRequest() {
723+
String json =
724+
getFileContents(
725+
"mocks/balancePlatform-webhooks/balanceplatform-recurringTopUp-created.json");
726+
727+
ConfigurationWebhooksHandler handler = new ConfigurationWebhooksHandler(json);
728+
Optional<TopUpConfigurationEventRequest> optionalRequest =
729+
handler.getTopUpConfigurationEventRequest();
730+
assertTrue(optionalRequest.isPresent());
731+
732+
TopUpConfigurationEventRequest request = optionalRequest.get();
733+
assertEquals(
734+
TopUpConfigurationEventRequest.TypeEnum
735+
.BALANCEPLATFORM_BALANCEACCOUNT_RECURRINGTOPUP_CREATED,
736+
request.getType());
737+
assertEquals("test", request.getEnvironment());
738+
assertNotNull(request.getTimestamp());
739+
740+
TopUpWebhookData data = request.getData();
741+
assertNotNull(data);
742+
assertEquals("BA00000000000000000001", data.getAccountId());
743+
assertEquals("YOUR_BALANCE_PLATFORM", data.getBalancePlatform());
744+
assertNotNull(data.getCreationDate());
745+
746+
WebhookTopUpConfiguration config = data.getWebhookTopUpConfiguration();
747+
assertNotNull(config);
748+
assertEquals("TU4227C224555B5FTD2NT2JV4WN5", config.getId());
749+
assertEquals("Top up when balance is low", config.getDescription());
750+
assertEquals("TopUpFromSavings", config.getReferenceForBeneficiary());
751+
assertEquals(WebhookTopUpConfiguration.StatusEnum.ACTIVE, config.getStatus());
752+
753+
assertNotNull(config.getCounterparty());
754+
assertEquals("SE00000000000000000001", config.getCounterparty().getTransferInstrumentId());
755+
756+
assertNotNull(config.getMandate());
757+
assertEquals("MND00000000000000000001", config.getMandate().getReference());
758+
assertNotNull(config.getMandate().getCreationDate());
759+
760+
assertNotNull(config.getTopUpAmount());
761+
assertEquals("EUR", config.getTopUpAmount().getFixedAmount().getCurrency());
762+
assertEquals(Long.valueOf(10000), config.getTopUpAmount().getFixedAmount().getValue());
763+
764+
assertNotNull(config.getTrigger());
765+
assertEquals(WebhookTopUpTrigger.ScheduleEnum.WEEKLY, config.getTrigger().getSchedule());
766+
assertEquals(Long.valueOf(5000), config.getTrigger().getThreshold().getValue());
767+
}
768+
769+
@Test
770+
public void testTopUpConfigurationUpdatedNotificationRequest() {
771+
String json =
772+
getFileContents(
773+
"mocks/balancePlatform-webhooks/balanceplatform-recurringTopUp-updated.json");
774+
775+
ConfigurationWebhooksHandler handler = new ConfigurationWebhooksHandler(json);
776+
Optional<TopUpConfigurationUpdatedEventRequest> optionalRequest =
777+
handler.getTopUpConfigurationUpdatedEventRequest();
778+
assertTrue(optionalRequest.isPresent());
779+
780+
TopUpConfigurationUpdatedEventRequest request = optionalRequest.get();
781+
assertEquals(
782+
TopUpConfigurationUpdatedEventRequest.TypeEnum
783+
.BALANCEPLATFORM_BALANCEACCOUNT_RECURRINGTOPUP_UPDATED,
784+
request.getType());
785+
assertEquals("test", request.getEnvironment());
786+
assertNotNull(request.getTimestamp());
787+
788+
TopUpUpdatedWebhookData data = request.getData();
789+
assertNotNull(data);
790+
assertEquals("BA00000000000000000001", data.getAccountId());
791+
assertEquals("YOUR_BALANCE_PLATFORM", data.getBalancePlatform());
792+
793+
WebhookTopUpConfigurationUpdated config = data.getWebhookTopUpConfiguration();
794+
assertNotNull(config);
795+
assertEquals("Top up when balance is low - updated", config.getDescription());
796+
assertEquals(WebhookTopUpConfigurationUpdated.StatusEnum.INACTIVE, config.getStatus());
797+
assertEquals("counterpartyAccountBlocked", config.getDisabledReason());
798+
assertEquals("The counterparty account is blocked.", config.getReasonDetail());
799+
assertEquals(Long.valueOf(15000), config.getTopUpAmount().getFixedAmount().getValue());
800+
assertEquals(WebhookTopUpTrigger.ScheduleEnum.MONTHLY, config.getTrigger().getSchedule());
801+
assertEquals(Long.valueOf(3000), config.getTrigger().getThreshold().getValue());
802+
}
803+
804+
@Test
805+
public void testTopUpConfigurationWithUnknownTypeReturnsEmpty() {
806+
String json =
807+
"{\"data\":{\"balancePlatform\":\"YOUR_BALANCE_PLATFORM\"},"
808+
+ "\"environment\":\"test\","
809+
+ "\"type\":\"balancePlatform.balanceAccount.recurringTopUp.unknown\"}";
810+
811+
ConfigurationWebhooksHandler handler = new ConfigurationWebhooksHandler(json);
812+
// an unknown event type does not match the TopUp created/updated type enums
813+
assertFalse(handler.getTopUpConfigurationEventRequest().isPresent());
814+
assertFalse(handler.getTopUpConfigurationUpdatedEventRequest().isPresent());
815+
}
641816
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"data": {
3+
"balancePlatform": "YOUR_BALANCE_PLATFORM",
4+
"creationDate": "2026-04-17T10:30:00+01:00",
5+
"accountId": "BA00000000000000000001",
6+
"webhookTopUpConfiguration": {
7+
"id": "TU4227C224555B5FTD2NT2JV4WN5",
8+
"description": "Top up when balance is low",
9+
"status": "active",
10+
"topUpAmount": {
11+
"fixedAmount": {
12+
"currency": "EUR",
13+
"value": 10000
14+
}
15+
},
16+
"trigger": {
17+
"schedule": "weekly",
18+
"threshold": {
19+
"currency": "EUR",
20+
"value": 5000
21+
}
22+
},
23+
"counterparty": {
24+
"transferInstrumentId": "SE00000000000000000001"
25+
},
26+
"referenceForBeneficiary": "TopUpFromSavings",
27+
"mandate": {
28+
"reference": "MND00000000000000000001",
29+
"creationDate": "2026-04-17T10:30:00+01:00"
30+
}
31+
}
32+
},
33+
"environment": "test",
34+
"timestamp": "2026-04-17T10:30:00+01:00",
35+
"type": "balancePlatform.balanceAccount.recurringTopUp.created"
36+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"data": {
3+
"balancePlatform": "YOUR_BALANCE_PLATFORM",
4+
"creationDate": "2026-04-17T10:30:00+01:00",
5+
"accountId": "BA00000000000000000001",
6+
"webhookTopUpConfiguration": {
7+
"id": "TU4227C224555B5FTD2NT2JV4WN5",
8+
"description": "Top up when balance is low - updated",
9+
"status": "inactive",
10+
"topUpAmount": {
11+
"fixedAmount": {
12+
"currency": "EUR",
13+
"value": 15000
14+
}
15+
},
16+
"trigger": {
17+
"schedule": "monthly",
18+
"threshold": {
19+
"currency": "EUR",
20+
"value": 3000
21+
}
22+
},
23+
"counterparty": {
24+
"transferInstrumentId": "SE00000000000000000001"
25+
},
26+
"referenceForBeneficiary": "TopUpFromSavings",
27+
"mandate": {
28+
"reference": "MND00000000000000000001",
29+
"creationDate": "2026-04-17T10:30:00+01:00"
30+
},
31+
"disabledReason": "counterpartyAccountBlocked",
32+
"reasonDetail": "The counterparty account is blocked."
33+
}
34+
},
35+
"environment": "test",
36+
"timestamp": "2026-04-17T14:45:00+01:00",
37+
"type": "balancePlatform.balanceAccount.recurringTopUp.updated"
38+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"data": {
3+
"balancePlatform": "YOUR_BALANCE_PLATFORM",
4+
"paymentInstrument": {
5+
"balanceAccountId": "BA00000000000000000001",
6+
"issuingCountryCode": "NL",
7+
"status": "active",
8+
"type": "bankAccount",
9+
"bankAccount": {
10+
"type": "iban",
11+
"iban": "NL11ADYB00000000"
12+
},
13+
"additionalBankAccountIdentifications": [
14+
{
15+
"type": "iban",
16+
"iban": "NL11ADYB00000000"
17+
}
18+
],
19+
"id": "PI00000000000000000001"
20+
}
21+
},
22+
"environment": "test",
23+
"timestamp": "2026-03-24T09:30:12+01:00",
24+
"type": "balancePlatform.paymentInstrument.created"
25+
}

0 commit comments

Comments
 (0)