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