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.mockito.Mockito.doReturn;
24 import org.camunda.bpm.client.task.ExternalTask;
25 import org.camunda.bpm.client.task.ExternalTaskService;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.mockito.InjectMocks;
29 import org.mockito.Mock;
30 import org.mockito.Mockito;
31 import org.mockito.MockitoAnnotations;
32 import org.onap.appc.client.lcm.model.Status;
33 import org.onap.appc.client.lcm.exceptions.AppcClientException;
34 import org.onap.appc.client.lcm.model.ResumeTrafficOutput;
36 public class ApplicationControllerCallbackTest {
39 ApplicationControllerCallback appcTaskCallback;
42 ApplicationControllerSupport applicationControllerSupport;
45 ExternalTask mockExternalTask;
48 ExternalTaskService mockExternalTaskService;
52 MockitoAnnotations.initMocks(this);
53 appcTaskCallback = new ApplicationControllerCallback(mockExternalTask, mockExternalTaskService,
54 applicationControllerSupport);
58 public void onResponse_appcCallback_success_Test() throws Exception {
59 Status status = new Status();
61 ResumeTrafficOutput response = new ResumeTrafficOutput();
62 response.setStatus(status);
63 doReturn(status).when(applicationControllerSupport).getStatusFromGenericResponse(response);
64 doReturn(true).when(applicationControllerSupport).getFinalityOf(status);
65 doReturn(StatusCategory.NORMAL).when(applicationControllerSupport).getCategoryOf(status);
66 appcTaskCallback.onResponse(response);
67 Mockito.verify(mockExternalTaskService).complete(mockExternalTask);
71 public void onResponse_appcCallback_intermediateResponse_Test() throws Exception {
72 Status status = new Status();
74 ResumeTrafficOutput response = new ResumeTrafficOutput();
75 response.setStatus(status);
76 doReturn(status).when(applicationControllerSupport).getStatusFromGenericResponse(response);
77 appcTaskCallback.onResponse(response);
78 Mockito.verifyZeroInteractions(mockExternalTaskService);
82 public void onResponse_appcCallback_failure_Test() throws Exception {
83 String testFailure = "test failure";
84 Status status = new Status();
86 status.setMessage(testFailure);
87 ResumeTrafficOutput response = new ResumeTrafficOutput();
88 response.setStatus(status);
89 doReturn(status).when(applicationControllerSupport).getStatusFromGenericResponse(response);
90 doReturn(true).when(applicationControllerSupport).getFinalityOf(status);
91 doReturn(StatusCategory.ERROR).when(applicationControllerSupport).getCategoryOf(status);
92 appcTaskCallback.onResponse(response);
93 Mockito.verify(mockExternalTaskService).handleBpmnError(mockExternalTask, "MSOWorkflowException", testFailure);
97 public void onException_appcCallback_failure_Test() throws Exception {
98 String testFailure = "test failure";
99 AppcClientException appcException = new AppcClientException(testFailure);
100 Status status = new Status();
102 String exceptionMessage = "Exception on APPC request: " + testFailure;
103 status.setMessage(exceptionMessage);
104 doReturn(status).when(applicationControllerSupport).buildStatusFromAppcException(appcException);
105 doReturn(StatusCategory.ERROR).when(applicationControllerSupport).getCategoryOf(status);
106 appcTaskCallback.onException(appcException);
107 Mockito.verify(mockExternalTaskService).handleBpmnError(mockExternalTask, "MSOWorkflowException",