Containerization feature of SO
[so.git] / adapters / mso-adapter-utils / src / test / java / org / onap / so / cloud / authentication / AuthenticationMethodTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.cloud.authentication;
22
23 import static org.junit.Assert.assertTrue;
24
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;
36
37 import com.woorea.openstack.keystone.model.Authentication;
38 import com.woorea.openstack.keystone.model.authentication.UsernamePassword;
39
40 /**
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
43  * only are tested.
44  *
45  */
46 @RunWith(SpringRunner.class)
47 @SpringBootTest(classes = Application.class)
48 @ActiveProfiles("test")
49 public class AuthenticationMethodTest {
50
51         @Autowired
52         private AuthenticationMethodFactory authenticationMethodFactory;
53         /**
54          * 
55          */
56         public AuthenticationMethodTest() {
57                 // TODO Auto-generated constructor stub
58         }
59         
60         @Test
61         public void testCustomRackspaceAuth() {
62                 CloudIdentity ci = new CloudIdentity();
63                 ci.setIdentityAuthenticationType(AuthenticationType.RACKSPACE_APIKEY);
64                 ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
65                 ci.setMsoId("test");
66                 
67                 Authentication auth = authenticationMethodFactory.getAuthenticationFor(ci);
68                 assertTrue(RackspaceAuthentication.class.equals(auth.getClass()));
69         
70         }
71         
72         @Test
73         public void testCoreUsernamePasswordAuth() {
74                 CloudIdentity ci = new CloudIdentity();
75                 ci.setIdentityAuthenticationType(AuthenticationType.USERNAME_PASSWORD);
76                 ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
77                 ci.setMsoId("someuser");
78                 
79                 Authentication auth = authenticationMethodFactory.getAuthenticationFor(ci);
80                 assertTrue(UsernamePassword.class.equals(auth.getClass()));
81                 
82         }
83         
84         @Test
85         public void testCustomRackspaceAuthFromCloudIdentity() {
86                 CloudIdentity ci = new CloudIdentity();
87                 ci.setIdentityAuthenticationType(AuthenticationType.RACKSPACE_APIKEY);
88                 ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
89                 ci.setMsoId("test");
90                 
91                 Authentication auth = authenticationMethodFactory.getAuthenticationFor(ci);
92                 assertTrue(RackspaceAuthentication.class.equals(auth.getClass()));
93         }
94         
95         @Test
96         public void testCoreUsernamePasswordAuthFromCloudIdentity() {
97                 CloudIdentity ci = new CloudIdentity();
98                 ci.setIdentityAuthenticationType(AuthenticationType.USERNAME_PASSWORD);
99                 ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
100                 ci.setMsoId("someuser");
101
102                 Authentication auth = authenticationMethodFactory.getAuthenticationFor(ci);
103                 assertTrue(UsernamePassword.class.equals(auth.getClass()));
104         
105         }
106 }