Jian Li | c704b67 | 2018-09-04 18:52:53 +0900 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2018-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.openstacknode.api; |
| 17 | |
| 18 | import com.google.common.testing.EqualsTester; |
| 19 | import org.junit.Before; |
| 20 | import org.junit.Test; |
| 21 | |
| 22 | import static junit.framework.TestCase.assertEquals; |
| 23 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 24 | |
| 25 | /** |
| 26 | * Unit tests for DefaultNeutronConfig. |
| 27 | */ |
| 28 | public class DefaultNeutronConfigTest { |
| 29 | |
| 30 | private static final boolean USE_METADATA_PROXY_1 = true; |
| 31 | private static final boolean USE_METADATA_PROXY_2 = false; |
| 32 | |
| 33 | private static final String METADATA_PROXY_SECRET_1 = "onos"; |
| 34 | private static final String METADATA_PROXY_SECRET_2 = "cord"; |
| 35 | |
| 36 | private NeutronConfig config1; |
| 37 | private NeutronConfig sameAsConfig1; |
| 38 | private NeutronConfig config2; |
| 39 | |
| 40 | /** |
| 41 | * Tests class immutability. |
| 42 | */ |
| 43 | @Test |
| 44 | public void testImmutability() { |
| 45 | assertThatClassIsImmutable(DefaultNeutronConfig.class); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Initial setup for this unit test. |
| 50 | */ |
| 51 | @Before |
| 52 | public void setUp() { |
| 53 | config1 = DefaultNeutronConfig.builder() |
| 54 | .useMetadataProxy(USE_METADATA_PROXY_1) |
| 55 | .metadataProxySecret(METADATA_PROXY_SECRET_1) |
| 56 | .build(); |
| 57 | |
| 58 | sameAsConfig1 = DefaultNeutronConfig.builder() |
| 59 | .useMetadataProxy(USE_METADATA_PROXY_1) |
| 60 | .metadataProxySecret(METADATA_PROXY_SECRET_1) |
| 61 | .build(); |
| 62 | |
| 63 | config2 = DefaultNeutronConfig.builder() |
| 64 | .useMetadataProxy(USE_METADATA_PROXY_2) |
| 65 | .metadataProxySecret(METADATA_PROXY_SECRET_2) |
| 66 | .build(); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Tests object equality. |
| 71 | */ |
| 72 | @Test |
| 73 | public void testEquality() { |
| 74 | new EqualsTester().addEqualityGroup(config1, sameAsConfig1) |
| 75 | .addEqualityGroup(config2) |
| 76 | .testEquals(); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Test object construction. |
| 81 | */ |
| 82 | @Test |
| 83 | public void testConstruction() { |
| 84 | NeutronConfig config = config1; |
| 85 | |
| 86 | assertEquals(config.useMetadataProxy(), USE_METADATA_PROXY_1); |
| 87 | assertEquals(config.metadataProxySecret(), METADATA_PROXY_SECRET_1); |
| 88 | } |
| 89 | } |