Search in sources :

Example 31 with WorkflowDTO

use of org.wso2.carbon.apimgt.impl.dto.WorkflowDTO in project carbon-apimgt by wso2.

the class UserSignUpSimpleWorkflowExecutorTest method init.

@Before
public void init() throws Exception {
    userSignUpSimpleWorkflowExecutor = new UserSignUpSimpleWorkflowExecutor();
    workflowDTO = new WorkflowDTO();
    workflowDTO.setExternalWorkflowReference("12345");
    workflowDTO.setTenantDomain(tenantDomain);
    workflowDTO.setStatus(WorkflowStatus.APPROVED);
    workflowDTO.setWorkflowReference(username);
    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
    RealmService realmService = Mockito.mock(RealmService.class);
    TenantManager tenantManager = Mockito.mock(TenantManager.class);
    UserRealm userRealm = Mockito.mock(UserRealm.class);
    userStoreManager = Mockito.mock(UserStoreManager.class);
    ServiceClient serviceClient = Mockito.mock(ServiceClient.class);
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    PowerMockito.mockStatic(SelfSignUpUtil.class);
    PowerMockito.mockStatic(CarbonUtils.class);
    Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    APIManagerConfigurationService apiManagerConfigurationService = new APIManagerConfigurationServiceImpl(apiManagerConfiguration);
    Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
    Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
    Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
    Mockito.when(tenantManager.getTenantId(tenantDomain)).thenReturn(tenantID);
    Mockito.when(tenantManager.getTenantId(tenantDomain)).thenReturn(tenantID);
    Mockito.when(realmService.getTenantUserRealm(tenantID)).thenReturn(userRealm);
    Mockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) UserRealm(org.wso2.carbon.user.core.UserRealm) APIManagerConfigurationService(org.wso2.carbon.apimgt.impl.APIManagerConfigurationService) APIManagerConfigurationServiceImpl(org.wso2.carbon.apimgt.impl.APIManagerConfigurationServiceImpl) RealmService(org.wso2.carbon.user.core.service.RealmService) ServiceClient(org.apache.axis2.client.ServiceClient) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) TenantManager(org.wso2.carbon.user.core.tenant.TenantManager) Before(org.junit.Before)

Example 32 with WorkflowDTO

use of org.wso2.carbon.apimgt.impl.dto.WorkflowDTO in project carbon-apimgt by wso2.

the class UserSignUpSimpleWorkflowExecutorTest method testFailuresToCompleteUserSignUpSimpleWorkflow.

@Test
public void testFailuresToCompleteUserSignUpSimpleWorkflow() throws Exception {
    Map<String, Boolean> roleMap = new HashMap<String, Boolean>();
    roleMap.put(signUpRole, false);
    UserRegistrationConfigDTO userRegistrationConfigDTO = new UserRegistrationConfigDTO();
    userRegistrationConfigDTO.setRoles(roleMap);
    workflowDTO.setTenantDomain(tenantDomain);
    PowerMockito.when(SelfSignUpUtil.class, "getSignupConfiguration", tenantDomain).thenReturn(userRegistrationConfigDTO);
    PowerMockito.when(SelfSignUpUtil.class, "getRoleNames", userRegistrationConfigDTO).thenReturn(Collections.singletonList("Internal/" + signUpRole));
    Mockito.when(userStoreManager.isExistingUser(username)).thenReturn(true);
    // Test failure to complete workflow execution, when sign up roles are not existing in user realm
    Mockito.when(userStoreManager.isExistingRole("Internal/" + signUpRole)).thenReturn(false);
    try {
        userSignUpSimpleWorkflowExecutor.execute(workflowDTO);
        Assert.fail("Expected WorkflowException has not been thrown when signup role is not existing");
    } catch (WorkflowException e) {
        Assert.assertEquals(e.getMessage(), "Error while assigning role to user");
    }
    // Test failure to complete workflow execution, when error has been occurred while retrieving signup config
    PowerMockito.when(SelfSignUpUtil.getSignupConfiguration(tenantDomain)).thenThrow(new APIManagementException("Error occurred while retrieving signup configuration"));
    try {
        userSignUpSimpleWorkflowExecutor.execute(workflowDTO);
        Assert.fail("Expected WorkflowException has not been thrown retrieving sign up configuration");
    } catch (WorkflowException e) {
        Assert.assertEquals(e.getMessage(), "Error while accessing signup configuration");
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) HashMap(java.util.HashMap) UserRegistrationConfigDTO(org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO) SelfSignUpUtil(org.wso2.carbon.apimgt.impl.utils.SelfSignUpUtil) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 33 with WorkflowDTO

use of org.wso2.carbon.apimgt.impl.dto.WorkflowDTO in project carbon-apimgt by wso2.

the class ApplicationCreationSimpleWorkflowExecutorTest method init.

@Before
public void init() {
    applicationCreationSimpleWorkflowExecutor = new ApplicationCreationSimpleWorkflowExecutor();
    PowerMockito.mockStatic(ApiMgtDAO.class);
    apiMgtDAO = Mockito.mock(ApiMgtDAO.class);
    PowerMockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO);
    workflowDTO = new ApplicationWorkflowDTO();
    workflowDTO.setWorkflowReference("1");
}
Also used : ApplicationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) Before(org.junit.Before)

