Jian Li | e1fe06a | 2021-01-08 03:18:35 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021-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.kubevirtnetworking.api; |
| 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.onosproject.net.DeviceId; |
| 24 | import org.onosproject.net.PortNumber; |
| 25 | |
| 26 | import static junit.framework.TestCase.assertEquals; |
| 27 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 28 | |
| 29 | /** |
| 30 | * Unit tests for the default kubevirt port class. |
| 31 | */ |
| 32 | public class DefaultKubevirtPortTest { |
Jian Li | 7bca127 | 2021-01-14 11:30:36 +0900 | [diff] [blame] | 33 | private static final String NETWORK_ID_1 = "net-1"; |
| 34 | private static final String NETWORK_ID_2 = "net-2"; |
Jian Li | e1fe06a | 2021-01-08 03:18:35 +0900 | [diff] [blame] | 35 | private static final MacAddress MAC_ADDRESS_1 = MacAddress.valueOf("00:11:22:33:44:55"); |
| 36 | private static final MacAddress MAC_ADDRESS_2 = MacAddress.valueOf("11:22:33:44:55:66"); |
| 37 | private static final IpAddress IP_ADDRESS_1 = IpAddress.valueOf("10.10.10.10"); |
| 38 | private static final IpAddress IP_ADDRESS_2 = IpAddress.valueOf("20.20.20.20"); |
| 39 | private static final DeviceId DEVICE_ID_1 = DeviceId.deviceId("of:000000000000001"); |
| 40 | private static final DeviceId DEVICE_ID_2 = DeviceId.deviceId("of:000000000000002"); |
| 41 | private static final PortNumber PORT_NUMBER_1 = PortNumber.portNumber(1); |
| 42 | private static final PortNumber PORT_NUMBER_2 = PortNumber.portNumber(2); |
| 43 | |
| 44 | private KubevirtPort port1; |
| 45 | private KubevirtPort sameAsPort1; |
| 46 | private KubevirtPort port2; |
| 47 | |
| 48 | /** |
| 49 | * Tests class immutability. |
| 50 | */ |
| 51 | @Test |
| 52 | public void testImmutability() { |
| 53 | assertThatClassIsImmutable(DefaultKubevirtPort.class); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Initial setup for this unit test. |
| 58 | */ |
| 59 | @Before |
| 60 | public void setUp() { |
| 61 | port1 = DefaultKubevirtPort.builder() |
Jian Li | 7bca127 | 2021-01-14 11:30:36 +0900 | [diff] [blame] | 62 | .networkId(NETWORK_ID_1) |
Jian Li | e1fe06a | 2021-01-08 03:18:35 +0900 | [diff] [blame] | 63 | .macAddress(MAC_ADDRESS_1) |
| 64 | .ipAddress(IP_ADDRESS_1) |
| 65 | .deviceId(DEVICE_ID_1) |
| 66 | .portNumber(PORT_NUMBER_1) |
| 67 | .build(); |
| 68 | |
| 69 | sameAsPort1 = DefaultKubevirtPort.builder() |
Jian Li | 7bca127 | 2021-01-14 11:30:36 +0900 | [diff] [blame] | 70 | .networkId(NETWORK_ID_1) |
Jian Li | e1fe06a | 2021-01-08 03:18:35 +0900 | [diff] [blame] | 71 | .macAddress(MAC_ADDRESS_1) |
| 72 | .ipAddress(IP_ADDRESS_1) |
| 73 | .deviceId(DEVICE_ID_1) |
| 74 | .portNumber(PORT_NUMBER_1) |
| 75 | .build(); |
| 76 | |
| 77 | port2 = DefaultKubevirtPort.builder() |
Jian Li | 7bca127 | 2021-01-14 11:30:36 +0900 | [diff] [blame] | 78 | .networkId(NETWORK_ID_2) |
Jian Li | e1fe06a | 2021-01-08 03:18:35 +0900 | [diff] [blame] | 79 | .macAddress(MAC_ADDRESS_2) |
| 80 | .ipAddress(IP_ADDRESS_2) |
| 81 | .deviceId(DEVICE_ID_2) |
| 82 | .portNumber(PORT_NUMBER_2) |
| 83 | .build(); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Tests object equality. |
| 88 | */ |
| 89 | @Test |
| 90 | public void testEquality() { |
| 91 | new EqualsTester().addEqualityGroup(port1, sameAsPort1) |
| 92 | .addEqualityGroup(port2) |
| 93 | .testEquals(); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Test object construction. |
| 98 | */ |
| 99 | @Test |
| 100 | public void testConstruction() { |
| 101 | KubevirtPort port = port1; |
| 102 | |
Jian Li | 7bca127 | 2021-01-14 11:30:36 +0900 | [diff] [blame] | 103 | assertEquals(NETWORK_ID_1, port.networkId()); |
Jian Li | e1fe06a | 2021-01-08 03:18:35 +0900 | [diff] [blame] | 104 | assertEquals(MAC_ADDRESS_1, port.macAddress()); |
| 105 | assertEquals(IP_ADDRESS_1, port.ipAddress()); |
| 106 | assertEquals(DEVICE_ID_1, port.deviceId()); |
| 107 | assertEquals(PORT_NUMBER_1, port.portNumber()); |
| 108 | } |
| 109 | } |