Jian Li | 9ee9c8b | 2019-01-24 11:48:12 +0900 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.k8snetworking.api; |
| 17 | |
| 18 | import com.google.common.testing.EqualsTester; |
| 19 | import org.junit.Before; |
| 20 | import org.junit.Test; |
| 21 | import org.onlab.packet.IpAddress; |
| 22 | |
| 23 | import static junit.framework.TestCase.assertEquals; |
| 24 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 25 | |
| 26 | /** |
| 27 | * Unit tests for the default kubernetes IPAM. |
| 28 | */ |
| 29 | public 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 Li | 9b19916 | 2019-02-10 18:00:35 +0900 | [diff] [blame^] | 35 | 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 Li | 9ee9c8b | 2019-01-24 11:48:12 +0900 | [diff] [blame] | 37 | |
| 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 Li | 9b19916 | 2019-02-10 18:00:35 +0900 | [diff] [blame^] | 55 | 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 Li | 9ee9c8b | 2019-01-24 11:48:12 +0900 | [diff] [blame] | 58 | } |
| 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 Li | 9b19916 | 2019-02-10 18:00:35 +0900 | [diff] [blame^] | 77 | assertEquals(IPAM_ID_1, ipam.ipamId()); |
Jian Li | 9ee9c8b | 2019-01-24 11:48:12 +0900 | [diff] [blame] | 78 | assertEquals(IP_ADDRESS_1, ipam.ipAddress()); |
| 79 | assertEquals(NETWORK_ID_1, ipam.networkId()); |
| 80 | } |
| 81 | } |