use of org.wso2.carbon.apimgt.api.model.Workflow in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testResumeWorkflow.
@Test
public void testResumeWorkflow() throws Exception {
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper();
apiConsumer.apiMgtDAO = apiMgtDAO;
WorkflowDTO workflowDTO = new WorkflowDTO();
workflowDTO.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
when(apiMgtDAO.retrieveWorkflow(Mockito.anyString())).thenReturn(workflowDTO);
// Null input case
assertNotNull(apiConsumer.resumeWorkflow(null));
String[] args = { UUID.randomUUID().toString(), WorkflowStatus.CREATED.toString(), UUID.randomUUID().toString() };
assertNotNull(apiConsumer.resumeWorkflow(args));
Mockito.reset(apiMgtDAO);
workflowDTO.setTenantDomain("wso2.com");
when(apiMgtDAO.retrieveWorkflow(Mockito.anyString())).thenReturn(workflowDTO);
JSONObject row = apiConsumer.resumeWorkflow(args);
assertNotNull(row);
Mockito.reset(apiMgtDAO);
when(apiMgtDAO.retrieveWorkflow(Mockito.anyString())).thenThrow(APIManagementException.class);
when(APIUtil.isStringArray(args)).thenReturn(true);
row = apiConsumer.resumeWorkflow(args);
assertEquals("Error while resuming the workflow. null", row.get("message"));
// Workflow DAO null case
Mockito.reset(apiMgtDAO);
when(apiMgtDAO.retrieveWorkflow(Mockito.anyString())).thenReturn(null);
row = apiConsumer.resumeWorkflow(args);
assertNotNull(row);
assertEquals(true, row.get("error"));
assertEquals(500, row.get("statusCode"));
// Invalid status test
args[1] = "Invalid status";
Mockito.reset(apiMgtDAO);
when(apiMgtDAO.retrieveWorkflow(Mockito.anyString())).thenReturn(workflowDTO);
row = apiConsumer.resumeWorkflow(args);
assertEquals("Illegal argument provided. Valid values for status are APPROVED and REJECTED.", row.get("message"));
}
use of org.wso2.carbon.apimgt.api.model.Workflow in project carbon-apimgt by wso2.
the class UserPostSelfRegistrationHandler method executeUserRegistrationWorkflow.
/**
* This method adds new role to the existing user roles
* @param tenantDomain tenant domain extracted from the event
* @param userName username extracted from the event
* @throws org.wso2.carbon.identity.recovery.IdentityRecoveryServerException when unable to retrieve
* userStoreManager instance
*/
private void executeUserRegistrationWorkflow(String tenantDomain, String userName) throws org.wso2.carbon.identity.recovery.IdentityRecoveryServerException {
try {
// Realm service is used for user management tasks
RealmService realmService = ServiceReferenceHolder.getInstance().getRealmService();
UserStoreManager userStoreManager;
try {
userStoreManager = realmService.getTenantUserRealm(IdentityTenantUtil.getTenantId(tenantDomain)).getUserStoreManager();
} catch (UserStoreException e) {
throw Utils.handleServerException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED, userName, e);
}
// Start a tenant flow
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
carbonContext.setTenantId(IdentityTenantUtil.getTenantId(tenantDomain));
carbonContext.setTenantDomain(tenantDomain);
if (userStoreManager.isExistingUser(userName)) {
List<String> roleList = asList(userStoreManager.getRoleListOfUser(userName));
// User should have selfSignup role. Checking whether the user is in the new role
if (roleList.contains(SELF_SIGNUP_ROLE) && !roleList.contains(SUBSCRIBER_ROLE)) {
WorkflowExecutor userSignUpWFExecutor = WorkflowExecutorFactory.getInstance().getWorkflowExecutor(WorkflowConstants.WF_TYPE_AM_USER_SIGNUP);
// initiate a new signup workflow
WorkflowDTO signUpWFDto = new WorkflowDTO();
signUpWFDto.setWorkflowReference(userName);
signUpWFDto.setStatus(WorkflowStatus.CREATED);
signUpWFDto.setCreatedTime(System.currentTimeMillis());
signUpWFDto.setTenantDomain(tenantDomain);
signUpWFDto.setTenantId(IdentityTenantUtil.getTenantId(tenantDomain));
signUpWFDto.setExternalWorkflowReference(userSignUpWFExecutor.generateUUID());
signUpWFDto.setWorkflowType(WorkflowConstants.WF_TYPE_AM_USER_SIGNUP);
signUpWFDto.setCallbackUrl(userSignUpWFExecutor.getCallbackURL());
userSignUpWFExecutor.execute(signUpWFDto);
}
}
} catch (UserStoreException | WorkflowException e) {
throw Utils.handleServerException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED, userName, e);
} finally {
Utils.clearArbitraryProperties();
PrivilegedCarbonContext.endTenantFlow();
}
}
use of org.wso2.carbon.apimgt.api.model.Workflow 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"));
}
}
use of org.wso2.carbon.apimgt.api.model.Workflow 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()));
}
}
use of org.wso2.carbon.apimgt.api.model.Workflow 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");
}
}
Aggregations