1 package io.fd.honeycomb.lisp.translate.read.dump.executor;
4 import static org.junit.Assert.assertArrayEquals;
5 import static org.junit.Assert.assertEquals;
6 import static org.junit.Assert.assertNotNull;
7 import static org.junit.Assert.assertTrue;
8 import static org.junit.Assert.fail;
10 import com.google.common.collect.ImmutableList;
11 import io.fd.honeycomb.translate.read.ReadFailedException;
12 import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor;
13 import io.fd.honeycomb.vpp.test.read.JvppDumpExecutorTest;
14 import io.fd.vpp.jvpp.VppCallbackException;
15 import io.fd.vpp.jvpp.core.dto.LispMapResolverDetails;
16 import io.fd.vpp.jvpp.core.dto.LispMapResolverDetailsReplyDump;
17 import java.util.concurrent.TimeoutException;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.mockito.Mockito;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.map.resolvers.grouping.map.resolvers.MapResolver;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 public class MapResolversDumpExecutorTest extends JvppDumpExecutorTest<MapResolversDumpExecutor> {
27 private LispMapResolverDetailsReplyDump validDump;
29 private InstanceIdentifier identifier;
33 identifier = InstanceIdentifier.create(MapResolver.class);
34 validDump = new LispMapResolverDetailsReplyDump();
35 final LispMapResolverDetails details = new LispMapResolverDetails();
37 details.ipAddress = new byte[]{-64, -88, 5, 4};
40 validDump.lispMapResolverDetails = ImmutableList.of(details);
44 public void testExecuteDumpTimeout() throws Exception {
45 doThrowTimeoutExceptionWhen().lispMapResolverDump(Mockito.any());
47 getExecutor().executeDump(identifier, EntityDumpExecutor.NO_PARAMS);
48 } catch (ReadFailedException e) {
49 assertTrue(e.getCause() instanceof TimeoutException);
50 assertEquals(identifier, ((ReadFailedException) e).getFailedId());
53 fail("Test should have thrown ReadFailedException");
57 public void testExecuteDumpHalted() throws ReadFailedException {
58 doThrowFailExceptionWhen().lispMapResolverDump(Mockito.any());
60 getExecutor().executeDump(identifier, EntityDumpExecutor.NO_PARAMS);
61 } catch (ReadFailedException e) {
62 assertTrue(e.getCause() instanceof VppCallbackException);
63 assertEquals(identifier, ((ReadFailedException) e).getFailedId());
66 fail("Test should have thrown ReadFailedException");
70 public void testExecuteDump() throws ReadFailedException {
71 doReturnResponseWhen(validDump).lispMapResolverDump(Mockito.any());
72 final LispMapResolverDetailsReplyDump reply =
73 getExecutor().executeDump(identifier, EntityDumpExecutor.NO_PARAMS);
76 assertEquals(1, reply.lispMapResolverDetails.size());
78 final LispMapResolverDetails detail = reply.lispMapResolverDetails.get(0);
79 assertEquals(7, detail.context);
80 assertEquals(0, detail.isIpv6);
81 assertArrayEquals(new byte[]{-64, -88, 5, 4}, detail.ipAddress);
85 protected MapResolversDumpExecutor initExecutor() {
86 return new MapResolversDumpExecutor(api);