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.junit.Assert.assertTrue;
28 import java.io.IOException;
29 import java.net.URISyntaxException;
31 import org.junit.Test;
32 import org.openecomp.mso.cloud.CloudIdentity;
33 import org.openecomp.mso.cloud.authentication.models.RackspaceAuthentication;
34 import org.openecomp.mso.openstack.exceptions.MsoException;
36 import com.woorea.openstack.keystone.model.Authentication;
37 import com.woorea.openstack.keystone.model.authentication.UsernamePassword;
40 * A few JUnit tests to evaluate the new factory that manages authentication
41 * types and their associated wrapper classes. Here it is assumed that core types
45 public class AuthenticationMethodTest {
50 public AuthenticationMethodTest() {
51 // TODO Auto-generated constructor stub
55 public void testCustomRackspaceAuth() {
56 CloudIdentity ci = new CloudIdentity();
57 ci.setIdentityAuthenticationType(CloudIdentity.IdentityAuthenticationType.RACKSPACE_APIKEY);
58 ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
62 Authentication auth = AuthenticationMethodFactory.getAuthenticationFor(ci);
63 assertTrue(RackspaceAuthentication.class.equals(auth.getClass()));
64 } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | IOException
65 | URISyntaxException e) {
71 public void testCoreUsernamePasswordAuth() {
72 CloudIdentity ci = new CloudIdentity();
73 ci.setIdentityAuthenticationType(CloudIdentity.IdentityAuthenticationType.USERNAME_PASSWORD);
74 ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
75 ci.setMsoId("someuser");
78 Authentication auth = AuthenticationMethodFactory.getAuthenticationFor(ci);
79 assertTrue(UsernamePassword.class.equals(auth.getClass()));
80 } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | IOException
81 | URISyntaxException e) {
87 public void testCustomRackspaceAuthFromCloudIdentity() {
88 CloudIdentity ci = new CloudIdentity();
89 ci.setIdentityAuthenticationType(CloudIdentity.IdentityAuthenticationType.RACKSPACE_APIKEY);
90 ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
94 Authentication auth = ci.getAuthentication();
95 assertTrue(RackspaceAuthentication.class.equals(auth.getClass()));
96 } catch (MsoException e) {
102 public void testCoreUsernamePasswordAuthFromCloudIdentity() {
103 CloudIdentity ci = new CloudIdentity();
104 ci.setIdentityAuthenticationType(CloudIdentity.IdentityAuthenticationType.USERNAME_PASSWORD);
105 ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
106 ci.setMsoId("someuser");
109 Authentication auth = ci.getAuthentication();
110 assertTrue(UsernamePassword.class.equals(auth.getClass()));
111 } catch (MsoException e) {