2 * Copyright (c) 2016 Cisco and/or its affiliates.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package io.fd.honeycomb.lisp.translate.read;
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;
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;
41 public class VrfSubtableCustomizerTest extends SubtableReaderTestCase<VrfSubtable, VrfSubtableBuilder> {
43 private InstanceIdentifier<VrfSubtable> validId;
45 public VrfSubtableCustomizerTest() {
46 super(VrfSubtable.class, VrfSubtableBuilder.class);
51 validId = InstanceIdentifier.create(EidTable.class).child(VniTable.class, new VniTableKey(expectedVni))
52 .child(VrfSubtable.class);
56 public void testReadCurrentSuccessfull() throws ReadFailedException {
57 doReturnValidNonEmptyDataOnDump();
58 VrfSubtableBuilder builder = new VrfSubtableBuilder();
59 customizer.readCurrentAttributes(validId, builder, ctx);
61 verifyLispEidTableMapDumpCalled(L3);
63 final VrfSubtable subtable = builder.build();
64 assertNotNull(subtable);
65 assertEquals(expectedTableId, subtable.getTableId().longValue());
69 public void testReadCurrentEmptyDump() throws ReadFailedException {
70 doReturnEmptyDataOnDump();
71 VrfSubtableBuilder builder = new VrfSubtableBuilder();
72 customizer.readCurrentAttributes(validId, builder, ctx);
74 verifyLispEidTableMapDumpCalled(L3);
76 final VrfSubtable subtable = builder.build();
77 assertNotNull(subtable);
78 assertNull(subtable.getTableId());
82 public void testReadCurrentFailed() {
84 VrfSubtableBuilder builder = new VrfSubtableBuilder();
86 customizer.readCurrentAttributes(validId, builder, ctx);
87 } catch (ReadFailedException e) {
88 assertTrue(e.getCause() instanceof VppCallbackException);
89 assertTrue(builder.getTableId() == null);
90 verifyLispEidTableMapDumpNotCalled();
95 fail("Test should throw ReadFailedException");
99 protected ReaderCustomizer<VrfSubtable, VrfSubtableBuilder> initCustomizer() {
100 return new VrfSubtableCustomizer(api);
104 public void testGetBuilder() {
105 final VrfSubtableBuilder builder = customizer.getBuilder(validId);
107 assertNotNull(builder);
108 assertNull(builder.getLocalMappings());
109 assertNull(builder.getRemoteMappings());
110 assertNull(builder.getTableId());
114 public void testMerge() {
115 VniTableBuilder parentBuilder = new VniTableBuilder();
116 VrfSubtable subtable = new VrfSubtableBuilder().build();
118 customizer.merge(parentBuilder, subtable);
119 assertEquals(subtable, parentBuilder.getVrfSubtable());