Search in sources :

Example 1 with EMailMessageModel

use of io.syndesis.connector.email.model.EMailMessageModel in project syndesis by syndesisio.

the class EMailSendRouteTest method testPriorityOfValuesInputtedValues.

@Test
public void testPriorityOfValuesInputtedValues() throws Exception {
    server = smtpServer();
    Step directStep = createDirectStep();
    Connector mailConnector = RouteUtils.createEMailConnector(server, new PropertyBuilder<String>().property(PROTOCOL, Protocol.SMTP.id()).property(HOST, server.getHost()).property(PORT, Integer.toString(server.getPort())).property(USER, TEST_ADDRESS).property(PASSWORD, TEST_PASSWORD));
    EMailMessageModel injectedDataModel = new EMailMessageModel();
    injectedDataModel.setSubject("Injected Data Email 1");
    injectedDataModel.setFrom(TEST_ADDRESS);
    injectedDataModel.setTo(TEST_ADDRESS);
    injectedDataModel.setContent("Hello, this is an email from injected data!\r\n");
    String inputValueSubject = "Input Values Email 1";
    String inputValueText = "Hello, this is an email using inputted values!\r\n";
    // 
    // Change the integration's priority to prefer input values if present
    // 
    PropertyBuilder<String> builder = new PropertyBuilder<>();
    builder.property(PRIORITY, Priority.INPUT_VALUES.toString());
    builder.property(MAIL_SUBJECT, inputValueSubject);
    builder.property(MAIL_TEXT, inputValueText);
    Step mailStep = RouteUtils.createEMailStep(mailConnector, this::createConnectorAction, builder.build());
    Integration mailIntegration = RouteUtils.createIntegrationWithMock(directStep, mailStep);
    RouteBuilder routes = RouteUtils.newIntegrationRouteBuilder(mailIntegration);
    context.start();
    context.addRoutes(routes);
    MockEndpoint result = RouteUtils.initMockEndpoint(context);
    result.setExpectedMessageCount(1);
    DirectEndpoint directEndpoint = context.getEndpoint("direct://start", DirectEndpoint.class);
    ProducerTemplate template = context.createProducerTemplate();
    // 
    // Sending through injected data model as if consumed from another connection
    // 
    template.sendBody(directEndpoint, injectedDataModel);
    result.assertIsSatisfied();
    List<EMailMessageModel> emails = server.getEmails();
    assertEquals(1, emails.size());
    // 
    // The email looks like injectedData but retains
    // the subject & text specified by the input values
    // 
    EMailMessageModel expectedModel = new EMailMessageModel();
    expectedModel.setSubject(inputValueSubject);
    expectedModel.setFrom(injectedDataModel.getFrom());
    expectedModel.setTo(injectedDataModel.getTo());
    expectedModel.setContent(inputValueText);
    assertEquals(expectedModel, emails.get(0));
}
Also used : Connector(io.syndesis.common.model.connection.Connector) ProducerTemplate(org.apache.camel.ProducerTemplate) Integration(io.syndesis.common.model.integration.Integration) EMailMessageModel(io.syndesis.connector.email.model.EMailMessageModel) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) DirectEndpoint(org.apache.camel.component.direct.DirectEndpoint) Step(io.syndesis.common.model.integration.Step) PropertyBuilder(io.syndesis.connector.support.util.PropertyBuilder) AbstractEmailServerTest(io.syndesis.connector.email.AbstractEmailServerTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with EMailMessageModel

use of io.syndesis.connector.email.model.EMailMessageModel in project syndesis by syndesisio.

the class EMailSendRouteTest method testPriorityOfValuesInjectedData.

@Test
public void testPriorityOfValuesInjectedData() throws Exception {
    server = smtpServer();
    Step directStep = createDirectStep();
    Connector mailConnector = RouteUtils.createEMailConnector(server, new PropertyBuilder<String>().property(PROTOCOL, Protocol.SMTP.id()).property(HOST, server.getHost()).property(PORT, Integer.toString(server.getPort())).property(USER, TEST_ADDRESS).property(PASSWORD, TEST_PASSWORD));
    EMailMessageModel injectedDataModel = new EMailMessageModel();
    injectedDataModel.setSubject("Injected Data Email 1");
    injectedDataModel.setFrom(TEST_ADDRESS);
    injectedDataModel.setTo(TEST_ADDRESS);
    injectedDataModel.setContent("Hello, this is an email from injected data!\r\n");
    String inputValueSubject = "Input Values Email 1";
    String inputValueText = "Hello, this is an email using inputted values!";
    PropertyBuilder<String> builder = new PropertyBuilder<>();
    builder.property(PRIORITY, Priority.CONSUMED_DATA.toString());
    builder.property(MAIL_SUBJECT, inputValueSubject);
    builder.property(MAIL_TEXT, inputValueText);
    Step mailStep = RouteUtils.createEMailStep(mailConnector, this::createConnectorAction, builder.build());
    Integration mailIntegration = RouteUtils.createIntegrationWithMock(directStep, mailStep);
    RouteBuilder routes = RouteUtils.newIntegrationRouteBuilder(mailIntegration);
    context.start();
    context.addRoutes(routes);
    MockEndpoint result = RouteUtils.initMockEndpoint(context);
    result.setExpectedMessageCount(1);
    DirectEndpoint directEndpoint = context.getEndpoint("direct://start", DirectEndpoint.class);
    ProducerTemplate template = context.createProducerTemplate();
    // 
    // Sending through injected data model as if consumed from another connection
    // 
    template.sendBody(directEndpoint, injectedDataModel);
    result.assertIsSatisfied();
    List<EMailMessageModel> emails = server.getEmails();
    assertEquals(1, emails.size());
    // 
    // The email is consistent with the injected data and has overridden
    // the values set by the inputted values
    // 
    assertEquals(injectedDataModel, emails.get(0));
}
Also used : Connector(io.syndesis.common.model.connection.Connector) ProducerTemplate(org.apache.camel.ProducerTemplate) Integration(io.syndesis.common.model.integration.Integration) EMailMessageModel(io.syndesis.connector.email.model.EMailMessageModel) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) DirectEndpoint(org.apache.camel.component.direct.DirectEndpoint) Step(io.syndesis.common.model.integration.Step) PropertyBuilder(io.syndesis.connector.support.util.PropertyBuilder) AbstractEmailServerTest(io.syndesis.connector.email.AbstractEmailServerTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with EMailMessageModel

use of io.syndesis.connector.email.model.EMailMessageModel in project syndesis by syndesisio.

the class EMailReceiveCustomizer method beforeConsumer.

private static void beforeConsumer(Exchange exchange) throws MessagingException, IOException {
    final Message in = exchange.getIn();
    final EMailMessageModel mail = new EMailMessageModel();
    if (ObjectHelper.isNotEmpty(in.getBody())) {
        textFromMessage(in, mail);
    }
    if (ObjectHelper.isNotEmpty(in.getHeader(MAIL_SUBJECT))) {
        mail.setSubject(in.getHeader(MAIL_SUBJECT, String.class));
    }
    if (ObjectHelper.isNotEmpty(in.getHeader(MAIL_FROM))) {
        mail.setFrom(in.getHeader(MAIL_FROM, String.class));
    }
    if (ObjectHelper.isNotEmpty(in.getHeader(MAIL_TO))) {
        mail.setTo(in.getHeader(MAIL_TO, String.class));
    }
    if (ObjectHelper.isNotEmpty(in.getHeader(MAIL_CC))) {
        mail.setCc(in.getHeader(MAIL_CC, String.class));
    }
    if (ObjectHelper.isNotEmpty(in.getHeader(MAIL_BCC))) {
        mail.setBcc(in.getHeader(MAIL_BCC, String.class));
    }
    exchange.getIn().setBody(mail);
}
Also used : EMailMessageModel(io.syndesis.connector.email.model.EMailMessageModel) Message(org.apache.camel.Message)

Example 4 with EMailMessageModel

use of io.syndesis.connector.email.model.EMailMessageModel in project syndesis by syndesisio.

the class EMailReadRouteTest method testImapEMailRouteWithFolder.

@Test
public void testImapEMailRouteWithFolder() throws Exception {
    server = imapServer();
    server.generateFolder(TEST_ADDRESS, TEST_PASSWORD, TEST_FOLDER);
    Connector mailConnector = RouteUtils.createEMailConnector(server, new PropertyBuilder<String>().property(PROTOCOL, Protocol.IMAP.id()).property(HOST, server.getHost()).property(PORT, Integer.toString(server.getPort())).property(USER, TEST_ADDRESS).property(PASSWORD, TEST_PASSWORD).property(FOLDER, TEST_FOLDER));
    Step mailStep = RouteUtils.createEMailStep(mailConnector, this::createConnectorAction);
    Integration mailIntegration = RouteUtils.createIntegrationWithMock(mailStep);
    RouteBuilder routes = RouteUtils.newIntegrationRouteBuilder(mailIntegration);
    context.start();
    context.addRoutes(routes);
    MockEndpoint result = RouteUtils.initMockEndpoint(context);
    result.setAssertPeriod(2000L);
    result.setMinimumExpectedMessageCount(server.getEmailCountInFolder(TEST_ADDRESS, TEST_PASSWORD, TEST_FOLDER));
    result.assertIsSatisfied();
    List<EMailMessageModel> emails = server.getEmailsInFolder(TEST_ADDRESS, TEST_PASSWORD, TEST_FOLDER);
    for (int i = 0; i < emails.size(); ++i) {
        RouteUtils.testResult(result, i, emails.get(i));
    }
}
Also used : Connector(io.syndesis.common.model.connection.Connector) Integration(io.syndesis.common.model.integration.Integration) EMailMessageModel(io.syndesis.connector.email.model.EMailMessageModel) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Step(io.syndesis.common.model.integration.Step) Endpoint(org.apache.camel.Endpoint) MailEndpoint(org.apache.camel.component.mail.MailEndpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) AbstractEmailServerTest(io.syndesis.connector.email.AbstractEmailServerTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with EMailMessageModel

use of io.syndesis.connector.email.model.EMailMessageModel in project syndesis by syndesisio.

the class EMailReadRouteTest method testImapsEMailRoute.

@Test
public void testImapsEMailRoute() throws Exception {
    server = imapsServer();
    Connector mailConnector = RouteUtils.createEMailConnector(server, new PropertyBuilder<String>().property(PROTOCOL, Protocol.IMAP.id()).property(SECURE_TYPE, SecureType.SSL_TLS.id()).property(HOST, server.getHost()).property(PORT, Integer.toString(server.getPort())).property(USER, TEST_ADDRESS).property(PASSWORD, TEST_PASSWORD).property(SERVER_CERTIFICATE, server.getCertificate()));
    Step mailStep = RouteUtils.createEMailStep(mailConnector, this::createConnectorAction);
    Integration mailIntegration = RouteUtils.createIntegrationWithMock(mailStep);
    RouteBuilder routes = RouteUtils.newIntegrationRouteBuilder(mailIntegration);
    context.start();
    context.addRoutes(routes);
    MockEndpoint result = RouteUtils.initMockEndpoint(context);
    result.setMinimumExpectedMessageCount(server.getEmailCount());
    RouteUtils.assertSatisfied(result);
    List<EMailMessageModel> emails = server.getEmails();
    for (int i = 0; i < emails.size(); ++i) {
        RouteUtils.testResult(result, i, emails.get(i));
    }
}
Also used : Connector(io.syndesis.common.model.connection.Connector) Integration(io.syndesis.common.model.integration.Integration) EMailMessageModel(io.syndesis.connector.email.model.EMailMessageModel) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Step(io.syndesis.common.model.integration.Step) Endpoint(org.apache.camel.Endpoint) MailEndpoint(org.apache.camel.component.mail.MailEndpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) PropertyBuilder(io.syndesis.connector.support.util.PropertyBuilder) AbstractEmailServerTest(io.syndesis.connector.email.AbstractEmailServerTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

EMailMessageModel (io.syndesis.connector.email.model.EMailMessageModel)18 Connector (io.syndesis.common.model.connection.Connector)12 Integration (io.syndesis.common.model.integration.Integration)12 Step (io.syndesis.common.model.integration.Step)12 AbstractEmailServerTest (io.syndesis.connector.email.AbstractEmailServerTest)12 RouteBuilder (org.apache.camel.builder.RouteBuilder)12 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)12 Test (org.junit.Test)12 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)12 PropertyBuilder (io.syndesis.connector.support.util.PropertyBuilder)11 Endpoint (org.apache.camel.Endpoint)6 MailEndpoint (org.apache.camel.component.mail.MailEndpoint)6 ProducerTemplate (org.apache.camel.ProducerTemplate)5 DirectEndpoint (org.apache.camel.component.direct.DirectEndpoint)5 ArrayList (java.util.ArrayList)2 MimeMessage (javax.mail.internet.MimeMessage)2 Exchange (org.apache.camel.Exchange)2 Message (org.apache.camel.Message)2 SmtpServer (com.icegreen.greenmail.smtp.SmtpServer)1 IOException (java.io.IOException)1