diff options
Diffstat (limited to 'catalog-fe/src/test/java/org/openecomp/sdc/fe/impl')
5 files changed, 204 insertions, 18 deletions
diff --git a/catalog-fe/src/test/java/org/openecomp/sdc/fe/impl/AuditTest.java b/catalog-fe/src/test/java/org/openecomp/sdc/fe/impl/AuditTest.java index 83bcaab871..c65d75bdab 100644 --- a/catalog-fe/src/test/java/org/openecomp/sdc/fe/impl/AuditTest.java +++ b/catalog-fe/src/test/java/org/openecomp/sdc/fe/impl/AuditTest.java @@ -20,14 +20,6 @@ package org.openecomp.sdc.fe.impl; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.HashMap; -import java.util.Map; -import javax.servlet.http.HttpServletRequest; - import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -35,6 +27,14 @@ import org.mockito.junit.MockitoJUnitRunner; import org.openecomp.sdc.common.api.Constants; import org.slf4j.Logger; +import javax.servlet.http.HttpServletRequest; +import java.util.HashMap; +import java.util.Map; + +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + @RunWith(MockitoJUnitRunner.class) public class AuditTest { diff --git a/catalog-fe/src/test/java/org/openecomp/sdc/fe/impl/HealthCheckScheduledTaskTest.java b/catalog-fe/src/test/java/org/openecomp/sdc/fe/impl/HealthCheckScheduledTaskTest.java new file mode 100644 index 0000000000..362d40cb29 --- /dev/null +++ b/catalog-fe/src/test/java/org/openecomp/sdc/fe/impl/HealthCheckScheduledTaskTest.java @@ -0,0 +1,185 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2020 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.sdc.fe.impl; + +import com.google.common.collect.Lists; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.openecomp.sdc.common.api.Constants; +import org.openecomp.sdc.common.api.HealthCheckInfo; +import org.openecomp.sdc.fe.config.Configuration; + +import java.util.Collections; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class HealthCheckScheduledTaskTest { + + private static final String PROTOCOL = "http"; + private static final String HOST = "192.115.113.25"; + private static final Integer PORT = 8090; + private static final String URI = "/healthCheck"; + private static final String HC_URL = String.format("%s://%s:%s%s", PROTOCOL, HOST, PORT, URI); + + @Mock + private Configuration.CatalogFacadeMsConfig catalogFacadeMsConfig; + @Mock + private Configuration.DcaeConfig dcaeConfig; + @Mock + private Configuration.OnboardingConfig onboardingConfig; + @Mock + private Configuration configuration; + @Mock + private HealthCheckService healthCheckService; + + @InjectMocks + private HealthCheckScheduledTask healthCheckScheduledTask; + + @Before + public void setUp() { + healthCheckScheduledTask = new HealthCheckScheduledTask(healthCheckService); + initMocks(); + } + + @Test + public void getOnboardingUrlWhenConfigurationIsNotProvided() { + when(configuration.getOnboarding()).thenReturn(null); + assertNull(healthCheckScheduledTask.getExternalComponentHcUrl(Constants.HC_COMPONENT_ON_BOARDING)); + } + + @Test + public void getUrlForUnknownComponent() { + assertNull(healthCheckScheduledTask.getExternalComponentHcUrl("test")); + } + + @Test + public void getOnboardingUrlWhenConfigurationIsProvided() { + when(configuration.getOnboarding()).thenReturn(onboardingConfig); + assertNull(HealthCheckScheduledTask.getOnboardingHcUrl()); + healthCheckScheduledTask.getExternalComponentHcUrl(Constants.HC_COMPONENT_ON_BOARDING); + assertEquals(HC_URL, HealthCheckScheduledTask.getOnboardingHcUrl()); + } + + @Test + public void getCatalogFacadeMsUrlWhenConfigurationIsProvidedAndVerifyThatItIsCalculatedOnlyOnce() { + when(configuration.getCatalogFacadeMs()).thenReturn(catalogFacadeMsConfig); + assertNull(HealthCheckScheduledTask.getCatalogFacadeMsHcUrl()); + + HealthCheckScheduledTask healthCheckScheduledTaskSpy = Mockito.spy(healthCheckScheduledTask); + + healthCheckScheduledTaskSpy.getExternalComponentHcUrl(Constants.HC_COMPONENT_CATALOG_FACADE_MS); + assertEquals(HC_URL, HealthCheckScheduledTask.getCatalogFacadeMsHcUrl()); + //try to run again and verify that assignment is not recalled + healthCheckScheduledTaskSpy.getExternalComponentHcUrl(Constants.HC_COMPONENT_CATALOG_FACADE_MS); + verify(healthCheckScheduledTaskSpy, times(1)). + buildHealthCheckUrl(any(String.class), any(String.class), any(Integer.class), any(String.class)); + } + + @Test + public void getDcaeUrlWhenConfigurationIsProvided() { + when(configuration.getDcae()).thenReturn(dcaeConfig); + assertNull(HealthCheckScheduledTask.getDcaeHcUrl()); + healthCheckScheduledTask.getExternalComponentHcUrl(Constants.HC_COMPONENT_DCAE); + assertEquals(HC_URL, HealthCheckScheduledTask.getDcaeHcUrl()); + } + + @Test + public void getExcludedComponentListWhenCatalogFacadeMsConfigExists() { + when(configuration.getCatalogFacadeMs()).thenReturn(catalogFacadeMsConfig); + when(catalogFacadeMsConfig.getPath()).thenReturn("/uicache"); + when(configuration.getHealthStatusExclude()).thenReturn(Lists.newArrayList("DMAAP", "DCAE")); + assertFalse(healthCheckScheduledTask.getExcludedComponentList().contains(Constants.HC_COMPONENT_CATALOG_FACADE_MS)); + } + + @Test + public void getExcludedComponentListWhenCatalogFacadeMsConfigDoesNotExist() { + when(configuration.getCatalogFacadeMs()).thenReturn(null); + when(configuration.getHealthStatusExclude()).thenReturn(Lists.newArrayList()); + assertTrue(healthCheckScheduledTask.getExcludedComponentList().contains(Constants.HC_COMPONENT_CATALOG_FACADE_MS)); + } + + @Test + public void getExcludedComponentListWhenCatalogFacadeMsConfigPathIsNotSet() { + when(configuration.getCatalogFacadeMs()).thenReturn(catalogFacadeMsConfig); + when(catalogFacadeMsConfig.getPath()).thenReturn(null); + when(configuration.getHealthStatusExclude()).thenReturn(Lists.newArrayList()); + assertTrue(healthCheckScheduledTask.getExcludedComponentList().contains(Constants.HC_COMPONENT_CATALOG_FACADE_MS)); + } + + @Test + public void getMergedHCListWhenFeHcIsEmptyAndMainListIsSet() { + HealthCheckInfo mainHC = new HealthCheckInfo(); + mainHC.setComponentsInfo(Collections.emptyList()); + assertEquals(0, healthCheckScheduledTask.updateSubComponentsInfoOfBeHc(mainHC, Collections.emptyList()).getComponentsInfo().size()); + } + + @Test + public void getMergedHCListWhenFeHcIsEmptyAndMainListIsNotSet() { + assertNull(healthCheckScheduledTask.updateSubComponentsInfoOfBeHc(new HealthCheckInfo(), Collections.emptyList()).getComponentsInfo()); + } + + @Test + public void getMergedHCListWhenFeHcListAndMainListAreNotEmpty() { + HealthCheckInfo mainHC = new HealthCheckInfo(); + mainHC.setComponentsInfo(Lists.newArrayList(new HealthCheckInfo())); + assertEquals(2, healthCheckScheduledTask.updateSubComponentsInfoOfBeHc(mainHC, + Collections.singletonList(new HealthCheckInfo())).getComponentsInfo().size()); + } + + @Test + public void getMergedHCListWhenFeHcListIsNotEmptyAndMainListIsEmpty() { + assertEquals(1, healthCheckScheduledTask.updateSubComponentsInfoOfBeHc(new HealthCheckInfo(), + Collections.singletonList(new HealthCheckInfo())).getComponentsInfo().size()); + } + + + private void initMocks() { + when(healthCheckService.getConfig()).thenReturn(configuration); + + when(onboardingConfig.getProtocolFe()).thenReturn(PROTOCOL); + when(onboardingConfig.getHostFe()).thenReturn(HOST); + when(onboardingConfig.getPortFe()).thenReturn(PORT); + when(onboardingConfig.getHealthCheckUriFe()).thenReturn(URI); + + when(dcaeConfig.getProtocol()).thenReturn(PROTOCOL); + when(dcaeConfig.getHost()).thenReturn(HOST); + when(dcaeConfig.getPort()).thenReturn(PORT); + when(dcaeConfig.getHealthCheckUri()).thenReturn(URI); + + when(catalogFacadeMsConfig.getProtocol()).thenReturn(PROTOCOL); + when(catalogFacadeMsConfig.getHost()).thenReturn(HOST); + when(catalogFacadeMsConfig.getPort()).thenReturn(PORT); + when(catalogFacadeMsConfig.getHealthCheckUri()).thenReturn(URI); + } +} diff --git a/catalog-fe/src/test/java/org/openecomp/sdc/fe/impl/HttpRequestInfoTest.java b/catalog-fe/src/test/java/org/openecomp/sdc/fe/impl/HttpRequestInfoTest.java index bfc45528c4..156e1624c4 100644 --- a/catalog-fe/src/test/java/org/openecomp/sdc/fe/impl/HttpRequestInfoTest.java +++ b/catalog-fe/src/test/java/org/openecomp/sdc/fe/impl/HttpRequestInfoTest.java @@ -22,12 +22,6 @@ package org.openecomp.sdc.fe.impl; -import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import javax.servlet.http.HttpServletRequest; import org.apache.commons.io.IOUtils; import org.junit.Assert; import org.junit.Test; @@ -36,6 +30,13 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters; + @RunWith(MockitoJUnitRunner.class) public class HttpRequestInfoTest { diff --git a/catalog-fe/src/test/java/org/openecomp/sdc/fe/impl/ImportMetadataTest.java b/catalog-fe/src/test/java/org/openecomp/sdc/fe/impl/ImportMetadataTest.java index 2fd5b56b18..cb1beda053 100644 --- a/catalog-fe/src/test/java/org/openecomp/sdc/fe/impl/ImportMetadataTest.java +++ b/catalog-fe/src/test/java/org/openecomp/sdc/fe/impl/ImportMetadataTest.java @@ -21,12 +21,12 @@ */ package org.openecomp.sdc.fe.impl; +import org.junit.Test; + import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters; import static org.hamcrest.core.IsEqual.equalTo; import static org.junit.Assert.assertThat; -import org.junit.Test; - public class ImportMetadataTest { private static final String CHECKSUM = "CHECKSUM"; diff --git a/catalog-fe/src/test/java/org/openecomp/sdc/fe/impl/MdcDataTest.java b/catalog-fe/src/test/java/org/openecomp/sdc/fe/impl/MdcDataTest.java index d07470668e..a967f46a8e 100644 --- a/catalog-fe/src/test/java/org/openecomp/sdc/fe/impl/MdcDataTest.java +++ b/catalog-fe/src/test/java/org/openecomp/sdc/fe/impl/MdcDataTest.java @@ -21,10 +21,10 @@ */ package org.openecomp.sdc.fe.impl; -import static org.junit.Assert.assertEquals; - import org.junit.Test; +import static org.junit.Assert.assertEquals; + public class MdcDataTest { private static final String INSTANCE_ID = "INSTANCE_ID"; |