Overriding abstract checks

I have check() logic in a trait which is used by individual request objects. Different requests need different checks. I have coded two abstract regex variables which can be checked in the trait as shown below. However, what I really want is to define an abstract check which can be implemented separately in each individual request object, but I cannot work out the syntax. Can anyone point me in the right direction. Thanks.

/Martin

What I have :

trait GeneralRequest {`

def regex1 : String
def regex2 : String

...

.check(regex(regex1).exists)
.check(regex(regex2).exists)

`

What I would like to have

`
trait GeneralRequest {

def checks : HttpCheck*

.check(checks)

}

object GetImageRequest extends GeneralRequest {

val checks = new HttpCheck(regex(“abc”).exists, new HttpCheck(some other check), and so on

`

Hi,

Sorry, I don’t get what you’re trying to do.
Could you provide a concrete example, please?

Hi Stéphane, let me try and talk you through the example.

The objective is that in the Trait GeneralRequest, I have a method myRequest() which performs a http request, and which will contain a check() method on the response.

The Trait is extended by a number of different scenario objects, each of which invoke the GeneralRequest.myRequest() method. The myRequest is the same for all the Scenarios that extend GeneralRequest. They all say, send a request, and receive a response. However, the implementation of the check() is different for each Scenario. I would like to declare a single abstract variable in GeneralRequest which will contain the parameters for the check(). Each scenario will override this variable so that its’ own checks are performed when myRequest() is called. The variable will contain a list of checks. Some Scenarios will have one or two checks, some scenarios will have many more.

In the example of what I have today, I can have two abstract regex parameters in the Trait, and each of the Scenarios can specify their own regex parameters for these two regex expressions. This works. But I’m looking for a more general solution where the Scenario can declare any number of checks of any variety, and these are picked up and applied by myRequest in the GeneralRequest Trait. In order to do that I need to work out how to declare a variable of type , and how that syntax is applied in the Trait and in the Scenario.

Cheers

/Martin

So you want to be able to set up global per scenario checks? If so, why don’t you define them on the protocol? http://gatling.io/docs/2.0.2/http/http_protocol.html#checks

Hi Stéphane, is that not what I’m doing? I’m calling check() following the http() call. This is what GeneralRequest.myRequest() looks like

`
trait GeneralRequest {

def regex1 : String
def regex2 : String

val myRequest = exec( http(requestName)
.post(postUrl)
.headers(postHeaders)
.body(ELFileBody(requestFileName))
.check(status.is(httpOK))
.check(bodyString.exists)
.check(regex(regex1).exists)
.check(regex(regex2).exists)
// TODO - can we pass in a variable length list instead of two elements?

`

No, it’s not.

You’re defining individual checks on requests, not global checks on the protocol.