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.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;
36 public class BridgeDomainCustomizerTest extends SubtableWriterTestCase {
38 private BridgeDomainSubtableCustomizer customizer;
39 private InstanceIdentifier<BridgeDomainSubtable> validId;
40 private BridgeDomainSubtable validData;
41 private NamingContext bridgeDomainContext;
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");
54 public void testWriteSuccessfull() throws WriteFailedException {
55 whenAddDelEidTableAddDelMapSuccess();
56 customizer.writeCurrentAttributes(validId, validData, writeContext);
57 verifyAddDelEidTableAddDelMapInvokedCorrectly(1, 12, 10, 1);
61 public void testWriteFailed() throws WriteFailedException {
62 whenAddDelEidTableAddDelMapFail();
65 customizer.writeCurrentAttributes(validId, validData, writeContext);
66 } catch (Exception e) {
67 assertTrue(e instanceof WriteFailedException);
69 final WriteFailedException realException = ((WriteFailedException) e);
70 assertEquals(validId, realException.getFailedId());
71 assertTrue(e.getCause() instanceof VppCallbackException);
75 fail("Test should throw exception");
78 @Test(expected = UnsupportedOperationException.class)
79 public void testUpdate() throws WriteFailedException {
80 customizer.updateCurrentAttributes(validId, validData, validData, writeContext);
84 public void testDeleteSuccessfull() throws WriteFailedException {
85 whenAddDelEidTableAddDelMapSuccess();
86 customizer.deleteCurrentAttributes(validId, validData, writeContext);
87 verifyAddDelEidTableAddDelMapInvokedCorrectly(0, 12, 10, 1);
91 public void testDeleteFailed() {
92 whenAddDelEidTableAddDelMapFail();
95 customizer.deleteCurrentAttributes(validId, validData, writeContext);
96 } catch (Exception e) {
97 assertTrue(e instanceof WriteFailedException);
99 final WriteFailedException realException = ((WriteFailedException) e);
100 assertEquals(validId, realException.getFailedId());
101 assertTrue(e.getCause() instanceof VppCallbackException);
105 fail("Test should throw exception");