aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks/src
diff options
context:
space:
mode:
authorLukasz Muszkieta <lukasz.muszkieta@nokia.com>2021-04-23 17:56:03 +0200
committerLukasz Muszkieta <lukasz.muszkieta@nokia.com>2021-05-25 18:01:18 +0200
commit4b77e8873cb690b5df2391db8ca770d70de61ee1 (patch)
tree18bb60b532f7789c4a5a8b8d02f88b60a1ee1d9c /bpmn/so-bpmn-tasks/src
parentc6276a6e0ca148213a9d7b66cec184e419da3916 (diff)
add junit coverage
Issue-ID: SO-3433 Signed-off-by: Lukasz Muszkieta <lukasz.muszkieta@nokia.com> Change-Id: Ie099e0482c8581426c3ddf16d9a34bb0f39ca937 Signed-off-by: Lukasz Muszkieta <lukasz.muszkieta@nokia.com>
Diffstat (limited to 'bpmn/so-bpmn-tasks/src')
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelTest.java66
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;
}
}