use of org.wso2.carbon.apimgt.core.workflow.Workflow in project carbon-apimgt by wso2.
the class WorkflowDAOIT method testGetExternalWorkflowReferenceForApplication.
@Test
public void testGetExternalWorkflowReferenceForApplication() throws Exception {
WorkflowDAO workflowDAO = DAOFactory.getWorkflowDAO();
String workflowExtRefId = UUID.randomUUID().toString();
String applicationId = UUID.randomUUID().toString();
Workflow workflow = SampleTestObjectCreator.createWorkflow(workflowExtRefId);
workflow.setWorkflowType(WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION);
workflow.setWorkflowReference(applicationId);
workflow.setStatus(WorkflowStatus.CREATED);
workflowDAO.addWorkflowEntry(workflow);
Optional<String> externalRefFromDb = workflowDAO.getExternalWorkflowReferenceForPendingTask(applicationId, WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION);
if (externalRefFromDb.isPresent()) {
Assert.assertEquals(externalRefFromDb.get(), workflowExtRefId);
} else {
Assert.fail("External workflow reference does not exist");
}
}
use of org.wso2.carbon.apimgt.core.workflow.Workflow in project carbon-apimgt by wso2.
the class WorkflowDAOIT method testAddWorkflowEntryWithoutAttributes.
@Test
public void testAddWorkflowEntryWithoutAttributes() throws Exception {
String workflowRefId = UUID.randomUUID().toString();
WorkflowDAO workflowDAO = DAOFactory.getWorkflowDAO();
Workflow workflow = SampleTestObjectCreator.createWorkflow(workflowRefId);
workflow.setAttributes(null);
workflowDAO.addWorkflowEntry(workflow);
Workflow retrieveWorflow = workflowDAO.retrieveWorkflow(workflow.getExternalWorkflowReference());
Assert.assertEquals(retrieveWorflow.getExternalWorkflowReference(), workflowRefId);
Assert.assertEquals(retrieveWorflow.getStatus(), workflow.getStatus());
Assert.assertEquals(retrieveWorflow.getWorkflowReference(), workflow.getWorkflowReference());
Assert.assertNull(retrieveWorflow.getAttributes());
}
use of org.wso2.carbon.apimgt.core.workflow.Workflow in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testCompleteApplicationWorkflowWithoutReference.
// End of exception testing
@Test(description = "Exception when completing application creation workflow without a reference", expectedExceptions = APIManagementException.class)
public void testCompleteApplicationWorkflowWithoutReference() throws Exception {
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
APIStore apiStore = getApiStoreImpl(applicationDAO, workflowDAO);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
WorkflowExecutor executor = new DefaultWorkflowExecutor();
Workflow workflow = new ApplicationCreationWorkflow(applicationDAO, workflowDAO, apiGateway);
workflow.setWorkflowReference(null);
apiStore.completeWorkflow(executor, workflow);
}
use of org.wso2.carbon.apimgt.core.workflow.Workflow in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddApplicationUpdateWorkflowReject.
@Test(description = "Test Application update workflow reject")
public void testAddApplicationUpdateWorkflowReject() throws APIManagementException {
/*
* This test is to validate the rollback the application to its previous state for application
* update request rejection
*/
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
Policy policy = Mockito.mock(Policy.class);
APIStore apiStore = getApiStoreImpl(applicationDAO, policyDAO, workflowDAO);
Application application = new Application(APP_NAME, USER_NAME);
application.setStatus(ApplicationStatus.APPLICATION_APPROVED);
application.setPolicy(new ApplicationPolicy(TIER));
application.setId(UUID);
application.setPermissionString("[{\"groupId\": \"testGroup\",\"permission\":[\"READ\",\"UPDATE\",\"DELETE\",\"SUBSCRIPTION\"]}]");
Mockito.when(applicationDAO.isApplicationNameExists(APP_NAME)).thenReturn(false);
Mockito.when(policyDAO.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, TIER)).thenReturn(policy);
// following section mock the workflow callback api
DefaultWorkflowExecutor executor = Mockito.mock(DefaultWorkflowExecutor.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
Workflow workflow = new ApplicationUpdateWorkflow(applicationDAO, workflowDAO, apiGateway);
workflow.setWorkflowReference(application.getId());
workflow.setExternalWorkflowReference(UUID);
// validate the rejection flow
// here we assume the application is an approve state before update
// this attribute is set internally based on the workflow data
workflow.setAttribute(WorkflowConstants.ATTRIBUTE_APPLICATION_EXISTIN_APP_STATUS, ApplicationStatus.APPLICATION_APPROVED);
WorkflowResponse response = new GeneralWorkflowResponse();
response.setWorkflowStatus(WorkflowStatus.REJECTED);
Mockito.when(executor.complete(workflow)).thenReturn(response);
apiStore.completeWorkflow(executor, workflow);
Mockito.verify(applicationDAO, Mockito.times(1)).updateApplicationState(application.getId(), ApplicationStatus.APPLICATION_APPROVED);
// here we assume the application is an rejected state before update.
workflow.setAttribute(WorkflowConstants.ATTRIBUTE_APPLICATION_EXISTIN_APP_STATUS, ApplicationStatus.APPLICATION_REJECTED);
apiStore.completeWorkflow(executor, workflow);
Mockito.verify(applicationDAO, Mockito.times(1)).updateApplicationState(application.getId(), ApplicationStatus.APPLICATION_REJECTED);
}
use of org.wso2.carbon.apimgt.core.workflow.Workflow in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddSubscriptionWorkflowReject.
@Test(description = "Test Subscription workflow rejection")
public void testAddSubscriptionWorkflowReject() throws APIManagementException {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
Policy policy = new SubscriptionPolicy(UUID, TIER);
APIStore apiStore = getApiStoreImpl(apiDAO, applicationDAO, apiSubscriptionDAO, workflowDAO, apiGateway, policyDAO);
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, TIER)).thenReturn(policy);
API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI();
apiBuilder.lifeCycleStatus(APIStatus.PUBLISHED.getStatus());
API api = apiBuilder.build();
String apiId = api.getId();
Application application = new Application("TestApp", USER_ID);
application.setId(UUID);
Mockito.when(apiDAO.getAPI(apiId)).thenReturn(api);
Mockito.when(applicationDAO.getApplication(UUID)).thenReturn(application);
SubscriptionResponse response = apiStore.addApiSubscription(apiId, UUID, TIER);
DefaultWorkflowExecutor executor = Mockito.mock(DefaultWorkflowExecutor.class);
Workflow workflow = new SubscriptionCreationWorkflow(apiSubscriptionDAO, workflowDAO, apiGateway);
workflow.setWorkflowType(APIMgtConstants.WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION);
workflow.setWorkflowReference(response.getSubscriptionUUID());
WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
workflowResponse.setWorkflowStatus(WorkflowStatus.REJECTED);
Mockito.when(executor.complete(workflow)).thenReturn(workflowResponse);
apiStore.completeWorkflow(executor, workflow);
Mockito.verify(apiSubscriptionDAO, Mockito.times(1)).updateSubscriptionStatus(response.getSubscriptionUUID(), SubscriptionStatus.REJECTED);
}
Aggregations