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.SERVICE_INSTANCE_ID;
28 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.TIMEOUT_FOR_NOTIFICATION;
30 import java.util.UUID;
31 import org.camunda.bpm.engine.delegate.BpmnError;
32 import org.camunda.bpm.engine.delegate.DelegateExecution;
33 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
34 import org.junit.Before;
35 import org.junit.Test;
37 public class PnfCheckInputsTest {
39 private static final String DEFAULT_TIMEOUT = "P1D";
40 private static final String VALID_UUID = UUID.nameUUIDFromBytes("testUuid".getBytes()).toString();
41 private static final String RESERVED_UUID = new UUID(0, 0).toString();
42 private static final String DEFAULT_SERVICE_INSTANCE_ID = "da7d07d9-b71c-4128-809d-2ec01c807169";
43 private static final String DEFAULT_CORRELATION_ID = "testCorrelationId";
45 private DelegateExecutionBuilder delegateExecutionBuilder;
49 delegateExecutionBuilder = new DelegateExecutionBuilder();
53 public void shouldThrowException_whenCorrelationIdNotSet() {
54 PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
55 DelegateExecution execution = delegateExecutionBuilder.setCorrelationId(null).setPnfUuid(VALID_UUID).build();
56 assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
60 public void shouldThrowException_whenTimeoutIsEmptyStringAndDefaultIsNotDefined() {
61 PnfCheckInputs testedObject = new PnfCheckInputs(null);
62 DelegateExecution execution = delegateExecutionBuilder.setTimeoutForNotification("").build();
63 assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
67 public void shouldSetDefaultTimeout_whenTimeoutIsNotSet() {
68 PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
69 DelegateExecution execution = delegateExecutionBuilder.setTimeoutForNotification(null).build();
70 testedObject.execute(execution);
71 assertThat(execution.getVariable(TIMEOUT_FOR_NOTIFICATION)).isEqualTo(DEFAULT_TIMEOUT);
75 public void shouldThrowException_whenPnfUuidIsNotSet() {
76 PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
77 DelegateExecution execution = delegateExecutionBuilder.setPnfUuid(null).build();
78 assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
82 public void shouldThrowException_whenPnfUuidIsEmptyString() {
83 PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
84 DelegateExecution execution = delegateExecutionBuilder.setPnfUuid("").build();
85 assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
89 public void shouldThrowException_whenPnfUuidIsReservedUuid() {
90 PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
91 DelegateExecution execution = delegateExecutionBuilder.setPnfUuid(RESERVED_UUID).build();
92 assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
96 public void shouldThrowException_whenServiceInstanceIdIsNotSet() {
97 PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
98 DelegateExecution execution = delegateExecutionBuilder.setServiceInstanceId(null).build();
99 assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
102 private static class DelegateExecutionBuilder {
103 private String correlationId = DEFAULT_CORRELATION_ID;
104 private String pnfUuid = VALID_UUID;
105 private String serviceInstanceId = DEFAULT_SERVICE_INSTANCE_ID;
106 private String timeoutForNotification;
108 public DelegateExecutionBuilder setCorrelationId(String correlationId) {
109 this.correlationId = correlationId;
113 public DelegateExecutionBuilder setPnfUuid(String pnfUuid) {
114 this.pnfUuid = pnfUuid;
118 public DelegateExecutionBuilder setServiceInstanceId(String serviceInstanceId) {
119 this.serviceInstanceId = serviceInstanceId;
123 public DelegateExecutionBuilder setTimeoutForNotification(String timeoutForNotification) {
124 this.timeoutForNotification = timeoutForNotification;
128 public DelegateExecution build() {
129 DelegateExecution execution = new DelegateExecutionFake();
130 execution.setVariable("testProcessKey", "testProcessKeyValue");
131 execution.setVariable(CORRELATION_ID, this.correlationId);
132 execution.setVariable(PNF_UUID, this.pnfUuid);
133 execution.setVariable(SERVICE_INSTANCE_ID, this.serviceInstanceId);
134 execution.setVariable(TIMEOUT_FOR_NOTIFICATION, this.timeoutForNotification);