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 | import static org.onosproject.openstacknode.api.OpenstackAuth.Perspective.PUBLIC; |
| 25 | import static org.onosproject.openstacknode.api.OpenstackAuth.Protocol.HTTP; |
| 26 | |
| 27 | /** |
| 28 | * Unit tests for DefaultKeystoneConfig. |
| 29 | */ |
| 30 | public final class DefaultKeystoneConfigTest { |
| 31 | |
| 32 | private static final String ENDPOINT_1 = "192.168.0.10:35357/v2.0"; |
| 33 | private static final String ENDPOINT_2 = "192.168.0.11:80/v3"; |
| 34 | |
| 35 | private static final String USERNAME = "admin"; |
| 36 | private static final String PASSWORD = "nova"; |
| 37 | private static final String PROJECT = "admin"; |
| 38 | private static final String VERSION_2 = "v2.0"; |
| 39 | private static final String VERSION_3 = "v3"; |
| 40 | |
| 41 | private static final OpenstackAuth AUTHENTICATION_1 = createAuthv2(); |
| 42 | private static final OpenstackAuth AUTHENTICATION_2 = createAuthv3(); |
| 43 | |
| 44 | private KeystoneConfig config1; |
| 45 | private KeystoneConfig sameAsConfig1; |
| 46 | private KeystoneConfig config2; |
| 47 | |
| 48 | private static OpenstackAuth createAuthv2() { |
| 49 | return DefaultOpenstackAuth.builder() |
| 50 | .username(USERNAME) |
| 51 | .password(PASSWORD) |
| 52 | .project(PROJECT) |
| 53 | .version(VERSION_2) |
| 54 | .perspective(PUBLIC) |
| 55 | .protocol(HTTP) |
| 56 | .build(); |
| 57 | } |
| 58 | |
| 59 | private static OpenstackAuth createAuthv3() { |
| 60 | return DefaultOpenstackAuth.builder() |
| 61 | .username(USERNAME) |
| 62 | .password(PASSWORD) |
| 63 | .project(PROJECT) |
| 64 | .version(VERSION_3) |
| 65 | .perspective(PUBLIC) |
| 66 | .protocol(HTTP) |
| 67 | .build(); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Tests class immutability. |
| 72 | */ |
| 73 | @Test |
| 74 | public void testImmutability() { |
| 75 | assertThatClassIsImmutable(DefaultKeystoneConfig.class); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Initial setup for this unit test. |
| 80 | */ |
| 81 | @Before |
| 82 | public void setUp() { |
| 83 | config1 = DefaultKeystoneConfig.builder() |
| 84 | .endpoint(ENDPOINT_1) |
| 85 | .authentication(AUTHENTICATION_1) |
| 86 | .build(); |
| 87 | |
| 88 | sameAsConfig1 = DefaultKeystoneConfig.builder() |
| 89 | .endpoint(ENDPOINT_1) |
| 90 | .authentication(AUTHENTICATION_1) |
| 91 | .build(); |
| 92 | |
| 93 | config2 = DefaultKeystoneConfig.builder() |
| 94 | .endpoint(ENDPOINT_2) |
| 95 | .authentication(AUTHENTICATION_2) |
| 96 | .build(); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Tests object equality. |
| 101 | */ |
| 102 | @Test |
| 103 | public void testEquality() { |
| 104 | new EqualsTester().addEqualityGroup(config1, sameAsConfig1) |
| 105 | .addEqualityGroup(config2) |
| 106 | .testEquals(); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Test object construction. |
| 111 | */ |
| 112 | @Test |
| 113 | public void testConstruction() { |
| 114 | KeystoneConfig config = config1; |
| 115 | |
| 116 | assertEquals(config.endpoint(), ENDPOINT_1); |
| 117 | assertEquals(config.authentication(), AUTHENTICATION_1); |
| 118 | } |
| 119 | } |