Springboot 2.0 upgrade
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / workflow / tasks / FlowCompletionTasksTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
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.bpmn.infrastructure.workflow.tasks;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.Matchers.any;
25 import static org.mockito.Mockito.doNothing;
26 import static org.mockito.Mockito.times;
27 import static org.mockito.Mockito.verify;
28 import static org.mockito.Mockito.when;
29
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.mockito.InjectMocks;
33 import org.onap.so.bpmn.BaseTaskTest;
34 import org.onap.so.bpmn.core.WorkflowException;
35 import org.onap.so.db.request.beans.InfraActiveRequests;
36 import org.springframework.beans.factory.annotation.Autowired;
37
38 public class FlowCompletionTasksTest extends BaseTaskTest {
39
40         @InjectMocks
41         protected FlowCompletionTasks flowCompletionTasks = new FlowCompletionTasks();  
42
43         @Before
44         public void before() {
45                 setRequestContext();
46         }
47         
48         @Test
49         public void updateRequestDbStatusComplete_Test() throws Exception{
50                 InfraActiveRequests mockedRequest = new InfraActiveRequests();
51                 when(requestsDbClient.getInfraActiveRequestbyRequestId(any(String.class))).thenReturn(mockedRequest);
52                 doNothing().when(requestsDbClient).updateInfraActiveRequests(any(InfraActiveRequests.class));
53                 flowCompletionTasks.updateRequestDbStatus(execution);           
54                 verify(requestsDbClient, times(1)).updateInfraActiveRequests(any(InfraActiveRequests.class));
55                 assertEquals(mockedRequest.getRequestStatus(), "COMPLETE");
56         }
57         
58         @Test
59         public void updateRequestDbStatusFailed_Test() throws Exception{
60                 WorkflowException workflowException = new WorkflowException("testProcessKey", 7000, "Error");
61                 execution.setVariable("WorkflowException", workflowException);
62                 InfraActiveRequests mockedRequest = new InfraActiveRequests();
63                 when(requestsDbClient.getInfraActiveRequestbyRequestId(any(String.class))).thenReturn(mockedRequest);
64                 doNothing().when(requestsDbClient).updateInfraActiveRequests(any(InfraActiveRequests.class));
65                 flowCompletionTasks.updateRequestDbStatus(execution);           
66                 verify(requestsDbClient, times(1)).updateInfraActiveRequests(any(InfraActiveRequests.class));
67                 assertEquals(mockedRequest.getRequestStatus(), "FAILED");
68         }
69 }