aboutsummaryrefslogtreecommitdiffstats
path: root/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodFactoryTest.java
blob: 2cfce276d82e50ed95bc6d2c102801c6d098e6ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 * ============LICENSE_START==========================================
 * ===================================================================
 * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
 * ===================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END============================================
 *
 * ECOMP and OpenECOMP are trademarks
 * and service marks of AT&T Intellectual Property.
 *
 */

package org.openecomp.mso.cloud.authentication;

import static org.assertj.core.api.Assertions.assertThat;

import com.woorea.openstack.keystone.model.Authentication;
import org.junit.Test;
import org.openecomp.mso.cloud.CloudIdentity;
import org.openecomp.mso.cloud.CloudIdentity.IdentityAuthenticationType;
import org.openecomp.mso.cloud.authentication.wrappers.RackspaceAPIKeyWrapper;

public class AuthenticationMethodFactoryTest {

    private static final Class WRAPPER_CLASS = RackspaceAPIKeyWrapper.class;
    private static final String AUTHENTICATION_TYPE = "authenticationTest";

    @Test
    public void register_NoExceptionThrown() throws IllegalAccessException, InstantiationException {
        AuthenticationMethodFactory.register(AUTHENTICATION_TYPE, WRAPPER_CLASS);
    }

    @Test
    public void register_throwExceptionWhenAuthTypeIsNull() throws InstantiationException, IllegalAccessException {
        try {
            AuthenticationMethodFactory.register(null, WRAPPER_CLASS);
        } catch (IllegalArgumentException e) {
            assertThat(e.getMessage()).isNotEmpty().contains("Authentication Type to register cannot be null "
                    + "or an empty name string");
        }
    }

    @Test
    public void register_throwExceptionWhenAuthTypeIsEmpty() throws InstantiationException, IllegalAccessException {
        try {
            AuthenticationMethodFactory.register("", WRAPPER_CLASS);
        } catch (IllegalArgumentException e) {
            assertThat(e.getMessage()).isNotEmpty().contains("Authentication Type to register cannot be null "
                    + "or an empty name string");
        }
    }

    @Test
    public void register_throwExceptionWhenWrapperIsNull() throws IllegalAccessException, InstantiationException {
        try {
            AuthenticationMethodFactory.register(AUTHENTICATION_TYPE, null);
        } catch (IllegalArgumentException e) {
            assertThat(e.getMessage()).isNotEmpty()
                    .contains("Wrapper Class to register for Authentication cannot be null");
        }
    }

    @Test
    public void getAuthentication_NoExceptionThrown() {
        CloudIdentity cloudIdentity = new CloudIdentity();
        cloudIdentity.setIdentityAuthenticationType(IdentityAuthenticationType.RACKSPACE_APIKEY);
        cloudIdentity.setMsoId("msoIdTest");
        cloudIdentity.setMsoPass("123");
        Authentication result = AuthenticationMethodFactory.getAuthenticationFor(cloudIdentity);
        assertThat(result).isNotNull();
    }

    @Test
    public void getAuthentication_ThrowExWhenCloudSiteIsNull() {
        try {
            AuthenticationMethodFactory.getAuthenticationFor(null);
        } catch (IllegalArgumentException e) {
            assertThat(e.getMessage()).isNotEmpty().contains("Cloud identity cannot be null");
        }
    }

    @Test
    public void getAuthentication_ThrowExWhenIdentityAuthenticationTypeIsNotSet() {
        try {
            AuthenticationMethodFactory.getAuthenticationFor(new CloudIdentity());
        } catch (IllegalArgumentException e) {
            assertThat(e.getMessage()).isNotEmpty()
                    .contains("Cloud identity authentication type cannot be null or empty");
        }
    }

}