Search in sources :

Example 36 with WorkflowException

use of org.wso2.carbon.apimgt.core.exception.WorkflowException 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 37 with WorkflowException

use of org.wso2.carbon.apimgt.core.exception.WorkflowException in project carbon-apimgt by wso2.

the class WorkflowExecutorFactoryTest method testRegistryExceptionWhileInitialisingWorkflowConfigCache.

@Test
public void testRegistryExceptionWhileInitialisingWorkflowConfigCache() throws Exception {
    String errorMessage = "Error occurred while creating workflow configurations for tenant " + tenantDomain;
    Mockito.when(cache.get(Mockito.anyString())).thenReturn(null);
    PowerMockito.whenNew(TenantWorkflowConfigHolder.class).withAnyArguments().thenReturn(tenantWorkflowConfigHolder);
    PowerMockito.doThrow(new RegistryException(errorMessage)).when(tenantWorkflowConfigHolder).load();
    try {
        workflowExecutorFactory.getWorkflowConfigurations();
        Assert.fail("Expected WorkflowException has not occurred while retrieving workflow configuration");
    } catch (WorkflowException e) {
        Assert.assertEquals(e.getMessage(), errorMessage);
    }
}
Also used : RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 38 with WorkflowException

use of org.wso2.carbon.apimgt.core.exception.WorkflowException 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 39 with WorkflowException

use of org.wso2.carbon.apimgt.core.exception.WorkflowException 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)

Example 40 with WorkflowException

use of org.wso2.carbon.apimgt.core.exception.WorkflowException in project carbon-apimgt by wso2.

the class ApplicationRegistrationWSWorkflowExecutorTest method testFailureToCompleteApplicationRegistrationWSWFWhenKeyGenerationFailed.

@Test
public void testFailureToCompleteApplicationRegistrationWSWFWhenKeyGenerationFailed() throws Exception {
    applicationRegistrationWSWorkflowExecutor.setUsername(adminUsername);
    applicationRegistrationWSWorkflowExecutor.setPassword(adminPassword.toCharArray());
    workflowDTO.setStatus(WorkflowStatus.APPROVED);
    PowerMockito.doThrow(new APIManagementException("Error occurred when updating the status of the Application " + "Registration process")).when(keyManager).createApplication((OAuthAppRequest) Mockito.anyObject());
    try {
        applicationRegistrationWSWorkflowExecutor.complete(workflowDTO);
        Assert.fail("Expected WorkflowException has not occurred while completing application registration " + "workflow");
    } catch (WorkflowException e) {
        Assert.assertEquals(e.getMessage(), "Error occurred when updating the status of the Application " + "Registration process");
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)56 Test (org.junit.Test)49 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)49 WorkflowDTO (org.wso2.carbon.apimgt.impl.dto.WorkflowDTO)32 ApplicationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO)25 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)24 SubscriptionWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO)24 Application (org.wso2.carbon.apimgt.api.model.Application)18 WorkflowExecutor (org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutor)17 WorkflowException (org.wso2.carbon.apimgt.impl.workflow.WorkflowException)15 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)13 HashMap (java.util.HashMap)12 JSONObject (org.json.simple.JSONObject)12 ApplicationRegistrationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO)12 ServiceReferenceHolderMockCreator (org.wso2.carbon.apimgt.impl.ServiceReferenceHolderMockCreator)10 XMLStreamException (javax.xml.stream.XMLStreamException)9 UserRegistrationConfigDTO (org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO)9 WorkflowResponse (org.wso2.carbon.apimgt.api.WorkflowResponse)8 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)7 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)6