aboutsummaryrefslogtreecommitdiffstats
path: root/appc-dispatcher/appc-workflow-management
diff options
context:
space:
mode:
authorJoss Armstrong <joss.armstrong@ericsson.com>2019-01-17 12:52:30 +0000
committerTakamune Cho <takamune.cho@att.com>2019-01-17 15:18:21 +0000
commit696e33461539663bacea88245cb28463618d13e2 (patch)
tree0134813ff83c657d3aed0d7b0fcb031efb8ac5ac /appc-dispatcher/appc-workflow-management
parent3be4c991bc7d18e3d0bcf4b8524f5b93934242a8 (diff)
Test coverage for appc-workflow-management-core
Increase test coverage from 2% to 73% Issue-ID: APPC-1332 Change-Id: I41567d3b5108581bbdce95671366a57323c7b1a4 Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
Diffstat (limited to 'appc-dispatcher/appc-workflow-management')
-rw-r--r--appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/activator/TransactionAbortedMarker.java11
-rw-r--r--appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkFlowManagerImpl.java116
-rw-r--r--appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/impl/TestWorkFlowManager.java139
3 files changed, 152 insertions, 114 deletions
diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/activator/TransactionAbortedMarker.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/activator/TransactionAbortedMarker.java
index 682e41a9a..61a336b6c 100644
--- a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/activator/TransactionAbortedMarker.java
+++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/activator/TransactionAbortedMarker.java
@@ -5,6 +5,8 @@
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications (C) 2019 Ericsson
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,11 +31,12 @@ import org.onap.appc.transactionrecorder.TransactionRecorder;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
-
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
import java.util.UUID;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
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 50b37ece3..e6edc2657 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
@@ -5,6 +5,8 @@
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications (C) 2019 Ericsson
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +26,6 @@
package org.onap.appc.workflow.impl;
import org.apache.commons.lang.ObjectUtils;
-import org.apache.commons.lang3.StringUtils;
import org.onap.appc.common.constant.Constants;
import org.onap.appc.configuration.Configuration;
import org.onap.appc.configuration.ConfigurationFactory;
@@ -57,7 +58,7 @@ public class WorkFlowManagerImpl implements WorkFlowManager{
);
public void setWorkflowResolver(WorkflowResolver workflowResolver){
- this.workflowResolver=workflowResolver;
+ this.workflowResolver = workflowResolver;
}
public void setSvcLogicServiceRef(SvcLogicService svcLogic) {
@@ -78,14 +79,12 @@ public class WorkFlowManagerImpl implements WorkFlowManager{
@Override
public WorkflowResponse executeWorkflow(WorkflowRequest workflowRequest) {
if (logger.isTraceEnabled()) {
- logger.trace("Entering to executeWorkflow with WorkflowRequest = "+ ObjectUtils.toString(workflowRequest.toString()));
+ logger.trace("Entering to executeWorkflow with WorkflowRequest = " + ObjectUtils.toString(workflowRequest.toString()));
}
WorkflowResponse workflowResponse = new WorkflowResponse();
workflowResponse.setResponseContext(workflowRequest.getResponseContext());
try {
-
-
WorkflowKey workflowKey = workflowResolver.resolve(workflowRequest.getRequestContext().getAction().name(), workflowRequest.getVnfContext().getType(), null,workflowRequest.getRequestContext().getCommonHeader().getApiVer());
Properties workflowParams = new Properties();
@@ -107,78 +106,76 @@ public class WorkFlowManagerImpl implements WorkFlowManager{
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 subRequestId = configuration.getProperty("org.onap.appc.workflow.subRequestId",Constants.SUB_REQUEST_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(actionProperty, workflowRequest.getRequestContext().getAction().name());
workflowParams.put(requestIdProperty, workflowRequest.getRequestContext().getCommonHeader().getRequestId());
workflowParams.put(vfIdProperty, workflowRequest.getVnfContext().getId());
- workflowParams.put(vfTypeProperty,workflowRequest.getVnfContext().getType());
- workflowParams.put(apiVerProperty,workflowRequest.getRequestContext().getCommonHeader().getApiVer());
- workflowParams.put(originatorIdProperty,workflowRequest.getRequestContext().getCommonHeader().getOriginatorId());
- workflowParams.put(subRequestId,workflowRequest.getRequestContext().getCommonHeader().getSubRequestId());
+ workflowParams.put(vfTypeProperty, workflowRequest.getVnfContext().getType());
+ workflowParams.put(apiVerProperty, workflowRequest.getRequestContext().getCommonHeader().getApiVer());
+ workflowParams.put(originatorIdProperty, workflowRequest.getRequestContext().getCommonHeader().getOriginatorId());
+ workflowParams.put(subRequestId, workflowRequest.getRequestContext().getCommonHeader().getSubRequestId());
Object payloadJson = workflowRequest.getRequestContext().getPayload();
- if(payloadJson!=null) {
+ if(payloadJson != null) {
try {
Map<String, String> payloadProperties = ObjectMapper.map(payloadJson);
workflowParams.putAll(payloadProperties);
- if (logger.isDebugEnabled()) {
- logger.debug("DG properties: " + workflowParams);
- }
+ logger.debug("DG properties: " + workflowParams);
} catch (Exception e) {
logger.error("Error parsing payload json string", e);
Properties workflowPrp = new Properties();
workflowPrp.setProperty("error-message", "Error parsing payload json string");
- fillStatus(501, "Error parsing payload json string: "+e.getMessage(), workflowRequest.getResponseContext());
- if (logger.isTraceEnabled()) {
- logger.trace("Exiting from executeWorkflow with (workflowResponse = "+ObjectUtils.toString(workflowResponse)+")");
- }
+ fillStatus(501, "Error parsing payload json string: " + e.getMessage(), workflowRequest.getResponseContext());
+ logger.trace("Exiting from executeWorkflow with (workflowResponse = " + ObjectUtils.toString(workflowResponse) + ")");
return workflowResponse;
}
}
- if (logger.isDebugEnabled()) {
- logger.debug("DG parameters "+ actionProperty +":"+ workflowRequest.getRequestContext().getAction().name()+", "+
- requestIdProperty +":"+ workflowRequest.getRequestContext().getCommonHeader().getRequestId()+", "+
- vfIdProperty +":"+ workflowRequest.getVnfContext().getId());
+ logger.debug("DG parameters "+ actionProperty +":"+ workflowRequest.getRequestContext().getAction().name() + ", "+
+ requestIdProperty +":"+ workflowRequest.getRequestContext().getCommonHeader().getRequestId() + ", " +
+ vfIdProperty + ":" + workflowRequest.getVnfContext().getId());
- logger.debug("Starting DG Execution for request "+workflowRequest.getRequestContext().getCommonHeader().getRequestId());
- }
+ logger.debug("Starting DG Execution for request "+workflowRequest.getRequestContext().getCommonHeader().getRequestId());
}
if (workflowRequest.getRequestContext().getCommonHeader().getApiVer().startsWith("1.")){
- workflowParams.put("isBwcMode","true");
+ workflowParams.put("isBwcMode", "true");
} else {
workflowParams.put("isBwcMode", "false");
}
SVCLogicServiceExecute(workflowKey, workflowRequest.getRequestContext(), workflowParams , workflowResponse);
- if (logger.isTraceEnabled()) {
- logger.trace("Completed DG Execution for Request id: " + workflowRequest.getRequestContext().getCommonHeader().getRequestId() + "with response code: " + workflowResponse.getResponseContext().getStatus().getCode());
- }
+ logger.trace("Completed DG Execution for Request id: " + workflowRequest.getRequestContext().getCommonHeader().getRequestId()
+ + "with response code: " + workflowResponse.getResponseContext().getStatus().getCode());
}catch (Exception e){
- logger.error("Error Executing DG " +e.getMessage(),e);
- fillStatus(501, "Error Executing DG "+e.getMessage(), workflowRequest.getResponseContext());
- }
- if (logger.isTraceEnabled()) {
- logger.trace("Exiting from executeWorkflow with (workflowResponse = "+ ObjectUtils.toString(workflowResponse.getResponseContext().getStatus().getMessage())+")");
+ logger.error("Error Executing DG " + e.getMessage(), e);
+ fillStatus(501, "Error Executing DG "+ e.getMessage(), workflowRequest.getResponseContext());
}
+ logger.trace("Exiting from executeWorkflow with (workflowResponse = " +
+ ObjectUtils.toString(workflowResponse.getResponseContext().getStatus().getMessage()) + ")");
return workflowResponse;
}
private void populateDGContext(Properties workflowParams, WorkflowRequest workflowRequest) {
- workflowParams.put("input.common-header.timestamp",new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(workflowRequest.getRequestContext().getCommonHeader().getTimeStamp()));
- workflowParams.put("input.common-header.api-ver",workflowRequest.getRequestContext().getCommonHeader().getApiVer());
- workflowParams.put("input.common-header.request-id",workflowRequest.getRequestContext().getCommonHeader().getRequestId());
- workflowParams.put("input.common-header.originator-id",workflowRequest.getRequestContext().getCommonHeader().getOriginatorId());
- workflowParams.put("input.common-header.sub-request-id",workflowRequest.getRequestContext().getCommonHeader().getSubRequestId()!=null ? workflowRequest.getRequestContext().getCommonHeader().getSubRequestId():"");
- workflowParams.put("input.action",workflowRequest.getRequestContext().getAction().toString());
- workflowParams.put("input.payload",null != workflowRequest.getRequestContext().getPayload() ? workflowRequest.getRequestContext().getPayload() : "");
- workflowParams.put("input.action-identifiers.vnf-id",workflowRequest.getVnfContext().getId());
- workflowParams.put("input.action-identifiers.vnfc-name",workflowRequest.getRequestContext().getActionIdentifiers().getVnfcName()!=null?workflowRequest.getRequestContext().getActionIdentifiers().getVnfcName():"");
- workflowParams.put("input.action-identifiers.service-instance-id",workflowRequest.getRequestContext().getActionIdentifiers().getServiceInstanceId()!=null?workflowRequest.getRequestContext().getActionIdentifiers().getServiceInstanceId():"");
- workflowParams.put("input.action-identifiers.vserver-id",workflowRequest.getRequestContext().getActionIdentifiers().getVserverId()!=null?workflowRequest.getRequestContext().getActionIdentifiers().getVserverId():"");
- workflowParams.put("input.action-identifiers.vf-module-id",workflowRequest.getRequestContext().getActionIdentifiers().getVfModuleId()!=null?workflowRequest.getRequestContext().getActionIdentifiers().getVfModuleId():"");
+ workflowParams.put("input.common-header.timestamp", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(workflowRequest.getRequestContext().getCommonHeader().getTimeStamp()));
+ workflowParams.put("input.common-header.api-ver", workflowRequest.getRequestContext().getCommonHeader().getApiVer());
+ workflowParams.put("input.common-header.request-id", workflowRequest.getRequestContext().getCommonHeader().getRequestId());
+ workflowParams.put("input.common-header.originator-id", workflowRequest.getRequestContext().getCommonHeader().getOriginatorId());
+ workflowParams.put("input.common-header.sub-request-id", workflowRequest.getRequestContext().getCommonHeader().getSubRequestId() != null ?
+ workflowRequest.getRequestContext().getCommonHeader().getSubRequestId() : "");
+ workflowParams.put("input.action", workflowRequest.getRequestContext().getAction().toString());
+ workflowParams.put("input.payload", null != workflowRequest.getRequestContext().getPayload() ?
+ workflowRequest.getRequestContext().getPayload() : "");
+ workflowParams.put("input.action-identifiers.vnf-id", workflowRequest.getVnfContext().getId());
+ workflowParams.put("input.action-identifiers.vnfc-name", workflowRequest.getRequestContext().getActionIdentifiers().getVnfcName() != null ?
+ workflowRequest.getRequestContext().getActionIdentifiers().getVnfcName() : "");
+ workflowParams.put("input.action-identifiers.service-instance-id", workflowRequest.getRequestContext().getActionIdentifiers().getServiceInstanceId() !=null ?
+ workflowRequest.getRequestContext().getActionIdentifiers().getServiceInstanceId() : "");
+ workflowParams.put("input.action-identifiers.vserver-id", workflowRequest.getRequestContext().getActionIdentifiers().getVserverId() !=null ?
+ workflowRequest.getRequestContext().getActionIdentifiers().getVserverId() : "");
+ 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) {
for (Map.Entry<String, String> entry : additionalContext.entrySet()) {
@@ -196,9 +193,7 @@ public class WorkFlowManagerImpl implements WorkFlowManager{
@Override
public WorkflowExistsOutput workflowExists(WorkflowRequest workflowQueryParams) {
WorkflowExistsOutput workflowExistsOutput = new WorkflowExistsOutput(false,false);
- if (logger.isTraceEnabled()) {
- logger.trace("Entering to workflowExists with WorkflowRequest = "+ObjectUtils.toString(workflowQueryParams.toString()));
- }
+ logger.trace("Entering to workflowExists with WorkflowRequest = " + ObjectUtils.toString(workflowQueryParams.toString()));
try {
WorkflowKey workflowKey = workflowResolver.resolve(
@@ -230,9 +225,7 @@ public class WorkFlowManagerImpl implements WorkFlowManager{
logger.error("Error querying workflow from database"+e.getMessage());
throw new RuntimeException(e);
}
- if (logger.isTraceEnabled()) {
- logger.trace("Exiting workflowExists");
- }
+ logger.trace("Exiting workflowExists");
return workflowExistsOutput;
}
@@ -242,9 +235,7 @@ public class WorkFlowManagerImpl implements WorkFlowManager{
}
private void SVCLogicServiceExecute(WorkflowKey workflowKey, RequestContext requestContext, Properties workflowParams, WorkflowResponse workflowResponse) {
- if (logger.isTraceEnabled()) {
- logger.trace("Entering SVCLogicServiceExecute");
- }
+ logger.trace("Entering SVCLogicServiceExecute");
Properties respProps = null;
@@ -252,11 +243,10 @@ public class WorkFlowManagerImpl implements WorkFlowManager{
respProps = svcLogic.execute(workflowKey.module(), workflowKey.name(), workflowKey.version(), "sync", workflowParams);
} catch (Exception e) {
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);
}
if (respProps != null) {
@@ -274,14 +264,10 @@ public class WorkFlowManagerImpl implements WorkFlowManager{
setWorkFlowResponseStatus(workflowResponse.getResponseContext(), commonStatus, specificStatusMessage, specificStatusCode);
- if (logger.isDebugEnabled()) {
- logger.debug("DG Execution Status: " + commonStatus);
- }
+ logger.debug("DG Execution Status: " + commonStatus);
}
- if (logger.isTraceEnabled()) {
- logger.trace("Exiting from SVCLogicServiceExecute");
- }
+ logger.trace("Exiting from SVCLogicServiceExecute");
}
/**
@@ -344,6 +330,4 @@ public class WorkFlowManagerImpl implements WorkFlowManager{
responceContext.getStatus().setCode(code);
responceContext.getStatus().setMessage(message);
}
-
-
}
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 7912ade9a..eb8a8d4f6 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
@@ -5,6 +5,8 @@
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications (C) 2019 Ericsson
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,11 +27,25 @@ package org.onap.appc.workflow.impl;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mockito;
-import org.onap.appc.domainmodel.lcm.*;
+import org.onap.appc.common.constant.Constants;
+import org.onap.appc.configuration.Configuration;
+import org.onap.appc.configuration.ConfigurationFactory;
+import org.onap.appc.dao.util.DBUtils;
+import org.onap.appc.domainmodel.lcm.ActionIdentifiers;
+import org.onap.appc.domainmodel.lcm.CommonHeader;
+import org.onap.appc.domainmodel.lcm.Flags;
+import org.onap.appc.domainmodel.lcm.RequestContext;
+import org.onap.appc.domainmodel.lcm.ResponseContext;
+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.workflow.impl.WorkFlowManagerImpl;
import org.onap.appc.workflow.impl.WorkflowKey;
import org.onap.appc.workflow.impl.WorkflowResolver;
@@ -38,9 +54,13 @@ import org.onap.appc.workflow.objects.WorkflowRequest;
import org.onap.appc.workflow.objects.WorkflowResponse;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
+import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import java.util.Date;
import java.util.Properties;
@@ -48,8 +68,12 @@ import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.anyString;
@RunWith(PowerMockRunner.class)
-@PrepareForTest( { WorkflowResolver.class,WorkFlowManagerImpl.class} )
+@PrepareForTest({ConfigurationFactory.class, DBUtils.class})
public class TestWorkFlowManager {
+
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+
public TestWorkFlowManager() {
}
@@ -61,9 +85,11 @@ public class TestWorkFlowManager {
@Before
public void init(){
-
- this.workflowResolver= Mockito.mock(WorkflowResolver.class);
- this.svcLogicService=Mockito.mock(SvcLogicService.class);
+ PowerMockito.mockStatic(ConfigurationFactory.class);
+ Configuration mockConfiguration = Mockito.mock(Configuration.class);
+ PowerMockito.when(ConfigurationFactory.getConfiguration()).thenReturn(mockConfiguration);
+ this.workflowResolver = Mockito.mock(WorkflowResolver.class);
+ this.svcLogicService = Mockito.mock(SvcLogicService.class);
workflowManger.setWorkflowResolver(workflowResolver);
workflowManger.setSvcLogicServiceRef(svcLogicService);
@@ -71,12 +97,14 @@ public class TestWorkFlowManager {
@Test
public void testExecuteWorkFlow() throws SvcLogicException{
- Mockito.when(workflowResolver.resolve(anyString(),anyString(),anyString(),anyString())).thenReturn(getWorkFlowKey());
- Mockito.when(svcLogicService.execute(anyString(),anyString(), anyString(),anyString(),anyObject())).thenReturn(createSvcExexuteSuccessResponse());
+ 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(), "2.00" ,"ST_249","O1652", "uid34", VNFOperation.Lock,"mj13","Payload");
+ WorkflowRequest workflowRequest = getWorkflowRequest("vSCP", 300, new Date(), "2.00", "ST_249", "O1652", "uid34",
+ VNFOperation.Lock, "mj13", Constants.PAYLOAD);
- WorkflowResponse response=workflowManger.executeWorkflow(workflowRequest);
+ WorkflowResponse response = workflowManger.executeWorkflow(workflowRequest);
Assert.assertTrue(response.getResponseContext().getStatus().getMessage().equals("success"));
@@ -85,10 +113,12 @@ public class TestWorkFlowManager {
@Test
public void testExecuteWorkFlowFalse() throws SvcLogicException{
- Mockito.when(workflowResolver.resolve(anyString(),anyString(),anyString(),anyString())).thenReturn(getWorkFlowKey());
- Mockito.when(svcLogicService.execute(anyString(),anyString(), anyString(),anyString(),anyObject())).thenReturn(createSvcExexuteFailureResponse());
+ Mockito.when(workflowResolver.resolve(anyString(), anyString(), anyString(), anyString())).thenReturn(getWorkFlowKey());
+ Mockito.when(svcLogicService.execute(anyString(), anyString(), anyString(), anyString(), anyObject()))
+ .thenReturn(createSvcExexuteFailureResponse());
- WorkflowRequest workflowRequest =getWorkflowRequest("vSCP",300,new Date(), "2.00" ,"ST_249","O1652", "uid34", VNFOperation.Lock,"mj13","Payload");
+ WorkflowRequest workflowRequest = getWorkflowRequest("vSCP", 300, new Date(), "2.00", "ST_249", "O1652", "uid34",
+ VNFOperation.Lock, "mj13", Constants.PAYLOAD);
WorkflowResponse response=workflowManger.executeWorkflow(workflowRequest);
Assert.assertTrue(response.getResponseContext().getStatus().getMessage().equals("failure"));
@@ -97,10 +127,12 @@ public class TestWorkFlowManager {
@Test
public void testExecuteWorkFlowAPIVersionStartWithOne() throws SvcLogicException{
- Mockito.when(workflowResolver.resolve(anyString(),anyString(),anyString(),anyString())).thenReturn(getWorkFlowKey());
- Mockito.when(svcLogicService.execute(anyString(),anyString(), anyString(),anyString(),anyObject())).thenReturn(createSvcExexuteSuccessResponse());
+ 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","Payload");
+ WorkflowRequest workflowRequest = getWorkflowRequest("vSCP", 300, new Date(), "1.00", "ST_249", "O1652", "uid34",
+ VNFOperation.Lock, "mj13", Constants.PAYLOAD);
WorkflowResponse response=workflowManger.executeWorkflow(workflowRequest);
Assert.assertTrue(response.getResponseContext().getStatus().getMessage().equals("success"));
@@ -108,31 +140,50 @@ public class TestWorkFlowManager {
@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);
+ Mockito.when(workflowResolver.resolve(anyString(), anyString(), anyString(), anyString())).thenReturn(getWorkFlowKey());
+ 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","Payload");
+ WorkflowRequest workflowRequest = getWorkflowRequest("vSCP", 300, new Date(), "2.00", "ST_249", "O1652", "uid34",
+ VNFOperation.Lock, "mj13", Constants.PAYLOAD);
- WorkflowExistsOutput response=workflowManger.workflowExists(workflowRequest);
+ WorkflowExistsOutput response = workflowManger.workflowExists(workflowRequest);
Assert.assertTrue(response.isMappingExist());
}
@Test
- public void testWorkFlowNotExist() throws SvcLogicException{
- Mockito.when(workflowResolver.resolve(anyString(),anyString(),anyString(),anyString())).thenReturn(getWorkFlowKey());
- Mockito.when(svcLogicService.hasGraph(anyString(),anyString(), anyString(),anyString())).thenReturn(false);
+ public void testWorkFlowNotExist() throws SvcLogicException {
+ Mockito.when(workflowResolver.resolve(anyString(), anyString(), anyString(), anyString())).thenReturn(getWorkFlowKey());
+ Mockito.when(svcLogicService.hasGraph(anyString(), anyString(), anyString(), anyString())).thenReturn(false);
- WorkflowRequest workflowRequest =getWorkflowRequest("vSCP",300,new Date(), "2.00" ,"ST_249","O1652", "uid34", VNFOperation.Lock,"mj13","Payload");
+ WorkflowRequest workflowRequest = getWorkflowRequest("vSCP", 300, new Date(), "2.00", "ST_249", "O1652", "uid34",
+ VNFOperation.Lock, "mj13", Constants.PAYLOAD);
- WorkflowExistsOutput response=workflowManger.workflowExists(workflowRequest);
+ WorkflowExistsOutput response = workflowManger.workflowExists(workflowRequest);
Assert.assertTrue(response.isMappingExist());
}
- 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();
+ @Test
+ public void testWorkflowResolver() throws SQLException {
+ PowerMockito.mockStatic(DBUtils.class);
+ Connection mockConnection = Mockito.mock(Connection.class);
+ PreparedStatement mockStatement = Mockito.mock(PreparedStatement.class);
+ ResultSet mockResultSet = Mockito.mock(ResultSet.class);
+ PowerMockito.when(DBUtils.getConnection(Mockito.anyString())).thenReturn(mockConnection);
+ PowerMockito.when(mockConnection.prepareStatement(Mockito.anyString())).thenReturn(mockStatement);
+ PowerMockito.when(mockStatement.executeQuery()).thenReturn(mockResultSet);
+ PowerMockito.when(mockResultSet.next()).thenReturn(true);
+ workflowResolver = new WorkflowResolver(1);
+ expectedEx.expect(IllegalArgumentException.class);
+ expectedEx.expectMessage("Duplicated configuration entry: ");
+ workflowResolver.resolve("ACTION", "VNF_TYPE", "VNF_VERSION", "API_VERSION");
+ }
+
+ 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();
runtimeContext.getRequestContext().getCommonHeader().getFlags().setTtl(ttl);
runtimeContext.getRequestContext().getCommonHeader().setApiVer(apiVersion);
@@ -155,7 +206,7 @@ public class TestWorkFlowManager {
}
private RequestContext creatRequestContext(){
- RequestContext requestContext=new RequestContext();
+ RequestContext requestContext = new RequestContext();
CommonHeader commonHeader = new CommonHeader();
Flags flags = new Flags();
ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
@@ -166,7 +217,7 @@ public class TestWorkFlowManager {
return requestContext;
}
private ResponseContext createResponseContext(){
- ResponseContext responseContext=new ResponseContext();
+ ResponseContext responseContext = new ResponseContext();
CommonHeader commonHeader = new CommonHeader();
Flags flags = new Flags();
Status status = new Status();
@@ -177,38 +228,38 @@ public class TestWorkFlowManager {
return responseContext;
}
private RuntimeContext createRuntimeContext(){
- RuntimeContext runtimeContext=new RuntimeContext();
- RequestContext requestContext=creatRequestContext();
- ResponseContext responseContext=createResponseContext();
+ RuntimeContext runtimeContext = new RuntimeContext();
+ RequestContext requestContext = creatRequestContext();
+ ResponseContext responseContext = createResponseContext();
runtimeContext.setRequestContext(requestContext);
runtimeContext.setResponseContext(responseContext);
- VNFContext vnfContext=new VNFContext();
+ VNFContext vnfContext = new VNFContext();
runtimeContext.setVnfContext(vnfContext);
return runtimeContext;
}
public WorkflowKey getWorkFlowKey(){
- WorkflowKey workflowKey=new WorkflowKey("APPCDG","2.0.0.0","dgModule");
+ WorkflowKey workflowKey = new WorkflowKey("APPCDG", "2.0.0.0", "dgModule");
return workflowKey;
}
private Properties createSvcExexuteSuccessResponse(){
- Properties properties=new Properties();
- properties.setProperty("output.payload","success");
- properties.setProperty("SvcLogic.status","success");
- properties.setProperty("output.status.code","400");
- properties.setProperty("output.status.message","success");
+ Properties properties = new Properties();
+ properties.setProperty("output.payload", "success");
+ properties.setProperty(Constants.DG_ATTRIBUTE_STATUS, "success");
+ properties.setProperty(Constants.DG_OUTPUT_STATUS_CODE, "400");
+ properties.setProperty(Constants.DG_OUTPUT_STATUS_MESSAGE, "success");
return properties;
}
private Properties createSvcExexuteFailureResponse(){
- Properties properties=new Properties();
- properties.setProperty("output.payload","failure");
- properties.setProperty("SvcLogic.status","failure");
- properties.setProperty("output.status.message","failure");
+ Properties properties = new Properties();
+ properties.setProperty("output.payload", "failure");
+ properties.setProperty(Constants.DG_ATTRIBUTE_STATUS, "failure");
+ properties.setProperty(Constants.DG_OUTPUT_STATUS_MESSAGE, "failure");
return properties;
}