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.appc.orchestrator.client;
23 import static org.hamcrest.CoreMatchers.any;
24 import static org.mockito.Mockito.doReturn;
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.appc.orchestrator.client.ApplicationControllerCallback;
34 import org.onap.so.adapters.appc.orchestrator.client.ApplicationControllerSupport;
35 import org.onap.appc.client.lcm.model.Status;
36 import org.onap.appc.client.lcm.exceptions.AppcClientException;
37 import org.onap.appc.client.lcm.model.ResumeTrafficOutput;
39 public class ApplicationControllerCallbackTest {
42 ApplicationControllerCallback appcTaskCallback;
45 ApplicationControllerSupport applicationControllerSupport;
48 ExternalTask mockExternalTask;
51 ExternalTaskService mockExternalTaskService;
55 MockitoAnnotations.initMocks(this);
56 appcTaskCallback = new ApplicationControllerCallback(mockExternalTask, mockExternalTaskService,
57 applicationControllerSupport);
61 public void onResponse_appcCallback_success_Test() throws Exception {
62 Status status = new Status();
64 ResumeTrafficOutput response = new ResumeTrafficOutput();
65 response.setStatus(status);
66 doReturn(status).when(applicationControllerSupport).getStatusFromGenericResponse(response);
67 doReturn(true).when(applicationControllerSupport).getFinalityOf(status);
68 doReturn(StatusCategory.NORMAL).when(applicationControllerSupport).getCategoryOf(status);
69 appcTaskCallback.onResponse(response);
70 Mockito.verify(mockExternalTaskService).complete(mockExternalTask);
74 public void onResponse_appcCallback_intermediateResponse_Test() throws Exception {
75 Status status = new Status();
77 ResumeTrafficOutput response = new ResumeTrafficOutput();
78 response.setStatus(status);
79 doReturn(status).when(applicationControllerSupport).getStatusFromGenericResponse(response);
80 appcTaskCallback.onResponse(response);
81 Mockito.verifyZeroInteractions(mockExternalTaskService);
85 public void onResponse_appcCallback_failure_Test() throws Exception {
86 String testFailure = "test failure";
87 Status status = new Status();
89 status.setMessage(testFailure);
90 ResumeTrafficOutput response = new ResumeTrafficOutput();
91 response.setStatus(status);
92 doReturn(status).when(applicationControllerSupport).getStatusFromGenericResponse(response);
93 doReturn(true).when(applicationControllerSupport).getFinalityOf(status);
94 doReturn(StatusCategory.ERROR).when(applicationControllerSupport).getCategoryOf(status);
95 appcTaskCallback.onResponse(response);
96 Mockito.verify(mockExternalTaskService).handleBpmnError(mockExternalTask, "MSOWorkflowException", testFailure);
100 public void onException_appcCallback_failure_Test() throws Exception {
101 String testFailure = "test failure";
102 AppcClientException appcException = new AppcClientException(testFailure);
103 Status status = new Status();
105 String exceptionMessage = "Exception on APPC request: " + testFailure;
106 status.setMessage(exceptionMessage);
107 doReturn(status).when(applicationControllerSupport).buildStatusFromAppcException(appcException);
108 doReturn(StatusCategory.ERROR).when(applicationControllerSupport).getCategoryOf(status);
109 appcTaskCallback.onException(appcException);
110 Mockito.verify(mockExternalTaskService).handleBpmnError(mockExternalTask, "MSOWorkflowException",