2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.infrastructure.pnf.delegate;
23 import static org.assertj.core.api.Assertions.assertThatThrownBy;
24 import static org.mockito.Matchers.eq;
25 import static org.mockito.Mockito.mock;
26 import static org.mockito.Mockito.verify;
27 import static org.mockito.Mockito.when;
28 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID;
29 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.TIMEOUT_FOR_NOTIFICATION;
31 import org.camunda.bpm.engine.delegate.BpmnError;
32 import org.camunda.bpm.engine.delegate.DelegateExecution;
33 import org.junit.Test;
35 public class PnfCheckInputsTest {
37 private static final String DEFAULT_TIMEOUT = "P1D";
39 private DelegateExecution mockDelegateExecution() {
40 new PnfCheckInputs(DEFAULT_TIMEOUT);
41 DelegateExecution delegateExecution = mock(DelegateExecution.class);
42 when(delegateExecution.getVariable("testProcessKey")).thenReturn("testProcessKeyValue");
43 return delegateExecution;
47 public void shouldThrowException_whenPnfIdNotSet() {
49 PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
50 DelegateExecution delegateExecution = mockDelegateExecution();
52 assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
56 public void shouldThrowException_whenPnfIdIsEmptyString() throws Exception {
58 PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
59 DelegateExecution delegateExecution = mockDelegateExecution();
60 when(delegateExecution.getVariable(CORRELATION_ID)).thenReturn("");
62 assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
65 private DelegateExecution mockDelegateExecutionWithCorrelationId() {
66 new PnfCheckInputs(DEFAULT_TIMEOUT);
67 DelegateExecution delegateExecution = mockDelegateExecution();
68 when(delegateExecution.getVariable(CORRELATION_ID)).thenReturn("testCorrelationId");
69 return delegateExecution;
73 public void shouldThrowException_whenTimeoutIsNotSetAndDefaultIsNotDefined() {
75 PnfCheckInputs testedObject = new PnfCheckInputs(null);
76 DelegateExecution delegateExecution = mockDelegateExecutionWithCorrelationId();
78 assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
82 public void shouldThrowException_whenTimeoutIsEmptyStringAndDefaultIsNotDefined() throws Exception {
84 PnfCheckInputs testedObject = new PnfCheckInputs(null);
85 DelegateExecution delegateExecution = mockDelegateExecutionWithCorrelationId();
86 when(delegateExecution.getVariable(TIMEOUT_FOR_NOTIFICATION)).thenReturn("");
88 assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
92 public void shouldSetDefaultTimeout_whenTimeoutIsNotSet() {
94 PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
95 DelegateExecution delegateExecution = mockDelegateExecutionWithCorrelationId();
97 testedObject.execute(delegateExecution);
99 verify(delegateExecution).setVariable(eq(TIMEOUT_FOR_NOTIFICATION), eq(DEFAULT_TIMEOUT));