Replaced all tabs with spaces in java and pom.xml
[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 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;
34
35 public class PnfCheckInputsTest {
36
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";
42
43     private DelegateExecutionBuilder delegateExecutionBuilder;
44
45     @Before
46     public void setUp() {
47         delegateExecutionBuilder = new DelegateExecutionBuilder();
48     }
49
50     @Test
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);
55     }
56
57     @Test
58     public void shouldThrowException_whenPnfEntryNotificationTimeoutIsNull() {
59         PnfCheckInputs testedObject = new PnfCheckInputs(null);
60         DelegateExecution execution = delegateExecutionBuilder.build();
61         assertThatThrownBy(() -> testedObject.execute(execution)).isInstanceOf(BpmnError.class);
62     }
63
64     @Test
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);
69     }
70
71     @Test
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);
76     }
77
78     @Test
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);
83     }
84
85     @Test
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);
90     }
91
92     @Test
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);
97     }
98
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;
103
104         public DelegateExecutionBuilder setPnfCorrelationId(String pnfCorrelationId) {
105             this.pnfCorrelationId = pnfCorrelationId;
106             return this;
107         }
108
109         public DelegateExecutionBuilder setPnfUuid(String pnfUuid) {
110             this.pnfUuid = pnfUuid;
111             return this;
112         }
113
114         public DelegateExecutionBuilder setServiceInstanceId(String serviceInstanceId) {
115             this.serviceInstanceId = serviceInstanceId;
116             return this;
117         }
118
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);
125             return execution;
126         }
127     }
128 }