@Test(expected = UserCreationException.class) public void executeRethrowsTheExceptionsOfTheLocalUserCreator() throws Exception { doThrow(new UserCreationException("")).when(localUserCreator).create(ArgumentMatchers.any()); ImmutableMultimap<String, String> immutableMultimap = ImmutableMultimap.<String, String>builder() .put(UserInfoKeys.USER_PID, PID) .put(UserInfoKeys.USER_NAME, USER_NAME) .put(UserInfoKeys.PASSWORD, PWD) .put(UserInfoKeys.GIVEN_NAME, GIVEN_NAME) .put(UserInfoKeys.SURNAME, SURNAME) .put(UserInfoKeys.EMAIL_ADDRESS, EMAIL) .put(UserInfoKeys.ORGANIZATION, ORGANIZATION) .put(UserInfoKeys.VRE_ID, VRE_ID) .put(UserInfoKeys.VRE_ROLE, VRE_ROLE) .build(); instance.execute(immutableMultimap, mock(PrintWriter.class)); }
@Override public void execute(ImmutableMultimap<String, String> immutableMultimap, PrintWriter printWriter) throws Exception { LOG.debug("Input {}", immutableMultimap); Sets.SetView<String> missingKeys = Sets.difference(UserInfoKeys.all, immutableMultimap.keySet()); if (!missingKeys.isEmpty()) { printWriter.write("Not importing users, because the map missing keys: " + missingKeys); return; } List<String> duplicates = getDuplicateKeys(immutableMultimap); if (!duplicates.isEmpty()) { printWriter.write("Not importing users, because the map contains duplicate keys: " + duplicates); return; } Map<String, String> userInfo = Maps.newHashMap(); immutableMultimap.keySet().stream() .filter(key -> UserInfoKeys.contains(key)) .forEach(key -> userInfo.put(key, immutableMultimap.get(key).iterator().next())); localUserCreator.create(userInfo); printWriter.write( String.format("User created with pid '%s' and user name '%s'", userInfo.get(USER_PID), userInfo.get(USER_NAME))); }
UserCreationTask extends Task { @Override public void execute(ImmutableMultimap<String, String> immutableMultimap, PrintWriter printWriter) throws Exception { LOG.debug("Input {}", immutableMultimap); Sets.SetView<String> missingKeys = Sets.difference(UserInfoKeys.all, immutableMultimap.keySet()); if (!missingKeys.isEmpty()) { printWriter.write("Not importing users, because the map missing keys: " + missingKeys); return; } List<String> duplicates = getDuplicateKeys(immutableMultimap); if (!duplicates.isEmpty()) { printWriter.write("Not importing users, because the map contains duplicate keys: " + duplicates); return; } Map<String, String> userInfo = Maps.newHashMap(); immutableMultimap.keySet().stream() .filter(key -> UserInfoKeys.contains(key)) .forEach(key -> userInfo.put(key, immutableMultimap.get(key).iterator().next())); localUserCreator.create(userInfo); printWriter.write( String.format("User created with pid '%s' and user name '%s'", userInfo.get(USER_PID), userInfo.get(USER_NAME))); } }
UserCreationTask extends Task { @Override public void execute(ImmutableMultimap<String, String> immutableMultimap, PrintWriter printWriter) throws Exception { LOG.debug("Input {}", immutableMultimap); Sets.SetView<String> missingKeys = Sets.difference(UserInfoKeys.all, immutableMultimap.keySet()); if (!missingKeys.isEmpty()) { printWriter.write("Not importing users, because the map missing keys: " + missingKeys); return; } List<String> duplicates = getDuplicateKeys(immutableMultimap); if (!duplicates.isEmpty()) { printWriter.write("Not importing users, because the map contains duplicate keys: " + duplicates); return; } Map<String, String> userInfo = Maps.newHashMap(); immutableMultimap.keySet().stream() .filter(key -> UserInfoKeys.contains(key)) .forEach(key -> userInfo.put(key, immutableMultimap.get(key).iterator().next())); localUserCreator.create(userInfo); printWriter.write( String.format("User created with pid '%s' and user name '%s'", userInfo.get(USER_PID), userInfo.get(USER_NAME))); } UserCreationTask(LocalUserCreator localUserCreator); }
UserCreationTask extends Task { @Override public void execute(ImmutableMultimap<String, String> immutableMultimap, PrintWriter printWriter) throws Exception { LOG.debug("Input {}", immutableMultimap); Sets.SetView<String> missingKeys = Sets.difference(UserInfoKeys.all, immutableMultimap.keySet()); if (!missingKeys.isEmpty()) { printWriter.write("Not importing users, because the map missing keys: " + missingKeys); return; } List<String> duplicates = getDuplicateKeys(immutableMultimap); if (!duplicates.isEmpty()) { printWriter.write("Not importing users, because the map contains duplicate keys: " + duplicates); return; } Map<String, String> userInfo = Maps.newHashMap(); immutableMultimap.keySet().stream() .filter(key -> UserInfoKeys.contains(key)) .forEach(key -> userInfo.put(key, immutableMultimap.get(key).iterator().next())); localUserCreator.create(userInfo); printWriter.write( String.format("User created with pid '%s' and user name '%s'", userInfo.get(USER_PID), userInfo.get(USER_NAME))); } UserCreationTask(LocalUserCreator localUserCreator); @Override void execute(ImmutableMultimap<String, String> immutableMultimap, PrintWriter printWriter); }
UserCreationTask extends Task { @Override public void execute(ImmutableMultimap<String, String> immutableMultimap, PrintWriter printWriter) throws Exception { LOG.debug("Input {}", immutableMultimap); Sets.SetView<String> missingKeys = Sets.difference(UserInfoKeys.all, immutableMultimap.keySet()); if (!missingKeys.isEmpty()) { printWriter.write("Not importing users, because the map missing keys: " + missingKeys); return; } List<String> duplicates = getDuplicateKeys(immutableMultimap); if (!duplicates.isEmpty()) { printWriter.write("Not importing users, because the map contains duplicate keys: " + duplicates); return; } Map<String, String> userInfo = Maps.newHashMap(); immutableMultimap.keySet().stream() .filter(key -> UserInfoKeys.contains(key)) .forEach(key -> userInfo.put(key, immutableMultimap.get(key).iterator().next())); localUserCreator.create(userInfo); printWriter.write( String.format("User created with pid '%s' and user name '%s'", userInfo.get(USER_PID), userInfo.get(USER_NAME))); } UserCreationTask(LocalUserCreator localUserCreator); @Override void execute(ImmutableMultimap<String, String> immutableMultimap, PrintWriter printWriter); static final Logger LOG; }