@Test public void testShouldUpdateAction() throws Exception { List<Action> actions = new ArrayList<Action>(); Action action1 = new Action(); Action action2 = new Action(); action1.setId(1l); action1.setName("test1"); action1.setUrl("/test"); action1.setDisplayName("Create Test"); action1.setEnabled(true); action1.setOrderNumber(1); action1.setCreatedBy(1l); action1.setLastModifiedBy(1l); action2.setId(2l); action2.setName("test2"); action2.setUrl("/test/test2"); action2.setDisplayName("Update Test"); action2.setEnabled(true); action2.setOrderNumber(2); action2.setCreatedBy(1l); action2.setLastModifiedBy(1l); actions.add(action1); actions.add(action2); when(actionService.updateAction(any(ActionRequest.class))).thenReturn(actions); when(actionService.checkActionNameExit(any(String.class))).thenReturn(true); ResponseInfo responseInfo = ResponseInfo.builder().build(); when(responseInfoFactory.createResponseInfoFromRequestInfo(any(RequestInfo.class), any(Boolean.class))) .thenReturn(responseInfo); responseInfo.setApiId("org.egov.accesscontrol"); responseInfo.setTs("Thu Mar 09 18:30:00 UTC 2017"); responseInfo.setResMsgId("uief87324"); mockMvc.perform(post("/v1/actions/_update").contentType(MediaType.APPLICATION_JSON_UTF8) .content(new Resources().getFileContents("actionUpdateRequest.json"))).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().json(new Resources().getFileContents("actionUpdateSuccessResponse.json"))); }
@PostMapping(value = "_update") public ResponseEntity<?> updateAction(@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("Update Action Request::" + actionRequest); final List<ErrorResponse> errorResponses = validateActionRequest(actionRequest, taskAction[1]); if (!errorResponses.isEmpty()) return new ResponseEntity<>(errorResponses, HttpStatus.BAD_REQUEST); List<Action> actions = actionService.updateAction(actionRequest); return getSuccessResponse(actions, actionRequest.getRequestInfo()); }
ActionController { @PostMapping(value = "_update") public ResponseEntity<?> updateAction(@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("Update Action Request::" + actionRequest); final List<ErrorResponse> errorResponses = validateActionRequest(actionRequest, taskAction[1]); if (!errorResponses.isEmpty()) return new ResponseEntity<>(errorResponses, HttpStatus.BAD_REQUEST); List<Action> actions = actionService.updateAction(actionRequest); return getSuccessResponse(actions, actionRequest.getRequestInfo()); } }
ActionController { @PostMapping(value = "_update") public ResponseEntity<?> updateAction(@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("Update Action Request::" + actionRequest); final List<ErrorResponse> errorResponses = validateActionRequest(actionRequest, taskAction[1]); if (!errorResponses.isEmpty()) return new ResponseEntity<>(errorResponses, HttpStatus.BAD_REQUEST); List<Action> actions = actionService.updateAction(actionRequest); return getSuccessResponse(actions, actionRequest.getRequestInfo()); }  }
ActionController { @PostMapping(value = "_update") public ResponseEntity<?> updateAction(@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("Update Action Request::" + actionRequest); final List<ErrorResponse> errorResponses = validateActionRequest(actionRequest, taskAction[1]); if (!errorResponses.isEmpty()) return new ResponseEntity<>(errorResponses, HttpStatus.BAD_REQUEST); List<Action> actions = actionService.updateAction(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 = "_update") public ResponseEntity<?> updateAction(@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("Update Action Request::" + actionRequest); final List<ErrorResponse> errorResponses = validateActionRequest(actionRequest, taskAction[1]); if (!errorResponses.isEmpty()) return new ResponseEntity<>(errorResponses, HttpStatus.BAD_REQUEST); List<Action> actions = actionService.updateAction(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);  }