summaryrefslogtreecommitdiffstats
path: root/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils')
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/CloudConfigTest.java173
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoCommonUtilsTest.java130
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoHeatUtilsTest.java91
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoHeatUtilsWithUpdateTest.java132
4 files changed, 526 insertions, 0 deletions
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
new file mode 100644
index 0000000000..8632d02164
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/CloudConfigTest.java
@@ -0,0 +1,173 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * 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.BeforeClass;
+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;
+
+
+/**
+ * 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
+ */
+ @BeforeClass
+ public static final void prepare () {
+ 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");
+
+ 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");
+
+ }
+
+
+ /**
+ * 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 (identity1.getKeystoneUrl(), "http://localhost:5000/v2.0");
+// assertEquals (identity1.getIdentityUrl(), "http://localhost:5000/v2.0");
+ assertEquals (identity1.getMsoId(), "john");
+ assertEquals (identity1.getMsoPass(), "changeme");
+ assertEquals (identity1.getAdminTenant(), "admin");
+ assertEquals (identity1.getMemberRole(), "_member_");
+ assertEquals (identity1.hasTenantMetadata(), false);
+
+// assertEquals (identity2.getKeystoneUrl(), "http://localhost:5000/v2.0");
+// assertEquals (identity2.getIdentityUrl(), "http://localhost:5000/v2.0");
+ assertEquals (identity2.getMsoId(), "mockId");
+ assertEquals (identity2.getMsoPass(), "stack123");
+ assertEquals (identity2.getAdminTenant(), "service");
+ assertEquals (identity2.getMemberRole(), "_member_");
+ assertEquals (identity2.hasTenantMetadata(), false);
+
+// assertEquals (identity3.getKeystoneUrl(), "http://localhost:5000/v2.0");
+// assertEquals (identity3.getIdentityUrl(), "http://localhost:5000/v2.0");
+ assertEquals (identity3.getMsoId(), "mockIdToo");
+ assertEquals (identity3.getMsoPass(), "AICG@mm@@2015");
+ assertEquals (identity3.getAdminTenant(), "service");
+ assertEquals (identity3.getMemberRole(), "admin");
+ assertEquals (identity3.hasTenantMetadata(), true);
+
+// assertEquals (identity4.getKeystoneUrl(), "https://localhost:5000/v2.0");
+// assertEquals (identity4.getIdentityUrl(), "https://localhost:5000/v2.0");
+ assertEquals (identity4.getMsoId(), "mockIdToo");
+ assertEquals (identity4.getMsoPass(), "2315QRS2015srq");
+ assertEquals (identity4.getAdminTenant(), "service");
+ assertEquals (identity4.getMemberRole(), "admin");
+ assertEquals (identity4.hasTenantMetadata(), true);
+
+ }
+
+ /**
+ * 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.getKeystoneUrl(), "http://localhost:5000/v2.0");
+// assertEquals (identity1.getIdentityUrl(), "http://localhost:5000/v2.0");
+ 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);
+ }
+
+}
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoCommonUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoCommonUtilsTest.java
new file mode 100644
index 0000000000..9f17283786
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoCommonUtilsTest.java
@@ -0,0 +1,130 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * 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.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import org.openecomp.mso.logger.MsoAlarmLogger;
+import org.openecomp.mso.openstack.exceptions.MsoAdapterException;
+import org.openecomp.mso.openstack.exceptions.MsoException;
+import org.openecomp.mso.openstack.exceptions.MsoExceptionCategory;
+import org.openecomp.mso.openstack.exceptions.MsoIOException;
+import org.openecomp.mso.openstack.exceptions.MsoOpenstackException;
+import org.openecomp.mso.openstack.utils.MsoCommonUtils;
+import org.openecomp.mso.properties.MsoJavaProperties;
+import org.openecomp.mso.properties.MsoPropertiesException;
+import org.openecomp.mso.properties.MsoPropertiesFactory;
+import com.woorea.openstack.base.client.OpenStackBaseException;
+import com.woorea.openstack.base.client.OpenStackConnectException;
+import com.woorea.openstack.base.client.OpenStackRequest;
+import com.woorea.openstack.base.client.OpenStackResponseException;
+
+
+/**
+ * This class implements test methods of the MsoCommonUtils
+ *
+ *
+ */
+public class MsoCommonUtilsTest extends MsoCommonUtils {
+
+ public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
+
+ @Test
+ public final void testExecuteAndRecordOpenstackRequest () {
+ OpenStackRequest openstackRequest = Mockito.mock(OpenStackRequest.class);
+ Mockito.when(openstackRequest.endpoint()).thenReturn("localhost");
+ Mockito.when(openstackRequest.path()).thenReturn("/test");
+ //TODO:Must try a real connection
+ assertNull(super.executeAndRecordOpenstackRequest (openstackRequest));
+
+ }
+
+ @Test
+ public final void testKeystoneErrorToMsoException () {
+ OpenStackBaseException openStackConnectException = new OpenStackConnectException("connect");
+
+ OpenStackBaseException openStackResponseException = new OpenStackResponseException("response",1);
+
+ MsoException me = super.keystoneErrorToMsoException (openStackConnectException,"ContextError");
+
+ assertTrue(me instanceof MsoIOException);
+ assertTrue("connect".equals(me.getMessage()));
+
+
+ MsoException me2 = super.keystoneErrorToMsoException (openStackResponseException,"ContextError");
+ assertTrue(me2 instanceof MsoOpenstackException);
+ assertTrue("ContextError".equals(me2.getContext()));
+ assertTrue(MsoExceptionCategory.OPENSTACK.equals(me2.getCategory()));
+
+ }
+
+ @Test
+ public final void testHeatExceptionToMsoException () {
+ OpenStackBaseException openStackConnectException = new OpenStackConnectException("connect");
+
+ OpenStackBaseException openStackResponseException = new OpenStackResponseException("response",1);
+
+ MsoException me = super.heatExceptionToMsoException (openStackConnectException,"ContextError");
+
+ assertTrue(me instanceof MsoIOException);
+ assertTrue("connect".equals(me.getMessage()));
+
+
+ MsoException me2 = super.heatExceptionToMsoException (openStackResponseException,"ContextError");
+ assertTrue(me2 instanceof MsoOpenstackException);
+ assertTrue("ContextError".equals(me2.getContext()));
+ assertTrue(MsoExceptionCategory.OPENSTACK.equals(me2.getCategory()));
+ }
+
+ @Test
+ public final void testNeutronExceptionToMsoException () {
+ OpenStackBaseException openStackConnectException = new OpenStackConnectException("connect");
+
+ OpenStackBaseException openStackResponseException = new OpenStackResponseException("response",1);
+
+ MsoException me = super.neutronExceptionToMsoException (openStackConnectException,"ContextError");
+
+ assertTrue(me instanceof MsoIOException);
+ assertTrue("connect".equals(me.getMessage()));
+
+ MsoException me2 = super.neutronExceptionToMsoException (openStackResponseException,"ContextError");
+ assertTrue(me2 instanceof MsoOpenstackException);
+ assertTrue("ContextError".equals(me2.getContext()));
+ assertTrue(MsoExceptionCategory.OPENSTACK.equals(me2.getCategory()));
+ }
+
+ @Test
+ public final void testRuntimeExceptionToMsoException () {
+ RuntimeException re = new RuntimeException ("runtime");
+ MsoException me = super.runtimeExceptionToMsoException (re, "ContextError");
+
+ assertTrue (me instanceof MsoAdapterException);
+ assertTrue("ContextError".equals(me.getContext()));
+ assertTrue(MsoExceptionCategory.INTERNAL.equals(me.getCategory()));
+ }
+}
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
new file mode 100644
index 0000000000..6f8a6e93d8
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoHeatUtilsTest.java
@@ -0,0 +1,91 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * 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 java.util.HashMap;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.openecomp.mso.cloud.CloudConfigFactory;
+import org.openecomp.mso.openstack.exceptions.MsoAdapterException;
+import org.openecomp.mso.openstack.exceptions.MsoCloudSiteNotFound;
+import org.openecomp.mso.openstack.exceptions.MsoException;
+import org.openecomp.mso.openstack.exceptions.MsoIOException;
+import org.openecomp.mso.openstack.exceptions.MsoStackAlreadyExists;
+import org.openecomp.mso.openstack.exceptions.MsoTenantNotFound;
+import org.openecomp.mso.openstack.utils.MsoCommonUtils;
+import org.openecomp.mso.openstack.utils.MsoHeatUtils;
+import org.openecomp.mso.properties.MsoPropertiesFactory;
+
+
+
+/**
+ * This class implements test methods of the MsoHeatUtils
+ *
+ *
+ */
+public class MsoHeatUtilsTest extends MsoCommonUtils {
+ public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
+ public static CloudConfigFactory cloudConfigFactory = new CloudConfigFactory();
+ public static MsoHeatUtils msoHeatUtils;
+
+ @BeforeClass
+ public static final void loadClasses() {
+ ClassLoader classLoader = CloudConfigTest.class.getClassLoader();
+ String config = classLoader.getResource("cloud_config.json").toString().substring(5);
+ cloudConfigFactory.initializeCloudConfig(config, 1);
+ msoHeatUtils = new MsoHeatUtils("NO_PROP",msoPropertiesFactory,cloudConfigFactory);
+ }
+
+ @Test
+ public final void testCreateStackBadCloudConfig () {
+ try {
+ msoHeatUtils.createStack ("DOESNOTEXIST", "test", "stackName", "test", new HashMap<String,Object> (), Boolean.TRUE, 10);
+ } catch (MsoException e) {
+
+ }
+
+ }
+
+ @Test
+ public final void testCreateStackFailedConnectionHeatClient () throws MsoStackAlreadyExists, MsoTenantNotFound, MsoException, MsoCloudSiteNotFound {
+ try {
+ msoHeatUtils.createStack ("MT", "test", "stackName", "test", new HashMap<String,Object> (), Boolean.TRUE, 10);
+ } catch (MsoIOException e) {
+
+ }
+
+ }
+
+ @Test
+ public final void testCreateStackFailedConnection () throws MsoStackAlreadyExists, MsoTenantNotFound, MsoException, MsoCloudSiteNotFound {
+ try {
+ msoHeatUtils.createStack ("MT", "test", "stackName", "test", new HashMap<String,Object> (), Boolean.TRUE, 10);
+ } catch (MsoIOException e) {
+
+ }
+
+ }
+
+
+
+}
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoHeatUtilsWithUpdateTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoHeatUtilsWithUpdateTest.java
new file mode 100644
index 0000000000..a5d46da614
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoHeatUtilsWithUpdateTest.java
@@ -0,0 +1,132 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * 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.fail;
+import static org.mockito.Mockito.when;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+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.MsoCloudSiteNotFound;
+import org.openecomp.mso.openstack.exceptions.MsoException;
+import org.openecomp.mso.openstack.exceptions.MsoIOException;
+import org.openecomp.mso.openstack.utils.MsoHeatUtilsWithUpdate;
+import org.openecomp.mso.properties.MsoPropertiesFactory;
+import com.woorea.openstack.base.client.OpenStackConnectException;
+
+@RunWith(MockitoJUnitRunner.class)
+public class MsoHeatUtilsWithUpdateTest {
+
+ public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
+ public static CloudConfigFactory cloudConfigFactory = new CloudConfigFactory();
+
+ @Mock
+ CloudConfig cloudConfig;
+ @InjectMocks
+ MsoHeatUtilsWithUpdate util=new MsoHeatUtilsWithUpdate("NO_PROP",msoPropertiesFactory,cloudConfigFactory);
+
+ private CloudSite cloudSite;
+
+ @Before
+ public void init () {
+ cloudSite = new CloudSite ();
+ cloudSite.setId ("cloud");
+ CloudIdentity cloudIdentity = new CloudIdentity ();
+ cloudSite.setIdentityService (cloudIdentity);
+ cloudIdentity.setKeystoneUrl ("toto");
+ cloudIdentity.setMsoPass (CloudIdentity.encryptPassword ("mockId"));
+
+ when (cloudConfig.getCloudSite ("cloud")).thenReturn (cloudSite);
+ when (cloudConfig.getCloudSite ("none")).thenReturn (null);
+ }
+
+ @Test
+ public void testUpdateStack () {
+ // Heat heat = Mockito.mock (Heat.class);
+ Map <String, Object> stackInputs = new HashMap <> ();
+ try {
+ util.updateStack ("none", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1);
+ } catch (MsoException e) {
+ if (e instanceof MsoCloudSiteNotFound) {
+ // Ok
+ } else {
+ e.printStackTrace ();
+ fail ("Exception caught");
+ }
+ }
+ try {
+ util.updateStack ("cloud", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1);
+ } catch (MsoException e) {
+ if (e instanceof MsoIOException && e.getCause () != null
+ && e.getCause () instanceof OpenStackConnectException) {
+ // Ok, we were able to go up to the connection to OpenStack
+ } else {
+ e.printStackTrace ();
+ fail ("Exception caught");
+ }
+ }
+ try {
+ util.updateStack ("cloud", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1, "environment");
+ } catch (MsoException e) {
+ if (e instanceof MsoIOException && e.getCause () != null
+ && e.getCause () instanceof OpenStackConnectException) {
+ // Ok, we were able to go up to the connection to OpenStack
+ } else {
+ e.printStackTrace ();
+ fail ("Exception caught");
+ }
+ }
+ try {
+ util.updateStack ("cloud", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1, "environment", null);
+ } catch (MsoException e) {
+ if (e instanceof MsoIOException && e.getCause () != null
+ && e.getCause () instanceof OpenStackConnectException) {
+ // Ok, we were able to go up to the connection to OpenStack
+ } else {
+ e.printStackTrace ();
+ fail ("Exception caught");
+ }
+ }
+ try {
+ util.updateStack ("cloud", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1, "environment", null, null);
+ } catch (MsoException e) {
+ if (e instanceof MsoIOException && e.getCause () != null
+ && e.getCause () instanceof OpenStackConnectException) {
+ // Ok, we were able to go up to the connection to OpenStack
+ } else {
+ e.printStackTrace ();
+ fail ("Exception caught");
+ }
+ }
+ }
+}