HONEYCOMB-58 - Routing Api
[honeycomb.git] / lisp / lisp2vpp / src / test / java / io / fd / honeycomb / lisp / translate / write / VniTableCustomizerTest.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package io.fd.honeycomb.lisp.translate.write;
18
19
20 import static org.junit.Assert.fail;
21 import static org.mockito.Mockito.when;
22 import static org.mockito.MockitoAnnotations.initMocks;
23
24 import com.google.common.base.Optional;
25 import io.fd.honeycomb.translate.write.WriteFailedException;
26 import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.VniTable;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.VniTableBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.vni.table.VrfSubtableBuilder;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33
34 public class VniTableCustomizerTest extends WriterCustomizerTest {
35
36     private VniTableCustomizer customizer;
37     private InstanceIdentifier<VniTable> validId;
38     private VniTable validData;
39
40     @Before
41     public void init() {
42         initMocks(this);
43         customizer = new VniTableCustomizer(api);
44
45         validId = InstanceIdentifier.create(VniTable.class);
46         validData = new VniTableBuilder()
47                 .setVrfSubtable(new VrfSubtableBuilder()
48                         .build()).build();
49     }
50
51     @Test
52     public void testWriteSuccessfull() {
53         whenReadAfterReturnValid();
54         try {
55             customizer.writeCurrentAttributes(validId, validData, writeContext);
56         } catch (Exception e) {
57             fail("Test should pass without exception");
58         }
59     }
60
61     @Test(expected = IllegalStateException.class)
62     public void testWriteFailed() throws WriteFailedException {
63         whenReadAfterReturnInvalid();
64         customizer.writeCurrentAttributes(validId, validData, writeContext);
65     }
66
67     @Test(expected = UnsupportedOperationException.class)
68     public void testUpdate() throws WriteFailedException {
69         customizer.updateCurrentAttributes(validId, validData, validData, writeContext);
70     }
71
72     @Test
73     public void testDeleteSuccessfull() {
74         whenReadBeforeReturnValid();
75         try {
76             customizer.deleteCurrentAttributes(validId, validData, writeContext);
77         } catch (Exception e) {
78             fail("Test should pass without exception");
79         }
80     }
81
82     @Test(expected = IllegalStateException.class)
83     public void testDeleteFailed() throws WriteFailedException {
84         whenReadBeforeReturnInvalid();
85         customizer.deleteCurrentAttributes(validId, validData, writeContext);
86     }
87
88     private void whenReadBeforeReturnValid() {
89         when(writeContext.readBefore(validId)).thenReturn(Optional.of(validData));
90     }
91
92     private void whenReadBeforeReturnInvalid() {
93         when(writeContext.readBefore(validId)).thenReturn(Optional.absent());
94     }
95
96     private void whenReadAfterReturnValid() {
97         when(writeContext.readAfter(validId)).thenReturn(Optional.of(validData));
98     }
99
100     private void whenReadAfterReturnInvalid() {
101         when(writeContext.readAfter(validId)).thenReturn(Optional.absent());
102     }
103 }