BUG-4827: Path Selection mode Config Subsystem integration
[bgpcep.git] / bgp / path-selection-mode / src / test / java / org / opendaylight / protocol / bgp / mode / impl / base / OffsetMapTest.java
1 /*
2  * Copyright (c) 2015 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 package org.opendaylight.protocol.bgp.mode.impl.base;
9
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12
13 import org.junit.Test;
14 import org.opendaylight.protocol.bgp.rib.spi.RouterIds;
15
16 public class OffsetMapTest {
17
18     private final String LOCAL_ADDRESS = "127.0.0.1";
19     private final int LOCAL_ADDRESS_DECIMAL = 0x7f000001;
20     private final Integer[] TESTED_VALUES = {1, 2, 3, 4, 5, 6, 7};
21     private final Integer[] TESTED_VALUES_REMOVE = {2, 3, 4, 5, 6, 7};
22     private final int EXPECTED_ROUTER_OFFSET = 0;
23     private final int EXPECTED_VALUE = 1;
24     private final int CHANGED_VALUE = 111;
25
26     @Test
27     public void testAllMethods() {
28         final OffsetMap offsetMap = OffsetMap.EMPTY.with(RouterIds.routerIdForAddress(LOCAL_ADDRESS));
29         assertEquals(EXPECTED_ROUTER_OFFSET, offsetMap.offsetOf(RouterIds.routerIdForAddress(LOCAL_ADDRESS)));
30         assertEquals(LOCAL_ADDRESS_DECIMAL, offsetMap.getRouterId(EXPECTED_ROUTER_OFFSET).intValue());
31
32         assertEquals(EXPECTED_VALUE, (int) offsetMap.getValue(TESTED_VALUES, EXPECTED_ROUTER_OFFSET));
33         offsetMap.setValue(TESTED_VALUES, EXPECTED_ROUTER_OFFSET, CHANGED_VALUE);
34         assertEquals(CHANGED_VALUE, (int) offsetMap.getValue(TESTED_VALUES, EXPECTED_ROUTER_OFFSET));
35         assertArrayEquals(TESTED_VALUES_REMOVE, offsetMap.removeValue(TESTED_VALUES, 0));
36         assertEquals(0, offsetMap.without(RouterIds.routerIdForAddress(LOCAL_ADDRESS)).size());
37     }
38 }