2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nokia
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.infrastructure.service.level;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.ArgumentMatchers.eq;
26 import static org.mockito.Mockito.times;
27 import static org.mockito.Mockito.verify;
28 import java.util.ArrayList;
29 import java.util.List;
30 import org.camunda.bpm.engine.delegate.DelegateExecution;
31 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
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.infrastructure.service.level.impl.ServiceLevelConstants;
39 import org.onap.so.client.exception.ExceptionBuilder;
41 @RunWith(MockitoJUnitRunner.class)
42 public class ServiceLevelTest {
44 private static final String EXECUTION_KEY_PNF_NAME_LIST = "pnfNameList";
45 private static final String EXECUTION_KEY_PNF_COUNTER = "pnfCounter";
46 private static final String PARAM_NAME = "param1";
47 private static final String SCOPE = "scope1";
48 private static final String PNF_NAME = "pnfName1";
51 private ExceptionBuilder exceptionBuilderMock;
53 private ServiceLevel testedObject;
55 private DelegateExecution execution;
59 execution = new DelegateExecutionFake();
63 public void pnfCounterExecution_success() {
65 execution.setVariable(EXECUTION_KEY_PNF_NAME_LIST, createPnfNameList());
66 execution.setVariable(EXECUTION_KEY_PNF_COUNTER, 0);
68 testedObject.pnfCounterExecution(execution);
70 assertThat(execution.getVariable(ServiceLevelConstants.PNF_NAME)).isEqualTo(PNF_NAME);
71 assertThat(execution.getVariable(EXECUTION_KEY_PNF_COUNTER)).isEqualTo(1);
75 public void validateParams_success_paramExistsInExecution() {
77 execution.setVariable(PARAM_NAME, "anyValue");
79 testedObject.validateParamsWithScope(execution, "anyScope", createParamList());
81 verify(exceptionBuilderMock, times(0)).buildAndThrowWorkflowException(any(DelegateExecution.class),
82 eq(ServiceLevelConstants.ERROR_CODE), any(String.class));
86 public void validateParams_exceptionParamDoesNotExistInExecution() {
88 testedObject.validateParamsWithScope(execution, SCOPE, createParamList());
90 verify(exceptionBuilderMock).buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE,
91 "Validation of health check workflow parameters failed for the scope: " + SCOPE);
94 private List<String> createParamList() {
95 List<String> params = new ArrayList<>();
96 params.add(PARAM_NAME);
100 private List<String> createPnfNameList() {
101 List<String> pnfNameList = new ArrayList<>();
102 pnfNameList.add(PNF_NAME);