955a5a01a6861aa403e403bcb59d795823692f5f
[honeycomb.git] / lisp / lisp2vpp / src / test / java / io / fd / honeycomb / lisp / translate / read / VrfSubtableCustomizerTest.java
1 package io.fd.honeycomb.lisp.translate.read;
2
3
4 import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.SubtableDumpParams.MapLevel.L3;
5 import static org.junit.Assert.assertEquals;
6 import static org.junit.Assert.assertNotNull;
7 import static org.junit.Assert.assertNull;
8 import static org.junit.Assert.assertTrue;
9 import static org.junit.Assert.fail;
10
11 import io.fd.honeycomb.lisp.translate.read.trait.SubtableReaderTestCase;
12 import io.fd.honeycomb.translate.read.ReadFailedException;
13 import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
14 import io.fd.vpp.jvpp.VppCallbackException;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTable;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableKey;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtableBuilder;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24
25 public class VrfSubtableCustomizerTest extends SubtableReaderTestCase<VrfSubtable, VrfSubtableBuilder> {
26
27     private InstanceIdentifier<VrfSubtable> validId;
28
29     public VrfSubtableCustomizerTest() {
30         super(VrfSubtable.class, VrfSubtableBuilder.class);
31     }
32
33     @Before
34     public void init() {
35         validId = InstanceIdentifier.create(EidTable.class).child(VniTable.class, new VniTableKey(expectedVni))
36                 .child(VrfSubtable.class);
37     }
38
39     @Test
40     public void testReadCurrentSuccessfull() throws ReadFailedException {
41         doReturnValidNonEmptyDataOnDump();
42         VrfSubtableBuilder builder = new VrfSubtableBuilder();
43         customizer.readCurrentAttributes(validId, builder, ctx);
44
45         verifyLispEidTableMapDumpCalled(L3);
46
47         final VrfSubtable subtable = builder.build();
48         assertNotNull(subtable);
49         assertEquals(expectedTableId, subtable.getTableId().longValue());
50     }
51
52     @Test
53     public void testReadCurrentEmptyDump() throws ReadFailedException {
54         doReturnEmptyDataOnDump();
55         VrfSubtableBuilder builder = new VrfSubtableBuilder();
56         customizer.readCurrentAttributes(validId, builder, ctx);
57
58         verifyLispEidTableMapDumpCalled(L3);
59
60         final VrfSubtable subtable = builder.build();
61         assertNotNull(subtable);
62         assertNull(subtable.getTableId());
63     }
64
65     @Test
66     public void testReadCurrentFailed() {
67         doThrowOnDump();
68         VrfSubtableBuilder builder = new VrfSubtableBuilder();
69         try {
70             customizer.readCurrentAttributes(validId, builder, ctx);
71         } catch (ReadFailedException e) {
72             assertTrue(e.getCause() instanceof VppCallbackException);
73             assertTrue(builder.getTableId() == null);
74             verifyLispEidTableMapDumpNotCalled();
75
76             return;
77         }
78
79         fail("Test should throw ReadFailedException");
80     }
81
82     @Override
83     protected ReaderCustomizer<VrfSubtable, VrfSubtableBuilder> initCustomizer() {
84         return new VrfSubtableCustomizer(api);
85     }
86
87     @Test
88     public void testGetBuilder() {
89         final VrfSubtableBuilder builder = customizer.getBuilder(validId);
90
91         assertNotNull(builder);
92         assertNull(builder.getLocalMappings());
93         assertNull(builder.getRemoteMappings());
94         assertNull(builder.getTableId());
95     }
96
97     @Test
98     public void testMerge() {
99         VniTableBuilder parentBuilder = new VniTableBuilder();
100         VrfSubtable subtable = new VrfSubtableBuilder().build();
101
102         customizer.merge(parentBuilder, subtable);
103         assertEquals(subtable, parentBuilder.getVrfSubtable());
104     }
105 }