use of org.wso2.carbon.apimgt.api.model.Workflow in project carbon-apimgt by wso2.
the class UserSignUpWSWorkflowExecutorTest method testFailureToCompleteUserSignUpWorkflowApprovedByAdmin.
@Test
public void testFailureToCompleteUserSignUpWorkflowApprovedByAdmin() throws Exception {
Map<String, Boolean> roleMap = new HashMap<String, Boolean>();
roleMap.put(signUpRole, false);
UserRegistrationConfigDTO userRegistrationConfigDTO = new UserRegistrationConfigDTO();
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);
// Set workflow status to be approved
workflowDTO.setStatus(WorkflowStatus.APPROVED);
workflowDTO.setTenantDomain(tenantDomain);
// Set tenant admin credentials
userRegistrationConfigDTO.setAdminUserName("admin");
userRegistrationConfigDTO.setAdminPassword("admin");
// Test failure to complete workflow execution, when error has been occurred while updating user with signup roles
Mockito.doThrow(UserStoreException.class).when(userStoreManager).updateRoleListOfUser(Mockito.anyString(), Mockito.any(), new String[] { Mockito.anyString() });
try {
userSignUpWSWorkflowExecutor.complete(workflowDTO);
Assert.fail("Expected WorkflowException has not been thrown when signup user role update failed");
} catch (WorkflowException e) {
Assert.assertEquals(e.getMessage(), "Error while assigning role to user");
}
// 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 {
userSignUpWSWorkflowExecutor.complete(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 {
userSignUpWSWorkflowExecutor.complete(workflowDTO);
Assert.fail("Expected WorkflowException has not been thrown when signup role is not existing");
} catch (WorkflowException e) {
Assert.assertEquals(e.getMessage(), "Error while accessing signup configuration");
}
}
use of org.wso2.carbon.apimgt.api.model.Workflow in project carbon-apimgt by wso2.
the class UserSignUpWSWorkflowExecutorTest method testFailureToCompleteUserSignUpWorkflowRejectedByAdmin.
@Test
public void testFailureToCompleteUserSignUpWorkflowRejectedByAdmin() 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.doNothing().when(apiMgtDAO).updateWorkflowStatus(workflowDTO);
// Set workflow status to be approved
workflowDTO.setStatus(WorkflowStatus.REJECTED);
Mockito.doThrow(UserStoreException.class).when(userStoreManager).deleteUser(Mockito.anyString());
try {
userSignUpWSWorkflowExecutor.complete(workflowDTO);
Assert.fail("Expected WorkflowException has not been thrown when user deletion failed");
} catch (WorkflowException e) {
Assert.assertEquals(e.getMessage(), "Error while deleting the user");
}
}
use of org.wso2.carbon.apimgt.api.model.Workflow in project carbon-apimgt by wso2.
the class UserSignUpWSWorkflowExecutorTest method testCompletingUserSignUpWorkflowRejectedByAdmin.
@Test
public void testCompletingUserSignUpWorkflowRejectedByAdmin() 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.doNothing().when(apiMgtDAO).updateWorkflowStatus(workflowDTO);
// Set workflow status to be approved
workflowDTO.setStatus(WorkflowStatus.REJECTED);
try {
Assert.assertNotNull(userSignUpWSWorkflowExecutor.complete(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException occurred while completing 'REJECTED' user sign up workflow");
}
}
use of org.wso2.carbon.apimgt.api.model.Workflow in project carbon-apimgt by wso2.
the class ApplicationCreationWSWorkflowExecutorTest method testWorkflowExecuteWithoutExecutorParam.
@Test
public void testWorkflowExecuteWithoutExecutorParam() throws Exception {
ApplicationWorkflowDTO workflowDTO = new ApplicationWorkflowDTO();
Application application = new Application("TestAPP", new Subscriber(null));
application.setTier("Gold");
application.setCallbackUrl("www.wso2.com");
application.setDescription("Description");
workflowDTO.setApplication(application);
workflowDTO.setTenantDomain("wso2");
workflowDTO.setUserName("admin");
workflowDTO.setCallbackUrl("http://localhost:8280/workflow-callback");
workflowDTO.setWorkflowReference("1");
workflowDTO.setExternalWorkflowReference(UUID.randomUUID().toString());
PowerMockito.doNothing().when(apiMgtDAO).updateSubscriptionStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.REJECTED);
ServiceReferenceHolderMockCreator serviceRefMock = new ServiceReferenceHolderMockCreator(-1234);
ServiceReferenceHolderMockCreator.initContextService();
PowerMockito.whenNew(ServiceClient.class).withArguments(Mockito.any(ConfigurationContext.class), Mockito.any(AxisService.class)).thenReturn(serviceClient);
applicationCreationWSWorkflowExecutor.setUsername(null);
applicationCreationWSWorkflowExecutor.setPassword(null);
try {
// shouldn't fail. this checks for unsecured enpoint use case
Assert.assertNotNull(applicationCreationWSWorkflowExecutor.execute(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException occurred while executing Application creation ws workflow");
}
// empty values
applicationCreationWSWorkflowExecutor.setUsername("");
applicationCreationWSWorkflowExecutor.setPassword("".toCharArray());
try {
// shouldn't fail. this checks for unsecured enpoint use case
Assert.assertNotNull(applicationCreationWSWorkflowExecutor.execute(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException occurred while executing Application creation ws workflow");
}
// one empty value and other null
applicationCreationWSWorkflowExecutor.setUsername("");
applicationCreationWSWorkflowExecutor.setPassword(null);
try {
// shouldn't fail. this checks for unsecured enpoint use case
Assert.assertNotNull(applicationCreationWSWorkflowExecutor.execute(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException occurred while executing Application creation ws workflow");
}
applicationCreationWSWorkflowExecutor.setUsername(null);
applicationCreationWSWorkflowExecutor.setPassword("".toCharArray());
try {
// shouldn't fail. this checks for unsecured enpoint use case
Assert.assertNotNull(applicationCreationWSWorkflowExecutor.execute(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException occurred while executing Application creation ws workflow");
}
// without a password
applicationCreationWSWorkflowExecutor.setUsername("admin");
applicationCreationWSWorkflowExecutor.setPassword("".toCharArray());
try {
// shouldn't fail. this checks for unsecured enpoint use case.
Assert.assertNotNull(applicationCreationWSWorkflowExecutor.execute(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException occurred while executing Application creation ws workflow");
}
applicationCreationWSWorkflowExecutor.setUsername("admin");
applicationCreationWSWorkflowExecutor.setPassword(null);
try {
// shouldn't fail. this checks for unsecured enpoint use case.
Assert.assertNotNull(applicationCreationWSWorkflowExecutor.execute(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException occurred while executing Application creation ws workflow");
}
}
use of org.wso2.carbon.apimgt.api.model.Workflow in project carbon-apimgt by wso2.
the class SubscriptionCreationWSWorkflowExecutorTest method testWorkflowExecute.
@Test
public void testWorkflowExecute() throws Exception {
SubscriptionWorkflowDTO workflowDTO = new SubscriptionWorkflowDTO();
workflowDTO.setApiContext("/test");
workflowDTO.setApiName("TestAPI");
workflowDTO.setApiVersion("1.0");
workflowDTO.setApiProvider("admin");
workflowDTO.setSubscriber("admin");
workflowDTO.setApplicationName("TestApp");
workflowDTO.setTierName("Gold");
workflowDTO.setWorkflowReference("1");
workflowDTO.setExternalWorkflowReference(UUID.randomUUID().toString());
PowerMockito.doNothing().when(apiMgtDAO).updateSubscriptionStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.REJECTED);
ServiceReferenceHolderMockCreator serviceRefMock = new ServiceReferenceHolderMockCreator(-1234);
ServiceReferenceHolderMockCreator.initContextService();
PowerMockito.whenNew(ServiceClient.class).withArguments(Mockito.any(ConfigurationContext.class), Mockito.any(AxisService.class)).thenReturn(serviceClient);
try {
Assert.assertNotNull(subscriptionCreationWSWorkflowExecutor.execute(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException occurred while executing Subscription creation ws workflow");
}
}
Aggregations