...
Code Block |
---|
|
public void testRendportIncident() throws Exception {
...
OutputReportIncident out = client.reportIncident(input);
assertEquals("Response code is wrong", "OK", out.getCode());
// give the event driven consumer time to react
Thread.sleep(500010 * 1000);
}
|
We run the test with mvn clean test
and have eyes fixed on the console output.
During all the output in the console, we see that our consumer has been triggered, as we want.
Code Block |
---|
2008-07-19 12:09:24,140 [mponent@1f12c4e] DEBUG FileProcessStrategySupport - Locking the file: target\subfolder\mail-incident-123.txt ...
Sending email...Incident 123 has been reported on the 2008-07-16 by Claus Ibsen.
The person can be contact by:
- email: davsclaus@apache.org
- phone: +45 2962 7576
Summary: bla bla
Details:
more bla bla
This is an auto generated email. You can not reply.
2008-07-19 12:09:24,156 [mponent@1f12c4e] DEBUG FileConsumer - Done processing file: target\subfolder\mail-incident-123.txt. Status is: OK
|
Sending the email
Sending the email requires access to a SMTP mail server, but the implementation code is very simple:
Code Block |
---|
|
private void sendEmail(String body) {
// send the email to your mail server
String url = "smtp://someone@localhost&password=secret&to=incident@localhost.org";
// As we dont have a mail server we disable this code
//template.sendBodyAndHeader(url, body, "subject", "New incident reported");
}
|
And just invoke the method from our consumer:
Code Block |
---|
|
// okay now we are read to send it as an email
System.out.println("Sending email...");
sendEmail(mailBody);
System.out.println("Email sent");
|