beb85a4a8eac737dfd65d890460c89e2a3f6e653
[so.git] /
1 /*
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
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
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============================================
18  *
19  * ECOMP and OpenECOMP are trademarks
20  * and service marks of AT&T Intellectual Property.
21  *
22  */
23
24 package org.openecomp.mso.cloud.authentication;
25
26 import static org.junit.Assert.assertTrue;
27
28 import java.io.IOException;
29 import java.net.URISyntaxException;
30
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;
35
36 import com.woorea.openstack.keystone.model.Authentication;
37 import com.woorea.openstack.keystone.model.authentication.UsernamePassword;
38
39 /**
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
42  * only are tested.
43  *
44  */
45 public class AuthenticationMethodTest {
46
47         /**
48          * 
49          */
50         public AuthenticationMethodTest() {
51                 // TODO Auto-generated constructor stub
52         }
53         
54         @Test
55         public void testCustomRackspaceAuth() {
56                 CloudIdentity ci = new CloudIdentity();
57                 ci.setIdentityAuthenticationType(CloudIdentity.IdentityAuthenticationType.RACKSPACE_APIKEY);
58                 ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
59                 ci.setMsoId("test");
60                 
61                 try {
62                         Authentication auth = AuthenticationMethodFactory.getAuthenticationFor(ci);
63                         assertTrue(RackspaceAuthentication.class.equals(auth.getClass()));
64                 } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | IOException
65                                 | URISyntaxException e) {
66                         e.printStackTrace();
67                 }
68         }
69         
70         @Test
71         public void testCoreUsernamePasswordAuth() {
72                 CloudIdentity ci = new CloudIdentity();
73                 ci.setIdentityAuthenticationType(CloudIdentity.IdentityAuthenticationType.USERNAME_PASSWORD);
74                 ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
75                 ci.setMsoId("someuser");
76                 
77                 try {
78                         Authentication auth = AuthenticationMethodFactory.getAuthenticationFor(ci);
79                         assertTrue(UsernamePassword.class.equals(auth.getClass()));
80                 } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | IOException
81                                 | URISyntaxException e) {
82                         e.printStackTrace();
83                 }
84         }
85         
86         @Test
87         public void testCustomRackspaceAuthFromCloudIdentity() {
88                 CloudIdentity ci = new CloudIdentity();
89                 ci.setIdentityAuthenticationType(CloudIdentity.IdentityAuthenticationType.RACKSPACE_APIKEY);
90                 ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
91                 ci.setMsoId("test");
92                 
93                 try {
94                         Authentication auth = ci.getAuthentication();
95                         assertTrue(RackspaceAuthentication.class.equals(auth.getClass()));
96                 } catch (MsoException e) {
97                         e.printStackTrace();
98                 }
99         }
100         
101         @Test
102         public void testCoreUsernamePasswordAuthFromCloudIdentity() {
103                 CloudIdentity ci = new CloudIdentity();
104                 ci.setIdentityAuthenticationType(CloudIdentity.IdentityAuthenticationType.USERNAME_PASSWORD);
105                 ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
106                 ci.setMsoId("someuser");
107                 
108                 try {
109                         Authentication auth = ci.getAuthentication();
110                         assertTrue(UsernamePassword.class.equals(auth.getClass()));
111                 } catch (MsoException e) {
112                         e.printStackTrace();
113                 }
114         }
115 }