c4fa9ee2c550e1854d5ceee36eab94b2ac1c413f
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 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
21 package org.onap.so.adapters.inventory.create;
22
23 import static org.mockito.Mockito.doReturn;
24 import static org.mockito.Mockito.times;
25 import org.camunda.bpm.client.task.ExternalTask;
26 import org.camunda.bpm.client.task.ExternalTaskService;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.mockito.InjectMocks;
30 import org.mockito.Mock;
31 import org.mockito.Mockito;
32 import org.mockito.MockitoAnnotations;
33 import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider;
34 import org.onap.so.externaltasks.logging.AuditMDCSetup;
35 import org.onap.so.objects.audit.AAIObjectAudit;
36 import org.onap.so.objects.audit.AAIObjectAuditList;
37 import com.fasterxml.jackson.core.JsonProcessingException;
38
39 public class CreateInventoryTaskTest {
40
41     @Mock
42     ExternalTask externalTask;
43
44     @Mock
45     CreateAAIInventory createAAIInventory;
46
47     @Mock
48     ExternalTaskService externalTaskService;
49
50     @Mock
51     private AuditMDCSetup mdcSetup;
52
53     @InjectMocks
54     CreateInventoryTask inventoryTask;
55
56     @Before
57     public void setup() {
58         MockitoAnnotations.initMocks(this);
59     }
60
61     @Test
62     public void test_Runtime_Parse_Exception() {
63         doReturn(null).when(externalTask).getVariable("auditInventoryResult");
64         inventoryTask.executeExternalTask(externalTask, externalTaskService);
65         Mockito.verify(externalTaskService, times(1)).handleBpmnError(externalTask, "AAIInventoryFailure");
66     }
67
68     @Test
69     public void testExecuteExternalTask_InventoryException() throws InventoryException, JsonProcessingException {
70         AAIObjectAuditList object = new AAIObjectAuditList();
71         AAIObjectAudit e = new AAIObjectAudit();
72         e.setDoesObjectExist(true);
73         object.getAuditList().add(e);
74         GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
75         doReturn(objectMapper.getMapper().writeValueAsString(e)).when(externalTask).getVariable("auditInventoryResult");
76         Mockito.doThrow(InventoryException.class).when(createAAIInventory).createInventory(Mockito.any());
77         inventoryTask.executeExternalTask(externalTask, externalTaskService);
78         Mockito.verify(externalTaskService, times(1)).handleBpmnError(externalTask, "AAIInventoryFailure");
79     }
80 }