@Test public void testShouldNotCreateActionIfNoActions() throws Exception { List<Action> actions = getActions(); when(actionService.createAction(any(ActionRequest.class))).thenReturn(actions); ResponseInfo responseInfo = ResponseInfo.builder().build(); when(responseInfoFactory.createResponseInfoFromRequestInfo(any(RequestInfo.class), any(Boolean.class))) .thenReturn(responseInfo); mockMvc.perform(post("/v1/actions/_create").contentType(MediaType.APPLICATION_JSON_UTF8) .content(new Resources().getFileContents("actionRequestWithoutActions.json"))) .andExpect(status().isBadRequest()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().json(new Resources().getFileContents("actionResponseWithoutActions.json"))); }
@PostMapping(value = "_create") public ResponseEntity<?> createAction(@RequestBody @Valid final ActionRequest actionRequest, final BindingResult errors) { if (errors.hasErrors()) { final ErrorResponse errRes = populateErrors(errors); return new ResponseEntity<>(errRes, HttpStatus.BAD_REQUEST); } logger.info("Create Action Type Request::" + actionRequest); final List<ErrorResponse> errorResponses = validateActionRequest(actionRequest, taskAction[0]); if (!errorResponses.isEmpty()) return new ResponseEntity<>(errorResponses, HttpStatus.BAD_REQUEST); List<Action> actions = actionService.createAction(actionRequest); return getSuccessResponse(actions, actionRequest.getRequestInfo()); }
ActionController { @PostMapping(value = "_create") public ResponseEntity<?> createAction(@RequestBody @Valid final ActionRequest actionRequest, final BindingResult errors) { if (errors.hasErrors()) { final ErrorResponse errRes = populateErrors(errors); return new ResponseEntity<>(errRes, HttpStatus.BAD_REQUEST); } logger.info("Create Action Type Request::" + actionRequest); final List<ErrorResponse> errorResponses = validateActionRequest(actionRequest, taskAction[0]); if (!errorResponses.isEmpty()) return new ResponseEntity<>(errorResponses, HttpStatus.BAD_REQUEST); List<Action> actions = actionService.createAction(actionRequest); return getSuccessResponse(actions, actionRequest.getRequestInfo()); } }
ActionController { @PostMapping(value = "_create") public ResponseEntity<?> createAction(@RequestBody @Valid final ActionRequest actionRequest, final BindingResult errors) { if (errors.hasErrors()) { final ErrorResponse errRes = populateErrors(errors); return new ResponseEntity<>(errRes, HttpStatus.BAD_REQUEST); } logger.info("Create Action Type Request::" + actionRequest); final List<ErrorResponse> errorResponses = validateActionRequest(actionRequest, taskAction[0]); if (!errorResponses.isEmpty()) return new ResponseEntity<>(errorResponses, HttpStatus.BAD_REQUEST); List<Action> actions = actionService.createAction(actionRequest); return getSuccessResponse(actions, actionRequest.getRequestInfo()); }  }
ActionController { @PostMapping(value = "_create") public ResponseEntity<?> createAction(@RequestBody @Valid final ActionRequest actionRequest, final BindingResult errors) { if (errors.hasErrors()) { final ErrorResponse errRes = populateErrors(errors); return new ResponseEntity<>(errRes, HttpStatus.BAD_REQUEST); } logger.info("Create Action Type Request::" + actionRequest); final List<ErrorResponse> errorResponses = validateActionRequest(actionRequest, taskAction[0]); if (!errorResponses.isEmpty()) return new ResponseEntity<>(errorResponses, HttpStatus.BAD_REQUEST); List<Action> actions = actionService.createAction(actionRequest); return getSuccessResponse(actions, actionRequest.getRequestInfo()); }  @PostMapping(value = "_search") ActionResponse getActionsBasedOnRoles(@RequestBody final ActionRequest actionRequest); @PostMapping(value = "_list") ResponseEntity<?> getAllActionsBasedOnRoles(@RequestBody final ActionRequest actionRequest); @PostMapping(value = "_get") ResponseEntity<?> getAllActions(@RequestBody final ActionRequest actionRequest); @PostMapping(value = "mdms/_get") ResponseEntity<?> getAllMDMSActions(@RequestBody final ActionRequest actionRequest); @PostMapping(value = "_validate") ValidateActionResponse validateAction(@RequestBody ValidateActionRequest validateActionRequest); @PostMapping(value = "_authorize") ResponseEntity<Void> authorize(@RequestBody @Valid AuthorizationRequestWrapper authorizationRequestWrapper); @PostMapping(value = "_create") ResponseEntity<?> createAction(@RequestBody @Valid final ActionRequest actionRequest,
			final BindingResult errors); @PostMapping(value = "_update") ResponseEntity<?> updateAction(@RequestBody @Valid final ActionRequest actionRequest,
			final BindingResult errors); }
ActionController { @PostMapping(value = "_create") public ResponseEntity<?> createAction(@RequestBody @Valid final ActionRequest actionRequest, final BindingResult errors) { if (errors.hasErrors()) { final ErrorResponse errRes = populateErrors(errors); return new ResponseEntity<>(errRes, HttpStatus.BAD_REQUEST); } logger.info("Create Action Type Request::" + actionRequest); final List<ErrorResponse> errorResponses = validateActionRequest(actionRequest, taskAction[0]); if (!errorResponses.isEmpty()) return new ResponseEntity<>(errorResponses, HttpStatus.BAD_REQUEST); List<Action> actions = actionService.createAction(actionRequest); return getSuccessResponse(actions, actionRequest.getRequestInfo()); }  @PostMapping(value = "_search") ActionResponse getActionsBasedOnRoles(@RequestBody final ActionRequest actionRequest); @PostMapping(value = "_list") ResponseEntity<?> getAllActionsBasedOnRoles(@RequestBody final ActionRequest actionRequest); @PostMapping(value = "_get") ResponseEntity<?> getAllActions(@RequestBody final ActionRequest actionRequest); @PostMapping(value = "mdms/_get") ResponseEntity<?> getAllMDMSActions(@RequestBody final ActionRequest actionRequest); @PostMapping(value = "_validate") ValidateActionResponse validateAction(@RequestBody ValidateActionRequest validateActionRequest); @PostMapping(value = "_authorize") ResponseEntity<Void> authorize(@RequestBody @Valid AuthorizationRequestWrapper authorizationRequestWrapper); @PostMapping(value = "_create") ResponseEntity<?> createAction(@RequestBody @Valid final ActionRequest actionRequest,
			final BindingResult errors); @PostMapping(value = "_update") ResponseEntity<?> updateAction(@RequestBody @Valid final ActionRequest actionRequest,
			final BindingResult errors);  }