1 package org.onap.so.bpmn.infrastructure.pnf.tasks;
3 import org.camunda.bpm.engine.delegate.BpmnError;
4 import org.junit.Before;
7 import org.junit.experimental.runners.Enclosed;
8 import org.junit.rules.ExpectedException;
9 import org.junit.runner.RunWith;
10 import org.mockito.InjectMocks;
11 import org.mockito.Mock;
12 import org.mockito.junit.MockitoJUnitRunner;
13 import org.onap.so.bpmn.common.BuildingBlockExecution;
14 import org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementTestImpl;
15 import org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementThrowingException;
16 import org.onap.so.bpmn.infrastructure.pnf.management.PnfManagement;
17 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
18 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
19 import org.onap.so.client.exception.ExceptionBuilder;
20 import java.io.IOException;
21 import static org.mockito.ArgumentMatchers.any;
22 import static org.mockito.ArgumentMatchers.eq;
23 import static org.mockito.Mockito.anyInt;
24 import static org.mockito.Mockito.anyString;
25 import static org.mockito.Mockito.doThrow;
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.ExecutionVariableNames.AAI_CONTAINS_INFO_ABOUT_PNF;
30 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID;
31 import static org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementTestImpl.ID_WITHOUT_ENTRY;
32 import static org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementTestImpl.ID_WITH_ENTRY;
33 import static org.onap.so.bpmn.infrastructure.pnf.tasks.PnfTasksUtils.PNF_UUID;
34 import static org.onap.so.bpmn.infrastructure.pnf.tasks.PnfTasksUtils.preparePnf;
36 @RunWith(Enclosed.class)
37 public class CheckAaiForPnfCorrelationIdTest {
39 @RunWith(MockitoJUnitRunner.class)
40 public static class ConnectionOkTests {
43 private ExtractPojosForBB extractPojosForBB;
45 private ExceptionBuilder exceptionUtil;
47 public ExpectedException expectedException = ExpectedException.none();
50 private CheckAaiForPnfCorrelationId task = new CheckAaiForPnfCorrelationId();
51 private PnfManagement pnfManagementTest = new PnfManagementTestImpl();
55 task.setPnfManagement(pnfManagementTest);
59 public void shouldThrowExceptionWhenPnfCorrelationIdIsNotSet() throws Exception {
61 when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF))).thenReturn(preparePnf(null, PNF_UUID));
62 BuildingBlockExecution execution = mock(BuildingBlockExecution.class);
63 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(eq(execution),
64 anyInt(), anyString());
66 expectedException.expect(BpmnError.class);
67 task.execute(execution);
68 verify(exceptionUtil).buildAndThrowWorkflowException(eq(execution), anyInt(), anyString());
72 public void shouldSetCorrectVariablesWhenAaiDoesNotContainInfoAboutPnf() throws Exception {
74 when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF)))
75 .thenReturn(preparePnf(ID_WITHOUT_ENTRY, PNF_UUID));
76 BuildingBlockExecution execution = mock(BuildingBlockExecution.class);
78 task.execute(execution);
80 verify(execution).setVariable(AAI_CONTAINS_INFO_ABOUT_PNF, false);
84 public void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnfWithoutIp() throws Exception {
86 when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF)))
87 .thenReturn(preparePnf(ID_WITH_ENTRY, PNF_UUID));
88 BuildingBlockExecution execution = mock(BuildingBlockExecution.class);
90 task.execute(execution);
92 verify(execution).setVariable(AAI_CONTAINS_INFO_ABOUT_PNF, true);
96 @RunWith(MockitoJUnitRunner.class)
97 public static class NoConnectionTests {
100 private ExtractPojosForBB extractPojosForBB;
102 private ExceptionBuilder exceptionUtil;
104 public ExpectedException expectedException = ExpectedException.none();
107 private CheckAaiForPnfCorrelationId task = new CheckAaiForPnfCorrelationId();
108 private PnfManagement pnfManagementTest = new PnfManagementThrowingException();
111 public void setUp() throws Exception {
112 task.setPnfManagement(pnfManagementTest);
113 when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF)))
114 .thenReturn(preparePnf(PNF_CORRELATION_ID, PNF_UUID));
118 public void shouldThrowExceptionWhenIoExceptionOnConnectionToAai() {
120 BuildingBlockExecution execution = mock(BuildingBlockExecution.class);
121 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(eq(execution),
122 anyInt(), any(IOException.class));
124 expectedException.expect(BpmnError.class);
125 task.execute(execution);
126 verify(exceptionUtil).buildAndThrowWorkflowException(eq(execution), anyInt(), any(IOException.class));