Search in sources :

Example 1 with Property

use of org.simplejavamail.config.ConfigLoader.Property in project simple-java-mail by bbottema.

the class EmailPopulatingBuilderImpl2Test method testConstructorApplyingPreconfiguredDefaults_EmbeddedImageResolving_IgnoreFailure.

@Test
public void testConstructorApplyingPreconfiguredDefaults_EmbeddedImageResolving_IgnoreFailure() throws Exception {
    assumeThat(getUrl("https://www.simplejavamail.org")).isEqualTo(HttpURLConnection.HTTP_OK);
    HashedMap<Property, Object> value = new HashedMap<>();
    value.put(EMBEDDEDIMAGES_DYNAMICRESOLUTION_ENABLE_DIR, "true");
    value.put(EMBEDDEDIMAGES_DYNAMICRESOLUTION_ENABLE_CLASSPATH, "true");
    value.put(EMBEDDEDIMAGES_DYNAMICRESOLUTION_ENABLE_URL, "true");
    value.put(EMBEDDEDIMAGES_DYNAMICRESOLUTION_BASE_DIR, RESOURCES_PATH);
    value.put(EMBEDDEDIMAGES_DYNAMICRESOLUTION_BASE_URL, "https://www.simplejavamail.org");
    value.put(EMBEDDEDIMAGES_DYNAMICRESOLUTION_BASE_CLASSPATH, "/pkcs12");
    value.put(EMBEDDEDIMAGES_DYNAMICRESOLUTION_MUSTBESUCCESFUL, "false");
    ConfigLoaderTestHelper.setResolvedProperties(value);
    final Email email = EmailBuilder.startingBlank().withHTMLText("<img src=\"cid:cid_name\"/>").appendTextHTML("<img src=\"missing.html\"/>").appendTextHTML("<img src=\"/missing.html\"/>").appendTextHTML("<img src=\"missing.xml\"/>").buildEmail();
    assertThat(email.getEmbeddedImages()).isEmpty();
}
Also used : Email(org.simplejavamail.api.email.Email) HashedMap(org.apache.commons.collections4.map.HashedMap) Property(org.simplejavamail.config.ConfigLoader.Property) Test(org.junit.Test)

Example 2 with Property

use of org.simplejavamail.config.ConfigLoader.Property in project simple-java-mail by bbottema.

the class EmailPopulatingBuilderImpl2Test method testConstructorApplyingPreconfiguredDefaults_EmbeddedImageResolving_BubbleFailure.

@Test
public void testConstructorApplyingPreconfiguredDefaults_EmbeddedImageResolving_BubbleFailure() throws Exception {
    assumeThat(getUrl("https://www.simplejavamail.org")).isEqualTo(HttpURLConnection.HTTP_OK);
    HashedMap<Property, Object> value = new HashedMap<>();
    value.put(EMBEDDEDIMAGES_DYNAMICRESOLUTION_ENABLE_DIR, "true");
    value.put(EMBEDDEDIMAGES_DYNAMICRESOLUTION_ENABLE_CLASSPATH, "true");
    value.put(EMBEDDEDIMAGES_DYNAMICRESOLUTION_ENABLE_URL, "true");
    value.put(EMBEDDEDIMAGES_DYNAMICRESOLUTION_BASE_DIR, RESOURCES_PATH);
    value.put(EMBEDDEDIMAGES_DYNAMICRESOLUTION_BASE_URL, "https://www.simplejavamail.org");
    value.put(EMBEDDEDIMAGES_DYNAMICRESOLUTION_BASE_CLASSPATH, "/pkcs12");
    value.put(EMBEDDEDIMAGES_DYNAMICRESOLUTION_MUSTBESUCCESFUL, "true");
    ConfigLoaderTestHelper.setResolvedProperties(value);
    final EmailPopulatingBuilder emailPopulatingBuilder = EmailBuilder.startingBlank().withHTMLText("<img src=\"cid:cid_name\"/>").appendTextHTML("<img src=\"missing.html\"/>");
    assertThatThrownBy(emailPopulatingBuilder::buildEmail).isInstanceOf(EmailException.class).hasMessage("Unable to dynamically resolve data source for the following image src: missing.html");
}
Also used : EmailPopulatingBuilder(org.simplejavamail.api.email.EmailPopulatingBuilder) HashedMap(org.apache.commons.collections4.map.HashedMap) Property(org.simplejavamail.config.ConfigLoader.Property) Test(org.junit.Test)

