Search in sources :

Example 1 with WorkflowContext

use of org.onap.so.bpmn.common.workflow.context.WorkflowContext in project so by onap.

the class WorkflowContextHolderTest method testProcessCallback.

@Test
public void testProcessCallback() throws Exception {
    String requestId = UUID.randomUUID().toString();
    String message = "TEST MESSATGE";
    String responseMessage = "Successfully processed request";
    int testCode = 200;
    WorkflowContextHolder contextHolder = WorkflowContextHolder.getInstance();
    WorkflowCallbackResponse callbackResponse = new WorkflowCallbackResponse();
    callbackResponse.setMessage(message);
    callbackResponse.setResponse(responseMessage);
    callbackResponse.setStatusCode(testCode);
    contextHolder.processCallback("testAsyncProcess", "process-instance-id", requestId, callbackResponse);
    // same object returned
    WorkflowContext contextFound = contextHolder.getWorkflowContext(requestId);
    if (contextFound == null)
        throw new Exception("Expected to find Context Object");
    WorkflowResponse testResponse = contextFound.getWorkflowResponse();
    Assert.assertEquals(200, testResponse.getMessageCode());
    Assert.assertEquals(message, testResponse.getMessage());
    Assert.assertEquals(responseMessage, testResponse.getResponse());
}
Also used : WorkflowContextHolder(org.onap.so.bpmn.common.workflow.context.WorkflowContextHolder) WorkflowContext(org.onap.so.bpmn.common.workflow.context.WorkflowContext) WorkflowCallbackResponse(org.onap.so.bpmn.common.workflow.context.WorkflowCallbackResponse) WorkflowResponse(org.onap.so.bpmn.common.workflow.context.WorkflowResponse) Test(org.junit.Test)

Example 2 with WorkflowContext

use of org.onap.so.bpmn.common.workflow.context.WorkflowContext in project so by onap.

the class WorkflowAsyncResource method waitForResponse.

protected WorkflowResponse waitForResponse(Map<String, Object> inputVariables) throws Exception {
    String requestId = getRequestId(inputVariables);
    long currentWaitTime = 0;
    long waitTime = getWaitTime();
    logger.debug("WorkflowAsyncResource.waitForResponse using timeout: " + waitTime);
    while (waitTime > currentWaitTime) {
        Thread.sleep(workflowPollInterval);
        currentWaitTime = currentWaitTime + workflowPollInterval;
        WorkflowContext foundContext = contextHolder.getWorkflowContext(requestId);
        if (foundContext != null) {
            contextHolder.remove(foundContext);
            return buildResponse(foundContext);
        }
    }
    throw new Exception("TimeOutOccured in WorkflowAsyncResource.waitForResponse for time " + waitTime + "ms");
}
Also used : WorkflowContext(org.onap.so.bpmn.common.workflow.context.WorkflowContext) WorkflowProcessorException(org.openecomp.mso.bpmn.common.workflow.service.WorkflowProcessorException)

Aggregations

WorkflowContext (org.onap.so.bpmn.common.workflow.context.WorkflowContext)2 Test (org.junit.Test)1 WorkflowCallbackResponse (org.onap.so.bpmn.common.workflow.context.WorkflowCallbackResponse)1 WorkflowContextHolder (org.onap.so.bpmn.common.workflow.context.WorkflowContextHolder)1 WorkflowResponse (org.onap.so.bpmn.common.workflow.context.WorkflowResponse)1 WorkflowProcessorException (org.openecomp.mso.bpmn.common.workflow.service.WorkflowProcessorException)1