Search in sources :

Example 1 with WsdlTestRequest

use of com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest 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());
}
Also used : XPathExpression(javax.xml.xpath.XPathExpression) WsdlInterface(com.eviware.soapui.impl.wsdl.WsdlInterface) java.util(java.util) XPathExpressionException(javax.xml.xpath.XPathExpressionException) WsdlProject(com.eviware.soapui.impl.wsdl.WsdlProject) WsdlOperation(com.eviware.soapui.impl.wsdl.WsdlOperation) LoggerFactory(org.slf4j.LoggerFactory) WsdlTestRequestStep(com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep) TestSuite(com.eviware.soapui.model.testsuite.TestSuite) RestMockResponse(com.eviware.soapui.impl.rest.mock.RestMockResponse) XPathExpression(javax.xml.xpath.XPathExpression) MockOperation(com.eviware.soapui.model.mock.MockOperation) DispatchCriteriaHelper(io.github.microcks.util.DispatchCriteriaHelper) DefintionPartConfig(com.eviware.soapui.config.DefintionPartConfig) RestTestRequestStep(com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep) MockRepositoryImporter(io.github.microcks.util.MockRepositoryImporter) WsdlTestRequest(com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest) DispatchStyles(io.github.microcks.util.DispatchStyles) MockRepositoryImportException(io.github.microcks.util.MockRepositoryImportException) WsdlMockService(com.eviware.soapui.impl.wsdl.mock.WsdlMockService) InputSource(org.xml.sax.InputSource) RESTMockActionConfig(com.eviware.soapui.config.RESTMockActionConfig) Logger(org.slf4j.Logger) RESTMockResponseConfig(com.eviware.soapui.config.RESTMockResponseConfig) TestCase(com.eviware.soapui.model.testsuite.TestCase) WsdlMockResponse(com.eviware.soapui.impl.wsdl.mock.WsdlMockResponse) MockResponse(com.eviware.soapui.model.mock.MockResponse) MockOperationDispatcher(com.eviware.soapui.impl.wsdl.mock.dispatch.MockOperationDispatcher) IOException(java.io.IOException) ScriptMockOperationDispatcher(com.eviware.soapui.impl.wsdl.mock.dispatch.ScriptMockOperationDispatcher) QueryMatchMockOperationDispatcher(com.eviware.soapui.impl.wsdl.mock.dispatch.QueryMatchMockOperationDispatcher) Collectors(java.util.stream.Collectors) RestMockService(com.eviware.soapui.impl.rest.mock.RestMockService) WsdlMockOperation(com.eviware.soapui.impl.wsdl.mock.WsdlMockOperation) TestStep(com.eviware.soapui.model.testsuite.TestStep) MockService(com.eviware.soapui.model.mock.MockService) RestTestRequest(com.eviware.soapui.impl.wsdl.teststeps.RestTestRequest) RestParamsPropertyHolder(com.eviware.soapui.impl.rest.support.RestParamsPropertyHolder) StringToStringsMap(com.eviware.soapui.support.types.StringToStringsMap) StringReader(java.io.StringReader) AbstractInterface(com.eviware.soapui.impl.support.AbstractInterface) Interface(com.eviware.soapui.model.iface.Interface) io.github.microcks.domain(io.github.microcks.domain) RestMockResponse(com.eviware.soapui.impl.rest.mock.RestMockResponse) WsdlMockResponse(com.eviware.soapui.impl.wsdl.mock.WsdlMockResponse) MockResponse(com.eviware.soapui.model.mock.MockResponse) InputSource(org.xml.sax.InputSource) WsdlTestRequest(com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest) RestTestRequest(com.eviware.soapui.impl.wsdl.teststeps.RestTestRequest) RestMockResponse(com.eviware.soapui.impl.rest.mock.RestMockResponse) WsdlMockResponse(com.eviware.soapui.impl.wsdl.mock.WsdlMockResponse) MockResponse(com.eviware.soapui.model.mock.MockResponse) StringReader(java.io.StringReader) WsdlTestRequest(com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest) MockOperation(com.eviware.soapui.model.mock.MockOperation) WsdlMockOperation(com.eviware.soapui.impl.wsdl.mock.WsdlMockOperation)

