AccountController { @RequestMapping(value = "/", method = RequestMethod.GET) @ResponseBody @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_DEVICE_MANAGER') or hasRole('ROLE_DRPROGRAM')") public AbstractUserWithRoleDto registeredUser(Principal principal) { AbstractUser findOneByUsername = abstractUserDao.findOneByUsername(principal.getName()); if (findOneByUsername != null) { return dtoMapper.map(findOneByUsername, AbstractUserWithRoleDto.class); } return null; }  @RequestMapping(value = "/", method = RequestMethod.GET) @ResponseBody @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_DEVICE_MANAGER') or hasRole('ROLE_DRPROGRAM')") AbstractUserWithRoleDto registeredUser(Principal principal); @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/user", method = RequestMethod.GET) @ResponseBody List<OadrUserDto> listUser(); @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/user", method = RequestMethod.POST) @ResponseBody ResponseEntity<InputStreamResource> createUser(@RequestBody OadrUserCreateDto dto,
			HttpServletResponse response); @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/user/{username}", method = RequestMethod.DELETE) @ResponseBody void deleteUser(@PathVariable("username") String username, HttpServletResponse response); @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/app", method = RequestMethod.GET) @ResponseBody List<OadrAppDto> listApp(); @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/app", method = RequestMethod.POST) @ResponseBody ResponseEntity<InputStreamResource> createApp(@RequestBody OadrAppCreateDto dto,
			HttpServletResponse response); @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/app/{username}", method = RequestMethod.DELETE) @ResponseBody void deleteApp(@PathVariable("username") String username, HttpServletResponse response);  }
@Test public void registeredUserTest() throws Exception { this.mockMvc .perform(MockMvcRequestBuilders.get(ACCOUNT_URL).header("Content-Type", "application/json").with(user)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.FORBIDDEN_403)); MvcResult andReturn = this.mockMvc .perform(MockMvcRequestBuilders.get(ACCOUNT_URL).header("Content-Type", "application/json").with(admin)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.OK_200)).andReturn(); AbstractUserWithRoleDto convertMvcResultToOadrUserDto = convertMvcResultToObject(andReturn, AbstractUserWithRoleDto.class); assertEquals("admin", convertMvcResultToOadrUserDto.getUsername()); assertTrue(convertMvcResultToOadrUserDto.getRoles().contains("ROLE_ADMIN")); andReturn = this.mockMvc .perform(MockMvcRequestBuilders.get(ACCOUNT_URL).header("Content-Type", "application/json").with(app)) .andExpect(MockMvcResultMatchers.status().is(HttpStatus.OK_200)).andReturn(); convertMvcResultToOadrUserDto = convertMvcResultToObject(andReturn, AbstractUserWithRoleDto.class); assertEquals("app", convertMvcResultToOadrUserDto.getUsername()); assertTrue(convertMvcResultToOadrUserDto.getRoles().contains("ROLE_DEVICE_MANAGER")); }