Jian Li | a1ebbf4 | 2020-12-24 02:43:21 +0900 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2020-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.kubevirtnode.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 | import static org.onosproject.kubevirtnode.api.KubevirtApiConfig.Scheme.HTTP; |
| 26 | import static org.onosproject.kubevirtnode.api.KubevirtApiConfig.Scheme.HTTPS; |
| 27 | import static org.onosproject.kubevirtnode.api.KubevirtApiConfig.State.CONNECTED; |
| 28 | |
| 29 | |
| 30 | /** |
| 31 | * Unit tests for DefaultKubevirtApiConfig. |
| 32 | */ |
| 33 | public final class DefaultKubevirtApiConfigTest { |
| 34 | |
| 35 | private static final KubevirtApiConfig.Scheme SCHEME_1 = HTTP; |
| 36 | private static final KubevirtApiConfig.Scheme SCHEME_2 = HTTPS; |
| 37 | |
| 38 | private static final IpAddress IP_ADDRESS_1 = IpAddress.valueOf("192.168.0.200"); |
| 39 | private static final IpAddress IP_ADDRESS_2 = IpAddress.valueOf("192.168.0.201"); |
| 40 | |
| 41 | private static final int PORT_1 = 6443; |
| 42 | private static final int PORT_2 = 443; |
| 43 | |
| 44 | private static final String TOKEN_1 = "token1"; |
| 45 | private static final String TOKEN_2 = "token2"; |
| 46 | |
| 47 | private static final String CA_CERT_DATA_1 = "caCertData1"; |
| 48 | private static final String CA_CERT_DATA_2 = "caCertData2"; |
| 49 | |
| 50 | private static final String CLIENT_CERT_DATA_1 = "clientCertData1"; |
| 51 | private static final String CLIENT_CERT_DATA_2 = "clientCertData2"; |
| 52 | |
| 53 | private static final String CLIENT_KEY_DATA_1 = "clientKeyData1"; |
| 54 | private static final String CLIENT_KEY_DATA_2 = "clientKeyData2"; |
| 55 | |
| 56 | private KubevirtApiConfig config1; |
| 57 | private KubevirtApiConfig sameAsConfig1; |
| 58 | private KubevirtApiConfig config2; |
| 59 | |
| 60 | /** |
| 61 | * Tests class immutability. |
| 62 | */ |
| 63 | @Test |
| 64 | public void testImmutability() { |
| 65 | assertThatClassIsImmutable(DefaultKubevirtApiConfig.class); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Initial setup for this unit test. |
| 70 | */ |
| 71 | @Before |
| 72 | public void setUp() { |
| 73 | config1 = DefaultKubevirtApiConfig.builder() |
| 74 | .scheme(SCHEME_1) |
| 75 | .ipAddress(IP_ADDRESS_1) |
| 76 | .port(PORT_1) |
| 77 | .state(CONNECTED) |
| 78 | .token(TOKEN_1) |
| 79 | .caCertData(CA_CERT_DATA_1) |
| 80 | .clientCertData(CLIENT_CERT_DATA_1) |
| 81 | .clientKeyData(CLIENT_KEY_DATA_1) |
| 82 | .build(); |
| 83 | |
| 84 | sameAsConfig1 = DefaultKubevirtApiConfig.builder() |
| 85 | .scheme(SCHEME_1) |
| 86 | .ipAddress(IP_ADDRESS_1) |
| 87 | .port(PORT_1) |
| 88 | .state(CONNECTED) |
| 89 | .token(TOKEN_1) |
| 90 | .caCertData(CA_CERT_DATA_1) |
| 91 | .clientCertData(CLIENT_CERT_DATA_1) |
| 92 | .clientKeyData(CLIENT_KEY_DATA_1) |
| 93 | .build(); |
| 94 | |
| 95 | config2 = DefaultKubevirtApiConfig.builder() |
| 96 | .scheme(SCHEME_2) |
| 97 | .ipAddress(IP_ADDRESS_2) |
| 98 | .port(PORT_2) |
| 99 | .state(CONNECTED) |
| 100 | .token(TOKEN_2) |
| 101 | .caCertData(CA_CERT_DATA_2) |
| 102 | .clientCertData(CLIENT_CERT_DATA_2) |
| 103 | .clientKeyData(CLIENT_KEY_DATA_2) |
| 104 | .build(); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Tests object equality. |
| 109 | */ |
| 110 | @Test |
| 111 | public void testEquality() { |
| 112 | new EqualsTester().addEqualityGroup(config1, sameAsConfig1) |
| 113 | .addEqualityGroup(config2) |
| 114 | .testEquals(); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Test object construction. |
| 119 | */ |
| 120 | @Test |
| 121 | public void testConstruction() { |
| 122 | KubevirtApiConfig config = config1; |
| 123 | |
| 124 | assertEquals(SCHEME_1, config.scheme()); |
| 125 | assertEquals(IP_ADDRESS_1, config.ipAddress()); |
| 126 | assertEquals(PORT_1, config.port()); |
| 127 | assertEquals(CONNECTED, config.state()); |
| 128 | assertEquals(TOKEN_1, config.token()); |
| 129 | assertEquals(CA_CERT_DATA_1, config.caCertData()); |
| 130 | assertEquals(CLIENT_CERT_DATA_1, config.clientCertData()); |
| 131 | assertEquals(CLIENT_KEY_DATA_1, config.clientKeyData()); |
| 132 | } |
| 133 | } |