blob: f91ad2e19c66bbfca150dbba0f307e8c91b93924 [file] [log] [blame]
Jian Lib9642832021-01-08 03:18:35 +09001/*
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 */
16package org.onosproject.kubevirtnetworking.api;
17
18import com.google.common.testing.EqualsTester;
19import org.junit.Before;
20import org.junit.Test;
21import org.onlab.packet.IpAddress;
22import org.onlab.packet.MacAddress;
23import org.onosproject.net.DeviceId;
24import org.onosproject.net.PortNumber;
25
26import static junit.framework.TestCase.assertEquals;
27import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
28
29/**
30 * Unit tests for the default kubevirt port class.
31 */
32public class DefaultKubevirtPortTest {
Jian Li3ba5c582021-01-14 11:30:36 +090033 private static final String NETWORK_ID_1 = "net-1";
34 private static final String NETWORK_ID_2 = "net-2";
Jian Lib9642832021-01-08 03:18:35 +090035 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 Li3ba5c582021-01-14 11:30:36 +090062 .networkId(NETWORK_ID_1)
Jian Lib9642832021-01-08 03:18:35 +090063 .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 Li3ba5c582021-01-14 11:30:36 +090070 .networkId(NETWORK_ID_1)
Jian Lib9642832021-01-08 03:18:35 +090071 .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 Li3ba5c582021-01-14 11:30:36 +090078 .networkId(NETWORK_ID_2)
Jian Lib9642832021-01-08 03:18:35 +090079 .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 Li3ba5c582021-01-14 11:30:36 +0900103 assertEquals(NETWORK_ID_1, port.networkId());
Jian Lib9642832021-01-08 03:18:35 +0900104 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}