2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017 - 2018 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.bpmn.infrastructure.aai;
 
  23 import static org.mockito.ArgumentMatchers.isA;
 
  24 import static org.mockito.Mockito.doNothing;
 
  25 import static org.mockito.Mockito.doReturn;
 
  26 import static org.mockito.Mockito.doThrow;
 
  27 import static org.mockito.Mockito.times;
 
  28 import static org.mockito.Mockito.verify;
 
  29 import org.camunda.bpm.engine.delegate.BpmnError;
 
  30 import org.camunda.bpm.engine.delegate.DelegateExecution;
 
  31 import org.junit.Before;
 
  32 import org.junit.Rule;
 
  33 import org.junit.Test;
 
  34 import org.junit.rules.ExpectedException;
 
  35 import org.mockito.Mock;
 
  36 import org.mockito.MockitoAnnotations;
 
  37 import org.onap.aaiclient.client.aai.AAIResourcesClient;
 
  38 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
 
  40 public class AAIDeleteServiceInstanceTest {
 
  41     private AAIDeleteServiceInstance aaiDeleteServiceInstance;
 
  43     private DelegateExecution execution;
 
  46     private AAIResourcesClient aaiResourcesClient;
 
  49     public ExpectedException expectedException = ExpectedException.none();
 
  53     public void before() {
 
  54         MockitoAnnotations.initMocks(this);
 
  56         aaiDeleteServiceInstance = new AAIDeleteServiceInstance();
 
  57         aaiDeleteServiceInstance.setAaiClient(aaiResourcesClient);
 
  61     public void executeTest() throws Exception {
 
  62         doReturn("serviceInstanceId").when(execution).getVariable("serviceInstanceId");
 
  63         doNothing().when(aaiResourcesClient).delete(isA(AAIResourceUri.class));
 
  64         doNothing().when(execution).setVariable(isA(String.class), isA(Boolean.class));
 
  66         aaiDeleteServiceInstance.execute(execution);
 
  68         verify(execution, times(1)).getVariable("serviceInstanceId");
 
  69         verify(aaiResourcesClient, times(1)).delete(isA(AAIResourceUri.class));
 
  70         verify(execution, times(1)).setVariable("GENDS_SuccessIndicator", true);
 
  74     public void executeExceptionTest() throws Exception {
 
  75         expectedException.expect(BpmnError.class);
 
  77         doReturn("testProcessKey").when(execution).getVariable("testProcessKey");
 
  78         doReturn("serviceInstanceId").when(execution).getVariable("serviceInstanceId");
 
  79         doThrow(RuntimeException.class).when(aaiResourcesClient).delete(isA(AAIResourceUri.class));
 
  81         aaiDeleteServiceInstance.execute(execution);