SmtpOnlyToAddresParser implements ToAddressParser { @Override public Set<Address> parse(String addresses, DirectDocuments documents) { Set<Address> addressTo = new HashSet<>(); List<String> forwards = new ArrayList<>(); if (null != addresses && StringUtils.isNotBlank(addresses)) { try { forwards = Arrays.asList(new URI(addresses).getSchemeSpecificPart()); } catch (URISyntaxException e) { LOG.error("Unable to parse Direct To header, attempting to parse XDR intended recipients: " + e.getLocalizedMessage(), e); } } else if (documents != null && documents.getSubmissionSet() != null) { forwards = ParserHL7.parseDirectRecipients(documents); } if (CollectionUtils.isNotEmpty(forwards) && getResolver().hasSmtpEndpoints(forwards)) { for (String recipient : getResolver().getSmtpEndpoints(forwards)) { try { addressTo.add(new InternetAddress(recipient)); } catch (AddressException e) { LOG.error("Unable to convert " + recipient + " to an InternetAdress: " + e.getLocalizedMessage(), e); } } } else { throw new DirectException("There were no SMTP endpoints provided."); } return addressTo; }  @Override Set<Address> parse(String addresses, DirectDocuments documents);  }
@Test public void testParseHappy1() { String addresses = "test@connectopensource.org"; DirectDocuments documents = null; SmtpOnlyToAddresParser instance = new SmtpOnlyToAddresParser(); Set result = instance.parse(addresses, documents); assertNotNull(result); }
@Test public void testParseHappy2() { String addresses = null; DirectDocuments documents = new DirectDocuments(); SubmissionSet oSubmissionSet = new SubmissionSet(); String intendentRcpt = "||^^^vlewis@lewistower.com"; oSubmissionSet.getIntendedRecipient().add(intendentRcpt); documents.setSubmissionSet(oSubmissionSet); SmtpOnlyToAddresParser instance = new SmtpOnlyToAddresParser(); Set result = instance.parse(addresses, documents); assertNotNull(result); }
@Test(expected = DirectException.class) public void testParseFailure() { String addresses = null; DirectDocuments documents = mock(DirectDocuments.class); SubmissionSet submissionSet = mock(SubmissionSet.class); Set result = null; SmtpOnlyToAddresParser instance = new SmtpOnlyToAddresParser(); when(documents.getSubmissionSet()).thenReturn(submissionSet); when(submissionSet.getIntendedRecipient()).thenReturn(new ArrayList<String>()); try { result = instance.parse(addresses, documents); } catch (DirectException e) { System.out.println(e.getMessage()); assertEquals(e.getMessage(), "There were no SMTP endpoints provided."); throw e; } }