Example 3 with Property

use of org.simplejavamail.config.ConfigLoader.Property in project simple-java-mail by bbottema.

the class EmailPopulatingBuilderImpl2Test method testConstructorApplyingPreconfiguredDefaults_EmbeddedImageResolving.

@Test
public void testConstructorApplyingPreconfiguredDefaults_EmbeddedImageResolving() throws Exception {
    assumeThat(getUrl("https://www.simplejavamail.org")).isEqualTo(HttpURLConnection.HTTP_OK);
    HashedMap<Property, Object> value = new HashedMap<>();
    value.put(EMBEDDEDIMAGES_DYNAMICRESOLUTION_ENABLE_DIR, "true");
    value.put(EMBEDDEDIMAGES_DYNAMICRESOLUTION_ENABLE_CLASSPATH, "true");
    value.put(EMBEDDEDIMAGES_DYNAMICRESOLUTION_ENABLE_URL, "true");
    value.put(EMBEDDEDIMAGES_DYNAMICRESOLUTION_BASE_DIR, RESOURCES_PATH);
    value.put(EMBEDDEDIMAGES_DYNAMICRESOLUTION_BASE_URL, "https://www.simplejavamail.org");
    value.put(EMBEDDEDIMAGES_DYNAMICRESOLUTION_BASE_CLASSPATH, "/pkcs12");
    ConfigLoaderTestHelper.setResolvedProperties(value);
    Email email = EmailBuilder.startingBlank().withHTMLText("<img src=\"cid:cid_name\"/>").appendTextHTML(// comes from simplejavamail.org
    "<img src=\"download.html\"/>").appendTextHTML(// comes from classpath
    "<img src=\"/how-to.html\"/>").appendTextHTML(// comes from folder
    "<img src=\"log4j2.xml\"/>").buildEmail();
    assertThat(email.getEmbeddedImages()).extracting(new DatasourceReadingExtractor()).containsExactlyInAnyOrder(DOWNLOAD_SIMPLE_JAVA_MAIL, CREATE_SELF_SIGNED_S_MIME_CERTIFICATES, CONSOLE_NAME_CONSOLE_TARGET_SYSTEM_OUT);
}
Also used : Email(org.simplejavamail.api.email.Email) HashedMap(org.apache.commons.collections4.map.HashedMap) Property(org.simplejavamail.config.ConfigLoader.Property) Test(org.junit.Test)

Example 4 with Property

use of org.simplejavamail.config.ConfigLoader.Property in project simple-java-mail by bbottema.

the class EmailPopulatingBuilderImpl2Test method testConstructorApplyingPreconfiguredDefaults2.

@Test
public void testConstructorApplyingPreconfiguredDefaults2() throws Exception {
    HashedMap<Property, Object> value = new HashedMap<>();
    value.put(DEFAULT_FROM_ADDRESS, "test_from@domain.com");
    value.put(DEFAULT_REPLYTO_ADDRESS, "test_replyto@domain.com");
    value.put(DEFAULT_BOUNCETO_ADDRESS, "test_boundeto@domain.com");
    value.put(DEFAULT_TO_ADDRESS, "test_to1@domain.com,test_to2@domain.com");
    value.put(DEFAULT_CC_ADDRESS, "test_cc1@domain.com,test_cc2@domain.com");
    value.put(DEFAULT_BCC_ADDRESS, "test_bcc1@domain.com,test_bcc2@domain.com");
    value.put(SMIME_ENCRYPTION_CERTIFICATE, "src/test/resources/pkcs12/smime_test_user.pem.standard.crt");
    ConfigLoaderTestHelper.setResolvedProperties(value);
    Email email = EmailBuilder.startingBlank().buildEmail();
    EmailAssert.assertThat(email).hasFromRecipient(new Recipient(null, "test_from@domain.com", null)).hasReplyToRecipient(new Recipient(null, "test_replyto@domain.com", null)).hasBounceToRecipient(new Recipient(null, "test_boundeto@domain.com", null)).hasRecipients(new Recipient(null, "test_to1@domain.com", TO), new Recipient(null, "test_to2@domain.com", TO), new Recipient(null, "test_cc1@domain.com", CC), new Recipient(null, "test_cc2@domain.com", CC), new Recipient(null, "test_bcc1@domain.com", BCC), new Recipient(null, "test_bcc2@domain.com", BCC));
    assertThat(email.getX509CertificateForSmimeEncryption()).isNotNull();
}
Also used : Email(org.simplejavamail.api.email.Email) Recipient(org.simplejavamail.api.email.Recipient) HashedMap(org.apache.commons.collections4.map.HashedMap) Property(org.simplejavamail.config.ConfigLoader.Property) Test(org.junit.Test)

