|
8 | 8 | import static org.mockito.Mockito.verify; |
9 | 9 |
|
10 | 10 | import com.adyen.constants.ApiConstants; |
| 11 | +import com.adyen.model.RequestOptions; |
11 | 12 | import com.adyen.model.balanceplatform.*; |
12 | 13 | import com.adyen.service.balanceplatform.*; |
13 | 14 | import com.fasterxml.jackson.core.JsonProcessingException; |
14 | 15 | import java.util.HashMap; |
| 16 | +import java.util.List; |
15 | 17 | import java.util.Map; |
16 | 18 | import org.junit.Test; |
| 19 | +import org.mockito.ArgumentCaptor; |
17 | 20 |
|
18 | 21 | public class BalancePlatformTest extends BaseTest { |
19 | 22 | @Test |
@@ -764,4 +767,207 @@ public void updateAuthorisedCardUsersTest() throws Exception { |
764 | 767 | ApiConstants.HttpMethod.PATCH, |
765 | 768 | null); |
766 | 769 | } |
| 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 | + } |
767 | 973 | } |
0 commit comments