1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
package org.onap.so.bpmn.infrastructure.pnf.tasks;
import org.camunda.bpm.engine.delegate.BpmnError;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.so.bpmn.common.BuildingBlockExecution;
import org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementTestImpl;
import org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementThrowingException;
import org.onap.so.bpmn.infrastructure.pnf.management.PnfManagement;
import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
import org.onap.so.client.exception.ExceptionBuilder;
import java.io.IOException;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.AAI_CONTAINS_INFO_ABOUT_PNF;
import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID;
import static org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementTestImpl.ID_WITHOUT_ENTRY;
import static org.onap.so.bpmn.infrastructure.pnf.delegate.PnfManagementTestImpl.ID_WITH_ENTRY;
import static org.onap.so.bpmn.infrastructure.pnf.tasks.PnfTasksUtils.PNF_UUID;
import static org.onap.so.bpmn.infrastructure.pnf.tasks.PnfTasksUtils.preparePnf;
@RunWith(Enclosed.class)
public class CheckAaiForPnfCorrelationIdTest {
@RunWith(MockitoJUnitRunner.class)
public static class ConnectionOkTests {
@Mock
private ExtractPojosForBB extractPojosForBB;
@Mock
private ExceptionBuilder exceptionUtil;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@InjectMocks
private CheckAaiForPnfCorrelationId task = new CheckAaiForPnfCorrelationId();
private PnfManagement pnfManagementTest = new PnfManagementTestImpl();
@Before
public void setUp() {
task.setPnfManagement(pnfManagementTest);
}
@Test
public void shouldThrowExceptionWhenPnfCorrelationIdIsNotSet() throws Exception {
// given
when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF))).thenReturn(preparePnf(null, PNF_UUID));
BuildingBlockExecution execution = mock(BuildingBlockExecution.class);
doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(eq(execution),
anyInt(), anyString());
// when, then
expectedException.expect(BpmnError.class);
task.execute(execution);
verify(exceptionUtil).buildAndThrowWorkflowException(eq(execution), anyInt(), anyString());
}
@Test
public void shouldSetCorrectVariablesWhenAaiDoesNotContainInfoAboutPnf() throws Exception {
// given
when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF)))
.thenReturn(preparePnf(ID_WITHOUT_ENTRY, PNF_UUID));
BuildingBlockExecution execution = mock(BuildingBlockExecution.class);
// when
task.execute(execution);
// then
verify(execution).setVariable(AAI_CONTAINS_INFO_ABOUT_PNF, false);
}
@Test
public void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnfWithoutIp() throws Exception {
// given
when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF)))
.thenReturn(preparePnf(ID_WITH_ENTRY, PNF_UUID));
BuildingBlockExecution execution = mock(BuildingBlockExecution.class);
// when
task.execute(execution);
// then
verify(execution).setVariable(AAI_CONTAINS_INFO_ABOUT_PNF, true);
}
}
@RunWith(MockitoJUnitRunner.class)
public static class NoConnectionTests {
@Mock
private ExtractPojosForBB extractPojosForBB;
@Mock
private ExceptionBuilder exceptionUtil;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@InjectMocks
private CheckAaiForPnfCorrelationId task = new CheckAaiForPnfCorrelationId();
private PnfManagement pnfManagementTest = new PnfManagementThrowingException();
@Before
public void setUp() throws Exception {
task.setPnfManagement(pnfManagementTest);
when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.PNF)))
.thenReturn(preparePnf(PNF_CORRELATION_ID, PNF_UUID));
}
@Test
public void shouldThrowExceptionWhenIoExceptionOnConnectionToAai() {
// given
BuildingBlockExecution execution = mock(BuildingBlockExecution.class);
doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(eq(execution),
anyInt(), any(IOException.class));
// when, then
expectedException.expect(BpmnError.class);
task.execute(execution);
verify(exceptionUtil).buildAndThrowWorkflowException(eq(execution), anyInt(), any(IOException.class));
}
}
}
|