summaryrefslogtreecommitdiffstats
path: root/adapters/mso-openstack-adapters/src/test/java
diff options
context:
space:
mode:
authorBoslet, Cory <cory.boslet@att.com>2019-07-17 13:36:05 -0400
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2019-07-17 14:15:41 -0400
commiteaef24e96c1ce95195845258ce0a304ab9c0c21a (patch)
tree00879f3616c5369307803e347950dc292c35d8dc /adapters/mso-openstack-adapters/src/test/java
parent785c77ae295b287678d4842269222c31b3e4c330 (diff)
add query stack data and populate table step
Need to check if audit is enabled first in the delete record task Updates to audit delete redeisgn and data to table Various updates to logging, audit object, added tag to query, updated tag value. Updated write method to make sure an entry for this heat stack doesnt already exist to avoid duplicate entrys Updated unit test to account for get query Added so that id is not hidden from query results Updated the was delete is done plus minor updates. Updated delete method to use resttemplate instead of bowman client Combined the write and get stack data task into the external tasks. Removed the task to delete the stack data from db Updates to junit request id so its not a random id for test Updated service tasks in att BB to call external task Update to be a real uuid format due to failing unit test Updated fields to protected and updated unit test Issue-ID: SO-2111 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com> Change-Id: I8f479a046cf837403f60c330ed6ad8bc08a9c82f
Diffstat (limited to 'adapters/mso-openstack-adapters/src/test/java')
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditDataServiceTest.java101
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java25
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditVServerTest.java73
3 files changed, 195 insertions, 4 deletions
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditDataServiceTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditDataServiceTest.java
new file mode 100644
index 0000000000..d3380a6a33
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditDataServiceTest.java
@@ -0,0 +1,101 @@
+package org.onap.so.adapters.audit;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.aai.domain.yang.Vserver;
+import org.onap.so.audit.beans.AuditInventory;
+import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider;
+import org.onap.so.db.request.beans.RequestProcessingData;
+import org.onap.so.db.request.client.RequestsDbClient;
+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 {
+
+ @InjectMocks
+ AuditDataService auditDataService = new AuditDataService();
+
+ @Mock
+ protected RequestsDbClient requestsDbClient;
+
+ AuditInventory auditInventory = new AuditInventory();
+
+ @Before
+ public void before() throws JsonProcessingException {
+ auditInventory.setCloudOwner("testCloudOwner");
+ auditInventory.setCloudRegion("testLcpCloudRegionId");
+ auditInventory.setHeatStackName("testVfModuleName1");
+ auditInventory.setVfModuleId("testVnfModuleId");
+ auditInventory.setTenantId("testTenantId");
+ auditInventory.setGenericVnfId("testVnfId1");
+ }
+
+ @Test
+ public void testWriteStackDataToRequestDb() throws Exception {
+ Mockito.doReturn(new ArrayList<RequestProcessingData>()).when(requestsDbClient)
+ .getRequestProcessingDataByGroupingIdAndNameAndTag(Mockito.any(), Mockito.any(), Mockito.any());
+ Mockito.doNothing().when(requestsDbClient).saveRequestProcessingData(Mockito.any());
+
+ AAIObjectAuditList auditList = new AAIObjectAuditList();
+ auditList.setHeatStackName("testHeatStackName");
+ AAIObjectAudit audit = new AAIObjectAudit();
+ Vserver vserver = new Vserver();
+ vserver.setVserverId("testVserverId");
+ audit.setAaiObject(vserver);
+ auditList.getAuditList().add(audit);
+
+ GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
+ String auditListString = objectMapper.getMapper().writeValueAsString(auditList);;
+
+ RequestProcessingData requestProcessingData = new RequestProcessingData();
+ requestProcessingData.setSoRequestId(auditInventory.getMsoRequestId());
+ requestProcessingData.setGroupingId(auditInventory.getVfModuleId());
+ requestProcessingData.setName(auditInventory.getHeatStackName());
+ requestProcessingData.setTag("AuditStackData");
+ requestProcessingData.setValue(auditListString);
+
+ auditDataService.writeStackDataToRequestDb(auditInventory, auditList);
+ Mockito.verify(requestsDbClient, Mockito.times(1)).saveRequestProcessingData(requestProcessingData);
+ }
+
+ @Test
+ public void testGetStackDataToRequestDb() throws Exception {
+ AAIObjectAuditList auditList = new AAIObjectAuditList();
+ auditList.setHeatStackName("testHeatStackName");
+ AAIObjectAudit audit = new AAIObjectAudit();
+ Vserver vserver = new Vserver();
+ vserver.setVserverId("testVserverId");
+ audit.setAaiObject(vserver);
+ auditList.getAuditList().add(audit);
+ GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
+ String auditListString = objectMapper.getMapper().writeValueAsString(audit);
+
+ List<RequestProcessingData> list = new ArrayList();
+ RequestProcessingData requestProcessingData = new RequestProcessingData();
+ requestProcessingData.setId(234321432);
+ requestProcessingData.setGroupingId("testVfModuleId");
+ requestProcessingData.setName("heatStackName");
+ requestProcessingData.setTag("AuditStackData");
+ requestProcessingData.setValue(auditListString);
+ list.add(requestProcessingData);
+
+ Mockito.doReturn(list).when(requestsDbClient).getRequestProcessingDataByGroupingIdAndNameAndTag(Mockito.any(),
+ Mockito.any(), Mockito.any());
+ auditDataService.getStackDataFromRequestDb(auditInventory);
+ Mockito.verify(requestsDbClient, Mockito.times(1)).getRequestProcessingDataByGroupingIdAndNameAndTag(
+ "testVnfModuleId", "testVfModuleName1", "AuditStackData");
+ }
+
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java
index f23486c45c..3432e4a8b6 100644
--- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -40,6 +40,7 @@ import org.onap.so.audit.beans.AuditInventory;
import org.onap.so.objects.audit.AAIObjectAuditList;
import org.springframework.core.env.Environment;
import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -48,6 +49,9 @@ public class AuditStackServiceDataTest extends AuditCreateStackService {
@InjectMocks
private AuditCreateStackService auditStackService = new AuditCreateStackService();
+ @InjectMocks
+ private AuditQueryStackService auditQueryStackService = new AuditQueryStackService();
+
@Mock
private HeatStackAudit heatStackAuditMock;
@@ -60,6 +64,9 @@ public class AuditStackServiceDataTest extends AuditCreateStackService {
@Mock
private ExternalTaskService mockExternalTaskService;
+ @Mock
+ private AuditDataService auditDataService;
+
private ObjectMapper objectMapper = new ObjectMapper();
private AuditInventory auditInventory = new AuditInventory();
@@ -112,6 +119,20 @@ public class AuditStackServiceDataTest extends AuditCreateStackService {
}
@Test
+ public void executeExternalTaskQueryAuditTest() throws JsonProcessingException {
+ doReturn(auditListOptSuccess).when(heatStackAuditMock).queryHeatStack("cloudOwner", "cloudRegion", "tenantId",
+ "stackName");
+ Mockito.doNothing().when(auditDataService).writeStackDataToRequestDb(Mockito.any(AuditInventory.class),
+ Mockito.any(AAIObjectAuditList.class));
+ auditQueryStackService.executeExternalTask(mockExternalTask, mockExternalTaskService);
+ ArgumentCaptor<Map> captor = ArgumentCaptor.forClass(Map.class);
+ ArgumentCaptor<ExternalTask> taskCaptor = ArgumentCaptor.forClass(ExternalTask.class);
+ Mockito.verify(mockExternalTaskService).complete(taskCaptor.capture(), captor.capture());
+ Mockito.verify(auditDataService).writeStackDataToRequestDb(Mockito.any(AuditInventory.class),
+ Mockito.any(AAIObjectAuditList.class));
+ }
+
+ @Test
public void execute_external_task_audit_first_failure_Test() {
doReturn(auditListOptFailure).when(heatStackAuditMock).auditHeatStack("cloudRegion", "cloudOwner", "tenantId",
"stackName");
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditVServerTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditVServerTest.java
index 2075557721..3d9a128318 100644
--- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditVServerTest.java
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditVServerTest.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -33,14 +33,19 @@ import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.aai.domain.yang.LInterface;
import org.onap.aai.domain.yang.LInterfaces;
+import org.onap.aai.domain.yang.Relationship;
+import org.onap.aai.domain.yang.RelationshipList;
+import org.onap.aai.domain.yang.VfModule;
import org.onap.aai.domain.yang.Vserver;
import org.onap.so.client.aai.AAIObjectPlurals;
import org.onap.so.client.aai.AAIObjectType;
@@ -48,6 +53,7 @@ import org.onap.so.client.aai.AAIResourcesClient;
import org.onap.so.client.aai.entities.AAIResultWrapper;
import org.onap.so.client.aai.entities.uri.AAIResourceUri;
import org.onap.so.client.aai.entities.uri.AAIUriFactory;
+import org.onap.so.objects.audit.AAIObjectAudit;
import org.onap.so.objects.audit.AAIObjectAuditList;
import org.skyscreamer.jsonassert.JSONAssert;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@@ -362,6 +368,69 @@ public class AuditVServerTest extends AuditVServer {
JSONAssert.assertEquals(expected, actualString, false);
}
+ @Test
+ public void testAuditVserversWithList() {
+
+ AAIObjectAuditList auditList = new AAIObjectAuditList();
+ AAIObjectAudit obj1 = new AAIObjectAudit();
+ Vserver vserver = new Vserver();
+ vserver.setVserverId("testVserverId");
+ obj1.setAaiObject(vserver);
+ obj1.setResourceURI(AAIUriFactory
+ .createResourceUri(AAIObjectType.VSERVER, cloudOwner, cloudRegion, tenantId, "testVserverId").build());
+ auditList.getAuditList().add(obj1);
+
+ doReturn(false).when(aaiResourcesMock).exists(AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, cloudOwner,
+ cloudRegion, tenantId, "testVserverId"));
+
+ auditNova.auditVservers(auditList);
+
+ Mockito.verify(aaiResourcesMock).exists(AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, cloudOwner,
+ cloudRegion, tenantId, "testVserverId"));
+
+ Assert.assertEquals(false, auditList.getAuditList().get(0).isDoesObjectExist());
+ }
+
+ @Test
+ public void testAuditVserversThroughRelationships() {
+
+ VfModule vfModule = new VfModule();
+ vfModule.setVfModuleId("id");
+
+ AAIResultWrapper wrapper = new AAIResultWrapper(vfModule);
+
+ doReturn(wrapper).when(aaiResourcesMock)
+ .get(AAIUriFactory.createResourceUri(AAIObjectPlurals.VF_MODULE, "genericVnfId")
+ .queryParam("vf-module-name", "vfModuleName"));
+
+ Optional<AAIObjectAuditList> auditList =
+ auditNova.auditVserversThroughRelationships("genericVnfId", "vfModuleName");
+
+ Assert.assertTrue(auditList.get().getAuditList().isEmpty());
+ }
+
+ @Test
+ public void testAuditVserversThroughRelationships_exists() throws IOException {
+
+ String vfModule = getJson("vfModule.json");
+
+ AAIResultWrapper wrapper = new AAIResultWrapper(vfModule);
+ AAIResultWrapper vserverWrapper = new AAIResultWrapper(new Vserver());
+
+ doReturn(wrapper).when(aaiResourcesMock)
+ .get(AAIUriFactory.createResourceUri(AAIObjectPlurals.VF_MODULE, "genericVnfId")
+ .queryParam("vf-module-name", "vfModuleName"));
+
+ doReturn(vserverWrapper).when(aaiResourcesMock).get(AAIUriFactory.createResourceUri(AAIObjectType.VSERVER,
+ "cloud-owner", "cloud-region-id", "tenant-id", "VUSCHGA1"));
+
+ Optional<AAIObjectAuditList> auditList =
+ auditNova.auditVserversThroughRelationships("genericVnfId", "vfModuleName");
+
+ Assert.assertFalse(auditList.get().getAuditList().isEmpty());
+ }
+
+
private String getJson(String filename) throws IOException {
return new String(Files.readAllBytes(Paths.get("src/test/resources/" + filename)));
}