ccfede72977748a1ef87c683aebd5ff09592a0b2
[so.git] /
1 /*\r
2  * ============LICENSE_START==========================================\r
3  * ===================================================================\r
4  * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.\r
5  * ===================================================================\r
6  * Licensed under the Apache License, Version 2.0 (the "License");\r
7  * you may not use this file except in compliance with the License.\r
8  * You may obtain a copy of the License at\r
9  *\r
10  *        http://www.apache.org/licenses/LICENSE-2.0\r
11  *\r
12  * Unless required by applicable law or agreed to in writing, software\r
13  * distributed under the License is distributed on an "AS IS" BASIS,\r
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
15  * See the License for the specific language governing permissions and\r
16  * limitations under the License.\r
17  * ============LICENSE_END============================================\r
18  *\r
19  * ECOMP and OpenECOMP are trademarks\r
20  * and service marks of AT&T Intellectual Property.\r
21  *\r
22  */\r
23 \r
24 package org.openecomp.mso.cloud.authentication;\r
25 \r
26 import static org.junit.Assert.assertTrue;\r
27 \r
28 import java.io.IOException;\r
29 import java.net.URISyntaxException;\r
30 \r
31 import org.junit.Test;\r
32 import org.openecomp.mso.cloud.CloudIdentity;\r
33 import org.openecomp.mso.cloud.authentication.models.RackspaceAuthentication;\r
34 import org.openecomp.mso.openstack.exceptions.MsoException;\r
35 \r
36 import com.woorea.openstack.keystone.model.Authentication;\r
37 import com.woorea.openstack.keystone.model.authentication.UsernamePassword;\r
38 \r
39 /**\r
40  * A few JUnit tests to evaluate the new factory that manages authentication\r
41  * types and their associated wrapper classes. Here it is assumed that core types\r
42  * only are tested.\r
43  *\r
44  */\r
45 public class AuthenticationMethodTest {\r
46 \r
47         /**\r
48          * \r
49          */\r
50         public AuthenticationMethodTest() {\r
51                 // TODO Auto-generated constructor stub\r
52         }\r
53         \r
54         @Test\r
55         public void testCustomRackspaceAuth() {\r
56                 CloudIdentity ci = new CloudIdentity();\r
57                 ci.setIdentityAuthenticationType(CloudIdentity.IdentityAuthenticationType.RACKSPACE_APIKEY);\r
58                 ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");\r
59                 ci.setMsoId("test");\r
60                 \r
61                 try {\r
62                         Authentication auth = AuthenticationMethodFactory.getAuthenticationFor(ci);\r
63                         assertTrue(RackspaceAuthentication.class.equals(auth.getClass()));\r
64                 } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | IOException\r
65                                 | URISyntaxException e) {\r
66                         e.printStackTrace();\r
67                 }\r
68         }\r
69         \r
70         @Test\r
71         public void testCoreUsernamePasswordAuth() {\r
72                 CloudIdentity ci = new CloudIdentity();\r
73                 ci.setIdentityAuthenticationType(CloudIdentity.IdentityAuthenticationType.USERNAME_PASSWORD);\r
74                 ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");\r
75                 ci.setMsoId("someuser");\r
76                 \r
77                 try {\r
78                         Authentication auth = AuthenticationMethodFactory.getAuthenticationFor(ci);\r
79                         assertTrue(UsernamePassword.class.equals(auth.getClass()));\r
80                 } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | IOException\r
81                                 | URISyntaxException e) {\r
82                         e.printStackTrace();\r
83                 }\r
84         }\r
85         \r
86         @Test\r
87         public void testCustomRackspaceAuthFromCloudIdentity() {\r
88                 CloudIdentity ci = new CloudIdentity();\r
89                 ci.setIdentityAuthenticationType(CloudIdentity.IdentityAuthenticationType.RACKSPACE_APIKEY);\r
90                 ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");\r
91                 ci.setMsoId("test");\r
92                 \r
93                 try {\r
94                         Authentication auth = ci.getAuthentication();\r
95                         assertTrue(RackspaceAuthentication.class.equals(auth.getClass()));\r
96                 } catch (MsoException e) {\r
97                         e.printStackTrace();\r
98                 }\r
99         }\r
100         \r
101         @Test\r
102         public void testCoreUsernamePasswordAuthFromCloudIdentity() {\r
103                 CloudIdentity ci = new CloudIdentity();\r
104                 ci.setIdentityAuthenticationType(CloudIdentity.IdentityAuthenticationType.USERNAME_PASSWORD);\r
105                 ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");\r
106                 ci.setMsoId("someuser");\r
107                 \r
108                 try {\r
109                         Authentication auth = ci.getAuthentication();\r
110                         assertTrue(UsernamePassword.class.equals(auth.getClass()));\r
111                 } catch (MsoException e) {\r
112                         e.printStackTrace();\r
113                 }\r
114         }\r
115 }\r