2 * Copyright (c) 2015 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.mode.impl.add.n.paths;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertTrue;
13 import static org.mockito.Mockito.doReturn;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.protocol.bgp.mode.impl.AbstractRouteEntryTest;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 public final class SimpleRouteEntryTest extends AbstractRouteEntryTest {
22 private static final long N_PATHS = 2;
23 private SimpleRouteEntry testBARE;
31 public void testSimpleRouteEntry() throws Exception {
32 this.testBARE = (SimpleRouteEntry) new AddPathBestNPathSelection(N_PATHS)
33 .createRouteEntry(false);
34 testWriteEmptyBestPath();
35 testAddRouteSelectBestAndWriteOnDS();
36 testRewriteSameRoute();
37 testInitializePeerWithExistentRoute();
42 * Add non Add Path Route.
44 @Test(expected = NullPointerException.class)
45 public void testAddRouteSelectBestAndWriteOnDSs() {
46 this.testBARE.addRoute(ROUTER_ID, REMOTE_PATH_ID, this.ribSupport.routeAttributesIdentifier(), this.attributes);
49 private void testWriteEmptyBestPath() {
50 doReturn(ROUTE_ID_PA).when(this.entryInfo).getRouteId();
52 this.testBARE.initializeBestPaths(this.entryDep, this.entryInfo, this.peg, this.tx);
53 assertEquals(0, this.yiichanges.size());
59 private void testAddRouteSelectBestAndWriteOnDS() {
60 this.testBARE.addRoute(ROUTER_ID, REMOTE_PATH_ID, this.ribSupport.routeAttributesIdentifier(),
62 assertFalse(this.testBARE.isEmpty());
63 assertTrue(this.testBARE.selectBest(AS));
64 this.testBARE.updateBestPaths(this.entryDep, ROUTE_ID_PA_ADD_PATH, this.tx);
65 final Map<YangInstanceIdentifier, Long> yiiCount = collectInfo();
66 assertEquals(3, yiiCount.size());
67 assertEquals(1, (long) yiiCount.get(this.routePaAddPathYii));
68 assertEquals(1, (long) yiiCount.get(this.routeAddRiboutYii));
69 assertEquals(1, (long) yiiCount.get(this.routeAddRiboutAttYii));
72 private void testRewriteSameRoute() {
73 this.testBARE.addRoute(ROUTER_ID, REMOTE_PATH_ID, this.ribSupport.routeAttributesIdentifier(), this.attributes);
74 assertFalse(this.testBARE.selectBest(AS));
77 private void testInitializePeerWithExistentRoute() {
78 assertEquals(3, this.yiichanges.size());
79 doReturn(ROUTE_ID_PA_ADD_PATH).when(this.entryInfo).getRouteId();
81 this.testBARE.initializeBestPaths(this.entryDep, this.entryInfo, this.peg, this.tx);
82 assertEquals(5, this.yiichanges.size());
83 final Map<YangInstanceIdentifier, Long> yiiCount = collectInfo();
84 assertEquals(1, (long) yiiCount.get(this.routeAddRiboutYiiPeer2));
85 assertEquals(1, (long) yiiCount.get(this.routeAddRiboutYiiPeer2));
88 private void testRemoveRoute() {
89 Map<YangInstanceIdentifier, Long> yiiCount = collectInfo();
90 assertEquals(5, yiiCount.size());
91 assertEquals(1, (long) yiiCount.get(this.routePaAddPathYii));
92 assertTrue(this.testBARE.removeRoute(ROUTER_ID, REMOTE_PATH_ID));
93 assertTrue(this.testBARE.selectBest(AS));
94 this.testBARE.updateBestPaths(this.entryDep, ROUTE_ID_PA_ADD_PATH, this.tx);
95 yiiCount = collectInfo();
96 assertEquals(2, yiiCount.size());
97 assertFalse(yiiCount.containsKey(this.routePaAddPathYii));
98 assertFalse(yiiCount.containsKey(this.routeAddRiboutYii));