1 package org.onap.so.adapters.inventory.create;
3 import static org.mockito.Mockito.doReturn;
4 import static org.mockito.Mockito.times;
5 import org.camunda.bpm.client.task.ExternalTask;
6 import org.camunda.bpm.client.task.ExternalTaskService;
7 import org.junit.Before;
9 import org.mockito.InjectMocks;
10 import org.mockito.Mock;
11 import org.mockito.Mockito;
12 import org.mockito.MockitoAnnotations;
13 import org.onap.so.adapters.audit.AAIObjectAudit;
14 import org.onap.so.adapters.audit.AAIObjectAuditList;
15 import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider;
16 import com.fasterxml.jackson.core.JsonProcessingException;
18 public class CreateInventoryTaskTest {
21 ExternalTask externalTask;
24 CreateAAIInventory createAAIInventory;
27 ExternalTaskService externalTaskService;
30 CreateInventoryTask inventoryTask;
34 MockitoAnnotations.initMocks(this);
38 public void test_Runtime_Parse_Exception() {
39 doReturn(null).when(externalTask).getVariable("auditInventoryResult");
40 inventoryTask.executeExternalTask(externalTask, externalTaskService);
41 Mockito.verify(externalTaskService, times(1)).handleBpmnError(externalTask, "AAIInventoryFailure");
45 public void testExecuteExternalTask_InventoryException() throws InventoryException, JsonProcessingException {
46 AAIObjectAuditList object = new AAIObjectAuditList();
47 AAIObjectAudit e = new AAIObjectAudit();
48 e.setDoesObjectExist(true);
49 object.getAuditList().add(e);
50 GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
51 doReturn(objectMapper.getMapper().writeValueAsString(e)).when(externalTask).getVariable("auditInventoryResult");
52 Mockito.doThrow(InventoryException.class).when(createAAIInventory).createInventory(Mockito.any());
53 inventoryTask.executeExternalTask(externalTask, externalTaskService);
54 Mockito.verify(externalTaskService, times(1)).handleBpmnError(externalTask, "AAIInventoryFailure");