HONEYCOMB-58 - Routing Api
[honeycomb.git] / lisp / lisp2vpp / src / test / java / io / fd / honeycomb / lisp / translate / read / BridgeDomainSubtableCustomizerTest.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.L2;
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.honeycomb.translate.vpp.util.NamingContext;
31 import io.fd.vpp.jvpp.VppCallbackException;
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.BridgeDomainSubtable;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtableBuilder;
39 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
40
41 public class BridgeDomainSubtableCustomizerTest
42         extends SubtableReaderTestCase<BridgeDomainSubtable, BridgeDomainSubtableBuilder> {
43
44     private InstanceIdentifier<BridgeDomainSubtable> validId;
45     private NamingContext bridgeDomainContext;
46
47     public BridgeDomainSubtableCustomizerTest() {
48         super(BridgeDomainSubtable.class, VniTableBuilder.class);
49     }
50
51     @Override
52     protected void setUp() throws Exception {
53         bridgeDomainContext = new NamingContext("br", "br-domain-context");
54         validId = InstanceIdentifier.create(EidTable.class).child(VniTable.class, new VniTableKey(expectedVni))
55                 .child(BridgeDomainSubtable.class);
56
57         defineMapping(mappingContext, "br-domain", expectedTableId, "br-domain-context");
58     }
59
60     @Test
61     public void testReadCurrentSuccessfull() throws ReadFailedException {
62         doReturnValidNonEmptyDataOnDump();
63         BridgeDomainSubtableBuilder builder = new BridgeDomainSubtableBuilder();
64         customizer.readCurrentAttributes(validId, builder, ctx);
65
66         verifyLispEidTableMapDumpCalled(L2);
67
68         final BridgeDomainSubtable subtable = builder.build();
69         assertNotNull(subtable);
70         assertEquals("br-domain", subtable.getBridgeDomainRef());
71     }
72
73
74     @Test
75     public void testReadCurrentEmptyDump() throws ReadFailedException {
76         doReturnEmptyDataOnDump();
77         BridgeDomainSubtableBuilder builder = new BridgeDomainSubtableBuilder();
78         customizer.readCurrentAttributes(validId, builder, ctx);
79
80         verifyLispEidTableMapDumpCalled(L2);
81
82         final BridgeDomainSubtable subtable = builder.build();
83         assertNotNull(subtable);
84         assertNull(subtable.getBridgeDomainRef());
85     }
86
87     @Test
88     public void testReadCurrentFailed() {
89         doThrowOnDump();
90         BridgeDomainSubtableBuilder builder = new BridgeDomainSubtableBuilder();
91         try {
92             customizer.readCurrentAttributes(validId, builder, ctx);
93         } catch (ReadFailedException e) {
94             assertTrue(e.getCause() instanceof VppCallbackException);
95             assertNull(builder.getBridgeDomainRef());
96             verifyLispEidTableMapDumpNotCalled();
97
98             return;
99         }
100
101         fail("Test should throw ReadFailedException");
102     }
103
104     @Test
105     public void testGetBuilder() {
106         final BridgeDomainSubtableBuilder builder = customizer.getBuilder(validId);
107
108         assertNotNull(builder);
109         assertNull(builder.getLocalMappings());
110         assertNull(builder.getRemoteMappings());
111         assertNull(builder.getBridgeDomainRef());
112     }
113
114     @Override
115     protected ReaderCustomizer<BridgeDomainSubtable, BridgeDomainSubtableBuilder> initCustomizer() {
116         return new BridgeDomainSubtableCustomizer(api, bridgeDomainContext);
117     }
118 }