summaryrefslogtreecommitdiffstats
path: root/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/executor/MappingsDumpExecutorTest.java
diff options
context:
space:
mode:
authorJan Srnicek <jsrnicek@cisco.com>2016-09-28 09:33:32 +0200
committerMarek Gradzki <mgradzki@cisco.com>2016-09-28 07:51:13 +0000
commitcab279cb43bf47fb4a15987f5130c7a09df9abee (patch)
tree999f26efd2799975e2e5c2b38d47a485a4884f9a /lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/executor/MappingsDumpExecutorTest.java
parent482e75efafbc43ec4c7e5a0516b688dee721fc27 (diff)
Lisp test coverage increased to ~80%
Change-Id: Id4e9072ebb8d66e532e30c1dc3bb6036bfdc9012 Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/executor/MappingsDumpExecutorTest.java')
-rw-r--r--lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/executor/MappingsDumpExecutorTest.java121
1 files changed, 121 insertions, 0 deletions
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/executor/MappingsDumpExecutorTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/executor/MappingsDumpExecutorTest.java
new file mode 100644
index 000000000..85b22fa7e
--- /dev/null
+++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/executor/MappingsDumpExecutorTest.java
@@ -0,0 +1,121 @@
+package io.fd.honeycomb.lisp.translate.read.dump.executor;
+
+import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType;
+import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams.FilterType;
+import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams.MappingsDumpParamsBuilder;
+import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams.QuantityType;
+import static org.junit.Assert.assertArrayEquals;
+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.Matchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import com.google.common.collect.ImmutableList;
+import io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams;
+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.util.concurrent.TimeoutException;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.openvpp.jvpp.core.dto.LispEidTableDetails;
+import org.openvpp.jvpp.core.dto.LispEidTableDetailsReplyDump;
+import org.openvpp.jvpp.core.dto.LispEidTableDump;
+
+public class MappingsDumpExecutorTest extends JvppDumpExecutorTest<MappingsDumpExecutor> {
+
+ private static final byte[] EID = {-64, -88, 2, 1};
+
+ @Captor
+ private ArgumentCaptor<LispEidTableDump> requestCaptor;
+
+ private LispEidTableDetailsReplyDump validDump;
+ private MappingsDumpParams emptyParams;
+ private MappingsDumpParams validParams;
+
+ @Before
+ public void init() {
+ validDump = new LispEidTableDetailsReplyDump();
+
+ LispEidTableDetails detail = new LispEidTableDetails();
+ detail.action = 0;
+ detail.authoritative = 1;
+ detail.context = 4;
+ detail.eid = new byte[]{-64, -88, 2, 1};
+ detail.eidPrefixLen = 32;
+ detail.isLocal = 1;
+ detail.locatorSetIndex = 2;
+ detail.ttl = 7;
+ detail.vni = 2;
+
+ validDump.lispEidTableDetails = ImmutableList.of(detail);
+
+ emptyParams = MappingsDumpParamsBuilder.newInstance().build();
+ validParams =
+ MappingsDumpParamsBuilder.newInstance().setVni(2).setPrefixLength((byte) 32).setEidSet(QuantityType.ALL)
+ .setEid(EID)
+ .setEidType(EidType.IPV4).setFilter(FilterType.LOCAL).build();
+ }
+
+ @Test
+ public void testExecuteDumpTimeout() throws Exception {
+ doThrowTimeoutExceptionWhen().lispEidTableDump(any());
+ try {
+ getExecutor().executeDump(emptyParams);
+ } 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().lispEidTableDump(any());
+ getExecutor().executeDump(emptyParams);
+ }
+
+ @Test
+ public void testExecuteDump() throws DumpExecutionFailedException {
+ doReturnResponseWhen(validDump).lispEidTableDump(any());
+ final LispEidTableDetailsReplyDump reply = getExecutor().executeDump(validParams);
+ verify(api, times(1)).lispEidTableDump(requestCaptor.capture());
+
+ final LispEidTableDump request = requestCaptor.getValue();
+ assertNotNull(request);
+ assertEquals(2, request.vni);
+ assertEquals(QuantityType.ALL.getValue(), request.eidSet);
+ assertArrayEquals(EID, request.eid);
+ assertEquals(EidType.IPV4.getValue(), request.eidType);
+ assertEquals(FilterType.LOCAL.getValue(), request.filter);
+ assertEquals(32, request.prefixLength);
+
+ assertNotNull(reply);
+ assertEquals(1, reply.lispEidTableDetails.size());
+
+ final LispEidTableDetails detail = reply.lispEidTableDetails.get(0);
+
+ assertNotNull(detail);
+ assertEquals(0, detail.action);
+ assertEquals(1, detail.authoritative);
+ assertEquals(4, detail.context);
+ assertArrayEquals(EID, detail.eid);
+ assertEquals(32, detail.eidPrefixLen);
+ assertEquals(1, detail.isLocal);
+ assertEquals(2, detail.locatorSetIndex);
+ assertEquals(7, detail.ttl);
+ assertEquals(2, detail.vni);
+ }
+
+ @Override
+ protected MappingsDumpExecutor initExecutor() {
+ return new MappingsDumpExecutor(api);
+ }
+} \ No newline at end of file