Search in sources :

Example 1 with RestTestRequest

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

the class SoapUIProjectImporter method buildRequest.

/**
 * Build a domain Request from SoapUI RestTestRequest.
 */
private Request buildRequest(RestTestRequest rtr) {
    Request request = new Request();
    request.setName(rtr.getName());
    request.setContent(rtr.getRequestContent());
    request.setHeaders(buildHeaders(rtr.getRequestHeaders()));
    // Add query parameters only (template are holded by the operation itself.)
    RestParamsPropertyHolder paramsHolder = rtr.getParams();
    for (int i = 0; i < paramsHolder.getPropertyCount(); i++) {
        // if (paramsHolder.getPropertyAt(i).getStyle() == ParameterStyle.QUERY){
        Parameter param = new Parameter();
        param.setName(paramsHolder.getPropertyAt(i).getName());
        param.setValue(paramsHolder.getPropertyAt(i).getValue());
        request.addQueryParameter(param);
    // }
    }
    return request;
}
Also used : RestParamsPropertyHolder(com.eviware.soapui.impl.rest.support.RestParamsPropertyHolder) WsdlTestRequest(com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest) RestTestRequest(com.eviware.soapui.impl.wsdl.teststeps.RestTestRequest)

Example 2 with RestTestRequest

use of com.eviware.soapui.impl.wsdl.teststeps.RestTestRequest 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());
}
Also used : 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) RESTMockActionConfig(com.eviware.soapui.config.RESTMockActionConfig) WsdlTestRequest(com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest) RestTestRequest(com.eviware.soapui.impl.wsdl.teststeps.RestTestRequest) RESTMockResponseConfig(com.eviware.soapui.config.RESTMockResponseConfig) RestMockResponse(com.eviware.soapui.impl.rest.mock.RestMockResponse) WsdlMockResponse(com.eviware.soapui.impl.wsdl.mock.WsdlMockResponse) MockResponse(com.eviware.soapui.model.mock.MockResponse) RestTestRequest(com.eviware.soapui.impl.wsdl.teststeps.RestTestRequest) MockOperation(com.eviware.soapui.model.mock.MockOperation) WsdlMockOperation(com.eviware.soapui.impl.wsdl.mock.WsdlMockOperation) StringToStringsMap(com.eviware.soapui.support.types.StringToStringsMap)

Example 3 with RestTestRequest

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

the class SoapUIProjectImporter method collectRestTestRequests.

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

Aggregations

RestTestRequest (com.eviware.soapui.impl.wsdl.teststeps.RestTestRequest)3 RestParamsPropertyHolder (com.eviware.soapui.impl.rest.support.RestParamsPropertyHolder)2 RestTestRequestStep (com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep)2 WsdlTestRequest (com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest)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 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