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;
28 import java.util.UUID;
29 import org.apache.commons.lang3.StringUtils;
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 PNF_ENTRY_NOTIFICATION_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();
41 private static final String DEFAULT_SERVICE_INSTANCE_ID = "da7d07d9-b71c-4128-809d-2ec01c807169";
42 private static final String DEFAULT_PNF_CORRELATION_ID = "testPnfCorrelationId";
44 private DelegateExecutionBuilder delegateExecutionBuilder;
48 delegateExecutionBuilder = new DelegateExecutionBuilder();
52 public void shouldThrowException_whenPnfCorrelationIdNotSet() {
53 PnfCheckInputs testedObject = new PnfCheckInputs(PNF_ENTRY_NOTIFICATION_TIMEOUT);
54 DelegateExecution execution = delegateExecutionBuilder.setPnfCorrelationId(null).setPnfUuid(VALID_UUID).build();
55 assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
59 public void shouldThrowException_whenPnfEntryNotificationTimeoutIsNull() {
60 PnfCheckInputs testedObject = new PnfCheckInputs(null);
61 DelegateExecution execution = delegateExecutionBuilder.build();
62 assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
66 public void shouldThrowException_whenPnfEntryNotificationTimeoutIsEmpty() {
67 PnfCheckInputs testedObject = new PnfCheckInputs(StringUtils.EMPTY);
68 DelegateExecution execution = delegateExecutionBuilder.build();
69 assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
73 public void shouldThrowException_whenPnfUuidIsNotSet() {
74 PnfCheckInputs testedObject = new PnfCheckInputs(PNF_ENTRY_NOTIFICATION_TIMEOUT);
75 DelegateExecution execution = delegateExecutionBuilder.setPnfUuid(null).build();
76 assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
80 public void shouldThrowException_whenPnfUuidIsEmptyString() {
81 PnfCheckInputs testedObject = new PnfCheckInputs(PNF_ENTRY_NOTIFICATION_TIMEOUT);
82 DelegateExecution execution = delegateExecutionBuilder.setPnfUuid(StringUtils.EMPTY).build();
83 assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
87 public void shouldThrowException_whenPnfUuidIsReservedUuid() {
88 PnfCheckInputs testedObject = new PnfCheckInputs(PNF_ENTRY_NOTIFICATION_TIMEOUT);
89 DelegateExecution execution = delegateExecutionBuilder.setPnfUuid(RESERVED_UUID).build();
90 assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
94 public void shouldThrowException_whenServiceInstanceIdIsNotSet() {
95 PnfCheckInputs testedObject = new PnfCheckInputs(PNF_ENTRY_NOTIFICATION_TIMEOUT);
96 DelegateExecution execution = delegateExecutionBuilder.setServiceInstanceId(null).build();
97 assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
100 private static class DelegateExecutionBuilder {
101 private String pnfCorrelationId = DEFAULT_PNF_CORRELATION_ID;
102 private String pnfUuid = VALID_UUID;
103 private String serviceInstanceId = DEFAULT_SERVICE_INSTANCE_ID;
105 public DelegateExecutionBuilder setPnfCorrelationId(String pnfCorrelationId) {
106 this.pnfCorrelationId = pnfCorrelationId;
110 public DelegateExecutionBuilder setPnfUuid(String pnfUuid) {
111 this.pnfUuid = pnfUuid;
115 public DelegateExecutionBuilder setServiceInstanceId(String serviceInstanceId) {
116 this.serviceInstanceId = serviceInstanceId;
120 public DelegateExecution build() {
121 DelegateExecution execution = new DelegateExecutionFake();
122 execution.setVariable("testProcessKey", "testProcessKeyValue");
123 execution.setVariable(PNF_CORRELATION_ID, this.pnfCorrelationId);
124 execution.setVariable(PNF_UUID, this.pnfUuid);
125 execution.setVariable(SERVICE_INSTANCE_ID, this.serviceInstanceId);