Merge "Reorder modifiers"
[so.git] / bpmn / MSOInfrastructureBPMN / src / test / java / org / openecomp / mso / 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.openecomp.mso.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.openecomp.mso.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID;
29 import static org.openecomp.mso.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.Before;
34 import org.junit.Test;
35
36 public class PnfCheckInputsTest {
37
38     private PnfCheckInputs delegate;
39
40     @Before
41     public void setUp() throws Exception {
42         delegate = new PnfCheckInputs();
43     }
44
45     private DelegateExecution mockDelegateExecution() {
46         DelegateExecution delegateExecution = mock(DelegateExecution.class);
47         when(delegateExecution.getVariable("testProcessKey")).thenReturn("testProcessKeyValue");
48         return delegateExecution;
49     }
50
51     @Test
52     public void shouldThrowException_whenPnfIdNotSet() throws Exception {
53         // given
54         DelegateExecution delegateExecution = mockDelegateExecution();
55         // when, then
56         assertThatThrownBy(() -> delegate.execute(delegateExecution)).isInstanceOf(BpmnError.class);
57     }
58
59     private DelegateExecution mockDelegateExecutionWithCorrelationId() {
60         DelegateExecution delegateExecution = mockDelegateExecution();
61         when(delegateExecution.getVariable(CORRELATION_ID)).thenReturn("testCorrelationId");
62         return delegateExecution;
63     }
64
65     @Test
66     public void shouldThrowException_whenTimeoutIsNotSetAndDefaultIsNotDefined() throws Exception {
67         // given
68         DelegateExecution delegateExecution = mockDelegateExecutionWithCorrelationId();
69         // when, then
70         assertThatThrownBy(() -> delegate.execute(delegateExecution)).isInstanceOf(BpmnError.class);
71     }
72
73     @Test
74     public void shouldSetDefaultTimeout_whenTimeoutIsNotSet() throws Exception {
75         // given
76         String defaultTimeout = "T1D";
77         delegate.setDefaultTimeout(defaultTimeout);
78         DelegateExecution delegateExecution = mockDelegateExecutionWithCorrelationId();
79         // when
80         delegate.execute(delegateExecution);
81         // then
82         verify(delegateExecution).setVariable(eq(TIMEOUT_FOR_NOTIFICATION), eq(defaultTimeout));
83     }
84 }