blob: 00f3cd4377f371309fc389b7a58d05956fe6501c [file] [log] [blame]
Jian Lie1fe06a2021-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 {
33 private static final MacAddress MAC_ADDRESS_1 = MacAddress.valueOf("00:11:22:33:44:55");
34 private static final MacAddress MAC_ADDRESS_2 = MacAddress.valueOf("11:22:33:44:55:66");
35 private static final IpAddress IP_ADDRESS_1 = IpAddress.valueOf("10.10.10.10");
36 private static final IpAddress IP_ADDRESS_2 = IpAddress.valueOf("20.20.20.20");
37 private static final DeviceId DEVICE_ID_1 = DeviceId.deviceId("of:000000000000001");
38 private static final DeviceId DEVICE_ID_2 = DeviceId.deviceId("of:000000000000002");
39 private static final PortNumber PORT_NUMBER_1 = PortNumber.portNumber(1);
40 private static final PortNumber PORT_NUMBER_2 = PortNumber.portNumber(2);
41
42 private KubevirtPort port1;
43 private KubevirtPort sameAsPort1;
44 private KubevirtPort port2;
45
46 /**
47 * Tests class immutability.
48 */
49 @Test
50 public void testImmutability() {
51 assertThatClassIsImmutable(DefaultKubevirtPort.class);
52 }
53
54 /**
55 * Initial setup for this unit test.
56 */
57 @Before
58 public void setUp() {
59 port1 = DefaultKubevirtPort.builder()
60 .macAddress(MAC_ADDRESS_1)
61 .ipAddress(IP_ADDRESS_1)
62 .deviceId(DEVICE_ID_1)
63 .portNumber(PORT_NUMBER_1)
64 .build();
65
66 sameAsPort1 = DefaultKubevirtPort.builder()
67 .macAddress(MAC_ADDRESS_1)
68 .ipAddress(IP_ADDRESS_1)
69 .deviceId(DEVICE_ID_1)
70 .portNumber(PORT_NUMBER_1)
71 .build();
72
73 port2 = DefaultKubevirtPort.builder()
74 .macAddress(MAC_ADDRESS_2)
75 .ipAddress(IP_ADDRESS_2)
76 .deviceId(DEVICE_ID_2)
77 .portNumber(PORT_NUMBER_2)
78 .build();
79 }
80
81 /**
82 * Tests object equality.
83 */
84 @Test
85 public void testEquality() {
86 new EqualsTester().addEqualityGroup(port1, sameAsPort1)
87 .addEqualityGroup(port2)
88 .testEquals();
89 }
90
91 /**
92 * Test object construction.
93 */
94 @Test
95 public void testConstruction() {
96 KubevirtPort port = port1;
97
98 assertEquals(MAC_ADDRESS_1, port.macAddress());
99 assertEquals(IP_ADDRESS_1, port.ipAddress());
100 assertEquals(DEVICE_ID_1, port.deviceId());
101 assertEquals(PORT_NUMBER_1, port.portNumber());
102 }
103}