2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.mso.adapter_utils.tests;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertNull;
28 import org.junit.Assert;
29 import org.junit.Before;
30 import org.junit.Test;
32 import org.openecomp.mso.cloud.CloudConfig;
33 import org.openecomp.mso.cloud.CloudConfigFactory;
34 import org.openecomp.mso.cloud.CloudIdentity;
35 import org.openecomp.mso.cloud.CloudSite;
36 import org.openecomp.mso.openstack.exceptions.MsoCloudIdentityNotFound;
39 * This class implements test methods of the CloudConfig features.
41 public class CloudConfigTest {
43 private static CloudConfig con;
44 private static CloudConfigFactory cloudConfigFactory= new CloudConfigFactory();
46 public CloudConfigTest () {
51 * This method is called before any test occurs.
52 * It creates a fake tree from scratch
53 * @throws MsoCloudIdentityNotFound
56 public final void prepare () throws MsoCloudIdentityNotFound {
57 ClassLoader classLoader = CloudConfigTest.class.getClassLoader();
58 String config = classLoader.getResource("cloud_config.json").toString().substring(5);
60 cloudConfigFactory.initializeCloudConfig(config,1);
61 con = cloudConfigFactory.getCloudConfig();
65 * This method implements a test for the getCloudConfig method.
68 public final void testGetCloudConfig () {
73 * This method implements a test for the getCloudSites method.
76 public final void testGetCloudSites () {
77 Map<String,CloudSite> siteMap = con.getCloudSites();
78 assertNotNull(siteMap);
80 CloudSite site1 = siteMap.get("MT");
81 CloudSite site2 = siteMap.get("DAN");
82 CloudSite site3 = siteMap.get("MTINJVCC101");
83 CloudSite site4 = siteMap.get("MTSNJA4LCP1");
85 assertEquals (site1.getRegionId(), "regionOne");
86 assertEquals (site1.getIdentityServiceId(), "MT_KEYSTONE");
87 assertEquals (site2.getRegionId(), "RegionOne");
88 assertEquals (site2.getIdentityServiceId(), "DAN_KEYSTONE");
89 assertEquals (site3.getRegionId(), "regionTwo");
90 assertEquals (site3.getIdentityServiceId(), "MTINJVCC101_DCP");
91 assertEquals (site4.getRegionId(), "mtsnjlcp1");
92 assertEquals (site4.getIdentityServiceId(), "MTSNJA3DCP1");
97 * This method implements a test for the getIdentityServices method.
100 public final void testGetIdentityServices () {
101 Map<String,CloudIdentity> identityMap = con.getIdentityServices ();
102 assertNotNull(identityMap);
104 CloudIdentity identity1 = identityMap.get("MT_KEYSTONE");
105 CloudIdentity identity2 = identityMap.get("DAN_KEYSTONE");
106 CloudIdentity identity3 = identityMap.get("MTINJVCC101_DCP");
107 CloudIdentity identity4 = identityMap.get("MTSNJA3DCP1");
109 assertEquals("john", identity1.getMsoId());
110 assertEquals("changeme", identity1.getMsoPass());
111 assertEquals("admin", identity1.getAdminTenant());
112 assertEquals("_member_", identity1.getMemberRole());
113 assertEquals(false, identity1.hasTenantMetadata());
115 assertEquals("mockId", identity2.getMsoId());
116 assertEquals("stack123", identity2.getMsoPass());
117 assertEquals("service", identity2.getAdminTenant());
118 assertEquals("_member_", identity2.getMemberRole());
119 assertEquals(false, identity2.hasTenantMetadata());
121 assertEquals("mockIdToo", identity3.getMsoId());
122 assertEquals("AICG@mm@@2015", identity3.getMsoPass());
123 assertEquals("service", identity3.getAdminTenant());
124 assertEquals("admin", identity3.getMemberRole());
125 assertEquals(true, identity3.hasTenantMetadata());
127 assertEquals("mockIdToo", identity4.getMsoId());
128 assertEquals("2315QRS2015srq", identity4.getMsoPass());
129 assertEquals("service", identity4.getAdminTenant());
130 assertEquals("admin", identity4.getMemberRole());
131 assertEquals(true, identity4.hasTenantMetadata());
136 * This method implements a test for the getCloudSite method.
139 public final void testGetCloudSite () {
140 CloudSite site1 = con.getCloudSite("MT");
141 assertNotNull(site1);
142 assertEquals (site1.getRegionId(), "regionOne");
143 assertEquals (site1.getIdentityServiceId(), "MT_KEYSTONE");
147 * This method implements a test for the getIdentityService method.
150 public final void testGetIdentityService () {
151 CloudIdentity identity1 = con.getIdentityService("MT_KEYSTONE");
152 assertNotNull(identity1);
153 assertEquals (identity1.getMsoId(), "john");
154 assertEquals (identity1.getMsoPass(), "changeme");
155 assertEquals (identity1.getAdminTenant(), "admin");
156 assertEquals (identity1.getMemberRole(), "_member_");
157 assertEquals (identity1.hasTenantMetadata(), false);
159 CloudIdentity identity2 = con.getIdentityService("Test");
160 assertNull(identity2);
163 @Test (expected = MsoCloudIdentityNotFound.class)
164 public final void testLoadWithWrongFile () throws MsoCloudIdentityNotFound {
165 ClassLoader classLoader = CloudConfigTest.class.getClassLoader();
166 String config = classLoader.getResource("cloud_config_bad.json").toString().substring(5);
168 cloudConfigFactory.initializeCloudConfig(config,1);
172 public final void testReloadWithWrongFile () {
173 ClassLoader classLoader = CloudConfigTest.class.getClassLoader();
174 String config = classLoader.getResource("cloud_config_bad.json").toString().substring(5);
177 cloudConfigFactory.initializeCloudConfig(config,1);
178 Assert.fail("MsoCloudIdentityNotFound was expected");
179 } catch (MsoCloudIdentityNotFound e) {
182 Assert.assertTrue("Should be an empty CloudConfig", cloudConfigFactory.getCloudConfig().getCloudSites().isEmpty());
183 Assert.assertTrue("Should be an empty CloudConfig", cloudConfigFactory.getCloudConfig().getIdentityServices().isEmpty());
185 // Now reload the right config
186 config = classLoader.getResource("cloud_config.json").toString().substring(5);
187 cloudConfigFactory.changeMsoPropertiesFilePath(config);
188 cloudConfigFactory.reloadCloudConfig();
189 Assert.assertTrue("Flag valid Config should be true now that the cloud_config is correct", cloudConfigFactory.getCloudConfig().isValidCloudConfig());