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.onap.so.bpmn.infrastructure.pnf.delegate;
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.AaiConnectionTestImpl.ID_WITHOUT_ENTRY;
29 import static org.onap.so.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.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.CORRELATION_ID;
33 import org.camunda.bpm.engine.delegate.BpmnError;
34 import org.camunda.bpm.engine.delegate.DelegateExecution;
35 import org.junit.Before;
36 import org.junit.Rule;
37 import org.junit.Test;
38 import org.junit.experimental.runners.Enclosed;
39 import org.junit.rules.ExpectedException;
40 import org.junit.runner.RunWith;
41 import org.onap.so.bpmn.core.WorkflowException;
43 @RunWith(Enclosed.class)
44 public class CheckAaiForCorrelationIdDelegateTest {
46 public static class ConnectionOkTests {
48 private CheckAaiForCorrelationIdDelegate delegate;
51 public ExpectedException expectedException = ExpectedException.none();
55 delegate = new CheckAaiForCorrelationIdDelegate();
56 delegate.setAaiConnection(new AaiConnectionTestImpl());
60 public void shouldThrowExceptionWhenCorrelationIdIsNotSet() throws Exception {
62 DelegateExecution execution = mock(DelegateExecution.class);
63 when(execution.getVariable(CORRELATION_ID)).thenReturn(null);
64 when(execution.getVariable("testProcessKey")).thenReturn("testProcessKeyValue");
66 expectedException.expect(BpmnError.class);
67 delegate.execute(execution);
68 verify(execution).setVariable(eq("WorkflowException"), any(WorkflowException.class));
72 public void shouldSetCorrectVariablesWhenAaiDoesNotContainInfoAboutPnf() throws Exception {
74 DelegateExecution execution = mock(DelegateExecution.class);
75 when(execution.getVariable(CORRELATION_ID)).thenReturn(ID_WITHOUT_ENTRY);
77 delegate.execute(execution);
79 verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, false);
83 public void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnfWithoutIp() throws Exception {
85 DelegateExecution execution = mock(DelegateExecution.class);
86 when(execution.getVariable(CORRELATION_ID)).thenReturn(ID_WITH_ENTRY);
88 delegate.execute(execution);
90 verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, true);
94 public static class NoConnectionTests {
96 private CheckAaiForCorrelationIdDelegate delegate;
99 public ExpectedException expectedException = ExpectedException.none();
102 public void setUp() {
103 delegate = new CheckAaiForCorrelationIdDelegate();
104 delegate.setAaiConnection(new AaiConnectionThrowingException());
108 public void shouldThrowExceptionWhenIoExceptionOnConnectionToAai() throws Exception {
110 DelegateExecution execution = mock(DelegateExecution.class);
111 when(execution.getVariable(CORRELATION_ID)).thenReturn(ID_WITH_ENTRY);
112 when(execution.getVariable("testProcessKey")).thenReturn("testProcessKey");
114 expectedException.expect(BpmnError.class);
115 delegate.execute(execution);
116 verify(execution).setVariable(eq("WorkflowException"), any(WorkflowException.class));