Jian Li | 2784166 | 2018-04-14 01:59:47 +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.impl; |
| 17 | |
| 18 | import com.google.common.testing.EqualsTester; |
| 19 | import org.junit.Test; |
| 20 | import org.onosproject.openstacknode.api.OpenstackAuth; |
| 21 | |
| 22 | import static org.hamcrest.MatcherAssert.assertThat; |
| 23 | import static org.hamcrest.Matchers.is; |
| 24 | |
| 25 | /** |
| 26 | * Unit tests for DefaultOpenstackAuth. |
| 27 | */ |
| 28 | public class DefaultOpenstackAuthTest { |
| 29 | |
| 30 | private static final String USERNAME = "admin"; |
| 31 | private static final String PASSWORD = "nova"; |
| 32 | private static final String PROJECT = "admin"; |
| 33 | private static final String VERSION_1 = "v2.0"; |
| 34 | private static final String VERSION_2 = "v3"; |
| 35 | private static final Integer PORT_1 = 35357; |
| 36 | private static final Integer PORT_2 = 5000; |
| 37 | private static final OpenstackAuth.Protocol PROTOCOL_1 = OpenstackAuth.Protocol.HTTP; |
| 38 | private static final OpenstackAuth.Protocol PROTOCOL_2 = OpenstackAuth.Protocol.HTTPS; |
| 39 | |
| 40 | private static final OpenstackAuth OS_AUTH_1 = |
| 41 | createOpenstackAuth(VERSION_1, PORT_1, PROTOCOL_1); |
| 42 | private static final OpenstackAuth OS_AUTH_2 = |
| 43 | createOpenstackAuth(VERSION_2, PORT_2, PROTOCOL_2); |
| 44 | private static final OpenstackAuth OS_AUTH_3 = |
| 45 | createOpenstackAuth(VERSION_1, PORT_1, PROTOCOL_1); |
| 46 | |
| 47 | private static OpenstackAuth createOpenstackAuth(String version, |
| 48 | Integer port, |
| 49 | OpenstackAuth.Protocol protocol) { |
| 50 | return DefaultOpenstackAuth.builder() |
| 51 | .version(version) |
| 52 | .port(port) |
| 53 | .protocol(protocol) |
| 54 | .username(USERNAME) |
| 55 | .password(PASSWORD) |
| 56 | .project(PROJECT) |
| 57 | .perspective(OpenstackAuth.Perspective.PUBLIC) |
| 58 | .build(); |
| 59 | } |
| 60 | |
| 61 | @Test |
| 62 | public void testEquality() { |
| 63 | new EqualsTester().addEqualityGroup(OS_AUTH_1, OS_AUTH_3) |
| 64 | .addEqualityGroup(OS_AUTH_2) |
| 65 | .testEquals(); |
| 66 | } |
| 67 | |
| 68 | @Test |
| 69 | public void testConstruction() { |
| 70 | OpenstackAuth auth = OS_AUTH_1; |
| 71 | |
| 72 | assertThat(auth.version(), is("v2.0")); |
| 73 | assertThat(auth.port(), is(35357)); |
| 74 | assertThat(auth.protocol(), is(OpenstackAuth.Protocol.HTTP)); |
| 75 | assertThat(auth.username(), is("admin")); |
| 76 | assertThat(auth.password(), is("nova")); |
| 77 | assertThat(auth.project(), is("admin")); |
| 78 | assertThat(auth.perspective(), is(OpenstackAuth.Perspective.PUBLIC)); |
| 79 | } |
| 80 | } |