Jian Li | da0b485 | 2018-08-29 20:40:44 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | * |
| 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 |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 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. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.simplefabric.impl; |
| 18 | |
| 19 | import com.google.common.testing.EqualsTester; |
| 20 | import org.junit.Before; |
| 21 | import org.junit.Test; |
| 22 | import org.onlab.packet.IpAddress; |
| 23 | import org.onlab.packet.IpPrefix; |
| 24 | import org.onosproject.cluster.NodeId; |
| 25 | import org.onosproject.simplefabric.api.FabricRoute; |
| 26 | import org.onosproject.simplefabric.api.FabricRoute.Source; |
| 27 | |
| 28 | import static junit.framework.TestCase.assertEquals; |
| 29 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 30 | |
| 31 | /** |
| 32 | * Unit tests for the default fabric router. |
| 33 | */ |
| 34 | public final class DefaultFabricRouteTest { |
| 35 | |
| 36 | private static final Source SOURCE_1 = Source.STATIC; |
| 37 | private static final Source SOURCE_2 = Source.BGP; |
| 38 | |
| 39 | private static final IpPrefix IP_PREFIX_1 = IpPrefix.valueOf("10.10.10.1/32"); |
| 40 | private static final IpPrefix IP_PREFIX_2 = IpPrefix.valueOf("20.20.20.2/32"); |
| 41 | |
| 42 | private static final IpAddress NEXT_HOP_1 = IpAddress.valueOf("10.10.10.1"); |
| 43 | private static final IpAddress NEXT_HOP_2 = IpAddress.valueOf("20.20.20.2"); |
| 44 | |
| 45 | private static final NodeId SOURCE_NODE_1 = NodeId.nodeId("1"); |
| 46 | private static final NodeId SOURCE_NODE_2 = NodeId.nodeId("2"); |
| 47 | |
| 48 | private FabricRoute fabricRoute1; |
| 49 | private FabricRoute sameAsFabricRoute1; |
| 50 | private FabricRoute fabricRoute2; |
| 51 | |
| 52 | /** |
| 53 | * Tests class immutability. |
| 54 | */ |
| 55 | @Test |
| 56 | public void testImmutability() { |
| 57 | assertThatClassIsImmutable(DefaultFabricRoute.class); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Initial setup for this unit test. |
| 62 | */ |
| 63 | @Before |
| 64 | public void setUp() { |
| 65 | fabricRoute1 = DefaultFabricRoute.builder() |
| 66 | .source(SOURCE_1) |
| 67 | .prefix(IP_PREFIX_1) |
| 68 | .nextHop(NEXT_HOP_1) |
| 69 | .sourceNode(SOURCE_NODE_1) |
| 70 | .build(); |
| 71 | |
| 72 | sameAsFabricRoute1 = DefaultFabricRoute.builder() |
| 73 | .source(SOURCE_1) |
| 74 | .prefix(IP_PREFIX_1) |
| 75 | .nextHop(NEXT_HOP_1) |
| 76 | .sourceNode(SOURCE_NODE_1) |
| 77 | .build(); |
| 78 | |
| 79 | fabricRoute2 = DefaultFabricRoute.builder() |
| 80 | .source(SOURCE_2) |
| 81 | .prefix(IP_PREFIX_2) |
| 82 | .nextHop(NEXT_HOP_2) |
| 83 | .sourceNode(SOURCE_NODE_2) |
| 84 | .build(); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Tests object equality. |
| 89 | */ |
| 90 | @Test |
| 91 | public void testEquality() { |
| 92 | new EqualsTester().addEqualityGroup(fabricRoute1, sameAsFabricRoute1) |
| 93 | .addEqualityGroup(fabricRoute2) |
| 94 | .testEquals(); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Test object construction. |
| 99 | */ |
| 100 | @Test |
| 101 | public void testConstruction() { |
| 102 | FabricRoute route = fabricRoute1; |
| 103 | |
| 104 | assertEquals(route.source(), SOURCE_1); |
| 105 | assertEquals(route.prefix(), IP_PREFIX_1); |
| 106 | assertEquals(route.nextHop(), NEXT_HOP_1); |
| 107 | assertEquals(route.sourceNode(), SOURCE_NODE_1); |
| 108 | } |
| 109 | } |