Example 2 with WsdlTestRequest

use of com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest in project microcks by microcks.

the class SoapUIProjectImporter method collectWsdlTestRequests.

/**
 * Collect and filter by operation all the WsldTestrequest from the current project.
 */
private Map<String, WsdlTestRequest> collectWsdlTestRequests(Operation operation) {
    Map<String, WsdlTestRequest> result = new HashMap<>();
    for (TestSuite testsuite : project.getTestSuiteList()) {
        for (TestCase testcase : testsuite.getTestCaseList()) {
            for (TestStep teststep : testcase.getTestStepList()) {
                if (teststep instanceof WsdlTestRequestStep) {
                    WsdlTestRequestStep ws = (WsdlTestRequestStep) teststep;
                    WsdlTestRequest wr = ws.getHttpRequest();
                    if (wr.getOperationName().equals(operation.getName())) {
                        result.put(wr.getName(), wr);
                    }
                }
            }
        }
    }
    return result;
}
Also used : TestStep(com.eviware.soapui.model.testsuite.TestStep) WsdlTestRequestStep(com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep) TestSuite(com.eviware.soapui.model.testsuite.TestSuite) TestCase(com.eviware.soapui.model.testsuite.TestCase) WsdlTestRequest(com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest)

Example 3 with WsdlTestRequest

use of com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest in project microcks by microcks.

the class SoapUIProjectImporter method buildRequest.

/**
 * Build a domain Request from SoapUI WsdlTestRequest.
 */
private Request buildRequest(WsdlTestRequest wtr) {
    Request request = new Request();
    request.setName(wtr.getName());
    request.setContent(wtr.getRequestContent());
    request.setHeaders(buildHeaders(wtr.getRequestHeaders()));
    return request;
}
Also used : WsdlTestRequest(com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest) RestTestRequest(com.eviware.soapui.impl.wsdl.teststeps.RestTestRequest)

Aggregations

WsdlTestRequest (com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest)3 RestTestRequest (com.eviware.soapui.impl.wsdl.teststeps.RestTestRequest)2 WsdlTestRequestStep (com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep)2 TestCase (com.eviware.soapui.model.testsuite.TestCase)2 TestStep (com.eviware.soapui.model.testsuite.TestStep)2 TestSuite (com.eviware.soapui.model.testsuite.TestSuite)2 DefintionPartConfig (com.eviware.soapui.config.DefintionPartConfig)1 RESTMockActionConfig (com.eviware.soapui.config.RESTMockActionConfig)1 RESTMockResponseConfig (com.eviware.soapui.config.RESTMockResponseConfig)1 RestMockResponse (com.eviware.soapui.impl.rest.mock.RestMockResponse)1 RestMockService (com.eviware.soapui.impl.rest.mock.RestMockService)1 RestParamsPropertyHolder (com.eviware.soapui.impl.rest.support.RestParamsPropertyHolder)1 AbstractInterface (com.eviware.soapui.impl.support.AbstractInterface)1 WsdlInterface (com.eviware.soapui.impl.wsdl.WsdlInterface)1 WsdlOperation (com.eviware.soapui.impl.wsdl.WsdlOperation)1 WsdlProject (com.eviware.soapui.impl.wsdl.WsdlProject)1 WsdlMockOperation (com.eviware.soapui.impl.wsdl.mock.WsdlMockOperation)1 WsdlMockResponse (com.eviware.soapui.impl.wsdl.mock.WsdlMockResponse)1 WsdlMockService (com.eviware.soapui.impl.wsdl.mock.WsdlMockService)1 MockOperationDispatcher (com.eviware.soapui.impl.wsdl.mock.dispatch.MockOperationDispatcher)1