Skip to content

Instantly share code, notes, and snippets.

@willemsst
Last active December 24, 2015 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willemsst/6873636 to your computer and use it in GitHub Desktop.
Save willemsst/6873636 to your computer and use it in GitHub Desktop.
working akka smtp-camel actor test
package be.idevelop.opencom.smtp.server.actor
import akka.actor.ActorRef
import akka.actor.ActorSystem
import akka.camel.Camel
import akka.camel.CamelExtension
import akka.util.Timeout
import be.idevelop.opencom.util.Condition
import org.apache.camel.CamelContext
import org.apache.camel.component.james.smtp.SMTPComponent
import org.apache.camel.impl.DefaultCamelContext
import org.apache.commons.mail.SimpleEmail
import scala.concurrent.Future
import scala.concurrent.duration.Duration
import spock.lang.Ignore
import spock.lang.Specification
import static be.idevelop.opencom.util.WaitCondition.waitFor
import static java.util.concurrent.TimeUnit.SECONDS
class SmtpActorTest extends Specification {
def 'test send and receive real email'() {
given:
def system = ActorSystem.create("SMTP-unit-test")
Camel camel = CamelExtension.get(system)
Timeout timeout = new Timeout(Duration.create(15, SECONDS));
def smtpConsumer = system.actorOf(SmtpActor.create(system))
Future<ActorRef> activationFuture = camel.activationFutureFor(smtpConsumer, timeout, system.dispatcher());
waitFor({ activationFuture.completed } as Condition)
SimpleEmail email = new SimpleEmail()
email.setHostName('localhost')
email.setDebug(true)
email.setSmtpPort(25052)
email.setFrom('steven@opencom.io')
email.addTo('receiver@opencom.io')
email.setMsg('Test message')
when:
email.send()
then:
notThrown(Exception.class)
cleanup:
system.shutdown()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment