@Test public void testShouldNotUpdateRoleIfNoName() throws Exception { List<Role> roles = getRoles(); when(roleService.updateRole(any(RoleRequest.class))).thenReturn(roles); ResponseInfo responseInfo = ResponseInfo.builder().build(); when(responseInfoFactory.createResponseInfoFromRequestInfo(any(RequestInfo.class), any(Boolean.class))) .thenReturn(responseInfo); mockMvc.perform(post("/v1/roles/_update").contentType(MediaType.APPLICATION_JSON_UTF8) .content(new Resources().getFileContents("roleUpdateRequestWithoutName.json"))) .andExpect(status().isBadRequest()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().json(new Resources().getFileContents("roleUpdateResponseWithoutName.json"))); }
@PostMapping(value = "_update") public ResponseEntity<?> updateRole(@RequestBody @Valid final RoleRequest roleRequest, final BindingResult errors) { if (errors.hasErrors()) { final ErrorResponse errRes = populateErrors(errors); return new ResponseEntity<>(errRes, HttpStatus.BAD_REQUEST); } logger.info("Update Role Request::" + roleRequest); final List<ErrorResponse> errorResponses = validatRoleRequest(roleRequest, taskAction[1]); if (!errorResponses.isEmpty()) return new ResponseEntity<>(errorResponses, HttpStatus.BAD_REQUEST); List<Role> roles = roleService.updateRole(roleRequest); return getSuccessResponse(roles, roleRequest.getRequestInfo()); }
RoleController { @PostMapping(value = "_update") public ResponseEntity<?> updateRole(@RequestBody @Valid final RoleRequest roleRequest, final BindingResult errors) { if (errors.hasErrors()) { final ErrorResponse errRes = populateErrors(errors); return new ResponseEntity<>(errRes, HttpStatus.BAD_REQUEST); } logger.info("Update Role Request::" + roleRequest); final List<ErrorResponse> errorResponses = validatRoleRequest(roleRequest, taskAction[1]); if (!errorResponses.isEmpty()) return new ResponseEntity<>(errorResponses, HttpStatus.BAD_REQUEST); List<Role> roles = roleService.updateRole(roleRequest); return getSuccessResponse(roles, roleRequest.getRequestInfo()); } }
RoleController { @PostMapping(value = "_update") public ResponseEntity<?> updateRole(@RequestBody @Valid final RoleRequest roleRequest, final BindingResult errors) { if (errors.hasErrors()) { final ErrorResponse errRes = populateErrors(errors); return new ResponseEntity<>(errRes, HttpStatus.BAD_REQUEST); } logger.info("Update Role Request::" + roleRequest); final List<ErrorResponse> errorResponses = validatRoleRequest(roleRequest, taskAction[1]); if (!errorResponses.isEmpty()) return new ResponseEntity<>(errorResponses, HttpStatus.BAD_REQUEST); List<Role> roles = roleService.updateRole(roleRequest); return getSuccessResponse(roles, roleRequest.getRequestInfo()); } RoleController(RoleService roleService); }
RoleController { @PostMapping(value = "_update") public ResponseEntity<?> updateRole(@RequestBody @Valid final RoleRequest roleRequest, final BindingResult errors) { if (errors.hasErrors()) { final ErrorResponse errRes = populateErrors(errors); return new ResponseEntity<>(errRes, HttpStatus.BAD_REQUEST); } logger.info("Update Role Request::" + roleRequest); final List<ErrorResponse> errorResponses = validatRoleRequest(roleRequest, taskAction[1]); if (!errorResponses.isEmpty()) return new ResponseEntity<>(errorResponses, HttpStatus.BAD_REQUEST); List<Role> roles = roleService.updateRole(roleRequest); return getSuccessResponse(roles, roleRequest.getRequestInfo()); } RoleController(RoleService roleService); @PostMapping(value = "_search") RoleResponse getMDMSRoles(@RequestParam(value = "code", required = false) String code,@RequestParam(value = "tenantId", required = false) String tenantId,
			@RequestBody final RoleRequest roleRequest); @PostMapping(value = "_create") ResponseEntity<?> createRole(@RequestBody @Valid final RoleRequest roleRequest, final BindingResult errors); @PostMapping(value = "_update") ResponseEntity<?> updateRole(@RequestBody @Valid final RoleRequest roleRequest, final BindingResult errors); }
RoleController { @PostMapping(value = "_update") public ResponseEntity<?> updateRole(@RequestBody @Valid final RoleRequest roleRequest, final BindingResult errors) { if (errors.hasErrors()) { final ErrorResponse errRes = populateErrors(errors); return new ResponseEntity<>(errRes, HttpStatus.BAD_REQUEST); } logger.info("Update Role Request::" + roleRequest); final List<ErrorResponse> errorResponses = validatRoleRequest(roleRequest, taskAction[1]); if (!errorResponses.isEmpty()) return new ResponseEntity<>(errorResponses, HttpStatus.BAD_REQUEST); List<Role> roles = roleService.updateRole(roleRequest); return getSuccessResponse(roles, roleRequest.getRequestInfo()); } RoleController(RoleService roleService); @PostMapping(value = "_search") RoleResponse getMDMSRoles(@RequestParam(value = "code", required = false) String code,@RequestParam(value = "tenantId", required = false) String tenantId,
			@RequestBody final RoleRequest roleRequest); @PostMapping(value = "_create") ResponseEntity<?> createRole(@RequestBody @Valid final RoleRequest roleRequest, final BindingResult errors); @PostMapping(value = "_update") ResponseEntity<?> updateRole(@RequestBody @Valid final RoleRequest roleRequest, final BindingResult errors);  }