/*
The following method call (populateDGContext) populates DG context with the
request parameters to maintain backward compatibility with old DGs,
- we are not altering the old way of passing (org.onap.appc.vnfId and so on..)
+ we are not altering the old way of passing (org.onap.appc.vnfId and so on..)
This is still a temporary solution, the end solution should be agreed with
all stakeholders and implemented.
- */
- populateDGContext(workflowParams,workflowRequest);
+ */
+ populateDGContext(workflowParams, workflowRequest);
} else {
actionProperty = configuration.getProperty("org.onap.appc.workflow.action", String.valueOf(Constants.ACTION));
requestIdProperty = configuration.getProperty("org.onap.appc.workflow.request.id", String.valueOf(Constants.REQUEST_ID));
vfIdProperty = configuration.getProperty("org.onap.appc.workflow.vfid", String.valueOf(Constants.VF_ID));
String vfTypeProperty = configuration.getProperty("org.onap.appc.workflow.vftype", String.valueOf(Constants.VF_TYPE));
String apiVerProperty = configuration.getProperty("org.onap.appc.workflow.apiVersion", String.valueOf(Constants.API_VERSION));
- String originatorIdProperty = configuration.getProperty("org.onap.appc.workflow.originatorId", Constants.ORIGINATOR_ID);
+ String originatorIdProperty = configuration.getProperty("org.onap.appc.workflow.originatorId", Constants.ORIGINATOR_ID);
String subRequestId = configuration.getProperty("org.onap.appc.workflow.subRequestId", Constants.SUB_REQUEST_ID);
workflowParams.put(actionProperty, workflowRequest.getRequestContext().getAction().name());
workflowParams.put("input.action-identifiers.vf-module-id",workflowRequest.getRequestContext().getActionIdentifiers().getVfModuleId() !=null ?
workflowRequest.getRequestContext().getActionIdentifiers().getVfModuleId() : "");
final Map<String, String> additionalContext;
- if ((additionalContext = workflowRequest.getRequestContext().getAdditionalContext())!=null) {
+ if ((additionalContext = workflowRequest.getRequestContext().getAdditionalContext()) != null) {
for (Map.Entry<String, String> entry : additionalContext.entrySet()) {
workflowParams.put("input." + entry.getKey(), null != entry.getValue() ? entry.getValue() : "");
}
setWorkFlowResponseStatus(workflowResponse.getResponseContext(), "failure", "Unexpected SLI Adapter failure", 200);
if (logger.isDebugEnabled()) {
logger.debug("Error while executing DG " + e.getMessage() + e.getStackTrace());
- logger.error("Error in DG", e.getMessage()+ Arrays.toString(e.getStackTrace()),e);
+ logger.error("Error in DG", e.getMessage() + Arrays.toString(e.getStackTrace()), e);
}
}
import org.onap.appc.domainmodel.lcm.Status;
import org.onap.appc.domainmodel.lcm.VNFContext;
import org.onap.appc.domainmodel.lcm.VNFOperation;
+import org.onap.appc.util.ObjectMapper;
import org.onap.appc.workflow.impl.WorkFlowManagerImpl;
import org.onap.appc.workflow.impl.WorkflowKey;
import org.onap.appc.workflow.impl.WorkflowResolver;
import static org.mockito.Matchers.anyString;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({ConfigurationFactory.class, DBUtils.class})
+@PrepareForTest({ConfigurationFactory.class, DBUtils.class, ObjectMapper.class})
public class TestWorkFlowManager {
@Rule
Assert.assertTrue(response.getResponseContext().getStatus().getMessage().equals("success"));
}
+ @Test
+ public void testExecuteWorkFlowException() throws SvcLogicException{
+ Mockito.when(workflowResolver.resolve(anyString(), anyString(), anyString(), anyString())).thenReturn(getWorkFlowKey());
+ Mockito.when(svcLogicService.execute(anyString(), anyString(), anyString(), anyString(), anyObject()))
+ .thenReturn(createSvcExexuteSuccessResponse());
+
+ WorkflowRequest workflowRequest = Mockito.spy(getWorkflowRequest("vSCP", 300, new Date(), "2.00", "ST_249", "O1652", "uid34",
+ VNFOperation.Lock, "mj13", Constants.PAYLOAD));
+ Mockito.when(workflowRequest.getRequestContext()).thenThrow(new RuntimeException());
+
+ WorkflowResponse response = workflowManger.executeWorkflow(workflowRequest);
+ Mockito.verify(workflowRequest, Mockito.times(2)).getResponseContext();
+ }
+
+ @Test
+ public void testExecuteWorkAPIVersion1Exception() throws SvcLogicException{
+ Mockito.when(workflowResolver.resolve(anyString(), anyString(), anyString(), anyString())).thenReturn(getWorkFlowKey());
+ Mockito.when(svcLogicService.execute(anyString(), anyString(), anyString(), anyString(), anyObject()))
+ .thenReturn(createSvcExexuteSuccessResponse());
+
+ WorkflowRequest workflowRequest = getWorkflowRequest("vSCP", 300, new Date(), "1.00", "ST_249", "O1652", "uid34",
+ VNFOperation.Lock, "mj13", Constants.PAYLOAD);
+ PowerMockito.mockStatic(ObjectMapper.class);
+ PowerMockito.when(ObjectMapper.map(Mockito.any())).thenThrow(new RuntimeException());
+ WorkflowResponse response=workflowManger.executeWorkflow(workflowRequest);
+ Assert.assertEquals(501, response.getResponseContext().getStatus().getCode());
+ }
+
@Test
public void testWorkFlowExist() throws SvcLogicException{
Mockito.when(workflowResolver.resolve(anyString(), anyString(), anyString(), anyString())).thenReturn(getWorkFlowKey());
Assert.assertTrue(response.isMappingExist());
}
+ @Test
+ public void testWorkFlowExistNullKey() throws SvcLogicException{
+ Mockito.when(workflowResolver.resolve(anyString(), anyString(), anyString(), anyString())).thenReturn(null);
+ Mockito.when(svcLogicService.hasGraph(anyString(), anyString(), anyString(), anyString())).thenReturn(true);
+ WorkflowRequest workflowRequest = getWorkflowRequest("vSCP", 300, new Date(), "2.00", "ST_249", "O1652", "uid34",
+ VNFOperation.Lock, "mj13", Constants.PAYLOAD);
+ WorkflowExistsOutput response = workflowManger.workflowExists(workflowRequest);
+ Assert.assertFalse(response.isMappingExist());
+ }
+
@Test
public void testWorkflowResolver() throws SQLException {
PowerMockito.mockStatic(DBUtils.class);
workflowResolver.resolve("ACTION", "VNF_TYPE", "VNF_VERSION", "API_VERSION");
}
- private WorkflowRequest getWorkflowRequest(String vnfType, int ttl, Date timeStamp, String apiVersion, String requestId,
+ private WorkflowRequest getWorkflowRequest(String vnfType, int ttl, Date timeStamp, String apiVersion, String requestId,
String originatorID, String subRequestID, VNFOperation action, String vnfId , String payload) {
WorkflowRequest workflowRequest = new WorkflowRequest();
RuntimeContext runtimeContext = createRuntimeContext();
return requestContext;
}
+
private ResponseContext createResponseContext(){
ResponseContext responseContext = new ResponseContext();
CommonHeader commonHeader = new CommonHeader();
return responseContext;
}
+
private RuntimeContext createRuntimeContext(){
RuntimeContext runtimeContext = new RuntimeContext();
RequestContext requestContext = creatRequestContext();