diff options
2 files changed, 23 insertions, 11 deletions
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditDataService.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditDataService.java index 4e8443bf45..200f6375ea 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditDataService.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditDataService.java @@ -17,6 +17,8 @@ import com.fasterxml.jackson.databind.JsonMappingException; @Component public class AuditDataService { + private static final String AUDIT_STACK_DATA = "AuditStackData"; + @Autowired private RequestsDbClient requestsDbClient; @@ -30,7 +32,7 @@ public class AuditDataService { throws JsonProcessingException { List<RequestProcessingData> requestProcessingDataList = requestsDbClient.getRequestProcessingDataByGroupingIdAndNameAndTag(auditInventory.getVfModuleId(), - auditInventory.getHeatStackName(), "AuditStackData"); + auditInventory.getHeatStackName(), AUDIT_STACK_DATA); if (requestProcessingDataList.isEmpty()) { GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider(); String auditListString = objectMapper.getMapper().writeValueAsString(auditList);; @@ -39,7 +41,7 @@ public class AuditDataService { requestProcessingData.setSoRequestId(auditInventory.getMsoRequestId()); requestProcessingData.setGroupingId(auditInventory.getVfModuleId()); requestProcessingData.setName(auditInventory.getHeatStackName()); - requestProcessingData.setTag("AuditStackData"); + requestProcessingData.setTag(AUDIT_STACK_DATA); requestProcessingData.setValue(auditListString); requestsDbClient.saveRequestProcessingData(requestProcessingData); @@ -53,12 +55,11 @@ public class AuditDataService { * @throws JsonMappingException * @throws JsonParseException */ - public Optional<AAIObjectAuditList> getStackDataFromRequestDb(AuditInventory auditInventory) - throws JsonParseException, JsonMappingException, IOException { + public Optional<AAIObjectAuditList> getStackDataFromRequestDb(AuditInventory auditInventory) throws IOException { List<RequestProcessingData> requestProcessingDataList = requestsDbClient.getRequestProcessingDataByGroupingIdAndNameAndTag(auditInventory.getVfModuleId(), - auditInventory.getHeatStackName(), "AuditStackData"); + auditInventory.getHeatStackName(), AUDIT_STACK_DATA); if (!requestProcessingDataList.isEmpty()) { RequestProcessingData requestProcessingData = requestProcessingDataList.get(0); String auditListString = requestProcessingData.getValue(); diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditDataServiceTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditDataServiceTest.java index fd36995f3d..76e5bbc47f 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditDataServiceTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditDataServiceTest.java @@ -1,10 +1,9 @@ package org.onap.so.adapters.tasks.audit; -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; +import static org.assertj.core.api.Assertions.assertThat; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -13,7 +12,6 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; import org.onap.aai.domain.yang.Vserver; -import org.onap.so.adapters.tasks.audit.AuditDataService; import org.onap.so.audit.beans.AuditInventory; import org.onap.aaiclient.client.graphinventory.GraphInventoryCommonObjectMapperProvider; import org.onap.so.db.request.beans.RequestProcessingData; @@ -22,6 +20,7 @@ import org.onap.so.objects.audit.AAIObjectAudit; import org.onap.so.objects.audit.AAIObjectAuditList; import com.fasterxml.jackson.core.JsonProcessingException; + @RunWith(MockitoJUnitRunner.Silent.class) public class AuditDataServiceTest { @@ -56,9 +55,8 @@ public class AuditDataServiceTest { vserver.setVserverId("testVserverId"); audit.setAaiObject(vserver); auditList.getAuditList().add(audit); - GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider(); - String auditListString = objectMapper.getMapper().writeValueAsString(auditList);; + String auditListString = objectMapper.getMapper().writeValueAsString(auditList); RequestProcessingData requestProcessingData = new RequestProcessingData(); requestProcessingData.setSoRequestId(auditInventory.getMsoRequestId()); @@ -99,4 +97,17 @@ public class AuditDataServiceTest { "testVnfModuleId", "testVfModuleName1", "AuditStackData"); } + @Test + public void testGetStackDataToRequestDbWhenRequestProcessingDataListIsEmpty() throws Exception { + + Mockito.doReturn(new ArrayList<RequestProcessingData>()).when(requestsDbClient) + .getRequestProcessingDataByGroupingIdAndNameAndTag(Mockito.any(), Mockito.any(), Mockito.any()); + Optional<AAIObjectAuditList> result = auditDataService.getStackDataFromRequestDb(auditInventory); + Mockito.verify(requestsDbClient, Mockito.times(1)).getRequestProcessingDataByGroupingIdAndNameAndTag( + "testVnfModuleId", "testVfModuleName1", "AuditStackData"); + assertThat(result).isEmpty(); + + } + + } |