From 3ee4ec41ac18e51a16eafa767e090502b1a33fb5 Mon Sep 17 00:00:00 2001 From: Rob Daugherty Date: Wed, 2 May 2018 16:46:14 -0400 Subject: Fix CloudConfig junits ...for some definition of the word "fix". There is still a lot that's less than ideal about how CloudConfig is handled, and with how the unit tests are written. Change-Id: Ic8c66c64d336f22c141687cf41a4828810bf1aec Issue-ID: SO-584 Signed-off-by: Rob Daugherty --- .../mso/cloud/CloudConfigFactoryTest.java | 28 ++++++++++------------ .../mso/cloud/servertype/NewServerTypeUtils.java | 8 +++---- .../mso/cloud/servertype/ServerTypeTest.java | 10 ++++++++ 3 files changed, 26 insertions(+), 20 deletions(-) (limited to 'adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud') 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 index fe768b5774..c6c6baf61b 100644 --- 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 @@ -30,6 +30,7 @@ import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; import javax.ws.rs.core.Response; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openecomp.mso.openstack.exceptions.MsoCloudIdentityNotFound; @@ -41,12 +42,23 @@ public class CloudConfigFactoryTest { private CloudConfigFactory testedObject; private CloudConfig cloudConfigMock; + private CloudConfig savedCloudConfig; @Before public void init() throws NoSuchFieldException, IllegalAccessException { cloudConfigMock = mock(CloudConfig.class); testedObject = new CloudConfigFactory(); - setCloudConfig(); + Field field = CloudConfigFactory.class.getDeclaredField(CLOUD_CONFIG_FIELD_NAME); + field.setAccessible(true); + savedCloudConfig = (CloudConfig) field.get(null); + field.set(null, cloudConfigMock); + } + + @After + public void reset() throws NoSuchFieldException, IllegalAccessException { + Field field = CloudConfigFactory.class.getDeclaredField(CLOUD_CONFIG_FIELD_NAME); + field.setAccessible(true); + field.set(null, savedCloudConfig); } @Test @@ -66,17 +78,6 @@ public class CloudConfigFactoryTest { 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); @@ -156,9 +157,6 @@ public class CloudConfigFactoryTest { 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/servertype/NewServerTypeUtils.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/servertype/NewServerTypeUtils.java index aaa732c9a3..40108b3802 100644 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/servertype/NewServerTypeUtils.java +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/servertype/NewServerTypeUtils.java @@ -22,6 +22,7 @@ package org.openecomp.mso.cloud.servertype; import java.util.Map; +import org.openecomp.mso.cloud.CloudConfigFactory; import org.openecomp.mso.cloud.CloudIdentity; import org.openecomp.mso.openstack.beans.MsoTenant; import org.openecomp.mso.openstack.exceptions.MsoCloudSiteNotFound; @@ -31,11 +32,8 @@ import org.openecomp.mso.openstack.utils.MsoTenantUtils; public class NewServerTypeUtils extends MsoTenantUtils { - /** - * @param msoPropID - */ - public NewServerTypeUtils(String msoPropID) { - super(msoPropID); + public NewServerTypeUtils(String msoPropID, CloudConfigFactory cloudConfigFactory) { + super(msoPropID, cloudConfigFactory); } @Override diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/servertype/ServerTypeTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/servertype/ServerTypeTest.java index 4aaf379512..69fab27f78 100644 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/servertype/ServerTypeTest.java +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/servertype/ServerTypeTest.java @@ -24,14 +24,24 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; +import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; +import org.openecomp.mso.cloud.CloudConfigFactory; import org.openecomp.mso.cloud.CloudIdentity; import org.openecomp.mso.cloud.CloudIdentity.IdentityServerType; import org.openecomp.mso.cloud.IdentityServerTypeAbstract; import org.openecomp.mso.openstack.exceptions.MsoException; +import org.openecomp.mso.openstack.utils.MsoKeystoneUtilsTest; public class ServerTypeTest { + + @BeforeClass + public static void init() throws Exception { + String cloudConfigJson = ServerTypeTest.class.getClassLoader() + .getResource("cloud_config.json").getPath(); + (new CloudConfigFactory()).initializeCloudConfig(cloudConfigJson, 0); + } @Test @Ignore // IGNORED FOR 1710 MERGE TO ONAP -- cgit 1.2.3-korg