diff --git a/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/IdPManagementFacade.java b/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/IdPManagementFacade.java index 4226c170cb34..8d342de4299d 100644 --- a/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/IdPManagementFacade.java +++ b/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/IdPManagementFacade.java @@ -94,13 +94,6 @@ public int getCountOfFilteredIdPs(int tenantId, List expressionC return dao.getCountOfFilteredIdPs(tenantId, expressionConditions); } - public ProvisioningConnectorConfig[] getProvisioningConnectorConfigs(Connection dbConnection, - String idPName, int idPId, int tenantId) - throws IdentityProviderManagementException, SQLException { - - return dao.getProvisioningConnectorConfigs(dbConnection, idPName, idPId, tenantId); - } - public IdentityProvider getIdPByName(Connection dbConnection, String idPName, int tenantId, String tenantDomain) throws IdentityProviderManagementException { @@ -268,12 +261,6 @@ public void renameTenantRole(String newRoleName, String oldRoleName, int tenantI dao.renameTenantRole(newRoleName, oldRoleName, tenantId, tenantDomain); } - public void renameClaimURI(String newClaimURI, String oldClaimURI, int tenantId, String tenantDomain) - throws IdentityProviderManagementException { - - dao.renameClaimURI(newClaimURI, oldClaimURI, tenantId, tenantDomain); - } - public boolean isIdPAvailableForAuthenticatorProperty(String authenticatorName, String propertyName, String idPEntityId, int tenantId) throws IdentityProviderManagementException { diff --git a/components/idp-mgt/org.wso2.carbon.idp.mgt/src/test/java/org/wso2/carbon/idp/mgt/IdentityProviderManagementServiceTest.java b/components/idp-mgt/org.wso2.carbon.idp.mgt/src/test/java/org/wso2/carbon/idp/mgt/IdentityProviderManagementServiceTest.java index c134528573fd..02954b83ebb6 100644 --- a/components/idp-mgt/org.wso2.carbon.idp.mgt/src/test/java/org/wso2/carbon/idp/mgt/IdentityProviderManagementServiceTest.java +++ b/components/idp-mgt/org.wso2.carbon.idp.mgt/src/test/java/org/wso2/carbon/idp/mgt/IdentityProviderManagementServiceTest.java @@ -693,6 +693,25 @@ public void testForceDeleteIdP(String idpName) throws Exception { Assert.assertNull(identityProviderManagementService.getIdPByName(idpName)); } + @Test(dataProvider = "forceDeleteIdPData") + public void testForceDeleteIdPDAOException(String idpName) throws Exception { + + addTestIdps(); + Assert.assertNotNull(identityProviderManagementService.getIdPByName(idpName)); + + IdPManagementDAO daoForError = mock(IdPManagementDAO.class); + doThrow(IdentityProviderManagementServerException.class).when(daoForError) + .forceDeleteIdPByResourceId(anyString(), anyInt(), anyString()); + daoForException = new CacheBackedIdPMgtDAO(daoForError); + field.set(identityProviderManager, daoForException); + + assertThrows(IdentityProviderManagementException.class, () -> + identityProviderManagementService.forceDeleteIdP(idpName)); + + field.set(identityProviderManager, dao); + Assert.assertNotNull(identityProviderManagementService.getIdPByName(idpName)); + } + @DataProvider public Object[][] forceDeleteIdPExceptionData() { diff --git a/components/idp-mgt/org.wso2.carbon.idp.mgt/src/test/java/org/wso2/carbon/idp/mgt/dao/CacheBackedIdPMgtDAOTest.java b/components/idp-mgt/org.wso2.carbon.idp.mgt/src/test/java/org/wso2/carbon/idp/mgt/dao/CacheBackedIdPMgtDAOTest.java index a5057473fa80..df83077a47d8 100644 --- a/components/idp-mgt/org.wso2.carbon.idp.mgt/src/test/java/org/wso2/carbon/idp/mgt/dao/CacheBackedIdPMgtDAOTest.java +++ b/components/idp-mgt/org.wso2.carbon.idp.mgt/src/test/java/org/wso2/carbon/idp/mgt/dao/CacheBackedIdPMgtDAOTest.java @@ -68,11 +68,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; @@ -80,9 +76,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mockStatic; import static org.mockito.Mockito.when; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertThrows; +import static org.testng.Assert.*; import static org.wso2.carbon.idp.mgt.util.IdPManagementConstants.RESET_PROVISIONING_ENTITIES_ON_CONFIG_UPDATE; /** @@ -469,6 +463,29 @@ public void testGetIdPById(String idpName, int idpId, int tenantId, boolean isEx } } + @Test + public void testGetIdPNamesById() throws Exception { + + try (MockedStatic identityDatabaseUtil = mockStatic(IdentityDatabaseUtil.class); + Connection connection = getConnection(DB_NAME)) { + identityDatabaseUtil.when(() -> IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection); + identityDatabaseUtil.when(IdentityDatabaseUtil::getDataSource).thenReturn(dataSourceMap.get(DB_NAME)); + addTestIdps(); + + Set idpIds = new HashSet<>(Arrays.asList( + cacheBackedIdPMgtDAO.getIdPByName(connection, "testIdP1", SAMPLE_TENANT_ID1, TENANT_DOMAIN) + .getIdentityProviderName(), + cacheBackedIdPMgtDAO.getIdPByName(connection, "testIdP2", SAMPLE_TENANT_ID1, TENANT_DOMAIN) + .getIdentityProviderName() + )); + // Retrieving IDP form DB and adding to cache. + Map idpNameMap = cacheBackedIdPMgtDAO.getIdPNamesById(SAMPLE_TENANT_ID1, idpIds); + + assertTrue(idpNameMap.containsKey("testIdP1")); + assertTrue(idpNameMap.containsKey("testIdP2")); + } + } + @DataProvider public Object[][] getIDPbyResourceIdData() { @@ -558,6 +575,25 @@ public void testGetIdPNameByResourceId(String idpName, int tenantId) throws Exce } } + @Test(dataProvider = "getIDPNameByResourceIdData") + public void testGetIdPNameByResourceIdFromDB(String idpName, int tenantId) throws Exception { + + try (MockedStatic identityDatabaseUtil = mockStatic(IdentityDatabaseUtil.class); + Connection connection = getConnection(DB_NAME)) { + identityDatabaseUtil.when(() -> IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection); + identityDatabaseUtil.when(IdentityDatabaseUtil::getDBConnection).thenReturn(connection); + identityDatabaseUtil.when(IdentityDatabaseUtil::getDataSource).thenReturn(dataSourceMap.get(DB_NAME)); + addTestIdps(); + + // Retrieving IDP from DB. + IdentityProvider idPResult = idPManagementDAO.getIdPByName(connection, idpName, tenantId, TENANT_DOMAIN); + String uuid = idPResult.getResourceId(); + + String nameFromDB = cacheBackedIdPMgtDAO.getIdPNameByResourceId(uuid); + assertEquals(nameFromDB, idpName); + } + } + @DataProvider public Object[][] getIdPByAuthenticatorPropertyValueWithoutAuthenticatorData() { @@ -1113,7 +1149,7 @@ public void testDeleteIdPs(int tenantId) throws Exception { identityDatabaseUtil.when(IdentityDatabaseUtil::getDataSource).thenReturn(dataSourceMap.get(DB_NAME)); addTestIdps(); // Deleting multiple IDPs on a tenant. - idPManagementDAO.deleteIdPs(tenantId); + cacheBackedIdPMgtDAO.deleteIdPs(tenantId); } try (Connection connection = getConnection(DB_NAME)) { @@ -1131,6 +1167,20 @@ public void testDeleteIdPs(int tenantId) throws Exception { } } + @Test + public void testDeleteIdPsDAOException(int tenantId) throws Exception { + + try (MockedStatic identityDatabaseUtil = mockStatic(IdentityDatabaseUtil.class); + Connection connection = getConnection(DB_NAME)) { + identityDatabaseUtil.when(() -> IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection); + identityDatabaseUtil.when(IdentityDatabaseUtil::getDBConnection).thenReturn(connection); + identityDatabaseUtil.when(IdentityDatabaseUtil::getDataSource).thenReturn(dataSourceMap.get(DB_NAME)); + addTestIdps(); + // Deleting multiple IDPs on a tenant. + cacheBackedIdPMgtDAO.deleteIdPs(tenantId); + } + } + @Test(dataProvider = "deleteIdPData") public void testDeleteIdPByResourceId(String idpName, int tenantId) throws Exception { @@ -1173,6 +1223,25 @@ public void testForceDeleteIdPByResourceId(String idpName, int tenantId) throws } } + @Test(dataProvider = "deleteIdPData") + public void testForceDeleteIdP(String idpName, int tenantId) throws Exception { + + try (MockedStatic identityDatabaseUtil = mockStatic(IdentityDatabaseUtil.class); + Connection connection = getConnection(DB_NAME)) { + identityDatabaseUtil.when(() -> IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection); + identityDatabaseUtil.when(IdentityDatabaseUtil::getDBConnection).thenReturn(connection); + identityDatabaseUtil.when(IdentityDatabaseUtil::getDataSource).thenReturn(dataSourceMap.get(DB_NAME)); + addTestIdps(); + + // Force delete IDP using resourceId. + cacheBackedIdPMgtDAO.forceDeleteIdP(idpName, tenantId, TENANT_DOMAIN); + int resultSize = getIdPCount(connection, idpName, tenantId); + assertEquals(resultSize, 0, "'forceDeleteIdPByResourceId' method fails"); + IdentityProvider idpFromCache = idpFromCacheByName(idpName); + assertNull(idpFromCache, "'deleteIdPByResourceId' method fails"); + } + } + @DataProvider public Object[][] addIdPCacheData() {