summaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks
diff options
context:
space:
mode:
authorBhatt, Prema <prema.bhatt@att.com>2019-06-18 15:13:35 -0400
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2019-06-18 15:13:42 -0400
commit496a93265e8326e48aba073e825df25b13349bbe (patch)
treec8152d487d9897b7fdaa9cf81c2c73fdcf478b3c /bpmn/so-bpmn-tasks
parent7c69f07593a8c7474bd7a69a65979dc0635f1526 (diff)
nullpointer in vnfadaptervfmoduleobjectmapper
Added code block to throw exception when we get a 'Name' wthout a 'Value' tag in the SDNC vf-module-topology. Right now we are seeing oam0_net_id is missing a value tag. Added Unit test to test this code change. Change-Id: I765d5a4eb9d351b7613d4c3561a2a5dbe37e4781 Issue-ID: SO-2031 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'bpmn/so-bpmn-tasks')
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapper.java12
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/exceptions/MissingValueTagException.java15
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/VnfAdapterVfModuleResources.java3
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapperPayloadTest.java35
4 files changed, 62 insertions, 3 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapper.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapper.java
index a1fcbff0db..bf8c80db82 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapper.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapper.java
@@ -78,6 +78,9 @@ import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
import org.onap.so.entity.MsoRequest;
import org.onap.so.jsonpath.JsonPathUtil;
import org.onap.so.openstack.utils.MsoMulticloudUtils;
+import org.onap.so.client.adapter.vnf.mapper.exceptions.MissingValueTagException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.fasterxml.jackson.core.JsonParseException;
@@ -92,6 +95,7 @@ import com.google.common.base.Joiner;
public class VnfAdapterVfModuleObjectMapper {
@Autowired
protected VnfAdapterObjectMapperUtils vnfAdapterObjectMapperUtils;
+ private static final Logger logger = LoggerFactory.getLogger(VnfAdapterVfModuleObjectMapper.class);
private static List<String> sdncResponseParamsToSkip =
asList("vnf_id", "vf_module_id", "vnf_name", "vf_module_name");
@@ -203,8 +207,8 @@ public class VnfAdapterVfModuleObjectMapper {
return paramsMap;
}
- private void buildDirectivesParamFromMap(Map<String, Object> paramsMap, String directive,
- Map<String, Object> srcMap) {
+ protected void buildDirectivesParamFromMap(Map<String, Object> paramsMap, String directive,
+ Map<String, Object> srcMap) throws MissingValueTagException {
StringBuilder directives = new StringBuilder();
int no_directives_size = 0;
if (directive.equals(MsoMulticloudUtils.USER_DIRECTIVES)
@@ -217,6 +221,10 @@ public class VnfAdapterVfModuleObjectMapper {
for (String attributeName : srcMap.keySet()) {
if (!(MsoMulticloudUtils.USER_DIRECTIVES.equals(directive)
&& attributeName.equals(MsoMulticloudUtils.OOF_DIRECTIVES))) {
+ if (srcMap.get(attributeName) == null) {
+ logger.error("No value tag found for attribute: {}", attributeName);
+ throw new MissingValueTagException("No value tag found for " + attributeName);
+ }
directives.append(new AttributeNameValue(attributeName, srcMap.get(attributeName).toString()));
if (i < (srcMap.size() - 1 + no_directives_size))
directives.append(", ");
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/exceptions/MissingValueTagException.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/exceptions/MissingValueTagException.java
new file mode 100644
index 0000000000..7271971e46
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/exceptions/MissingValueTagException.java
@@ -0,0 +1,15 @@
+package org.onap.so.client.adapter.vnf.mapper.exceptions;
+
+public class MissingValueTagException extends Exception {
+
+ private static final long serialVersionUID = -1598147488593823724L;
+
+ public MissingValueTagException() {
+ super();
+ }
+
+ public MissingValueTagException(String message) {
+ super(message);
+ }
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/VnfAdapterVfModuleResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/VnfAdapterVfModuleResources.java
index efe5f34824..0a825b8424 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/VnfAdapterVfModuleResources.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/VnfAdapterVfModuleResources.java
@@ -33,6 +33,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
import org.onap.so.client.adapter.vnf.mapper.VnfAdapterVfModuleObjectMapper;
+import org.onap.so.client.adapter.vnf.mapper.exceptions.MissingValueTagException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -47,7 +48,7 @@ public class VnfAdapterVfModuleResources {
public CreateVfModuleRequest createVfModuleRequest(RequestContext requestContext, CloudRegion cloudRegion,
OrchestrationContext orchestrationContext, ServiceInstance serviceInstance, GenericVnf genericVnf,
VfModule vfModule, VolumeGroup volumeGroup, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse)
- throws IOException {
+ throws IOException, MissingValueTagException {
return vnfAdapterVfModuleObjectMapper.createVfModuleRequestMapper(requestContext, cloudRegion,
orchestrationContext, serviceInstance, genericVnf, vfModule, volumeGroup, sdncVnfQueryResponse,
sdncVfModuleQueryResponse);
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapperPayloadTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapperPayloadTest.java
index 5a8e57135a..44a08139d6 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapperPayloadTest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapperPayloadTest.java
@@ -29,7 +29,9 @@ import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.onap.sdnc.northbound.client.model.GenericResourceApiVmNetworkData;
import org.onap.so.adapters.vnfrest.CreateVfModuleRequest;
import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest;
@@ -43,6 +45,8 @@ import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf;
import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule;
+import org.onap.so.openstack.utils.MsoMulticloudUtils;
+import org.onap.so.client.adapter.vnf.mapper.exceptions.MissingValueTagException;
import com.fasterxml.jackson.databind.ObjectMapper;
public class VnfAdapterVfModuleObjectMapperPayloadTest {
@@ -52,6 +56,9 @@ public class VnfAdapterVfModuleObjectMapperPayloadTest {
private VnfAdapterVfModuleObjectMapper vfModuleObjectMapper = new VnfAdapterVfModuleObjectMapper();
private ObjectMapper omapper = new ObjectMapper();
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
@Before
public void setUp() {
vfModuleObjectMapper.vnfAdapterObjectMapperUtils = new VnfAdapterObjectMapperUtils();
@@ -362,6 +369,34 @@ public class VnfAdapterVfModuleObjectMapperPayloadTest {
}
@Test
+ public void buildDirectivesParamFromMapNoValueTagTest() throws Exception {
+
+ Map<String, Object> paramsMap = new HashMap<>();
+ Map<String, Object> srcMap = new HashMap<>();
+ srcMap.put("key1", "value1");
+ srcMap.put("key2", "value2");
+ srcMap.put("key3", null);
+
+ expectedException.expect(MissingValueTagException.class);
+ vfModuleObjectMapper.buildDirectivesParamFromMap(paramsMap, MsoMulticloudUtils.SDNC_DIRECTIVES, srcMap);
+ }
+
+ @Test
+ public void buildDirectivesParamFromMapSunnyDayTest() throws Exception {
+
+ Map<String, Object> paramsMap = new HashMap<>();
+ Map<String, Object> srcMap = new HashMap<>();
+ srcMap.put("key1", "value1");
+ srcMap.put("key2", "value2");
+ String expectedResult =
+ "[{ \"attributes\": [ {\"attribute_name\": \"key1\", \"attribute_value\": \"value1\"}, {\"attribute_name\": \"key2\", \"attribute_value\": \"value2\"}] }]";
+
+ vfModuleObjectMapper.buildDirectivesParamFromMap(paramsMap, MsoMulticloudUtils.SDNC_DIRECTIVES, srcMap);
+
+ assertEquals(expectedResult, paramsMap.values().toString());
+ }
+
+ @Test
public void createVfModuleWithVolumeGroupRequestMapperTest() throws Exception {
// prepare and set service instance