MsoTenantUtilsFactoryTest unit tests 42/75742/3
authorMichal Kabaj <michal.kabaj@nokia.com>
Mon, 14 Jan 2019 12:56:32 +0000 (13:56 +0100)
committerMichal Kabaj <michal.kabaj@nokia.com>
Tue, 15 Jan 2019 08:45:27 +0000 (09:45 +0100)
-added new test cases for factory class

Change-Id: Iddd221d1ff5fa6748657b635bc07b6c795b8b9d8
Issue-ID: SO-1339
Signed-off-by: Michal Kabaj <michal.kabaj@nokia.com>
adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoTenantUtilsFactoryTest.java

index c3c4735..f2717ab 100644 (file)
@@ -4,12 +4,14 @@
  * ================================================================================
  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
+ * Modifications Copyright 2019 Nokia
+ * ================================================================================
  * 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.
@@ -34,6 +36,7 @@ import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
 import org.onap.so.cloud.CloudConfig;
 import org.onap.so.db.catalog.beans.CloudSite;
+import org.onap.so.db.catalog.beans.ServerType;
 import org.onap.so.openstack.exceptions.MsoCloudSiteNotFound;
 
 @RunWith(MockitoJUnitRunner.class)
@@ -41,6 +44,10 @@ public class MsoTenantUtilsFactoryTest {
 
     @Mock
     private CloudConfig cloudConfig;
+    @Mock
+    private MsoKeystoneUtils msoKeystoneUtils;
+    @Mock
+    private MsoKeystoneV3Utils msoKeystoneV3Utils;
     @InjectMocks
     private MsoTenantUtilsFactory msoTenantUtilsFactory;
 
@@ -71,4 +78,29 @@ public class MsoTenantUtilsFactoryTest {
         // THEN
         assertThat(tenantUtils).isNull();
     }
+
+    @Test
+    public void getTenantUtils_shouldReturnKeystoneUtils_forKeystoneServerType() throws MsoCloudSiteNotFound {
+        shouldReturnAppropriateUtilsInstanceForGivenServerType(ServerType.KEYSTONE, msoKeystoneUtils);
+    }
+
+    @Test
+    public void getTenantUtils_shouldReturnKeystoneV3Utils_forKeystoneV3ServerType() throws MsoCloudSiteNotFound {
+        shouldReturnAppropriateUtilsInstanceForGivenServerType(ServerType.KEYSTONE_V3, msoKeystoneV3Utils);
+    }
+
+    private <T extends MsoTenantUtils> void shouldReturnAppropriateUtilsInstanceForGivenServerType(
+        ServerType serverType, T expectedInstance) throws MsoCloudSiteNotFound {
+        // GIVEN
+        String cloudSiteId = "CloudSiteId";
+        CloudSite cloudSite = mock(CloudSite.class, RETURNS_DEEP_STUBS);
+        given(cloudSite.getIdentityService().getIdentityServerType()).willReturn(serverType);
+        given(cloudConfig.getCloudSite(cloudSiteId)).willReturn(Optional.of(cloudSite));
+
+        // WHEN
+        MsoTenantUtils tenantUtils = msoTenantUtilsFactory.getTenantUtils(cloudSiteId);
+
+        // THEN
+        assertThat(tenantUtils).isEqualTo(expectedInstance);
+    }
 }