Forum Discussion
a_wasink
15 years agoOccasional Contributor
There is another code change that is necessary to get it working. I thought the changed had no impact but as I was reverting obsolete changes the test case wasn’t running anymore. The code I changed is in the selectMockResponse method of the QueryMatchMockOperationDispatcher class. See below. The commented line is the original code replaced.
There are two problems requiring this change:
1.) Without the change the WsdlMockResponseTestStep fails with a timeout although a request is received and successfully dispatched. The problem lies therein that there are two MockResponse objects assigned to the MockOperation object with the same name. The first object is the MockResponse object set as mockReponse in the WsdlMockResponseTestStep. The second one is the MockResponse object newly created in the method and set as testMockResponse in the WsdlMockResponseTestStep. This second one is the one to use and is returned by the code change.
Note that the actual problem is that no deep copy of the MockResponseConfig is made in the initTestMockResponse method of the WsdlMockResponseTestStep class.
Further, it is unclear to me why a new MockResponse object is created in the initTestMockResponse method in case of a Query/Match. Also I don’t understand why a generated unique name is used in the Query object to address the MockResponse object and not a reference.
2.) Having fixed point 1, subsequent runs of the test case fail. This is because no Mock Response is found by the dispatcher. This is caused by the fact the Query objects of previous test runs are not removed from the query list of the dispatcher. These ‘old’ Query objects have no matching MockResponse object anymore because they are removed. Thus the first Query object processed in the loop will return null as method result. This is easily worked around by only returning a result when the result is not null.
Note that the missing removal of the Query objects is causing a memory leak in soap-ui.
Regards,
Arjen
WsdlMockResponse resp = null;
for (MockResponse mockResponse : this.getMockOperation().getMockResponses()) {
if (query.getResponse().equals(mockResponse.getName())){
resp = (WsdlMockResponse) mockResponse;
}
}
// return getMockOperation().getMockResponseByName( query.getResponse() );
if (resp != null){
return resp;
}
There are two problems requiring this change:
1.) Without the change the WsdlMockResponseTestStep fails with a timeout although a request is received and successfully dispatched. The problem lies therein that there are two MockResponse objects assigned to the MockOperation object with the same name. The first object is the MockResponse object set as mockReponse in the WsdlMockResponseTestStep. The second one is the MockResponse object newly created in the method and set as testMockResponse in the WsdlMockResponseTestStep. This second one is the one to use and is returned by the code change.
Note that the actual problem is that no deep copy of the MockResponseConfig is made in the initTestMockResponse method of the WsdlMockResponseTestStep class.
Further, it is unclear to me why a new MockResponse object is created in the initTestMockResponse method in case of a Query/Match. Also I don’t understand why a generated unique name is used in the Query object to address the MockResponse object and not a reference.
2.) Having fixed point 1, subsequent runs of the test case fail. This is because no Mock Response is found by the dispatcher. This is caused by the fact the Query objects of previous test runs are not removed from the query list of the dispatcher. These ‘old’ Query objects have no matching MockResponse object anymore because they are removed. Thus the first Query object processed in the loop will return null as method result. This is easily worked around by only returning a result when the result is not null.
Note that the missing removal of the Query objects is causing a memory leak in soap-ui.
Regards,
Arjen