blob: 0a739b3a8836eb17028c6a04df470dc1446a9717 (
plain)
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
|
package io.fd.honeycomb.lisp.translate.read.dump.executor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import com.google.common.collect.ImmutableList;
import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor;
import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecutionFailedException;
import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpCallFailedException;
import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpTimeoutException;
import io.fd.honeycomb.vpp.test.read.JvppDumpExecutorTest;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeoutException;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import io.fd.vpp.jvpp.core.dto.LispLocatorSetDetails;
import io.fd.vpp.jvpp.core.dto.LispLocatorSetDetailsReplyDump;
import io.fd.vpp.jvpp.core.dto.LispLocatorSetDump;
public class LocatorSetsDumpExecutorTest extends JvppDumpExecutorTest<LocatorSetsDumpExecutor> {
public static final byte[] LOCATOR_SET_NAME_BYTES = "loc-set".getBytes(StandardCharsets.UTF_8);
private LispLocatorSetDetailsReplyDump validDump;
@Captor
private ArgumentCaptor<LispLocatorSetDump> requestCaptor;
@Before
public void init() {
validDump = new LispLocatorSetDetailsReplyDump();
LispLocatorSetDetails detail = new LispLocatorSetDetails();
detail.lsIndex = 2;
detail.lsName = LOCATOR_SET_NAME_BYTES;
detail.context = 4;
validDump.lispLocatorSetDetails = ImmutableList.of(detail);
}
@Test
public void testExecuteDumpTimeout() throws Exception {
doThrowTimeoutExceptionWhen().lispLocatorSetDump(any());
try {
getExecutor().executeDump(EntityDumpExecutor.NO_PARAMS);
} catch (Exception e) {
assertTrue(e instanceof DumpTimeoutException);
assertTrue(e.getCause() instanceof TimeoutException);
return;
}
fail("Test should have thrown exception");
}
@Test(expected = DumpCallFailedException.class)
public void testExecuteDumpHalted() throws DumpExecutionFailedException {
doThrowFailExceptionWhen().lispLocatorSetDump(any());
getExecutor().executeDump(EntityDumpExecutor.NO_PARAMS);
}
@Test
public void testExecuteDump() throws DumpExecutionFailedException {
doReturnResponseWhen(validDump).lispLocatorSetDump(any());
final LispLocatorSetDetailsReplyDump replyDump = getExecutor().executeDump(EntityDumpExecutor.NO_PARAMS);
verify(api, times(1)).lispLocatorSetDump(requestCaptor.capture());
final LispLocatorSetDump request = requestCaptor.getValue();
assertNotNull(request);
assertEquals(1, request.filter);
assertNotNull(replyDump);
assertNotNull(replyDump.lispLocatorSetDetails);
assertEquals(1, replyDump.lispLocatorSetDetails.size());
final LispLocatorSetDetails detail = replyDump.lispLocatorSetDetails.get(0);
assertNotNull(detail);
assertEquals(4, detail.context);
assertEquals(2, detail.lsIndex);
assertEquals(LOCATOR_SET_NAME_BYTES, detail.lsName);
}
@Override
protected LocatorSetsDumpExecutor initExecutor() {
return new LocatorSetsDumpExecutor(api);
}
}
|