blob: 243d64d52f59dd2a24a6504f8f96977d17ab7844 [file] [log] [blame]
Jian Li9ee9c8b2019-01-24 11:48:12 +09001/*
2 * Copyright 2019-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.k8snetworking.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 kubernetes IPAM.
28 */
29public class DefaultK8sIpamTest {
30
31 private static final IpAddress IP_ADDRESS_1 = IpAddress.valueOf("10.10.10.10");
32 private static final IpAddress IP_ADDRESS_2 = IpAddress.valueOf("20.20.20.20");
33 private static final String NETWORK_ID_1 = "network-1";
34 private static final String NETWORK_ID_2 = "network-2";
Jian Li9b199162019-02-10 18:00:35 +090035 private static final String IPAM_ID_1 = NETWORK_ID_1 + "-" + IP_ADDRESS_1.toString();
36 private static final String IPAM_ID_2 = NETWORK_ID_2 + "-" + IP_ADDRESS_2.toString();
Jian Li9ee9c8b2019-01-24 11:48:12 +090037
38 private K8sIpam ipam1;
39 private K8sIpam sameAsIpam1;
40 private K8sIpam ipam2;
41
42 /**
43 * Tests class immutability.
44 */
45 @Test
46 public void testImmutability() {
47 assertThatClassIsImmutable(DefaultK8sIpam.class);
48 }
49
50 /**
51 * Initial setup for this unit test.
52 */
53 @Before
54 public void setUp() {
Jian Li9b199162019-02-10 18:00:35 +090055 ipam1 = new DefaultK8sIpam(IPAM_ID_1, IP_ADDRESS_1, NETWORK_ID_1);
56 sameAsIpam1 = new DefaultK8sIpam(IPAM_ID_1, IP_ADDRESS_1, NETWORK_ID_1);
57 ipam2 = new DefaultK8sIpam(IPAM_ID_2, IP_ADDRESS_2, NETWORK_ID_2);
Jian Li9ee9c8b2019-01-24 11:48:12 +090058 }
59
60 /**
61 * Tests object equality.
62 */
63 @Test
64 public void testEquality() {
65 new EqualsTester().addEqualityGroup(ipam1, sameAsIpam1)
66 .addEqualityGroup(ipam2)
67 .testEquals();
68 }
69
70 /**
71 * Test object construction.
72 */
73 @Test
74 public void testConstruction() {
75 K8sIpam ipam = ipam1;
76
Jian Li9b199162019-02-10 18:00:35 +090077 assertEquals(IPAM_ID_1, ipam.ipamId());
Jian Li9ee9c8b2019-01-24 11:48:12 +090078 assertEquals(IP_ADDRESS_1, ipam.ipAddress());
79 assertEquals(NETWORK_ID_1, ipam.networkId());
80 }
81}