I am relatively new to camel, but until you get more experienced replies, I'd suggest your second path (replaceFromWith) but use something like seda:mockKafka - then send your test messages to seda:mockKafka. I'm under the impression that a mock can't produce a message, which is why you're getting the UnsupportedOperationException.
-Steve > -----Original Message----- > From: ganga_camel [mailto:ganga...@gmail.com] > Sent: Friday, June 10, 2016 7:59 AM > To: users@camel.apache.org > Subject: How to Mock Kafka Consumer Endpoint with Spock Framework Unit > Test cases > > Hi, > > I am using Spock Framework to perform Unit Testing of Camel Routes. My > first route consumes from Kafka Consumer Endpoint. I need to mock this end > point and send the message to mock endpoint as part of the unit testing, > below is how I have tried > > camelctx.getRouteDefinitions().get(0).adviceWith(camelctx, new > AdviceWithRouteBuilder() { > @Override > void configure() throws Exception { > > interceptSendToEndpoint("kafka:{{server}}?topic={{topic}}&zookeeperHost > ={{zookeeper}}&zookeeperPort={{zookeeperport}}&groupId={{group}}&aut > oCommitEnable=true&autoOffsetReset=smallest&autoCommitIntervalMs=1 > 000") > .skipSendToOriginalEndpoint() > .to("mock:kafkaCon") > } > }) > > Here I get the error "java.lang.NullPointerException: Cannot invoke method > getIn() on null object" . > > I have also tried > camelctx.getRouteDefinitions().get(0).adviceWith(camelctx, new > AdviceWithRouteBuilder() { > @Override > void configure() throws Exception { > replaceFromWith("mock:kafkaCon") > } > }) > I get the error "java.lang.UnsupportedOperationException: You cannot > consume from this endpoint" > > Any suggession on how to Mock the Kafka Consumer endpoint and advise if I > am trying to do it wrong.. > > -Ganga > > > > -- > View this message in context: http://camel.465427.n5.nabble.com/How-to- > Mock-Kafka-Consumer-Endpoint-with-Spock-Framework-Unit-Test-cases- > tp5783856.html > Sent from the Camel - Users mailing list archive at Nabble.com.