Skip to content

Commit 18403df

Browse files
committed
Add tests
1 parent 082313b commit 18403df

File tree

6 files changed

+270
-0
lines changed

6 files changed

+270
-0
lines changed

src/test/java/com/adyen/BalancePlatformTest.java

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
import static org.mockito.Mockito.verify;
99

1010
import com.adyen.constants.ApiConstants;
11+
import com.adyen.model.RequestOptions;
1112
import com.adyen.model.balanceplatform.*;
1213
import com.adyen.service.balanceplatform.*;
1314
import com.fasterxml.jackson.core.JsonProcessingException;
1415
import java.util.HashMap;
16+
import java.util.List;
1517
import java.util.Map;
1618
import org.junit.Test;
19+
import org.mockito.ArgumentCaptor;
1720

1821
public class BalancePlatformTest extends BaseTest {
1922
@Test
@@ -764,4 +767,207 @@ public void updateAuthorisedCardUsersTest() throws Exception {
764767
ApiConstants.HttpMethod.PATCH,
765768
null);
766769
}
770+
771+
@Test
772+
public void scaAssociationManagementApproveAssociationTest() throws Exception {
773+
Client client = createMockClientFromFile("mocks/balancePlatform/ScaAssociations.json");
774+
ScaAssociationManagementApi service = new ScaAssociationManagementApi(client);
775+
ApproveAssociationResponse response =
776+
service.approveAssociation(
777+
new ApproveAssociationRequest()
778+
.status(AssociationStatus.ACTIVE)
779+
.entityId("AH00000000000000000000001")
780+
.entityType(ScaEntityType.ACCOUNTHOLDER)
781+
.scaDeviceIds(List.of("BSDR42XV3223223S5N6CDQDGH53M8H")),
782+
new RequestOptions().wwwAuthenticateHeader("abcd-1234-xyzw-5678"));
783+
784+
assertNotNull(response);
785+
assertEquals(1, response.getScaAssociations().size());
786+
787+
ArgumentCaptor<RequestOptions> optionsCaptor = ArgumentCaptor.forClass(RequestOptions.class);
788+
verify(client.getHttpClient())
789+
.request(
790+
eq("https://balanceplatform-api-test.adyen.com/bcl/v2/scaAssociations"),
791+
anyString(),
792+
eq(client.getConfig()),
793+
eq(false),
794+
optionsCaptor.capture(),
795+
eq(ApiConstants.HttpMethod.PATCH),
796+
eq(null));
797+
798+
assertNotNull(optionsCaptor.getValue().getWwwAuthenticateHeader());
799+
assertEquals("abcd-1234-xyzw-5678", optionsCaptor.getValue().getWwwAuthenticateHeader());
800+
}
801+
802+
@Test
803+
public void scaAssociationManagementRemoveAssociationTest() throws Exception {
804+
Client client = createMockClientFromResponse("");
805+
ScaAssociationManagementApi service = new ScaAssociationManagementApi(client);
806+
RemoveAssociationRequest removeAssociationRequest =
807+
new RemoveAssociationRequest()
808+
.entityId("AH00000000000000000000001")
809+
.entityType(ScaEntityType.ACCOUNTHOLDER)
810+
.scaDeviceIds(List.of("BSDR42XV3223223S5N6CDQDGH53M8H"));
811+
812+
service.removeAssociation(
813+
removeAssociationRequest,
814+
new RequestOptions().wwwAuthenticateHeader("abcd-1234-xyzw-5678"));
815+
816+
ArgumentCaptor<String> requestBodyCaptor = ArgumentCaptor.forClass(String.class);
817+
ArgumentCaptor<RequestOptions> optionsCaptor = ArgumentCaptor.forClass(RequestOptions.class);
818+
verify(client.getHttpClient())
819+
.request(
820+
eq("https://balanceplatform-api-test.adyen.com/bcl/v2/scaAssociations"),
821+
requestBodyCaptor.capture(),
822+
eq(client.getConfig()),
823+
eq(false),
824+
optionsCaptor.capture(),
825+
eq(ApiConstants.HttpMethod.DELETE),
826+
eq(null));
827+
828+
assertEquals(removeAssociationRequest.toJson(), requestBodyCaptor.getValue());
829+
assertNotNull(optionsCaptor.getValue().getWwwAuthenticateHeader());
830+
assertEquals("abcd-1234-xyzw-5678", optionsCaptor.getValue().getWwwAuthenticateHeader());
831+
}
832+
833+
@Test
834+
public void scaAssociationManagementListAssociationsTest() throws Exception {
835+
Client client = createMockClientFromFile("mocks/balancePlatform/ScaAssociationsList.json");
836+
ScaAssociationManagementApi service = new ScaAssociationManagementApi(client);
837+
ListAssociationsResponse response =
838+
service.listAssociations(ScaEntityType.ACCOUNTHOLDER, "AH00000000000000000000001", 10, 0);
839+
840+
assertNotNull(response);
841+
assertEquals(2, response.getData().size());
842+
assertEquals("BSDR11111111111A1AAA1AAAAA1AA1", response.getData().get(0).getScaDeviceId());
843+
844+
ArgumentCaptor<Map<String, String>> queryParamsCaptor = ArgumentCaptor.forClass(Map.class);
845+
verify(client.getHttpClient())
846+
.request(
847+
eq("https://balanceplatform-api-test.adyen.com/bcl/v2/scaAssociations"),
848+
eq(null),
849+
eq(client.getConfig()),
850+
eq(false),
851+
eq(null),
852+
eq(ApiConstants.HttpMethod.GET),
853+
queryParamsCaptor.capture());
854+
855+
Map<String, String> queryParams = queryParamsCaptor.getValue();
856+
assertEquals("accountHolder", queryParams.get("entityType"));
857+
assertEquals("AH00000000000000000000001", queryParams.get("entityId"));
858+
assertEquals("10", queryParams.get("pageSize"));
859+
assertEquals("0", queryParams.get("pageNumber"));
860+
}
861+
862+
@Test
863+
public void scaDeviceManagementBeginScaDeviceRegistrationTest() throws Exception {
864+
Client client =
865+
createMockClientFromFile("mocks/balancePlatform/BeginScaDeviceRegistrationResponse.json");
866+
ScaDeviceManagementApi service = new ScaDeviceManagementApi(client);
867+
868+
BeginScaDeviceRegistrationRequest request =
869+
new BeginScaDeviceRegistrationRequest()
870+
.name("My Device")
871+
.sdkOutput(
872+
"eyJjaGFsbGVuZ2UiOiJVWEZaTURONGNXWjZUVFExUlhWV2JuaEJPVzVzTm05cVVEUktUbFZtZGtrPSJ9");
873+
874+
BeginScaDeviceRegistrationResponse response = service.beginScaDeviceRegistration(request);
875+
876+
assertNotNull(response);
877+
assertNotNull(response.getScaDevice());
878+
assertEquals("BSDR42XV3223223S5N6CDQDGH53M8H", response.getScaDevice().getId());
879+
assertEquals("My Device", response.getScaDevice().getName());
880+
assertEquals(ScaDeviceType.IOS, response.getScaDevice().getType());
881+
assertEquals(
882+
"eyJjaGFsbGVuZ2UiOiJVWEZaTURONGNXWjZUVFExUlhWV2JuaEJPVzVzTm05cVVEUktUbFZtZGtrPSJ9",
883+
response.getSdkInput());
884+
885+
ArgumentCaptor<String> requestBodyCaptor = ArgumentCaptor.forClass(String.class);
886+
verify(client.getHttpClient())
887+
.request(
888+
eq("https://balanceplatform-api-test.adyen.com/bcl/v2/scaDevices"),
889+
requestBodyCaptor.capture(),
890+
eq(client.getConfig()),
891+
eq(false),
892+
eq(null),
893+
eq(ApiConstants.HttpMethod.POST),
894+
eq(null));
895+
896+
assertEquals(request.toJson(), requestBodyCaptor.getValue());
897+
}
898+
899+
@Test
900+
public void scaDeviceManagementFinishScaDeviceRegistrationTest() throws Exception {
901+
Client client =
902+
createMockClientFromFile("mocks/balancePlatform/FinishScaDeviceRegistrationResponse.json");
903+
ScaDeviceManagementApi service = new ScaDeviceManagementApi(client);
904+
905+
String deviceId = "BSDR42XV3223223S5N6CDQDGH53M8H";
906+
FinishScaDeviceRegistrationRequest request =
907+
new FinishScaDeviceRegistrationRequest()
908+
.sdkOutput(
909+
"eyJjaGFsbGVuZ2UiOiJVWEZaTURONGNXWjZUVFExUlhWV2JuaEJPVzVzTm05cVVEUktUbFZtZGtrPSJ9");
910+
911+
FinishScaDeviceRegistrationResponse response =
912+
service.finishScaDeviceRegistration(deviceId, request);
913+
914+
assertNotNull(response);
915+
assertNotNull(response.getScaDevice());
916+
assertEquals("BSDR42XV3223223S5N6CDQDGH53M8H", response.getScaDevice().getId());
917+
assertEquals("Device", response.getScaDevice().getName());
918+
assertEquals(ScaDeviceType.IOS, response.getScaDevice().getType());
919+
920+
ArgumentCaptor<String> requestBodyCaptor = ArgumentCaptor.forClass(String.class);
921+
verify(client.getHttpClient())
922+
.request(
923+
eq(
924+
"https://balanceplatform-api-test.adyen.com/bcl/v2/scaDevices/BSDR42XV3223223S5N6CDQDGH53M8H"),
925+
requestBodyCaptor.capture(),
926+
eq(client.getConfig()),
927+
eq(false),
928+
eq(null),
929+
eq(ApiConstants.HttpMethod.PATCH),
930+
eq(null));
931+
932+
assertEquals(request.toJson(), requestBodyCaptor.getValue());
933+
}
934+
935+
@Test
936+
public void scaDeviceManagementSubmitScaAssociationTest() throws Exception {
937+
Client client =
938+
createMockClientFromFile("mocks/balancePlatform/SubmitScaAssociationResponse.json");
939+
ScaDeviceManagementApi service = new ScaDeviceManagementApi(client);
940+
941+
String deviceId = "BSDR11111111111A1AAA1AAAAA1AA1";
942+
SubmitScaAssociationRequest request =
943+
new SubmitScaAssociationRequest()
944+
.addEntitiesItem(
945+
new ScaEntity().type(ScaEntityType.ACCOUNTHOLDER).id("AH00000000000000000000001"));
946+
947+
SubmitScaAssociationResponse response = service.submitScaAssociation(deviceId, request);
948+
949+
assertNotNull(response);
950+
assertNotNull(response.getScaAssociations());
951+
assertEquals(1, response.getScaAssociations().size());
952+
assertEquals(
953+
"BSDR11111111111A1AAA1AAAAA1AA1", response.getScaAssociations().get(0).getScaDeviceId());
954+
assertEquals(ScaEntityType.ACCOUNTHOLDER, response.getScaAssociations().get(0).getEntityType());
955+
assertEquals("AH00000000000000000000001", response.getScaAssociations().get(0).getEntityId());
956+
assertEquals(
957+
AssociationStatus.PENDINGAPPROVAL, response.getScaAssociations().get(0).getStatus());
958+
959+
ArgumentCaptor<String> requestBodyCaptor = ArgumentCaptor.forClass(String.class);
960+
verify(client.getHttpClient())
961+
.request(
962+
eq(
963+
"https://balanceplatform-api-test.adyen.com/bcl/v2/scaDevices/BSDR11111111111A1AAA1AAAAA1AA1/scaAssociations"),
964+
requestBodyCaptor.capture(),
965+
eq(client.getConfig()),
966+
eq(false),
967+
eq(null),
968+
eq(ApiConstants.HttpMethod.POST),
969+
eq(null));
970+
971+
assertEquals(request.toJson(), requestBodyCaptor.getValue());
972+
}
767973
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"scaDevice": {
3+
"id": "BSDR42XV3223223S5N6CDQDGH53M8H",
4+
"name": "My Device",
5+
"type": "ios"
6+
},
7+
"sdkInput": "eyJjaGFsbGVuZ2UiOiJVWEZaTURONGNXWjZUVFExUlhWV2JuaEJPVzVzTm05cVVEUktUbFZtZGtrPSJ9"
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"scaDevice": {
3+
"id": "BSDR42XV3223223S5N6CDQDGH53M8H",
4+
"name": "Device",
5+
"type": "ios"
6+
}
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"scaAssociations": [
3+
{
4+
"scaDeviceId": "BSDR42XV3223223S5N6CDQDGH53M8H",
5+
"entityType": "accountHolder",
6+
"entityId": "AH00000000000000000000001",
7+
"status": "active"
8+
}
9+
]
10+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"_links": {
3+
"self": {
4+
"href": "https://exampledomain.com/bcl/api/v2/scaAssociations?pageNumber=0&entityType=accountHolder&pageSize=10&entityId=AH3227J223222D5HHM4779X6X"
5+
}
6+
},
7+
"itemsTotal": 2,
8+
"pagesTotal": 1,
9+
"data": [
10+
{
11+
"scaDeviceId": "BSDR11111111111A1AAA1AAAAA1AA1",
12+
"scaDeviceName": "Device 1",
13+
"scaDeviceType": "ios",
14+
"entityType": "accountHolder",
15+
"entityId": "AH00000000000000000000001",
16+
"status": "active",
17+
"createdAt": "2025-09-02T14:39:17.232Z"
18+
},
19+
{
20+
"scaDeviceId": "BSDR22222222222B2BBB2BBBBB2BB2",
21+
"scaDeviceName": "Device 2",
22+
"scaDeviceType": "ios",
23+
"entityType": "accountHolder",
24+
"entityId": "AH00000000000000000000001",
25+
"status": "pendingApproval",
26+
"createdAt": "2025-09-02T14:39:17.232Z"
27+
}
28+
]
29+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"scaAssociations": [
3+
{
4+
"scaDeviceId": "BSDR11111111111A1AAA1AAAAA1AA1",
5+
"entityType": "accountHolder",
6+
"entityId": "AH00000000000000000000001",
7+
"status": "pendingApproval"
8+
}
9+
]
10+
}

0 commit comments

Comments
 (0)