001815b206a4bf1f7fdf17e1d1c368856dc891e0
[so.git] / bpmn / so-bpmn-infrastructure-common / src / test / java / org / onap / so / bpmn / infrastructure / pnf / delegate / PnfCheckInputsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.pnf.delegate;
22
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
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;
35
36 public class PnfCheckInputsTest {
37
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";
43
44     private DelegateExecutionBuilder delegateExecutionBuilder;
45
46     @Before
47     public void setUp() {
48         delegateExecutionBuilder = new DelegateExecutionBuilder();
49     }
50
51     @Test
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);
56     }
57
58     @Test
59     public void shouldThrowException_whenPnfEntryNotificationTimeoutIsNull() {
60         PnfCheckInputs testedObject = new PnfCheckInputs(null);
61         DelegateExecution execution = delegateExecutionBuilder.build();
62         assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
63     }
64
65     @Test
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);
70     }
71
72     @Test
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);
77     }
78
79     @Test
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);
84     }
85
86     @Test
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);
91     }
92
93     @Test
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);
98     }
99
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;
104
105         public DelegateExecutionBuilder setPnfCorrelationId(String pnfCorrelationId) {
106             this.pnfCorrelationId = pnfCorrelationId;
107             return this;
108         }
109
110         public DelegateExecutionBuilder setPnfUuid(String pnfUuid) {
111             this.pnfUuid = pnfUuid;
112             return this;
113         }
114
115         public DelegateExecutionBuilder setServiceInstanceId(String serviceInstanceId) {
116             this.serviceInstanceId = serviceInstanceId;
117             return this;
118         }
119
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);
126             return execution;
127         }
128     }
129 }