RdfEngine implements Engine { @Override public Set<Role> getUserRoles(String username) { Optional<User> userOptional = retrieveUser(username); if (!userOptional.isPresent()) { throw new IllegalArgumentException("User with that id does not exist"); } Set<Role> roles = new HashSet<>(); try (RepositoryConnection conn = repository.getConnection()) { GraphQuery query = conn.prepareGraphQuery(GET_USER_ROLES_QUERY); query.setBinding(USER_BINDING, userOptional.get().getResource()); Model rolesModel = QueryResults.asModel(query.evaluate(), mf); roles.addAll(roleFactory.getAllExisting(rolesModel)); return roles; } }  @Override Optional<Role> getRole(String roleName); @Override Set<User> getUsers(); @Override User createUser(UserConfig userConfig); @Override void storeUser(User user); @Override boolean userExists(String username); @Override boolean userExists(Resource userId); @Override Optional<User> retrieveUser(String username); @Override void updateUser(User newUser); @Override void deleteUser(String username); @Override Set<Group> getGroups(); @Override Group createGroup(GroupConfig groupConfig); @Override void storeGroup(Group group); @Override boolean groupExists(String groupTitle); @Override boolean groupExists(Resource groupId); @Override Optional<Group> retrieveGroup(String groupTitle); @Override void updateGroup(Group newGroup); @Override void deleteGroup(String groupTitle); @Override Set<Role> getUserRoles(String username); @Override boolean checkPassword(String username, String password); @Override String getEngineName(); static final String ENGINE_NAME; }
@Test public void testGetUserRoles() { Set<Role> roles = engine.getUserRoles(username); assertFalse(roles.isEmpty()); Set<Resource> roleIds = roles.stream() .map(Thing::getResource) .collect(Collectors.toSet()); assertTrue(roleIds.contains(VALUE_FACTORY.createIRI(userRoleId))); assertTrue(roleIds.contains(VALUE_FACTORY.createIRI(adminRoleId))); }
@Test(expected = IllegalArgumentException.class) public void testGetUserRolesThatDoesNotExist() { engine.getUserRoles("http: }