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.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.onap.so.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITHOUT_ENTRY;
30 import static org.onap.so.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_ENTRY;
31 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.AAI_CONTAINS_INFO_ABOUT_PNF;
32 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID;
34 import org.camunda.bpm.engine.delegate.BpmnError;
35 import org.camunda.bpm.engine.delegate.DelegateExecution;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.junit.experimental.runners.Enclosed;
39 import org.junit.runner.RunWith;
40 import org.onap.so.bpmn.core.WorkflowException;
42 @RunWith(Enclosed.class)
43 public class CheckAaiForCorrelationIdDelegateTest {
45 public static class ConnectionOkTests {
47 private CheckAaiForCorrelationIdDelegate delegate;
51 delegate = new CheckAaiForCorrelationIdDelegate();
52 delegate.setAaiConnection(new AaiConnectionTestImpl());
56 public void shouldThrowExceptionWhenCorrelationIdIsNotSet() {
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 verify(execution).setVariable(eq("WorkflowException"), any(WorkflowException.class));
67 public void shouldSetCorrectVariablesWhenAaiDoesNotContainInfoAboutPnf() throws Exception {
69 DelegateExecution execution = mock(DelegateExecution.class);
70 when(execution.getVariable(CORRELATION_ID)).thenReturn(ID_WITHOUT_ENTRY);
72 delegate.execute(execution);
74 verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, false);
78 public void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnfWithoutIp() throws Exception {
80 DelegateExecution execution = mock(DelegateExecution.class);
81 when(execution.getVariable(CORRELATION_ID)).thenReturn(ID_WITH_ENTRY);
83 delegate.execute(execution);
85 verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, true);
89 public static class NoConnectionTests {
91 private CheckAaiForCorrelationIdDelegate delegate;
95 delegate = new CheckAaiForCorrelationIdDelegate();
96 delegate.setAaiConnection(new AaiConnectionThrowingException());
100 public void shouldThrowExceptionWhenIoExceptionOnConnectionToAai() {
102 DelegateExecution execution = mock(DelegateExecution.class);
103 when(execution.getVariable(CORRELATION_ID)).thenReturn(ID_WITH_ENTRY);
104 when(execution.getVariable("testProcessKey")).thenReturn("testProcessKey");
106 assertThatThrownBy(() -> delegate.execute(execution)).isInstanceOf(BpmnError.class);
107 verify(execution).setVariable(eq("WorkflowException"), any(WorkflowException.class));