LoggerService extends Service { @GET @Produces(APPLICATION_JSON) @ApiOperation( value = "Get loggers which are configured", notes = "This operation can be performed only by authorized user", response = LoggerDto.class, responseContainer = "List") @ApiResponses({ @ApiResponse(code = 200, message = "The loggers successfully fetched"), }) public List<LoggerDto> getLoggers( @ApiParam("The number of the items to skip") @DefaultValue("0") @QueryParam("skipCount") Integer skipCount, @ApiParam("The limit of the items in the response, default is 30") @DefaultValue("30") @QueryParam("maxItems") Integer maxItems) { LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); return loggerContext .getLoggerList() .stream() .filter(log -> log.getLevel() != null || log.iteratorForAppenders().hasNext()) .skip(skipCount) .limit(maxItems) .map(this::asDto) .collect(Collectors.toList()); }  @GET @Path("/{name}") @Produces(APPLICATION_JSON) @ApiOperation(value = "Get the logger level for the given logger") @ApiResponses({ @ApiResponse(code = 200, message = "The response contains requested logger entity"), @ApiResponse(code = 404, message = "The logger with specified name does not exist") }) LoggerDto getLoggerByName(@ApiParam(value = "logger name") @PathParam("name") String name); @GET @Produces(APPLICATION_JSON) @ApiOperation( value = "Get loggers which are configured", notes = "This operation can be performed only by authorized user", response = LoggerDto.class, responseContainer = "List") @ApiResponses({ @ApiResponse(code = 200, message = "The loggers successfully fetched"), }) List<LoggerDto> getLoggers(
      @ApiParam("The number of the items to skip") @DefaultValue("0") @QueryParam("skipCount")
          Integer skipCount,
      @ApiParam("The limit of the items in the response, default is 30")
          @DefaultValue("30")
          @QueryParam("maxItems")
          Integer maxItems); @PUT @Path("/{name}") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Update the logger level") @ApiResponses({ @ApiResponse(code = 200, message = "The logger successfully updated"), }) LoggerDto updateLogger(
      @ApiParam(value = "logger name") @PathParam("name") String name, LoggerDto update); @POST @Path("/{name}") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Create a new logger level") @ApiResponses({ @ApiResponse(code = 200, message = "The logger successfully created"), }) LoggerDto createLogger(
      @ApiParam(value = "logger name") @PathParam("name") String name, LoggerDto createdLogger);  }
@Test public void shouldCreateLogger() throws Exception { LoggerDto toCreateLoggerDto = newDto(LoggerDto.class).withName(LOGGER_NAME).withLevel("INFO"); final Response response = given() .auth() .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD) .contentType("application/json") .body(toCreateLoggerDto) .when() .post(SECURE_PATH + "/logger/" + LOGGER_NAME); assertEquals(response.getStatusCode(), 200); List<LoggerDto> loggers = this.loggerService.getLoggers(0, 30); assertTrue(loggers.contains(toCreateLoggerDto)); }
@Test(dependsOnMethods = "shouldCreateLogger") public void shouldUpdateLogger() throws Exception { LoggerDto toUpdateLoggerDto = newDto(LoggerDto.class).withName(LOGGER_NAME).withLevel("DEBUG"); final Response response = given() .auth() .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD) .contentType("application/json") .body(toUpdateLoggerDto) .when() .put(SECURE_PATH + "/logger/" + LOGGER_NAME); assertEquals(response.getStatusCode(), 200); List<LoggerDto> loggers = this.loggerService.getLoggers(0, 30); assertTrue(loggers.contains(toUpdateLoggerDto)); }