From 59e4171c755943b1ac7e16d80980e8736045e5aa Mon Sep 17 00:00:00 2001 From: biniek Date: Thu, 17 May 2018 12:11:50 +0200 Subject: Added checking input variables in pnf-pnp Change-Id: I1a4f4b9704385a17995e76d4b87484c2f588b889 Issue-ID: SO-506 Signed-off-by: biniek --- .../pnf/delegate/PnfCheckInputsTest.java | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/PnfCheckInputsTest.java (limited to 'bpmn/MSOInfrastructureBPMN/src/test/java/org') diff --git a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/PnfCheckInputsTest.java b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/PnfCheckInputsTest.java new file mode 100644 index 0000000000..1799e7fcbc --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/PnfCheckInputsTest.java @@ -0,0 +1,84 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.bpmn.infrastructure.pnf.delegate; + +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.openecomp.mso.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.TIMEOUT_FOR_NOTIFICATION; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.junit.Before; +import org.junit.Test; + +public class PnfCheckInputsTest { + + private PnfCheckInputs delegate; + + @Before + public void setUp() throws Exception { + delegate = new PnfCheckInputs(); + } + + private DelegateExecution mockDelegateExecution() { + DelegateExecution delegateExecution = mock(DelegateExecution.class); + when(delegateExecution.getVariable("testProcessKey")).thenReturn("testProcessKeyValue"); + return delegateExecution; + } + + @Test + public void shouldThrowException_whenPnfIdNotSet() throws Exception { + // given + DelegateExecution delegateExecution = mockDelegateExecution(); + // when, then + assertThatThrownBy(() -> delegate.execute(delegateExecution)).isInstanceOf(BpmnError.class); + } + + private DelegateExecution mockDelegateExecutionWithCorrelationId() { + DelegateExecution delegateExecution = mockDelegateExecution(); + when(delegateExecution.getVariable(CORRELATION_ID)).thenReturn("testCorrelationId"); + return delegateExecution; + } + + @Test + public void shouldThrowException_whenTimeoutIsNotSetAndDefaultIsNotDefined() throws Exception { + // given + DelegateExecution delegateExecution = mockDelegateExecutionWithCorrelationId(); + // when, then + assertThatThrownBy(() -> delegate.execute(delegateExecution)).isInstanceOf(BpmnError.class); + } + + @Test + public void shouldSetDefaultTimeout_whenTimeoutIsNotSet() throws Exception { + // given + String defaultTimeout = "T1D"; + delegate.setDefaultTimeout(defaultTimeout); + DelegateExecution delegateExecution = mockDelegateExecutionWithCorrelationId(); + // when + delegate.execute(delegateExecution); + // then + verify(delegateExecution).setVariable(eq(TIMEOUT_FOR_NOTIFICATION), eq(defaultTimeout)); + } +} \ No newline at end of file -- cgit 1.2.3-korg