Example 34 with WorkflowDTO

use of org.wso2.carbon.apimgt.impl.dto.WorkflowDTO in project carbon-apimgt by wso2.

the class ApplicationCreationSimpleWorkflowExecutorTest method testFailureWhileExecutingApplicationDeletionWorkFlow.

@Test
public void testFailureWhileExecutingApplicationDeletionWorkFlow() throws APIManagementException {
    PowerMockito.doThrow(new APIManagementException("Error occurred while updating application status")).when(apiMgtDAO).updateApplicationStatus(Mockito.anyInt(), Mockito.anyString());
    try {
        // Test workflow execution when workflow status = 'CREATED'
        workflowDTO.setStatus(WorkflowStatus.CREATED);
        applicationCreationSimpleWorkflowExecutor.execute(workflowDTO);
        Assert.fail("Expected WorkflowException is not thrown while executing application deletion workflow");
    } catch (WorkflowException e) {
        Assert.assertTrue(e.getMessage().contains("Error occured when updating the status of the Application " + "creation process"));
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 35 with WorkflowDTO

use of org.wso2.carbon.apimgt.impl.dto.WorkflowDTO in project carbon-apimgt by wso2.

the class ApplicationDeletionSimpleWorkflowExecutorTest method testFailureWhileExecutingApplicationDeletionWorkFlow.

@Test
public void testFailureWhileExecutingApplicationDeletionWorkFlow() throws APIManagementException {
    // Test throwing WorkflowException with an error message
    Mockito.doThrow(new APIManagementException("Could not complete application deletion workflow")).when(apiMgtDAO).deleteApplication(application);
    try {
        applicationDeletionSimpleWorkflowExecutor.execute(workflowDTO);
        Assert.fail("Expected WorkflowException is not thrown when application deletion simple workflow" + " execution failed");
    } catch (WorkflowException e) {
        Assert.assertTrue(e.getMessage().contains("Could not complete application deletion workflow"));
    }
    // Test throwing WorkflowException without an empty error message
    Mockito.doThrow(APIManagementException.class).when(apiMgtDAO).deleteApplication(application);
    try {
        applicationDeletionSimpleWorkflowExecutor.execute(workflowDTO);
        Assert.fail("Expected WorkflowException is not thrown when application deletion simple workflow" + " execution failed");
    } catch (WorkflowException e) {
        Assert.assertTrue(e.getMessage().contains("Couldn't complete simple application deletion workflow for " + "application: " + application.getName()));
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Test (org.junit.Test)51 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)51 WorkflowDTO (org.wso2.carbon.apimgt.impl.dto.WorkflowDTO)49 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)46 ApplicationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO)33 SubscriptionWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO)31 Application (org.wso2.carbon.apimgt.api.model.Application)25 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)22 ApplicationRegistrationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO)19 ServiceReferenceHolderMockCreator (org.wso2.carbon.apimgt.impl.ServiceReferenceHolderMockCreator)17 WorkflowExecutor (org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutor)14 Subscriber (org.wso2.carbon.apimgt.api.model.Subscriber)11 XMLStreamException (javax.xml.stream.XMLStreamException)10 JSONObject (org.json.simple.JSONObject)10 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)10 WorkflowException (org.wso2.carbon.apimgt.impl.workflow.WorkflowException)10 HashMap (java.util.HashMap)9 UserRegistrationConfigDTO (org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO)9 ServiceClient (org.apache.axis2.client.ServiceClient)7 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)7