camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tom Howe <tomh...@artcore.com>
Subject Re: Can you actually mock out endpoints that interact with other systems to prevent them doing so?
Date Tue, 29 Mar 2011 18:01:52 GMT
I think my problem can be summarized:

I'n one test I need to consume from an endpoint  and in another test I want
to send messages to the same endpoint.

You cannot use mock: if you need to consume and you cannot use direct: if I
want to check the messages being sent to it.

I dont appear to be able to inject a mock: into a direct: endpoint

So it seems like I might need a separate properties file for each test ;-(





On Tue, Mar 29, 2011 at 6:50 PM, Tom Howe <tomhowe@artcore.com> wrote:

> Also it seems, I cannot inject a mock into a direct:xx endpoint
>
>     @EndpointInject(uri="direct:activemq-general.in")
>
> I get..
>
> java.lang.IllegalArgumentException: Invalid type:
> org.apache.camel.component.mock.MockEndpoint which cannot be injected via
> @EndpointInject/@Produce for: Endpoint[direct://activemq-general.in]
>
>
> any suggestions?
>
>
>
> On Tue, Mar 29, 2011 at 6:46 PM, Tom Howe <tomhowe@artcore.com> wrote:
>
>> The only problem i am having with this is I cannot use mocks for endpoints
>> that are consumed from.
>>
>> I get the following error..
>>
>>  org.apache.camel.RuntimeCamelException:
>> java.lang.UnsupportedOperationException: You cannot consume from this
>> endpoint
>>
>> So I tried to use direct:xxx for these, but then I cannot see if they have
>> received any messages.
>>
>>
>>
>>
>>
>> On Tue, Mar 29, 2011 at 6:06 PM, Tom Howe <tomhowe@artcore.com> wrote:
>>
>>> yes placeholders is the way I solved it myself. I coudn't get the
>>> advicewith to work and it didnt really seem like a good fit.
>>>
>>> So I have..
>>>
>>> <endpoint uri="${myendpoint}"/>
>>>
>>> like this..
>>>
>>> int.properties
>>> myendpoint=activemq:myendpoint
>>>
>>> test.properties
>>> myendpoint=mock:activemq-myendpoint
>>>
>>> Is 2.8 final? or coming soon?
>>>
>>>
>>>
>>> On Tue, Mar 29, 2011 at 3:14 PM, Claus Ibsen <claus.ibsen@gmail.com>wrote:
>>>
>>>> Hi Tom
>>>>
>>>> Yeah the adviceWith started as a feature to advice single routes. But
>>>> can also be used to mock and skip sending to endpoints as shown on
>>>> those wiki pages.
>>>>
>>>> However its often easier to either
>>>> - use property placeholders for uris, so you can use mock:xxx for unit
>>>> tests, and mina:xxx for the real apps
>>>> - or add the endpoint pre starting the routes
>>>>
>>>> In the latter you can most likely do something like:
>>>>    context.addEndpoint("mina:xxx", new MockEndpoint());
>>>>
>>>> However in Camel 2.8 onwards its easier as you can replace entire
>>>> components with mock using
>>>>   context.addComponent("mina", context.getComponent("mock"));
>>>>
>>>>
>>>>
>>>> On Tue, Mar 29, 2011 at 10:35 AM, Tom Howe <tomhowe@artcore.com> wrote:
>>>> > I tried this..
>>>> >
>>>> >        context.getRouteDefinitions().get(0).adviceWith(context, new
>>>> > RouteBuilder() {
>>>> >            @Override
>>>> >            public void configure() throws Exception {
>>>> >
>>>> >
>>>>  interceptSendToEndpoint("mock:mina:tcp://unreachable.splunk.server:9000")
>>>> >                        .skipSendToOriginalEndpoint()
>>>> >                        .to("mock:mina-advised");
>>>> >            }
>>>> >        });
>>>> >
>>>> >
>>>> > I have multiple routes in my config - does get(0) just get the first
>>>> route?
>>>> >
>>>> > I also tried this..
>>>> >
>>>> >        context.getRouteDefinition("toSplunk").adviceWith(context, new
>>>> > RouteBuilder() {
>>>> >            @Override
>>>> >            public void configure() throws Exception {
>>>> >
>>>> >
>>>>  interceptSendToEndpoint("mock:mina:tcp://unreachable.splunk.server:9000")
>>>> >                        .skipSendToOriginalEndpoint()
>>>> >                        .to("mock:mina-advised");
>>>> >            }
>>>> >        });
>>>> >
>>>> > and this (with direct component - not mock)..
>>>> >        context.getRouteDefinition("toSplunk").adviceWith(context, new
>>>> > RouteBuilder() {
>>>> >            @Override
>>>> >            public void configure() throws Exception {
>>>> >
>>>> >  interceptSendToEndpoint("mina:tcp://unreachable.splunk.server:9000")
>>>> >                        .skipSendToOriginalEndpoint()
>>>> >                        .to("mock:mina-advised");
>>>> >            }
>>>> >        });
>>>> >
>>>> > All give   java.nio.channels.UnresolvedAddressException because they
>>>> are
>>>> > trying to write to splunk server.
>>>> >
>>>> > My route looks like:
>>>> >
>>>> >        <route autoStartup="true" id="tosplunk" xmlns="
>>>> > http://camel.apache.org/schema/spring">
>>>> >            <from uri="direct:splunk.in"/>
>>>> >            <filter>
>>>> >                <xpath>//*[local-name() = "event"]</xpath>
>>>> >                <bean ref="unWrapEnvelopeXml"/>
>>>> >                <bean ref="ispyXmlToSplunk"/>
>>>> >                <to
>>>> >
>>>> uri="mina:tcp://unreachable.splunk.server:9000?textline=true&amp;textlineDelimiter=UNIX&amp;sync=false"/>
>>>> >            </filter>
>>>> >        </route>
>>>> >
>>>> >
>>>> > Thanks, Tom
>>>> >
>>>> >
>>>> >
>>>> > On Mon, Mar 28, 2011 at 8:24 PM, Tom Howe <tomhowe@artcore.com>
>>>> wrote:
>>>> >
>>>> >> Is this what you are pointing me to? .skipSendToOriginalEndpoint()
>>>> >>
>>>> >> How do I use this in my spring xml routes?
>>>> >>
>>>> >>
>>>> >> On Mon, Mar 28, 2011 at 7:02 PM, Claus Ibsen <claus.ibsen@gmail.com
>>>> >wrote:
>>>> >>
>>>> >>> See
>>>> >>> http://camel.apache.org/advicewith.html
>>>> >>>
>>>> >>> On Mon, Mar 28, 2011 at 7:47 PM, Tom Howe <tomhowe@artcore.com>
>>>> wrote:
>>>> >>> > I have a route such as:
>>>> >>> >
>>>> >>> >  <route autoStartup="true" xmlns="
>>>> http://camel.apache.org/schema/spring
>>>> >>> ">
>>>> >>> >         <from uri="activemq:somequeue"/>
>>>> >>> >         ...
>>>> >>> >         <to uri="http:hostname/some/path"/>
>>>> >>> >   </route>
>>>> >>> >
>>>> >>> > If I set up mocking, using a wrapper xml file containing:
>>>> >>> >
>>>> >>> >    <bean id="mockAllEndpoints"
>>>> >>> >
>>>> class="org.apache.camel.impl.InterceptSendToMockEndpointStrategy"/>
>>>> >>> >
>>>> >>> > I can now intercept the endpoints to see what was sent
but how to
>>>> I
>>>> >>> prevent
>>>> >>> > the test from connecting to activemq and the remote http
server so
>>>> I can
>>>> >>> run
>>>> >>> > the test without any external interaction?
>>>> >>> >
>>>> >>> > I managed to use
>>>> >>> >    <bean id="activemq"
>>>> >>> > class="org.apache.camel.component.direct.DirectComponent"
/>
>>>> >>> >
>>>> >>> > to prevent activemq connecting, but the same trick did
not work
>>>> with
>>>> >>> mina or
>>>> >>> > http since the parameters passed are not appropriate.
>>>> >>> >
>>>> >>> >
>>>> >>> > Thanks, Tom
>>>> >>> >
>>>> >>>
>>>> >>>
>>>> >>>
>>>> >>> --
>>>> >>> Claus Ibsen
>>>> >>> -----------------
>>>> >>> FuseSource
>>>> >>> Email: cibsen@fusesource.com
>>>> >>> Web: http://fusesource.com
>>>> >>> Twitter: davsclaus
>>>> >>> Blog: http://davsclaus.blogspot.com/
>>>> >>> Author of Camel in Action: http://www.manning.com/ibsen/
>>>> >>>
>>>> >>
>>>> >>
>>>> >
>>>>
>>>>
>>>>
>>>> --
>>>> Claus Ibsen
>>>> -----------------
>>>> FuseSource
>>>> Email: cibsen@fusesource.com
>>>> Web: http://fusesource.com
>>>> Twitter: davsclaus
>>>> Blog: http://davsclaus.blogspot.com/
>>>> Author of Camel in Action: http://www.manning.com/ibsen/
>>>>
>>>
>>>
>>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message