@Test public void testShouldupdateRole() throws Exception { List<Role> roles = new ArrayList<>(); Role role1 = Role.builder().id(1L).name("test1test1").code("testonecode112234324") .description("test1description").build(); Role role2 = Role.builder().id(2L).name("test2test2").code("testtwocode11234354") .description("test2codedescription").build(); roles.add(role1); roles.add(role2); when(roleService.updateRole(any(RoleRequest.class))).thenReturn(roles); when(roleService.checkRoleNameDuplicationValidationErrors(any(String.class))).thenReturn(true); ResponseInfo responseInfo = ResponseInfo.builder().build(); responseInfo.setApiId("org.egov.accesscontrol"); responseInfo.setMsgId("20170310130900"); responseInfo.setResMsgId("uief87324"); responseInfo.setTs("Thu Mar 09 18:30:00 UTC 2017"); responseInfo.setVer("1.0"); 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("roleUpdateRequest.json"))).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().json(new Resources().getFileContents("roleUpdateSuccessResponse.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);  }