use of org.wso2.carbon.apimgt.rest.api.admin.dto.WorkflowRequestDTO in project carbon-apimgt by wso2.
the class WorkflowsApiServiceImplTestCase method testWorkflowsWorkflowReferenceIdPutNotExist.
@Test
public void testWorkflowsWorkflowReferenceIdPutNotExist() throws Exception {
printTestMethodName();
WorkflowsApiServiceImpl workflowsApiService = new WorkflowsApiServiceImpl();
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
String workflowRefId = UUID.randomUUID().toString();
WorkflowRequestDTO workflowRequestDTO = new WorkflowRequestDTO();
workflowRequestDTO.setDescription("Test Desc");
workflowRequestDTO.setStatus(WorkflowRequestDTO.StatusEnum.APPROVED);
Mockito.doReturn(null).doThrow(new IllegalArgumentException()).when(adminService).retrieveWorkflow(workflowRefId);
Response response = workflowsApiService.workflowsWorkflowReferenceIdPut(workflowRefId, workflowRequestDTO, getRequest());
assertEquals(404, response.getStatus());
}
use of org.wso2.carbon.apimgt.rest.api.admin.dto.WorkflowRequestDTO in project carbon-apimgt by wso2.
the class WorkflowsApiServiceImplTestCase method testWorkflowsWorkflowReferenceIdPutAlreadyPublished.
@Test
public void testWorkflowsWorkflowReferenceIdPutAlreadyPublished() throws Exception {
printTestMethodName();
WorkflowsApiServiceImpl workflowsApiService = new WorkflowsApiServiceImpl();
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
String workflowRefId = UUID.randomUUID().toString();
WorkflowRequestDTO workflowRequestDTO = new WorkflowRequestDTO();
workflowRequestDTO.setDescription("Test Desc");
workflowRequestDTO.setStatus(WorkflowRequestDTO.StatusEnum.APPROVED);
Workflow workflow = new APIStateChangeWorkflow(null, null, null, null, null, null);
workflow.setStatus(WorkflowStatus.APPROVED);
Mockito.doReturn(workflow).doThrow(new IllegalArgumentException()).when(adminService).retrieveWorkflow(workflowRefId);
Response response = workflowsApiService.workflowsWorkflowReferenceIdPut(workflowRefId, workflowRequestDTO, getRequest());
assertEquals(400, response.getStatus());
}
use of org.wso2.carbon.apimgt.rest.api.admin.dto.WorkflowRequestDTO in project carbon-apimgt by wso2.
the class WorkflowsApiServiceImpl method workflowsWorkflowReferenceIdPut.
@Override
public Response workflowsWorkflowReferenceIdPut(String workflowReferenceId, WorkflowRequestDTO body, Request request) throws NotFoundException {
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
Workflow workflow = apiMgtAdminService.retrieveWorkflow(workflowReferenceId);
if (workflow == null) {
String errorMessage = "Workflow entry not found for: " + workflowReferenceId;
APIMgtResourceNotFoundException e = new APIMgtResourceNotFoundException(errorMessage, ExceptionCodes.WORKFLOW_NOT_FOUND);
Map<String, String> paramList = new HashMap<>();
paramList.put(APIMgtConstants.ExceptionsConstants.WORKFLOW_REF_ID, workflowReferenceId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
} else {
if (WorkflowStatus.APPROVED == workflow.getStatus()) {
String errorMessage = "Workflow is already in complete state";
APIMgtResourceNotFoundException e = new APIMgtResourceNotFoundException(errorMessage, ExceptionCodes.WORKFLOW_ALREADY_COMPLETED);
Map<String, String> paramList = new HashMap<>();
paramList.put(APIMgtConstants.ExceptionsConstants.WORKFLOW_REF_ID, workflowReferenceId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
} else {
WorkflowExecutor workflowExecutor = WorkflowExecutorFactory.getInstance().getWorkflowExecutor(workflow.getWorkflowType());
if (body == null) {
RestApiUtil.handleBadRequest("Request payload is missing", log);
}
if (body.getDescription() != null) {
workflow.setWorkflowDescription(body.getDescription());
}
if (body.getStatus() == null) {
String errorMessage = "Workflow status is not defined";
APIManagementException e = new APIManagementException(errorMessage, ExceptionCodes.WORKFLOW_STATE_MISSING);
Map<String, String> paramList = new HashMap<>();
paramList.put(APIMgtConstants.ExceptionsConstants.WORKFLOW_REF_ID, workflowReferenceId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
} else {
workflow.setStatus(WorkflowStatus.valueOf(body.getStatus().toString()));
}
if (body.getAttributes() != null) {
Map<String, String> existingAttributs = workflow.getAttributes();
Map<String, String> newAttributes = body.getAttributes();
if (existingAttributs == null) {
workflow.setAttributes(newAttributes);
} else {
newAttributes.forEach(existingAttributs::putIfAbsent);
workflow.setAttributes(existingAttributs);
}
}
WorkflowResponse response = apiMgtAdminService.completeWorkflow(workflowExecutor, workflow);
WorkflowResponseDTO workflowResponseDTO = WorkflowMappingUtil.toWorkflowResponseDTO(response);
return Response.ok().entity(workflowResponseDTO).build();
}
}
} catch (APIManagementException e) {
String errorMessage = "Error while completing workflow for reference : " + workflowReferenceId + ". " + e.getMessage();
Map<String, String> paramList = new HashMap<>();
paramList.put(APIMgtConstants.ExceptionsConstants.WORKFLOW_REF_ID, workflowReferenceId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.admin.dto.WorkflowRequestDTO in project carbon-apimgt by wso2.
the class WorkflowsApiServiceImplTestCase method testWorkflowsWorkflowReferenceIdPutException.
@Test
public void testWorkflowsWorkflowReferenceIdPutException() throws Exception {
printTestMethodName();
WorkflowsApiServiceImpl workflowsApiService = new WorkflowsApiServiceImpl();
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
String workflowRefId = UUID.randomUUID().toString();
String message = "Error while retrieving workflow entry for :" + workflowRefId;
Mockito.doThrow(new APIManagementException(message, ExceptionCodes.APIMGT_DAO_EXCEPTION)).when(adminService).retrieveWorkflow(workflowRefId);
WorkflowRequestDTO workflowRequestDTO = new WorkflowRequestDTO();
workflowRequestDTO.setDescription("Test Desc");
workflowRequestDTO.setStatus(WorkflowRequestDTO.StatusEnum.APPROVED);
Response response = workflowsApiService.workflowsWorkflowReferenceIdPut(workflowRefId, workflowRequestDTO, getRequest());
assertEquals(500, response.getStatus());
}
use of org.wso2.carbon.apimgt.rest.api.admin.dto.WorkflowRequestDTO in project carbon-apimgt by wso2.
the class WorkflowsApiServiceImplTestCase method testWorkflowsWorkflowReferenceIdGet.
@Test
public void testWorkflowsWorkflowReferenceIdGet() throws Exception {
printTestMethodName();
WorkflowsApiServiceImpl workflowsApiService = new WorkflowsApiServiceImpl();
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
String workflowRefId = UUID.randomUUID().toString();
WorkflowRequestDTO workflowRequestDTO = new WorkflowRequestDTO();
workflowRequestDTO.setDescription("Test Desc");
workflowRequestDTO.setStatus(WorkflowRequestDTO.StatusEnum.APPROVED);
Workflow workflow = new ApplicationCreationWorkflow(null, null, null);
workflow.setStatus(WorkflowStatus.APPROVED);
LocalDateTime date1 = LocalDateTime.now();
workflow.setCreatedTime(date1);
workflow.setWorkflowDescription("Description 1");
workflow.setWorkflowType(WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION);
String ref1 = UUID.randomUUID().toString();
workflow.setExternalWorkflowReference(ref1);
Mockito.doReturn(workflow).doThrow(new IllegalArgumentException()).when(adminService).retrieveWorkflow(workflowRefId);
Response response = workflowsApiService.workflowsWorkflowReferenceIdGet(workflowRefId, getRequest());
assertEquals(200, response.getStatus());
}
Aggregations