|
47 | 47 | import java.sql.SQLException; |
48 | 48 | import java.util.ArrayList; |
49 | 49 | import java.util.Arrays; |
| 50 | +import java.util.Collections; |
50 | 51 | import java.util.List; |
51 | 52 | import java.util.Map; |
52 | 53 | import java.util.UUID; |
@@ -675,6 +676,44 @@ public void testUpdateAuthorizationUserWithUnmatchedAuthID() throws Exception { |
675 | 676 | } |
676 | 677 | } |
677 | 678 |
|
| 679 | + @Test |
| 680 | + public void testDeleteAuthorizationResource() throws Exception { |
| 681 | + |
| 682 | + ConsentResource storedConsentResource; |
| 683 | + AuthorizationResource storedAuthorizationResource; |
| 684 | + ConsentResource consentResource = ConsentMgtDAOTestData.getSampleTestConsentResource(); |
| 685 | + |
| 686 | + try (Connection connection = DAOUtils.getConnection(DB_NAME)) { |
| 687 | + |
| 688 | + storedConsentResource = consentCoreDAO.storeConsentResource(connection, consentResource); |
| 689 | + Assert.assertNotNull(storedConsentResource.getConsentID()); |
| 690 | + |
| 691 | + AuthorizationResource authorizationResource = new AuthorizationResource(); |
| 692 | + authorizationResource.setConsentID(storedConsentResource.getConsentID()); |
| 693 | + authorizationResource.setAuthorizationType(ConsentMgtDAOTestData.SAMPLE_AUTHORIZATION_TYPE); |
| 694 | + authorizationResource.setUserID(ConsentMgtDAOTestData.SAMPLE_USER_ID); |
| 695 | + authorizationResource.setAuthorizationStatus(ConsentMgtDAOTestData.SAMPLE_AUTHORIZATION_STATUS); |
| 696 | + |
| 697 | + storedAuthorizationResource = consentCoreDAO.storeAuthorizationResource(connection, |
| 698 | + authorizationResource); |
| 699 | + |
| 700 | + Assert.assertNotNull(storedAuthorizationResource.getConsentID()); |
| 701 | + Assert.assertNotNull(storedAuthorizationResource.getAuthorizationID()); |
| 702 | + |
| 703 | + boolean result = consentCoreDAO.deleteAuthorizationResources(connection, |
| 704 | + Collections.singletonList(storedAuthorizationResource.getAuthorizationID())); |
| 705 | + Assert.assertTrue(result); |
| 706 | + } |
| 707 | + } |
| 708 | + |
| 709 | + @Test(expectedExceptions = ConsentDataDeletionException.class) |
| 710 | + public void testDeleteAuthorizationResourceError() throws Exception { |
| 711 | + |
| 712 | + Mockito.doThrow(SQLException.class).when(mockedConnection).prepareStatement(Mockito.anyString()); |
| 713 | + |
| 714 | + consentCoreDAO.deleteAuthorizationResources(mockedConnection, Collections.singletonList("1234")); |
| 715 | + } |
| 716 | + |
678 | 717 | @Test |
679 | 718 | public void testStoreConsentMappingResource() throws Exception { |
680 | 719 |
|
@@ -850,6 +889,57 @@ public void testUpdateConsentMappingStatusSQLError() throws Exception { |
850 | 889 | ConsentMgtDAOTestData.SAMPLE_MAPPING_STATUS); |
851 | 890 | } |
852 | 891 |
|
| 892 | + @Test |
| 893 | + public void testDeleteConsentMappingResource() throws Exception { |
| 894 | + |
| 895 | + ConsentResource storedConsentResource; |
| 896 | + AuthorizationResource storedAuthorizationResource; |
| 897 | + ConsentMappingResource storedConsentMappingResource; |
| 898 | + ConsentResource consentResource = ConsentMgtDAOTestData.getSampleTestConsentResource(); |
| 899 | + |
| 900 | + try (Connection connection = DAOUtils.getConnection(DB_NAME)) { |
| 901 | + |
| 902 | + storedConsentResource = consentCoreDAO.storeConsentResource(connection, consentResource); |
| 903 | + Assert.assertNotNull(storedConsentResource.getConsentID()); |
| 904 | + |
| 905 | + AuthorizationResource authorizationResource = new AuthorizationResource(); |
| 906 | + authorizationResource.setConsentID(storedConsentResource.getConsentID()); |
| 907 | + authorizationResource.setAuthorizationType(ConsentMgtDAOTestData.SAMPLE_AUTHORIZATION_TYPE); |
| 908 | + authorizationResource.setUserID(ConsentMgtDAOTestData.SAMPLE_USER_ID); |
| 909 | + authorizationResource.setAuthorizationStatus(ConsentMgtDAOTestData.SAMPLE_AUTHORIZATION_STATUS); |
| 910 | + |
| 911 | + storedAuthorizationResource = consentCoreDAO.storeAuthorizationResource(connection, |
| 912 | + authorizationResource); |
| 913 | + |
| 914 | + Assert.assertNotNull(storedAuthorizationResource.getConsentID()); |
| 915 | + Assert.assertNotNull(storedAuthorizationResource.getAuthorizationID()); |
| 916 | + |
| 917 | + ConsentMappingResource consentMappingResource = new ConsentMappingResource(); |
| 918 | + consentMappingResource.setAuthorizationID(storedAuthorizationResource.getAuthorizationID()); |
| 919 | + consentMappingResource.setAccountID(ConsentMgtDAOTestData.SAMPLE_ACCOUNT_ID); |
| 920 | + consentMappingResource.setPermission(ConsentMgtDAOTestData.SAMPLE_PERMISSION); |
| 921 | + consentMappingResource.setMappingStatus(ConsentMgtDAOTestData.SAMPLE_MAPPING_STATUS); |
| 922 | + |
| 923 | + storedConsentMappingResource = consentCoreDAO.storeConsentMappingResource(connection, |
| 924 | + consentMappingResource); |
| 925 | + |
| 926 | + Assert.assertNotNull(storedConsentMappingResource.getMappingID()); |
| 927 | + Assert.assertNotNull(storedConsentMappingResource.getAuthorizationID()); |
| 928 | + |
| 929 | + boolean result = consentCoreDAO.deleteConsentMappingResources(connection, |
| 930 | + Collections.singletonList(storedConsentMappingResource.getMappingID())); |
| 931 | + Assert.assertTrue(result); |
| 932 | + } |
| 933 | + } |
| 934 | + |
| 935 | + @Test(expectedExceptions = ConsentDataDeletionException.class) |
| 936 | + public void testDeleteConsentMappingResourceError() throws Exception { |
| 937 | + |
| 938 | + Mockito.doThrow(SQLException.class).when(mockedConnection).prepareStatement(Mockito.anyString()); |
| 939 | + |
| 940 | + consentCoreDAO.deleteConsentMappingResources(mockedConnection, Collections.singletonList("1234")); |
| 941 | + } |
| 942 | + |
853 | 943 | @Test |
854 | 944 | public void testStoreConsentAttributes() throws Exception { |
855 | 945 |
|
|
0 commit comments