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
10 * http://www.apache.org/licenses/LICENSE-2.0
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============================================
19 * ECOMP and OpenECOMP are trademarks
20 * and service marks of AT&T Intellectual Property.
24 package org.openecomp.mso.cloud.authentication;
26 import static org.assertj.core.api.Assertions.assertThat;
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;
34 public class AuthenticationMethodFactoryTest {
36 private static final Class WRAPPER_CLASS = RackspaceAPIKeyWrapper.class;
37 private static final String AUTHENTICATION_TYPE = "authenticationTest";
40 public void register_NoExceptionThrown() throws IllegalAccessException, InstantiationException {
41 AuthenticationMethodFactory.register(AUTHENTICATION_TYPE, WRAPPER_CLASS);
45 public void register_throwExceptionWhenAuthTypeIsNull() throws InstantiationException, IllegalAccessException {
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");
55 public void register_throwExceptionWhenAuthTypeIsEmpty() throws InstantiationException, IllegalAccessException {
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");
65 public void register_throwExceptionWhenWrapperIsNull() throws IllegalAccessException, InstantiationException {
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");
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();
85 public void getAuthentication_ThrowExWhenCloudSiteIsNull() {
87 AuthenticationMethodFactory.getAuthenticationFor(null);
88 } catch (IllegalArgumentException e) {
89 assertThat(e.getMessage()).isNotEmpty().contains("Cloud identity cannot be null");
94 public void getAuthentication_ThrowExWhenIdentityAuthenticationTypeIsNotSet() {
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");