summaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks/src/test
diff options
context:
space:
mode:
authorLukasz Muszkieta <lukasz.muszkieta@nokia.com>2019-10-18 18:23:40 +0200
committerLukasz Muszkieta <lukasz.muszkieta@nokia.com>2019-10-18 18:31:08 +0200
commit847d9cefc96b4f5a9bbd6d3dc1d8d28789346304 (patch)
tree3a86909c20463075ec187fd67bb0c2dc3fd21f38 /bpmn/so-bpmn-tasks/src/test
parent78cd154393607d41974fbcf1e3ebc2669a8165c2 (diff)
add junit coverage and sonar fix
Change-Id: I80632046b259cd75b0ab57e2c7bf673c3d021bcd Issue-ID: SO-1576 Signed-off-by: Lukasz Muszkieta <lukasz.muszkieta@nokia.com>
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/test')
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnfTest.java70
1 files changed, 53 insertions, 17 deletions
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnfTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnfTest.java
index bbc20706a6..2d7649438e 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnfTest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnfTest.java
@@ -22,11 +22,16 @@
package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -36,6 +41,7 @@ import org.junit.Before;
import org.junit.Test;
import org.onap.so.bpmn.common.BuildingBlockExecution;
import org.onap.so.bpmn.common.DelegateExecutionImpl;
+import org.onap.so.bpmn.infrastructure.flowspecific.exceptions.VnfNotFoundException;
import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
@@ -74,33 +80,63 @@ public class ConfigAssignVnfTest {
private static final String INSTANCE_PARAM5_NAME = "paramName5";
private static final String INSTANCE_PARAM5_VALUE = "paramValue5";
-
private ConfigAssignVnf testedObject;
- private BuildingBlockExecution buildingBlockExecution;
private ExtractPojosForBB extractPojosForBB;
+ private ExceptionBuilder exceptionBuilderMock;
@Before
public void setup() {
- buildingBlockExecution = createBuildingBlockExecution();
extractPojosForBB = mock(ExtractPojosForBB.class);
- testedObject = new ConfigAssignVnf(extractPojosForBB, new ExceptionBuilder());
+ exceptionBuilderMock = mock(ExceptionBuilder.class);
+ testedObject = new ConfigAssignVnf(extractPojosForBB, exceptionBuilderMock);
}
@Test
public void prepareAbstractCDSPropertiesBean_success() throws Exception {
// given
+ BuildingBlockExecution buildingBlockExecution = createBuildingBlockExecution(createService(createVnfList()));
+ prepareExtractPojosForBB(buildingBlockExecution);
+ // when
+ testedObject.preProcessAbstractCDSProcessing(buildingBlockExecution);
+ // then
+ verifyConfigAssignPropertiesJsonContent(buildingBlockExecution);
+ }
+
+ @Test
+ public void invalidServiceJsonContentWhenPrepareCDSBean_flowExIsThrown() throws Exception {
+ // given
+ BuildingBlockExecution buildingBlockExecution = createBuildingBlockExecution("{invalidJsonContent}");
+ prepareExtractPojosForBB(buildingBlockExecution);
+ // when
+ testedObject.preProcessAbstractCDSProcessing(buildingBlockExecution);
+ // then
+ verify(exceptionBuilderMock).buildAndThrowWorkflowException(eq(buildingBlockExecution), eq(7000),
+ any(IOException.class));
+ }
+
+ @Test
+ public void vnfIsNotFoundWhenPrepareCDSBean_flowExIsThrown() throws Exception {
+ // given
+ BuildingBlockExecution buildingBlockExecution =
+ createBuildingBlockExecution(createService(Collections.emptyList()));
+ prepareExtractPojosForBB(buildingBlockExecution);
+ // when
+ testedObject.preProcessAbstractCDSProcessing(buildingBlockExecution);
+ // then
+ verify(exceptionBuilderMock).buildAndThrowWorkflowException(eq(buildingBlockExecution), eq(7000),
+ any(VnfNotFoundException.class));
+ }
+
+ private void prepareExtractPojosForBB(BuildingBlockExecution buildingBlockExecution) throws Exception {
when(extractPojosForBB.extractByKey(buildingBlockExecution, ResourceKey.GENERIC_VNF_ID))
.thenReturn(createGenericVnf());
when(extractPojosForBB.extractByKey(buildingBlockExecution, ResourceKey.SERVICE_INSTANCE_ID))
.thenReturn(createServiceInstance());
- // when
- testedObject.preProcessAbstractCDSProcessing(buildingBlockExecution);
- // then
- verifyConfigAssignPropertiesJsonContent();
}
- private void verifyConfigAssignPropertiesJsonContent() throws Exception {
+ private void verifyConfigAssignPropertiesJsonContent(BuildingBlockExecution buildingBlockExecution)
+ throws Exception {
AbstractCDSPropertiesBean abstractCDSPropertiesBean = buildingBlockExecution.getVariable("executionObject");
String payload = abstractCDSPropertiesBean.getRequestObject();
ObjectMapper mapper = new ObjectMapper();
@@ -121,9 +157,9 @@ public class ConfigAssignVnfTest {
assertThat(configAssignPropertiesNode.get(INSTANCE_PARAM3_NAME).asText()).isEqualTo(INSTANCE_PARAM3_VALUE);
}
- private BuildingBlockExecution createBuildingBlockExecution() {
+ private BuildingBlockExecution createBuildingBlockExecution(Object serviceJson) {
DelegateExecution execution = new DelegateExecutionFake();
- execution.setVariable(GENERAL_BLOCK_EXECUTION_MAP_KEY, createGeneralBuildingBlock());
+ execution.setVariable(GENERAL_BLOCK_EXECUTION_MAP_KEY, createGeneralBuildingBlock(serviceJson));
return new DelegateExecutionImpl(execution);
}
@@ -148,28 +184,28 @@ public class ConfigAssignVnfTest {
return genericVnf;
}
- private GeneralBuildingBlock createGeneralBuildingBlock() {
+ private GeneralBuildingBlock createGeneralBuildingBlock(Object serviceJson) {
GeneralBuildingBlock generalBuildingBlock = new GeneralBuildingBlock();
RequestContext requestContext = new RequestContext();
RequestParameters requestParameters = new RequestParameters();
- requestParameters.setUserParams(createRequestUserParams());
+ requestParameters.setUserParams(createRequestUserParams(serviceJson));
requestContext.setRequestParameters(requestParameters);
generalBuildingBlock.setRequestContext(requestContext);
return generalBuildingBlock;
}
- private List<Map<String, Object>> createRequestUserParams() {
+ private List<Map<String, Object>> createRequestUserParams(Object serviceJson) {
List<Map<String, Object>> userParams = new ArrayList<>();
Map<String, Object> userParamMap = new HashMap<>();
- userParamMap.put("service", createService());
+ userParamMap.put("service", serviceJson);
userParams.add(userParamMap);
return userParams;
}
- private Service createService() {
+ private Service createService(List<Vnfs> vnfList) {
Service service = new Service();
Resources resources = new Resources();
- resources.setVnfs(createVnfList());
+ resources.setVnfs(vnfList);
service.setResources(resources);
return service;
}