diff options
author | Seshu Kumar M <seshu.kumar.m@huawei.com> | 2021-06-15 13:08:09 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2021-06-15 13:08:09 +0000 |
commit | bcd074c7b4289d9fc3ed9813c5480e4e9647bba3 (patch) | |
tree | fbd2ff99966c3bf5dd175fc52aaf7d0709cfdf86 /bpmn | |
parent | e7dc04d315cacbe219c9044dbfd4b3ccd078621f (diff) | |
parent | 4b77e8873cb690b5df2391db8ca770d70de61ee1 (diff) |
Merge "add junit coverage"
Diffstat (limited to 'bpmn')
-rw-r--r-- | bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelTest.java | 66 |
1 files 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<String> 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<String> createParamList() { + List<String> params = new ArrayList<>(); + params.add(PARAM_NAME); + return params; + } + + private List<String> createPnfNameList() { List<String> pnfNameList = new ArrayList<>(); - pnfNameList.add(pnfName); + pnfNameList.add(PNF_NAME); return pnfNameList; } } |