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;
41 * This class implements test methods of the CloudConfig features.
45 public class CloudConfigTest {
47 private static CloudConfig con;
48 private static CloudConfigFactory cloudConfigFactory= new CloudConfigFactory();
50 public CloudConfigTest () {
55 * This method is called before any test occurs.
56 * It creates a fake tree from scratch
57 * @throws MsoCloudIdentityNotFound
60 public final void prepare () throws MsoCloudIdentityNotFound {
61 ClassLoader classLoader = CloudConfigTest.class.getClassLoader();
62 String config = classLoader.getResource("cloud_config.json").toString().substring(5);
64 cloudConfigFactory.initializeCloudConfig(config,1);
65 con = cloudConfigFactory.getCloudConfig();
69 * This method implements a test for the getCloudConfig method.
72 public final void testGetCloudConfig () {
77 * This method implements a test for the getCloudSites method.
80 public final void testGetCloudSites () {
81 Map<String,CloudSite> siteMap = con.getCloudSites();
82 assertNotNull(siteMap);
84 CloudSite site1 = siteMap.get("MT");
85 CloudSite site2 = siteMap.get("DAN");
86 CloudSite site3 = siteMap.get("MTINJVCC101");
87 CloudSite site4 = siteMap.get("MTSNJA4LCP1");
89 assertEquals (site1.getRegionId(), "regionOne");
90 assertEquals (site1.getIdentityServiceId(), "MT_KEYSTONE");
91 assertEquals (site2.getRegionId(), "RegionOne");
92 assertEquals (site2.getIdentityServiceId(), "DAN_KEYSTONE");
93 assertEquals (site3.getRegionId(), "regionTwo");
94 assertEquals (site3.getIdentityServiceId(), "MTINJVCC101_DCP");
95 assertEquals (site4.getRegionId(), "mtsnjlcp1");
96 assertEquals (site4.getIdentityServiceId(), "MTSNJA3DCP1");
101 * This method implements a test for the getIdentityServices method.
104 public final void testGetIdentityServices () {
105 Map<String,CloudIdentity> identityMap = con.getIdentityServices ();
106 assertNotNull(identityMap);
108 CloudIdentity identity1 = identityMap.get("MT_KEYSTONE");
109 CloudIdentity identity2 = identityMap.get("DAN_KEYSTONE");
110 CloudIdentity identity3 = identityMap.get("MTINJVCC101_DCP");
111 CloudIdentity identity4 = identityMap.get("MTSNJA3DCP1");
113 // assertEquals (identity1.getKeystoneUrl(), "http://localhost:5000/v2.0");
114 // assertEquals (identity1.getIdentityUrl(), "http://localhost:5000/v2.0");
115 assertEquals (identity1.getMsoId(), "john");
116 assertEquals (identity1.getMsoPass(), "changeme");
117 assertEquals (identity1.getAdminTenant(), "admin");
118 assertEquals (identity1.getMemberRole(), "_member_");
119 assertEquals (identity1.hasTenantMetadata(), false);
121 // assertEquals (identity2.getKeystoneUrl(), "http://localhost:5000/v2.0");
122 // assertEquals (identity2.getIdentityUrl(), "http://localhost:5000/v2.0");
123 assertEquals (identity2.getMsoId(), "mockId");
124 assertEquals (identity2.getMsoPass(), "stack123");
125 assertEquals (identity2.getAdminTenant(), "service");
126 assertEquals (identity2.getMemberRole(), "_member_");
127 assertEquals (identity2.hasTenantMetadata(), false);
129 // assertEquals (identity3.getKeystoneUrl(), "http://localhost:5000/v2.0");
130 // assertEquals (identity3.getIdentityUrl(), "http://localhost:5000/v2.0");
131 assertEquals (identity3.getMsoId(), "mockIdToo");
132 assertEquals (identity3.getMsoPass(), "AICG@mm@@2015");
133 assertEquals (identity3.getAdminTenant(), "service");
134 assertEquals (identity3.getMemberRole(), "admin");
135 assertEquals (identity3.hasTenantMetadata(), true);
137 // assertEquals (identity4.getKeystoneUrl(), "https://localhost:5000/v2.0");
138 // assertEquals (identity4.getIdentityUrl(), "https://localhost:5000/v2.0");
139 assertEquals (identity4.getMsoId(), "mockIdToo");
140 assertEquals (identity4.getMsoPass(), "2315QRS2015srq");
141 assertEquals (identity4.getAdminTenant(), "service");
142 assertEquals (identity4.getMemberRole(), "admin");
143 assertEquals (identity4.hasTenantMetadata(), true);
148 * This method implements a test for the getCloudSite method.
151 public final void testGetCloudSite () {
152 CloudSite site1 = con.getCloudSite("MT");
153 assertNotNull(site1);
154 assertEquals (site1.getRegionId(), "regionOne");
155 assertEquals (site1.getIdentityServiceId(), "MT_KEYSTONE");
159 * This method implements a test for the getIdentityService method.
162 public final void testGetIdentityService () {
163 CloudIdentity identity1 = con.getIdentityService("MT_KEYSTONE");
164 assertNotNull(identity1);
165 // assertEquals (identity1.getKeystoneUrl(), "http://localhost:5000/v2.0");
166 // assertEquals (identity1.getIdentityUrl(), "http://localhost:5000/v2.0");
167 assertEquals (identity1.getMsoId(), "john");
168 assertEquals (identity1.getMsoPass(), "changeme");
169 assertEquals (identity1.getAdminTenant(), "admin");
170 assertEquals (identity1.getMemberRole(), "_member_");
171 assertEquals (identity1.hasTenantMetadata(), false);
173 CloudIdentity identity2 = con.getIdentityService("Test");
174 assertNull(identity2);
177 @Test (expected = MsoCloudIdentityNotFound.class)
178 public final void testLoadWithWrongFile () throws MsoCloudIdentityNotFound {
179 ClassLoader classLoader = CloudConfigTest.class.getClassLoader();
180 String config = classLoader.getResource("cloud_config_bad.json").toString().substring(5);
182 cloudConfigFactory.initializeCloudConfig(config,1);
186 public final void testReloadWithWrongFile () {
187 ClassLoader classLoader = CloudConfigTest.class.getClassLoader();
188 String config = classLoader.getResource("cloud_config_bad.json").toString().substring(5);
191 cloudConfigFactory.initializeCloudConfig(config,1);
192 Assert.fail("MsoCloudIdentityNotFound was expected");
193 } catch (MsoCloudIdentityNotFound e) {
196 Assert.assertTrue("Should be an empty CloudConfig", cloudConfigFactory.getCloudConfig().getCloudSites().isEmpty());
197 Assert.assertTrue("Should be an empty CloudConfig", cloudConfigFactory.getCloudConfig().getIdentityServices().isEmpty());
199 // Now reload the right config
200 config = classLoader.getResource("cloud_config.json").toString().substring(5);
201 cloudConfigFactory.changeMsoPropertiesFilePath(config);
202 cloudConfigFactory.reloadCloudConfig();
203 Assert.assertTrue("Flag valid Config should be true now that the cloud_config is correct", cloudConfigFactory.getCloudConfig().isValidCloudConfig());