2016-06-07 51 views
0

我有一個jsonurl,我想讀,它看起來像這樣:如何爲gatling json編寫自定義進紙器?

> { 
>  "elements": [ 
>  { 
>   "box": { 
>   "x": 0, 
>   "y": 0, 
>   "width": 186, 
>   "height": 10.526316 
>   }, 
>   "type": "Header" 
>  }, 
>  { 
>   "box": { 
>   "x": 0, 
>   "y": 0, 
>   "width": 0, 
>   "height": 0 
>   }, 
>   "type": "Regular" 
>  }, 
>  { 
>   "box": { 
>   "x": 0, 
>   "y": 14.035088, 
>   "width": 43.333332, 
>   "height": 3.508772 
>   }, 
>   "type": "Regular" 
>  }, 
>  { 
>   "box": { 
>   "x": 95.08772, 
>   "y": 14.035088, 
>   "width": 90.87719, 
>   "height": 45.614037 
>   }, 
>   "type": "Image" 
>  }, 
>  { 
>   "box": { 
>   "x": 95.08772, 
>   "y": 63.157894, 
>   "width": 90.87719, 
>   "height": 3.508772 
>   }, 
>   "type": "Regular" 
>  }, 
>  { 
>   "box": { 
>   "x": 95.08772, 
>   "y": 63.157894, 
>   "width": 90.87719, 
>   "height": 3.508772 
>   }, 
>   "type": "Regular" 
>  }, 
>  { 
>   "box": { 
>   "x": 47.54386, 
>   "y": 42.105263, 
>   "width": 43.333332, 
>   "height": 5.9649124 
>   }, 
>   "type": "Regular" 
>  }, 
>  { 
>   "box": { 
>   "x": 0, 
>   "y": 0, 
>   "width": 43.333332, 
>   "height": 98.24561 
>   }, 
>   "type": "Regular" 
>  }, 
>  { 
>   "box": { 
>   "x": 47.54386, 
>   "y": 0, 
>   "width": 43.333332, 
>   "height": 98.24561 
>   }, 
>   "type": "Regular" 
>  }, 
>  { 
>   "box": { 
>   "x": 95.08772, 
>   "y": 0, 
>   "width": 43.333332, 
>   "height": 98.24561 
>   }, 
>   "type": "Regular" 
>  }, 
>  { 
>   "box": { 
>   "x": 142.63158, 
>   "y": 0, 
>   "width": 43.333332, 
>   "height": 98.24561 
>   }, 
>   "type": "Regular" 
>  } 
>  ], 
>  "points": [ 
>  { 
>   "x": 190, 
>   "y": 22.192982 
>  }, 
>  { 
>   "x": 376, 
>   "y": 22.192982 
>  }, 
>  { 
>   "x": 376, 
>   "y": 120.4386 
>  }, 
>  { 
>   "x": 190, 
>   "y": 120.4386 
>  } 
>  ], 
>  "state": "UNUSED", 
>  "contentPath": "/content/ffx/print-authoring/en/newsholes/FNZ/DPT/2016/05/30/test_pages/q001/newshole-63019301", 
>  "assetId": null }, 

然後我想讀的"state""contentPath"和映射。 目前我使用的是靜態源,如:

VAL nhfeeder = jsonFile( 「形狀-data.json」)

使用如,

.feed(nhfeeder)

這是一個靜態的源,所以我想要一個自定義的進紙器,可以直接從jsonurl讀取,並做需要。

回答

0

Gatling documentation您可以在「JSON饋線」部分

val jsonUrlFeeder = jsonUrl("http://me.com/foo.json") 
+0

這不是一個非常有用的答案,也是通用的,除了重點 – VeRo

0

您需要更改的唯一的事情就是讓你的JSON的根元素是一個數組找到解決方案。 不這樣做,將導致:#

java.lang.IllegalArgumentException: Root element of JSON feeder file isn't an array

你的JSON結構應該是:

[ 
    {"box": { 
     "x": 0, 
     "y": 0, 
     "width": 186, 
     "height": 10.526316 
    }, 
    "type": "Header" 
    }, 
    { 
    "box": { 
     "x": 0, 
     "y": 0, 
     "width": 0, 
     "height": 0 
    }, 
    "type": "Regular" 
    }, 
    { 
    "box": { 
     "x": 0, 
     "y": 14.035088, 
     "width": 43.333332, 
     "height": 3.508772 
    }, 
    "type": "Regular" 
    } 
] 

從這點上來說,當你創建進紙器:

val nhfeeder = jsonUrl("http://url-to-json/shapes-data.json").records 

你現在有一個饋線,它將在會話表達式中使用時提供值:

scenario("my-scenario") 
.foreach(nhfeeder, "shape", "index") { 
exec(
    http("calculate-for-shape-{index}") 
    .get("/calculate-area/${shape.box.width}/${shape.box.height}") 
)} 

我想象一個場景,你想測試一個函數來計算你的形狀的面積。這裏的重要部分是您可以使用表達式語言來瀏覽記錄。 Json數組內的Json對象。