RdfEngine implements Engine { @Override public Optional<User> retrieveUser(String username) { try (RepositoryConnection conn = repository.getConnection()) { Optional<Resource> optId = getUserId(username, conn); if (!optId.isPresent()) { return Optional.empty(); } Model userModel = mf.createModel(); RepositoryResult<Statement> statements = conn.getStatements(optId.get(), null, null, context); statements.forEach(userModel::add); roles.stream() .map(this::getRole) .forEach(roleOptional -> roleOptional.ifPresent(role -> userModel.addAll(role.getModel()))); return userFactory.getExisting(optId.get(), userModel); } }  @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 testRetrieveUser() { Optional<User> userOptional = engine.retrieveUser(username); assertTrue(userOptional.isPresent()); User user = userOptional.get(); assertEquals(user.getResource().stringValue(), userId); assertTrue(user.getPassword().isPresent()); assertEquals(user.getPassword().get().stringValue(), password); }
@Test public void testRetrieveUserThatDoesNotExist() { Optional<User> userOptional = engine.retrieveUser("http: assertFalse(userOptional.isPresent()); }