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.translate.v3po.interfaces;
19 import static org.mockito.Matchers.any;
20 import static org.mockito.Mockito.verify;
21 import static org.mockito.Mockito.when;
23 import io.fd.honeycomb.translate.vpp.util.NamingContext;
24 import io.fd.honeycomb.translate.write.WriteFailedException;
25 import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
26 import io.fd.vpp.jvpp.core.dto.SwInterfaceSetTable;
27 import io.fd.vpp.jvpp.core.dto.SwInterfaceSetTableReply;
28 import org.junit.Test;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceAugmentation;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.Routing;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.RoutingBuilder;
35 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
37 public class RoutingCustomizerTest extends WriterCustomizerTest {
38 private static final String IFACE_CTX_NAME = "interface-ctx";
39 private static final String IF_NAME = "eth1";
40 private static final int IF_INDEX = 1;
41 private static final InstanceIdentifier<Routing> IID =
42 InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME))
43 .augmentation(VppInterfaceAugmentation.class).child(Routing.class);
45 private RoutingCustomizer customizer;
48 protected void setUp() throws Exception {
49 customizer = new RoutingCustomizer(api, new NamingContext("ifacePrefix", IFACE_CTX_NAME));
50 defineMapping(mappingContext, IF_NAME, IF_INDEX, IFACE_CTX_NAME);
54 public void testWrite() throws WriteFailedException {
55 final int vrfId = 123;
56 when(api.swInterfaceSetTable(any())).thenReturn(future(new SwInterfaceSetTableReply()));
57 customizer.writeCurrentAttributes(IID, routing(vrfId), writeContext);
58 verify(api).swInterfaceSetTable(expectedRequest(vrfId));
61 @Test(expected = WriteFailedException.class)
62 public void testWriteFailed() throws WriteFailedException {
63 when(api.swInterfaceSetTable(any())).thenReturn(failedFuture());
64 customizer.writeCurrentAttributes(IID, routing(213), writeContext);
67 @Test(expected = WriteFailedException.class)
68 public void testUpdateFailed() throws WriteFailedException {
69 when(api.swInterfaceSetTable(any())).thenReturn(failedFuture());
70 customizer.updateCurrentAttributes(IID, routing(123L), routing(321L), writeContext);
74 public void testDelete() throws WriteFailedException {
75 when(api.swInterfaceSetTable(any())).thenReturn(future(new SwInterfaceSetTableReply()));
76 customizer.deleteCurrentAttributes(IID, routing(123), writeContext);
77 verify(api).swInterfaceSetTable(expectedRequest(0));
80 @Test(expected = WriteFailedException.DeleteFailedException.class)
81 public void testDeleteFailed() throws WriteFailedException {
82 when(api.swInterfaceSetTable(any())).thenReturn(failedFuture());
83 customizer.deleteCurrentAttributes(IID, routing(123), writeContext);
86 private Routing routing(final long vrfId) {
87 return new RoutingBuilder().setIpv4VrfId(vrfId).build();
90 private SwInterfaceSetTable expectedRequest(final int vrfId) {
91 final SwInterfaceSetTable request = new SwInterfaceSetTable();
93 request.swIfIndex = IF_INDEX;
94 request.vrfId = vrfId;