From 95ac2e00966646914f0c03f1d97cb4a48b6342c7 Mon Sep 17 00:00:00 2001 From: Michal Kabaj Date: Mon, 14 Jan 2019 13:56:32 +0100 Subject: MsoTenantUtilsFactoryTest unit tests -added new test cases for factory class Change-Id: Iddd221d1ff5fa6748657b635bc07b6c795b8b9d8 Issue-ID: SO-1339 Signed-off-by: Michal Kabaj --- .../openstack/utils/MsoTenantUtilsFactoryTest.java | 36 ++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'adapters/mso-adapter-utils/src/test/java/org') diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoTenantUtilsFactoryTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoTenantUtilsFactoryTest.java index c3c473591a..f2717ab7ce 100644 --- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoTenantUtilsFactoryTest.java +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoTenantUtilsFactoryTest.java @@ -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 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); + } } -- cgit 1.2.3-korg