d98a3958383466785b5c751f7de84869d1e8bb18
[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.openecomp.mso.bpmn.infrastructure.pnf.delegate;
22
23 import static org.assertj.core.api.Assertions.assertThatThrownBy;
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.verify;
26 import static org.mockito.Mockito.when;
27 import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.DEFAULT_IP;
28 import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITHOUT_ENTRY;
29 import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_ENTRY_AND_IP;
30 import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_ENTRY_NO_IP;
31 import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_IP_V6;
32 import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.AAI_CONTAINS_INFO_ABOUT_IP;
33 import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.AAI_CONTAINS_INFO_ABOUT_PNF;
34 import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID;
35
36 import org.camunda.bpm.engine.delegate.BpmnError;
37 import org.camunda.bpm.engine.delegate.DelegateExecution;
38 import org.junit.Test;
39 import org.junit.experimental.runners.Enclosed;
40 import org.junit.runner.RunWith;
41 import org.springframework.beans.factory.annotation.Autowired;
42 import org.springframework.boot.test.context.SpringBootTest;
43 import org.springframework.test.context.junit4.SpringRunner;
44
45 @RunWith(Enclosed.class)
46 public class CheckAaiForCorrelationIdDelegateTest {
47
48     @RunWith(SpringRunner.class)
49     @SpringBootTest(classes = {CheckAaiForCorrelationIdDelegate.class, AaiConnectionTestImpl.class})
50     public static class ConnectionOkTests {
51
52         @Autowired
53         private CheckAaiForCorrelationIdDelegate delegate;
54
55         @Test
56         public void shouldThrowExceptionWhenCorrelationIdIsNotSet() throws Exception {
57             // given
58             DelegateExecution execution = mock(DelegateExecution.class);
59             when(execution.getVariable(CORRELATION_ID)).thenReturn(null);
60             when(execution.getVariable("testProcessKey")).thenReturn("testProcessKeyValue");
61             // when, then
62             assertThatThrownBy(() -> delegate.execute(execution)).isInstanceOf(BpmnError.class);
63             // todo: uncomment line below after fixing Execution -> DelecateExecution in groovy scripts
64 //        verify(execution).setVariable(eq("WorkflowException"), any(WorkflowException.class));
65         }
66
67         @Test
68         public void shouldSetCorrectVariablesWhenAaiDoesNotContainInfoAboutPnf() throws Exception {
69             // given
70             DelegateExecution execution = mock(DelegateExecution.class);
71             when(execution.getVariable(CORRELATION_ID)).thenReturn(ID_WITHOUT_ENTRY);
72             // when
73             delegate.execute(execution);
74             // then
75             verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, false);
76         }
77
78         @Test
79         public void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnf() throws Exception {
80             shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnf(ID_WITH_ENTRY_AND_IP);
81         }
82
83         @Test
84         public void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnfWithIpV6() throws Exception {
85             shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnf(ID_WITH_IP_V6);
86         }
87
88         private void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnf(String id) throws Exception {
89             // given
90             DelegateExecution execution = mock(DelegateExecution.class);
91             when(execution.getVariable(CORRELATION_ID)).thenReturn(id);
92             // when
93             delegate.execute(execution);
94             // then
95             verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, true);
96             verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_IP, true);
97         }
98
99         @Test
100         public void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnfWithoutIp() throws Exception {
101             // given
102             DelegateExecution execution = mock(DelegateExecution.class);
103             when(execution.getVariable(CORRELATION_ID)).thenReturn(ID_WITH_ENTRY_NO_IP);
104             // when
105             delegate.execute(execution);
106             // then
107             verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, true);
108             verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_IP, false);
109         }
110     }
111
112
113     @RunWith(SpringRunner.class)
114     @SpringBootTest(classes = {CheckAaiForCorrelationIdDelegate.class, AaiConnectionThrowingException.class})
115     public static class NoConnectionTests {
116
117         @Autowired
118         private CheckAaiForCorrelationIdDelegate delegate;
119
120         @Test
121         public void shouldThrowExceptionWhenSSADFDSADSFDS() throws Exception {
122             // given
123             DelegateExecution execution = mock(DelegateExecution.class);
124             when(execution.getVariable(CORRELATION_ID)).thenReturn(ID_WITH_ENTRY_NO_IP);
125             // when, then
126             assertThatThrownBy(() -> delegate.execute(execution)).isInstanceOf(BpmnError.class);
127         }
128     }
129 }