summaryrefslogtreecommitdiffstats
path: root/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/executor/VniTableDumpExecutorTest.java
blob: 13033bf65b481361d6b0990a70b972fec593fdeb (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
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 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.util.concurrent.TimeoutException;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.openvpp.jvpp.core.dto.LispEidTableMapDetails;
import org.openvpp.jvpp.core.dto.LispEidTableMapDetailsReplyDump;


public class VniTableDumpExecutorTest extends JvppDumpExecutorTest<VniTableDumpExecutor> {

    private LispEidTableMapDetailsReplyDump validDump;

    @Before
    public void init() {
        validDump = new LispEidTableMapDetailsReplyDump();
        LispEidTableMapDetails detail = new LispEidTableMapDetails();
        detail.dpTable = 1;
        detail.vni = 2;
        detail.context = 4;
        validDump.lispEidTableMapDetails = ImmutableList.of(detail);
    }

    @Test(expected = DumpCallFailedException.class)
    public void testExecuteDumpFail() throws DumpExecutionFailedException {
        doThrowFailExceptionWhen().lispEidTableMapDump(Mockito.any());
        getExecutor().executeDump(EntityDumpExecutor.NO_PARAMS);
    }


    @Test
    public void testExecuteDumpTimeout() throws Exception {
        doThrowTimeoutExceptionWhen().lispEidTableMapDump(Mockito.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
    public void testExecuteDump() throws DumpExecutionFailedException {

        doReturnResponseWhen(validDump).lispEidTableMapDump(Mockito.any());
        final LispEidTableMapDetailsReplyDump reply = getExecutor().executeDump(EntityDumpExecutor.NO_PARAMS);

        assertNotNull(reply);
        assertEquals(1, reply.lispEidTableMapDetails.size());
        final LispEidTableMapDetails detail = reply.lispEidTableMapDetails.get(0);

        assertEquals(4, detail.context);
        assertEquals(1, detail.dpTable);
        assertEquals(2, detail.vni);
    }

    @Override
    protected VniTableDumpExecutor initExecutor() {
        return new VniTableDumpExecutor(api);
    }
}