2012-07-19 30 views
1
@RequestMapping(method=RequestMethod.POST, value="/employeeXML") 
public ModelAndView addEmployeePostXMl(@RequestBody String body) { 
    Source source = new StreamSource(new StringReader(body)); 
    Employee e = (Employee) jaxb2Mashaller.unmarshal(source); 
    employeeDS.add(e); 
    List<Employee> employees = employeeDS.getAll(); 
    EmployeeList list = new EmployeeList(employees); 
    return new ModelAndView(XML_VIEW_NAME, "employees", list); 
} 

我可以測試它的單POST主體即通過JMETER測試Spring RESTful服務。如何爲XML數據提供多個動態輸入?

<employee> 
    <id>3</id> 
    <name>guest3</name> 
    <email>[email protected]</email> 
</employee>. 

但如何檢查它像CSV文件。如果多個動態值我使用CSV文件與數據:

3 aFFaFD  xfchghcxh 
4 dsfgsdF  cxhchcxht 
5 asFDdsF  chcxhcg 
6 sdFsF  cxhxhcgh 
7 SDFsF  cghcxhcg 
8 gfzsgzd  cxghchc 
9 hgfxhfx  cghchgc 
10 fghxf  ghcxhxc 
11 fhgfxh  cghchcc 
12 ghcxxh  cxhcghch 
13 chgxgcvx  cghchcxgch 
14 hgxfhxch  cxhgxchcg 
15 ghcxhcx  vmcvmnvbm 
16 cghch  bnmvmbh 
17 cxghcxhcx mvbhgn 
18 cxghcxh  mnmcghmh 
19 cxghcxhxch mnvmvmcv 
20 xcghchcx  mvcmvmv 

它給unmarshalling異常,因爲後主體應該是XML格式。

回答

1

嘗試使用JMeterRestSampler - 定製JMeter的採樣測試REST服務:

你可以用它與下面的模式一起:

 
Thread Group 
    . . . 
    While Controller 
    Condition: ${__javaScript("${email}"!="<EOF>",)} // until the EOF 
     CSV Data Set Config 
     Filename: [path to your file with test-data] 
     Variable Names: id,name,email 
     REST Sampler 
  <employee> 
       <id>${id}</id> 
       <name>${name}</name> 
       <email>${email}</email> 
      </employee> 
+0

非常感謝@Alies Belik的工作。 – user1500694 2012-07-20 05:55:46

相關問題