summaryrefslogtreecommitdiffstats
path: root/dcae-analytics/dcae-analytics-web/src
diff options
context:
space:
mode:
authorSingla, Rajiv (rs153v) <rs153v@att.com>2018-09-18 17:04:12 -0400
committerVENKATESH KUMAR <vv770d@att.com>2018-09-19 17:38:25 -0400
commiteb2c72bc742f4e430a09da5cba297c4512a9d453 (patch)
tree8181426e3c48ce74dca88e057d7946e432479f5d /dcae-analytics/dcae-analytics-web/src
parenta1da81f6798dded45047e95f7a29ee6d98e8f9eb (diff)
Increased code coverage
Issue-ID: DCAEGEN2-797 Change-Id: I082ab0126b9284de941f0affff13504896459f60 Signed-off-by: Singla, Rajiv (rs153v) <rs153v@att.com> Signed-off-by: VENKATESH KUMAR <vv770d@att.com>
Diffstat (limited to 'dcae-analytics/dcae-analytics-web/src')
-rw-r--r--dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/dmaap/MrMessageSplitterTest.java43
-rw-r--r--dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/http/EelfAuditLogInterceptorTest.java35
-rw-r--r--dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/http/HttpClientPreferencesCustomizerTest.java28
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();
+
+ }
+}