Jian Li | fae7b38 | 2018-07-12 22:27:47 +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 | package org.onosproject.openstacknetworking.impl; |
| 17 | |
| 18 | import com.google.common.testing.EqualsTester; |
| 19 | import org.junit.Before; |
| 20 | import org.junit.Test; |
| 21 | import org.onlab.packet.IpAddress; |
| 22 | import org.onlab.packet.MacAddress; |
| 23 | import org.onlab.packet.VlanId; |
| 24 | import org.onosproject.openstacknetworking.api.ExternalPeerRouter; |
| 25 | |
| 26 | import static org.hamcrest.MatcherAssert.assertThat; |
| 27 | import static org.hamcrest.Matchers.is; |
| 28 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 29 | |
| 30 | /** |
| 31 | * Unit tests for DefaultExternalPeerRouter. |
| 32 | */ |
| 33 | public class DefaultExternalPeerRouterTest { |
| 34 | |
| 35 | private static final IpAddress ROUTER_IP_1 = IpAddress.valueOf("1.2.3.4"); |
| 36 | private static final IpAddress ROUTER_IP_2 = IpAddress.valueOf("5.6.7.8"); |
| 37 | private static final MacAddress ROUTER_MAC_1 = MacAddress.valueOf("11:22:33:44:55:66"); |
| 38 | private static final MacAddress ROUTER_MAC_2 = MacAddress.valueOf("77:88:99:AA:BB:CC"); |
| 39 | private static final VlanId VLAN_ID_1 = VlanId.vlanId("1"); |
| 40 | private static final VlanId VLAN_ID_2 = VlanId.vlanId("2"); |
| 41 | |
| 42 | private ExternalPeerRouter router1; |
| 43 | private ExternalPeerRouter sameAsRouter1; |
| 44 | private ExternalPeerRouter router2; |
| 45 | |
| 46 | /** |
| 47 | * Checks that the DefaultExternalPeerRouter class is immutable. |
| 48 | */ |
| 49 | @Test |
| 50 | public void testImmutability() { |
| 51 | assertThatClassIsImmutable(DefaultExternalPeerRouter.class); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Initial setup for this unit test. |
| 56 | */ |
| 57 | @Before |
| 58 | public void setUp() { |
Jian Li | 5e2ad4a | 2018-07-16 13:40:53 +0900 | [diff] [blame] | 59 | ExternalPeerRouter.Builder builder1 = DefaultExternalPeerRouter.builder(); |
| 60 | |
| 61 | router1 = builder1 |
| 62 | .ipAddress(ROUTER_IP_1) |
| 63 | .macAddress(ROUTER_MAC_1) |
| 64 | .vlanId(VLAN_ID_1) |
| 65 | .build(); |
| 66 | |
| 67 | ExternalPeerRouter.Builder builder2 = DefaultExternalPeerRouter.builder(); |
| 68 | |
| 69 | sameAsRouter1 = builder2 |
| 70 | .ipAddress(ROUTER_IP_1) |
| 71 | .macAddress(ROUTER_MAC_1) |
| 72 | .vlanId(VLAN_ID_1) |
| 73 | .build(); |
| 74 | |
| 75 | ExternalPeerRouter.Builder builder3 = DefaultExternalPeerRouter.builder(); |
| 76 | |
| 77 | router2 = builder3 |
| 78 | .ipAddress(ROUTER_IP_2) |
| 79 | .macAddress(ROUTER_MAC_2) |
| 80 | .vlanId(VLAN_ID_2) |
| 81 | .build(); |
Jian Li | fae7b38 | 2018-07-12 22:27:47 +0900 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Tests object equality. |
| 86 | */ |
| 87 | @Test |
| 88 | public void testEquality() { |
| 89 | new EqualsTester().addEqualityGroup(router1, sameAsRouter1) |
| 90 | .addEqualityGroup(router2) |
| 91 | .testEquals(); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Test object construction. |
| 96 | */ |
| 97 | @Test |
| 98 | public void testConstruction() { |
| 99 | ExternalPeerRouter router = router1; |
| 100 | |
Jian Li | 5e2ad4a | 2018-07-16 13:40:53 +0900 | [diff] [blame] | 101 | assertThat(router.ipAddress(), is(router1.ipAddress())); |
| 102 | assertThat(router.macAddress(), is(router1.macAddress())); |
| 103 | assertThat(router.vlanId(), is(router1.vlanId())); |
Jian Li | fae7b38 | 2018-07-12 22:27:47 +0900 | [diff] [blame] | 104 | } |
| 105 | } |