@Test @WithMockUser public void getRoleShouldReturnUnAuthorizedUser() throws Exception { FideliusUserEntry user = new FideliusUserEntry("U250", "someDn", "user@company.com", "John Doe"); FideliusRole role = FideliusRole.UNAUTHORIZED; when(fideliusRoleService.getUserProfile()).thenReturn(user); when(fideliusRoleService.getRole()).thenReturn(role); mockMvc.perform(getRoleRequest) .andExpect(status().isOk()) .andExpect(jsonPath("role", is("UNAUTHORIZED"))) .andExpect(jsonPath("name", is("John Doe"))); }
@ResponseBody @GetMapping(value="/role") public Map<String, Object> getRole() { FideliusUserEntry user = fideliusRoleService.getUserProfile(); FideliusRole role = fideliusRoleService.getRole(); Map<String, Object> result = new HashMap<>(); result.put("userId", user.getUserId()); result.put("name", user.getName()); result.put("email", user.getEmail()); result.put("role", role); switch (role) { case MASTER: result.put("memberships", fideliusRoleService.getMasterMemberships()); return result; case OPS: result.put("memberships", fideliusRoleService.getOpsMemberships()); return result; case DEV: { result.put("memberships", fideliusRoleService.getDevMemberships()); return result; } } return result; }
AuthController { @ResponseBody @GetMapping(value="/role") public Map<String, Object> getRole() { FideliusUserEntry user = fideliusRoleService.getUserProfile(); FideliusRole role = fideliusRoleService.getRole(); Map<String, Object> result = new HashMap<>(); result.put("userId", user.getUserId()); result.put("name", user.getName()); result.put("email", user.getEmail()); result.put("role", role); switch (role) { case MASTER: result.put("memberships", fideliusRoleService.getMasterMemberships()); return result; case OPS: result.put("memberships", fideliusRoleService.getOpsMemberships()); return result; case DEV: { result.put("memberships", fideliusRoleService.getDevMemberships()); return result; } } return result; } }
AuthController { @ResponseBody @GetMapping(value="/role") public Map<String, Object> getRole() { FideliusUserEntry user = fideliusRoleService.getUserProfile(); FideliusRole role = fideliusRoleService.getRole(); Map<String, Object> result = new HashMap<>(); result.put("userId", user.getUserId()); result.put("name", user.getName()); result.put("email", user.getEmail()); result.put("role", role); switch (role) { case MASTER: result.put("memberships", fideliusRoleService.getMasterMemberships()); return result; case OPS: result.put("memberships", fideliusRoleService.getOpsMemberships()); return result; case DEV: { result.put("memberships", fideliusRoleService.getDevMemberships()); return result; } } return result; }  }
AuthController { @ResponseBody @GetMapping(value="/role") public Map<String, Object> getRole() { FideliusUserEntry user = fideliusRoleService.getUserProfile(); FideliusRole role = fideliusRoleService.getRole(); Map<String, Object> result = new HashMap<>(); result.put("userId", user.getUserId()); result.put("name", user.getName()); result.put("email", user.getEmail()); result.put("role", role); switch (role) { case MASTER: result.put("memberships", fideliusRoleService.getMasterMemberships()); return result; case OPS: result.put("memberships", fideliusRoleService.getOpsMemberships()); return result; case DEV: { result.put("memberships", fideliusRoleService.getDevMemberships()); return result; } } return result; }  @ResponseBody @GetMapping(value="/role") Map<String, Object> getRole(); }
AuthController { @ResponseBody @GetMapping(value="/role") public Map<String, Object> getRole() { FideliusUserEntry user = fideliusRoleService.getUserProfile(); FideliusRole role = fideliusRoleService.getRole(); Map<String, Object> result = new HashMap<>(); result.put("userId", user.getUserId()); result.put("name", user.getName()); result.put("email", user.getEmail()); result.put("role", role); switch (role) { case MASTER: result.put("memberships", fideliusRoleService.getMasterMemberships()); return result; case OPS: result.put("memberships", fideliusRoleService.getOpsMemberships()); return result; case DEV: { result.put("memberships", fideliusRoleService.getDevMemberships()); return result; } } return result; }  @ResponseBody @GetMapping(value="/role") Map<String, Object> getRole();  }