2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.bgp.rib.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
12 import io.netty.channel.ChannelFuture;
13 import java.util.HashSet;
15 import java.util.concurrent.ExecutionException;
16 import java.util.concurrent.Future;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.mockito.Mockito;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.peer.rpc.rev160322.PeerRef;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.peer.rpc.rev160322.RouteRefreshRequestInput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.peer.rpc.rev160322.RouteRefreshRequestInputBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
27 import org.opendaylight.yangtools.yang.binding.Notification;
28 import org.opendaylight.yangtools.yang.common.RpcResult;
30 public class BgpPeerRpcTest {
32 private final Set<TablesKey> supportedFamilies = new HashSet<TablesKey>();
33 private final BGPSessionImpl session = Mockito.mock(BGPSessionImpl.class);
34 private final BgpPeerRpc rpc = new BgpPeerRpc(this.session, this.supportedFamilies);
35 private final PeerRef peer = Mockito.mock(PeerRef.class);
37 private final ChannelOutputLimiter limiter = new ChannelOutputLimiter(this.session);
38 private final ChannelFuture future = Mockito.mock(ChannelFuture.class);
41 public void setUp() throws InterruptedException, ExecutionException {
42 this.supportedFamilies.add(new TablesKey(Ipv4AddressFamily.class, SubsequentAddressFamily.class));
44 Mockito.doReturn(this.limiter).when(this.session).getLimiter();
45 Mockito.doReturn(this.future).when(this.session).writeAndFlush(Mockito.any(Notification.class));
46 Mockito.doReturn(true).when(this.future).isDone();
47 Mockito.doReturn(null).when(this.future).get();
48 Mockito.doReturn(true).when(this.future).isSuccess();
52 public void testSuccessRequest() throws InterruptedException, ExecutionException {
53 final RouteRefreshRequestInput input = new RouteRefreshRequestInputBuilder()
54 .setAfi(Ipv4AddressFamily.class)
55 .setSafi(SubsequentAddressFamily.class)
56 .setPeerRef(this.peer).build();
57 final Future<RpcResult<Void>> result = this.rpc.routeRefreshRequest(input);
58 assertTrue(result.get().getErrors().isEmpty());
62 public void testFailedRequest() throws InterruptedException, ExecutionException {
63 final RouteRefreshRequestInput input = new RouteRefreshRequestInputBuilder()
64 .setAfi(Ipv6AddressFamily.class)
65 .setSafi(SubsequentAddressFamily.class)
66 .setPeerRef(this.peer).build();
67 final Future<RpcResult<Void>> result = this.rpc.routeRefreshRequest(input);
68 assertEquals(1, result.get().getErrors().size());
69 assertEquals("Failed to send Route Refresh message due to unsupported address families.", result.get().getErrors().iterator().next().getMessage());