Search in sources :

Example 1 with ApiPurge

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

the class ApiPurgeTest method testOrganizationRemoval.

@Test
public void testOrganizationRemoval() throws APIManagementException, APIPersistenceException {
    PowerMockito.mockStatic(OrganizationPurgeDAO.class);
    PowerMockito.when(OrganizationPurgeDAO.getInstance()).thenReturn(organizationPurgeDAO);
    PowerMockito.mockStatic(GatewayArtifactsMgtDAO.class);
    PowerMockito.when(GatewayArtifactsMgtDAO.getInstance()).thenReturn(gatewayArtifactsMgtDAO);
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
    Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
    APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
    Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
    PowerMockito.mockStatic(APIUtil.class);
    Mockito.when(APIUtil.isAllowDisplayAPIsWithMultipleStatus()).thenReturn(true);
    APIIdentifier api = Mockito.mock(APIIdentifier.class);
    ArrayList<APIIdentifier> apiIdentifierList = new ArrayList<>();
    apiIdentifierList.add(api);
    Mockito.doReturn(apiIdentifierList).when(organizationPurgeDAO).getAPIIdList("testOrg");
    Mockito.doNothing().when(organizationPurgeDAO).deleteOrganizationAPIList(Mockito.any());
    Mockito.doNothing().when(gatewayArtifactsMgtDAO).removeOrganizationGatewayArtifacts(Mockito.any());
    Mockito.doNothing().when(apiPersistenceInstance).deleteAllAPIs(any(Organization.class));
    Mockito.doReturn(true).when(organizationPurgeDAO).apiOrganizationExist(Mockito.anyString());
    ApiPurge apiPurge = new ApiPurgeWrapper(apiPersistenceInstance);
    LinkedHashMap<String, String> subtaskResult = apiPurge.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)).getAPIIdList("testOrg");
    Mockito.verify(organizationPurgeDAO, Mockito.times(1)).deleteOrganizationAPIList(Mockito.any());
    Mockito.verify(gatewayArtifactsMgtDAO, Mockito.times(1)).removeOrganizationGatewayArtifacts(Mockito.any());
}
Also used : ApiPurge(org.wso2.carbon.apimgt.cleanup.service.ApiPurge) ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) APIManagerConfigurationService(org.wso2.carbon.apimgt.impl.APIManagerConfigurationService) ArrayList(java.util.ArrayList) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) 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 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)1 ApiPurge (org.wso2.carbon.apimgt.cleanup.service.ApiPurge)1 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)1 APIManagerConfigurationService (org.wso2.carbon.apimgt.impl.APIManagerConfigurationService)1 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)1 Organization (org.wso2.carbon.apimgt.persistence.dto.Organization)1