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.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID;
25 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID;
26 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.SERVICE_INSTANCE_ID;
27 import java.util.UUID;
28 import org.apache.commons.lang3.StringUtils;
29 import org.camunda.bpm.engine.delegate.BpmnError;
30 import org.camunda.bpm.engine.delegate.DelegateExecution;
31 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
32 import org.junit.Before;
33 import org.junit.Test;
35 public class PnfCheckInputsTest {
37 private static final String PNF_ENTRY_NOTIFICATION_TIMEOUT = "P1D";
38 private static final String VALID_UUID = UUID.nameUUIDFromBytes("testUuid".getBytes()).toString();
39 private static final String RESERVED_UUID = new UUID(0, 0).toString();
40 private static final String DEFAULT_SERVICE_INSTANCE_ID = "da7d07d9-b71c-4128-809d-2ec01c807169";
41 private static final String DEFAULT_PNF_CORRELATION_ID = "testPnfCorrelationId";
43 private DelegateExecutionBuilder delegateExecutionBuilder;
47 delegateExecutionBuilder = new DelegateExecutionBuilder();
51 public void shouldThrowException_whenPnfCorrelationIdNotSet() {
52 PnfCheckInputs testedObject = new PnfCheckInputs(PNF_ENTRY_NOTIFICATION_TIMEOUT);
53 DelegateExecution execution = delegateExecutionBuilder.setPnfCorrelationId(null).setPnfUuid(VALID_UUID).build();
54 assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
58 public void shouldThrowException_whenPnfEntryNotificationTimeoutIsNull() {
59 PnfCheckInputs testedObject = new PnfCheckInputs(null);
60 DelegateExecution execution = delegateExecutionBuilder.build();
61 assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
65 public void shouldThrowException_whenPnfEntryNotificationTimeoutIsEmpty() {
66 PnfCheckInputs testedObject = new PnfCheckInputs(StringUtils.EMPTY);
67 DelegateExecution execution = delegateExecutionBuilder.build();
68 assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
72 public void shouldThrowException_whenPnfUuidIsNotSet() {
73 PnfCheckInputs testedObject = new PnfCheckInputs(PNF_ENTRY_NOTIFICATION_TIMEOUT);
74 DelegateExecution execution = delegateExecutionBuilder.setPnfUuid(null).build();
75 assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
79 public void shouldThrowException_whenPnfUuidIsEmptyString() {
80 PnfCheckInputs testedObject = new PnfCheckInputs(PNF_ENTRY_NOTIFICATION_TIMEOUT);
81 DelegateExecution execution = delegateExecutionBuilder.setPnfUuid(StringUtils.EMPTY).build();
82 assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
86 public void shouldThrowException_whenPnfUuidIsReservedUuid() {
87 PnfCheckInputs testedObject = new PnfCheckInputs(PNF_ENTRY_NOTIFICATION_TIMEOUT);
88 DelegateExecution execution = delegateExecutionBuilder.setPnfUuid(RESERVED_UUID).build();
89 assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
93 public void shouldThrowException_whenServiceInstanceIdIsNotSet() {
94 PnfCheckInputs testedObject = new PnfCheckInputs(PNF_ENTRY_NOTIFICATION_TIMEOUT);
95 DelegateExecution execution = delegateExecutionBuilder.setServiceInstanceId(null).build();
96 assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
99 private static class DelegateExecutionBuilder {
100 private String pnfCorrelationId = DEFAULT_PNF_CORRELATION_ID;
101 private String pnfUuid = VALID_UUID;
102 private String serviceInstanceId = DEFAULT_SERVICE_INSTANCE_ID;
104 public DelegateExecutionBuilder setPnfCorrelationId(String pnfCorrelationId) {
105 this.pnfCorrelationId = pnfCorrelationId;
109 public DelegateExecutionBuilder setPnfUuid(String pnfUuid) {
110 this.pnfUuid = pnfUuid;
114 public DelegateExecutionBuilder setServiceInstanceId(String serviceInstanceId) {
115 this.serviceInstanceId = serviceInstanceId;
119 public DelegateExecution build() {
120 DelegateExecution execution = new DelegateExecutionFake();
121 execution.setVariable("testProcessKey", "testProcessKeyValue");
122 execution.setVariable(PNF_CORRELATION_ID, this.pnfCorrelationId);
123 execution.setVariable(PNF_UUID, this.pnfUuid);
124 execution.setVariable(SERVICE_INSTANCE_ID, this.serviceInstanceId);