diff options
Diffstat (limited to 'dcae-analytics')
9 files changed, 208 insertions, 32 deletions
diff --git a/dcae-analytics/dcae-analytics-test/src/main/java/org/onap/dcae/analytics/test/BaseAnalyticsTest.java b/dcae-analytics/dcae-analytics-test/src/main/java/org/onap/dcae/analytics/test/BaseAnalyticsTest.java index 43cc377..8b2958e 100644 --- a/dcae-analytics/dcae-analytics-test/src/main/java/org/onap/dcae/analytics/test/BaseAnalyticsTest.java +++ b/dcae-analytics/dcae-analytics-test/src/main/java/org/onap/dcae/analytics/test/BaseAnalyticsTest.java @@ -395,7 +395,7 @@ abstract class BaseAnalyticsTest { * @throws NoSuchFieldException no such method exception */ @SuppressWarnings("unchecked") - protected static void setEnvironmentVariables(final Map<String, String> testEnvironmentVariables) + public static void setEnvironmentVariables(final Map<String, String> testEnvironmentVariables) throws ClassNotFoundException, IllegalAccessException, NoSuchFieldException { try { final Class<?> processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment"); 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); + } +} diff --git a/dcae-analytics/pom.xml b/dcae-analytics/pom.xml index 65a2541..fc48e7e 100644 --- a/dcae-analytics/pom.xml +++ b/dcae-analytics/pom.xml @@ -116,8 +116,10 @@ CONFIG PACKAGE - CONTAINS WIRINGS OF SPRING BEANS, EXCEPTIONS PACKAGE - CONTAINS CUSTOM EXCEPTIONS - NO BUSINESS LOGIC, PREFERENCES CLASSES - JUST POJOS + CONTEXTS CLASSES - JUST POJOS + ENTITY CLASSES - JUST POJOS --> - <sonar.coverage.exclusions>**/test/**,**/model/**,**/config/**,**/exception/**,**/*Preferences.java</sonar.coverage.exclusions> + <sonar.coverage.exclusions>**/test/**,**/model/**,**/config/**,**/exception/**,**/*Preferences.java,**/*Context*.java,**/*Entity.java</sonar.coverage.exclusions> </properties> |