Containerization feature of SO
[so.git] / adapters / mso-adapter-utils / src / test / java / org / onap / so / cloud / CloudIdentityTest.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;
22
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertTrue;
26
27 import java.security.GeneralSecurityException;
28
29 import org.junit.Test;
30 import org.onap.so.utils.CryptoUtils;
31
32 public class CloudIdentityTest {
33         
34         private CloudIdentity cloudIdentity = new CloudIdentity();
35         private static final String ID = "testId";
36         private static final String IDENTITY_URL = "testIdentityUrl";
37         private static final String MSO_ID = "testMsoId";
38         private static final String MSO_PASS = "testMsoPassword";
39         private static final String ADMIN_TENANT = "testAdminTenant";
40         private static final String MEMBER_ROLE = "testMemberRole";
41         private static final Boolean TENANT_METADATA = true;
42         
43     @Test
44     public final void testCloudIdentity () {
45         CloudIdentity id = new CloudIdentity ();
46         id.setAdminTenant ("AdminTenant");
47         id.setId ("id");
48 //        id.setKeystoneUrl ("keystone");
49         id.setIdentityUrl ("keystone");
50         id.setMemberRole ("member");
51         id.setMsoId ("msoId");
52         id.setMsoPass (CryptoUtils.encryptCloudConfigPassword("password"));
53         id.setTenantMetadata (true);
54         id.setIdentityServerType(null);
55         id.setIdentityAuthenticationType(null);
56         
57
58         assertTrue (id.getAdminTenant ().equals ("AdminTenant"));
59         assertTrue (id.getId ().equals ("id"));
60 //        assertTrue (id.getKeystoneUrl ().equals ("keystone"));
61         assertTrue (id.getMemberRole ().equals ("member"));
62         assertTrue (id.getMsoId ().equals ("msoId"));
63         assertTrue (CryptoUtils.decryptCloudConfigPassword(id.getMsoPass()).equals ("password"));
64         assertTrue (id.hasTenantMetadata ());
65 //        assertTrue (id.toString ().contains ("keystone"));
66         assertTrue(id.toString().contains("null"));
67     }
68
69     @Test
70     public final void testEncryption () throws GeneralSecurityException {
71         String encrypted = CryptoUtils.encryptCloudConfigPassword("password");
72         assertTrue (encrypted != null);
73         assertTrue (!encrypted.equals ("password"));
74     }
75     
76     @Test
77     public void cloneTest() {
78         cloudIdentity = setupCloudIdentity(cloudIdentity, ID, IDENTITY_URL, MSO_ID, MSO_PASS, ADMIN_TENANT, 
79                         MEMBER_ROLE, TENANT_METADATA, ServerType.ORM, AuthenticationType.USERNAME_PASSWORD);
80         CloudIdentity cloudIdentity2 = cloudIdentity.clone();
81         
82         assertEquals(cloudIdentity.getClass(), cloudIdentity2.getClass());
83     }
84         
85     private CloudIdentity setupCloudIdentity(CloudIdentity obj, String id, String identityUrl, 
86                 String msoId, String msoPass, String adminTenant, String memberRole, Boolean tenantMetadata, 
87                 ServerType identityServerType, AuthenticationType identityAuthenticationType) {
88                 obj.setId(id);
89                 obj.setIdentityUrl(identityUrl);
90                 obj.setMsoId(msoId);
91                 obj.setMsoPass(msoPass);
92                 obj.setAdminTenant(adminTenant);
93                 obj.setMemberRole(memberRole);
94                 obj.setTenantMetadata(tenantMetadata);
95                 obj.setIdentityServerType(identityServerType);
96                 obj.setIdentityAuthenticationType(identityAuthenticationType);
97                 
98                 return obj;
99         }
100 }