From 847d9cefc96b4f5a9bbd6d3dc1d8d28789346304 Mon Sep 17 00:00:00 2001 From: Lukasz Muszkieta Date: Fri, 18 Oct 2019 18:23:40 +0200 Subject: add junit coverage and sonar fix Change-Id: I80632046b259cd75b0ab57e2c7bf673c3d021bcd Issue-ID: SO-1576 Signed-off-by: Lukasz Muszkieta --- .../flowspecific/exceptions/VnfNotFoundException.java | 7 +++++++ .../infrastructure/flowspecific/tasks/ConfigAssignVnf.java | 11 ++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/exceptions/VnfNotFoundException.java (limited to 'bpmn/so-bpmn-tasks/src/main/java/org/onap') diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/exceptions/VnfNotFoundException.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/exceptions/VnfNotFoundException.java new file mode 100644 index 0000000000..e1c2e01832 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/exceptions/VnfNotFoundException.java @@ -0,0 +1,7 @@ +package org.onap.so.bpmn.infrastructure.flowspecific.exceptions; + +public class VnfNotFoundException extends Exception { + public VnfNotFoundException(String modelCustomizationUuidOfSearchedVnf) { + super("Can not find vnf for model customization uuid: " + modelCustomizationUuidOfSearchedVnf); + }; +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnf.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnf.java index e73a504291..3a69d27f32 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnf.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnf.java @@ -22,11 +22,13 @@ package org.onap.so.bpmn.infrastructure.flowspecific.tasks; import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.UUID; import org.onap.so.bpmn.common.BuildingBlockExecution; +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; @@ -127,12 +129,12 @@ public class ConfigAssignVnf { return getServiceObjectFromServiceMap(serviceMap); } - private Service getServiceObjectFromServiceMap(Map serviceMap) throws Exception { + private Service getServiceObjectFromServiceMap(Map serviceMap) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); String serviceFromJson = objectMapper.writeValueAsString(serviceMap.get("service")); try { return objectMapper.readValue(serviceFromJson, Service.class); - } catch (Exception e) { + } catch (IOException e) { logger.error(String.format( "An exception occurred while converting json object to Service object. The json is: %s", serviceFromJson), e); @@ -141,15 +143,14 @@ public class ConfigAssignVnf { } private List> getInstanceParamForVnf(Service service, String genericVnfModelCustomizationUuid) - throws Exception { + throws VnfNotFoundException { Optional foundedVnf = service.getResources().getVnfs().stream() .filter(vnfs -> vnfs.getModelInfo().getModelCustomizationId().equals(genericVnfModelCustomizationUuid)) .findFirst(); if (foundedVnf.isPresent()) { return foundedVnf.get().getInstanceParams(); } else { - throw new Exception(String.format("Can not find vnf for genericVnfModelCustomizationUuid: %s", - genericVnfModelCustomizationUuid)); + throw new VnfNotFoundException(genericVnfModelCustomizationUuid); } } } -- cgit 1.2.3-korg