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.BaseTest;
28 import org.onap.so.cloud.Application;
29 import org.onap.so.db.catalog.beans.AuthenticationType;
30 import org.onap.so.db.catalog.beans.CloudIdentity;
31 import org.onap.so.cloud.authentication.models.RackspaceAuthentication;
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 public class AuthenticationMethodTest extends BaseTest {
49 private AuthenticationMethodFactory authenticationMethodFactory;
53 public AuthenticationMethodTest() {
54 // TODO Auto-generated constructor stub
58 public void testCustomRackspaceAuth() {
59 CloudIdentity ci = new CloudIdentity();
60 ci.setIdentityAuthenticationType(AuthenticationType.RACKSPACE_APIKEY);
61 ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
64 Authentication auth = authenticationMethodFactory.getAuthenticationFor(ci);
65 assertTrue(RackspaceAuthentication.class.equals(auth.getClass()));
70 public void testCoreUsernamePasswordAuth() {
71 CloudIdentity ci = new CloudIdentity();
72 ci.setIdentityAuthenticationType(AuthenticationType.USERNAME_PASSWORD);
73 ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
74 ci.setMsoId("someuser");
76 Authentication auth = authenticationMethodFactory.getAuthenticationFor(ci);
77 assertTrue(UsernamePassword.class.equals(auth.getClass()));
82 public void testCustomRackspaceAuthFromCloudIdentity() {
83 CloudIdentity ci = new CloudIdentity();
84 ci.setIdentityAuthenticationType(AuthenticationType.RACKSPACE_APIKEY);
85 ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
88 Authentication auth = authenticationMethodFactory.getAuthenticationFor(ci);
89 assertTrue(RackspaceAuthentication.class.equals(auth.getClass()));
93 public void testCoreUsernamePasswordAuthFromCloudIdentity() {
94 CloudIdentity ci = new CloudIdentity();
95 ci.setIdentityAuthenticationType(AuthenticationType.USERNAME_PASSWORD);
96 ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
97 ci.setMsoId("someuser");
99 Authentication auth = authenticationMethodFactory.getAuthenticationFor(ci);
100 assertTrue(UsernamePassword.class.equals(auth.getClass()));