RdfEngine implements Engine { @Override public Group createGroup(GroupConfig groupConfig) { Group group = groupFactory.createNew(createGroupIri(groupConfig.getTitle())); group.setProperty(vf.createLiteral(groupConfig.getTitle()), vf.createIRI(DCTERMS.TITLE.stringValue())); if (groupConfig.getMembers() != null) { Set<Agent> members = new HashSet<>(groupConfig.getMembers()); if (!members.isEmpty()) { group.setMember(members); } } if (groupConfig.getRoles() != null) { Set<Role> newRoles = groupConfig.getRoles().stream() .map(this::getRole) .filter(Optional::isPresent) .map(Optional::get) .collect(Collectors.toSet()); if (!newRoles.isEmpty()) { group.setHasGroupRole(newRoles); } } if (!groupConfig.getDescription().equals("")) { group.setProperty(vf.createLiteral(groupConfig.getDescription()), vf.createIRI(DCTERMS.DESCRIPTION.stringValue())); } return group; }  @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 testCreateGroup() { Set<User> members = Stream.of(userFactory.createNew(VALUE_FACTORY.createIRI(userId))).collect(Collectors.toSet()); Set<String> roles = Stream.of("user").collect(Collectors.toSet()); GroupConfig config = new GroupConfig.Builder(groupName1).description("Test") .members(members).roles(roles).build(); Group group = engine.createGroup(config); assertEquals(group.getResource().stringValue(), groupId1); assertEquals(group.getMember_resource().size(), members.size()); assertEquals(group.getHasGroupRole_resource().size(), roles.size()); assertTrue(group.getProperty(VALUE_FACTORY.createIRI(DCTERMS.TITLE.stringValue())).isPresent() && group.getProperty(VALUE_FACTORY.createIRI(DCTERMS.TITLE.stringValue())).get().stringValue().equals(groupName1)); assertTrue(group.getProperty(VALUE_FACTORY.createIRI(DCTERMS.DESCRIPTION.stringValue())).isPresent() && group.getProperty(VALUE_FACTORY.createIRI(DCTERMS.DESCRIPTION.stringValue())).get().stringValue().equals("Test")); }