Example 5 with Property

use of org.simplejavamail.config.ConfigLoader.Property in project simple-java-mail by bbottema.

the class EmailPopulatingBuilderImpl2Test method testConstructorApplyingPreconfiguredDefaults1.

@Test
public void testConstructorApplyingPreconfiguredDefaults1() throws Exception {
    Map<Property, Object> value = new HashedMap<>();
    value.put(DEFAULT_FROM_ADDRESS, "test_from@domain.com");
    value.put(DEFAULT_FROM_NAME, "Test From");
    value.put(DEFAULT_REPLYTO_ADDRESS, "test_replyto@domain.com");
    value.put(DEFAULT_REPLYTO_NAME, "Test Replyto");
    value.put(DEFAULT_BOUNCETO_ADDRESS, "test_boundeto@domain.com");
    value.put(DEFAULT_BOUNCETO_NAME, "Test Bounceto");
    value.put(DEFAULT_TO_ADDRESS, "test_to1@domain.com,test_to2@domain.com");
    value.put(DEFAULT_TO_NAME, "test TO name");
    value.put(DEFAULT_CC_ADDRESS, "test_cc1@domain.com,test_cc2@domain.com");
    value.put(DEFAULT_CC_NAME, "test CC name");
    value.put(DEFAULT_BCC_ADDRESS, "test_bcc1@domain.com,test_bcc2@domain.com");
    value.put(DEFAULT_BCC_NAME, "test BCC name");
    value.put(DEFAULT_SUBJECT, "test subject");
    value.put(SMIME_SIGNING_KEYSTORE, "src/test/resources/pkcs12/smime_keystore.pkcs12");
    value.put(SMIME_SIGNING_KEYSTORE_PASSWORD, "letmein");
    value.put(SMIME_SIGNING_KEY_ALIAS, "smime_test_user_alias");
    value.put(SMIME_SIGNING_KEY_PASSWORD, "letmein");
    ConfigLoaderTestHelper.setResolvedProperties(value);
    EmailAssert.assertThat(EmailBuilder.startingBlank().buildEmail()).hasFromRecipient(new Recipient("Test From", "test_from@domain.com", null)).hasReplyToRecipient(new Recipient("Test Replyto", "test_replyto@domain.com", null)).hasBounceToRecipient(new Recipient("Test Bounceto", "test_boundeto@domain.com", null)).hasRecipients(new Recipient("test TO name", "test_to1@domain.com", TO), new Recipient("test TO name", "test_to2@domain.com", TO), new Recipient("test CC name", "test_cc1@domain.com", CC), new Recipient("test CC name", "test_cc2@domain.com", CC), new Recipient("test BCC name", "test_bcc1@domain.com", BCC), new Recipient("test BCC name", "test_bcc2@domain.com", BCC)).hasSubject("test subject").hasPkcs12ConfigForSmimeSigning(null);
}
Also used : Recipient(org.simplejavamail.api.email.Recipient) HashedMap(org.apache.commons.collections4.map.HashedMap) Property(org.simplejavamail.config.ConfigLoader.Property) Test(org.junit.Test)

Aggregations

HashedMap (org.apache.commons.collections4.map.HashedMap)5 Test (org.junit.Test)5 Property (org.simplejavamail.config.ConfigLoader.Property)5 Email (org.simplejavamail.api.email.Email)3 Recipient (org.simplejavamail.api.email.Recipient)2 EmailPopulatingBuilder (org.simplejavamail.api.email.EmailPopulatingBuilder)1