@POST
    @Timed
    @Path("/test")
    @NoAuditEvent("Only used to test pattern.")
    @ApiOperation(value = "Test pattern with sample data")
    public Response testPattern(@ApiParam(name = "pattern", required = true) GrokPatternTestRequest request) {
        Map<String, Object> result;
        try {
            result = grokPatternService.match(request.grokPattern(), request.sampleData());
        } catch (GrokException | IllegalArgumentException e) {
            Map<String, String> error = ImmutableMap.of("message", e.getMessage());

            throw new BadRequestException(Response.status(Response.Status.BAD_REQUEST).entity(error).build());
        }
        return Response.ok(result).build();
    }
@Test
    public void testPatternWithSampleData() throws Exception {
        final String sampleData = "1.2.3.4";
        final GrokPattern grokPattern = GrokPattern.create("IP", "\\d.\\d.\\d.\\d");
        grokPatternService.save(grokPattern);
        final GrokPatternTestRequest grokPatternTestRequest = GrokPatternTestRequest.create(grokPattern, sampleData);
        final Map<String, Object> expectedReturn = Collections.singletonMap("IP", "1.2.3.4");

        final Response response = grokResource.testPattern(grokPatternTestRequest);
        assertThat(response.hasEntity()).isTrue();
        assertThat(response.getEntity()).isEqualTo(expectedReturn);
    }