2012-01-19 14:38:44 +00:00
|
|
|
/**
|
2016-01-25 10:16:14 +01:00
|
|
|
* Copyright (C) 2009-2016 Typesafe Inc. <http://www.typesafe.com>
|
2012-01-19 14:38:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package akka.camel
|
|
|
|
|
|
|
|
|
|
import akka.camel.TestSupport.SharedCamelSystem
|
|
|
|
|
import internal.DefaultCamel
|
2013-12-17 14:25:56 +01:00
|
|
|
import org.scalatest.Matchers
|
2012-01-19 14:38:44 +00:00
|
|
|
import org.scalatest.mock.MockitoSugar
|
|
|
|
|
import org.apache.camel.{ CamelContext, ProducerTemplate }
|
|
|
|
|
import org.scalatest.WordSpec
|
|
|
|
|
import akka.event.LoggingAdapter
|
2012-07-22 21:57:27 +02:00
|
|
|
import akka.actor.ActorSystem.Settings
|
|
|
|
|
import com.typesafe.config.ConfigFactory
|
2012-09-03 12:08:46 +02:00
|
|
|
import org.apache.camel.impl.DefaultCamelContext
|
|
|
|
|
import org.apache.camel.spi.Registry
|
2012-09-26 17:12:30 +02:00
|
|
|
import akka.actor.{ ExtendedActorSystem, ActorSystem }
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2013-12-17 14:25:56 +01:00
|
|
|
class DefaultCamelTest extends WordSpec with SharedCamelSystem with Matchers with MockitoSugar {
|
2012-01-19 14:38:44 +00:00
|
|
|
|
|
|
|
|
import org.mockito.Mockito.{ when, verify }
|
2012-09-26 17:12:30 +02:00
|
|
|
val sys = mock[ExtendedActorSystem]
|
2012-07-22 21:57:27 +02:00
|
|
|
val config = ConfigFactory.defaultReference()
|
2012-09-26 17:12:30 +02:00
|
|
|
when(sys.dynamicAccess) thenReturn system.asInstanceOf[ExtendedActorSystem].dynamicAccess
|
2012-07-22 21:57:27 +02:00
|
|
|
when(sys.settings) thenReturn (new Settings(this.getClass.getClassLoader, config, "mocksystem"))
|
|
|
|
|
when(sys.name) thenReturn ("mocksystem")
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2012-07-22 21:57:27 +02:00
|
|
|
def camelWithMocks = new DefaultCamel(sys) {
|
2012-01-19 14:38:44 +00:00
|
|
|
override val log = mock[LoggingAdapter]
|
|
|
|
|
override lazy val template = mock[ProducerTemplate]
|
2012-09-03 12:08:46 +02:00
|
|
|
override lazy val context = mock[DefaultCamelContext]
|
2012-07-22 21:57:27 +02:00
|
|
|
override val settings = mock[CamelSettings]
|
2012-01-19 14:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"during shutdown, when both context and template fail to shutdown" when {
|
2012-07-22 13:27:24 +02:00
|
|
|
val camel = camelWithMocks
|
2012-01-19 14:38:44 +00:00
|
|
|
|
|
|
|
|
when(camel.context.stop()) thenThrow new RuntimeException("context")
|
|
|
|
|
when(camel.template.stop()) thenThrow new RuntimeException("template")
|
|
|
|
|
val exception = intercept[RuntimeException] {
|
|
|
|
|
camel.shutdown()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"throws exception thrown by context.stop()" in {
|
2015-01-16 11:09:59 +01:00
|
|
|
exception.getMessage() should ===("context");
|
2012-01-19 14:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"tries to stop both template and context" in {
|
|
|
|
|
verify(camel.template).stop()
|
|
|
|
|
verify(camel.context).stop()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"during start, if template fails to start, it will stop the context" in {
|
2012-07-22 13:27:24 +02:00
|
|
|
val camel = camelWithMocks
|
2012-01-19 14:38:44 +00:00
|
|
|
|
|
|
|
|
when(camel.template.start()) thenThrow new RuntimeException
|
|
|
|
|
|
|
|
|
|
intercept[RuntimeException] {
|
|
|
|
|
camel.start
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
verify(camel.context).stop()
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|