diff options
author | 2018-09-19 22:45:14 -0400 | |
---|---|---|
committer | 2018-09-19 22:45:52 -0400 | |
commit | 51dea82ee0402d1677d8ed15fbda8f9e8f8337de (patch) | |
tree | be6cbfc4a90a090c8283d6c8ca2847f126dfe65f /dcae-analytics/dcae-analytics-web/src | |
parent | 7ccd44a86b4d021615f084a165b20cff2fab2424 (diff) |
Improve code coverage
Issue-ID: DCAEGEN2-797
Change-Id: If5f418445d7925d7a55cccecfad81d1446956ad1
Signed-off-by: Singla, Rajiv (rs153v) <rs153v@att.com>
Diffstat (limited to 'dcae-analytics/dcae-analytics-web/src')
7 files changed, 204 insertions, 30 deletions
diff --git a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/BaseAnalyticsWebTest.java b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/BaseAnalyticsWebTest.java index 4258973..641ad95 100644 --- a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/BaseAnalyticsWebTest.java +++ b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/BaseAnalyticsWebTest.java @@ -19,10 +19,30 @@ package org.onap.dcae.analytics.web; +import org.junit.jupiter.api.BeforeAll; import org.onap.dcae.analytics.test.BaseAnalyticsUnitTest; +import java.util.HashMap; + +import static org.onap.dcae.analytics.model.configbindingservice.ConfigBindingServiceConstants.CONFIG_BINDING_SERVICE_ENV_VARIABLE_KEY; +import static org.onap.dcae.analytics.model.configbindingservice.ConfigBindingServiceConstants.CONSUL_HOST_ENV_VARIABLE_KEY; +import static org.onap.dcae.analytics.model.configbindingservice.ConfigBindingServiceConstants.SERVICE_NAME_ENV_VARIABLE_KEY; + /** * @author Rajiv Singla */ public abstract class BaseAnalyticsWebTest extends BaseAnalyticsUnitTest { + + public static void initializeConfigBindingServiceEnvironmentVariables() throws Exception { + // sets up environment variables for testing purposes + final HashMap<String, String> testEnvironmentVariables = new HashMap<>(); + final String testConsulHostValue = "localhost"; + final String testConfigBindingService = "config_binding_service"; + final String testServiceName = "tca_dev"; + testEnvironmentVariables.put(CONSUL_HOST_ENV_VARIABLE_KEY, testConsulHostValue); + testEnvironmentVariables.put(CONFIG_BINDING_SERVICE_ENV_VARIABLE_KEY, testConfigBindingService); + testEnvironmentVariables.put(SERVICE_NAME_ENV_VARIABLE_KEY, testServiceName); + setEnvironmentVariables(testEnvironmentVariables); + } + } diff --git a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/dmaap/MrMessageSplitterTest.java b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/dmaap/MrMessageSplitterTest.java index 5ec48ef..19cdba7 100644 --- a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/dmaap/MrMessageSplitterTest.java +++ b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/dmaap/MrMessageSplitterTest.java @@ -1,23 +1,37 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.web.dmaap; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; -import org.onap.dcae.analytics.model.AnalyticsModel; -import org.onap.dcae.analytics.model.TcaModelConstants; import org.onap.dcae.analytics.web.BaseAnalyticsWebTest; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.support.MessageBuilder; -import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import java.util.stream.IntStream; import java.util.stream.Stream; -import static org.junit.jupiter.api.Assertions.*; import static org.onap.dcae.analytics.model.AnalyticsHttpConstants.REQUEST_ID_HEADER_KEY; import static org.onap.dcae.analytics.model.util.json.AnalyticsModelJsonConversion.ANALYTICS_MODEL_OBJECT_MAPPER; diff --git a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/http/EelfAuditLogInterceptorTest.java b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/http/EelfAuditLogInterceptorTest.java index b46e9d3..f620247 100644 --- a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/http/EelfAuditLogInterceptorTest.java +++ b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/http/EelfAuditLogInterceptorTest.java @@ -1,3 +1,22 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.web.http; import org.junit.jupiter.api.Test; @@ -12,8 +31,6 @@ import org.springframework.mock.http.client.MockClientHttpResponse; import java.io.IOException; -import static org.junit.jupiter.api.Assertions.*; - class EelfAuditLogInterceptorTest extends BaseAnalyticsWebTest { @Test diff --git a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/http/HttpClientPreferencesCustomizerTest.java b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/http/HttpClientPreferencesCustomizerTest.java index 33ec457..9c1bce0 100644 --- a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/http/HttpClientPreferencesCustomizerTest.java +++ b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/http/HttpClientPreferencesCustomizerTest.java @@ -1,3 +1,22 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.web.http; import org.assertj.core.api.Assertions; @@ -6,8 +25,6 @@ import org.onap.dcae.analytics.web.BaseAnalyticsWebTest; import org.onap.dcae.analytics.web.dmaap.MrSubscriberPreferences; import org.springframework.web.client.RestTemplate; -import static org.junit.jupiter.api.Assertions.*; - class HttpClientPreferencesCustomizerTest extends BaseAnalyticsWebTest { @Test diff --git a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/spring/ConfigBindingServiceEnvironmentPostProcessorIT.java b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/spring/ConfigBindingServiceEnvironmentPostProcessorIT.java index d459212..32c4fe8 100644 --- a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/spring/ConfigBindingServiceEnvironmentPostProcessorIT.java +++ b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/spring/ConfigBindingServiceEnvironmentPostProcessorIT.java @@ -19,23 +19,12 @@ package org.onap.dcae.analytics.web.spring; -import static org.onap.dcae.analytics.model.configbindingservice.ConfigBindingServiceConstants - .CONFIG_BINDING_SERVICE_ENV_VARIABLE_KEY; -import static org.onap.dcae.analytics.model.configbindingservice.ConfigBindingServiceConstants - .CONFIG_BINDING_SERVICE_PROPERTIES_KEY; -import static org.onap.dcae.analytics.model.configbindingservice.ConfigBindingServiceConstants - .CONSUL_HOST_ENV_VARIABLE_KEY; -import static org.onap.dcae.analytics.model.configbindingservice.ConfigBindingServiceConstants - .SERVICE_NAME_ENV_VARIABLE_KEY; - -import java.util.HashMap; -import java.util.Map; - import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.onap.dcae.analytics.model.AnalyticsProfile; import org.onap.dcae.analytics.web.BaseAnalyticsWebSpringBootIT; +import org.onap.dcae.analytics.web.BaseAnalyticsWebTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.AbstractEnvironment; import org.springframework.core.env.Environment; @@ -43,6 +32,11 @@ import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.PropertySource; import org.springframework.test.context.ActiveProfiles; +import java.util.HashMap; +import java.util.Map; + +import static org.onap.dcae.analytics.model.configbindingservice.ConfigBindingServiceConstants.CONFIG_BINDING_SERVICE_PROPERTIES_KEY; + /** * @author Rajiv Singla */ @@ -52,15 +46,7 @@ class ConfigBindingServiceEnvironmentPostProcessorIT extends BaseAnalyticsWebSpr @BeforeAll static void beforeAll() throws Exception { - // sets up environment variables for testing purposes - final HashMap<String, String> testEnvironmentVariables = new HashMap<>(); - final String testConsulHostValue = "localhost"; - final String testConfigBindingService = "config_binding_service"; - final String testServiceName = "tca_dev"; - testEnvironmentVariables.put(CONSUL_HOST_ENV_VARIABLE_KEY, testConsulHostValue); - testEnvironmentVariables.put(CONFIG_BINDING_SERVICE_ENV_VARIABLE_KEY, testConfigBindingService); - testEnvironmentVariables.put(SERVICE_NAME_ENV_VARIABLE_KEY, testServiceName); - setEnvironmentVariables(testEnvironmentVariables); + BaseAnalyticsWebTest.initializeConfigBindingServiceEnvironmentVariables(); } @Autowired diff --git a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/spring/ConfigBindingServiceEnvironmentPostProcessorTest.java b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/spring/ConfigBindingServiceEnvironmentPostProcessorTest.java new file mode 100644 index 0000000..5506342 --- /dev/null +++ b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/spring/ConfigBindingServiceEnvironmentPostProcessorTest.java @@ -0,0 +1,58 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.web.spring; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.onap.dcae.analytics.model.AnalyticsProfile; +import org.onap.dcae.analytics.web.BaseAnalyticsWebTest; +import org.onap.dcae.analytics.web.exception.AnalyticsValidationException; +import org.springframework.boot.SpringApplication; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.MutablePropertySources; + +class ConfigBindingServiceEnvironmentPostProcessorTest extends BaseAnalyticsWebTest { + + @BeforeAll + static void beforeAll() throws Exception { + BaseAnalyticsWebTest.initializeConfigBindingServiceEnvironmentVariables(); + } + + + @Test + void postProcessEnvironment() { + + Assertions.assertThrows(AnalyticsValidationException.class, () -> { + + final ConfigBindingServiceEnvironmentPostProcessor configBindingServiceEnvironmentPostProcessor = + new ConfigBindingServiceEnvironmentPostProcessor(); + + final ConfigurableEnvironment configurableEnvironment = Mockito.mock(ConfigurableEnvironment.class); + final SpringApplication springApplication = Mockito.mock(SpringApplication.class); + final String[] activeProfiles = {AnalyticsProfile.CONFIG_BINDING_SERVICE_PROFILE_NAME}; + Mockito.when(configurableEnvironment.getActiveProfiles()).thenReturn(activeProfiles); + + configBindingServiceEnvironmentPostProcessor + .postProcessEnvironment(configurableEnvironment, springApplication); + }); + } +} diff --git a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/spring/MongoAutoConfigurationPostProcessorTest.java b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/spring/MongoAutoConfigurationPostProcessorTest.java new file mode 100644 index 0000000..95a6950 --- /dev/null +++ b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/spring/MongoAutoConfigurationPostProcessorTest.java @@ -0,0 +1,62 @@ +/* + * ================================================================================ + * Copyright (c) 2018 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.onap.dcae.analytics.web.spring; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.onap.dcae.analytics.model.AnalyticsProfile; +import org.onap.dcae.analytics.web.BaseAnalyticsWebTest; +import org.springframework.boot.SpringApplication; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.MutablePropertySources; + +class MongoAutoConfigurationPostProcessorTest extends BaseAnalyticsWebTest { + @BeforeAll + static void beforeAll() throws Exception { + BaseAnalyticsWebTest.initializeConfigBindingServiceEnvironmentVariables(); + } + + + @Test + void postProcessEnvironmentWhenMongoIsNotActive() { + invokePostEnvironmentProcessor(AnalyticsProfile.NOT_MONGO_PROFILE_NAME); + } + + + @Test + void postProcessEnvironmentWhenMongoIsActive() { + invokePostEnvironmentProcessor(AnalyticsProfile.MONGO_PROFILE_NAME); + } + + private static void invokePostEnvironmentProcessor(final String... activeProfiles) { + final MongoAutoConfigurationPostProcessor mongoAutoConfigurationPostProcessor = + new MongoAutoConfigurationPostProcessor(); + + final ConfigurableEnvironment configurableEnvironment = Mockito.mock(ConfigurableEnvironment.class); + final SpringApplication springApplication = Mockito.mock(SpringApplication.class); + final MutablePropertySources mutablePropertySources = Mockito.mock(MutablePropertySources.class); + Mockito.when(configurableEnvironment.getActiveProfiles()).thenReturn(activeProfiles); + Mockito.when(configurableEnvironment.getPropertySources()).thenReturn(mutablePropertySources); + + mongoAutoConfigurationPostProcessor + .postProcessEnvironment(configurableEnvironment, springApplication); + } +} |