RdfEngine implements Engine { @Override public User createUser(UserConfig userConfig) { User user = userFactory.createNew(createUserIri(userConfig.getUsername())); user.setUsername(vf.createLiteral(userConfig.getUsername())); user.setPassword(vf.createLiteral(getEncryptedPassword(userConfig.getPassword()))); Set<Role> newRoles = userConfig.getRoles().stream() .map(this::getRole) .filter(Optional::isPresent) .map(Optional::get) .collect(Collectors.toSet()); if (!newRoles.isEmpty()) { user.setHasUserRole(newRoles); } if (!userConfig.getEmail().equals("")) { String emailStr = userConfig.getEmail(); Set<Thing> email = new HashSet<>(); email.add(thingFactory.createNew( vf.createIRI(emailStr.contains("mailto:") ? emailStr : "mailto:" + emailStr))); user.setMbox(email); } if (!userConfig.getFirstName().equals("")) { Set<Literal> firstName = new HashSet<>(); firstName.add(vf.createLiteral(userConfig.getFirstName())); user.setFirstName(firstName); } if (!userConfig.getLastName().equals("")) { Set<Literal> lastName = new HashSet<>(); lastName.add(vf.createLiteral(userConfig.getLastName())); user.setLastName(lastName); } return user; }  @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 testCreateUser() { Set<String> roles = Stream.of("user").collect(Collectors.toSet()); UserConfig config = new UserConfig.Builder(username, password, roles).email("example@example.com") .firstName("John").lastName("Doe").build(); User user = engine.createUser(config); assertEquals(user.getResource().stringValue(), userId); assertTrue(user.getUsername().isPresent() && user.getUsername().get().stringValue().equals(username)); assertTrue(user.getPassword().isPresent() && user.getPassword().get().stringValue().equals(password)); assertEquals(user.getHasUserRole_resource().size(), roles.size()); assertEquals(1, user.getMbox_resource().size()); assertTrue(user.getMbox_resource().stream().map(Value::stringValue).collect(Collectors.toSet()).contains("mailto:example@example.com")); assertEquals(1, user.getFirstName().size()); assertTrue(user.getFirstName().stream().map(Value::stringValue).collect(Collectors.toSet()).contains("John")); assertEquals(1, user.getLastName().size()); assertTrue(user.getLastName().stream().map(Value::stringValue).collect(Collectors.toSet()).contains("Doe")); }