HONEYCOMB-58 - Routing Api
[honeycomb.git] / lisp / lisp2vpp / src / test / java / io / fd / honeycomb / lisp / translate / write / BridgeDomainCustomizerTest.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 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertTrue;
21 import static org.junit.Assert.fail;
22
23 import io.fd.honeycomb.lisp.translate.write.trait.SubtableWriterTestCase;
24 import io.fd.honeycomb.translate.vpp.util.NamingContext;
25 import io.fd.honeycomb.translate.write.WriteFailedException;
26 import io.fd.vpp.jvpp.VppCallbackException;
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.EidTable;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.VniTable;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.VniTableKey;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtableBuilder;
34 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
35
36 public class BridgeDomainCustomizerTest extends SubtableWriterTestCase {
37
38     private BridgeDomainSubtableCustomizer customizer;
39     private InstanceIdentifier<BridgeDomainSubtable> validId;
40     private BridgeDomainSubtable validData;
41     private NamingContext bridgeDomainContext;
42
43     @Before
44     public void init() {
45         bridgeDomainContext = new NamingContext("br", "bridge-domain-context");
46         customizer = new BridgeDomainSubtableCustomizer(api, bridgeDomainContext);
47         validId = InstanceIdentifier.create(EidTable.class).child(VniTable.class, new VniTableKey(12L))
48                 .child(BridgeDomainSubtable.class);
49         validData = new BridgeDomainSubtableBuilder().setBridgeDomainRef("br-domain").build();
50         defineMapping(mappingContext, "br-domain", 10, "bridge-domain-context");
51     }
52
53     @Test
54     public void testWriteSuccessfull() throws WriteFailedException {
55         whenAddDelEidTableAddDelMapSuccess();
56         customizer.writeCurrentAttributes(validId, validData, writeContext);
57         verifyAddDelEidTableAddDelMapInvokedCorrectly(1, 12, 10, 1);
58     }
59
60     @Test
61     public void testWriteFailed() throws WriteFailedException {
62         whenAddDelEidTableAddDelMapFail();
63
64         try {
65             customizer.writeCurrentAttributes(validId, validData, writeContext);
66         } catch (Exception e) {
67             assertTrue(e instanceof WriteFailedException);
68
69             final WriteFailedException realException = ((WriteFailedException) e);
70             assertEquals(validId, realException.getFailedId());
71             assertTrue(e.getCause() instanceof VppCallbackException);
72             return;
73         }
74
75         fail("Test should throw exception");
76     }
77
78     @Test(expected = UnsupportedOperationException.class)
79     public void testUpdate() throws WriteFailedException {
80         customizer.updateCurrentAttributes(validId, validData, validData, writeContext);
81     }
82
83     @Test
84     public void testDeleteSuccessfull() throws WriteFailedException {
85         whenAddDelEidTableAddDelMapSuccess();
86         customizer.deleteCurrentAttributes(validId, validData, writeContext);
87         verifyAddDelEidTableAddDelMapInvokedCorrectly(0, 12, 10, 1);
88     }
89
90     @Test
91     public void testDeleteFailed() {
92         whenAddDelEidTableAddDelMapFail();
93
94         try {
95             customizer.deleteCurrentAttributes(validId, validData, writeContext);
96         } catch (Exception e) {
97             assertTrue(e instanceof WriteFailedException);
98
99             final WriteFailedException realException = ((WriteFailedException) e);
100             assertEquals(validId, realException.getFailedId());
101             assertTrue(e.getCause() instanceof VppCallbackException);
102             return;
103         }
104
105         fail("Test should throw exception");
106     }
107
108 }