Search in sources :

Example 1 with ExportFormat

use of org.graylog.plugins.views.search.export.ExportFormat in project graylog2-server by Graylog2.

the class MessageExportFormatFilterTest method filtersAcceptedMediaTypesToEnabledOnes.

@Test
void filtersAcceptedMediaTypesToEnabledOnes() throws Exception {
    final ExportFormat plainTextExportFormat = () -> MoreMediaTypes.TEXT_PLAIN_TYPE;
    final ContainerRequestFilter filter = new MessageExportFormatFilter(ImmutableSet.of(disabledJsonExportFormat, plainTextExportFormat));
    final ContainerRequestContext requestContext = mockRequestContext(ImmutableList.of(MoreMediaTypes.TEXT_CSV_TYPE, MoreMediaTypes.TEXT_PLAIN_TYPE, MoreMediaTypes.APPLICATION_JSON_TYPE));
    filter.filter(requestContext);
    verifyRequestNotAborted(requestContext);
    assertThat(requestContext.getHeaders().get(HttpHeaders.ACCEPT)).containsExactly(MoreMediaTypes.TEXT_PLAIN);
}
Also used : ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) ContainerRequestFilter(javax.ws.rs.container.ContainerRequestFilter) ExportFormat(org.graylog.plugins.views.search.export.ExportFormat) Test(org.junit.jupiter.api.Test)

Example 2 with ExportFormat

use of org.graylog.plugins.views.search.export.ExportFormat in project graylog2-server by Graylog2.

the class MessageExportFormatFilterTest method filtersAcceptedMediaTypesToExistingOnes.

@Test
void filtersAcceptedMediaTypesToExistingOnes() throws Exception {
    final ExportFormat jsonExportFormat = () -> MoreMediaTypes.APPLICATION_JSON_TYPE;
    final ExportFormat plainTextExportFormat = () -> MoreMediaTypes.TEXT_PLAIN_TYPE;
    final ContainerRequestFilter filter = new MessageExportFormatFilter(ImmutableSet.of(jsonExportFormat, plainTextExportFormat));
    final ContainerRequestContext requestContext = mockRequestContext(ImmutableList.of(MoreMediaTypes.TEXT_CSV_TYPE, MoreMediaTypes.TEXT_PLAIN_TYPE, MoreMediaTypes.APPLICATION_JSON_TYPE));
    filter.filter(requestContext);
    verifyRequestNotAborted(requestContext);
    assertThat(requestContext.getHeaders().get(HttpHeaders.ACCEPT)).containsExactly(MoreMediaTypes.APPLICATION_JSON, MoreMediaTypes.TEXT_PLAIN);
}
Also used : ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) ContainerRequestFilter(javax.ws.rs.container.ContainerRequestFilter) ExportFormat(org.graylog.plugins.views.search.export.ExportFormat) Test(org.junit.jupiter.api.Test)

Aggregations

ContainerRequestContext (javax.ws.rs.container.ContainerRequestContext)2 ContainerRequestFilter (javax.ws.rs.container.ContainerRequestFilter)2 ExportFormat (org.graylog.plugins.views.search.export.ExportFormat)2 Test (org.junit.jupiter.api.Test)2