use of org.wso2.carbon.apimgt.core.dao.WorkflowDAO in project carbon-apimgt by wso2.
the class DefaultWorkflowExecutorTestCase method testWorkflowResponses.
@Test(description = "Test workflow responses")
public void testWorkflowResponses() throws WorkflowException {
WorkflowExecutor executor = new DefaultWorkflowExecutor();
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
Workflow workflow = new SubscriptionCreationWorkflow(apiSubscriptionDAO, workflowDAO, apiGateway);
WorkflowResponse response = executor.execute(workflow);
Assert.assertEquals(response.getJSONPayload(), "");
Assert.assertEquals(response.getWorkflowStatus(), WorkflowStatus.APPROVED);
workflow.setStatus(WorkflowStatus.APPROVED);
response = executor.complete(workflow);
Assert.assertEquals(response.getWorkflowStatus(), WorkflowStatus.APPROVED);
executor.cleanUpPendingTask(workflow.getExternalWorkflowReference());
}
use of org.wso2.carbon.apimgt.core.dao.WorkflowDAO in project carbon-apimgt by wso2.
the class DAOFactory method getWorkflowDAO.
public static WorkflowDAO getWorkflowDAO() throws APIMgtDAOException {
WorkflowDAO workflowDAO = null;
try (Connection connection = DAOUtil.getConnection()) {
String driverName = connection.getMetaData().getDriverName();
if (driverName.contains(MYSQL) || driverName.contains(H2)) {
workflowDAO = new WorkflowDAOImpl();
} else if (driverName.contains(DB2)) {
} else if (driverName.contains(MS_SQL) || driverName.contains(MICROSOFT)) {
workflowDAO = new WorkflowDAOImpl();
} else if (driverName.contains(POSTGRE)) {
workflowDAO = new WorkflowDAOImpl();
} else if (driverName.contains(ORACLE)) {
workflowDAO = new WorkflowDAOImpl();
} else {
throw new APIMgtDAOException("Unhandled DB driver: " + driverName + " detected", ExceptionCodes.APIM_DAO_EXCEPTION);
}
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting WorkflowDAO", e);
}
setup();
return workflowDAO;
}
use of org.wso2.carbon.apimgt.core.dao.WorkflowDAO in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUpdateAPIStatusException.
@Test(description = "Exception when updating api status", expectedExceptions = APIManagementException.class)
public void testUpdateAPIStatusException() throws APIManagementException, LifecycleException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiLifecycleManager, apiDAO, workflowDAO, gateway);
API api = SampleTestObjectCreator.createDefaultAPI().build();
String uuid = api.getId();
String lcState = api.getLifeCycleStatus();
String lifecycleId = api.getLifecycleInstanceId();
LifecycleState lifecycleState = SampleTestObjectCreator.getMockLifecycleStateObject(lifecycleId);
Mockito.when(apiLifecycleManager.getLifecycleDataForState(lifecycleId, lcState)).thenReturn(lifecycleState);
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
API.APIBuilder apiBuilder = new API.APIBuilder(api);
apiBuilder.lifecycleState(lifecycleState);
apiBuilder.updatedBy(USER);
api = apiBuilder.build();
Mockito.when(apiLifecycleManager.executeLifecycleEvent(APIStatus.CREATED.getStatus(), APIStatus.PUBLISHED.getStatus(), lifecycleId, USER, api)).thenThrow(new LifecycleException("Couldn't change the status of api ID " + uuid));
apiPublisher.updateAPIStatus(uuid, APIStatus.PUBLISHED.getStatus(), new HashMap<>());
}
use of org.wso2.carbon.apimgt.core.dao.WorkflowDAO in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testTemovePendingLifecycleWorkflowTaskForAPIForAPIWithoutPendingLCState.
@Test(description = "Exception when removing api pending lc status change request for an api", expectedExceptions = APIManagementException.class)
public void testTemovePendingLifecycleWorkflowTaskForAPIForAPIWithoutPendingLCState() throws APIManagementException, LifecycleException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiLifecycleManager, apiDAO, workflowDAO, gateway);
APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
builder.workflowStatus(APILCWorkflowStatus.PENDING.toString());
API api = builder.build();
String uuid = api.getId();
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
/*
Mockito.doThrow(new APIMgtDAOException("Error while executing sql query")).when(workflowDAO)
.getExternalWorkflowReferenceForPendingTask(uuid, WorkflowConstants.WF_TYPE_AM_API_STATE);
*/
Mockito.when(workflowDAO.getExternalWorkflowReferenceForPendingTask(uuid, WorkflowConstants.WF_TYPE_AM_API_STATE)).thenThrow(new APIMgtDAOException("Error occurred while changing api lifecycle workflow status"));
apiPublisher.removePendingLifecycleWorkflowTaskForAPI(uuid);
Mockito.verify(workflowDAO, Mockito.times(1)).getExternalWorkflowReferenceForPendingTask(uuid, WorkflowConstants.WF_TYPE_AM_API_STATE);
}
use of org.wso2.carbon.apimgt.core.dao.WorkflowDAO in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUpdateAPIWorkflowStatus.
@Test(description = "Update API Status when its workflow status is pending", expectedExceptions = APIManagementException.class)
public void testUpdateAPIWorkflowStatus() throws APIManagementException, LifecycleException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiLifecycleManager, apiDAO, workflowDAO, gateway);
API api = SampleTestObjectCreator.createDefaultAPI().workflowStatus(APIMgtConstants.APILCWorkflowStatus.PENDING.toString()).build();
String uuid = api.getId();
String lcState = api.getLifeCycleStatus();
String lifecycleId = api.getLifecycleInstanceId();
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
LifecycleState lifecycleState = SampleTestObjectCreator.getMockLifecycleStateObject(lifecycleId);
Mockito.when(apiLifecycleManager.getLifecycleDataForState(lifecycleId, lcState)).thenReturn(lifecycleState);
Mockito.when(apiLifecycleManager.executeLifecycleEvent(APIStatus.CREATED.getStatus(), APIStatus.PUBLISHED.getStatus(), lifecycleId, USER, api)).thenReturn(lifecycleState);
API.APIBuilder apiBuilder = new API.APIBuilder(api);
apiBuilder.lifecycleState(lifecycleState);
apiBuilder.updatedBy(USER);
api = apiBuilder.build();
lifecycleState.setState(APIStatus.PUBLISHED.getStatus());
apiPublisher.updateAPIStatus(uuid, APIStatus.PUBLISHED.getStatus(), new HashMap<>());
Mockito.verify(apiLifecycleManager, Mockito.times(1)).executeLifecycleEvent(APIStatus.CREATED.getStatus(), APIStatus.PUBLISHED.getStatus(), lifecycleId, USER, api);
}
Aggregations