Springboot 2.0 upgrade
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / sdno / tasks / SDNOHealthCheckTasksTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 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.sdno.tasks;
22
23 import static org.mockito.ArgumentMatchers.any;
24 import static org.mockito.Matchers.eq;
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 static org.mockito.Mockito.when;
30
31 import org.camunda.bpm.engine.delegate.BpmnError;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.mockito.InjectMocks;
36 import org.mockito.Mock;
37 import org.mockito.junit.MockitoJUnitRunner;
38 import org.onap.so.bpmn.common.BuildingBlockExecution;
39 import org.onap.so.bpmn.common.data.TestDataSetup;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
41 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
42 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
43 import org.onap.so.client.exception.BBObjectNotFoundException;
44 import org.onap.so.client.exception.ExceptionBuilder;
45 import org.onap.so.client.orchestration.SDNOHealthCheckResources;
46
47
48 @RunWith(MockitoJUnitRunner.Silent.class)
49 public class SDNOHealthCheckTasksTest extends TestDataSetup {
50         
51         @InjectMocks
52         protected SDNOHealthCheckTasks sdnoHealthCheckTasks = new SDNOHealthCheckTasks();
53         
54         @Mock
55         SDNOHealthCheckResources MOCK_sdnoHealthCheckResources;
56         
57         
58         @Mock
59         private ExceptionBuilder exceptionUtil;
60         
61         @Mock
62         private ExtractPojosForBB extractPojosForBB;
63         
64         
65         private RequestContext requestContext;
66         private GenericVnf genericVnf;
67         
68         @Before
69         public void before() throws BBObjectNotFoundException {
70                 genericVnf = setGenericVnf();
71                 requestContext = setRequestContext();
72                 when(extractPojosForBB.extractByKey(any(),any(), any())).thenReturn(genericVnf);
73                 
74         }
75
76         @Test
77         public void sdnoHealthCheckTest() throws Exception {
78                 doReturn(true).when(MOCK_sdnoHealthCheckResources).healthCheck(genericVnf,  requestContext);
79                 sdnoHealthCheckTasks.sdnoHealthCheck(execution);
80                 verify(MOCK_sdnoHealthCheckResources, times(1)).healthCheck(genericVnf, requestContext);
81         }
82         
83         @Test
84         public void sdnoHealthCheckNoResponseTest() throws Exception {
85         
86                 doReturn(false).when(MOCK_sdnoHealthCheckResources).healthCheck(genericVnf, requestContext);
87                 try {
88                         sdnoHealthCheckTasks.sdnoHealthCheck(execution);
89                 } catch (Exception e) {
90                         verify(MOCK_sdnoHealthCheckResources, times(1)).healthCheck(genericVnf, requestContext);
91                         verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
92                 }
93                 
94         }
95         
96         @Test
97         public void sdnoHealthCheckExceptionTest() throws Exception {
98                 doThrow(new Exception("Unknown Error")).when(MOCK_sdnoHealthCheckResources).healthCheck(genericVnf, requestContext);
99                 doThrow(new BpmnError("Unknown Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
100                 try {
101                         sdnoHealthCheckTasks.sdnoHealthCheck(execution);
102                 } catch (Exception e) {
103                         verify(MOCK_sdnoHealthCheckResources, times(1)).healthCheck(genericVnf, requestContext);
104                         verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
105                 }
106
107         }
108 }