Closed geemang2000 closed 12 years ago
I figured out a work around by adding the following method to the Test Class. Where myService is a 'def myService' property of the Test Class
@Override JndiRegistry createRegistry() throws Exception { def registry = new JndiRegistry(createJndiContext()) registry.bind('myService', myService) return registry }
Hi there,
can you please provide a test case in the form of a ready to use example that I can execute without copy-pasting code? That'd help me understand your issue.
Best regards, Matthias.
2011/9/14 geemang2000 < reply@reply.github.com>
ENV: JDK 1.6 Grails 1.3.7 app with the routing plugin 1.1.3
I'm trying to execute a CamelTestSupport based integration test. It looks like I can't define my own routes (see RouteBuilder createRouteBuilder) using the "bean:myService?method=myMethod" URI as available when you define your own
Route.groovy class. My ultimate goal is to append the MockEndpoint to my test routes. I'd rather not put those in the
Route.groovy class Is there a pattern to Integration test routes with this Plugin?
--- EXCEPTION --- org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[Message: helloWorld] at org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1156) at org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:456) at org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:441) at org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:437) at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:125) at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:341) at org.apache.camel.ProducerTemplate$sendBody.call(Unknown Source) at com.wiseguy.routes.CamelServiceTests.testServiceRoute(CamelServiceTests.groovy:66) Caused by: org.apache.camel.NoSuchBeanException: No bean could be found in the registry for: myService at org.apache.camel.component.bean.RegistryBean.getBean(RegistryBean.java:68) at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:81) at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:91) at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:74) at org.apache.camel.impl.ProcessorEndpoint.onExchange(ProcessorEndpoint.java:102) at org.apache.camel.impl.ProcessorEndpoint$1.process(ProcessorEndpoint.java:72) at org.apache.camel.impl.converter.AsyncProcessorTypeConverter$ProcessorToAsyncProcessorBridge.process(AsyncProcessorTypeConverter.java:50) at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:70) at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:104) at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:272) at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:98) at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:70) at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98) at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89) at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:174) at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:70) at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:299) at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:208) at org.apache.camel.processor.DefaultChannel.process(DefaultChannel.java:256) at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:113) at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:70) at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98) at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89) at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:68) at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:70) at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:61) at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:99) at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:91) at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:85) at org.apache.camel.processor.UnitOfWorkProducer.process(UnitOfWorkProducer.java:63) at org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:333) at org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:303) at org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:208) at org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:303) at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:154) at org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:110) at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:123) at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:341) at org.apache.camel.ProducerTemplate$sendBody.call(Unknown Source) at com.wiseguy.routes.CamelServiceTests.testServiceRoute(CamelServiceTests.groovy:66) at _GrailsTest_groovy$_run_closure4.doCall(_GrailsTest_groovy:271) at _GrailsTest_groovy$_run_closure4.call(_GrailsTest_groovy) at _GrailsTest_groovy$_run_closure2.doCall(_GrailsTest_groovy:228) at _GrailsTest_groovy$_run_closure1_closure21.doCall(_GrailsTest_groovy:187) at _GrailsTest_groovy$_run_closure1.doCall(_GrailsTest_groovy:174) at TestApp$_run_closure1.doCall(TestApp.groovy:82) at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381) at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415) at gant.Gant$_dispatch_closure7.doCall(Gant.groovy) at gant.Gant.withBuildListeners(Gant.groovy:427) at gant.Gant.this$2$withBuildListeners(Gant.groovy) at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source) at gant.Gant.dispatch(Gant.groovy:415) at gant.Gant.this$2$dispatch(Gant.groovy) at gant.Gant.invokeMethod(Gant.groovy) at gant.Gant.executeTargets(Gant.groovy:590) at gant.Gant.executeTargets(Gant.groovy:589)
---- CODE ----
import grails.test.*
import org.apache.camel.EndpointInject import org.apache.camel.component.mock.MockEndpoint import org.apache.camel.builder.RouteBuilder import org.apache.camel.test.junit4.CamelTestSupport import org.apache.camel.Produce import org.apache.camel.ProducerTemplate import org.apache.camel.processor.interceptor.Tracer
import org.apache.log4j.BasicConfigurator import org.apache.log4j.LogManager import org.apache.log4j.Logger import org.apache.log4j.Level
import org.junit.AfterClass import org.junit.BeforeClass import org.junit.Test
/* */ class CamelServiceTests extends CamelTestSupport {
def grailsApplication def myService @Produce(uri = "direct:serviceInput") protected ProducerTemplate directServiceTemplate @EndpointInject(uri = "mock:result") protected MockEndpoint resultEndpoint /** * This works!! * * Uses a testRoute.groovy with: *
from("direct:serviceInput").to("bean:myService?method=myMethod") * MyService has this method: * def runMyMethod() { * sendMessage('direct:serviceInput', 'helloworld') * } * @throws Exception / @Test void testLookupService() throws Exception { myService.runMyMethod() }
/** * * Trying to use the RouteBuilder below so that we can eventually
use a Mock Result * This FAILS with: * org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[Message: helloWorld] * at org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1156) * at org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:456) * at org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:441) * at org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:437) * at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:125) * at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:341) * at org.apache.camel.ProducerTemplate$sendBody.call(Unknown Source) * at com.wiseguy.routes.CamelServiceTests.testServiceRoute(CamelServiceTests.groovy:66) * Caused by: org.apache.camel.NoSuchBeanException: No bean could be found in the registry for: myService * @throws Exception / @Test public void testServiceRoute() throws Exception { directServiceTemplate.sendBody("helloWorld") }
@Override protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { public void configure() { context.setTracing(true)
from("direct:serviceInput").to("bean:myService?method=myMethod") } }; } }
Reply to this email directly or view it on GitHub: https://github.com/padcom/grails-routing/issues/2
Since there's been no updates on the test case I'm going to close this one. Please reopen once a valid self-contained test case is provided. Thanks
ENV: JDK 1.6 Grails 1.3.7 app with the routing plugin 1.1.3
I'm trying to execute a CamelTestSupport based integration test. It looks like I can't define my own routes (see RouteBuilder createRouteBuilder) using the "bean:myService?method=myMethod" URI as available when you define your ownRoute.groovy class.
My ultimate goal is to append the MockEndpoint to my test routes. I'd rather not put those in theRoute.groovy class
Is there a pattern to Integration test routes with this Plugin?
--- EXCEPTION --- org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[Message: helloWorld] at org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1156) at org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:456) at org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:441) at org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:437) at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:125) at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:341) at org.apache.camel.ProducerTemplate$sendBody.call(Unknown Source) at com.wiseguy.routes.CamelServiceTests.testServiceRoute(CamelServiceTests.groovy:66) Caused by: org.apache.camel.NoSuchBeanException: No bean could be found in the registry for: myService at org.apache.camel.component.bean.RegistryBean.getBean(RegistryBean.java:68) at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:81) at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:91) at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:74) at org.apache.camel.impl.ProcessorEndpoint.onExchange(ProcessorEndpoint.java:102) at org.apache.camel.impl.ProcessorEndpoint$1.process(ProcessorEndpoint.java:72) at org.apache.camel.impl.converter.AsyncProcessorTypeConverter$ProcessorToAsyncProcessorBridge.process(AsyncProcessorTypeConverter.java:50) at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:70) at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:104) at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:272) at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:98) at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:70) at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98) at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89) at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:174) at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:70) at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:299) at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:208) at org.apache.camel.processor.DefaultChannel.process(DefaultChannel.java:256) at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:113) at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:70) at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98) at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89) at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:68) at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:70) at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:61) at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:99) at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:91) at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:85) at org.apache.camel.processor.UnitOfWorkProducer.process(UnitOfWorkProducer.java:63) at org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:333) at org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:303) at org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:208) at org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:303) at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:154) at org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:110) at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:123) at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:341) at org.apache.camel.ProducerTemplate$sendBody.call(Unknown Source) at com.wiseguy.routes.CamelServiceTests.testServiceRoute(CamelServiceTests.groovy:66) at _GrailsTest_groovy$_run_closure4.doCall(_GrailsTest_groovy:271) at _GrailsTest_groovy$_run_closure4.call(_GrailsTest_groovy) at _GrailsTest_groovy$_run_closure2.doCall(_GrailsTest_groovy:228) at _GrailsTest_groovy$_run_closure1_closure21.doCall(_GrailsTest_groovy:187) at _GrailsTest_groovy$_run_closure1.doCall(_GrailsTest_groovy:174) at TestApp$_run_closure1.doCall(TestApp.groovy:82) at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381) at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415) at gant.Gant$_dispatch_closure7.doCall(Gant.groovy) at gant.Gant.withBuildListeners(Gant.groovy:427) at gant.Gant.this$2$withBuildListeners(Gant.groovy) at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source) at gant.Gant.dispatch(Gant.groovy:415) at gant.Gant.this$2$dispatch(Gant.groovy) at gant.Gant.invokeMethod(Gant.groovy) at gant.Gant.executeTargets(Gant.groovy:590) at gant.Gant.executeTargets(Gant.groovy:589)
---- CODE ----
import grails.test.*
import org.apache.camel.EndpointInject import org.apache.camel.component.mock.MockEndpoint import org.apache.camel.builder.RouteBuilder import org.apache.camel.test.junit4.CamelTestSupport import org.apache.camel.Produce import org.apache.camel.ProducerTemplate import org.apache.camel.processor.interceptor.Tracer
import org.apache.log4j.BasicConfigurator import org.apache.log4j.LogManager import org.apache.log4j.Logger import org.apache.log4j.Level
import org.junit.AfterClass import org.junit.BeforeClass import org.junit.Test
/**
*/ class CamelServiceTests extends CamelTestSupport {
def grailsApplication def myService
@Produce(uri = "direct:serviceInput") protected ProducerTemplate directServiceTemplate
@EndpointInject(uri = "mock:result") protected MockEndpoint resultEndpoint
/**
/**
@Override protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { public void configure() { context.setTracing(true) from("direct:serviceInput").to("bean:myService?method=myMethod") } }; } }