2016-06-07 3 views
0

Ich habe einen jsonurl, die ich lesen will, und es sieht wie folgt aus:Wie schreibe ich eine benutzerdefinierte Zuführung für 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 }, 

ich die "state" und "contentPath" und ordnet sie dann lesen möchten. zur Zeit verwende ich eine statische Quelle wie:

val nhfeeder = jsonFile ("Formen-data.json")

als verwenden,

.feed (nhfeeder)

das ist eine statische Quelle, also möchte ich einen benutzerdefinierten Zubringer, der direkt von der jsonurl lesen kann und das Notwendige tun .

Antwort

0

In der Gatling documentation Sie Lösung in 'JSON Zubringer Abschnitt

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

Dies ist keine sehr nützliche Antwort und auch generische und neben dem Punkt – VeRo

0

Das einzige, was sich ändern müssen Sie finden können, ist Ihre JSON Root-Element ein Array zu machen. Andernfalls wird so zur Folge: #

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

Ihre JSON Struktur sein sollte:

[ 
    {"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" 
    } 
] 

Von diesem Punkt an, wenn Sie Ihre Feeder erstellen:

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

Sie haben jetzt einen Zubringer, der bei der Verwendung in Sitzungen Werte wie:

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

Ich stellte mir ein Szenario vor, in dem Sie eine Funktion testen möchten, die die Fläche Ihrer Formen berechnet. Der wichtige Teil hier ist, dass Sie Expression Language verwenden können, um durch die Datensätze zu navigieren, aka. Json-Objekt in Ihrem Json-Array.