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