use of com.eviware.soapui.impl.rest.mock.RestMockService in project microcks by microcks.
the class SoapUIProjectImporter method getRestMessageDefinitions.
/**
* Get message definition for an operation of a Rest mock service.
*/
private List<Exchange> getRestMessageDefinitions(RestMockService mockService, Operation operation) {
Map<Request, Response> result = new HashMap<Request, Response>();
// Collect mock responses for MockOperation corresponding to operation (it may be many).
List<MockResponse> mockResponses = new ArrayList<MockResponse>();
for (MockOperation mockOperation : mockService.getMockOperationList()) {
if (mockOperation.getName().equals(operation.getName())) {
mockResponses.addAll(mockOperation.getMockResponses());
}
}
// Collect also mock action configs, organizing them within a map with response name as key.
Map<String, RESTMockActionConfig> mockRestActionConfigsForResponses = new HashMap<String, RESTMockActionConfig>();
for (RESTMockActionConfig mockActionConfig : mockService.getConfig().getRestMockActionList()) {
if (mockActionConfig.getName().equals(operation.getName())) {
for (RESTMockResponseConfig mockRestResponse : mockActionConfig.getResponseList()) {
mockRestActionConfigsForResponses.put(mockRestResponse.getName(), mockActionConfig);
}
}
}
// Collect available test requests for this operation.
Map<String, RestTestRequest> availableRequests = collectRestTestRequests(operation);
// Then find only those that are candidates to mock response matching.
Map<RestTestRequest, MockResponse> requestToResponse = new HashMap<RestTestRequest, MockResponse>();
for (MockResponse mockResponse : mockResponses) {
// Check if there's a corresponding request in test cases.
RestTestRequest 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;
}
requestToResponse.put(matchingRequest, mockResponse);
}
for (Map.Entry<RestTestRequest, MockResponse> entry : requestToResponse.entrySet()) {
RestTestRequest rtr = entry.getKey();
MockResponse mr = entry.getValue();
String dispatchCriteria = null;
if (DispatchStyles.SEQUENCE.equals(operation.getDispatcher())) {
// Build a dispatch criteria from operation name projected onto resourcePath pattern
// eg. /deployment/byComponent/{component}/{version}.json => /deployment/byComponent/testREST/1.2.json
// for producing /component=testREST/version=1.2
RESTMockActionConfig actionConfig = mockRestActionConfigsForResponses.get(mr.getName());
dispatchCriteria = DispatchCriteriaHelper.extractFromURIPattern(operation.getName(), actionConfig.getResourcePath());
} else if (DispatchStyles.SCRIPT.equals(operation.getDispatcher())) {
// Build a dispatch criteria that is equal to response name (that script evaluation should return...)
dispatchCriteria = mr.getName();
}
Response response = buildResponse((RestMockResponse) mr, dispatchCriteria);
Request request = buildRequest(rtr);
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());
}
use of com.eviware.soapui.impl.rest.mock.RestMockService in project microcks by microcks.
the class SoapUIProjectImporter method getRestServiceDefinitions.
/**
* Get the definitions of Rest Services from mock services.
*/
private List<Service> getRestServiceDefinitions(List<RestMockService> mockServices) {
List<Service> result = new ArrayList<>();
for (RestMockService rms : mockServices) {
// First assume it's a Rest one for now.
Service service = new Service();
service.setName(rms.getName());
service.setType(ServiceType.REST);
// Extract version from custom properties.
String version = rms.getPropertyValue(SERVICE_VERSION_PROPERTY);
if (version == null) {
// TODO Throw a typed exception here...
}
service.setVersion(version);
// Then build its operations.
service.setOperations(extractOperations(rms));
result.add(service);
}
return result;
}
use of com.eviware.soapui.impl.rest.mock.RestMockService in project microcks by microcks.
the class SoapUIProjectImporter method getMessageDefinitions.
@Override
public List<Exchange> getMessageDefinitions(Service service, Operation operation) throws MockRepositoryImportException {
// First try with a Soap Service mock...
MockService mockService = project.getMockServiceByName(service.getName());
if (mockService != null) {
try {
return getSoapMessageDefinitions(mockService, operation);
} catch (XPathExpressionException xpe) {
log.error("Got a XPathExpressionException while retrieving soap messages", xpe);
throw new MockRepositoryImportException("XPathExpressionExceotion while retrieving soap messages", xpe);
}
}
// ... then with a Rest Service mock.
RestMockService restMockService = project.getRestMockServiceByName(service.getName());
if (restMockService != null) {
return getRestMessageDefinitions(restMockService, operation);
}
return new ArrayList<Exchange>();
}
Aggregations