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.PnfManagementTestImpl.ID_WITHOUT_ENTRY;
29 import static org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementTestImpl.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.PNF_CORRELATION_ID;
32 import org.camunda.bpm.engine.delegate.BpmnError;
33 import org.camunda.bpm.engine.delegate.DelegateExecution;
34 import org.junit.Before;
35 import org.junit.Rule;
36 import org.junit.Test;
37 import org.junit.experimental.runners.Enclosed;
38 import org.junit.rules.ExpectedException;
39 import org.junit.runner.RunWith;
40 import org.onap.so.bpmn.core.WorkflowException;
42 @RunWith(Enclosed.class)
43 public class CheckAaiForPnfCorrelationIdDelegateTest {
45 public static class ConnectionOkTests {
47 private CheckAaiForPnfCorrelationIdDelegate delegate;
50 public ExpectedException expectedException = ExpectedException.none();
54 delegate = new CheckAaiForPnfCorrelationIdDelegate();
55 delegate.setPnfManagement(new PnfManagementTestImpl());
59 public void shouldThrowExceptionWhenPnfCorrelationIdIsNotSet() throws Exception {
61 DelegateExecution execution = mock(DelegateExecution.class);
62 when(execution.getVariable(PNF_CORRELATION_ID)).thenReturn(null);
63 when(execution.getVariable("testProcessKey")).thenReturn("testProcessKeyValue");
65 expectedException.expect(BpmnError.class);
66 delegate.execute(execution);
67 verify(execution).setVariable(eq("WorkflowException"), any(WorkflowException.class));
71 public void shouldSetCorrectVariablesWhenAaiDoesNotContainInfoAboutPnf() throws Exception {
73 DelegateExecution execution = mock(DelegateExecution.class);
74 when(execution.getVariable(PNF_CORRELATION_ID)).thenReturn(ID_WITHOUT_ENTRY);
76 delegate.execute(execution);
78 verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, false);
82 public void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnfWithoutIp() throws Exception {
84 DelegateExecution execution = mock(DelegateExecution.class);
85 when(execution.getVariable(PNF_CORRELATION_ID)).thenReturn(ID_WITH_ENTRY);
87 delegate.execute(execution);
89 verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, true);
93 public static class NoConnectionTests {
95 private CheckAaiForPnfCorrelationIdDelegate delegate;
98 public ExpectedException expectedException = ExpectedException.none();
101 public void setUp() {
102 delegate = new CheckAaiForPnfCorrelationIdDelegate();
103 delegate.setPnfManagement(new PnfManagementThrowingException());
107 public void shouldThrowExceptionWhenIoExceptionOnConnectionToAai() throws Exception {
109 DelegateExecution execution = mock(DelegateExecution.class);
110 when(execution.getVariable(PNF_CORRELATION_ID)).thenReturn(ID_WITH_ENTRY);
111 when(execution.getVariable("testProcessKey")).thenReturn("testProcessKey");
113 expectedException.expect(BpmnError.class);
114 delegate.execute(execution);
115 verify(execution).setVariable(eq("WorkflowException"), any(WorkflowException.class));