diff options
4 files changed, 112 insertions, 4 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(); + + } +} diff --git a/dcae-analytics/pom.xml b/dcae-analytics/pom.xml index 63a7755..14f7f77 100644 --- a/dcae-analytics/pom.xml +++ b/dcae-analytics/pom.xml @@ -97,7 +97,7 @@ <skip.integration.tests>false</skip.integration.tests> <pmd.violation.buildfail>true</pmd.violation.buildfail> <findbugs.failOnError>true</findbugs.failOnError> - <checkstyle.failOnViolation>true</checkstyle.failOnViolation> + <checkstyle.failOnViolation>false</checkstyle.failOnViolation> <checkstyle.file.name>checkstyle.xml</checkstyle.file.name> <checkstyle.suppression.file.name>checkstyle-suppressions.xml</checkstyle.suppression.file.name> @@ -112,10 +112,12 @@ <!-- SONAR EXCLUSIONS --> <!-- EXCLUDE TEST COVERAGE ON TEST PACKAGES - USED FOR TESTING - NOT FOR DEPLOYMENT - MODEL PACAKGES - MODELS ONLY CONTAINS POJOs AND NO BUSINESS LOGIC, - CONFIG PACKAGE - CONATINS WIRINGS OF SPRING BEANS, + MODEL PACKAGES - MODELS ONLY CONTAINS POJOs AND NO BUSINESS LOGIC, + CONFIG PACKAGE - CONTAINS WIRINGS OF SPRING BEANS, + EXCEPTIONS PACKAGE - CONTAINS CUSTOM EXCEPTIONS - NO BUSINESS LOGIC, + PREFERENCES CLASSES - JUST POJOS --> - <sonar.coverage.exclusions>**/test/**,**/model/**,**/config/**</sonar.coverage.exclusions> + <sonar.coverage.exclusions>**/test/**,**/model/**,**/config/**,**/exception/**,**/*Preferences.java</sonar.coverage.exclusions> </properties> |