HONEYCOMB-154: update revison of models that changed since 16.09
[honeycomb.git] / lisp / lisp2vpp / src / test / java / io / fd / honeycomb / lisp / translate / write / VrfSubtableCustomizerTest.java
1 package io.fd.honeycomb.lisp.translate.write;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertTrue;
5 import static org.junit.Assert.fail;
6
7 import io.fd.honeycomb.lisp.translate.write.trait.SubtableWriterTestCase;
8 import io.fd.honeycomb.translate.write.WriteFailedException;
9 import io.fd.vpp.jvpp.VppCallbackException;
10 import org.junit.Before;
11 import org.junit.Test;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.EidTable;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.VniTable;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.VniTableKey;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.vni.table.VrfSubtable;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.vni.table.VrfSubtableBuilder;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18
19 public class VrfSubtableCustomizerTest extends SubtableWriterTestCase {
20
21     private VrfSubtableCustomizer customizer;
22     private InstanceIdentifier<VrfSubtable> validId;
23     private VrfSubtable validData;
24
25     @Before
26     public void init() {
27         customizer = new VrfSubtableCustomizer(api);
28         validId = InstanceIdentifier.create(EidTable.class).child(VniTable.class, new VniTableKey(12L))
29                 .child(VrfSubtable.class);
30         validData = new VrfSubtableBuilder().setTableId(10L).build();
31     }
32
33     @Test
34     public void testWriteSuccessfull() throws WriteFailedException {
35         whenAddDelEidTableAddDelMapSuccess();
36
37         customizer.writeCurrentAttributes(validId, validData, writeContext);
38         verifyAddDelEidTableAddDelMapInvokedCorrectly(1, 12, 10, 0);
39     }
40
41     @Test
42     public void testWriteFailed() {
43         whenAddDelEidTableAddDelMapFail();
44
45         try {
46             customizer.writeCurrentAttributes(validId, validData, writeContext);
47         } catch (Exception e) {
48             assertTrue(e instanceof WriteFailedException);
49
50             final WriteFailedException realException = ((WriteFailedException) e);
51             assertEquals(validId, realException.getFailedId());
52             assertTrue(e.getCause() instanceof VppCallbackException);
53             return;
54         }
55
56         fail("Test should throw exception");
57     }
58
59     @Test(expected = UnsupportedOperationException.class)
60     public void testUpdate() throws WriteFailedException {
61         customizer.updateCurrentAttributes(validId, validData, validData, writeContext);
62     }
63
64     @Test
65     public void testDeleteSuccessfull() throws WriteFailedException {
66         whenAddDelEidTableAddDelMapSuccess();
67
68         customizer.deleteCurrentAttributes(validId, validData, writeContext);
69         verifyAddDelEidTableAddDelMapInvokedCorrectly(0, 12, 10, 0);
70     }
71
72     @Test
73     public void testDeleteFailed() {
74         whenAddDelEidTableAddDelMapFail();
75
76         try {
77             customizer.deleteCurrentAttributes(validId, validData, writeContext);
78         } catch (Exception e) {
79             assertTrue(e instanceof WriteFailedException);
80
81             final WriteFailedException realException = ((WriteFailedException) e);
82             assertEquals(validId, realException.getFailedId());
83             assertTrue(e.getCause() instanceof VppCallbackException);
84             return;
85         }
86
87         fail("Test should throw exception");
88     }
89 }