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));
}
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));
}
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);
}
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));
}
}
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));
}
}
Aggregations