diff options
Diffstat (limited to 'dcae-analytics/dcae-analytics-web')
13 files changed, 695 insertions, 56 deletions
diff --git a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/config/AnalyticsWebTestConfig.java b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/config/AnalyticsWebTestConfig.java index b80be2c..b9a06a8 100644 --- a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/config/AnalyticsWebTestConfig.java +++ b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/config/AnalyticsWebTestConfig.java @@ -1,6 +1,7 @@ /* - * ================================================================================ + * ============LICENSE_START======================================================= * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2022 Huawei. 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. @@ -19,25 +20,15 @@ package org.onap.dcae.analytics.web.config; -import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; -import org.onap.dcae.analytics.model.util.json.AnalyticsModelJsonConversion; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; +import static org.junit.jupiter.api.Assertions.assertNotNull; -/** - * @author Rajiv Singla - */ -@Configuration -@EnableAutoConfiguration -@Import(value = {AnalyticsWebConfig.class, DmaapMrTestConfig.class}) public class AnalyticsWebTestConfig { - @Bean - public ObjectMapper objectMapper() { - return AnalyticsModelJsonConversion.ANALYTICS_MODEL_OBJECT_MAPPER; + @Test + public void AnalyticsWebTestConfigTest () throws Exception { + AnalyticsWebConfig analyticsWebConfig = new AnalyticsWebConfig(); + assertNotNull(analyticsWebConfig); } - } diff --git a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/config/DmaapMrTestConfig.java b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/config/DmaapMrTestConfig.java index 9e884ea..deb8642 100644 --- a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/config/DmaapMrTestConfig.java +++ b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/config/DmaapMrTestConfig.java @@ -1,6 +1,7 @@ /* - * ================================================================================ + * ============LICENSE_START======================================================= * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2022 Huawei. 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. @@ -19,55 +20,116 @@ package org.onap.dcae.analytics.web.config; -import org.onap.dcae.analytics.model.AnalyticsProfile; -import org.onap.dcae.analytics.web.BaseAnalyticsWebSpringBootIT; -import org.onap.dcae.analytics.web.dmaap.MrPublisherPreferences; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.onap.dcae.analytics.web.dmaap.MrSubscriberPollingPreferences; import org.onap.dcae.analytics.web.dmaap.MrSubscriberPreferences; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; +import org.onap.dcae.analytics.web.dmaap.MrTriggerMessageProvider; +import org.onap.dcae.analytics.web.dmaap.MrSubscriberPollingAdvice; +import org.onap.dcae.analytics.web.dmaap.MrMessageSplitter; +import org.onap.dcae.analytics.web.dmaap.MrPublisherPreferences; +import org.springframework.http.HttpHeaders; import org.springframework.integration.channel.DirectChannel; import org.springframework.integration.channel.QueueChannel; +import org.springframework.integration.core.MessageSource; import org.springframework.integration.dsl.IntegrationFlow; -import org.springframework.integration.dsl.IntegrationFlows; -import org.springframework.integration.handler.LoggingHandler; +import org.springframework.integration.handler.advice.RequestHandlerRetryAdvice; +import org.springframework.integration.scheduling.PollerMetadata; +import org.springframework.integration.store.BasicMessageGroupStore; +import org.springframework.web.client.RestTemplate; + +import java.net.URL; +import java.util.Arrays; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; -/** - * @author Rajiv Singla - */ -@Configuration -@Profile({AnalyticsProfile.DMAAP_PROFILE_NAME}) public class DmaapMrTestConfig { - @Bean - public MrSubscriberPreferences mrSubscriberPreferences() { - return new MrSubscriberPreferences(BaseAnalyticsWebSpringBootIT.TEST_SUBSCRIBER_TOPIC_URL, null, - null, BaseAnalyticsWebSpringBootIT.TEST_SUBSCRIBER_AAF_USERNAME, - BaseAnalyticsWebSpringBootIT.TEST_SUBSCRIBER_AAF_PASSWORD, - null, null, null, - BaseAnalyticsWebSpringBootIT.TEST_SUBSCRIBER_CONSUMER_GROUP, - BaseAnalyticsWebSpringBootIT.TEST_SUBSCRIBER_CONSUMER_IDS, - null, null, null); + @Test + public void mrPublisherInputChannelTest () throws Exception { + DmaapMrConfig dmaapMrConfig = new DmaapMrConfig(); + DirectChannel directChannel = dmaapMrConfig.mrPublisherInputChannel(); + assertNotNull(directChannel); } - @Bean - public MrPublisherPreferences mrPublisherPreferences() { - return new MrPublisherPreferences(BaseAnalyticsWebSpringBootIT.TEST_PUBLISHER_TOPIC_URL); + @Test + public void mrTriggerMessageProviderTest () throws Exception { + URL proxyURL = new URL("http://localhost"); + MrSubscriberPollingPreferences pollingPreferences = Mockito.mock(MrSubscriberPollingPreferences.class); + HttpHeaders headers = Mockito.mock(HttpHeaders.class); + MrSubscriberPreferences subscriberPreferences = + new MrSubscriberPreferences("http://localhost:8080", + "TestClientId", headers, + "TestUserName", "TestPassword", + proxyURL, true, false, "TestGroup", + Arrays.asList("TestId1"), + new Integer(4), new Integer(3), pollingPreferences); + DmaapMrConfig dmaapMrConfig = new DmaapMrConfig(); + MrTriggerMessageProvider mrTriggerMessageProvider = dmaapMrConfig.mrTriggerMessageProvider(subscriberPreferences); + assertEquals("getTriggerMessage", mrTriggerMessageProvider.TRIGGER_METHOD_NAME); + assertEquals("http://localhost:8080/TestGroup/TestId1?limit=4&timeout=3", + mrTriggerMessageProvider.getTriggerMessage().getPayload()); } - @Bean - public Integer processingBatchSize() { - return 1; + @Test + public void mrMessageSourceTest () throws Exception { + URL proxyURL = new URL("http://localhost"); + MrSubscriberPollingPreferences pollingPreferences = Mockito.mock(MrSubscriberPollingPreferences.class); + HttpHeaders headers = Mockito.mock(HttpHeaders.class); + MrSubscriberPreferences subscriberPreferences = + new MrSubscriberPreferences("http://localhost:8080", + "TestClientId", headers, + "TestUserName", "TestPassword", + proxyURL, true, false, "TestGroup", + Arrays.asList("TestId1", "TestId2"), + new Integer(4), new Integer(3), pollingPreferences); + DmaapMrConfig dmaapMrConfig = new DmaapMrConfig(); + MrTriggerMessageProvider mrTriggerMessageProvider = dmaapMrConfig.mrTriggerMessageProvider(subscriberPreferences); + MessageSource messageSource = dmaapMrConfig.mrMessageSource(mrTriggerMessageProvider); + assertEquals("inbound_channel_adapter", messageSource.getIntegrationPatternType().name()); } + @Test + public void mrSubscriberOutputChannelTest () throws Exception { + BasicMessageGroupStore basicMessageGroupStore = Mockito.mock(BasicMessageGroupStore.class); + DmaapMrConfig dmaapMrConfig = new DmaapMrConfig(); + QueueChannel queueChannel = dmaapMrConfig.mrSubscriberOutputChannel(basicMessageGroupStore); + assertTrue(queueChannel.getRemainingCapacity() > 0); + } - @Bean - public IntegrationFlow noOperationMrFlow(final QueueChannel mrSubscriberOutputChannel, - final DirectChannel mrPublisherInputChannel) { - return IntegrationFlows.from(mrSubscriberOutputChannel) - .log(LoggingHandler.Level.INFO) - .channel(mrPublisherInputChannel) - .get(); + @Test + public void mrSubscriberFlowTest () throws Exception { + PollerMetadata pollerMetadata = Mockito.mock(PollerMetadata.class); + QueueChannel queueChannel = Mockito.mock(QueueChannel.class); + RestTemplate restTemplate = Mockito.mock(RestTemplate.class); + MessageSource messageSource = Mockito.mock(MessageSource.class); + MrMessageSplitter mrMessageSplitter = Mockito.mock(MrMessageSplitter.class); + MrSubscriberPollingAdvice mrSubscriberPollingAdvice = Mockito.mock(MrSubscriberPollingAdvice.class); + DmaapMrConfig dmaapMrConfig = new DmaapMrConfig(); + IntegrationFlow integratedFlow = dmaapMrConfig.mrSubscriberFlow(pollerMetadata,restTemplate,messageSource,queueChannel, mrMessageSplitter, mrSubscriberPollingAdvice); + assertNotNull(integratedFlow.getInputChannel()); } + @Test + public void mrPublisherFlowTest () throws Exception { + RequestHandlerRetryAdvice requestHandlerRetryAdvice = Mockito.mock(RequestHandlerRetryAdvice.class); + DirectChannel directChannel = Mockito.mock(DirectChannel.class); + RestTemplate restTemplate = Mockito.mock(RestTemplate.class); + MrPublisherPreferences mrPublisherPreferences = Mockito.mock(MrPublisherPreferences.class); + DmaapMrConfig dmaapMrConfig = new DmaapMrConfig(); + IntegrationFlow integratedFlow = dmaapMrConfig.mrPublisherFlow(mrPublisherPreferences,restTemplate,directChannel,requestHandlerRetryAdvice); + assertNotNull(integratedFlow.getInputChannel()); + } + + @Test + public void mrMessageSplitterTest () throws Exception { + ObjectMapper objectMapper = new ObjectMapper(); + int processingBatchSize = 100; + DmaapMrConfig dmaapMrConfig = new DmaapMrConfig(); + MrMessageSplitter mrMessageSplitter = dmaapMrConfig.mrMessageSplitter(objectMapper, processingBatchSize); + assertNotNull(mrMessageSplitter); + } } diff --git a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/config/DmaapPollerTestConfig.java b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/config/DmaapPollerTestConfig.java new file mode 100644 index 0000000..d7bebb8 --- /dev/null +++ b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/config/DmaapPollerTestConfig.java @@ -0,0 +1,92 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (c) 2022 Huawei. 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.config; + +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.onap.dcae.analytics.web.dmaap.MrSubscriberPollingAdvice; +import org.onap.dcae.analytics.web.dmaap.MrSubscriberPollingPreferences; +import org.onap.dcae.analytics.web.dmaap.MrSubscriberPreferences; +import org.springframework.http.HttpHeaders; +import org.springframework.integration.scheduling.PollerMetadata; +import org.springframework.integration.util.DynamicPeriodicTrigger; + +import java.net.URL; +import java.util.Arrays; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class DmaapPollerTestConfig { + + @Test + public void mrSubscriberPollingAdviceTest () throws Exception { + URL proxyURL = new URL("http://localhost"); + MrSubscriberPollingPreferences pollingPreferences = Mockito.mock(MrSubscriberPollingPreferences.class); + + HttpHeaders headers = Mockito.mock(HttpHeaders.class); + MrSubscriberPreferences subscriberPreferences = + new MrSubscriberPreferences("http://localhost:8080", + "TestClientId", headers, + "TestUserName", "TestPassword", + proxyURL, true, false, "TestGroup", + Arrays.asList("TestId1", "TestId2"), + new Integer(4), new Integer(3), pollingPreferences); + + DmaapPollerConfig dmaapPollerConfig = new DmaapPollerConfig(); + DynamicPeriodicTrigger dynamicPeriodicTrigger = new DynamicPeriodicTrigger(1L); + MrSubscriberPollingAdvice mrSubscriberPollingAdvice = dmaapPollerConfig.mrSubscriberPollingAdvice( + dynamicPeriodicTrigger, subscriberPreferences); + assertNotNull(mrSubscriberPollingAdvice); + } + + @Test + public void dynamicPeriodicTriggerTest () throws Exception { + URL proxyURL = new URL("http://localhost"); + MrSubscriberPollingPreferences pollingPreferences = Mockito.mock(MrSubscriberPollingPreferences.class); + HttpHeaders headers = Mockito.mock(HttpHeaders.class); + MrSubscriberPreferences subscriberPreferences = + new MrSubscriberPreferences("http://localhost:8080", + "TestClientId", headers, + "TestUserName", "TestPassword", + proxyURL, true, false, "TestGroup", + Arrays.asList("TestId1", "TestId2"), + new Integer(4), new Integer(3), pollingPreferences); + + DmaapPollerConfig dmaapPollerConfig = new DmaapPollerConfig(); + DynamicPeriodicTrigger dynamicPeriodicTrigger = dmaapPollerConfig.dynamicPeriodicTrigger(subscriberPreferences); + assertTrue(dynamicPeriodicTrigger.isFixedRate()); + } + + @Test + public void pollerMetadataTest () throws Exception { + DmaapPollerConfig dmaapPollerConfig = new DmaapPollerConfig(); + DynamicPeriodicTrigger dynamicPeriodicTrigger = new DynamicPeriodicTrigger(60000); + PollerMetadata pollerMetadata = dmaapPollerConfig.pollerMetadata(dynamicPeriodicTrigger); + assertNotNull(pollerMetadata); + } + + @Test + public void defaultPollerTest () throws Exception { + DmaapPollerConfig dmaapPollerConfig = new DmaapPollerConfig(); + PollerMetadata pollerMetadata = dmaapPollerConfig.defaultPoller(); + assertNotNull(pollerMetadata); + } +} diff --git a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/config/DmaapRetryTestConfig.java b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/config/DmaapRetryTestConfig.java new file mode 100644 index 0000000..322053c --- /dev/null +++ b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/config/DmaapRetryTestConfig.java @@ -0,0 +1,104 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (c) 2022 Huawei. 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.config; + +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.springframework.integration.channel.QueueChannel; +import org.springframework.integration.dsl.IntegrationFlow; +import org.springframework.integration.handler.advice.ErrorMessageSendingRecoverer; +import org.springframework.integration.handler.advice.RequestHandlerRetryAdvice; +import org.springframework.integration.store.BasicMessageGroupStore; +import org.springframework.messaging.PollableChannel; +import org.springframework.retry.RetryPolicy; +import org.springframework.retry.backoff.BackOffPolicy; +import org.springframework.retry.support.RetryTemplate; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class DmaapRetryTestConfig { + + @Test + public void errorChannelTest () throws Exception { + DmaapRetryConfig dmaapRetryConfig = new DmaapRetryConfig(); + QueueChannel queueChannel = dmaapRetryConfig.errorChannel(); + assertNotNull(queueChannel); + } + + @Test + public void errorMessageSendingRecovererTest () throws Exception { + PollableChannel pollableChannel = Mockito.mock(PollableChannel.class); + DmaapRetryConfig dmaapRetryConfig = new DmaapRetryConfig(); + ErrorMessageSendingRecoverer errorMessageSendingRecoverer = + dmaapRetryConfig.errorMessageSendingRecoverer(pollableChannel); + Throwable throwable = new Throwable("test"); + assertEquals("test", errorMessageSendingRecoverer.getErrorMessageStrategy() + .buildErrorMessage(throwable, null).getPayload().getMessage()); + } + + @Test + public void recoveryChannelTest () throws Exception { + BasicMessageGroupStore basicMessageGroupStore = Mockito.mock(BasicMessageGroupStore.class); + DmaapRetryConfig dmaapRetryConfig = new DmaapRetryConfig(); + PollableChannel pollableChannel = dmaapRetryConfig.recoveryChannel(basicMessageGroupStore); + assertNotNull(pollableChannel); + } + + @Test + public void requestHandlerRetryAdviceTest () throws Exception { + RetryTemplate retryTemplate = Mockito.mock(RetryTemplate.class); + ErrorMessageSendingRecoverer errorMessageSendingRecoverer = Mockito.mock(ErrorMessageSendingRecoverer.class); + DmaapRetryConfig dmaapRetryConfig = new DmaapRetryConfig(); + RequestHandlerRetryAdvice requestHandlerRetryAdvice = dmaapRetryConfig.requestHandlerRetryAdvice(retryTemplate, + errorMessageSendingRecoverer); + assertNotNull(requestHandlerRetryAdvice); + } + + @Test + public void retryTemplateTest () throws Exception { + RetryPolicy retryPolicy = Mockito.mock(RetryPolicy.class); + BackOffPolicy backOffPolicy = Mockito.mock(BackOffPolicy.class); + DmaapRetryConfig dmaapRetryConfig = new DmaapRetryConfig(); + RetryTemplate retryTemplate = dmaapRetryConfig.retryTemplate(retryPolicy, backOffPolicy); + assertNotNull(retryTemplate); + } + + @Test + public void retryPolicyTest () throws Exception { + DmaapRetryConfig dmaapRetryConfig = new DmaapRetryConfig(); + RetryPolicy retryPolicy = dmaapRetryConfig.retryPolicy(); + assertNotNull(retryPolicy); + } + + @Test + public void backoffPolicyTest () throws Exception { + DmaapRetryConfig dmaapRetryConfig = new DmaapRetryConfig(); + BackOffPolicy backOffPolicy = dmaapRetryConfig.backOffPolicy(); + assertNotNull(backOffPolicy); + } + + @Test + public void loggingFlowTest () throws Exception { + DmaapRetryConfig dmaapRetryConfig = new DmaapRetryConfig(); + IntegrationFlow integrationFlow = dmaapRetryConfig.loggingFlow(); + assertNotNull(integrationFlow); + } +} diff --git a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/config/MessageStoreTestConfig.java b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/config/MessageStoreTestConfig.java new file mode 100644 index 0000000..6510805 --- /dev/null +++ b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/config/MessageStoreTestConfig.java @@ -0,0 +1,44 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (c) 2022 Huawei. 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.config; + +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.springframework.data.mongodb.MongoDatabaseFactory; +import org.springframework.integration.store.BasicMessageGroupStore; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class MessageStoreTestConfig { + @Test + public void simpleMessageGroupStoreTest () { + MessageStoreConfig messageStoreConfig = new MessageStoreConfig(); + BasicMessageGroupStore basicMessageGroupStore = messageStoreConfig.simpleMessageGroupStore(); + assertNotNull(basicMessageGroupStore); + } + + @Test + public void mongoMessageGroupStoreTest () { + MessageStoreConfig messageStoreConfig = new MessageStoreConfig(); + MongoDatabaseFactory mongoDatabaseFactory = Mockito.mock(MongoDatabaseFactory.class); + BasicMessageGroupStore basicMessageGroupStore = messageStoreConfig.mongoMessageGroupStore(mongoDatabaseFactory); + assertNotNull(basicMessageGroupStore); + } +} diff --git a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/dmaap/MrPublisherPreferencesTest.java b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/dmaap/MrPublisherPreferencesTest.java new file mode 100644 index 0000000..8cd6a9b --- /dev/null +++ b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/dmaap/MrPublisherPreferencesTest.java @@ -0,0 +1,44 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (c) 2022 Huawei. 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.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.springframework.http.HttpHeaders; + +import java.net.URL; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class MrPublisherPreferencesTest { + + @Test + public void mrPublisherPreferencesTest () throws Exception { + URL url = new URL("http", "8088", "test"); + HttpHeaders headers = Mockito.mock(HttpHeaders.class); + MrPublisherPreferences mrPublisherPreferences = + new MrPublisherPreferences("http://localhost:8080", + "TestClientId", headers, + "TestUserName", "TestPassword", + url, false, false); + assertEquals("TestClientId", mrPublisherPreferences.getHttpClientId()); + + } +} diff --git a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/dmaap/MrSubscriberPollingAdviceTest.java b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/dmaap/MrSubscriberPollingAdviceTest.java new file mode 100644 index 0000000..d9a0cef --- /dev/null +++ b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/dmaap/MrSubscriberPollingAdviceTest.java @@ -0,0 +1,39 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (c) 2022 Huawei. 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.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice; +import org.springframework.integration.util.DynamicPeriodicTrigger; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class MrSubscriberPollingAdviceTest { + + @Test + public void mrSubscriberPollingAdviceTest () throws Exception { + DynamicPeriodicTrigger dynamicPeriodicTrigger = Mockito.mock(DynamicPeriodicTrigger.class); + MrSubscriberPollingAdvice mrSubscriberPollingAdvice = + new MrSubscriberPollingAdvice(dynamicPeriodicTrigger,30000, 0, + 30000, 0); + assertNotNull(mrSubscriberPollingAdvice); + } +} diff --git a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/dmaap/MrSubscriberPreferencesTest.java b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/dmaap/MrSubscriberPreferencesTest.java new file mode 100644 index 0000000..931f20c --- /dev/null +++ b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/dmaap/MrSubscriberPreferencesTest.java @@ -0,0 +1,67 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (c) 2022 Huawei. 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.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.springframework.http.HttpHeaders; + +import java.net.URL; +import java.util.Arrays; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class MrSubscriberPreferencesTest { + + @Test + public void mrSubscriberPollingPreferencesTest () throws Exception { + URL proxyURL = new URL("http://localhost"); + MrSubscriberPollingPreferences pollingPreferences = Mockito.mock(MrSubscriberPollingPreferences.class); + HttpHeaders headers = Mockito.mock(HttpHeaders.class); + MrSubscriberPreferences subscriberPreferences = + new MrSubscriberPreferences("http://localhost:8080", + "TestClientId", headers, + "TestUserName", "TestPassword", + proxyURL, true, false, "TestGroup", + Arrays.asList("TestId1", "TestId2"), + new Integer(4), new Integer(3), pollingPreferences); + + MrSubscriberPollingPreferences mrSubscriberPollingPreferences = subscriberPreferences.getPollingPreferences(); + assertNotNull(mrSubscriberPollingPreferences); + } + + @Test + public void mrSubscriberPollingPreferences1Test () throws Exception { + URL proxyURL = new URL("http://localhost"); + MrSubscriberPollingPreferences pollingPreferences = Mockito.mock(MrSubscriberPollingPreferences.class); + HttpHeaders headers = Mockito.mock(HttpHeaders.class); + MrSubscriberPreferences subscriberPreferences = + new MrSubscriberPreferences("http://localhost:8080", + "TestClientId", headers, + "TestUserName", "TestPassword", + proxyURL, true, false, "TestGroup", + Arrays.asList("TestId1", "TestId2"), + new Integer(4), new Integer(3), null); + + MrSubscriberPollingPreferences mrSubscriberPollingPreferences = subscriberPreferences.getPollingPreferences(); + assertNotNull(mrSubscriberPollingPreferences); + } +} diff --git a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/exception/AnalyticsValidationExceptionTest.java b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/exception/AnalyticsValidationExceptionTest.java new file mode 100644 index 0000000..f019d2a --- /dev/null +++ b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/exception/AnalyticsValidationExceptionTest.java @@ -0,0 +1,39 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (c) 2022 Huawei. 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.exception; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class AnalyticsValidationExceptionTest { + + @Test + public void AnalyticsValidationExceptionTst() throws Exception { + AnalyticsValidationException analyticsValidationException = new AnalyticsValidationException("Exception", + null); + assertEquals("Exception", analyticsValidationException.getMessage()); + } + + @Test + public void EnvironmentLoaderExceptionTst() throws Exception { + EnvironmentLoaderException environmentLoaderException = new EnvironmentLoaderException("Exception"); + assertEquals("Exception", environmentLoaderException.getMessage()); + } +} diff --git a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/util/AnalyticsHttpUtilsTest.java b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/util/AnalyticsHttpUtilsTest.java new file mode 100644 index 0000000..d20cd65 --- /dev/null +++ b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/util/AnalyticsHttpUtilsTest.java @@ -0,0 +1,78 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (c) 2022 Huawei. 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.util; + +import org.junit.jupiter.api.Test; +import org.springframework.http.HttpHeaders; +import org.springframework.messaging.MessageHeaders; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class AnalyticsHttpUtilsTest { + + @Test + public void createDefaultHttpHeadersTest () throws Exception { + HttpHeaders httpHeaders = AnalyticsHttpUtils.createDefaultHttpHeaders(); + httpHeaders.set("X-TransactionID", "transactionID"); + String transactionId = AnalyticsHttpUtils.getTransactionId(httpHeaders); + assertEquals("transactionID", transactionId); + } + + @Test + public void createDefaultHttpHeadersRequestIDTest () throws Exception { + HttpHeaders httpHeaders = AnalyticsHttpUtils.createDefaultHttpHeaders("requestID"); + String requestId = AnalyticsHttpUtils.getRequestId(httpHeaders); + assertEquals("requestID", requestId); + } + + @Test + public void createDefaultHttpHeadersTransactionIDTest () throws Exception { + HttpHeaders httpHeaders = AnalyticsHttpUtils.createDefaultHttpHeaders(); + httpHeaders.set("X-TransactionID", "transactionID"); + String requestId = AnalyticsHttpUtils.getTransactionId(httpHeaders); + assertEquals("transactionID", requestId); + } + + @Test + public void getTransactionIdTest () throws Exception { + MessageHeaders httpHeaders = new MessageHeaders(null); + String transactionId = AnalyticsHttpUtils.getTransactionId(httpHeaders); + assertEquals("UNKNOWN-TRANSACTION_ID", transactionId); + } + + @Test + public void getRequestIdTest () throws Exception { + MessageHeaders httpHeaders = new MessageHeaders(null); + String requestId = AnalyticsHttpUtils.getRequestId(httpHeaders); + assertEquals("UNKNOWN-REQUEST_ID", requestId); + } + + @Test + public void getTimestampFromHeadersTest () throws Exception { + Map<String, Object> headers = new HashMap<String, Object>(); + Date dt = AnalyticsHttpUtils.getTimestampFromHeaders(headers, null); + assertNotNull(dt); + } +} diff --git a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/util/AnalyticsWebUtilsTest.java b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/util/AnalyticsWebUtilsTest.java new file mode 100644 index 0000000..49f00b0 --- /dev/null +++ b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/util/AnalyticsWebUtilsTest.java @@ -0,0 +1,40 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (c) 2022 Huawei. 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.util; + +import org.junit.jupiter.api.Test; + +import java.util.function.Supplier; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class AnalyticsWebUtilsTest { + + @Test + public void AnalyticsWebUtilsTst () throws Exception { + Supplier<String> creationTimestampSupplier = AnalyticsWebUtils.CREATION_TIMESTAMP_SUPPLIER; + Supplier<String> randomIdSupplier = AnalyticsWebUtils.RANDOM_ID_SUPPLIER; + Supplier<String> requestIdSupplier = AnalyticsWebUtils.REQUEST_ID_SUPPLIER; + assertNotNull(creationTimestampSupplier); + assertNotNull(randomIdSupplier.toString()); + assertNotNull(requestIdSupplier); + } +} diff --git a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/util/ValidationUtilsTest.java b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/util/ValidationUtilsTest.java new file mode 100644 index 0000000..0cac996 --- /dev/null +++ b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/util/ValidationUtilsTest.java @@ -0,0 +1,38 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (c) 2022 Huawei. 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.util; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ValidationUtilsTest { + + @Test + public void isEmptyTest() throws Exception { + boolean isEmpty = ValidationUtils.isEmpty("Test"); + assertEquals(false, isEmpty); + } + + @Test + public void isPresentTest() throws Exception { + boolean isPresent = ValidationUtils.isPresent("Test"); + assertEquals(true, isPresent); + } +} diff --git a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/validation/GenericValidationResponseTest.java b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/validation/GenericValidationResponseTest.java index 1f790dd..4ec7062 100644 --- a/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/validation/GenericValidationResponseTest.java +++ b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/validation/GenericValidationResponseTest.java @@ -1,8 +1,8 @@ /* - * ================================================================================ + * ============LICENSE_START======================================================= * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ * Copyright Copyright (c) 2019 IBM + * Copyright (c) 2022 Huawei. 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. @@ -50,6 +50,7 @@ public class GenericValidationResponseTest { Assertions.assertEquals(map, genericValidationResponse.getValidationResultsAsMap()); Assertions.assertEquals(errorMsg, genericValidationResponse.getAllErrorMessage()); Assertions.assertEquals(errorMsg, genericValidationResponse.getAllErrorMessage("testMsg")); - + genericValidationResponse.addErrorMessage("test", "test message"); + Assertions.assertEquals("test message", genericValidationResponse.getAllErrorMessage("test")); } } |