2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (c) 2020 Nokia
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 package org.onap.so.bpmn.infrastructure.audit;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.mockito.ArgumentMatchers.any;
27 import static org.mockito.ArgumentMatchers.eq;
28 import static org.mockito.Mockito.times;
29 import static org.mockito.Mockito.verify;
30 import static org.mockito.Mockito.when;
31 import org.junit.Before;
32 import org.junit.Rule;
33 import org.junit.Test;
34 import org.junit.rules.ExpectedException;
35 import org.mockito.InjectMocks;
36 import org.onap.aai.domain.yang.Vserver;
37 import org.onap.so.audit.beans.AuditInventory;
38 import org.onap.so.bpmn.BaseTaskTest;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
42 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
43 import org.onap.so.client.exception.BBObjectNotFoundException;
44 import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider;
45 import org.onap.so.objects.audit.AAIObjectAudit;
46 import org.onap.so.objects.audit.AAIObjectAuditList;
47 import com.fasterxml.jackson.core.JsonProcessingException;
49 public class AuditTasksTest extends BaseTaskTest {
52 private AuditTasks auditTasks = new AuditTasks();
53 private ServiceInstance serviceInstance;
54 private GenericVnf genericVnf;
55 private VfModule vfModule;
59 public final ExpectedException exception = ExpectedException.none();
62 public void before() throws BBObjectNotFoundException, JsonProcessingException {
63 serviceInstance = setServiceInstance();
64 genericVnf = setGenericVnf();
65 vfModule = setVfModule();
66 buildRequestContext();
69 when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(genericVnf);
70 when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule);
71 when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.SERVICE_INSTANCE_ID))).thenReturn(serviceInstance);
72 execution.setVariable("auditQuerySuccess", true);
73 AAIObjectAuditList auditList = new AAIObjectAuditList();
74 auditList.setHeatStackName("testHeatStackName");
75 AAIObjectAudit audit = new AAIObjectAudit();
76 Vserver vserver = new Vserver();
77 vserver.setVserverId("testVserverId");
78 audit.setAaiObject(vserver);
79 auditList.getAuditList().add(audit);
80 GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
81 String auditListString = objectMapper.getMapper().writeValueAsString(audit);
82 execution.setVariable("auditList", auditListString);
86 public void setupAuditVariableTest() throws Exception {
87 AuditInventory expectedAuditInventory = new AuditInventory();
88 expectedAuditInventory.setCloudOwner("testCloudOwner");
89 expectedAuditInventory.setCloudRegion("testLcpCloudRegionId");
90 expectedAuditInventory.setHeatStackName("testVfModuleName1");
91 expectedAuditInventory.setVfModuleId("testVfModuleId1");
92 expectedAuditInventory.setTenantId("testTenantId");
93 expectedAuditInventory.setGenericVnfId("testVnfId1");
94 expectedAuditInventory.setMsoRequestId("fb06f44c-c797-4f38-9b17-b4b975344600");
95 auditTasks.setupAuditVariable(execution);
96 // assertThat((AuditInventory) execution.getVariable("auditInventory"), sameBeanAs(expectedAuditInventory));
100 public void auditIsNeededTest() {
102 when(env.getProperty("mso.infra.auditInventory")).thenReturn("true");
104 auditTasks.isAuditNeeded(execution);
106 assertNotNull(execution.getVariable("auditInventoryNeeded"));
107 assertEquals(execution.getVariable("auditInventoryNeeded"), true);
111 public void auditIsNotNeededTest() {
113 when(env.getProperty("mso.infra.auditInventory")).thenReturn("false");
115 auditTasks.isAuditNeeded(execution);
117 assertNotNull(execution.getVariable("auditInventoryNeeded"));
118 assertEquals(execution.getVariable("auditInventoryNeeded"), false);
122 public void deleteAuditIsNeededTest() {
124 when(env.getProperty("mso.infra.deleteAuditInventory")).thenReturn("true");
126 auditTasks.isDeleteAuditNeeded(execution);
128 assertNotNull(execution.getVariable("auditInventoryNeeded"));
129 assertEquals(execution.getVariable("auditInventoryNeeded"), true);
133 public void deleteAuditIsNotNeededTest() {
135 when(env.getProperty("mso.infra.deleteAuditInventory")).thenReturn("false");
137 auditTasks.isDeleteAuditNeeded(execution);
139 assertNotNull(execution.getVariable("auditInventoryNeeded"));
140 assertEquals(execution.getVariable("auditInventoryNeeded"), false);
144 public void setupAuditVariable_shouldThrowWorkflowExceptionIfFails() {
146 execution.setVariable("gBBInput", null);
148 auditTasks.setupAuditVariable(execution);
150 verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(eq(execution), eq(7000), any(Exception.class));