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 / CheckAaiForPnfCorrelationIdDelegateTest.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.mockito.ArgumentMatchers.any;
24 import static org.mockito.ArgumentMatchers.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.PnfManagementTestImpl.ID_WITHOUT_ENTRY;
29 import static org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementTestImpl.ID_WITH_ENTRY;
30 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.AAI_CONTAINS_INFO_ABOUT_PNF;
31 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID;
32 import org.camunda.bpm.engine.delegate.BpmnError;
33 import org.camunda.bpm.engine.delegate.DelegateExecution;
34 import org.junit.Before;
35 import org.junit.Rule;
36 import org.junit.Test;
37 import org.junit.experimental.runners.Enclosed;
38 import org.junit.rules.ExpectedException;
39 import org.junit.runner.RunWith;
40 import org.onap.so.bpmn.core.WorkflowException;
41
42 @RunWith(Enclosed.class)
43 public class CheckAaiForPnfCorrelationIdDelegateTest {
44
45     public static class ConnectionOkTests {
46
47         private CheckAaiForPnfCorrelationIdDelegate delegate;
48
49         @Rule
50         public ExpectedException expectedException = ExpectedException.none();
51
52         @Before
53         public void setUp() {
54             delegate = new CheckAaiForPnfCorrelationIdDelegate();
55             delegate.setPnfManagement(new PnfManagementTestImpl());
56         }
57
58         @Test
59         public void shouldThrowExceptionWhenPnfCorrelationIdIsNotSet() throws Exception {
60             // given
61             DelegateExecution execution = mock(DelegateExecution.class);
62             when(execution.getVariable(PNF_CORRELATION_ID)).thenReturn(null);
63             when(execution.getVariable("testProcessKey")).thenReturn("testProcessKeyValue");
64             // when, then
65             expectedException.expect(BpmnError.class);
66             delegate.execute(execution);
67             verify(execution).setVariable(eq("WorkflowException"), any(WorkflowException.class));
68         }
69
70         @Test
71         public void shouldSetCorrectVariablesWhenAaiDoesNotContainInfoAboutPnf() throws Exception {
72             // given
73             DelegateExecution execution = mock(DelegateExecution.class);
74             when(execution.getVariable(PNF_CORRELATION_ID)).thenReturn(ID_WITHOUT_ENTRY);
75             // when
76             delegate.execute(execution);
77             // then
78             verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, false);
79         }
80
81         @Test
82         public void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnfWithoutIp() throws Exception {
83             // given
84             DelegateExecution execution = mock(DelegateExecution.class);
85             when(execution.getVariable(PNF_CORRELATION_ID)).thenReturn(ID_WITH_ENTRY);
86             // when
87             delegate.execute(execution);
88             // then
89             verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, true);
90         }
91     }
92
93     public static class NoConnectionTests {
94
95         private CheckAaiForPnfCorrelationIdDelegate delegate;
96
97         @Rule
98         public ExpectedException expectedException = ExpectedException.none();
99
100         @Before
101         public void setUp() {
102             delegate = new CheckAaiForPnfCorrelationIdDelegate();
103             delegate.setPnfManagement(new PnfManagementThrowingException());
104         }
105
106         @Test
107         public void shouldThrowExceptionWhenIoExceptionOnConnectionToAai() throws Exception {
108             // given
109             DelegateExecution execution = mock(DelegateExecution.class);
110             when(execution.getVariable(PNF_CORRELATION_ID)).thenReturn(ID_WITH_ENTRY);
111             when(execution.getVariable("testProcessKey")).thenReturn("testProcessKey");
112             // when, then
113             expectedException.expect(BpmnError.class);
114             delegate.execute(execution);
115             verify(execution).setVariable(eq("WorkflowException"), any(WorkflowException.class));
116         }
117     }
118 }