pekko/akka-camel/src/test/scala/akka/camel/DefaultCamelTest.scala

68 lines
2.1 KiB
Scala
Raw Normal View History

/*
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
package akka.camel
import akka.camel.TestSupport.SharedCamelSystem
import internal.DefaultCamel
import org.scalatest.Matchers
import org.scalatest.mock.MockitoSugar
import org.apache.camel.ProducerTemplate
import org.scalatest.WordSpec
import akka.event.MarkerLoggingAdapter
2012-07-22 21:57:27 +02:00
import akka.actor.ActorSystem.Settings
import com.typesafe.config.ConfigFactory
import org.apache.camel.impl.DefaultCamelContext
import akka.actor.ExtendedActorSystem
class DefaultCamelTest extends WordSpec with SharedCamelSystem with Matchers with MockitoSugar {
2019-03-11 10:38:24 +01:00
import org.mockito.Mockito.{ verify, when }
val sys = mock[ExtendedActorSystem]
2012-07-22 21:57:27 +02:00
val config = ConfigFactory.defaultReference()
2019-03-11 10:38:24 +01:00
when(sys.dynamicAccess).thenReturn(system.asInstanceOf[ExtendedActorSystem].dynamicAccess)
when(sys.settings).thenReturn(new Settings(this.getClass.getClassLoader, config, "mocksystem"))
when(sys.name).thenReturn("mocksystem")
2012-07-22 21:57:27 +02:00
def camelWithMocks = new DefaultCamel(sys) {
override val log = mock[MarkerLoggingAdapter]
override lazy val template = mock[ProducerTemplate]
override lazy val context = mock[DefaultCamelContext]
2012-07-22 21:57:27 +02:00
override val settings = mock[CamelSettings]
}
"during shutdown, when both context and template fail to shutdown" when {
val camel = camelWithMocks
2019-03-11 10:38:24 +01: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 {
exception.getMessage() should ===("context")
}
"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 {
val camel = camelWithMocks
2019-03-11 10:38:24 +01:00
when(camel.template.start()).thenThrow(new RuntimeException)
intercept[RuntimeException] {
camel.start
}
verify(camel.context).stop()
}
2016-02-22 20:18:15 +01:00
}