Test coverage in workflow-impl 22/78122/2
authorJoss Armstrong <joss.armstrong@ericsson.com>
Fri, 8 Feb 2019 15:38:18 +0000 (15:38 +0000)
committerTakamune Cho <takamune.cho@att.com>
Fri, 8 Feb 2019 21:23:37 +0000 (21:23 +0000)
Increased package coverage to 83%

Issue-ID: APPC-1408
Change-Id: I24b634ee7926bac2a196256cd20362d2f7b93b76
Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkFlowManagerImpl.java
appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/impl/TestWorkFlowManager.java

index e6edc26..000415c 100644 (file)
@@ -95,18 +95,18 @@ public class WorkFlowManagerImpl implements WorkFlowManager{
                 /*
                 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());
@@ -177,7 +177,7 @@ public class WorkFlowManagerImpl implements WorkFlowManager{
         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() : "");
     }
@@ -245,7 +245,7 @@ public class WorkFlowManagerImpl implements WorkFlowManager{
             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);
             }
         }
 
index eb8a8d4..8689fa7 100644 (file)
@@ -46,6 +46,7 @@ import org.onap.appc.domainmodel.lcm.RuntimeContext;
 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;
@@ -68,7 +69,7 @@ import static org.mockito.Matchers.anyObject;
 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
@@ -138,6 +139,34 @@ public class TestWorkFlowManager {
         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());
@@ -164,6 +193,16 @@ public class TestWorkFlowManager {
         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);
@@ -180,7 +219,7 @@ public class TestWorkFlowManager {
         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();
@@ -216,6 +255,7 @@ public class TestWorkFlowManager {
 
         return  requestContext;
     }
+
     private  ResponseContext createResponseContext(){
         ResponseContext responseContext = new ResponseContext();
         CommonHeader commonHeader = new CommonHeader();
@@ -227,6 +267,7 @@ public class TestWorkFlowManager {
 
         return  responseContext;
     }
+
     private RuntimeContext createRuntimeContext(){
         RuntimeContext runtimeContext = new RuntimeContext();
         RequestContext requestContext = creatRequestContext();