2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.mso.bpmn.infrastructure.pnf.delegate;
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;
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;
45 @RunWith(Enclosed.class)
46 public class CheckAaiForCorrelationIdDelegateTest {
48 @RunWith(SpringRunner.class)
49 @SpringBootTest(classes = {CheckAaiForCorrelationIdDelegate.class, AaiConnectionTestImpl.class})
50 public static class ConnectionOkTests {
53 private CheckAaiForCorrelationIdDelegate delegate;
56 public void shouldThrowExceptionWhenCorrelationIdIsNotSet() throws Exception {
58 DelegateExecution execution = mock(DelegateExecution.class);
59 when(execution.getVariable(CORRELATION_ID)).thenReturn(null);
60 when(execution.getVariable("testProcessKey")).thenReturn("testProcessKeyValue");
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));
68 public void shouldSetCorrectVariablesWhenAaiDoesNotContainInfoAboutPnf() throws Exception {
70 DelegateExecution execution = mock(DelegateExecution.class);
71 when(execution.getVariable(CORRELATION_ID)).thenReturn(ID_WITHOUT_ENTRY);
73 delegate.execute(execution);
75 verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, false);
79 public void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnf() throws Exception {
80 shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnf(ID_WITH_ENTRY_AND_IP);
84 public void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnfWithIpV6() throws Exception {
85 shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnf(ID_WITH_IP_V6);
88 private void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnf(String id) throws Exception {
90 DelegateExecution execution = mock(DelegateExecution.class);
91 when(execution.getVariable(CORRELATION_ID)).thenReturn(id);
93 delegate.execute(execution);
95 verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, true);
96 verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_IP, true);
100 public void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnfWithoutIp() throws Exception {
102 DelegateExecution execution = mock(DelegateExecution.class);
103 when(execution.getVariable(CORRELATION_ID)).thenReturn(ID_WITH_ENTRY_NO_IP);
105 delegate.execute(execution);
107 verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, true);
108 verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_IP, false);
113 @RunWith(SpringRunner.class)
114 @SpringBootTest(classes = {CheckAaiForCorrelationIdDelegate.class, AaiConnectionThrowingException.class})
115 public static class NoConnectionTests {
118 private CheckAaiForCorrelationIdDelegate delegate;
121 public void shouldThrowExceptionWhenSSADFDSADSFDS() throws Exception {
123 DelegateExecution execution = mock(DelegateExecution.class);
124 when(execution.getVariable(CORRELATION_ID)).thenReturn(ID_WITH_ENTRY_NO_IP);
126 assertThatThrownBy(() -> delegate.execute(execution)).isInstanceOf(BpmnError.class);