use of org.wso2.carbon.apimgt.rest.api.admin.dto.WorkflowDTO in project carbon-apimgt by wso2.
the class ApplicationRegistrationWSWorkflowExecutorTest method init.
@Before
public void init() throws Exception {
ServiceReferenceHolder serviceReferenceHolder = TestUtils.getServiceReferenceHolder();
ConfigurationContextService configurationContextService = Mockito.mock(ConfigurationContextService.class);
configurationContext = Mockito.mock(ConfigurationContext.class);
PowerMockito.when(serviceReferenceHolder.getContextService()).thenReturn(configurationContextService);
PowerMockito.when(configurationContextService.getClientConfigContext()).thenReturn(configurationContext);
serviceClient = Mockito.mock(ServiceClient.class);
PowerMockito.whenNew(ServiceClient.class).withAnyArguments().thenReturn(serviceClient);
applicationRegistrationWSWorkflowExecutor = new ApplicationRegistrationWSWorkflowExecutor();
apiMgtDAO = TestUtils.getApiMgtDAO();
application = new Application("test", new Subscriber("testUser"));
application.setCallbackUrl(callBaclURL);
application.setTier("Unlimited");
PowerMockito.mockStatic(KeyManagerHolder.class);
keyManager = Mockito.mock(KeyManager.class);
KeyManagerConfiguration keyManagerConfiguration = new KeyManagerConfiguration();
Mockito.when(keyManager.getKeyManagerConfiguration()).thenReturn(keyManagerConfiguration);
PowerMockito.when(KeyManagerHolder.getKeyManagerInstance("carbon.super", "default")).thenReturn(keyManager);
OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo();
PowerMockito.when(keyManager.createApplication((OAuthAppRequest) Mockito.anyObject())).thenReturn(oAuthApplicationInfo);
OAuthAppRequest oAuthAppRequest = new OAuthAppRequest();
oAuthAppRequest.setOAuthApplicationInfo(oAuthApplicationInfo);
workflowDTO = new ApplicationRegistrationWorkflowDTO();
workflowDTO.setWorkflowReference("1");
workflowDTO.setApplication(application);
workflowDTO.setCallbackUrl(callBaclURL);
workflowDTO.setTenantDomain("carbon.super");
workflowDTO.setUserName("testUser");
workflowDTO.setExternalWorkflowReference("testUser");
workflowDTO.setKeyType("PRODUCTION");
workflowDTO.setAppInfoDTO(oAuthAppRequest);
KeyManagerConfigurationDTO kmConfigDTO = new KeyManagerConfigurationDTO();
kmConfigDTO.setOrganization("carbon.super");
kmConfigDTO.setName("default");
PowerMockito.when(apiMgtDAO.getKeyManagerConfigurationByUUID("default")).thenReturn(kmConfigDTO);
}
use of org.wso2.carbon.apimgt.rest.api.admin.dto.WorkflowDTO 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.rest.api.admin.dto.WorkflowDTO 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.rest.api.admin.dto.WorkflowDTO 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.rest.api.admin.dto.WorkflowDTO 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