blob: b63cf001e9ca26e0117263014ae22d24171e2234 [file] [log] [blame]
Jian Li073f1ba2021-02-28 03:50:15 +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;
22
23import static junit.framework.TestCase.assertEquals;
24import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
25
26/**
27 * Unit tests for the default kubevirt floating IP class.
28 */
29public class DefaultKubevirtFloatingIpTest {
30
31 private static final String ID_1 = "fip_id_1";
32 private static final String ID_2 = "fip_id_2";
33 private static final String ROUTER_NAME_1 = "router-1";
34 private static final String ROUTER_NAME_2 = "router-2";
Jian Lib636f702021-03-03 14:46:50 +090035 private static final String NETWORK_NAME_1 = "flat-1";
36 private static final String NETWORK_NAME_2 = "flat-2";
Jian Li073f1ba2021-02-28 03:50:15 +090037 private static final IpAddress FLOATING_IP_1 = IpAddress.valueOf("10.10.10.10");
38 private static final IpAddress FLOATING_IP_2 = IpAddress.valueOf("20.20.20.20");
39 private static final String POD_NAME_1 = "pod-1";
40 private static final String POD_NAME_2 = "pod-2";
41 private static final IpAddress FIXED_IP_1 = IpAddress.valueOf("30.30.30.30");
42 private static final IpAddress FIXED_IP_2 = IpAddress.valueOf("40.40.40.40");
43
44 private KubevirtFloatingIp fip1;
45 private KubevirtFloatingIp sameAsFip1;
46 private KubevirtFloatingIp fip2;
47
48 /**
49 * Tests class immutability.
50 */
51 @Test
52 public void testImmutability() {
53 assertThatClassIsImmutable(DefaultKubevirtFloatingIp.class);
54 }
55
56 /**
57 * Initial setup for this unit test.
58 */
59 @Before
60 public void setUp() {
61 fip1 = DefaultKubevirtFloatingIp.builder()
62 .id(ID_1)
63 .routerName(ROUTER_NAME_1)
Jian Lib636f702021-03-03 14:46:50 +090064 .networkName(NETWORK_NAME_1)
Jian Li073f1ba2021-02-28 03:50:15 +090065 .floatingIp(FLOATING_IP_1)
66 .podName(POD_NAME_1)
67 .fixedIp(FIXED_IP_1)
68 .build();
69
70 sameAsFip1 = DefaultKubevirtFloatingIp.builder()
71 .id(ID_1)
72 .routerName(ROUTER_NAME_1)
Jian Lib636f702021-03-03 14:46:50 +090073 .networkName(NETWORK_NAME_1)
Jian Li073f1ba2021-02-28 03:50:15 +090074 .floatingIp(FLOATING_IP_1)
75 .podName(POD_NAME_1)
76 .fixedIp(FIXED_IP_1)
77 .build();
78
79 fip2 = DefaultKubevirtFloatingIp.builder()
80 .id(ID_2)
81 .routerName(ROUTER_NAME_2)
Jian Lib636f702021-03-03 14:46:50 +090082 .networkName(NETWORK_NAME_2)
Jian Li073f1ba2021-02-28 03:50:15 +090083 .floatingIp(FLOATING_IP_2)
84 .podName(POD_NAME_2)
85 .fixedIp(FIXED_IP_2)
86 .build();
87 }
88
89 /**
90 * Tests object equality.
91 */
92 @Test
93 public void testEquality() {
94 new EqualsTester().addEqualityGroup(fip1, sameAsFip1)
95 .addEqualityGroup(fip2)
96 .testEquals();
97 }
98
99 /**
100 * Test object construction.
101 */
102 @Test
103 public void testConstruction() {
104 KubevirtFloatingIp fip = fip1;
105
106 assertEquals(ID_1, fip.id());
107 assertEquals(ROUTER_NAME_1, fip.routerName());
Jian Lib636f702021-03-03 14:46:50 +0900108 assertEquals(NETWORK_NAME_1, fip.networkName());
Jian Li073f1ba2021-02-28 03:50:15 +0900109 assertEquals(FLOATING_IP_1, fip.floatingIp());
110 assertEquals(POD_NAME_1, fip.podName());
111 assertEquals(FIXED_IP_1, fip.fixedIp());
112 }
113}