Search in sources :

Example 1 with IdpKeyMangerPurge

use of org.wso2.carbon.apimgt.cleanup.service.IdpKeyMangerPurge in project carbon-apimgt by wso2.

the class IdpKmPurgeTest method testOrganizationRemoval.

@Test
public void testOrganizationRemoval() throws APIManagementException, UserStoreException {
    PowerMockito.mockStatic(APIUtil.class);
    PowerMockito.mockStatic(OrganizationPurgeDAO.class);
    PowerMockito.when(OrganizationPurgeDAO.getInstance()).thenReturn(organizationPurgeDAO);
    PowerMockito.mockStatic(ApiMgtDAO.class);
    PowerMockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO);
    KeyManagerConfigurationDTO kmConfig = Mockito.mock(KeyManagerConfigurationDTO.class);
    List<KeyManagerConfigurationDTO> keyManagerList = new ArrayList<>();
    keyManagerList.add(kmConfig);
    Mockito.doReturn(keyManagerList).when(amAdmin).getKeyManagerConfigurationsByOrganization("testOrg");
    Mockito.doNothing().when(organizationPurgeDAO).deleteKeyManagerConfigurationList(keyManagerList, "testOrg");
    Mockito.doReturn(true).when(organizationPurgeDAO).keyManagerOrganizationExist(Mockito.anyString());
    Mockito.doNothing().when(amAdmin).deleteIdentityProvider("testOrg", kmConfig);
    Mockito.when(APIUtil.isInternalOrganization("testOrg")).thenReturn(true);
    IdpKeyMangerPurge kmPurge = new IdpKeyManagerPurgeWrapper(organizationPurgeDAO);
    LinkedHashMap<String, String> subtaskResult = kmPurge.purge("testOrg");
    for (Map.Entry<String, String> entry : subtaskResult.entrySet()) {
        Assert.assertEquals(entry.getKey() + " is not successful", APIConstants.OrganizationDeletion.COMPLETED, entry.getValue());
    }
    Mockito.verify(organizationPurgeDAO, Mockito.times(1)).deleteKeyManagerConfigurationList(Matchers.anyListOf(KeyManagerConfigurationDTO.class), Mockito.any());
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) IdpKeyMangerPurge(org.wso2.carbon.apimgt.cleanup.service.IdpKeyMangerPurge) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 KeyManagerConfigurationDTO (org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO)1 IdpKeyMangerPurge (org.wso2.carbon.apimgt.cleanup.service.IdpKeyMangerPurge)1