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.assertThat;
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID;
26 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID;
27 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.TIMEOUT_FOR_NOTIFICATION;
29 import java.util.UUID;
30 import org.camunda.bpm.engine.delegate.BpmnError;
31 import org.camunda.bpm.engine.delegate.DelegateExecution;
32 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
33 import org.junit.Before;
34 import org.junit.Test;
36 public class PnfCheckInputsTest {
38 private static final String DEFAULT_TIMEOUT = "P1D";
39 private static final String VALID_UUID = UUID.nameUUIDFromBytes("testUuid".getBytes()).toString();
40 private static final String RESERVED_UUID = new UUID(0, 0).toString();
42 private DelegateExecution delegateExecution;
46 delegateExecution = new DelegateExecutionFake();
47 delegateExecution.setVariable("testProcessKey", "testProcessKeyValue");
51 public void shouldThrowException_whenCorrelationIdNotSet() {
52 PnfCheckInputs testedObject = prepareExecutionForCorrelationId(null);
53 assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
57 public void shouldThrowException_whenTimeoutIsEmptyStringAndDefaultIsNotDefined() {
58 PnfCheckInputs testedObject = prepareExecutionForTimeout(null, "");
59 assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
63 public void shouldSetDefaultTimeout_whenTimeoutIsNotSet() {
64 PnfCheckInputs testedObject = prepareExecutionForTimeout(DEFAULT_TIMEOUT, null);
65 testedObject.execute(delegateExecution);
66 assertThat(delegateExecution.getVariable(TIMEOUT_FOR_NOTIFICATION)).isEqualTo(DEFAULT_TIMEOUT);
70 public void shouldThrowException_whenPnfUuidIsNotSet() {
71 PnfCheckInputs testedObject = prepareExecutionForUuid(null);
72 assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
76 public void shouldThrowException_whenPnfUuidIsEmptyString() {
77 PnfCheckInputs testedObject = prepareExecutionForUuid("");
78 assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
82 public void shouldThrowException_whenPnfUuidIsReservedUuid() {
83 PnfCheckInputs testedObject = prepareExecutionForUuid(RESERVED_UUID);
84 assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
87 private PnfCheckInputs prepareExecutionForCorrelationId(String correlationId) {
88 PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
89 delegateExecution.setVariable(CORRELATION_ID, correlationId);
90 delegateExecution.setVariable(PNF_UUID, VALID_UUID);
94 private PnfCheckInputs prepareExecutionForTimeout(String defaultTimeout, String timeout) {
95 PnfCheckInputs testedObject = new PnfCheckInputs(defaultTimeout);
96 delegateExecution.setVariable(CORRELATION_ID, "testCorrelationId");
97 delegateExecution.setVariable(PNF_UUID, VALID_UUID);
98 delegateExecution.setVariable(TIMEOUT_FOR_NOTIFICATION, timeout);
102 private PnfCheckInputs prepareExecutionForUuid(String uuid) {
103 PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
104 delegateExecution.setVariable(CORRELATION_ID, "testCorrelationId");
105 delegateExecution.setVariable(PNF_UUID, uuid);