Search in sources :

Example 1 with WsdlMockService

use of com.eviware.soapui.impl.wsdl.mock.WsdlMockService in project microcks by microcks.

the class SoapUIProjectImporter method getSoapServiceDefinitions.

/**
 * Get the definitions of Soap Services from mock services.
 */
private List<Service> getSoapServiceDefinitions(List<WsdlMockService> mockServices) throws MockRepositoryImportException {
    List<Service> result = new ArrayList<>();
    for (WsdlMockService wms : mockServices) {
        // First assume it's a Soap one.
        Service service = new Service();
        service.setName(wms.getName());
        service.setType(ServiceType.SOAP_HTTP);
        // Ensure we've got only one interface and extract its namespace.
        WsdlInterface[] wi = wms.getMockedInterfaces();
        if (wi == null || wi.length > 1) {
        // TODO Throw a typed exception here...
        }
        service.setXmlNS(wi[0].getBindingName().getNamespaceURI());
        // Extract version from custom properties.
        String version = wms.getPropertyValue(SERVICE_VERSION_PROPERTY);
        if (version == null) {
            log.error("Version property is missing in Project properties");
            throw new MockRepositoryImportException("Version property is missing in Project properties");
        }
        service.setVersion(version);
        // Then build its operations.
        service.setOperations(extractOperations(wms, wi[0]));
        result.add(service);
    }
    return result;
}
Also used : WsdlMockService(com.eviware.soapui.impl.wsdl.mock.WsdlMockService) WsdlInterface(com.eviware.soapui.impl.wsdl.WsdlInterface) WsdlMockService(com.eviware.soapui.impl.wsdl.mock.WsdlMockService) RestMockService(com.eviware.soapui.impl.rest.mock.RestMockService) MockService(com.eviware.soapui.model.mock.MockService) MockRepositoryImportException(io.github.microcks.util.MockRepositoryImportException)

Example 2 with WsdlMockService

use of com.eviware.soapui.impl.wsdl.mock.WsdlMockService in project microcks by microcks.

the class SoapUIProjectImporter method getResourceDefinitions.

@Override
public List<Resource> getResourceDefinitions(Service service) {
    List<Resource> results = new ArrayList<>();
    // For now, only available for Wsdl based projects having mocked interfaces.
    WsdlMockService wsdlMockService = project.getMockServiceByName(service.getName());
    if (wsdlMockService != null) {
        // Use only the first interface of the mock service corresponding to service.
        WsdlInterface wi = project.getMockServiceByName(service.getName()).getMockedInterfaces()[0];
        // Find the name of the definition we must look for within all interfaces.
        String definitionName = wi.getConfig().getDefinition();
        List<Interface> pis = project.getInterfaceList();
        for (Interface pi : pis) {
            if (pi instanceof WsdlInterface) {
                WsdlInterface candidateWI = (WsdlInterface) pi;
                if (candidateWI.getDefinition().equals(definitionName)) {
                    List<DefintionPartConfig> parts = candidateWI.getConfig().getDefinitionCache().getPartList();
                    if (parts != null && parts.size() > 0) {
                        // First part is always the wsdl definition, get its content as string.
                        String wsdlContent = parts.get(0).getContent().newCursor().getTextValue();
                        // Then browse the following one (XSD) and change relative path in imports.
                        for (int i = 1; i < parts.size(); i++) {
                            DefintionPartConfig xsdConfig = parts.get(i);
                            String xsdUrl = xsdConfig.getUrl();
                            String xsdName = xsdUrl.substring(xsdUrl.lastIndexOf('/') + 1);
                            String xsdContent = xsdConfig.getContent().newCursor().getTextValue();
                            // Build a new xsd resource for this part.
                            Resource xsdResource = new Resource();
                            xsdResource.setName(xsdName);
                            xsdResource.setType(ResourceType.XSD);
                            xsdResource.setContent(xsdContent);
                            results.add(xsdResource);
                            // URL references within WSDL must be replaced by their local counterpart.
                            wsdlContent = wsdlContent.replace(xsdUrl, "./" + xsdName);
                        }
                        // Finally, declare englobing wsdl resource.
                        Resource wsdlResource = new Resource();
                        wsdlResource.setName(service.getName() + "-" + service.getVersion() + ".wsdl");
                        wsdlResource.setType(ResourceType.WSDL);
                        wsdlResource.setContent(wsdlContent);
                        results.add(wsdlResource);
                    }
                }
            }
        }
    }
    return results;
}
Also used : WsdlMockService(com.eviware.soapui.impl.wsdl.mock.WsdlMockService) DefintionPartConfig(com.eviware.soapui.config.DefintionPartConfig) WsdlInterface(com.eviware.soapui.impl.wsdl.WsdlInterface) WsdlInterface(com.eviware.soapui.impl.wsdl.WsdlInterface) AbstractInterface(com.eviware.soapui.impl.support.AbstractInterface) Interface(com.eviware.soapui.model.iface.Interface)

Aggregations

WsdlInterface (com.eviware.soapui.impl.wsdl.WsdlInterface)2 WsdlMockService (com.eviware.soapui.impl.wsdl.mock.WsdlMockService)2 DefintionPartConfig (com.eviware.soapui.config.DefintionPartConfig)1 RestMockService (com.eviware.soapui.impl.rest.mock.RestMockService)1 AbstractInterface (com.eviware.soapui.impl.support.AbstractInterface)1 Interface (com.eviware.soapui.model.iface.Interface)1 MockService (com.eviware.soapui.model.mock.MockService)1 MockRepositoryImportException (io.github.microcks.util.MockRepositoryImportException)1