@Test public void allocateUserRoleTest() throws Exception { byte[] roleAllocateDetailsContent = toJson(getRoleAllocateDetailsRequest()); when(userRolesMappingService.allocateUserRole(any(), any())).thenReturn(USER_ROLE_ALLOCATION_SUCCESS); mockMvc.perform(post("/users-roles/allocate").principal(principal) .content(roleAllocateDetailsContent) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("$.message", is("success"))) .andExpect(jsonPath("$.data", is(USER_ROLE_ALLOCATION_SUCCESS))); }
@ApiOperation(httpMethod = "POST", value = "API to allocate user roles", response = Response.class, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/allocate", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Object> allocateUserRole(@AuthenticationPrincipal Principal user, @ApiParam(value = "provide valid role details", required = true) @RequestBody(required = true) UserRoleConfigRequest userRoleConfigRequest) { try { return ResponseUtils.buildSucessResponse(userRolesMappingService.allocateUserRole(userRoleConfigRequest, user.getName())); } catch (Exception exception) { log.error(UNEXPECTED_ERROR_OCCURRED, exception); return ResponseUtils.buildFailureResponse(new Exception(UNEXPECTED_ERROR_OCCURRED), exception.getMessage()); } }
UserRolesMappingController { @ApiOperation(httpMethod = "POST", value = "API to allocate user roles", response = Response.class, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/allocate", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Object> allocateUserRole(@AuthenticationPrincipal Principal user, @ApiParam(value = "provide valid role details", required = true) @RequestBody(required = true) UserRoleConfigRequest userRoleConfigRequest) { try { return ResponseUtils.buildSucessResponse(userRolesMappingService.allocateUserRole(userRoleConfigRequest, user.getName())); } catch (Exception exception) { log.error(UNEXPECTED_ERROR_OCCURRED, exception); return ResponseUtils.buildFailureResponse(new Exception(UNEXPECTED_ERROR_OCCURRED), exception.getMessage()); } } }
UserRolesMappingController { @ApiOperation(httpMethod = "POST", value = "API to allocate user roles", response = Response.class, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/allocate", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Object> allocateUserRole(@AuthenticationPrincipal Principal user, @ApiParam(value = "provide valid role details", required = true) @RequestBody(required = true) UserRoleConfigRequest userRoleConfigRequest) { try { return ResponseUtils.buildSucessResponse(userRolesMappingService.allocateUserRole(userRoleConfigRequest, user.getName())); } catch (Exception exception) { log.error(UNEXPECTED_ERROR_OCCURRED, exception); return ResponseUtils.buildFailureResponse(new Exception(UNEXPECTED_ERROR_OCCURRED), exception.getMessage()); } }  }
UserRolesMappingController { @ApiOperation(httpMethod = "POST", value = "API to allocate user roles", response = Response.class, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/allocate", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Object> allocateUserRole(@AuthenticationPrincipal Principal user, @ApiParam(value = "provide valid role details", required = true) @RequestBody(required = true) UserRoleConfigRequest userRoleConfigRequest) { try { return ResponseUtils.buildSucessResponse(userRolesMappingService.allocateUserRole(userRoleConfigRequest, 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 user roles mappings details", response = Response.class, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> getAllUserRolesMapping(
		@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 = "POST", value = "API to allocate user roles", response = Response.class, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/allocate", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> allocateUserRole(@AuthenticationPrincipal Principal user,
			@ApiParam(value = "provide valid role details", required = true)
			@RequestBody(required = true) UserRoleConfigRequest userRoleConfigRequest); }
UserRolesMappingController { @ApiOperation(httpMethod = "POST", value = "API to allocate user roles", response = Response.class, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/allocate", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Object> allocateUserRole(@AuthenticationPrincipal Principal user, @ApiParam(value = "provide valid role details", required = true) @RequestBody(required = true) UserRoleConfigRequest userRoleConfigRequest) { try { return ResponseUtils.buildSucessResponse(userRolesMappingService.allocateUserRole(userRoleConfigRequest, 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 user roles mappings details", response = Response.class, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> getAllUserRolesMapping(
		@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 = "POST", value = "API to allocate user roles", response = Response.class, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/allocate", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> allocateUserRole(@AuthenticationPrincipal Principal user,
			@ApiParam(value = "provide valid role details", required = true)
			@RequestBody(required = true) UserRoleConfigRequest userRoleConfigRequest);  }