Search in sources :

Example 76 with ContainerRequestContext

use of javax.ws.rs.container.ContainerRequestContext in project graylog2-server by Graylog2.

the class MessageExportFormatFilterTest method returns415IfNoFormatIsPresent.

@Test
void returns415IfNoFormatIsPresent() throws Exception {
    final ContainerRequestFilter filter = new MessageExportFormatFilter(Collections.emptySet());
    final ContainerRequestContext requestContext = mockRequestContext();
    filter.filter(requestContext);
    verifyRequestAborted(requestContext);
}
Also used : ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) ContainerRequestFilter(javax.ws.rs.container.ContainerRequestFilter) Test(org.junit.jupiter.api.Test)

Example 77 with ContainerRequestContext

use of javax.ws.rs.container.ContainerRequestContext in project graylog2-server by Graylog2.

the class MessageExportFormatFilterTest method returns415IfNoAcceptedFormatIsSpecified.

@Test
void returns415IfNoAcceptedFormatIsSpecified() throws Exception {
    final ContainerRequestFilter filter = new MessageExportFormatFilter(Collections.singleton(() -> MoreMediaTypes.TEXT_PLAIN_TYPE));
    final ContainerRequestContext requestContext = mockRequestContext(Collections.emptyList());
    filter.filter(requestContext);
    verifyRequestAborted(requestContext);
}
Also used : ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) ContainerRequestFilter(javax.ws.rs.container.ContainerRequestFilter) Test(org.junit.jupiter.api.Test)

Example 78 with ContainerRequestContext

use of javax.ws.rs.container.ContainerRequestContext 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 79 with ContainerRequestContext

use of javax.ws.rs.container.ContainerRequestContext 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)

Example 80 with ContainerRequestContext

use of javax.ws.rs.container.ContainerRequestContext in project graylog2-server by Graylog2.

the class MessageExportFormatFilterTest method returns415IfNoCompatibleFormatIsFound.

@Test
void returns415IfNoCompatibleFormatIsFound() throws Exception {
    final ContainerRequestFilter filter = new MessageExportFormatFilter(Collections.singleton(() -> MoreMediaTypes.TEXT_PLAIN_TYPE));
    final ContainerRequestContext requestContext = mockRequestContext(Collections.singletonList(MoreMediaTypes.APPLICATION_JSON_TYPE));
    filter.filter(requestContext);
    verifyRequestAborted(requestContext);
}
Also used : ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) ContainerRequestFilter(javax.ws.rs.container.ContainerRequestFilter) Test(org.junit.jupiter.api.Test)

Aggregations

ContainerRequestContext (javax.ws.rs.container.ContainerRequestContext)81 Test (org.junit.Test)40 Response (javax.ws.rs.core.Response)32 UriInfo (javax.ws.rs.core.UriInfo)23 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)22 Test (org.junit.jupiter.api.Test)18 Resource (org.glassfish.jersey.server.model.Resource)15 ContainerRequestFilter (javax.ws.rs.container.ContainerRequestFilter)14 ApplicationHandler (org.glassfish.jersey.server.ApplicationHandler)12 ContainerRequest (org.glassfish.jersey.server.ContainerRequest)10 File (java.io.File)8 ContainerResponseContext (javax.ws.rs.container.ContainerResponseContext)8 ResourceInfo (javax.ws.rs.container.ResourceInfo)8 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)8 IOException (java.io.IOException)7 URI (java.net.URI)6 ContainerResponseFilter (javax.ws.rs.container.ContainerResponseFilter)6 FF4jAuthenticationFilter (org.ff4j.web.api.security.FF4jAuthenticationFilter)6 ContainerResponse (org.glassfish.jersey.server.ContainerResponse)6 ApiKeyValidatorFilter (org.ff4j.web.api.filter.ApiKeyValidatorFilter)5