Search in sources :

Example 6 with ValidationBean

use of com.thoughtworks.go.domain.materials.ValidationBean in project gocd by gocd.

the class ServerConfigService method sendTestMail.

public void sendTestMail(MailHost mailHost, LocalizedOperationResult result) {
    validate(mailHost, result);
    if (!result.isSuccessful()) {
        return;
    }
    GoMailSender sender = provider.createSender(mailHost);
    ValidationBean validationBean = sender.send(TEST_EMAIL_SUBJECT, GoSmtpMailSender.emailBody(), mailHost.getAdminMail());
    if (!validationBean.isValid()) {
        result.notAcceptable(LocalizedMessage.string("FAILED_TO_SEND_TEST_MAIL", validationBean.getError()));
    }
}
Also used : ValidationBean(com.thoughtworks.go.domain.materials.ValidationBean)

Example 7 with ValidationBean

use of com.thoughtworks.go.domain.materials.ValidationBean in project gocd by gocd.

the class GoSmtpMailSenderTest method shouldSet_MailFrom_Property.

@Test
public void shouldSet_MailFrom_Property() throws Exception {
    FakeMailSession mailSession = FakeMailSession.setupFor(username, password, from, to, subject, body);
    GoSmtpMailSender sender = new GoSmtpMailSender(hostName, port, username, password, true, from, to);
    ValidationBean bean = sender.send(subject, body, to);
    assertThat(bean, is(ValidationBean.valid()));
    mailSession.verifyMessageWasSent();
    mailSession.verifyProperty(MAIL_FROM_PROPERTY, from);
}
Also used : ValidationBean(com.thoughtworks.go.domain.materials.ValidationBean) Test(org.junit.Test)

Example 8 with ValidationBean

use of com.thoughtworks.go.domain.materials.ValidationBean in project gocd by gocd.

the class GoSmtpMailSenderTest method shouldSetProtocolToSMTPWhenSMTPSIsDisabled.

@Test
public void shouldSetProtocolToSMTPWhenSMTPSIsDisabled() throws Exception {
    FakeMailSession mailSession = FakeMailSession.setupFor(username, password, from, to, subject, body);
    boolean isSMTPSEnabled = false;
    GoSmtpMailSender sender = new GoSmtpMailSender(hostName, port, username, password, isSMTPSEnabled, from, to);
    ValidationBean bean = sender.send(subject, body, to);
    assertThat(bean, is(ValidationBean.valid()));
    mailSession.verifyMessageWasSent();
    mailSession.verifyProperty(MAIL_TRANSPORT_PROTOCOL_PROPERTY, "smtp");
}
Also used : ValidationBean(com.thoughtworks.go.domain.materials.ValidationBean) Test(org.junit.Test)

Example 9 with ValidationBean

use of com.thoughtworks.go.domain.materials.ValidationBean in project gocd by gocd.

the class GoSmtpMailSenderTest method testShouldNotSendOutTestEmailToAdminstrator.

@Test
public void testShouldNotSendOutTestEmailToAdminstrator() {
    GoSmtpMailSender sender = new GoSmtpMailSender(hostName, 465, to, password, true, from, to);
    ValidationBean bean = sender.send(subject, body, to);
    assertThat(bean, is(not(ValidationBean.valid())));
}
Also used : ValidationBean(com.thoughtworks.go.domain.materials.ValidationBean) Test(org.junit.Test)

Example 10 with ValidationBean

use of com.thoughtworks.go.domain.materials.ValidationBean in project gocd by gocd.

the class GoSmtpMailSenderTest method shouldSetDefaultMailTimeoutPropertiesWhenNoOverridingValuesAreProvided.

@Test
public void shouldSetDefaultMailTimeoutPropertiesWhenNoOverridingValuesAreProvided() throws Exception {
    FakeMailSession mailSession = FakeMailSession.setupFor(username, password, from, to, subject, body);
    GoSmtpMailSender sender = new GoSmtpMailSender(hostName, port, username, password, true, from, to);
    ValidationBean bean = sender.send(subject, body, to);
    assertThat(bean, is(ValidationBean.valid()));
    mailSession.verifyMessageWasSent();
    mailSession.verifyProperty(SMTP_CONNECTIONTIMEOUT_PROPERTY, GoConstants.DEFAULT_TIMEOUT);
    mailSession.verifyProperty(SMTP_TIMEOUT_PROPERTY, GoConstants.DEFAULT_TIMEOUT);
}
Also used : ValidationBean(com.thoughtworks.go.domain.materials.ValidationBean) Test(org.junit.Test)

Aggregations

ValidationBean (com.thoughtworks.go.domain.materials.ValidationBean)25 Test (org.junit.Test)22 TestSubprocessExecutionContext (com.thoughtworks.go.domain.materials.TestSubprocessExecutionContext)2 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)1 GoMailSender (com.thoughtworks.go.config.GoMailSender)1 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)1 Expectations (org.jmock.Expectations)1 Theory (org.junit.experimental.theories.Theory)1