0c53200a1005c6cc6415f16072a21490365dcb3b
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.so.adapters.appc.orchestrator.client;
22
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;
35
36 public class ApplicationControllerCallbackTest {
37
38     @InjectMocks
39     ApplicationControllerCallback appcTaskCallback;
40
41     @Mock
42     ApplicationControllerSupport applicationControllerSupport;
43
44     @Mock
45     ExternalTask mockExternalTask;
46
47     @Mock
48     ExternalTaskService mockExternalTaskService;
49
50     @Before
51     public void setup() {
52         MockitoAnnotations.initMocks(this);
53         appcTaskCallback = new ApplicationControllerCallback(mockExternalTask, mockExternalTaskService,
54                 applicationControllerSupport);
55     }
56
57     @Test
58     public void onResponse_appcCallback_success_Test() throws Exception {
59         Status status = new Status();
60         status.setCode(400);
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);
68     }
69
70     @Test
71     public void onResponse_appcCallback_intermediateResponse_Test() throws Exception {
72         Status status = new Status();
73         status.setCode(100);
74         ResumeTrafficOutput response = new ResumeTrafficOutput();
75         response.setStatus(status);
76         doReturn(status).when(applicationControllerSupport).getStatusFromGenericResponse(response);
77         appcTaskCallback.onResponse(response);
78         Mockito.verifyZeroInteractions(mockExternalTaskService);
79     }
80
81     @Test
82     public void onResponse_appcCallback_failure_Test() throws Exception {
83         String testFailure = "test failure";
84         Status status = new Status();
85         status.setCode(200);
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);
94     }
95
96     @Test
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();
101         status.setCode(200);
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",
108                 exceptionMessage);
109     }
110 }