Initial OpenECOMP MSO commit
[so.git] / adapters / mso-adapter-utils / src / test / java / org / openecomp / mso / adapter_utils / tests / CloudConfigTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
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.openecomp.mso.adapter_utils.tests;
22
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertNull;
27 import org.junit.BeforeClass;
28 import org.junit.Test;
29 import java.util.Map;
30 import org.openecomp.mso.cloud.CloudConfig;
31 import org.openecomp.mso.cloud.CloudConfigFactory;
32 import org.openecomp.mso.cloud.CloudIdentity;
33 import org.openecomp.mso.cloud.CloudSite;
34
35
36 /**
37  * This class implements test methods of the CloudConfig features.
38  *
39  *
40  */
41 public class CloudConfigTest {
42    
43         private static CloudConfig con;
44         private static CloudConfigFactory cloudConfigFactory= new CloudConfigFactory();
45         
46         public CloudConfigTest () {
47                    
48         }
49         
50         /**
51     * This method is called before any test occurs.
52     * It creates a fake tree from scratch
53     */
54    @BeforeClass
55    public static final void prepare () {
56            ClassLoader classLoader = CloudConfigTest.class.getClassLoader();
57            String config = classLoader.getResource("cloud_config.json").toString().substring(5);
58            
59            cloudConfigFactory.initializeCloudConfig(config,1);
60            con = cloudConfigFactory.getCloudConfig();
61    }
62  
63    /**
64     * This method implements a test for the getCloudConfig method.
65     */
66    @Test
67    public final void testGetCloudConfig () {
68            assertNotNull(con);
69    }
70
71    /**
72     * This method implements a test for the getCloudSites method.
73     */
74    @Test
75    public final void testGetCloudSites () {
76            Map<String,CloudSite> siteMap = con.getCloudSites();
77            assertNotNull(siteMap);
78
79            CloudSite site1 = siteMap.get("MT");
80            CloudSite site2 = siteMap.get("DAN");
81            CloudSite site3 = siteMap.get("MTINJVCC101");
82            
83            assertEquals (site1.getRegionId(), "regionOne");
84            assertEquals (site1.getIdentityServiceId(), "MT_KEYSTONE");
85            assertEquals (site2.getRegionId(), "RegionOne");
86            assertEquals (site2.getIdentityServiceId(), "DAN_KEYSTONE");
87            assertEquals (site3.getRegionId(), "regionTwo");
88            assertEquals (site3.getIdentityServiceId(), "MTINJVCC101_DCP");
89          
90    }
91    
92    
93    /**
94     * This method implements a test for the getIdentityServices method.
95     */
96    @Test
97    public final void testGetIdentityServices () {
98            Map<String,CloudIdentity> identityMap = con.getIdentityServices ();
99            assertNotNull(identityMap);
100            
101            CloudIdentity identity1 = identityMap.get("MT_KEYSTONE");
102            CloudIdentity identity2 = identityMap.get("DAN_KEYSTONE");
103            CloudIdentity identity3 = identityMap.get("MTINJVCC101_DCP");
104            CloudIdentity identity4 = identityMap.get("MTSNJA3DCP1");
105            
106 //         assertEquals (identity1.getKeystoneUrl(), "http://localhost:5000/v2.0");
107 //         assertEquals (identity1.getIdentityUrl(), "http://localhost:5000/v2.0");
108            assertEquals (identity1.getMsoId(), "john");
109            assertEquals (identity1.getMsoPass(), "changeme");
110            assertEquals (identity1.getAdminTenant(), "admin");
111            assertEquals (identity1.getMemberRole(), "_member_");
112            assertEquals (identity1.hasTenantMetadata(), false);
113            
114 //         assertEquals (identity2.getKeystoneUrl(), "http://localhost:5000/v2.0");
115 //         assertEquals (identity2.getIdentityUrl(), "http://localhost:5000/v2.0");
116            assertEquals (identity2.getMsoId(), "mockId");
117            assertEquals (identity2.getMsoPass(), "stack123");
118            assertEquals (identity2.getAdminTenant(), "service");
119            assertEquals (identity2.getMemberRole(), "_member_");
120            assertEquals (identity2.hasTenantMetadata(), false);
121            
122 //         assertEquals (identity3.getKeystoneUrl(), "http://localhost:5000/v2.0");
123 //         assertEquals (identity3.getIdentityUrl(), "http://localhost:5000/v2.0");
124            assertEquals (identity3.getMsoId(), "mockIdToo");
125            assertEquals (identity3.getMsoPass(), "AICG@mm@@2015");
126            assertEquals (identity3.getAdminTenant(), "service");
127            assertEquals (identity3.getMemberRole(), "admin");
128            assertEquals (identity3.hasTenantMetadata(), true);
129            
130 //         assertEquals (identity4.getKeystoneUrl(), "https://localhost:5000/v2.0");
131 //         assertEquals (identity4.getIdentityUrl(), "https://localhost:5000/v2.0");
132            assertEquals (identity4.getMsoId(), "mockIdToo");
133            assertEquals (identity4.getMsoPass(), "2315QRS2015srq");
134            assertEquals (identity4.getAdminTenant(), "service");
135            assertEquals (identity4.getMemberRole(), "admin");
136            assertEquals (identity4.hasTenantMetadata(), true);
137
138    }
139    
140    /**
141     * This method implements a test for the getCloudSite method.
142     */
143    @Test
144    public final void testGetCloudSite () {
145            CloudSite site1  = con.getCloudSite("MT");
146            assertNotNull(site1);
147            assertEquals (site1.getRegionId(), "regionOne");
148            assertEquals (site1.getIdentityServiceId(), "MT_KEYSTONE");
149            
150          
151
152    }
153
154    /**
155     * This method implements a test for the getIdentityService method.
156     */
157    @Test
158    public final void testGetIdentityService () {
159            CloudIdentity identity1  = con.getIdentityService("MT_KEYSTONE");
160            assertNotNull(identity1);
161 //         assertEquals (identity1.getKeystoneUrl(), "http://localhost:5000/v2.0");
162 //         assertEquals (identity1.getIdentityUrl(), "http://localhost:5000/v2.0");
163            assertEquals (identity1.getMsoId(), "john");
164            assertEquals (identity1.getMsoPass(), "changeme");
165            assertEquals (identity1.getAdminTenant(), "admin");
166            assertEquals (identity1.getMemberRole(), "_member_");
167            assertEquals (identity1.hasTenantMetadata(), false);
168            
169            CloudIdentity identity2  = con.getIdentityService("Test");
170            assertNull(identity2);
171    }
172
173 }