From 4b77e8873cb690b5df2391db8ca770d70de61ee1 Mon Sep 17 00:00:00 2001 From: Lukasz Muszkieta Date: Fri, 23 Apr 2021 17:56:03 +0200 Subject: add junit coverage Issue-ID: SO-3433 Signed-off-by: Lukasz Muszkieta Change-Id: Ie099e0482c8581426c3ddf16d9a34bb0f39ca937 Signed-off-by: Lukasz Muszkieta --- .../service/level/ServiceLevelTest.java | 66 +++++++++++++++++++--- 1 file changed, 58 insertions(+), 8 deletions(-) diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelTest.java index cfaa4040c7..fb15ffa2b3 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelTest.java @@ -21,35 +21,85 @@ package org.onap.so.bpmn.infrastructure.service.level; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import java.util.ArrayList; +import java.util.List; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Before; import org.junit.Test; -import java.util.List; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.bpmn.infrastructure.service.level.impl.ServiceLevelConstants; +import org.onap.so.client.exception.ExceptionBuilder; +@RunWith(MockitoJUnitRunner.class) public class ServiceLevelTest { private static final String EXECUTION_KEY_PNF_NAME_LIST = "pnfNameList"; private static final String EXECUTION_KEY_PNF_COUNTER = "pnfCounter"; + private static final String PARAM_NAME = "param1"; + private static final String SCOPE = "scope1"; + private static final String PNF_NAME = "pnfName1"; + + @Mock + private ExceptionBuilder exceptionBuilderMock; + @InjectMocks + private ServiceLevel testedObject; + + private DelegateExecution execution; + + @Before + public void init() { + execution = new DelegateExecutionFake(); + } @Test public void pnfCounterExecution_success() { // given - String pnfName = "pnfName1"; - DelegateExecution execution = new DelegateExecutionFake(); - execution.setVariable(EXECUTION_KEY_PNF_NAME_LIST, createPnfNameList(pnfName)); + execution.setVariable(EXECUTION_KEY_PNF_NAME_LIST, createPnfNameList()); execution.setVariable(EXECUTION_KEY_PNF_COUNTER, 0); // when - new ServiceLevel().pnfCounterExecution(execution); + testedObject.pnfCounterExecution(execution); // then - assertThat(execution.getVariable(ServiceLevelConstants.PNF_NAME)).isEqualTo(pnfName); + assertThat(execution.getVariable(ServiceLevelConstants.PNF_NAME)).isEqualTo(PNF_NAME); assertThat(execution.getVariable(EXECUTION_KEY_PNF_COUNTER)).isEqualTo(1); } - private List createPnfNameList(String pnfName) { + @Test + public void validateParams_success_paramExistsInExecution() { + // given + execution.setVariable(PARAM_NAME, "anyValue"); + // when + testedObject.validateParamsWithScope(execution, "anyScope", createParamList()); + // then + verify(exceptionBuilderMock, times(0)).buildAndThrowWorkflowException(any(DelegateExecution.class), + eq(ServiceLevelConstants.ERROR_CODE), any(String.class)); + } + + @Test + public void validateParams_exceptionParamDoesNotExistInExecution() { + // when + testedObject.validateParamsWithScope(execution, SCOPE, createParamList()); + // then + verify(exceptionBuilderMock).buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE, + "Validation of health check workflow parameters failed for the scope: " + SCOPE); + } + + private List createParamList() { + List params = new ArrayList<>(); + params.add(PARAM_NAME); + return params; + } + + private List createPnfNameList() { List pnfNameList = new ArrayList<>(); - pnfNameList.add(pnfName); + pnfNameList.add(PNF_NAME); return pnfNameList; } } -- cgit 1.2.3-korg