diff --git a/akka-camel/src/main/scala/akka/camel/CamelSupport.scala b/akka-camel/src/main/scala/akka/camel/CamelSupport.scala index fe92673f84..decdd720ed 100644 --- a/akka-camel/src/main/scala/akka/camel/CamelSupport.scala +++ b/akka-camel/src/main/scala/akka/camel/CamelSupport.scala @@ -10,7 +10,7 @@ private[camel] trait CamelSupport { this: Actor ⇒ /** * For internal use only. Returns a [[akka.camel.Camel]] trait which provides access to the CamelExtension. */ - protected def camel = CamelExtension(context.system) + protected val camel = CamelExtension(context.system) /** * Returns the CamelContext. diff --git a/akka-camel/src/main/scala/akka/camel/internal/DefaultCamel.scala b/akka-camel/src/main/scala/akka/camel/internal/DefaultCamel.scala index a596a869ce..8d207f3b7d 100644 --- a/akka-camel/src/main/scala/akka/camel/internal/DefaultCamel.scala +++ b/akka-camel/src/main/scala/akka/camel/internal/DefaultCamel.scala @@ -33,7 +33,7 @@ private[camel] class DefaultCamel(val system: ActorSystem) extends Camel { ctx } - lazy val settings = new CamelSettings(system.settings.config) + val settings = new CamelSettings(system.settings.config) lazy val template: ProducerTemplate = context.createProducerTemplate() diff --git a/akka-camel/src/test/scala/akka/camel/DefaultCamelTest.scala b/akka-camel/src/test/scala/akka/camel/DefaultCamelTest.scala index b671060c6f..dab91623d4 100644 --- a/akka-camel/src/test/scala/akka/camel/DefaultCamelTest.scala +++ b/akka-camel/src/test/scala/akka/camel/DefaultCamelTest.scala @@ -12,15 +12,22 @@ import akka.actor.ActorSystem import org.apache.camel.{ CamelContext, ProducerTemplate } import org.scalatest.WordSpec import akka.event.LoggingAdapter +import akka.actor.ActorSystem.Settings +import com.typesafe.config.ConfigFactory class DefaultCamelTest extends WordSpec with SharedCamelSystem with MustMatchers with MockitoSugar { import org.mockito.Mockito.{ when, verify } + val sys = mock[ActorSystem] + val config = ConfigFactory.defaultReference() + when(sys.settings) thenReturn (new Settings(this.getClass.getClassLoader, config, "mocksystem")) + when(sys.name) thenReturn ("mocksystem") - def camelWithMocks = new DefaultCamel(mock[ActorSystem]) { + def camelWithMocks = new DefaultCamel(sys) { override val log = mock[LoggingAdapter] override lazy val template = mock[ProducerTemplate] override lazy val context = mock[CamelContext] + override val settings = mock[CamelSettings] } "during shutdown, when both context and template fail to shutdown" when { diff --git a/akka-camel/src/test/scala/akka/camel/internal/component/ActorProducerTest.scala b/akka-camel/src/test/scala/akka/camel/internal/component/ActorProducerTest.scala index bf31755d53..d40dab2a56 100644 --- a/akka-camel/src/test/scala/akka/camel/internal/component/ActorProducerTest.scala +++ b/akka-camel/src/test/scala/akka/camel/internal/component/ActorProducerTest.scala @@ -7,7 +7,7 @@ package akka.camel.internal.component import org.scalatest.mock.MockitoSugar import org.mockito.Matchers.any import org.mockito.Mockito._ -import org.apache.camel.AsyncCallback +import org.apache.camel.{ CamelContext, ProducerTemplate, AsyncCallback } import java.util.concurrent.atomic.AtomicBoolean import akka.util.duration._ import akka.util.Duration @@ -22,6 +22,9 @@ import java.util.concurrent.{ TimeoutException, CountDownLatch, TimeUnit } import org.mockito.{ ArgumentMatcher, Matchers, Mockito } import org.scalatest.matchers.MustMatchers import akka.actor.Status.Failure +import com.typesafe.config.ConfigFactory +import akka.actor.ActorSystem.Settings +import akka.event.LoggingAdapter class ActorProducerTest extends TestKit(ActorSystem("test")) with WordSpec with MustMatchers with ActorProducerFixture { @@ -269,15 +272,25 @@ trait ActorProducerFixture extends MockitoSugar with BeforeAndAfterAll with Befo asyncCallback = createAsyncCallback probe = TestProbe() - camel = camelWithMocks - def camelWithMocks = new DefaultCamel(mock[ActorSystem]) { - override lazy val settings = mock[CamelSettings] + + val sys = mock[ActorSystem] + val config = ConfigFactory.defaultReference() + when(sys.settings) thenReturn (new Settings(this.getClass.getClassLoader, config, "mocksystem")) + when(sys.name) thenReturn ("mocksystem") + + def camelWithMocks = new DefaultCamel(sys) { + override val log = mock[LoggingAdapter] + override lazy val template = mock[ProducerTemplate] + override lazy val context = mock[CamelContext] + override val settings = mock[CamelSettings] } + camel = camelWithMocks + exchange = mock[CamelExchangeAdapter] callback = mock[AsyncCallback] actorEndpointPath = mock[ActorEndpointPath] actorComponent = mock[ActorComponent] - producer = new ActorProducer(config(), camel) + producer = new ActorProducer(configure(), camel) message = CamelMessage(null, null) } @@ -289,7 +302,7 @@ trait ActorProducerFixture extends MockitoSugar with BeforeAndAfterAll with Befo def given(actor: ActorRef = probe.ref, outCapable: Boolean = true, autoAck: Boolean = true, replyTimeout: Duration = Int.MaxValue seconds) = { prepareMocks(actor, outCapable = outCapable) - new ActorProducer(config(isAutoAck = autoAck, _replyTimeout = replyTimeout), camel) + new ActorProducer(configure(isAutoAck = autoAck, _replyTimeout = replyTimeout), camel) } def createAsyncCallback = new TestAsyncCallback @@ -323,7 +336,7 @@ trait ActorProducerFixture extends MockitoSugar with BeforeAndAfterAll with Befo } - def config(endpointUri: String = "test-uri", isAutoAck: Boolean = true, _replyTimeout: Duration = Int.MaxValue seconds) = { + def configure(endpointUri: String = "test-uri", isAutoAck: Boolean = true, _replyTimeout: Duration = Int.MaxValue seconds) = { val endpoint = new ActorEndpoint(endpointUri, actorComponent, actorEndpointPath, camel) endpoint.autoAck = isAutoAck endpoint.replyTimeout = _replyTimeout