use of com.eviware.soapui.impl.wsdl.mock.WsdlMockOperation in project microcks by microcks.
the class SoapUIProjectImporter method extractOperations.
/**
* Extract the list of operations from MockService according WsdlInterface.
*/
private List<Operation> extractOperations(MockService mockService, WsdlInterface wi) {
List<Operation> result = new ArrayList<Operation>();
List<MockOperation> operations = mockService.getMockOperationList();
for (MockOperation mockOperation : operations) {
// Build a new operation.
Operation operation = new Operation();
operation.setName(mockOperation.getName());
// Retrieve part name from Wsdl operation coming from interface.
WsdlOperation wo = wi.getOperationByName(mockOperation.getName());
operation.setAction(wo.getAction());
operation.setInputName(wo.getInputName());
operation.setOutputName(wo.getOutputName());
WsdlMockOperation wmo = (WsdlMockOperation) mockOperation;
operation.setDispatcher(wmo.getDispatchStyle());
// Check dispatcher configuration.
MockOperationDispatcher dispatcher = wmo.getDispatcher();
if (dispatcher instanceof QueryMatchMockOperationDispatcher) {
QueryMatchMockOperationDispatcher qmDispatcher = (QueryMatchMockOperationDispatcher) dispatcher;
String query = qmDispatcher.getQueryAt(0).getQuery();
operation.setDispatcherRules(query);
} else if (dispatcher instanceof ScriptMockOperationDispatcher) {
ScriptMockOperationDispatcher sDispatcher = (ScriptMockOperationDispatcher) dispatcher;
String script = sDispatcher.getMockOperation().getScript();
operation.setDispatcherRules(script);
}
result.add(operation);
}
return result;
}
use of com.eviware.soapui.impl.wsdl.mock.WsdlMockOperation in project microcks by microcks.
the class SoapUIProjectImporter method getSoapMessageDefinitions.
/**
* Get message definition for an operation of a Soap mock service.
*/
private List<Exchange> getSoapMessageDefinitions(MockService mockService, Operation operation) throws XPathExpressionException {
Map<Request, Response> result = new HashMap<Request, Response>();
// Get MockOperation corresponding to operation.
MockOperation mockOperation = mockService.getMockOperationByName(operation.getName());
// Collect available test requests for this operation.
Map<String, WsdlTestRequest> availableRequests = collectWsdlTestRequests(operation);
// Then filter only those that are candidates to mock response matching.
List<WsdlTestRequest> requests = new ArrayList<WsdlTestRequest>();
for (MockResponse mockResponse : mockOperation.getMockResponses()) {
// Check if there's a corresponding request in test cases.
WsdlTestRequest matchingRequest = availableRequests.get(mockResponse.getName());
if (matchingRequest == null) {
matchingRequest = availableRequests.get(mockResponse.getName() + " Request");
}
if (matchingRequest == null && mockResponse.getName().contains("Response")) {
matchingRequest = availableRequests.get(mockResponse.getName().replace("Response", "Request"));
}
if (matchingRequest == null) {
log.warn("No request found for response " + mockResponse.getName() + " into SoapUI project " + project.getName());
continue;
}
requests.add(matchingRequest);
}
if (DispatchStyles.QUERY_MATCH.equals(operation.getDispatcher())) {
// Browse candidates and apply query dispatcher criterion to find corresponding response.
XPathExpression xpath = initializeXPathMatcher(operation);
Map<String, String> matchToResponseMap = buildQueryMatchDispatchCriteriaToResponseMap((WsdlMockOperation) mockOperation);
for (WsdlTestRequest wtr : requests) {
// Evaluate matcher against request and get name of corresponding response.
String dispatchCriteria = xpath.evaluate(new InputSource(new StringReader(wtr.getRequestContent())));
String correspondingResponse = matchToResponseMap.get(dispatchCriteria);
MockResponse mockResponse = mockOperation.getMockResponseByName(correspondingResponse);
if (mockResponse != null) {
// Build response from MockResponse and response from matching one
Response response = buildResponse(mockResponse, dispatchCriteria);
Request request = buildRequest(wtr);
result.put(request, response);
}
}
} else if (DispatchStyles.SCRIPT.equals(operation.getDispatcher())) {
for (WsdlTestRequest wtr : requests) {
MockResponse mockResponse = mockOperation.getMockResponseByName(wtr.getName().replace(" Request", ""));
if (mockResponse == null && wtr.getName().contains("Request")) {
mockResponse = mockOperation.getMockResponseByName(wtr.getName().replace(" Request", " Response"));
}
if (mockResponse == null) {
log.warn("No response found for request " + wtr.getName() + " into SoapUI project " + project.getName());
continue;
}
// Build response from MockResponse and response from matching one.
Response response = buildResponse(mockResponse, mockResponse.getName());
Request request = buildRequest(wtr);
result.put(request, response);
}
}
// Adapt map to list of Exchanges.
return result.entrySet().stream().map(entry -> new RequestResponsePair(entry.getKey(), entry.getValue())).collect(Collectors.toList());
}
Aggregations