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.Matchers.any;
25 import static org.mockito.Matchers.eq;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.verify;
28 import static org.mockito.Mockito.when;
29 import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITHOUT_ENTRY;
30 import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_ENTRY_AND_IP;
31 import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_ENTRY_NO_IP;
32 import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_IP_V6;
33 import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.AAI_CONTAINS_INFO_ABOUT_IP;
34 import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.AAI_CONTAINS_INFO_ABOUT_PNF;
35 import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID;
37 import org.camunda.bpm.engine.delegate.BpmnError;
38 import org.camunda.bpm.engine.delegate.DelegateExecution;
39 import org.junit.Test;
40 import org.junit.experimental.runners.Enclosed;
41 import org.junit.runner.RunWith;
42 import org.openecomp.mso.bpmn.core.WorkflowException;
43 import org.springframework.beans.factory.annotation.Autowired;
44 import org.springframework.boot.test.context.SpringBootTest;
45 import org.springframework.test.context.junit4.SpringRunner;
47 @RunWith(Enclosed.class)
48 public class CheckAaiForCorrelationIdDelegateTest {
50 @RunWith(SpringRunner.class)
51 @SpringBootTest(classes = {CheckAaiForCorrelationIdDelegate.class, AaiConnectionTestImpl.class})
52 public static class ConnectionOkTests {
55 private CheckAaiForCorrelationIdDelegate delegate;
58 public void shouldThrowExceptionWhenCorrelationIdIsNotSet() throws Exception {
60 DelegateExecution execution = mock(DelegateExecution.class);
61 when(execution.getVariable(CORRELATION_ID)).thenReturn(null);
62 when(execution.getVariable("testProcessKey")).thenReturn("testProcessKeyValue");
64 assertThatThrownBy(() -> delegate.execute(execution)).isInstanceOf(BpmnError.class);
65 verify(execution).setVariable(eq("WorkflowException"), any(WorkflowException.class));
69 public void shouldSetCorrectVariablesWhenAaiDoesNotContainInfoAboutPnf() throws Exception {
71 DelegateExecution execution = mock(DelegateExecution.class);
72 when(execution.getVariable(CORRELATION_ID)).thenReturn(ID_WITHOUT_ENTRY);
74 delegate.execute(execution);
76 verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, false);
80 public void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnf() throws Exception {
81 shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnf(ID_WITH_ENTRY_AND_IP);
85 public void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnfWithIpV6() throws Exception {
86 shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnf(ID_WITH_IP_V6);
89 private void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnf(String id) throws Exception {
91 DelegateExecution execution = mock(DelegateExecution.class);
92 when(execution.getVariable(CORRELATION_ID)).thenReturn(id);
94 delegate.execute(execution);
96 verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, true);
97 verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_IP, true);
101 public void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnfWithoutIp() throws Exception {
103 DelegateExecution execution = mock(DelegateExecution.class);
104 when(execution.getVariable(CORRELATION_ID)).thenReturn(ID_WITH_ENTRY_NO_IP);
106 delegate.execute(execution);
108 verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, true);
109 verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_IP, false);
114 @RunWith(SpringRunner.class)
115 @SpringBootTest(classes = {CheckAaiForCorrelationIdDelegate.class, AaiConnectionThrowingException.class})
116 public static class NoConnectionTests {
119 private CheckAaiForCorrelationIdDelegate delegate;
122 public void shouldThrowExceptionWhenIoExceptionOnConnectionToAai() throws Exception {
124 DelegateExecution execution = mock(DelegateExecution.class);
125 when(execution.getVariable(CORRELATION_ID)).thenReturn(ID_WITH_ENTRY_NO_IP);
126 when(execution.getVariable("testProcessKey")).thenReturn("testProcessKey");
128 assertThatThrownBy(() -> delegate.execute(execution)).isInstanceOf(BpmnError.class);
129 verify(execution).setVariable(eq("WorkflowException"), any(WorkflowException.class));