diff options
Diffstat (limited to 'dcae-analytics/dcae-analytics-web/src/test')
3 files changed, 106 insertions, 0 deletions
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 new file mode 100644 index 0000000..5ec48ef --- /dev/null +++ b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/dmaap/MrMessageSplitterTest.java @@ -0,0 +1,43 @@ +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; + +class MrMessageSplitterTest extends BaseAnalyticsWebTest { + + @Test + @SuppressWarnings("unchecked") + void splitMessage() { + + final Map<String, Object> headers = new HashMap<>(); + headers.put(REQUEST_ID_HEADER_KEY, "testRequestId"); + final MessageHeaders messageHeaders = new MessageHeaders(headers); + + final Message<?> message = + MessageBuilder.createMessage(fromStream(TestFileLocation.CEF_JSON_MESSAGES), messageHeaders); + + final MrMessageSplitter mrMessageSplitter = new MrMessageSplitter(ANALYTICS_MODEL_OBJECT_MAPPER, 10); + final Object splitMessageStream = mrMessageSplitter.splitMessage(message); + + final List<String> messages = ((Stream<String>) splitMessageStream).collect(Collectors.toList()); + Assertions.assertThat(messages.size()).isEqualTo(4); + } +} 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 new file mode 100644 index 0000000..b46e9d3 --- /dev/null +++ b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/http/EelfAuditLogInterceptorTest.java @@ -0,0 +1,35 @@ +package org.onap.dcae.analytics.web.http; + +import org.junit.jupiter.api.Test; +import org.onap.dcae.analytics.web.BaseAnalyticsWebTest; +import org.onap.dcae.analytics.web.dmaap.MrSubscriberPreferences; +import org.springframework.http.HttpRequest; +import org.springframework.http.HttpStatus; +import org.springframework.http.client.ClientHttpRequestExecution; +import org.springframework.http.client.ClientHttpResponse; +import org.springframework.mock.http.client.MockClientHttpRequest; +import org.springframework.mock.http.client.MockClientHttpResponse; + +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.*; + +class EelfAuditLogInterceptorTest extends BaseAnalyticsWebTest { + + @Test + void intercept() throws Exception { + MrSubscriberPreferences mrSubscriberPreferences = new MrSubscriberPreferences("http://tst:123"); + mrSubscriberPreferences.enableEcompAuditLogging = true; + + final EelfAuditLogInterceptor eelfAuditLogInterceptor = new EelfAuditLogInterceptor(mrSubscriberPreferences); + + HttpRequest httpRequest = new MockClientHttpRequest(); + eelfAuditLogInterceptor.intercept(httpRequest, "test".getBytes(), new ClientHttpRequestExecution() { + @Override + public ClientHttpResponse execute(HttpRequest request, byte[] body) throws IOException { + return new MockClientHttpResponse("OK".getBytes(), HttpStatus.OK); + } + }); + + } +} 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 new file mode 100644 index 0000000..33ec457 --- /dev/null +++ b/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/http/HttpClientPreferencesCustomizerTest.java @@ -0,0 +1,28 @@ +package org.onap.dcae.analytics.web.http; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +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 + public void customize() { + + MrSubscriberPreferences mrSubscriberPreferences = new MrSubscriberPreferences("http://tst:123"); + mrSubscriberPreferences.enableEcompAuditLogging = false; + + HttpClientPreferencesCustomizer<MrSubscriberPreferences> subscriberPreferencesHttpClientPreferencesCustomizer + = new HttpClientPreferencesCustomizer<>(mrSubscriberPreferences); + + final RestTemplate restTemplate = new RestTemplate(); + subscriberPreferencesHttpClientPreferencesCustomizer.customize(restTemplate); + + Assertions.assertThat(restTemplate).isNotNull(); + + } +} |