2016-03-08 80 views
0

我有一个JSON文件,它看起来像下面使用里面的Json馈线,在加特林

{ 
"OrderRef": "Rand12345" 
"siteContactName": "ABC", 
    "siteContactNumber": "12345678", 
    "contactMobileNumber": "12345678", 
    "estimatedDeliveryDate": "2016-03-08", 
    "orderLines": [ 
    { 
     "productCode": "846581", 
     "productName": "ABC", 
     "quantity": 112, 
     "price": 5.01, 
     "vatAmount": 112.22 
    }, 
    { 
     "productCode": "938169", 
     "productName": "DEF", 
     "quantity": 6, 
     "price": 45.03, 
     "vatAmount": 54.04 
    } 
    ] 
"orderNett": 831.30, 
    "orderVatAmount": 166.26, 
    "orderTotal": 997.56 
} 

我要送这个JSON作为一个机构,一个POST请求,在这里我必须参数化OrderRef,产品代码和其各自的产品名称。

所以我创建了2个文件,即orderref.csv和product.csv,其中orderref.csv有一个order ID列表,product.csv有一个产品代码列表及其各自的名称。当我尝试这样做,

class Order extends Simulation { 

    val orderref = csv("orderref.csv").random 
    val product = csv("product.csv").random 

    val scn = scenario("OrderCreation") 
    .feed(orderref) 
    .feed(product) 

    .exec(http("OrderCreation") 
    .post("/abc/orders") 
    .body(""" 
      { 
    "OrderRef": "${orderref}" 
    "siteContactName": "ABC", 
     "siteContactNumber": "12345678", 
     "contactMobileNumber": "12345678", 
     "estimatedDeliveryDate": "2016-03-08", 
     "orderLines": [ 
     { 
// ProductCode and ProductName are the headers of the columns in my product.csv 
      "productCode": "${ProductCode}", 
      "productName": "${ProductName}", 
      "quantity": 112, 
      "price": 5.01, 
      "vatAmount": 112.22 
     }, 
     { 
      "productCode": "${ProductCode}", 
      "productName": "${ProductName}", 
      "quantity": 6, 
      "price": 45.03, 
      "vatAmount": 54.04 
     } 
     ] 
    "orderNett": 831.30, 
     "orderVatAmount": 166.26, 
     "orderTotal": 997.56 
    }""").asJson) 

    setUp(scn.inject(atOnceUsers(1))) 
    } 

我得到

not found: value ProductCode 
not found: value ProductName 

但orderref被接受。任何建议请。

谢谢

回答

0

水晶球:您的csv文件中的空白处。 CSV spec说不修剪。

+0

谢谢:)解决了我的问题 –

+0

要把工作交给chiromancy –

+0

@GoldMeen我有类似的程序,但它给了我下面的错误'igcZincCompiler $ -/Users/Sunil/gatling-charts- highcharts-bundle-2.2.5/user-files/simulations/VertexPerformance.scala:28:type mismatch; found:String(“' – Sunil