@Test public void createUserRoleTest() throws Exception { byte[] createUserRoleDetailsContent = toJson(getUserRoleDetailsRequest()); when(userRolesService.createUserRole(any(), any())).thenReturn(USER_ROLE_CREATION_SUCCESS); mockMvc.perform(post("/roles/create").principal(principal) .content(createUserRoleDetailsContent) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("$.message", is("success"))) .andExpect(jsonPath("$.data", is(USER_ROLE_CREATION_SUCCESS))); }
@ApiOperation(httpMethod = "POST", value = "API to create roles details", response = Response.class, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/create", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Object> createUserRole(@AuthenticationPrincipal Principal user, @ApiParam(value = "provide valid role details", required = true) @RequestBody(required = true) CreateRoleDetailsRequest roleDetailsRequest) { try { return ResponseUtils.buildSucessResponse(userRolesService.createUserRole(roleDetailsRequest, user.getName())); } catch (Exception exception) { log.error(UNEXPECTED_ERROR_OCCURRED, exception); return ResponseUtils.buildFailureResponse(new Exception(UNEXPECTED_ERROR_OCCURRED), exception.getMessage()); } }
UserRolesController { @ApiOperation(httpMethod = "POST", value = "API to create roles details", response = Response.class, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/create", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Object> createUserRole(@AuthenticationPrincipal Principal user, @ApiParam(value = "provide valid role details", required = true) @RequestBody(required = true) CreateRoleDetailsRequest roleDetailsRequest) { try { return ResponseUtils.buildSucessResponse(userRolesService.createUserRole(roleDetailsRequest, user.getName())); } catch (Exception exception) { log.error(UNEXPECTED_ERROR_OCCURRED, exception); return ResponseUtils.buildFailureResponse(new Exception(UNEXPECTED_ERROR_OCCURRED), exception.getMessage()); } } }
UserRolesController { @ApiOperation(httpMethod = "POST", value = "API to create roles details", response = Response.class, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/create", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Object> createUserRole(@AuthenticationPrincipal Principal user, @ApiParam(value = "provide valid role details", required = true) @RequestBody(required = true) CreateRoleDetailsRequest roleDetailsRequest) { try { return ResponseUtils.buildSucessResponse(userRolesService.createUserRole(roleDetailsRequest, user.getName())); } catch (Exception exception) { log.error(UNEXPECTED_ERROR_OCCURRED, exception); return ResponseUtils.buildFailureResponse(new Exception(UNEXPECTED_ERROR_OCCURRED), exception.getMessage()); } }  }
UserRolesController { @ApiOperation(httpMethod = "POST", value = "API to create roles details", response = Response.class, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/create", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Object> createUserRole(@AuthenticationPrincipal Principal user, @ApiParam(value = "provide valid role details", required = true) @RequestBody(required = true) CreateRoleDetailsRequest roleDetailsRequest) { try { return ResponseUtils.buildSucessResponse(userRolesService.createUserRole(roleDetailsRequest, 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 details", response = Response.class, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> getAllUserRoles(
		@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 = StringUtils.EMPTY, name = "searchTerm", required = false) String searchTerm); @ApiOperation(httpMethod = "GET", value = "API to get user role by id", response = Response.class, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/details-by-id", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> getUserRoleById(
		@ApiParam(value = "provide valid role id", required = true) @RequestParam(defaultValue="", name = "roleId", required = true) String roleId); @ApiOperation(httpMethod = "POST", value = "API to create roles details", response = Response.class, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/create", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> createUserRole(@AuthenticationPrincipal Principal user,
			@ApiParam(value = "provide valid role details", required = true)
			@RequestBody(required = true) CreateRoleDetailsRequest roleDetailsRequest); @ApiOperation(httpMethod = "POST", value = "API to update roles details", response = Response.class, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/update", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> updateUserRole(@AuthenticationPrincipal Principal user,
			@ApiParam(value = "provide valid role details", required = true)
			@RequestBody(required = true) UpdateRoleDetailsRequest roleDetailsRequest); }
UserRolesController { @ApiOperation(httpMethod = "POST", value = "API to create roles details", response = Response.class, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/create", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Object> createUserRole(@AuthenticationPrincipal Principal user, @ApiParam(value = "provide valid role details", required = true) @RequestBody(required = true) CreateRoleDetailsRequest roleDetailsRequest) { try { return ResponseUtils.buildSucessResponse(userRolesService.createUserRole(roleDetailsRequest, 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 details", response = Response.class, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> getAllUserRoles(
		@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 = StringUtils.EMPTY, name = "searchTerm", required = false) String searchTerm); @ApiOperation(httpMethod = "GET", value = "API to get user role by id", response = Response.class, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/details-by-id", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> getUserRoleById(
		@ApiParam(value = "provide valid role id", required = true) @RequestParam(defaultValue="", name = "roleId", required = true) String roleId); @ApiOperation(httpMethod = "POST", value = "API to create roles details", response = Response.class, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/create", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> createUserRole(@AuthenticationPrincipal Principal user,
			@ApiParam(value = "provide valid role details", required = true)
			@RequestBody(required = true) CreateRoleDetailsRequest roleDetailsRequest); @ApiOperation(httpMethod = "POST", value = "API to update roles details", response = Response.class, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(path = "/update", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Object> updateUserRole(@AuthenticationPrincipal Principal user,
			@ApiParam(value = "provide valid role details", required = true)
			@RequestBody(required = true) UpdateRoleDetailsRequest roleDetailsRequest);  }