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.write;
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertTrue;
21 import static org.junit.Assert.fail;
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;
35 public class VrfSubtableCustomizerTest extends SubtableWriterTestCase {
37 private VrfSubtableCustomizer customizer;
38 private InstanceIdentifier<VrfSubtable> validId;
39 private VrfSubtable validData;
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();
50 public void testWriteSuccessfull() throws WriteFailedException {
51 whenAddDelEidTableAddDelMapSuccess();
53 customizer.writeCurrentAttributes(validId, validData, writeContext);
54 verifyAddDelEidTableAddDelMapInvokedCorrectly(1, 12, 10, 0);
58 public void testWriteFailed() {
59 whenAddDelEidTableAddDelMapFail();
62 customizer.writeCurrentAttributes(validId, validData, writeContext);
63 } catch (Exception e) {
64 assertTrue(e instanceof WriteFailedException);
66 final WriteFailedException realException = ((WriteFailedException) e);
67 assertEquals(validId, realException.getFailedId());
68 assertTrue(e.getCause() instanceof VppCallbackException);
72 fail("Test should throw exception");
75 @Test(expected = UnsupportedOperationException.class)
76 public void testUpdate() throws WriteFailedException {
77 customizer.updateCurrentAttributes(validId, validData, validData, writeContext);
81 public void testDeleteSuccessfull() throws WriteFailedException {
82 whenAddDelEidTableAddDelMapSuccess();
84 customizer.deleteCurrentAttributes(validId, validData, writeContext);
85 verifyAddDelEidTableAddDelMapInvokedCorrectly(0, 12, 10, 0);
89 public void testDeleteFailed() {
90 whenAddDelEidTableAddDelMapFail();
93 customizer.deleteCurrentAttributes(validId, validData, writeContext);
94 } catch (Exception e) {
95 assertTrue(e instanceof WriteFailedException);
97 final WriteFailedException realException = ((WriteFailedException) e);
98 assertEquals(validId, realException.getFailedId());
99 assertTrue(e.getCause() instanceof VppCallbackException);
103 fail("Test should throw exception");