1888831e2e3b5ac9ff91dee402b69d06b193abc7
[so.git] /
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.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.TIMEOUT_FOR_NOTIFICATION;
28
29 import java.util.UUID;
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 DEFAULT_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
42     private DelegateExecution delegateExecution;
43
44     @Before
45     public void setUp() {
46         delegateExecution = new DelegateExecutionFake();
47         delegateExecution.setVariable("testProcessKey", "testProcessKeyValue");
48     }
49
50     @Test
51     public void shouldThrowException_whenCorrelationIdNotSet() {
52         PnfCheckInputs testedObject = prepareExecutionForCorrelationId(null);
53         assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
54     }
55
56     @Test
57     public void shouldThrowException_whenTimeoutIsEmptyStringAndDefaultIsNotDefined() {
58         PnfCheckInputs testedObject = prepareExecutionForTimeout(null, "");
59         assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
60     }
61
62     @Test
63     public void shouldSetDefaultTimeout_whenTimeoutIsNotSet() {
64         PnfCheckInputs testedObject = prepareExecutionForTimeout(DEFAULT_TIMEOUT, null);
65         testedObject.execute(delegateExecution);
66         assertThat(delegateExecution.getVariable(TIMEOUT_FOR_NOTIFICATION)).isEqualTo(DEFAULT_TIMEOUT);
67     }
68
69     @Test
70     public void shouldThrowException_whenPnfUuidIsNotSet() {
71         PnfCheckInputs testedObject = prepareExecutionForUuid(null);
72         assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
73     }
74
75     @Test
76     public void shouldThrowException_whenPnfUuidIsEmptyString() {
77         PnfCheckInputs testedObject = prepareExecutionForUuid("");
78         assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
79     }
80
81     @Test
82     public void shouldThrowException_whenPnfUuidIsReservedUuid() {
83         PnfCheckInputs testedObject = prepareExecutionForUuid(RESERVED_UUID);
84         assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
85     }
86
87     private PnfCheckInputs prepareExecutionForCorrelationId(String correlationId) {
88         PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
89         delegateExecution.setVariable(CORRELATION_ID, correlationId);
90         delegateExecution.setVariable(PNF_UUID, VALID_UUID);
91         return testedObject;
92     }
93
94     private PnfCheckInputs prepareExecutionForTimeout(String defaultTimeout, String timeout) {
95         PnfCheckInputs testedObject = new PnfCheckInputs(defaultTimeout);
96         delegateExecution.setVariable(CORRELATION_ID, "testCorrelationId");
97         delegateExecution.setVariable(PNF_UUID, VALID_UUID);
98         delegateExecution.setVariable(TIMEOUT_FOR_NOTIFICATION, timeout);
99         return testedObject;
100     }
101
102     private PnfCheckInputs prepareExecutionForUuid(String uuid) {
103         PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
104         delegateExecution.setVariable(CORRELATION_ID, "testCorrelationId");
105         delegateExecution.setVariable(PNF_UUID, uuid);
106         return testedObject;
107     }
108 }