以编程方式更新wsdl定义和请求,并在SoapUI中保留参数/属性

时间:2016-03-07 15:11:29

标签: soap groovy wsdl soapui

我们有很多wsdls,在我的SoapUI项目中更新/重构/更新定义和请求非常烦人,所以我开始在groovy脚本上做一些工作。 Curreny看起来像这样:

import com.eviware.soapui.impl.wsdl.*
import com.eviware.soapui.model.iface.Interface
import org.apache.log4j.Logger
import TestHelper.Wsdl.*

import static com.eviware.soapui.impl.wsdl.actions.iface.UpdateInterfaceAction.recreateRequests
import static com.eviware.soapui.impl.wsdl.actions.iface.UpdateInterfaceAction.recreateTestRequests

class UpdateWsdls {

    WsdlProjectPro wsdlProject
    Logger log

    public UpdateWsdls(Logger log, String projectFileName) {
           this.log = log
        this.wsdlProject = new WsdlProjectPro(projectFileName)
    }

    void updateInterfaceDefinitions(List<WsdlInfo> wsdlInfos) {
           if(!wsdlProject.isOpen()) {
            log.warn "Failed to open project"
            return
           }
        wsdlInfos.each { wsdlInfo ->
            def interfaceNames = getBindingNames(wsdlInfo.path)
            interfaceNames.each {
                updateInterfaceDefinition(it, wsdlInfo)
            }

        }        
    }

    void updateInterfaceDefinition(String interfaceName, WsdlInfo wsdlInfo) {        
        List<Interface> interfacesList = wsdlProject.interfaceList
        interfacesList.each { Interface anInterface ->
            if (anInterface instanceof WsdlInterface && interfaceName.equals(anInterface.name)) {
                WsdlInterface wsdlInterface = (WsdlInterface) anInterface
                def currentVersion = -1
                def text = wsdlInterface.getBindingName().toString().split('}');
                if(text.size() > 0) {
                    currentVersion = WsdlHelper.getVersionNumber(text[0])
                }
                if(currentVersion < wsdlInfo.version) {
                    log.info "Updating ${interfaceName}, ${currentVersion} -> ${wsdlInfo.version}"
                    wsdlInterface.updateDefinition(wsdlInfo.path, false)
                    updateRequests(wsdlInterface)
                } else {
                    log.info "${interfaceName} already up-to-date with version ${currentVersion}"
                }
            }            
        }
    }

    void updateRequestDo(WsdlInterface wsdlInterface) {
            try {
            recreateRequests(wsdlInterface,false,false,true,false)
            } 
            catch(Exception ex) {
                log.warn "Failed to update request ${wsdlInterface.getBindingName()}"
            }
            try {
                recreateTestRequests(wsdlInterface,false,false,true,false)
            } catch(Exception ex) {
                log.warn "Failed to update test request ${wsdlInterface.getBindingName()}"
            }     
    }

    void saveWsdlProject() {
        wsdlProject.save()
        wsdlProject.release()
    }

    def getBindingNames(String wsdlFile) {
        def definitions = new XmlParser().parse(new File(wsdlFile))
        return definitions.getByName('*:binding').@name
    }

}


def projectPath = ".." 
//Path to directory with the latest wsdls
def wsdlPathRoot = ".."

def w = new WsdlHelper(log) 
//Get info (name, path, verison number) of the latest wsdls
def wsdlInfos = w.getLatestWsdlInfo(wsdlPathRoot) 

UpdateWsdls updateWsdl = new UpdateWsdls(log, projectPath)
log.info "Updating definitions"
updateWsdl.updateInterfaceDefinitions(wsdlInfos)
log.info "Saving project"
updateWsdl.saveWsdlProject()
log.info "Restart SoapUI for changes to take effect"

总结它是这样做的:

  1. 通过wsdlPathRoot的目录浏览所有wsdls并选择具有最新版本的目录。
  2. 遍历我们当前的界面并检查我们是否有最新版本。
  3. 如果没有,请使用新路径更新其定义并重新创建请求和测试请求。
  4. 到目前为止这个工作正常,问题是我所有请求/测试中的所有数据/属性都消失了。这是一个非常重要的事情,因为我们的许多请求需要10个以上的参数,并且需要很长时间再次手动插入它们。

    我知道soapui pro有一个叫做“refactor definition”的函数,它设法在更新后放回所有内容。是否可以通过编程方式使用/调用?

0 个答案:

没有答案