RdfEngine implements Engine { @Override public void storeGroup(Group group) { Value title = group.getProperty(vf.createIRI(DCTERMS.TITLE.stringValue())).orElseThrow(() -> new IllegalArgumentException("Group must have a title")); if (resourceExists(group.getResource()) || groupExists(title.stringValue())) { throw new IllegalArgumentException("Group with that id already exists"); } try (RepositoryConnection conn = repository.getConnection()) { conn.add(group.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 testStoreGroup() { Resource newGroupId = VALUE_FACTORY.createIRI("http: Group newGroup = groupFactory.createNew(newGroupId); newGroup.setProperty(VALUE_FACTORY.createLiteral("newgroup"), VALUE_FACTORY.createIRI(DCTERMS.TITLE.stringValue())); engine.storeGroup(newGroup); RepositoryConnection connection = repo.getConnection(); RepositoryResult<Statement> statements = connection.getStatements(newGroupId, null, null); assertTrue(statements.hasNext()); connection.close(); }
@Test(expected = IllegalArgumentException.class) public void testStoreGroupWithNoTitle() { Resource newGroupId = VALUE_FACTORY.createIRI("http: Group newGroup = groupFactory.createNew(newGroupId); engine.storeGroup(newGroup); }
@Test(expected = IllegalArgumentException.class) public void testStoreGroupThatAlreadyExists() { Group group= groupFactory.createNew(VALUE_FACTORY.createIRI(groupId1)); engine.storeGroup(group); }