aboutsummaryrefslogtreecommitdiffstats
path: root/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/impl/TestWorkFlowManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/impl/TestWorkFlowManager.java')
-rw-r--r--appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/impl/TestWorkFlowManager.java139
1 files changed, 95 insertions, 44 deletions
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;
}