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.Matchers.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;
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.runners.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;
48 @RunWith(MockitoJUnitRunner.class)
49 public class SDNOHealthCheckTasksTest extends TestDataSetup {
52 protected SDNOHealthCheckTasks sdnoHealthCheckTasks = new SDNOHealthCheckTasks();
55 SDNOHealthCheckResources MOCK_sdnoHealthCheckResources;
59 private ExceptionBuilder exceptionUtil;
62 private ExtractPojosForBB extractPojosForBB;
65 private RequestContext requestContext;
66 private GenericVnf genericVnf;
69 public void before() throws BBObjectNotFoundException {
70 genericVnf = setGenericVnf();
71 requestContext = setRequestContext();
72 when(extractPojosForBB.extractByKey(any(),any(), any())).thenReturn(genericVnf);
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);
84 public void sdnoHealthCheckNoResponseTest() throws Exception {
86 doReturn(false).when(MOCK_sdnoHealthCheckResources).healthCheck(genericVnf, requestContext);
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));
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));
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));