blob: f5f400e714e163865ef2e73284d4836fba157294 [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";
35 private static final IpAddress FLOATING_IP_1 = IpAddress.valueOf("10.10.10.10");
36 private static final IpAddress FLOATING_IP_2 = IpAddress.valueOf("20.20.20.20");
37 private static final String POD_NAME_1 = "pod-1";
38 private static final String POD_NAME_2 = "pod-2";
39 private static final IpAddress FIXED_IP_1 = IpAddress.valueOf("30.30.30.30");
40 private static final IpAddress FIXED_IP_2 = IpAddress.valueOf("40.40.40.40");
41
42 private KubevirtFloatingIp fip1;
43 private KubevirtFloatingIp sameAsFip1;
44 private KubevirtFloatingIp fip2;
45
46 /**
47 * Tests class immutability.
48 */
49 @Test
50 public void testImmutability() {
51 assertThatClassIsImmutable(DefaultKubevirtFloatingIp.class);
52 }
53
54 /**
55 * Initial setup for this unit test.
56 */
57 @Before
58 public void setUp() {
59 fip1 = DefaultKubevirtFloatingIp.builder()
60 .id(ID_1)
61 .routerName(ROUTER_NAME_1)
62 .floatingIp(FLOATING_IP_1)
63 .podName(POD_NAME_1)
64 .fixedIp(FIXED_IP_1)
65 .build();
66
67 sameAsFip1 = DefaultKubevirtFloatingIp.builder()
68 .id(ID_1)
69 .routerName(ROUTER_NAME_1)
70 .floatingIp(FLOATING_IP_1)
71 .podName(POD_NAME_1)
72 .fixedIp(FIXED_IP_1)
73 .build();
74
75 fip2 = DefaultKubevirtFloatingIp.builder()
76 .id(ID_2)
77 .routerName(ROUTER_NAME_2)
78 .floatingIp(FLOATING_IP_2)
79 .podName(POD_NAME_2)
80 .fixedIp(FIXED_IP_2)
81 .build();
82 }
83
84 /**
85 * Tests object equality.
86 */
87 @Test
88 public void testEquality() {
89 new EqualsTester().addEqualityGroup(fip1, sameAsFip1)
90 .addEqualityGroup(fip2)
91 .testEquals();
92 }
93
94 /**
95 * Test object construction.
96 */
97 @Test
98 public void testConstruction() {
99 KubevirtFloatingIp fip = fip1;
100
101 assertEquals(ID_1, fip.id());
102 assertEquals(ROUTER_NAME_1, fip.routerName());
103 assertEquals(FLOATING_IP_1, fip.floatingIp());
104 assertEquals(POD_NAME_1, fip.podName());
105 assertEquals(FIXED_IP_1, fip.fixedIp());
106 }
107}