aboutsummaryrefslogtreecommitdiffstats
path: root/adapters
diff options
context:
space:
mode:
Diffstat (limited to 'adapters')
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfig.java102
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigIdentityMapper.java30
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java2
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/CloudConfigTest.java193
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoHeatUtilsTest.java1
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudConfigTest.java179
-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
-rw-r--r--adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/json/MapDeserializer.java1
-rw-r--r--adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/json/MapSerializer.java7
-rw-r--r--adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/AdapterRestInterfaceTest.java48
-rw-r--r--adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/BeanTest.java6
-rw-r--r--adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/json/MapSerializerTest.java56
13 files changed, 298 insertions, 351 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 0af0e9422b..ef37f9f719 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
@@ -7,9 +7,9 @@
* 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.
@@ -26,6 +26,7 @@ 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;
import org.codehaus.jackson.map.ObjectMapper;
@@ -36,8 +37,8 @@ import org.openecomp.mso.openstack.exceptions.MsoCloudIdentityNotFound;
/**
* JavaBean JSON class for a CloudConfig. This bean maps a JSON-format cloud
* configuration file to Java. The CloudConfig contains information about
- * Openstack cloud configurations. It includes:
- * - CloudIdentity objects,representing DCP nodes (Openstack Identity Service)
+ * Openstack cloud configurations. It includes:
+ * - CloudIdentity objects,representing DCP nodes (Openstack Identity Service)
* - CloudSite objects, representing LCP nodes (Openstack Compute & other services)
*
* Note that this is only used to access Cloud Configurations loaded from a JSON
@@ -51,19 +52,17 @@ import org.openecomp.mso.openstack.exceptions.MsoCloudIdentityNotFound;
@JsonRootName("cloud_config")
public class CloudConfig {
- private boolean validCloudConfig = false;
+ private static final String CLOUD_SITE_VERSION = "2.5";
+ private static final String DEFAULT_CLOUD_SITE_ID = "default";
+ private boolean validCloudConfig = false;
+ private static ObjectMapper mapper = new ObjectMapper();
+ private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA);
+ protected String configFilePath;
+ protected int refreshTimerInMinutes;
@JsonProperty("identity_services")
private Map<String, CloudIdentity> identityServices = new HashMap<>();
@JsonProperty("cloud_sites")
- private Map<String, CloudSite> cloudSites = new HashMap<>();
-
- private static ObjectMapper mapper = new ObjectMapper();
-
- private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA);
-
- protected String configFilePath;
-
- protected int refreshTimerInMinutes;
+ private Map<String, CloudSite> cloudSites = new HashMap<>();
public CloudConfig() {
mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
@@ -71,18 +70,14 @@ public class CloudConfig {
}
/**
- * Get a Map of all IdentityServices that have been loaded.
- *
- * @return the Map
+ * Get a map of all identity services that have been loaded.
*/
public synchronized Map<String, CloudIdentity> getIdentityServices() {
return identityServices;
}
/**
- * Get a Map of all CloudSites that have been loaded.
- *
- * @return the Map
+ * Get a map of all cloud sites that have been loaded.
*/
public synchronized Map<String, CloudSite> getCloudSites() {
return cloudSites;
@@ -93,7 +88,7 @@ public class CloudConfig {
* against the regions, and if no match is found there, then against
* individual entries to try and find one with a CLLI that matches the ID
* and an AIC version of 2.5.
- *
+ *
* @param id
* the ID to match
* @return a CloudSite, or null of no match found
@@ -104,53 +99,35 @@ public class CloudConfig {
return cloudSites.get(id);
}
// check for id == CLLI now as well
- return getCloudSiteWithClli(id, "2.5");
+ return getCloudSiteWithClli(id);
}
return null;
}
- /**
- * Get a specific CloudSites, based on a CLLI and (optional) version, which
- * will be matched against the aic_version field of the CloudSite.
- *
- * @param clli
- * the CLLI to match
- * @param version
- * the version to match; may be null in which case any version
- * matches
- * @return a CloudSite, or null of no match found
- */
- public synchronized CloudSite getCloudSiteWithClli(String clli, String version) {
- if (clli != null) {
- // New with 1610 - find cloud site called "DEFAULT" - return that
- // object,with the name modified to match what they asked for. We're
- // looping thru the cloud sites anyway - so save off the default one in case we
- // need it.
- CloudSite defaultCloudSite = null;
- for (CloudSite cs : cloudSites.values()) {
- if (cs.getClli() != null && clli.equals(cs.getClli())) {
- if (version == null || version.equals(cs.getAic_version())) {
- return cs;
- }
- } else if ("default".equalsIgnoreCase(cs.getId())) {
- // save it off in case we need it
- defaultCloudSite = cs.clone();
- }
- }
- // If we get here - we didn't find a match - so return the default
- // cloud site
- if (defaultCloudSite != null) {
- defaultCloudSite.setRegionId(clli);
- defaultCloudSite.setId(clli);
- }
+ private CloudSite getCloudSiteWithClli(String clli) {
+ Optional <CloudSite> cloudSiteOptional = cloudSites.values().stream().filter(cs ->
+ cs.getClli() != null && clli.equals(cs.getClli()) && (CLOUD_SITE_VERSION.equals(cs.getAic_version())))
+ .findAny();
+ return cloudSiteOptional.orElse(getDefaultCloudSite(clli));
+ }
+
+ // TODO in future the result will be optional
+ private CloudSite getDefaultCloudSite(String clli) {
+ Optional<CloudSite> cloudSiteOpt = cloudSites.values().stream()
+ .filter(cs -> cs.getId().equalsIgnoreCase(DEFAULT_CLOUD_SITE_ID)).findAny();
+ if (cloudSiteOpt.isPresent()) {
+ CloudSite defaultCloudSite = cloudSiteOpt.get();
+ defaultCloudSite.setRegionId(clli);
+ defaultCloudSite.setId(clli);
return defaultCloudSite;
+ } else {
+ return null;
}
- return null;
}
/**
* Get a specific CloudIdentity, based on an ID.
- *
+ *
* @param id
* the ID to match
* @return a CloudIdentity, or null of no match found
@@ -173,7 +150,7 @@ public class CloudConfig {
configFilePath = configFile;
this.refreshTimerInMinutes = refreshTimer;
this.validCloudConfig=false;
-
+
try {
reader = new FileReader(configFile);
// Parse the JSON input into a CloudConfig
@@ -200,7 +177,7 @@ public class CloudConfig {
}
}
this.validCloudConfig=true;
-
+
} finally {
try {
if (reader != null) {
@@ -227,12 +204,9 @@ public class CloudConfig {
public synchronized CloudConfig clone() {
CloudConfig ccCopy = new CloudConfig();
for (Entry<String, CloudIdentity> e : identityServices.entrySet()) {
-
ccCopy.identityServices.put(e.getKey(), e.getValue().clone());
}
-
for (Entry<String, CloudSite> e : cloudSites.entrySet()) {
-
ccCopy.cloudSites.put(e.getKey(), e.getValue().clone());
}
ccCopy.configFilePath = this.configFilePath;
@@ -290,5 +264,5 @@ public class CloudConfig {
return true;
}
-
+
}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigIdentityMapper.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigIdentityMapper.java
deleted file mode 100644
index 9677d0ee1c..0000000000
--- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigIdentityMapper.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*-
- * ============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;
-
-/**
- * This interface provides the method signature for mapping registration.
- * All mappings should be registered by the implementing class.
- */
-@FunctionalInterface
-public interface CloudConfigIdentityMapper {
-
- public void registerAllMappings();
-}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java
index fad0c2368b..08ea84d85d 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java
@@ -22,12 +22,10 @@
package org.openecomp.mso.openstack.utils;
import java.io.Serializable;
-import java.rmi.server.ObjID;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/CloudConfigTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/CloudConfigTest.java
deleted file mode 100644
index dd1b396fae..0000000000
--- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/CloudConfigTest.java
+++ /dev/null
@@ -1,193 +0,0 @@
-/*-
- * ============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.adapter_utils.tests;
-
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import java.util.Map;
-import org.openecomp.mso.cloud.CloudConfig;
-import org.openecomp.mso.cloud.CloudConfigFactory;
-import org.openecomp.mso.cloud.CloudIdentity;
-import org.openecomp.mso.cloud.CloudSite;
-import org.openecomp.mso.openstack.exceptions.MsoCloudIdentityNotFound;
-
-/**
- * This class implements test methods of the CloudConfig features.
- */
-public class CloudConfigTest {
-
- private static CloudConfig con;
- private static CloudConfigFactory cloudConfigFactory= new CloudConfigFactory();
-
- public CloudConfigTest () {
-
- }
-
- /**
- * This method is called before any test occurs.
- * It creates a fake tree from scratch
- * @throws MsoCloudIdentityNotFound
- */
- @Before
- public final void prepare () throws MsoCloudIdentityNotFound {
- ClassLoader classLoader = CloudConfigTest.class.getClassLoader();
- String config = classLoader.getResource("cloud_config.json").toString().substring(5);
-
- cloudConfigFactory.initializeCloudConfig(config,1);
- con = cloudConfigFactory.getCloudConfig();
- }
-
- /**
- * This method implements a test for the getCloudConfig method.
- */
- @Test
- public final void testGetCloudConfig () {
- assertNotNull(con);
- }
-
- /**
- * This method implements a test for the getCloudSites method.
- */
- @Test
- public final void testGetCloudSites () {
- Map<String,CloudSite> siteMap = con.getCloudSites();
- assertNotNull(siteMap);
-
- CloudSite site1 = siteMap.get("MT");
- CloudSite site2 = siteMap.get("DAN");
- CloudSite site3 = siteMap.get("MTINJVCC101");
- CloudSite site4 = siteMap.get("MTSNJA4LCP1");
-
- assertEquals (site1.getRegionId(), "regionOne");
- assertEquals (site1.getIdentityServiceId(), "MT_KEYSTONE");
- assertEquals (site2.getRegionId(), "RegionOne");
- assertEquals (site2.getIdentityServiceId(), "DAN_KEYSTONE");
- assertEquals (site3.getRegionId(), "regionTwo");
- assertEquals (site3.getIdentityServiceId(), "MTINJVCC101_DCP");
- assertEquals (site4.getRegionId(), "mtsnjlcp1");
- assertEquals (site4.getIdentityServiceId(), "MTSNJA3DCP1");
- }
-
-
- /**
- * This method implements a test for the getIdentityServices method.
- */
- @Test
- public final void testGetIdentityServices () {
- Map<String,CloudIdentity> identityMap = con.getIdentityServices ();
- assertNotNull(identityMap);
-
- 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());
- assertEquals(false, identity1.hasTenantMetadata());
-
- assertEquals("mockId", identity2.getMsoId());
- assertEquals("stack123", identity2.getMsoPass());
- assertEquals("service", identity2.getAdminTenant());
- assertEquals("_member_", identity2.getMemberRole());
- assertEquals(false, identity2.hasTenantMetadata());
-
- assertEquals("mockIdToo", identity3.getMsoId());
- assertEquals("AICG@mm@@2015", identity3.getMsoPass());
- assertEquals("service", identity3.getAdminTenant());
- assertEquals("admin", identity3.getMemberRole());
- assertEquals(true, identity3.hasTenantMetadata());
-
- assertEquals("mockIdToo", identity4.getMsoId());
- assertEquals("2315QRS2015srq", identity4.getMsoPass());
- assertEquals("service", identity4.getAdminTenant());
- assertEquals("admin", identity4.getMemberRole());
- assertEquals(true, identity4.hasTenantMetadata());
-
- }
-
- /**
- * This method implements a test for the getCloudSite method.
- */
- @Test
- public final void testGetCloudSite () {
- CloudSite site1 = con.getCloudSite("MT");
- assertNotNull(site1);
- assertEquals (site1.getRegionId(), "regionOne");
- assertEquals (site1.getIdentityServiceId(), "MT_KEYSTONE");
- }
-
- /**
- * This method implements a test for the getIdentityService method.
- */
- @Test
- public final void testGetIdentityService () {
- CloudIdentity identity1 = con.getIdentityService("MT_KEYSTONE");
- assertNotNull(identity1);
- assertEquals (identity1.getMsoId(), "john");
- assertEquals (identity1.getMsoPass(), "changeme");
- assertEquals (identity1.getAdminTenant(), "admin");
- assertEquals (identity1.getMemberRole(), "_member_");
- assertEquals (identity1.hasTenantMetadata(), false);
-
- CloudIdentity identity2 = con.getIdentityService("Test");
- assertNull(identity2);
- }
-
- @Test (expected = MsoCloudIdentityNotFound.class)
- public final void testLoadWithWrongFile () throws MsoCloudIdentityNotFound {
- ClassLoader classLoader = CloudConfigTest.class.getClassLoader();
- String config = classLoader.getResource("cloud_config_bad.json").toString().substring(5);
-
- cloudConfigFactory.initializeCloudConfig(config,1);
- }
-
- @Test
- public final void testReloadWithWrongFile () {
- ClassLoader classLoader = CloudConfigTest.class.getClassLoader();
- String config = classLoader.getResource("cloud_config_bad.json").toString().substring(5);
-
- try {
- cloudConfigFactory.initializeCloudConfig(config,1);
- Assert.fail("MsoCloudIdentityNotFound was expected");
- } catch (MsoCloudIdentityNotFound e) {
-
- }
- Assert.assertTrue("Should be an empty CloudConfig", cloudConfigFactory.getCloudConfig().getCloudSites().isEmpty());
- Assert.assertTrue("Should be an empty CloudConfig", cloudConfigFactory.getCloudConfig().getIdentityServices().isEmpty());
-
- // Now reload the right config
- config = classLoader.getResource("cloud_config.json").toString().substring(5);
- cloudConfigFactory.changeMsoPropertiesFilePath(config);
- cloudConfigFactory.reloadCloudConfig();
- Assert.assertTrue("Flag valid Config should be true now that the cloud_config is correct", cloudConfigFactory.getCloudConfig().isValidCloudConfig());
-
- }
-
-}
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoHeatUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoHeatUtilsTest.java
index cd96756644..6fd95d5948 100644
--- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoHeatUtilsTest.java
+++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoHeatUtilsTest.java
@@ -25,6 +25,7 @@ import java.util.HashMap;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openecomp.mso.cloud.CloudConfigFactory;
+import org.openecomp.mso.cloud.CloudConfigTest;
import org.openecomp.mso.openstack.exceptions.MsoCloudIdentityNotFound;
import org.openecomp.mso.openstack.exceptions.MsoCloudSiteNotFound;
import org.openecomp.mso.openstack.exceptions.MsoException;
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
new file mode 100644
index 0000000000..a73e4359fc
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudConfigTest.java
@@ -0,0 +1,179 @@
+/*-
+ * ============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.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+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;
+
+ @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();
+ }
+
+ private CloudConfig createTestObject(String jsonFilePath) throws MsoCloudIdentityNotFound {
+ CloudConfigFactory cloudConfigFactory = new CloudConfigFactory();
+ cloudConfigFactory.initializeCloudConfig(jsonFilePath, 1);
+ return cloudConfigFactory.getCloudConfig();
+ }
+
+ @Test
+ public void testGetCloudSites() throws MsoCloudIdentityNotFound {
+ CloudConfig con = createTestObject(cloudConfigJsonFilePath);
+ Map<String, CloudSite> siteMap = con.getCloudSites();
+ assertNotNull(siteMap);
+
+ 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());
+ }
+
+ @Test
+ public void testGetIdentityServices() throws MsoCloudIdentityNotFound {
+ CloudConfig con = createTestObject(cloudConfigJsonFilePath);
+ Map<String, CloudIdentity> identityMap = con.getIdentityServices();
+ assertNotNull(identityMap);
+
+ 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());
+ }
+
+ @Test
+ public void cloudSiteIsGotById_when_IdFound() throws MsoCloudIdentityNotFound {
+ CloudConfig con = createTestObject(cloudConfigJsonFilePath);
+ CloudSite cloudSite = con.getCloudSite("MT");
+ assertNotNull(cloudSite);
+ assertEquals("regionOne", cloudSite.getRegionId());
+ assertEquals("MT_KEYSTONE", cloudSite.getIdentityServiceId());
+ }
+
+ @Test
+ public void cloudSiteIsGotByClli_when_IdNotFound() throws MsoCloudIdentityNotFound {
+ CloudConfig con = createTestObject(cloudConfigJsonFilePath);
+ CloudSite cloudSite = con.getCloudSite("CS_clli");
+ assertNotNull(cloudSite);
+ assertEquals("clliRegion", cloudSite.getRegionId());
+ assertEquals("CS_clli", cloudSite.getClli());
+ assertEquals("CS_service", cloudSite.getIdentityServiceId());
+ }
+
+ @Test
+ public void cloudSiteIsGotByDefault_when_IdAndClliNotFound() throws MsoCloudIdentityNotFound {
+ CloudConfig con = createTestObject(cloudDefaultConfigJsonFilePath);
+ CloudSite cloudSite = con.getCloudSite("not_existing_id");
+ assertNotNull(cloudSite);
+ assertEquals("not_existing_id", cloudSite.getId());
+ assertEquals("not_existing_id", cloudSite.getRegionId());
+ }
+
+ @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);
+ }
+
+ @Test(expected = MsoCloudIdentityNotFound.class)
+ public void testLoadWithWrongFile() throws MsoCloudIdentityNotFound {
+ createTestObject(cloudConfigInvalidJsonFilePath);
+ }
+
+ @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());
+ }
+
+}
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 ee3532fe15..ff24633f32 100644
--- a/adapters/mso-adapter-utils/src/test/resources/cloud_config.json
+++ b/adapters/mso-adapter-utils/src/test/resources/cloud_config.json
@@ -44,7 +44,8 @@
"tenant_metadata": true,
"identity_server_type": "KEYSTONE",
"identity_authentication_type": "USERNAME_PASSWORD"
- }
+ },
+ "CS_service": {}
},
"cloud_sites":
@@ -76,8 +77,14 @@
"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
new file mode 100644
index 0000000000..35d18e9789
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/test/resources/cloud_default_config.json
@@ -0,0 +1,13 @@
+{
+ "cloud_config": {
+ "identity_services": {
+ "default_service": {}
+ },
+ "cloud_sites": {
+ "default": {
+ "region_id": "defaultRegion",
+ "identity_service_id": "default_service"
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/json/MapDeserializer.java b/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/json/MapDeserializer.java
index 2a3a64ce1b..5bb1dacb4a 100644
--- a/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/json/MapDeserializer.java
+++ b/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/json/MapDeserializer.java
@@ -26,7 +26,6 @@ import org.codehaus.jackson.map.JsonDeserializer;
import org.codehaus.jackson.map.ObjectMapper;
import java.io.IOException;
-import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
diff --git a/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/json/MapSerializer.java b/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/json/MapSerializer.java
index c2ea8242c3..3e9f5c6b58 100644
--- a/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/json/MapSerializer.java
+++ b/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/json/MapSerializer.java
@@ -19,7 +19,6 @@
*/
package org.openecomp.mso.adapters.json;
-import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;
@@ -47,12 +46,9 @@ import java.util.Map;
public class MapSerializer extends JsonSerializer<Map<String, String>> {
@Override
public void serialize(Map<String, String> map, JsonGenerator jsonGenerator,
- SerializerProvider serializerProvider) throws IOException,
- JsonGenerationException {
-
+ SerializerProvider serializerProvider) throws IOException {
jsonGenerator.writeStartObject();
jsonGenerator.writeArrayFieldStart("entry");
-
for (Map.Entry<String,String> entry : map.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
@@ -61,7 +57,6 @@ public class MapSerializer extends JsonSerializer<Map<String, String>> {
jsonGenerator.writeStringField("value", value);
jsonGenerator.writeEndObject();
}
-
jsonGenerator.writeEndArray();
jsonGenerator.writeEndObject();
}
diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/AdapterRestInterfaceTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/AdapterRestInterfaceTest.java
deleted file mode 100644
index 00c853ba0d..0000000000
--- a/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/AdapterRestInterfaceTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.adapters;
-
-import java.io.IOException;
-import java.util.HashMap;
-import org.codehaus.jackson.JsonGenerator;
-import org.codehaus.jackson.map.SerializerProvider;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.openecomp.mso.adapters.json.MapSerializer;
-
-public class AdapterRestInterfaceTest {
-
- @Test
- public final void mapSerializerTest() {
- MapSerializer mapSerializer = new MapSerializer();
- mapSerializer.isUnwrappingSerializer();
- mapSerializer.toString();
- mapSerializer.unwrappingSerializer();
- JsonGenerator jsonGenerator = Mockito.mock(JsonGenerator.class);
- SerializerProvider serializerProvider = Mockito
- .mock(SerializerProvider.class);
- try {
- mapSerializer.serialize(new HashMap(), jsonGenerator, serializerProvider);
- } catch (IOException e) {
- }
- }
-
-}
diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/BeanTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/BeanTest.java
index 984ba1b0af..5c3470acd9 100644
--- a/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/BeanTest.java
+++ b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/BeanTest.java
@@ -17,14 +17,12 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.openecomp.mso.test;
+package org.openecomp.mso.adapters;
import java.lang.reflect.Method;
-import java.lang.reflect.Parameter;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
-
import org.junit.Test;
import org.openecomp.mso.adapters.nwrest.ContrailNetwork;
import org.openecomp.mso.adapters.nwrest.CreateNetworkError;
@@ -34,7 +32,6 @@ import org.openecomp.mso.adapters.nwrest.DeleteNetworkError;
import org.openecomp.mso.adapters.nwrest.DeleteNetworkRequest;
import org.openecomp.mso.adapters.nwrest.DeleteNetworkResponse;
import org.openecomp.mso.adapters.nwrest.NetworkExceptionResponse;
-import org.openecomp.mso.adapters.nwrest.NetworkRequestCommon;
import org.openecomp.mso.adapters.nwrest.NetworkTechnology;
import org.openecomp.mso.adapters.nwrest.ProviderVlanNetwork;
import org.openecomp.mso.adapters.nwrest.QueryNetworkResponse;
@@ -74,7 +71,6 @@ import org.openecomp.mso.adapters.vnfrest.UpdateVolumeGroupRequest;
import org.openecomp.mso.adapters.vnfrest.UpdateVolumeGroupResponse;
import org.openecomp.mso.adapters.vnfrest.VfModuleExceptionResponse;
import org.openecomp.mso.adapters.vnfrest.VfModuleRollback;
-import org.openecomp.mso.adapters.vnfrest.VfResponseCommon;
import org.openecomp.mso.adapters.vnfrest.VolumeGroupRollback;
import org.openecomp.mso.entity.MsoRequest;
diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/json/MapSerializerTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/json/MapSerializerTest.java
new file mode 100644
index 0000000000..f903f21441
--- /dev/null
+++ b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/adapters/json/MapSerializerTest.java
@@ -0,0 +1,56 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.adapters.json;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.codehaus.jackson.JsonGenerator;
+import org.codehaus.jackson.map.SerializerProvider;
+import org.junit.Test;
+
+public class MapSerializerTest {
+
+ private static final String JSON_FIELD_NAME_1 = "testKey1";
+ private static final String JSON_VALUE_1 = "testValue1";
+ private static final String JSON_FIELD_NAME_2 = "testKey2";
+ private static final String JSON_VALUE_2 = "testValue2";
+
+ @Test
+ public void serializationWritesTheProperFieldsToJson() throws Exception {
+ JsonGenerator jsonGeneratorMock = mock(JsonGenerator.class);
+ MapSerializer testedObject = new MapSerializer();
+ testedObject.serialize(prepareMap(), jsonGeneratorMock, mock(SerializerProvider.class));
+ verify(jsonGeneratorMock).writeStringField("key", JSON_FIELD_NAME_1);
+ verify(jsonGeneratorMock).writeStringField("value", JSON_VALUE_1);
+ verify(jsonGeneratorMock).writeStringField("key", JSON_FIELD_NAME_2);
+ verify(jsonGeneratorMock).writeStringField("value", JSON_VALUE_2);
+ }
+
+ private Map<String, String> prepareMap() {
+ Map<String, String> map = new HashMap<>();
+ map.put(JSON_FIELD_NAME_1, JSON_VALUE_1);
+ map.put(JSON_FIELD_NAME_2, JSON_VALUE_2);
+ return map;
+ }
+}