aboutsummaryrefslogtreecommitdiffstats
path: root/adapters/mso-adapter-utils
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/mso-adapter-utils')
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfig.java6
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigFactory.java60
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudConfigFactoryTest.java164
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudConfigTest.java292
-rw-r--r--adapters/mso-adapter-utils/src/test/resources/cloud_config.json11
-rw-r--r--adapters/mso-adapter-utils/src/test/resources/cloud_default_config.json13
6 files changed, 361 insertions, 185 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfig.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfig.java
index 5d16a95e5f..275241f768 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfig.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfig.java
@@ -22,10 +22,10 @@ package org.openecomp.mso.cloud;
import java.io.FileReader;
import java.io.IOException;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
-
import java.util.Optional;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.DeserializationConfig;
@@ -78,8 +78,8 @@ public class CloudConfig {
/**
* Get a map of all cloud sites that have been loaded.
*/
- public synchronized Map<String, CloudSite> getCloudSites() {
- return cloudSites;
+ public Map<String, CloudSite> getCloudSites() {
+ return Collections.unmodifiableMap(cloudSites);
}
/**
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigFactory.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigFactory.java
index 445c135dab..144506c3bd 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigFactory.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigFactory.java
@@ -20,12 +20,10 @@
package org.openecomp.mso.cloud;
-
import java.io.IOException;
import java.io.Serializable;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantReadWriteLock;
-
import javax.ejb.ConcurrencyManagement;
import javax.ejb.ConcurrencyManagementType;
import javax.ejb.LocalBean;
@@ -36,22 +34,17 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
-
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
-
+import org.openecomp.mso.logger.MessageEnum;
import org.openecomp.mso.logger.MsoLogger;
import org.openecomp.mso.openstack.exceptions.MsoCloudIdentityNotFound;
import org.openecomp.mso.openstack.utils.MsoHeatUtils;
import org.openecomp.mso.openstack.utils.MsoKeystoneUtils;
import org.openecomp.mso.openstack.utils.MsoNeutronUtils;
-import org.openecomp.mso.properties.MsoPropertiesException;
-import org.openecomp.mso.logger.MessageEnum;
/**
* This class returns a cloud Config instances
- *
- *
*/
@Singleton(name = "CloudConfigFactory")
@@ -62,13 +55,13 @@ public class CloudConfigFactory implements Serializable {
private static final long serialVersionUID = 2956662716453261085L;
- private static CloudConfig cloudConfigCache = new CloudConfig ();
+ private CloudConfig cloudConfigCache = new CloudConfig();
protected static String prefixMsoPropertiesPath = System.getProperty ("mso.config.path");
private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
- private static int refreshTimer;
+ private int refreshTimer;
private static final ReentrantReadWriteLock rwl = new ReentrantReadWriteLock ();
@@ -79,7 +72,6 @@ public class CloudConfigFactory implements Serializable {
}
public void initializeCloudConfig (String filePath, int refreshTimer) throws MsoCloudIdentityNotFound {
-
rwl.writeLock ().lock ();
try {
cloudConfigCache.loadCloudConfig (prefixMsoPropertiesPath + filePath, refreshTimer);
@@ -95,18 +87,6 @@ public class CloudConfigFactory implements Serializable {
}
}
- public void changeMsoPropertiesFilePath (String newMsoPropPath) {
- rwl.writeLock ().lock ();
- try {
- CloudConfigFactory.cloudConfigCache.configFilePath = prefixMsoPropertiesPath + newMsoPropPath;
- } finally {
- rwl.writeLock ().unlock ();
- }
- }
-
- public CloudConfigFactory () {
- }
-
public CloudConfig getCloudConfig () {
rwl.readLock ().lock ();
try {
@@ -127,7 +107,7 @@ public class CloudConfigFactory implements Serializable {
* @return true if Properties have been reloaded, false otherwise
*/
@Schedule(minute = "*/1", hour = "*", persistent = false)
- public static void reloadCloudConfig () {
+ public void reloadCloudConfig () {
try {
if (!rwl.writeLock ().tryLock () && !rwl.writeLock ().tryLock (30L, TimeUnit.SECONDS)) {
@@ -180,23 +160,17 @@ public class CloudConfigFactory implements Serializable {
@Path("/showConfig")
@Produces("text/plain")
public Response showCloudConfig () {
- CloudConfig cloudConfig = this.getCloudConfig ();
- if (cloudConfig != null) {
- StringBuffer response = new StringBuffer ();
- response.append ("Cloud Sites:\n");
- for (CloudSite site : cloudConfig.getCloudSites ().values ()) {
- response.append(site.toString()).append("\n");
- }
-
- response.append ("\n\nCloud Identity Services:\n");
- for (CloudIdentity identity : cloudConfig.getIdentityServices ().values ()) {
- response.append(identity.toString()).append("\n");
- }
-
- return Response.status (200).entity (response).build ();
- } else {
- return Response.status (500).entity ("Cloud Config has not been loaded properly, this could be due to a bad JSON structure (Check the logs for additional details)").build ();
+ CloudConfig cloudConfig = this.getCloudConfig();
+ StringBuffer response = new StringBuffer();
+ response.append("Cloud Sites:\n");
+ for (CloudSite site : cloudConfig.getCloudSites().values()) {
+ response.append(site.toString()).append("\n");
+ }
+ response.append("\n\nCloud Identity Services:\n");
+ for (CloudIdentity identity : cloudConfig.getIdentityServices().values()) {
+ response.append(identity.toString()).append("\n");
}
+ return Response.status(200).entity(response).build();
}
@GET
@@ -207,8 +181,7 @@ public class CloudConfigFactory implements Serializable {
MsoKeystoneUtils.adminCacheReset ();
MsoHeatUtils.heatCacheReset ();
MsoNeutronUtils.neutronCacheReset ();
-
- String response = "Client caches reset. All entries removed.";
+ String response = "Client caches reset. All entries removed.";
return Response.status (200).entity (response).build ();
}
@@ -220,8 +193,7 @@ public class CloudConfigFactory implements Serializable {
MsoKeystoneUtils.adminCacheCleanup ();
MsoHeatUtils.heatCacheCleanup ();
MsoNeutronUtils.neutronCacheCleanup ();
-
- String response = "Client caches cleaned up. All expired entries removed";
+ String response = "Client caches cleaned up. All expired entries removed.";
return Response.status (200).entity (response).build ();
}
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudConfigFactoryTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudConfigFactoryTest.java
new file mode 100644
index 0000000000..fe768b5774
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudConfigFactoryTest.java
@@ -0,0 +1,164 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.cloud;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Map;
+import javax.ws.rs.core.Response;
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.mso.openstack.exceptions.MsoCloudIdentityNotFound;
+
+public class CloudConfigFactoryTest {
+
+ private static final String CLOUD_CONFIG_FIELD_NAME = "cloudConfigCache";
+ private static final int REFRESH_TIMER_VALUE = 1;
+
+ private CloudConfigFactory testedObject;
+ private CloudConfig cloudConfigMock;
+
+ @Before
+ public void init() throws NoSuchFieldException, IllegalAccessException {
+ cloudConfigMock = mock(CloudConfig.class);
+ testedObject = new CloudConfigFactory();
+ setCloudConfig();
+ }
+
+ @Test
+ public void initializeCloudConfigSuccessful() throws MsoCloudIdentityNotFound, IOException {
+ ClassLoader classLoader = CloudConfigFactoryTest.class.getClassLoader();
+ String cloudConfigJsonFilePath = classLoader.getResource("cloud_config.json").getPath();
+ testedObject.initializeCloudConfig(cloudConfigJsonFilePath, REFRESH_TIMER_VALUE);
+ verify(cloudConfigMock).loadCloudConfig(cloudConfigJsonFilePath, REFRESH_TIMER_VALUE);
+ }
+
+ @Test
+ public void getValidCloudConfig() {
+ when(cloudConfigMock.isValidCloudConfig()).thenReturn(true);
+
+ testedObject.getCloudConfig();
+
+ verify(cloudConfigMock).clone();
+ }
+
+ @Test
+ public void getNotValidCloudConfig() {
+ when(cloudConfigMock.isValidCloudConfig()).thenReturn(false);
+
+ CloudConfig result = testedObject.getCloudConfig();
+
+ assertThat(result).isNotNull();
+ assertThat(result.getCloudSites()).isEmpty();
+ assertThat(result.getIdentityServices()).isEmpty();
+ }
+
+ @Test
+ public void reload_CloudConfigValid() throws IOException, MsoCloudIdentityNotFound {
+ when(cloudConfigMock.isValidCloudConfig()).thenReturn(true);
+
+ testedObject.reloadCloudConfig();
+
+ verify(cloudConfigMock).clone();
+ verify(cloudConfigMock).reloadPropertiesFile();
+ }
+
+ @Test
+ public void reload_CloudConfigNotValid()
+ throws IOException, MsoCloudIdentityNotFound {
+ when(cloudConfigMock.isValidCloudConfig()).thenReturn(false);
+
+ testedObject.reloadCloudConfig();
+
+ verify(cloudConfigMock).reloadPropertiesFile();
+ }
+
+ @Test
+ public void showCloudConfig() throws NoSuchFieldException, IllegalAccessException {
+ when(cloudConfigMock.isValidCloudConfig()).thenReturn(true);
+ when(cloudConfigMock.clone()).thenReturn(createCloudConfig("IdTest576", "identityTest456"));
+ Response response = testedObject.showCloudConfig();
+
+ assertThat(response.getStatus()).isEqualTo(200);
+ assertThat(response.getEntity().toString()).containsPattern("CloudSite:.*IdTest576")
+ .containsPattern("Cloud Identity Service:.*identityTest456");
+
+ }
+
+ @Test
+ public void resetClientCaches_Successful() {
+ Response response = testedObject.resetClientCaches();
+ assertThat(response.getStatus()).isEqualTo(200);
+ assertThat(response.getEntity().toString()).isEqualTo("Client caches reset. All entries removed.");
+ }
+
+ @Test
+ public void cleanUpClientCache_Successful() {
+ Response response = testedObject.cleanupClientCaches();
+ assertThat(response.getStatus()).isEqualTo(200);
+ assertThat(response.getEntity().toString()).isEqualTo("Client caches cleaned up. All expired entries removed.");
+ }
+
+ @Test
+ public void encryptPassword_Successful() {
+ Response response = testedObject.encryptPassword("passTest123");
+ String expectedEncryptedPassword = CloudIdentity.encryptPassword("passTest123");
+ assertThat(response.getStatus()).isEqualTo(200);
+ assertThat(response.getEntity().toString()).isEqualTo("Encrypted Password = "+expectedEncryptedPassword);
+ }
+
+ private CloudConfig createCloudConfig(String cloudSiteId, String identityServiceId)
+ throws NoSuchFieldException, IllegalAccessException {
+ CloudConfig cloudConfig = new CloudConfig();
+ Map<String, CloudSite> cloudSiteMap = new HashMap<>();
+ CloudSite cs = new CloudSite();
+ cs.setId(cloudSiteId);
+ cloudSiteMap.put("keyTest", cs);
+ Field cloudSitesField = cloudConfig.getClass().getDeclaredField("cloudSites");
+ cloudSitesField.setAccessible(true);
+ cloudSitesField.set(cloudConfig, cloudSiteMap);
+
+ Map<String, CloudIdentity> identityServicesMap = new HashMap<>();
+ CloudIdentity cloudIdentity = new CloudIdentity();
+ cloudIdentity.setId(identityServiceId);
+ identityServicesMap.put("identityKey", cloudIdentity);
+
+ Field identityServicesField = cloudConfig.getClass().getDeclaredField("identityServices");
+ identityServicesField.setAccessible(true);
+ identityServicesField.set(cloudConfig, identityServicesMap);
+
+ return cloudConfig;
+ }
+
+ private void setCloudConfig()
+ throws NoSuchFieldException, IllegalAccessException {
+ Field field = testedObject.getClass().getDeclaredField(CLOUD_CONFIG_FIELD_NAME);
+ field.setAccessible(true);
+ field.set(testedObject, cloudConfigMock);
+ }
+
+}
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudConfigTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudConfigTest.java
index 1c2501e8e4..5b6be03a22 100644
--- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudConfigTest.java
+++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudConfigTest.java
@@ -20,161 +20,221 @@
package org.openecomp.mso.cloud;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertTrue;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Optional;
-import org.junit.Assert;
-import org.junit.BeforeClass;
+import org.junit.Before;
import org.junit.Test;
-import java.util.Map;
import org.openecomp.mso.openstack.exceptions.MsoCloudIdentityNotFound;
public class CloudConfigTest {
- private static String cloudConfigJsonFilePath;
- private static String cloudDefaultConfigJsonFilePath;
- private static String cloudConfigInvalidJsonFilePath;
+ private static final int NUMBER_OF_CLOUD_SITES_IN_JSON_FILE = 4;
+ private static final int NUMBER_OF_IDENTITY_SERVICES_IN_JSON_FILE = 4;
+ private static final String CLOUD_SITES_FIELD_NAME = "cloudSites";
+ private static final String IDENTITY_SERVICE_FIELD_NAME = "identityServices";
+ private static final String CLOUD_SITE_DEFAULT = "default";
+ private static final String CLOUD_CONFIG_JSON_FILE_NAME = "cloud_config.json";
+ private static final String CLOUD_CONFIG_INVALID_JSON_FILE_NAME = "cloud_config_bad.json";
+
+ private CloudConfig testedObject;
+ private CloudSite cloudSite;
+ private CloudSite cloudSiteDefault;
+
+ @Before
+ public void init() {
+ testedObject = new CloudConfig();
+ }
- @BeforeClass
- public static void preparePaths() {
- ClassLoader classLoader = CloudConfigTest.class.getClassLoader();
- cloudConfigJsonFilePath = classLoader.getResource("cloud_config.json").getPath();
- cloudDefaultConfigJsonFilePath = classLoader.getResource("cloud_default_config.json").getPath();
- cloudConfigInvalidJsonFilePath = classLoader.getResource("cloud_config_bad.json").getPath();
+ @Test
+ public void cloudSite_returnEmptyOptionalIfIdIsNull() {
+ Optional<CloudSite> cloudConfigOpt = new CloudConfig().getCloudSite(null);
+ assertThat(cloudConfigOpt).isEmpty();
+ }
+
+ @Test
+ public void cloudSiteIsGotById_when_IdFound() throws NoSuchFieldException, IllegalAccessException {
+ setCloudSitesMap();
+ Optional<CloudSite> cloudSiteOpt = testedObject.getCloudSite(cloudSite.getId());
+ assertThat(cloudSiteOpt).isPresent();
+ assertThat(cloudSiteOpt.get().getId()).isEqualTo(cloudSite.getId());
+ assertThat(cloudSiteOpt.get().getClli()).isEqualTo(cloudSite.getClli());
+ }
+
+ @Test
+ public void cloudSiteIsGotByClli_when_IdNotFound() throws NoSuchFieldException, IllegalAccessException {
+ setCloudSitesMap();
+ Optional<CloudSite> cloudSiteOpt = testedObject.getCloudSite(cloudSite.getClli());
+ assertTrue(cloudSiteOpt.isPresent());
+ assertThat(cloudSiteOpt.get().getId()).isEqualTo(cloudSite.getId());
+ assertThat(cloudSiteOpt.get().getClli()).isEqualTo(cloudSite.getClli());
+ }
+
+ @Test
+ public void cloudSiteIsGotByDefault_when_IdAndClliNotFound() throws NoSuchFieldException, IllegalAccessException {
+ setCloudSitesMap();
+ Optional<CloudSite> cloudSiteOpt = testedObject.getCloudSite("not_existing_id");
+ assertTrue(cloudSiteOpt.isPresent());
+ assertThat(cloudSiteOpt.get().getId()).isEqualTo("not_existing_id");
+ assertThat(cloudSiteOpt.get().getClli()).isEqualTo(cloudSiteDefault.getClli());
+ }
+
+ @Test
+ public void cloudSiteNotFound_returnNull() {
+ assertThat(testedObject.getCloudSite("not_existing_id")).isEmpty();
+ }
+
+ @Test
+ public void identityServiceFoundById() throws NoSuchFieldException, IllegalAccessException {
+ CloudIdentity cloudIdentity = createCloudIdentity();
+ setIdentityServiceMap();
+ CloudIdentity cloudIdentityResult = testedObject.getIdentityService(cloudIdentity.getId());
+
+ assertThat(cloudIdentityResult).isNotNull();
+ assertThat(cloudIdentityResult.getId()).isEqualTo(cloudIdentity.getId());
+ assertThat(cloudIdentityResult.getMsoId()).isEqualTo(cloudIdentity.getMsoId());
}
- private CloudConfig createTestObject(String jsonFilePath) throws MsoCloudIdentityNotFound {
- CloudConfigFactory cloudConfigFactory = new CloudConfigFactory();
- cloudConfigFactory.initializeCloudConfig(jsonFilePath, 1);
- return cloudConfigFactory.getCloudConfig();
+ @Test
+ public void defaultClodeSiteNotFound_returnNull() {
+ assertThat(testedObject.getIdentityService("not_existing_id")).isNull();
+ }
+
+ @Test
+ public void loadCloudConfigSuccessful() throws IOException, MsoCloudIdentityNotFound {
+ ClassLoader classLoader = CloudConfigTest.class.getClassLoader();
+ String cloudConfigJsonFilePath = classLoader.getResource(CLOUD_CONFIG_JSON_FILE_NAME).getPath();
+ testedObject.loadCloudConfig(cloudConfigJsonFilePath, 1);
+ assertThat(testedObject.isValidCloudConfig()).isTrue();
+ checkCloudSites();
+ checkIdentityServices();
}
@Test
- public void testGetCloudSites() throws MsoCloudIdentityNotFound {
- CloudConfig con = createTestObject(cloudConfigJsonFilePath);
- Map<String, CloudSite> siteMap = con.getCloudSites();
- assertNotNull(siteMap);
+ public void loadCloudConfig_cloudIdentityNotFound() {
+ ClassLoader classLoader = CloudConfigTest.class.getClassLoader();
+ String cloudConfigInvalidJsonFilePath = classLoader.getResource(CLOUD_CONFIG_INVALID_JSON_FILE_NAME).getPath();
+ assertThatThrownBy(() -> testedObject.loadCloudConfig(cloudConfigInvalidJsonFilePath, 1))
+ .isInstanceOf(MsoCloudIdentityNotFound.class)
+ .hasMessage("Cloud Identity [MT Cloud site refers to a non-existing identity service: "
+ + "MT_KEYSTONE_NOT_EXISTING] not found");
+ assertThat(testedObject.isValidCloudConfig()).isFalse();
+ }
+ private void checkCloudSites() {
+ Map<String, CloudSite> siteMap = testedObject.getCloudSites();
+ assertThat(siteMap).isNotEmpty().hasSize(NUMBER_OF_CLOUD_SITES_IN_JSON_FILE);
CloudSite site1 = siteMap.get("MT");
CloudSite site2 = siteMap.get("DAN");
CloudSite site3 = siteMap.get("MTINJVCC101");
CloudSite site4 = siteMap.get("MTSNJA4LCP1");
- assertEquals("regionOne", site1.getRegionId());
- assertEquals("MT_KEYSTONE", site1.getIdentityServiceId());
- assertEquals("RegionOne", site2.getRegionId());
- assertEquals("DAN_KEYSTONE", site2.getIdentityServiceId());
- assertEquals("regionTwo", site3.getRegionId());
- assertEquals("MTINJVCC101_DCP", site3.getIdentityServiceId());
- assertEquals("mtsnjlcp1", site4.getRegionId());
- assertEquals("MTSNJA3DCP1", site4.getIdentityServiceId());
+ assertThat(site1.getId()).isEqualTo("MT");
+ assertThat(site1.getRegionId()).isEqualTo("regionOne");
+ assertThat(site1.getIdentityServiceId()).isEqualTo("MT_KEYSTONE");
+ assertThat(site1.getIdentityService()).isNotNull();
+ assertThat(site1.getIdentityService().getId()).isEqualTo(site1.getIdentityServiceId());
+
+ assertThat(site2.getId()).isEqualTo("DAN");
+ assertThat(site2.getRegionId()).isEqualTo("RegionOne");
+ assertThat(site2.getIdentityServiceId()).isEqualTo("DAN_KEYSTONE");
+ assertThat(site2.getIdentityService()).isNotNull();
+ assertThat(site2.getIdentityService().getId()).isEqualTo(site2.getIdentityServiceId());
+
+ assertThat(site3.getId()).isEqualTo("MTINJVCC101");
+ assertThat(site3.getRegionId()).isEqualTo("regionTwo");
+ assertThat(site3.getIdentityServiceId()).isEqualTo("MTINJVCC101_DCP");
+ assertThat(site3.getIdentityService()).isNotNull();
+ assertThat(site3.getIdentityService().getId()).isEqualTo(site3.getIdentityServiceId());
+
+ assertThat(site4.getId()).isEqualTo("MTSNJA4LCP1");
+ assertThat(site4.getRegionId()).isEqualTo("mtsnjlcp1");
+ assertThat(site4.getIdentityServiceId()).isEqualTo("MTSNJA3DCP1");
+ assertThat(site4.getIdentityService()).isNotNull();
+ assertThat(site4.getIdentityService().getId()).isEqualTo(site4.getIdentityServiceId());
}
- @Test
- public void testGetIdentityServices() throws MsoCloudIdentityNotFound {
- CloudConfig con = createTestObject(cloudConfigJsonFilePath);
- Map<String, CloudIdentity> identityMap = con.getIdentityServices();
- assertNotNull(identityMap);
+ private void checkIdentityServices() {
+ Map<String, CloudIdentity> identityMap = testedObject.getIdentityServices();
+ assertThat(identityMap).isNotEmpty().hasSize(NUMBER_OF_IDENTITY_SERVICES_IN_JSON_FILE);
CloudIdentity identity1 = identityMap.get("MT_KEYSTONE");
CloudIdentity identity2 = identityMap.get("DAN_KEYSTONE");
CloudIdentity identity3 = identityMap.get("MTINJVCC101_DCP");
CloudIdentity identity4 = identityMap.get("MTSNJA3DCP1");
- assertEquals("john", identity1.getMsoId());
- assertEquals("changeme", identity1.getMsoPass());
- assertEquals("admin", identity1.getAdminTenant());
- assertEquals("_member_", identity1.getMemberRole());
- assertFalse(identity1.hasTenantMetadata());
-
- assertEquals("mockId", identity2.getMsoId());
- assertEquals("stack123", identity2.getMsoPass());
- assertEquals("service", identity2.getAdminTenant());
- assertEquals("_member_", identity2.getMemberRole());
- assertFalse(identity2.hasTenantMetadata());
-
- assertEquals("mockIdToo", identity3.getMsoId());
- assertEquals("AICG@mm@@2015", identity3.getMsoPass());
- assertEquals("service", identity3.getAdminTenant());
- assertEquals("admin", identity3.getMemberRole());
- assertTrue(identity3.hasTenantMetadata());
-
- assertEquals("mockIdToo", identity4.getMsoId());
- assertEquals("2315QRS2015srq", identity4.getMsoPass());
- assertEquals("service", identity4.getAdminTenant());
- assertEquals("admin", identity4.getMemberRole());
- assertTrue(identity4.hasTenantMetadata());
+ assertThat(identity1.getMsoId()).isEqualTo("john");
+ assertThat(identity1.getMsoPass()).isEqualTo("changeme");
+ assertThat(identity1.getAdminTenant()).isEqualTo("admin");
+ assertThat(identity1.getMemberRole()).isEqualTo("_member_");
+ assertThat(identity1.hasTenantMetadata()).isFalse();
+
+ assertThat(identity2.getMsoId()).isEqualTo("mockId");
+ assertThat(identity2.getMsoPass()).isEqualTo("stack123");
+ assertThat(identity2.getAdminTenant()).isEqualTo("service");
+ assertThat(identity2.getMemberRole()).isEqualTo("_member_");
+ assertThat(identity2.hasTenantMetadata()).isFalse();
+
+ assertThat(identity3.getMsoId()).isEqualTo("mockIdToo");
+ assertThat(identity3.getMsoPass()).isEqualTo("AICG@mm@@2015");
+ assertThat(identity3.getAdminTenant()).isEqualTo("service");
+ assertThat(identity3.getMemberRole()).isEqualTo("admin");
+ assertThat(identity3.hasTenantMetadata()).isTrue();
+
+ assertThat(identity4.getMsoId()).isEqualTo("mockIdToo");
+ assertThat(identity4.getMsoPass()).isEqualTo("2315QRS2015srq");
+ assertThat(identity4.getAdminTenant()).isEqualTo("service");
+ assertThat(identity4.getMemberRole()).isEqualTo("admin");
+ assertThat(identity4.hasTenantMetadata()).isTrue();
}
@Test
- public void cloudSiteIsGotById_when_IdFound() throws MsoCloudIdentityNotFound {
- CloudConfig con = createTestObject(cloudConfigJsonFilePath);
- Optional<CloudSite> cloudSite = con.getCloudSite("MT");
- assertTrue(cloudSite.isPresent());
- assertEquals("regionOne", cloudSite.get().getRegionId());
- assertEquals("MT_KEYSTONE", cloudSite.get().getIdentityServiceId());
+ public void cloneSuccessful() throws NoSuchFieldException, IllegalAccessException {
+ setCloudSitesMap();
+ setIdentityServiceMap();
+ assertThat(testedObject.clone()).isEqualTo(testedObject);
}
- @Test
- public void cloudSiteIsGotByClli_when_IdNotFound() throws MsoCloudIdentityNotFound {
- CloudConfig con = createTestObject(cloudConfigJsonFilePath);
- Optional<CloudSite> cloudSite = con.getCloudSite("CS_clli");
- assertTrue(cloudSite.isPresent());
- assertEquals("clliRegion", cloudSite.get().getRegionId());
- assertEquals("CS_clli", cloudSite.get().getClli());
- assertEquals("CS_service", cloudSite.get().getIdentityServiceId());
+ private void setCloudSitesMap() throws NoSuchFieldException, IllegalAccessException {
+ Field field = testedObject.getClass().getDeclaredField(CLOUD_SITES_FIELD_NAME);
+ field.setAccessible(true);
+ Map<String, CloudSite> cloudSites = new HashMap<>();
+ cloudSite = createCloudSite("idTest1", "clliTest1");
+ cloudSiteDefault = createCloudSite(CLOUD_SITE_DEFAULT, "clliTest2");
+ cloudSites.put(cloudSite.getId(), cloudSite);
+ cloudSites.put(cloudSiteDefault.getId(), cloudSiteDefault);
+ field.set(testedObject, cloudSites);
}
- @Test
- public void cloudSiteIsGotByDefault_when_IdAndClliNotFound() throws MsoCloudIdentityNotFound {
- CloudConfig con = createTestObject(cloudDefaultConfigJsonFilePath);
- Optional<CloudSite> cloudSite = con.getCloudSite("not_existing_id");
- assertTrue(cloudSite.isPresent());
- assertEquals("not_existing_id", cloudSite.get().getId());
- assertEquals("not_existing_id", cloudSite.get().getRegionId());
- }
+ private void setIdentityServiceMap() throws NoSuchFieldException, IllegalAccessException {
+ Field field = testedObject.getClass().getDeclaredField(IDENTITY_SERVICE_FIELD_NAME);
+ field.setAccessible(true);
- @Test
- public void testGetIdentityService() throws MsoCloudIdentityNotFound {
- CloudConfig con = createTestObject(cloudConfigJsonFilePath);
- CloudIdentity identity1 = con.getIdentityService("MT_KEYSTONE");
- assertNotNull(identity1);
- assertEquals("john", identity1.getMsoId());
- assertEquals("changeme", identity1.getMsoPass());
- assertEquals("admin", identity1.getAdminTenant());
- assertEquals("_member_", identity1.getMemberRole());
- assertFalse(identity1.hasTenantMetadata());
-
- CloudIdentity identity2 = con.getIdentityService("Test");
- assertNull(identity2);
+ Map<String, CloudIdentity> cloudIdentityMap = new HashMap<>();
+ CloudIdentity cloudIdentity = createCloudIdentity();
+ cloudIdentityMap.put(cloudIdentity.getId(), cloudIdentity);
+ field.set(testedObject, cloudIdentityMap);
}
- @Test(expected = MsoCloudIdentityNotFound.class)
- public void testLoadWithWrongFile() throws MsoCloudIdentityNotFound {
- createTestObject(cloudConfigInvalidJsonFilePath);
+ private CloudIdentity createCloudIdentity() {
+ CloudIdentity cloudIdentity = new CloudIdentity();
+ cloudIdentity.setId("identityTestId");
+ cloudIdentity.setMsoId("msoTestId");
+ return cloudIdentity;
}
- @Test
- public void testReloadWithWrongFile() {
- CloudConfigFactory cloudConfigFactory = new CloudConfigFactory();
- try {
- cloudConfigFactory.initializeCloudConfig(cloudConfigInvalidJsonFilePath, 1);
- Assert.fail("MsoCloudIdentityNotFound was expected");
- } catch (MsoCloudIdentityNotFound e) {
-
- }
- assertTrue("Should be an empty CloudConfig", cloudConfigFactory.getCloudConfig().getCloudSites().isEmpty());
- assertTrue("Should be an empty CloudConfig",
- cloudConfigFactory.getCloudConfig().getIdentityServices().isEmpty());
- // Now reload the right config
- cloudConfigFactory.changeMsoPropertiesFilePath(cloudConfigJsonFilePath);
- cloudConfigFactory.reloadCloudConfig();
- assertTrue("Flag valid Config should be true now that the cloud_config is correct",
- cloudConfigFactory.getCloudConfig().isValidCloudConfig());
+ private CloudSite createCloudSite(String id, String clli) {
+ CloudSite cloudSite = new CloudSite();
+ cloudSite.setId(id);
+ cloudSite.setClli(clli);
+ cloudSite.setAic_version("2.5");
+ cloudSite.setIdentityService(createCloudIdentity());
+ return cloudSite;
}
-
}
diff --git a/adapters/mso-adapter-utils/src/test/resources/cloud_config.json b/adapters/mso-adapter-utils/src/test/resources/cloud_config.json
index ff24633f32..ee3532fe15 100644
--- a/adapters/mso-adapter-utils/src/test/resources/cloud_config.json
+++ b/adapters/mso-adapter-utils/src/test/resources/cloud_config.json
@@ -44,8 +44,7 @@
"tenant_metadata": true,
"identity_server_type": "KEYSTONE",
"identity_authentication_type": "USERNAME_PASSWORD"
- },
- "CS_service": {}
+ }
},
"cloud_sites":
@@ -77,14 +76,8 @@
"clli": "MTSNJA4LCP1",
"aic_version": "2.5",
"identity_service_id": "MTSNJA3DCP1"
- },
- "CS":
- {
- "region_id": "clliRegion",
- "clli": "CS_clli",
- "aic_version": "2.5",
- "identity_service_id": "CS_service"
}
+
}
}
}
diff --git a/adapters/mso-adapter-utils/src/test/resources/cloud_default_config.json b/adapters/mso-adapter-utils/src/test/resources/cloud_default_config.json
deleted file mode 100644
index 35d18e9789..0000000000
--- a/adapters/mso-adapter-utils/src/test/resources/cloud_default_config.json
+++ /dev/null
@@ -1,13 +0,0 @@
-{
- "cloud_config": {
- "identity_services": {
- "default_service": {}
- },
- "cloud_sites": {
- "default": {
- "region_id": "defaultRegion",
- "identity_service_id": "default_service"
- }
- }
- }
-} \ No newline at end of file