X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=bpmn%2Fso-bpmn-infrastructure-common%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fso%2Fbpmn%2Finfrastructure%2Fpnf%2Fdelegate%2FPnfCheckInputsTest.java;h=1888831e2e3b5ac9ff91dee402b69d06b193abc7;hb=f1435439699e4e08d2bf912634208e18c894722f;hp=2e8fb4be786c0cf5c7bd0505ac67955841fbf597;hpb=60f8f5342f1fba49373699c1466e6ca06d1adc34;p=so.git diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputsTest.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputsTest.java index 2e8fb4be78..1888831e2e 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputsTest.java +++ b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputsTest.java @@ -20,62 +20,89 @@ package org.onap.so.bpmn.infrastructure.pnf.delegate; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID; import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.TIMEOUT_FOR_NOTIFICATION; +import java.util.UUID; import org.camunda.bpm.engine.delegate.BpmnError; import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Before; import org.junit.Test; public class PnfCheckInputsTest { private static final String DEFAULT_TIMEOUT = "P1D"; + private static final String VALID_UUID = UUID.nameUUIDFromBytes("testUuid".getBytes()).toString(); + private static final String RESERVED_UUID = new UUID(0, 0).toString(); - private DelegateExecution mockDelegateExecution() { - new PnfCheckInputs(DEFAULT_TIMEOUT); - DelegateExecution delegateExecution = mock(DelegateExecution.class); - when(delegateExecution.getVariable("testProcessKey")).thenReturn("testProcessKeyValue"); - return delegateExecution; + private DelegateExecution delegateExecution; + + @Before + public void setUp() { + delegateExecution = new DelegateExecutionFake(); + delegateExecution.setVariable("testProcessKey", "testProcessKeyValue"); } @Test - public void shouldThrowException_whenPnfIdNotSet() { - // given - PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT); - DelegateExecution delegateExecution = mockDelegateExecution(); - // when, then + public void shouldThrowException_whenCorrelationIdNotSet() { + PnfCheckInputs testedObject = prepareExecutionForCorrelationId(null); + assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class); + } + + @Test + public void shouldThrowException_whenTimeoutIsEmptyStringAndDefaultIsNotDefined() { + PnfCheckInputs testedObject = prepareExecutionForTimeout(null, ""); assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class); } - private DelegateExecution mockDelegateExecutionWithCorrelationId() { - new PnfCheckInputs(DEFAULT_TIMEOUT); - DelegateExecution delegateExecution = mockDelegateExecution(); - when(delegateExecution.getVariable(CORRELATION_ID)).thenReturn("testCorrelationId"); - return delegateExecution; + @Test + public void shouldSetDefaultTimeout_whenTimeoutIsNotSet() { + PnfCheckInputs testedObject = prepareExecutionForTimeout(DEFAULT_TIMEOUT, null); + testedObject.execute(delegateExecution); + assertThat(delegateExecution.getVariable(TIMEOUT_FOR_NOTIFICATION)).isEqualTo(DEFAULT_TIMEOUT); } @Test - public void shouldThrowException_whenTimeoutIsNotSetAndDefaultIsNotDefined() { - // given - PnfCheckInputs testedObject = new PnfCheckInputs(null); - DelegateExecution delegateExecution = mockDelegateExecutionWithCorrelationId(); - // when, then + public void shouldThrowException_whenPnfUuidIsNotSet() { + PnfCheckInputs testedObject = prepareExecutionForUuid(null); assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class); } @Test - public void shouldSetDefaultTimeout_whenTimeoutIsNotSet() { - // given + public void shouldThrowException_whenPnfUuidIsEmptyString() { + PnfCheckInputs testedObject = prepareExecutionForUuid(""); + assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class); + } + + @Test + public void shouldThrowException_whenPnfUuidIsReservedUuid() { + PnfCheckInputs testedObject = prepareExecutionForUuid(RESERVED_UUID); + assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class); + } + + private PnfCheckInputs prepareExecutionForCorrelationId(String correlationId) { PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT); - DelegateExecution delegateExecution = mockDelegateExecutionWithCorrelationId(); - // when - testedObject.execute(delegateExecution); - // then - verify(delegateExecution).setVariable(eq(TIMEOUT_FOR_NOTIFICATION), eq(DEFAULT_TIMEOUT)); + delegateExecution.setVariable(CORRELATION_ID, correlationId); + delegateExecution.setVariable(PNF_UUID, VALID_UUID); + return testedObject; + } + + private PnfCheckInputs prepareExecutionForTimeout(String defaultTimeout, String timeout) { + PnfCheckInputs testedObject = new PnfCheckInputs(defaultTimeout); + delegateExecution.setVariable(CORRELATION_ID, "testCorrelationId"); + delegateExecution.setVariable(PNF_UUID, VALID_UUID); + delegateExecution.setVariable(TIMEOUT_FOR_NOTIFICATION, timeout); + return testedObject; + } + + private PnfCheckInputs prepareExecutionForUuid(String uuid) { + PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT); + delegateExecution.setVariable(CORRELATION_ID, "testCorrelationId"); + delegateExecution.setVariable(PNF_UUID, uuid); + return testedObject; } -} \ No newline at end of file +}