RdfEngine implements Engine { @Override public Optional<Group> retrieveGroup(String groupTitle) { try (RepositoryConnection conn = repository.getConnection()) { Optional<Resource> optId = getGroupId(groupTitle, conn); if (!optId.isPresent()) { return Optional.empty(); } Model groupModel = mf.createModel(); RepositoryResult<Statement> statements = conn.getStatements(optId.get(), null, null, context); statements.forEach(groupModel::add); roles.stream() .map(this::getRole) .forEach(roleOptional -> roleOptional.ifPresent(role -> groupModel.addAll(role.getModel()))); groupModel.filter(optId.get(), vf.createIRI(Group.member_IRI), null) .objects().forEach(userIRI -> { RepositoryResult<Statement> userStatements = conn.getStatements((Resource) userIRI, null, null, context); userStatements.forEach(groupModel::add); }); return groupFactory.getExisting(optId.get(), groupModel); } }  @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 testRetrieveGroup() { Optional<Group> groupOptional = engine.retrieveGroup(groupName1); assertTrue(groupOptional.isPresent()); Group group = groupOptional.get(); assertEquals(group.getResource().stringValue(), groupId1); }
@Test public void testRetrieveGroupThatDoesNotExist() { Optional<Group> groupOptional= engine.retrieveGroup("http: assertFalse(groupOptional.isPresent()); }