RulesResource { @ApiOperation(notes = "Uploads the Rules Returns a copy of the uploaded rules.", value = "upload") @ApiResponses({ @ApiResponse(code = 400, message = "") }) @POST @Consumes({ MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN }) @Produces({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON }) public String upload(String rulesBuffer) { if (rulesBuffer == null || rulesBuffer.isEmpty()) { throw new WebApplicationException(Response.Status.BAD_REQUEST); } Rules rules = null; try { String decoded = new String(Base64.decodeBase64(rulesBuffer)); rules = new Rules(decoded); } catch (Throwable t) { log.error("Exception in rules upload", t); throw new BadRequestException( i18n.tr("Error decoding the rules. The text should be base 64 encoded")); } Rules oldRules = rulesCurator.getRules(); rulesCurator.update(rules); sink.emitRulesModified(oldRules, rules); jsProvider.compileRules(true); return rulesBuffer; } @Inject  RulesResource(RulesCurator rulesCurator,
        I18n i18n, EventSink sink, JsRunnerProvider jsProvider); @ApiOperation(notes = "Uploads the Rules Returns a copy of the uploaded rules.", value = "upload") @ApiResponses({ @ApiResponse(code = 400, message = "") }) @POST @Consumes({ MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN }) @Produces({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON }) String upload(String rulesBuffer); @ApiOperation(notes = "Retrieves the Rules", value = "get") @ApiResponses({ @ApiResponse(code = 503, message = "") }) @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN }) String get(); @ApiOperation(notes = "Removes the Rules Deletes any uploaded rules, uses bundled rules instead", value = "delete") @DELETE @Produces(MediaType.APPLICATION_JSON) void delete();  }
@Test public void testUpload() { String rulesBuffer = new String(Base64.encodeBase64String(( TestUtil.createRulesBlob(10000).getBytes()))); rulesResource.upload(rulesBuffer); Rules rules = rulesCurator.getRules(); String expected = "" + RulesCurator.RULES_API_VERSION + "." + 10000; assertEquals(expected, rules.getVersion()); }