@Test public void createRuleTest() throws Exception { byte[] ruleDetailsContent = toJson(getCreateUpdateRuleDetailsRequest()); MultipartFile firstFile = getMockMultipartFile(); when(ruleService.createRule(any(), any(), any())).thenReturn(AdminConstants.RULE_CREATION_SUCCESS); mockMvc.perform(MockMvcRequestBuilders.fileUpload("/rule/create").file("file", firstFile.getBytes()) .principal(principal).content(ruleDetailsContent).contentType(MediaType.MULTIPART_FORM_DATA_VALUE)) .andExpect(status().isOk()).andExpect(jsonPath("$.message", is("success"))) .andExpect(jsonPath("$.data", is(AdminConstants.RULE_CREATION_SUCCESS))); }
@ApiOperation(httpMethod = "POST", value = "API to create new rule", response = Response.class, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @RequestMapping(path = "/create", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public ResponseEntity<Object> createRule(@AuthenticationPrincipal Principal user, @ApiParam(value = "provide valid rule details", required = false) @RequestParam(defaultValue="", value = "file", required = false) MultipartFile fileToUpload, CreateUpdateRuleDetails createRuleDetails) { try { return ResponseUtils.buildSucessResponse(ruleService.createRule(fileToUpload, createRuleDetails, user.getName())); } catch (Exception exception) { log.error(UNEXPECTED_ERROR_OCCURRED, exception); return ResponseUtils.buildFailureResponse(new Exception(UNEXPECTED_ERROR_OCCURRED), exception.getMessage()); } }
RuleController { @ApiOperation(httpMethod = "POST", value = "API to create new rule", response = Response.class, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @RequestMapping(path = "/create", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public ResponseEntity<Object> createRule(@AuthenticationPrincipal Principal user, @ApiParam(value = "provide valid rule details", required = false) @RequestParam(defaultValue="", value = "file", required = false) MultipartFile fileToUpload, CreateUpdateRuleDetails createRuleDetails) { try { return ResponseUtils.buildSucessResponse(ruleService.createRule(fileToUpload, createRuleDetails, user.getName())); } catch (Exception exception) { log.error(UNEXPECTED_ERROR_OCCURRED, exception); return ResponseUtils.buildFailureResponse(new Exception(UNEXPECTED_ERROR_OCCURRED), exception.getMessage()); } } }
RuleController { @ApiOperation(httpMethod = "POST", value = "API to create new rule", response = Response.class, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @RequestMapping(path = "/create", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public ResponseEntity<Object> createRule(@AuthenticationPrincipal Principal user, @ApiParam(value = "provide valid rule details", required = false) @RequestParam(defaultValue="", value = "file", required = false) MultipartFile fileToUpload, CreateUpdateRuleDetails createRuleDetails) { try { return ResponseUtils.buildSucessResponse(ruleService.createRule(fileToUpload, createRuleDetails, user.getName())); } catch (Exception exception) { log.error(UNEXPECTED_ERROR_OCCURRED, exception); return ResponseUtils.buildFailureResponse(new Exception(UNEXPECTED_ERROR_OCCURRED), exception.getMessage()); } }  }
RuleController { @ApiOperation(httpMethod = "POST", value = "API to create new rule", response = Response.class, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @RequestMapping(path = "/create", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public ResponseEntity<Object> createRule(@AuthenticationPrincipal Principal user, @ApiParam(value = "provide valid rule details", required = false) @RequestParam(defaultValue="", value = "file", required = false) MultipartFile fileToUpload, CreateUpdateRuleDetails createRuleDetails) { try { return ResponseUtils.buildSucessResponse(ruleService.createRule(fileToUpload, createRuleDetails, user.getName())); } catch (Exception exception) { log.error(UNEXPECTED_ERROR_OCCURRED, exception); return ResponseUtils.buildFailureResponse(new Exception(UNEXPECTED_ERROR_OCCURRED), exception.getMessage()); } }  @ApiOperation(httpMethod = "GET", value = "API to get all rules", response = Page.class, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> getRules(
			@ApiParam(value = "provide valid page number", required = true) @RequestParam("page") Integer page,
			@ApiParam(value = "provide valid page size", required = true) @RequestParam("size") Integer size,
			@ApiParam(value = "provide valid search term", required = false) @RequestParam(defaultValue="", name = "searchTerm", required = false) String searchTerm); @ApiOperation(httpMethod = "GET", value = "API to get rule by id", response = Response.class, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/details-by-id", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> getRulesById(
			@ApiParam(value = "provide valid rule id", required = true) @RequestParam(defaultValue = "", name = "ruleId", required = true) String ruleId); @ApiOperation(httpMethod = "GET", value = "API to get alexa keywords", response = Response.class, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/alexa-keywords", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> getAllAlexaKeywords(); @ApiOperation(httpMethod = "GET", value = "API to get all Rule Id's", response = Response.class, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/rule-ids", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> getAllRuleIds(); @ApiOperation(httpMethod = "POST", value = "API to create new rule", response = Response.class, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @RequestMapping(path = "/create", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) ResponseEntity<Object> createRule(@AuthenticationPrincipal Principal user,
			@ApiParam(value = "provide valid rule details", required = false) @RequestParam(defaultValue="", value = "file", required = false) MultipartFile fileToUpload, CreateUpdateRuleDetails createRuleDetails); @ApiOperation(httpMethod = "POST", value = "API to update new rule", response = Response.class, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @RequestMapping(path = "/update", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) ResponseEntity<Object> updateRule(@AuthenticationPrincipal Principal user,
			@ApiParam(value = "provide valid rule details", required = false) @RequestParam(value = "file", required = false) MultipartFile fileToUpload, CreateUpdateRuleDetails updateRuleDetails); @ApiOperation(httpMethod = "POST", value = "API to invoke rule", response = Response.class, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/invoke", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> invokeRule(
			@ApiParam(value = "provide valid rule id", required = true) @RequestParam("ruleId") String ruleId,
			@ApiParam(value = "provide rule optional params", required = false) @RequestBody(required = false) List<Map<String, Object>> ruleOptionalParams); @ApiOperation(httpMethod = "POST", value = "API to enable disable rule", response = Response.class, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/enable-disable", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> enableDisableRule(@AuthenticationPrincipal Principal user,
			@ApiParam(value = "provide valid rule id", required = true) @RequestParam("ruleId") String ruleId,
			@ApiParam(value = "provide valid action", required = true) @RequestParam("action") String action); @ApiOperation(httpMethod = "GET", value = "API to get all Rule Category's", response = Response.class, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/categories", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> getAllRuleCategory(); }
RuleController { @ApiOperation(httpMethod = "POST", value = "API to create new rule", response = Response.class, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @RequestMapping(path = "/create", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public ResponseEntity<Object> createRule(@AuthenticationPrincipal Principal user, @ApiParam(value = "provide valid rule details", required = false) @RequestParam(defaultValue="", value = "file", required = false) MultipartFile fileToUpload, CreateUpdateRuleDetails createRuleDetails) { try { return ResponseUtils.buildSucessResponse(ruleService.createRule(fileToUpload, createRuleDetails, user.getName())); } catch (Exception exception) { log.error(UNEXPECTED_ERROR_OCCURRED, exception); return ResponseUtils.buildFailureResponse(new Exception(UNEXPECTED_ERROR_OCCURRED), exception.getMessage()); } }  @ApiOperation(httpMethod = "GET", value = "API to get all rules", response = Page.class, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> getRules(
			@ApiParam(value = "provide valid page number", required = true) @RequestParam("page") Integer page,
			@ApiParam(value = "provide valid page size", required = true) @RequestParam("size") Integer size,
			@ApiParam(value = "provide valid search term", required = false) @RequestParam(defaultValue="", name = "searchTerm", required = false) String searchTerm); @ApiOperation(httpMethod = "GET", value = "API to get rule by id", response = Response.class, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/details-by-id", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> getRulesById(
			@ApiParam(value = "provide valid rule id", required = true) @RequestParam(defaultValue = "", name = "ruleId", required = true) String ruleId); @ApiOperation(httpMethod = "GET", value = "API to get alexa keywords", response = Response.class, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/alexa-keywords", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> getAllAlexaKeywords(); @ApiOperation(httpMethod = "GET", value = "API to get all Rule Id's", response = Response.class, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/rule-ids", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> getAllRuleIds(); @ApiOperation(httpMethod = "POST", value = "API to create new rule", response = Response.class, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @RequestMapping(path = "/create", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) ResponseEntity<Object> createRule(@AuthenticationPrincipal Principal user,
			@ApiParam(value = "provide valid rule details", required = false) @RequestParam(defaultValue="", value = "file", required = false) MultipartFile fileToUpload, CreateUpdateRuleDetails createRuleDetails); @ApiOperation(httpMethod = "POST", value = "API to update new rule", response = Response.class, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @RequestMapping(path = "/update", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) ResponseEntity<Object> updateRule(@AuthenticationPrincipal Principal user,
			@ApiParam(value = "provide valid rule details", required = false) @RequestParam(value = "file", required = false) MultipartFile fileToUpload, CreateUpdateRuleDetails updateRuleDetails); @ApiOperation(httpMethod = "POST", value = "API to invoke rule", response = Response.class, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/invoke", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> invokeRule(
			@ApiParam(value = "provide valid rule id", required = true) @RequestParam("ruleId") String ruleId,
			@ApiParam(value = "provide rule optional params", required = false) @RequestBody(required = false) List<Map<String, Object>> ruleOptionalParams); @ApiOperation(httpMethod = "POST", value = "API to enable disable rule", response = Response.class, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/enable-disable", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> enableDisableRule(@AuthenticationPrincipal Principal user,
			@ApiParam(value = "provide valid rule id", required = true) @RequestParam("ruleId") String ruleId,
			@ApiParam(value = "provide valid action", required = true) @RequestParam("action") String action); @ApiOperation(httpMethod = "GET", value = "API to get all Rule Category's", response = Response.class, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/categories", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> getAllRuleCategory();  }