use of org.wso2.carbon.apimgt.api.model.Workflow in project carbon-apimgt by wso2.
the class SubscriptionCreationSimpleWorkflowExecutorTest method testExecutingSubscriptionCreationWorkFlow.
@Test
public void testExecutingSubscriptionCreationWorkFlow() throws APIManagementException {
WorkflowDTO workflowDTO = new WorkflowDTO();
workflowDTO.setWorkflowReference("1");
try {
PowerMockito.doNothing().when(apiMgtDAO).updateSubscriptionStatus(1, "UNBLOCKED");
Assert.assertNotNull(subscriptionCreationSimpleWorkflowExecutor.execute(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException occurred while executing Subscription creation simple workflow");
}
}
use of org.wso2.carbon.apimgt.api.model.Workflow in project carbon-apimgt by wso2.
the class SubscriptionDeletionSimpleWorkflowExecutorTest method testFailureWhileExecutingSubscriptionDeletionWorkFlow.
@Test
public void testFailureWhileExecutingSubscriptionDeletionWorkFlow() throws APIManagementException {
PowerMockito.doThrow(new APIManagementException("Error occurred while removing subscriptions")).when(apiMgtDAO).removeSubscription((APIIdentifier) Mockito.anyObject(), Mockito.anyInt());
try {
subscriptionDeletionSimpleWorkflowExecutor.execute(subscriptionWorkflowDTO);
Assert.fail("Expected WorkflowException is not thrown while executing subscription deletion workflow");
} catch (WorkflowException e) {
Assert.assertTrue(e.getMessage().contains("Could not complete subscription deletion workflow for api: " + subscriptionWorkflowDTO.getApiName()));
}
}
use of org.wso2.carbon.apimgt.api.model.Workflow in project carbon-apimgt by wso2.
the class UserSignUpSimpleWorkflowExecutorTest method testExecutingUserSignUpSimpleWorkflow.
@Test
public void testExecutingUserSignUpSimpleWorkflow() throws APIManagementException, UserStoreException {
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();
Mockito.when(userStoreManager.isExistingUser(username)).thenReturn(true);
Mockito.when(userStoreManager.isExistingRole("Internal/" + signUpRole)).thenReturn(true);
Mockito.doNothing().when(userStoreManager).updateRoleListOfUser(username, null, new String[] { "Internal/" + signUpRole });
try {
Assert.assertNotNull(userSignUpSimpleWorkflowExecutor.execute(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException has thrown while executing the user signup simple workflow");
}
}
use of org.wso2.carbon.apimgt.api.model.Workflow 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");
}
}
use of org.wso2.carbon.apimgt.api.model.Workflow in project carbon-apimgt by wso2.
the class SubscriptionCreationWSWorkflowExecutorTest method testWorkflowExecuteWithoutExecutorParam.
@Test
public void testWorkflowExecuteWithoutExecutorParam() 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());
workflowDTO.setCallbackUrl("http://test");
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);
subscriptionCreationWSWorkflowExecutor.setUsername(null);
subscriptionCreationWSWorkflowExecutor.setPassword(null);
try {
// shouldn't fail. this checks for unsecured enpoint use case
Assert.assertNotNull(subscriptionCreationWSWorkflowExecutor.execute(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException occurred while executing Subscription creation ws workflow");
}
// empty values
subscriptionCreationWSWorkflowExecutor.setUsername("");
subscriptionCreationWSWorkflowExecutor.setPassword("".toCharArray());
try {
// shouldn't fail. this checks for unsecured enpoint use case
Assert.assertNotNull(subscriptionCreationWSWorkflowExecutor.execute(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException occurred while executing Subscription creation ws workflow");
}
// one empty value and other null
subscriptionCreationWSWorkflowExecutor.setUsername("");
subscriptionCreationWSWorkflowExecutor.setPassword(null);
try {
// shouldn't fail. this checks for unsecured enpoint use case
Assert.assertNotNull(subscriptionCreationWSWorkflowExecutor.execute(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException occurred while executing Subscription creation ws workflow");
}
subscriptionCreationWSWorkflowExecutor.setUsername(null);
subscriptionCreationWSWorkflowExecutor.setPassword("".toCharArray());
try {
// shouldn't fail. this checks for unsecured enpoint use case
Assert.assertNotNull(subscriptionCreationWSWorkflowExecutor.execute(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException occurred while executing Subscription creation ws workflow");
}
// without a password
subscriptionCreationWSWorkflowExecutor.setUsername("admin");
subscriptionCreationWSWorkflowExecutor.setPassword("".toCharArray());
try {
// shouldn't fail. this checks for unsecured enpoint use case.
Assert.assertNotNull(subscriptionCreationWSWorkflowExecutor.execute(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException occurred while executing Subscription creation ws workflow");
}
subscriptionCreationWSWorkflowExecutor.setUsername("admin");
subscriptionCreationWSWorkflowExecutor.setPassword(null);
try {
// shouldn't fail. this checks for unsecured enpoint use case.
Assert.assertNotNull(subscriptionCreationWSWorkflowExecutor.execute(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException occurred while executing Subscription creation ws workflow");
}
}
Aggregations