2014-11-05 82 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 
}; 

希望這有助於,