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.inventory.create;
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;
38 public class CreateInventoryTaskTest {
41 ExternalTask externalTask;
44 CreateAAIInventory createAAIInventory;
47 ExternalTaskService externalTaskService;
50 CreateInventoryTask inventoryTask;
54 MockitoAnnotations.initMocks(this);
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");
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");