Forum Discussion

jazzyekim's avatar
jazzyekim
Occasional Contributor
13 years ago

Set MockOperation script using groovy

Hi there!

I am creating script that generates mock from an interface with all necessary settings setup. Beyond settings I need to set scripts to Mock/Operation/Response.
For mocks OnRequest and AfterRequest it is quite easy. There is appropriate methods, e.g.

public void setupMock (WsdlMockService mock)
{
...
String script = ReadTextFile.getFileContent(config.getOnRequestPath());
mock.setOnRequestScript(script) ;
...
}


same is for Response:

public void createAndSetupResponseSet ( WsdlMockOperation operation )
{
...
//create a set of responses
WsdlMockResponse response = operation.addNewMockResponse("Response 1", true);

//set script for responses
String script = ReadTextFile.getFileContent(config.getResponsePath());
response.setScript(script);
...
}


but as for Operation it is not so obvious. I am able to set dispatcher style to "SCRIPT" and get MockOperationDispatcher :

for(WsdlMockOperation it: arrOperations)
{
MockOperationDispatcher dispatcher = it.setDispatchStyle("SCRIPT");
}


Dispatcher has methods like getEditorComponent(), but I still can't find the way how can I set script in it.
Does anyone know how I can do it?

2 Replies

  • jazzyekim's avatar
    jazzyekim
    Occasional Contributor
    I have found a solution - the method that sets script for operation is setDispatchPath. For me this method name is confusing. But in any case - I am happy to find it


    for(WsdlMockOperation it: arrOperations)
    {
    it.setDispatchStyle("SCRIPT");
    it.setDispatchPath("log.info('This is my script')");
    }