Replaced all tabs with spaces in java and pom.xml
[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.ArgumentMatchers.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 import org.camunda.bpm.engine.delegate.BpmnError;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.InjectMocks;
35 import org.mockito.Mock;
36 import org.mockito.junit.MockitoJUnitRunner;
37 import org.onap.so.bpmn.common.BuildingBlockExecution;
38 import org.onap.so.bpmn.common.data.TestDataSetup;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
40 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
41 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
42 import org.onap.so.client.exception.BBObjectNotFoundException;
43 import org.onap.so.client.exception.ExceptionBuilder;
44 import org.onap.so.client.orchestration.SDNOHealthCheckResources;
45
46
47 @RunWith(MockitoJUnitRunner.Silent.class)
48 public class SDNOHealthCheckTasksTest extends TestDataSetup {
49
50     @InjectMocks
51     protected SDNOHealthCheckTasks sdnoHealthCheckTasks = new SDNOHealthCheckTasks();
52
53     @Mock
54     SDNOHealthCheckResources MOCK_sdnoHealthCheckResources;
55
56
57     @Mock
58     private ExceptionBuilder exceptionUtil;
59
60     @Mock
61     private ExtractPojosForBB extractPojosForBB;
62
63
64     private RequestContext requestContext;
65     private GenericVnf genericVnf;
66
67     @Before
68     public void before() throws BBObjectNotFoundException {
69         genericVnf = setGenericVnf();
70         requestContext = setRequestContext();
71         when(extractPojosForBB.extractByKey(any(), any())).thenReturn(genericVnf);
72
73     }
74
75     @Test
76     public void sdnoHealthCheckTest() throws Exception {
77         doReturn(true).when(MOCK_sdnoHealthCheckResources).healthCheck(genericVnf, requestContext);
78         sdnoHealthCheckTasks.sdnoHealthCheck(execution);
79         verify(MOCK_sdnoHealthCheckResources, times(1)).healthCheck(genericVnf, requestContext);
80     }
81
82     @Test
83     public void sdnoHealthCheckNoResponseTest() throws Exception {
84
85         doReturn(false).when(MOCK_sdnoHealthCheckResources).healthCheck(genericVnf, requestContext);
86         try {
87             sdnoHealthCheckTasks.sdnoHealthCheck(execution);
88         } catch (Exception e) {
89             verify(MOCK_sdnoHealthCheckResources, times(1)).healthCheck(genericVnf, requestContext);
90             verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000),
91                     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,
99                 requestContext);
100         doThrow(new BpmnError("Unknown Error")).when(exceptionUtil)
101                 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
102         try {
103             sdnoHealthCheckTasks.sdnoHealthCheck(execution);
104         } catch (Exception e) {
105             verify(MOCK_sdnoHealthCheckResources, times(1)).healthCheck(genericVnf, requestContext);
106             verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000),
107                     any(String.class));
108         }
109
110     }
111 }