2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright 2018 Nokia
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.infrastructure.pnf.delegate;
25 import static org.assertj.core.api.Assertions.assertThat;
26 import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
27 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID;
28 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID;
29 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.TIMEOUT_FOR_NOTIFICATION;
31 import java.util.UUID;
32 import org.camunda.bpm.engine.delegate.BpmnError;
33 import org.camunda.bpm.engine.delegate.DelegateExecution;
34 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
35 import org.junit.Before;
36 import org.junit.Test;
38 public class PnfCheckInputsTest {
40 private static final String DEFAULT_TIMEOUT = "P1D";
41 private static final String VALID_UUID = UUID.nameUUIDFromBytes("testUuid".getBytes()).toString();
42 private static final String RESERVED_UUID = new UUID(0, 0).toString();
44 private DelegateExecution delegateExecution;
48 delegateExecution = new DelegateExecutionFake();
49 delegateExecution.setVariable("testProcessKey", "testProcessKeyValue");
53 public void shouldThrowException_whenCorrelationIdNotSet() {
54 PnfCheckInputs testedObject = prepareExecutionForCorrelationId(null);
55 assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
59 public void shouldThrowException_whenCorrelationIdIsEmptyString() {
60 PnfCheckInputs testedObject = prepareExecutionForCorrelationId("");
61 assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
65 public void shouldThrowException_whenTimeoutIsNotSetAndDefaultIsNotDefined() {
66 PnfCheckInputs testedObject = prepareExecutionForTimeout(null, null);
67 assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
71 public void shouldThrowException_whenTimeoutIsEmptyStringAndDefaultIsNotDefined() {
72 PnfCheckInputs testedObject = prepareExecutionForTimeout(null, "");
73 assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
77 public void shouldSetDefaultTimeout_whenTimeoutIsNotSet() {
78 PnfCheckInputs testedObject = prepareExecutionForTimeout(DEFAULT_TIMEOUT, null);
79 testedObject.execute(delegateExecution);
80 assertThat(delegateExecution.getVariable(TIMEOUT_FOR_NOTIFICATION)).isEqualTo(DEFAULT_TIMEOUT);
84 public void shouldThrowException_whenPnfUuidIsNotSet() {
85 PnfCheckInputs testedObject = prepareExecutionForUuid(null);
86 assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
90 public void shouldThrowException_whenPnfUuidIsEmptyString() {
91 PnfCheckInputs testedObject = prepareExecutionForUuid("");
92 assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
96 public void shouldThrowException_whenPnfUuidIsReservedUuid() {
97 PnfCheckInputs testedObject = prepareExecutionForUuid(RESERVED_UUID);
98 assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
101 private PnfCheckInputs prepareExecutionForCorrelationId(String correlationId) {
102 PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
103 delegateExecution.setVariable(CORRELATION_ID, correlationId);
104 delegateExecution.setVariable(PNF_UUID, VALID_UUID);
108 private PnfCheckInputs prepareExecutionForTimeout(String defaultTimeout, String timeout) {
109 PnfCheckInputs testedObject = new PnfCheckInputs(defaultTimeout);
110 delegateExecution.setVariable(CORRELATION_ID, "testCorrelationId");
111 delegateExecution.setVariable(PNF_UUID, VALID_UUID);
112 delegateExecution.setVariable(TIMEOUT_FOR_NOTIFICATION, timeout);
116 private PnfCheckInputs prepareExecutionForUuid(String uuid) {
117 PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
118 delegateExecution.setVariable(CORRELATION_ID, "testCorrelationId");
119 delegateExecution.setVariable(PNF_UUID, uuid);