8dc9d7fe5c93c356b2598cde968f1514eb44bdae
[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.objects.audit.AAIObjectAudit;
35 import org.onap.so.objects.audit.AAIObjectAuditList;
36 import com.fasterxml.jackson.core.JsonProcessingException;
37
38 public class CreateInventoryTaskTest {
39
40     @Mock
41     ExternalTask externalTask;
42
43     @Mock
44     CreateAAIInventory createAAIInventory;
45
46     @Mock
47     ExternalTaskService externalTaskService;
48
49     @InjectMocks
50     CreateInventoryTask inventoryTask;
51
52     @Before
53     public void setup() {
54         MockitoAnnotations.initMocks(this);
55     }
56
57     @Test
58     public void test_Runtime_Parse_Exception() {
59         doReturn(null).when(externalTask).getVariable("auditInventoryResult");
60         inventoryTask.executeExternalTask(externalTask, externalTaskService);
61         Mockito.verify(externalTaskService, times(1)).handleBpmnError(externalTask, "AAIInventoryFailure");
62     }
63
64     @Test
65     public void testExecuteExternalTask_InventoryException() throws InventoryException, JsonProcessingException {
66         AAIObjectAuditList object = new AAIObjectAuditList();
67         AAIObjectAudit e = new AAIObjectAudit();
68         e.setDoesObjectExist(true);
69         object.getAuditList().add(e);
70         GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
71         doReturn(objectMapper.getMapper().writeValueAsString(e)).when(externalTask).getVariable("auditInventoryResult");
72         Mockito.doThrow(InventoryException.class).when(createAAIInventory).createInventory(Mockito.any());
73         inventoryTask.executeExternalTask(externalTask, externalTaskService);
74         Mockito.verify(externalTaskService, times(1)).handleBpmnError(externalTask, "AAIInventoryFailure");
75     }
76 }