Search in sources :

Example 21 with ValidationBean

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

the class GoSmtpMailSenderTest method shouldSendAMailWhenValidationSucceeds.

@Test
public void shouldSendAMailWhenValidationSucceeds() 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.verifyThatConnectionWasMadeTo(hostName, port, username, password);
    mailSession.verifyMessageWasSent();
    mailSession.verifyTransportWasClosed();
}
Also used : ValidationBean(com.thoughtworks.go.domain.materials.ValidationBean) Test(org.junit.Test)

Example 22 with ValidationBean

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

the class GoSmtpMailSenderTest method shouldSetProtocolToSMTPSWhenSMTPSIsEnabled.

@Test
public void shouldSetProtocolToSMTPSWhenSMTPSIsEnabled() throws Exception {
    FakeMailSession mailSession = FakeMailSession.setupFor(username, password, from, to, subject, body);
    boolean isSMTPSEnabled = true;
    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, "smtps");
}
Also used : ValidationBean(com.thoughtworks.go.domain.materials.ValidationBean) Test(org.junit.Test)

Example 23 with ValidationBean

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

the class P4MaterialTestBase method shouldValidateCorrectConnection.

@Test
public void shouldValidateCorrectConnection() throws Exception {
    P4Material p4Material = p4Fixture.material(VIEW);
    p4Material.setPassword("secret");
    p4Material.setUseTickets(false);
    ValidationBean validation = p4Material.checkConnection(new TestSubprocessExecutionContext());
    assertThat(validation.isValid(), is(true));
    assertThat(StringUtils.isBlank(validation.getError()), is(true));
}
Also used : TestSubprocessExecutionContext(com.thoughtworks.go.domain.materials.TestSubprocessExecutionContext) ValidationBean(com.thoughtworks.go.domain.materials.ValidationBean) Test(org.junit.Test)

Example 24 with ValidationBean

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

the class EmailNotificationListener method onMessage.

public void onMessage(SendEmailMessage message) {
    CruiseConfig cruiseConfig = goConfigService.currentCruiseConfig();
    if (!cruiseConfig.isMailHostConfigured()) {
        return;
    }
    GoMailSender mailSender = factory.createSender();
    ValidationBean validationBean = mailSender.send(message.getSubject(), message.getBody(), message.getTo());
    if (!validationBean.isValid()) {
        LOGGER.error(validationBean.getError());
    }
}
Also used : GoMailSender(com.thoughtworks.go.config.GoMailSender) ValidationBean(com.thoughtworks.go.domain.materials.ValidationBean) CruiseConfig(com.thoughtworks.go.config.CruiseConfig)

Example 25 with ValidationBean

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

the class MaterialConnectivityServiceTest method shouldCheckConnections.

@Theory
public void shouldCheckConnections(RequestDataPoints dataPoints) throws Exception {
    MaterialConfig config = dataPoints.material.config();
    MaterialConnectivityService spy = spy(service);
    doReturn(dataPoints.klass).when(spy).getMaterialClass(dataPoints.material);
    doReturn(dataPoints.material).when(materialConfigConverter).toMaterial(config);
    ValidationBean actual = spy.checkConnection(config, executionContext);
    assertThat(actual, is(dataPoints.expectedResult));
}
Also used : MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) ValidationBean(com.thoughtworks.go.domain.materials.ValidationBean) Theory(org.junit.experimental.theories.Theory)

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