2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.cloud.authentication;
23 import static org.junit.Assert.assertTrue;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.onap.so.cloud.Application;
28 import org.onap.so.cloud.AuthenticationType;
29 import org.onap.so.cloud.CloudIdentity;
30 import org.onap.so.cloud.authentication.models.RackspaceAuthentication;
31 import org.onap.so.openstack.exceptions.MsoException;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.boot.test.context.SpringBootTest;
34 import org.springframework.test.context.ActiveProfiles;
35 import org.springframework.test.context.junit4.SpringRunner;
37 import com.woorea.openstack.keystone.model.Authentication;
38 import com.woorea.openstack.keystone.model.authentication.UsernamePassword;
41 * A few JUnit tests to evaluate the new factory that manages authentication
42 * types and their associated wrapper classes. Here it is assumed that core types
46 @RunWith(SpringRunner.class)
47 @SpringBootTest(classes = Application.class)
48 @ActiveProfiles("test")
49 public class AuthenticationMethodTest {
52 private AuthenticationMethodFactory authenticationMethodFactory;
56 public AuthenticationMethodTest() {
57 // TODO Auto-generated constructor stub
61 public void testCustomRackspaceAuth() {
62 CloudIdentity ci = new CloudIdentity();
63 ci.setIdentityAuthenticationType(AuthenticationType.RACKSPACE_APIKEY);
64 ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
67 Authentication auth = authenticationMethodFactory.getAuthenticationFor(ci);
68 assertTrue(RackspaceAuthentication.class.equals(auth.getClass()));
73 public void testCoreUsernamePasswordAuth() {
74 CloudIdentity ci = new CloudIdentity();
75 ci.setIdentityAuthenticationType(AuthenticationType.USERNAME_PASSWORD);
76 ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
77 ci.setMsoId("someuser");
79 Authentication auth = authenticationMethodFactory.getAuthenticationFor(ci);
80 assertTrue(UsernamePassword.class.equals(auth.getClass()));
85 public void testCustomRackspaceAuthFromCloudIdentity() {
86 CloudIdentity ci = new CloudIdentity();
87 ci.setIdentityAuthenticationType(AuthenticationType.RACKSPACE_APIKEY);
88 ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
91 Authentication auth = authenticationMethodFactory.getAuthenticationFor(ci);
92 assertTrue(RackspaceAuthentication.class.equals(auth.getClass()));
96 public void testCoreUsernamePasswordAuthFromCloudIdentity() {
97 CloudIdentity ci = new CloudIdentity();
98 ci.setIdentityAuthenticationType(AuthenticationType.USERNAME_PASSWORD);
99 ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
100 ci.setMsoId("someuser");
102 Authentication auth = authenticationMethodFactory.getAuthenticationFor(ci);
103 assertTrue(UsernamePassword.class.equals(auth.getClass()));