RdfEngine implements Engine { @Override public void updateUser(User newUser) { if (!userExists(newUser.getResource())) { throw new IllegalArgumentException("User with that id does not exist"); } try (RepositoryConnection conn = repository.getConnection()) { conn.remove(newUser.getResource(), null, null, context); conn.add(newUser.getModel(), context); } }  @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 testUpdateUser() { User newUser = userFactory.createNew(VALUE_FACTORY.createIRI(userId)); newUser.setPassword(VALUE_FACTORY.createLiteral("123")); newUser.setUsername(VALUE_FACTORY.createLiteral("user")); engine.updateUser(newUser); Model userModel = MODEL_FACTORY.createModel(); RepositoryConnection connection = repo.getConnection(); RepositoryResult<Statement> statements = connection.getStatements(VALUE_FACTORY.createIRI(userId), null, null); statements.forEach(userModel::add); connection.close(); assertFalse(userModel.isEmpty()); Optional<User> optUser = userFactory.getExisting(VALUE_FACTORY.createIRI(userId), userModel); assertTrue(optUser.isPresent()); User savedUser = optUser.get(); assertTrue(savedUser.getPassword().isPresent() && savedUser.getPassword().get().stringValue().equals("123")); assertTrue(savedUser.getUsername().isPresent() && savedUser.getUsername().get().stringValue().equals("user")); }
@Test(expected = IllegalArgumentException.class) public void testUpdateUserThatDoesNotExist() { User newUser = userFactory.createNew(VALUE_FACTORY.createIRI("http: engine.updateUser(newUser); }