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