Message selection by http query parameter

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Message selection by http query parameter

BlueHaze
This post was updated on .
Hi,

In my test environment the SUT performs Gets on a Citrus http server and the identifier for the test is contained on one of the query parameters.

The response to the get is then determined by the test identity.

Is there a way that a query parameter can be used to perform the message selection so that only gets for the currently running test are processed?

I am using Citrus with Cucumber and the TestRunner class.

Many thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Message selection by http query parameter

Christoph Deppisch
Administrator
That should be possible with message selectors in combination with query parameter headers (citrus_http_ query_params).

http://www.citrusframework.org/reference/html/actions-receive.html#message-selectors

Reply | Threaded
Open this post in threaded view
|

Re: Message selection by http query parameter

BlueHaze
There are a number of query parameters contained in citrus_http_query_params but we just want to match on the just testId parameter.

Is there a way of extracting a single query parameter and matching on that?


I have seen that a custom MessageSelector can be created overriding the accept() method in the HeaderMatchingMessageSelector class which would give the ability to extract the testId parameter and test it's value.

However, the custom selector can only be used with a channel, I cannot see a way of using it with the HttpActionBuilder that I am using:

runner.http(new BuilderSupport<HttpActionBuilder>() {
     @Override
      public void configure(final HttpActionBuilder builder) {
          builder
            .server("citrusHttpBackendServer")
            .receive()
            .get("/backend/v1/CallData");
      }
});

I can see that citrusHttpBackendServer.inbound channel is being used, is there a way that I can add a custom selector to that channel?

Thank you for any information that you can provide me with.
Reply | Threaded
Open this post in threaded view
|

Re: Message selection by http query parameter

Christoph Deppisch
Administrator
Just add the selector to the http receive operation. Citrus will automatically use the inbound channel and apply the message selector on that.

By the way the default HeaderMatchingMessageSelector should also support the usage of validation matchers where you can operate with contains matcher for example to match on one single query parameter to be present. With Hamcrest validation matchers you can add more complex matchers with and/or/allOf syntax.

Just have a look at the validation matchers you can use those also as message selector value: http://www.citrusframework.org/reference/html/validation-matchers.html 
Reply | Threaded
Open this post in threaded view
|

Re: Message selection by http query parameter

BlueHaze
Thanks for getting back to me but I don't understand what I need to do to get this to work.

Could you provide me with an example to show me how I can use the testRunner code above to select on the testId query parameter from the following citrus_http_query_params header:

citrus_http_query_params=,refId=ajxUL1neTs04CUlUmyQVpA,testId=0975918071250806,callbackURL=http://123.45.67.89:7001/dataResponse/ajxUL1neTs04CUlUmyQVpA

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Message selection by http query parameter

BlueHaze
Hi, I've stepped through the code and it appears that the HeaderMatchingMessageSelector is only able to perform a simple string equals test.

We need the selector to be able to test an individual parameter within the citrus_http_query_params so that we can perform parallel testing.

Could the header selector test be modified to use a regexp expression rather than a simple equals?
This would provide the functionality to test the value of any header parameter's content.

Many thanks
Reply | Threaded
Open this post in threaded view
|

Re: Message selection by http query parameter

Christoph Deppisch
Administrator
You should be able to use Citrus validation matchers in header selector expressions. So you can use @contains@ or @matches@ implementations where latter is evaluating a regexp expression. Just use the validation matcher as the header selector value.
Reply | Threaded
Open this post in threaded view
|

Re: Message selection by http query parameter

BlueHaze
I cannot get the selector to do anything else apart from a simple string equals test.

This works:
Map<String, Object> selector = new HashMap<String, Object>();
selector.put("citrus_http_method", "GET");
builder
    .server("citrusHttpBackendServer")
    .receive()
    .get(url)
    .selector(selector);

This fails:
Map<String, Object> selector = new HashMap<String, Object>();
selector.put("citrus_http_query_params", "@contains('ip=146.1.25.25')@");
builder
    .server("citrusHttpBackendServer")
    .receive()
    .get(url)
    .selector(selector);

The execution path is identical in both cases.
Reply | Threaded
Open this post in threaded view
|

Re: Message selection by http query parameter

BlueHaze
I thought that I'd found the solution by using the .header() method rather than the .selector() method.

But that performs validation rather than selection so that doesn't help solve the parallel testing problem where we need to process only the test data appropriate for our test.