summaryrefslogtreecommitdiffstats
path: root/appc-dispatcher
diff options
context:
space:
mode:
authorJoss Armstrong <joss.armstrong@ericsson.com>2019-02-08 15:38:18 +0000
committerTakamune Cho <takamune.cho@att.com>2019-02-08 21:23:37 +0000
commit74cf8508ab0a778aec0a38e3786b1f17f1596385 (patch)
treef347cef89e90dc92c640a2ad6a8af106e413ce13 /appc-dispatcher
parent899c2f1520b1ec529bf6b4faef6623ea566634dd (diff)
Test coverage in workflow-impl
Increased package coverage to 83% Issue-ID: APPC-1408 Change-Id: I24b634ee7926bac2a196256cd20362d2f7b93b76 Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
Diffstat (limited to 'appc-dispatcher')
-rw-r--r--appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkFlowManagerImpl.java12
-rw-r--r--appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/impl/TestWorkFlowManager.java45
2 files changed, 49 insertions, 8 deletions
diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkFlowManagerImpl.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkFlowManagerImpl.java
index e6edc2657..000415c93 100644
--- a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkFlowManagerImpl.java
+++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkFlowManagerImpl.java
@@ -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);
}
}
diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/impl/TestWorkFlowManager.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/impl/TestWorkFlowManager.java
index eb8a8d4f6..8689fa70d 100644
--- a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/impl/TestWorkFlowManager.java
+++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/impl/TestWorkFlowManager.java
@@ -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
@@ -139,6 +140,34 @@ public class TestWorkFlowManager {
}
@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());
Mockito.when(svcLogicService.hasGraph(anyString(), anyString(), anyString(), anyString())).thenReturn(true);
@@ -165,6 +194,16 @@ public class TestWorkFlowManager {
}
@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);
Connection mockConnection = Mockito.mock(Connection.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();