HONEYCOMB-154: update revison of models that changed since 16.09
[honeycomb.git] / lisp / lisp2vpp / src / test / java / io / fd / honeycomb / lisp / translate / write / VniTableCustomizerTest.java
1 package io.fd.honeycomb.lisp.translate.write;
2
3
4 import static org.junit.Assert.fail;
5 import static org.mockito.Mockito.when;
6 import static org.mockito.MockitoAnnotations.initMocks;
7
8 import com.google.common.base.Optional;
9 import io.fd.honeycomb.translate.write.WriteFailedException;
10 import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
11 import org.junit.Before;
12 import org.junit.Test;
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.VniTableBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.vni.table.VrfSubtableBuilder;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
17
18 public class VniTableCustomizerTest extends WriterCustomizerTest {
19
20     private VniTableCustomizer customizer;
21     private InstanceIdentifier<VniTable> validId;
22     private VniTable validData;
23
24     @Before
25     public void init() {
26         initMocks(this);
27         customizer = new VniTableCustomizer(api);
28
29         validId = InstanceIdentifier.create(VniTable.class);
30         validData = new VniTableBuilder()
31                 .setVrfSubtable(new VrfSubtableBuilder()
32                         .build()).build();
33     }
34
35     @Test
36     public void testWriteSuccessfull() {
37         whenReadAfterReturnValid();
38         try {
39             customizer.writeCurrentAttributes(validId, validData, writeContext);
40         } catch (Exception e) {
41             fail("Test should pass without exception");
42         }
43     }
44
45     @Test(expected = IllegalStateException.class)
46     public void testWriteFailed() throws WriteFailedException {
47         whenReadAfterReturnInvalid();
48         customizer.writeCurrentAttributes(validId, validData, writeContext);
49     }
50
51     @Test(expected = UnsupportedOperationException.class)
52     public void testUpdate() throws WriteFailedException {
53         customizer.updateCurrentAttributes(validId, validData, validData, writeContext);
54     }
55
56     @Test
57     public void testDeleteSuccessfull() {
58         whenReadBeforeReturnValid();
59         try {
60             customizer.deleteCurrentAttributes(validId, validData, writeContext);
61         } catch (Exception e) {
62             fail("Test should pass without exception");
63         }
64     }
65
66     @Test(expected = IllegalStateException.class)
67     public void testDeleteFailed() throws WriteFailedException {
68         whenReadBeforeReturnInvalid();
69         customizer.deleteCurrentAttributes(validId, validData, writeContext);
70     }
71
72     private void whenReadBeforeReturnValid() {
73         when(writeContext.readBefore(validId)).thenReturn(Optional.of(validData));
74     }
75
76     private void whenReadBeforeReturnInvalid() {
77         when(writeContext.readBefore(validId)).thenReturn(Optional.absent());
78     }
79
80     private void whenReadAfterReturnValid() {
81         when(writeContext.readAfter(validId)).thenReturn(Optional.of(validData));
82     }
83
84     private void whenReadAfterReturnInvalid() {
85         when(writeContext.readAfter(validId)).thenReturn(Optional.absent());
86     }
87 }