2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.adapters.tasks.inventory;
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.adapters.tasks.inventory.CreateAAIInventory;
34 import org.onap.so.adapters.tasks.inventory.CreateInventoryTask;
35 import org.onap.so.adapters.tasks.inventory.InventoryException;
36 import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider;
37 import org.onap.so.logging.tasks.AuditMDCSetup;
38 import org.onap.so.objects.audit.AAIObjectAudit;
39 import org.onap.so.objects.audit.AAIObjectAuditList;
40 import com.fasterxml.jackson.core.JsonProcessingException;
42 public class CreateInventoryTaskTest {
45 ExternalTask externalTask;
48 CreateAAIInventory createAAIInventory;
51 ExternalTaskService externalTaskService;
54 CreateInventoryTask inventoryTask;
57 private AuditMDCSetup mdcSetup;
61 MockitoAnnotations.initMocks(this);
65 public void test_Runtime_Parse_Exception() {
66 doReturn(null).when(externalTask).getVariable("auditInventoryResult");
67 inventoryTask.executeExternalTask(externalTask, externalTaskService);
68 Mockito.verify(externalTaskService, times(1)).handleBpmnError(externalTask, "AAIInventoryFailure");
72 public void testExecuteExternalTask_InventoryException() throws InventoryException, JsonProcessingException {
73 AAIObjectAuditList object = new AAIObjectAuditList();
74 AAIObjectAudit e = new AAIObjectAudit();
75 e.setDoesObjectExist(true);
76 object.getAuditList().add(e);
77 GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
78 doReturn(objectMapper.getMapper().writeValueAsString(e)).when(externalTask).getVariable("auditInventoryResult");
79 Mockito.doThrow(InventoryException.class).when(createAAIInventory).createInventory(Mockito.any());
80 inventoryTask.executeExternalTask(externalTask, externalTaskService);
81 Mockito.verify(externalTaskService, times(1)).handleBpmnError(externalTask, "AAIInventoryFailure");