cee06caa75b305d987152cc9cd32bb49c91dfa0b
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / audit / AuditTasksTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.so.bpmn.infrastructure.audit;
21
22 import static com.shazam.shazamcrest.MatcherAssert.assertThat;
23 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
24 import static org.junit.Assert.assertEquals;
25 import static org.mockito.ArgumentMatchers.any;
26 import static org.mockito.Mockito.when;
27 import java.util.ArrayList;
28 import java.util.List;
29 import org.junit.Assert;
30 import org.junit.Before;
31 import org.junit.Rule;
32 import org.junit.Test;
33 import org.junit.rules.ExpectedException;
34 import org.mockito.ArgumentMatchers;
35 import org.mockito.InjectMocks;
36 import org.mockito.Mockito;
37 import org.onap.aai.domain.yang.Vserver;
38 import org.onap.so.audit.beans.AuditInventory;
39 import org.onap.so.bpmn.BaseTaskTest;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
43 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
44 import org.onap.so.client.exception.BBObjectNotFoundException;
45 import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider;
46 import org.onap.so.db.request.beans.RequestProcessingData;
47 import org.onap.so.objects.audit.AAIObjectAudit;
48 import org.onap.so.objects.audit.AAIObjectAuditList;
49 import com.fasterxml.jackson.core.JsonProcessingException;
50
51 public class AuditTasksTest extends BaseTaskTest {
52
53     @InjectMocks
54     private AuditTasks auditTasks = new AuditTasks();
55     private ServiceInstance serviceInstance;
56     private GenericVnf genericVnf;
57     private VfModule vfModule;
58
59
60     @Rule
61     public final ExpectedException exception = ExpectedException.none();
62
63     @Before
64     public void before() throws BBObjectNotFoundException, JsonProcessingException {
65         serviceInstance = setServiceInstance();
66         genericVnf = setGenericVnf();
67         vfModule = setVfModule();
68         buildRequestContext();
69         setCloudRegion();
70         setRequestContext();
71         when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID)))
72                 .thenReturn(genericVnf);
73         when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule);
74         when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID)))
75                 .thenReturn(serviceInstance);
76         execution.setVariable("auditQuerySuccess", true);
77         AAIObjectAuditList auditList = new AAIObjectAuditList();
78         auditList.setHeatStackName("testHeatStackName");
79         AAIObjectAudit audit = new AAIObjectAudit();
80         Vserver vserver = new Vserver();
81         vserver.setVserverId("testVserverId");
82         audit.setAaiObject(vserver);
83         auditList.getAuditList().add(audit);
84         GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
85         String auditListString = objectMapper.getMapper().writeValueAsString(audit);
86         execution.setVariable("auditList", auditListString);
87     }
88
89     @Test
90     public void setupAuditVariableTest() throws Exception {
91         AuditInventory expectedAuditInventory = new AuditInventory();
92         expectedAuditInventory.setCloudOwner("testCloudOwner");
93         expectedAuditInventory.setCloudRegion("testLcpCloudRegionId");
94         expectedAuditInventory.setHeatStackName("testVfModuleName1");
95         expectedAuditInventory.setVfModuleId("testVfModuleId1");
96         expectedAuditInventory.setTenantId("testTenantId");
97         expectedAuditInventory.setGenericVnfId("testVnfId1");
98         expectedAuditInventory.setMsoRequestId("fb06f44c-c797-4f38-9b17-b4b975344600");
99         auditTasks.setupAuditVariable(execution);
100         assertThat((AuditInventory) execution.getVariable("auditInventory"), sameBeanAs(expectedAuditInventory));
101     }
102
103 }