use of org.wso2.carbon.apimgt.core.exception.WorkflowException in project carbon-apimgt by wso2.
the class UserSignUpWSWorkflowExecutorTest method testCompletingUserSignUpWorkflowApprovedByAdmin.
@Test
public void testCompletingUserSignUpWorkflowApprovedByAdmin() throws Exception {
Map<String, Boolean> roleMap = new HashMap<String, Boolean>();
roleMap.put(signUpRole, false);
UserRegistrationConfigDTO userRegistrationConfigDTO = new UserRegistrationConfigDTO();
userRegistrationConfigDTO.setAdminUserName("admin");
userRegistrationConfigDTO.setAdminPassword("admin");
userRegistrationConfigDTO.setRoles(roleMap);
PowerMockito.when(SelfSignUpUtil.getSignupConfiguration(tenantDomain)).thenReturn(userRegistrationConfigDTO);
PowerMockito.when(SelfSignUpUtil.getRoleNames(userRegistrationConfigDTO)).thenCallRealMethod();
PowerMockito.doNothing().when(apiMgtDAO).updateWorkflowStatus(workflowDTO);
Mockito.when(userStoreManager.isExistingUser(testUsername)).thenReturn(true);
Mockito.when(userStoreManager.isExistingRole("Internal/" + signUpRole)).thenReturn(true);
PowerMockito.doNothing().when(userStoreManager).updateRoleListOfUser(testUsername, null, new String[] { "Internal/" + signUpRole });
// Set workflow status to be approved
workflowDTO.setStatus(WorkflowStatus.APPROVED);
try {
Assert.assertNotNull(userSignUpWSWorkflowExecutor.complete(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException occurred while completing 'APPROVED' user sign up workflow");
}
}
use of org.wso2.carbon.apimgt.core.exception.WorkflowException in project carbon-apimgt by wso2.
the class ApplicationRegistrationWSWorkflowExecutorTest method testFailureToExecuteApplicationRegistrationWSWFWhenPreservingWFEntry.
@Test
public void testFailureToExecuteApplicationRegistrationWSWFWhenPreservingWFEntry() throws Exception {
PowerMockito.doThrow(new APIManagementException("Error while creating Application Registration entry.")).when(apiMgtDAO).createApplicationRegistrationEntry(workflowDTO, false);
try {
applicationRegistrationWSWorkflowExecutor.execute(workflowDTO);
Assert.fail("Expected WorkflowException has not occurred while executing application registration " + "workflow");
} catch (WorkflowException e) {
Assert.assertEquals(e.getMessage(), "Error while creating Application Registration entry.");
}
}
use of org.wso2.carbon.apimgt.core.exception.WorkflowException in project carbon-apimgt by wso2.
the class SubscriptionCreationSimpleWorkflowExecutorTest method testFailureWhileExecutingSubscriptionCreationWorkFlow.
@Test
public void testFailureWhileExecutingSubscriptionCreationWorkFlow() throws APIManagementException {
WorkflowDTO workflowDTO = new WorkflowDTO();
workflowDTO.setWorkflowReference("1");
try {
PowerMockito.doThrow(new APIManagementException("Could not complete subscription creation workflow")).when(apiMgtDAO).updateSubscriptionStatus(1, "UNBLOCKED");
subscriptionCreationSimpleWorkflowExecutor.execute(workflowDTO);
Assert.fail("Expected WorkflowException is not thrown when subscription creation simple workflow" + " execution failed");
} catch (WorkflowException e) {
Assert.assertTrue(e.getMessage().contains("Could not complete subscription creation workflow"));
}
}
use of org.wso2.carbon.apimgt.core.exception.WorkflowException in project carbon-apimgt by wso2.
the class ApplicationCreationWSWorkflowExecutorTest method testWorkflowCompleteExceptionWhenReadingDB.
@Test(expected = WorkflowException.class)
public void testWorkflowCompleteExceptionWhenReadingDB() throws APIManagementException, WorkflowException {
WorkflowDTO workflowDTO = new WorkflowDTO();
workflowDTO.setWorkflowReference("1");
workflowDTO.setExternalWorkflowReference(UUID.randomUUID().toString());
workflowDTO.setStatus(WorkflowStatus.APPROVED);
Application app = Mockito.mock(Application.class);
PowerMockito.doThrow(new APIManagementException("")).when(apiMgtDAO).getApplicationById(Integer.parseInt(workflowDTO.getWorkflowReference()));
PowerMockito.doNothing().when(apiMgtDAO).updateApplicationStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.ApplicationStatus.APPLICATION_APPROVED);
applicationCreationWSWorkflowExecutor.complete(workflowDTO);
}
use of org.wso2.carbon.apimgt.core.exception.WorkflowException in project carbon-apimgt by wso2.
the class ApplicationCreationWSWorkflowExecutorTest method testWorkflowNotAllowedStatus.
@Test
public void testWorkflowNotAllowedStatus() throws APIManagementException, WorkflowException {
WorkflowDTO workflowDTO = new WorkflowDTO();
workflowDTO.setWorkflowReference("1");
workflowDTO.setExternalWorkflowReference(UUID.randomUUID().toString());
workflowDTO.setStatus(WorkflowStatus.REGISTERED);
Application app = Mockito.mock(Application.class);
PowerMockito.doReturn(app).when(apiMgtDAO).getApplicationById(Integer.parseInt(workflowDTO.getWorkflowReference()));
applicationCreationWSWorkflowExecutor.complete(workflowDTO);
// shouldn't update status
Mockito.verify(apiMgtDAO, Mockito.never()).updateApplicationStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.ApplicationStatus.APPLICATION_CREATED);
Mockito.verify(apiMgtDAO, Mockito.never()).updateApplicationStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.ApplicationStatus.APPLICATION_APPROVED);
Mockito.verify(apiMgtDAO, Mockito.never()).updateApplicationStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.ApplicationStatus.APPLICATION_REJECTED);
}
Aggregations