2 * ============LICENSE_START=======================================================
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
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.bpmn.sdno.tasks;
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;
47 @RunWith(MockitoJUnitRunner.Silent.class)
48 public class SDNOHealthCheckTasksTest extends TestDataSetup {
51 protected SDNOHealthCheckTasks sdnoHealthCheckTasks = new SDNOHealthCheckTasks();
54 SDNOHealthCheckResources MOCK_sdnoHealthCheckResources;
58 private ExceptionBuilder exceptionUtil;
61 private ExtractPojosForBB extractPojosForBB;
64 private RequestContext requestContext;
65 private GenericVnf genericVnf;
68 public void before() throws BBObjectNotFoundException {
69 genericVnf = setGenericVnf();
70 requestContext = setRequestContext();
71 when(extractPojosForBB.extractByKey(any(), any())).thenReturn(genericVnf);
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);
83 public void sdnoHealthCheckNoResponseTest() throws Exception {
85 doReturn(false).when(MOCK_sdnoHealthCheckResources).healthCheck(genericVnf, requestContext);
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),
97 public void sdnoHealthCheckExceptionTest() throws Exception {
98 doThrow(new Exception("Unknown Error")).when(MOCK_sdnoHealthCheckResources).healthCheck(genericVnf,
100 doThrow(new BpmnError("Unknown Error")).when(exceptionUtil)
101 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
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),