Merge "Reorder modifiers"
[so.git] / adapters / mso-adapter-utils / src / test / java / org / openecomp / mso / cloud / authentication / AuthenticationMethodFactoryTest.java
1 /*
2  * ============LICENSE_START==========================================
3  * ===================================================================
4  * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
5  * ===================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  * ============LICENSE_END============================================
18  *
19  * ECOMP and OpenECOMP are trademarks
20  * and service marks of AT&T Intellectual Property.
21  *
22  */
23
24 package org.openecomp.mso.cloud.authentication;
25
26 import static org.assertj.core.api.Assertions.assertThat;
27
28 import com.woorea.openstack.keystone.model.Authentication;
29 import org.junit.Test;
30 import org.openecomp.mso.cloud.CloudIdentity;
31 import org.openecomp.mso.cloud.CloudIdentity.IdentityAuthenticationType;
32 import org.openecomp.mso.cloud.authentication.wrappers.RackspaceAPIKeyWrapper;
33
34 public class AuthenticationMethodFactoryTest {
35
36     private static final Class WRAPPER_CLASS = RackspaceAPIKeyWrapper.class;
37     private static final String AUTHENTICATION_TYPE = "authenticationTest";
38
39     @Test
40     public void register_NoExceptionThrown() throws IllegalAccessException, InstantiationException {
41         AuthenticationMethodFactory.register(AUTHENTICATION_TYPE, WRAPPER_CLASS);
42     }
43
44     @Test
45     public void register_throwExceptionWhenAuthTypeIsNull() throws InstantiationException, IllegalAccessException {
46         try {
47             AuthenticationMethodFactory.register(null, WRAPPER_CLASS);
48         } catch (IllegalArgumentException e) {
49             assertThat(e.getMessage()).isNotEmpty().contains("Authentication Type to register cannot be null "
50                     + "or an empty name string");
51         }
52     }
53
54     @Test
55     public void register_throwExceptionWhenAuthTypeIsEmpty() throws InstantiationException, IllegalAccessException {
56         try {
57             AuthenticationMethodFactory.register("", WRAPPER_CLASS);
58         } catch (IllegalArgumentException e) {
59             assertThat(e.getMessage()).isNotEmpty().contains("Authentication Type to register cannot be null "
60                     + "or an empty name string");
61         }
62     }
63
64     @Test
65     public void register_throwExceptionWhenWrapperIsNull() throws IllegalAccessException, InstantiationException {
66         try {
67             AuthenticationMethodFactory.register(AUTHENTICATION_TYPE, null);
68         } catch (IllegalArgumentException e) {
69             assertThat(e.getMessage()).isNotEmpty()
70                     .contains("Wrapper Class to register for Authentication cannot be null");
71         }
72     }
73
74     @Test
75     public void getAuthentication_NoExceptionThrown() {
76         CloudIdentity cloudIdentity = new CloudIdentity();
77         cloudIdentity.setIdentityAuthenticationType(IdentityAuthenticationType.RACKSPACE_APIKEY);
78         cloudIdentity.setMsoId("msoIdTest");
79         cloudIdentity.setMsoPass("123");
80         Authentication result = AuthenticationMethodFactory.getAuthenticationFor(cloudIdentity);
81         assertThat(result).isNotNull();
82     }
83
84     @Test
85     public void getAuthentication_ThrowExWhenCloudSiteIsNull() {
86         try {
87             AuthenticationMethodFactory.getAuthenticationFor(null);
88         } catch (IllegalArgumentException e) {
89             assertThat(e.getMessage()).isNotEmpty().contains("Cloud identity cannot be null");
90         }
91     }
92
93     @Test
94     public void getAuthentication_ThrowExWhenIdentityAuthenticationTypeIsNotSet() {
95         try {
96             AuthenticationMethodFactory.getAuthenticationFor(new CloudIdentity());
97         } catch (IllegalArgumentException e) {
98             assertThat(e.getMessage()).isNotEmpty()
99                     .contains("Cloud identity authentication type cannot be null or empty");
100         }
101     }
102
103 }