2014-11-05 44 views
1

我有一个包含我的soap请求的目录,我想重用它们来构建测试套件。 我试过使用ENTITY定义,但无法使其工作,而使用xi:include作为我想包含的代码片段,看起来soapUI并不认识它。在soapUI项目中包含保存在文件中的请求

我的实际项目具有以下结构:

<con:soapui-project> 

    <con:interface > 
     <con:endpoints> 
      <con:endpoint>http://localhost/GestionePreventiviRemoteImpl/GestionePreventiviService_v1</con:endpoint> 
     </con:endpoints> 

     <con:operation isOneWay="false" action="" name="aggiornaPreventivo" bindingOperationName="aggiornaPreventivo" > 
      <con:settings/> 
     </con:operation> 

     <con:operation isOneWay="false" action="" name="creaPreventivo" bindingOperationName="creaPreventivo" > 
      <con:settings/> 
     </con:operation> 

     <con:operation isOneWay="false" action="" name="recuperaPreventivo" bindingOperationName="recuperaPreventivo"> 
      <con:settings/> 
     </con:operation> 
    </con:interface> 

    <con:testSuite name="GestioneServicePortBinding TestSuite"> 
     <con:testCase name="aggiornaPreventivo TestCase"> 
      <con:testStep name="aggiornaPreventivo"> 
       <con:config> 
        <con:interface>GestioneServicePortBinding</con:interface> 
        <con:operation>aggiornaPreventivo</con:operation> 
        <con:request name="aggiornaPreventivo"> 
         <con:endpoint>http://localhost/GestionePreventiviRemoteImpl/GestionePreventiviService_v1</con:endpoint> 

         <con:request> 
          <![CDATA[ 
          <?xml version="1.0" encoding="UTF-8"?> 
          <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://simulatore.Prodotto.be.service.bmed.it/v1"> 
           <soapenv:Header/> 
           <soapenv:Body> 
            <v1:aggiornaPreventivo> 
            <input> 
             <aggiornaPreventivoDTO> 
              <codPrev>1001</codPrev> 
              <codCliente>205</codCliente> 
              ..... 
             </aggiornaPreventivoDTO> 
            </input> 
            </v1:aggiornaPreventivo> 
           </soapenv:Body> 
          </soapenv:Envelope> 
          ]]> 
         </con:request> 
        </con:request> 
       </con:config> 
      </con:testStep> 
     </con:testCase> 
    </con:testSuite> 

</con:soapui-project> 

而我需要的是包括为了处理测试套件外部输入参数的测试案例的要求。因此,像:

<con:testStep name="aggiornaPreventivo"> 
    <con:config> 
     <con:interface>GestioneServicePortBinding</con:interface> 
     <con:operation>aggiornaPreventivo</con:operation> 
     <con:request name="aggiornaPreventivo"> 
      <con:endpoint>http://localhost/GestionePreventiviRemoteImpl/GestionePreventiviService_v1</con:endpoint> 
      <con:request> 
       <xi:include href="aggiornaPreventivoRequest.xml" parse="xml" xpointer="title"/> 
      </con:request> 
     </con:request> 
    </con:config> 
</con:testStep> 

凡aggiornaPreventivoRequest.xml有内容,如:

<v1:aggiornaPreventivo> 
    <input> 
     <aggiornaPreventivoDTO> 
      <codPrev>1001</codPrev> 
      <codCliente>205</codCliente> 
      ..... 
     </aggiornaPreventivoDTO> 
    </input> 
</v1:aggiornaPreventivo> 

感谢您的帮助!

回答

0

我不知道您是否可以在SOAPUI中使用http://www.w3.org/2001/XInclude中的<include>,但是如果您想在请求之外控制请求的节点值,您可以使用属性。

您可以在projecttestSuitetestCasetestStep水平等,可以直接用它在你的要求,你必须使用后续符号取决于你定义你的属性等级添加的属性。从SOAPUI documentation

${#Project#yourProperty} - 引用一个项目性质(跨特定了SoapUI项目引用属性)

${#TestSuite#yourProperty} - 中含的TestSuite

${#TestCase#yourProperty}引用一个TestSuite属性 - 在引用一个TestCase属性包含TestCase

${TestStep name#yourProperty} - 引用TestStep属性

例如,如果你添加的测试组件的属性:

<v1:aggiornaPreventivo> 
    <input> 
     <aggiornaPreventivoDTO> 
      <codPrev>${#TestSuite#codPrevValue}</codPrev> 
      <codCliente>${#TestSuite#codClienteValue}</codCliente> 
      ..... 
     </aggiornaPreventivoDTO> 
    </input> 
</v1:aggiornaPreventivo> 

如果你不知道如何将属性添加到您的项目看一看this

还有,如果你真的有兴趣发送从本地文件的请求,你也可以使用一个groovy一步步测试与后续的代码从特定的文件位置发送一个请求另一种可能性:

import java.io.IOException; 
import java.io.FileInputStream; 
import org.apache.http.entity.FileEntity 
import org.apache.http.client.HttpClient; 
import org.apache.http.client.ResponseHandler; 
import org.apache.http.client.methods.HttpPost; 
import org.apache.http.impl.client.BasicResponseHandler; 
import org.apache.http.impl.client.DefaultHttpClient; 
import org.apache.http.params.DefaultedHttpParams; 
import org.apache.http.params.HttpParams; 

def httpclient = new DefaultHttpClient(); 
// the directory with your xml requests 
def directory = new File("/tmp/myRequests/") 
// for each file in the directory 
directory.eachFile{ file -> 
    // create the request 
    HttpPost post = new HttpPost("http://your_endpoint") 
    def reqEntity = new FileEntity(file,"application/xml"); 
    post.setEntity(reqEntity) 
    // make the post and get the response 
    def responseHandler = new BasicResponseHandler() 
    def responseBody = httpclient.execute(post, responseHandler) 
    log.info responseBody 
}; 

希望这有助于,