aboutsummaryrefslogtreecommitdiffstats
path: root/adapters/mso-adapter-utils/src/test/java
diff options
context:
space:
mode:
authorRob Daugherty <rd472p@att.com>2018-05-02 16:46:14 -0400
committerRob Daugherty <rd472p@att.com>2018-05-04 15:28:51 +0000
commit3ee4ec41ac18e51a16eafa767e090502b1a33fb5 (patch)
tree11a4d7b6c3bc5b88ce8dd67f12c7726c9f7dd80f /adapters/mso-adapter-utils/src/test/java
parent13999df2b5cbcfd29d479e20970b39ba876725f3 (diff)
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 <rd472p@att.com>
Diffstat (limited to 'adapters/mso-adapter-utils/src/test/java')
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoHeatUtilsTest.java6
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudConfigFactoryTest.java28
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/servertype/NewServerTypeUtils.java8
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/servertype/ServerTypeTest.java10
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsTest2.java5
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtilsTest.java29
6 files changed, 54 insertions, 32 deletions
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 931f11efad..93afbcccaf 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
@@ -70,9 +70,9 @@ public class MsoHeatUtilsTest extends MsoCommonUtils {
@BeforeClass
public static final void loadClasses() throws MsoCloudIdentityNotFound, MsoPropertiesException {
- ClassLoader classLoader = CloudConfigTest.class.getClassLoader();
- String config = classLoader.getResource("cloud_config.json").toString().substring(5);
- cloudConfigFactory.initializeCloudConfig(config, 1);
+ ClassLoader classLoader = MsoHeatUtilsTest.class.getClassLoader();
+ String cloudConfigJson = classLoader.getResource("cloud_config.json").getPath();
+ cloudConfigFactory.initializeCloudConfig(cloudConfigJson, 1);
msoPropertiesFactory.initializeMsoProperties("NO_PROP", classLoader.getResource("mso.properties").getPath());
msoHeatUtils = new MsoHeatUtils("NO_PROP", msoPropertiesFactory, cloudConfigFactory);
}
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
@@ -67,17 +79,6 @@ public class CloudConfigFactoryTest {
}
@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
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsTest2.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsTest2.java
index a0ab8e6b11..74d512c63e 100644
--- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsTest2.java
+++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsTest2.java
@@ -42,6 +42,7 @@ import org.openecomp.mso.adapters.vdu.VduModelInfo;
import org.openecomp.mso.adapters.vdu.VduStateType;
import org.openecomp.mso.adapters.vdu.VduStatus;
import org.openecomp.mso.cloud.CloudConfig;
+import org.openecomp.mso.cloud.CloudConfigFactory;
import org.openecomp.mso.cloud.CloudSite;
import org.openecomp.mso.cloudify.beans.DeploymentInfo;
import org.openecomp.mso.cloudify.beans.DeploymentStatus;
@@ -68,7 +69,9 @@ public class MsoHeatUtilsTest2 {
CloudSite site = new CloudSite();
Optional<CloudSite> opSite = Optional.ofNullable(site);
CloudConfig config = Mockito.mock(CloudConfig.class);
- heatUtils.cloudConfig = config;
+ CloudConfigFactory cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
+ when(cloudConfigFactory.getCloudConfig()).thenReturn(config);
+ when(heatUtils.getCloudConfigFactory()).thenReturn(cloudConfigFactory);
CloudInfo cloudInfo = new CloudInfo();
cloudInfo.setCloudSiteId("cloudSiteId");
cloudInfo.setTenantId("tenantId");
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtilsTest.java
index 3e4758a8a2..f2d14d8b22 100644
--- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtilsTest.java
+++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtilsTest.java
@@ -29,9 +29,13 @@ import static org.mockito.Mockito.mock;
import java.util.HashMap;
import java.util.Map;
import org.junit.Assert;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.mockito.Mockito;
+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.beans.MsoTenant;
@@ -66,9 +70,19 @@ public class MsoKeystoneUtilsTest {
@Mock
MsoJavaProperties msoProps;
+ @Mock
+ private static CloudConfigFactory cloudConfigFactory;
+
+ @BeforeClass
+ public static final void prepare () {
+ cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
+ CloudConfig cloudConfig = Mockito.mock(CloudConfig.class);
+ Mockito.when(cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig);
+ }
+
@Test
public void testcreateTenant() throws MsoException{
- MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID"));
+ MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID", cloudConfigFactory));
Map<String,String>metadata=new HashMap<>();
metadata.put("1", "value");
tenant = mock(Tenant.class);
@@ -81,19 +95,19 @@ public class MsoKeystoneUtilsTest {
}
@Test
public void testdeleteTenant() throws MsoException{
- MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID"));
+ MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID", cloudConfigFactory));
doReturn(true).when(msk).deleteTenant("tenantId", "cloudSiteId");
assertTrue(msk.deleteTenant("tenantId", "cloudSiteId"));
}
@Test
public void testfindTenantByName() throws Exception{
- MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID"));
+ MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID", cloudConfigFactory));
doReturn(null).when(msk).findTenantByName(adminClient, "tenantName");
assertNull(msk.findTenantByName(adminClient, "tenantName"));
}
@Test
public void testqueryTenant() throws MsoException{
- MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID"));
+ MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID", cloudConfigFactory));
Map<String,String>metadata=new HashMap<>();
metadata.put("1", "value");
mst = mock(MsoTenant.class);
@@ -106,7 +120,7 @@ public class MsoKeystoneUtilsTest {
@Test
public void testqueryTenantByName()throws MsoException {
- MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID"));
+ MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID", cloudConfigFactory));
Map<String,String>metadata=new HashMap<>();
metadata.put("1", "value");
mst = mock(MsoTenant.class);
@@ -122,9 +136,8 @@ public class MsoKeystoneUtilsTest {
public void testgetKeystoneAdminClient() throws MsoException{
cloudIdentity = mock(CloudIdentity.class);
Keystone keystone = new Keystone (cloudIdentity.getKeystoneUrl ("region", "msoPropID"));
- MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID"));
+ MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID", cloudConfigFactory));
doReturn(keystone).when(msk).getKeystoneAdminClient(cs);
assertNotNull(msk.getKeystoneAdminClient(cs));
}
-
- }
+} \ No newline at end of file