Merge "remove unused code"
[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.mockito.Matchers.eq;
25 import static org.mockito.Mockito.mock;
26 import static org.mockito.Mockito.verify;
27 import static org.mockito.Mockito.when;
28 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID;
29 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.TIMEOUT_FOR_NOTIFICATION;
30
31 import org.camunda.bpm.engine.delegate.BpmnError;
32 import org.camunda.bpm.engine.delegate.DelegateExecution;
33 import org.junit.Test;
34
35 public class PnfCheckInputsTest {
36
37     private static final String DEFAULT_TIMEOUT = "P1D";
38
39     private DelegateExecution mockDelegateExecution() {
40         DelegateExecution delegateExecution = mock(DelegateExecution.class);
41         when(delegateExecution.getVariable("testProcessKey")).thenReturn("testProcessKeyValue");
42         return delegateExecution;
43     }
44
45     @Test
46     public void shouldThrowException_whenPnfIdNotSet() {
47         // given
48         PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
49         DelegateExecution delegateExecution = mockDelegateExecution();
50         // when, then
51         assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
52     }
53
54     @Test
55     public void shouldThrowException_whenPnfIdIsEmptyString() throws Exception {
56         // given
57         PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
58         DelegateExecution delegateExecution = mockDelegateExecution();
59         when(delegateExecution.getVariable(CORRELATION_ID)).thenReturn("");
60         // when, then
61         assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
62     }
63
64     private DelegateExecution mockDelegateExecutionWithCorrelationId() {
65         DelegateExecution delegateExecution = mockDelegateExecution();
66         when(delegateExecution.getVariable(CORRELATION_ID)).thenReturn("testCorrelationId");
67         return delegateExecution;
68     }
69
70     @Test
71     public void shouldThrowException_whenTimeoutIsNotSetAndDefaultIsNotDefined() {
72         // given
73         PnfCheckInputs testedObject = new PnfCheckInputs(null);
74         DelegateExecution delegateExecution = mockDelegateExecutionWithCorrelationId();
75         // when, then
76         assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
77     }
78
79     @Test
80     public void shouldThrowException_whenTimeoutIsEmptyStringAndDefaultIsNotDefined() throws Exception {
81         // given
82         PnfCheckInputs testedObject = new PnfCheckInputs(null);
83         DelegateExecution delegateExecution = mockDelegateExecutionWithCorrelationId();
84         when(delegateExecution.getVariable(TIMEOUT_FOR_NOTIFICATION)).thenReturn("");
85         // when, then
86         assertThatThrownBy(() -> testedObject.execute(delegateExecution)).isInstanceOf(BpmnError.class);
87     }
88
89     @Test
90     public void shouldSetDefaultTimeout_whenTimeoutIsNotSet() {
91         // given
92         PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
93         DelegateExecution delegateExecution = mockDelegateExecutionWithCorrelationId();
94         // when
95         testedObject.execute(delegateExecution);
96         // then
97         verify(delegateExecution).setVariable(eq(TIMEOUT_FOR_NOTIFICATION), eq(DEFAULT_TIMEOUT));
98     }
99 }