Reduce number of parameters for path selection
[bgpcep.git] / bgp / path-selection-mode / src / test / java / org / opendaylight / protocol / bgp / mode / impl / base / BaseRouteEntryTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.protocol.bgp.mode.impl.base;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertFalse;
13 import static org.mockito.Mockito.doReturn;
14
15 import java.util.Map;
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;
20
21 public class BaseRouteEntryTest extends AbstractRouteEntryTest {
22
23     private BaseSimpleRouteEntry testBARE;
24
25     @Before
26     public void setUp() {
27         super.setUp();
28     }
29
30     @Test
31     public void testBaseSimpleRouteEntry() throws Exception {
32         this.testBARE = new BaseSimpleRouteEntry();
33         testWriteEmptyBestPath();
34         testAddRouteSelectBestAndWriteOnDS();
35         testRewriteSameRoute();
36         testInitializePeerWithExistentRoute();
37         testRemoveRoute();
38     }
39
40     private void testRemoveRoute() {
41         Map<YangInstanceIdentifier, Long> yiiCount = collectInfo();
42         assertEquals(8, yiiCount.size());
43         assertEquals(1, (long) yiiCount.get(this.routePaYii));
44         this.testBARE.removeRoute(ROUTER_ID, REMOTE_PATH_ID);
45         this.testBARE.selectBest(AS);
46         this.testBARE.updateBestPaths(this.entryDep, ROUTE_ID_PA, this.tx);
47         yiiCount = collectInfo();
48         assertFalse(yiiCount.containsKey(this.routePaYii));
49         assertFalse(yiiCount.containsKey(this.routeAddRiboutAttYii));
50     }
51
52     private void testInitializePeerWithExistentRoute() {
53         doReturn(ROUTE_ID_PA).when(this.entryInfo).getRouteId();
54         this.testBARE.initializeBestPaths(this.entryDep, this.entryInfo, this.peg, this.tx);
55         assertEquals(8, this.yiichanges.size());
56         Map<YangInstanceIdentifier, Long> yiiCount = collectInfo();
57         assertEquals(1, (long) yiiCount.get(this.routeRiboutYiiPeer2));
58         assertEquals(1, (long) yiiCount.get(this.routeRiboutAttYiiPeer2));
59     }
60
61     private void testRewriteSameRoute() {
62         this.testBARE.addRoute(ROUTER_ID, REMOTE_PATH_ID, this.ribSupport.routeAttributesIdentifier(), this.attributes);
63         assertEquals(1, this.testBARE.getOffsets().size());
64         assertFalse(this.testBARE.selectBest(AS));
65     }
66
67     private void testAddRouteSelectBestAndWriteOnDS() {
68         this.testBARE.addRoute(ROUTER_ID, REMOTE_PATH_ID, this.ribSupport.routeAttributesIdentifier(), this.attributes);
69         assertFalse(this.testBARE.getOffsets().isEmpty());
70         this.testBARE.selectBest(AS);
71         this.testBARE.updateBestPaths(this.entryDep, ROUTE_ID_PA, this.tx);
72         Map<YangInstanceIdentifier, Long> yiiCount = collectInfo();
73         assertEquals(3, yiiCount.size());
74         assertEquals(1, (long) yiiCount.get(this.routePaYii));
75         assertEquals(1, (long) yiiCount.get(this.routeRiboutYii));
76         assertEquals(1, (long) yiiCount.get(this.routeRiboutAttYii));
77         this.testBARE.updateBestPaths(this.entryDep, ROUTE_ID_PA_ADD_PATH, this.tx);
78         yiiCount = collectInfo();
79         assertEquals(6, yiiCount.size());
80         assertEquals(1, (long) yiiCount.get(this.routePaAddPathYii));
81         assertEquals(1, (long) yiiCount.get(this.routeAddRiboutYii));
82         assertEquals(1, (long) yiiCount.get(this.routeAddRiboutAttYii));
83     }
84
85     private void testWriteEmptyBestPath() {
86         doReturn(ROUTE_ID_PA).when(this.entryInfo).getRouteId();
87         this.testBARE.initializeBestPaths(this.entryDep, this.entryInfo, this.peg, this.tx);
88         assertEquals(0, this.yiichanges.size());
89     }
90 }