UNPKG

13.1 kBPlain TextView Raw
1Feature: Complex Transformations
2
3
4Scenario: Serial readers and transformers configured with an array of objects
5
6 When I transform the following json:
7 ------------------------------------
8 {
9 "publishers": {
10 "IDW Publishing": {
11 "books": {
12 "Transformers: Combiner Wars": {
13 "isbn-10": "1631403869",
14 "isbn-13": "978-1631403866",
15 "format": "paperback",
16 "publisher": "IDW Publishing (27 Aug. 2015)",
17 "published": "2015-08-18T23:23:24.140Z",
18 "pages": 152
19 }
20 }
21 }
22 }
23 }
24 ------------------------------------
25
26
27 Using the mapping:
28 ------------------------------------
29 [
30 {
31 "reader": {
32 "type": "serial",
33 "readers": [{
34 "type": "jsonPointer",
35 "path": "/publishers/IDW Publishing/books/Transformers: Combiner Wars/isbn-10"
36 }, {
37 "type": "jsonPointer",
38 "path": "/publishers/IDW Publishing/books/Transformers: Combiner Wars/isbn-13"
39 }]
40 },
41 "transformer": {
42 "type": "serial",
43 "transformers": [{
44 "type": "concatenate",
45 "separator": "_"
46 }, {
47 "type": "prefix",
48 "text": "FOO_"
49 }]
50 },
51 "writer": {
52 "type": "jsonPointer",
53 "path": "/combined-isbn"
54 }
55 }
56 ]
57 ------------------------------------
58
59
60 Then I should get:
61 ------------------------------------
62 {
63 "combined-isbn": "FOO_1631403869_978-1631403866"
64 }
65 ------------------------------------
66
67
68Scenario: Serial readers and transformers configured with an array of strings
69
70 When I transform the following json:
71 ------------------------------------
72 {
73 "publishers": {
74 "IDW Publishing": {
75 "books": {
76 "Transformers: Combiner Wars": {
77 "isbn-10": "1631403869",
78 "isbn-13": "978-1631403866",
79 "format": "paperback",
80 "publisher": "IDW Publishing (27 Aug. 2015)",
81 "published": "2015-08-18T23:23:24.140Z",
82 "pages": 152
83 }
84 }
85 }
86 }
87 }
88 ------------------------------------
89
90
91 Using the mapping:
92 ------------------------------------
93 [
94 {
95 "reader": {
96 "type": "serial",
97 "readers": [
98 "/publishers/IDW Publishing/books/Transformers: Combiner Wars/isbn-10",
99 "/publishers/IDW Publishing/books/Transformers: Combiner Wars/isbn-13"
100 ]
101 },
102 "transformer": {
103 "type": "serial",
104 "transformers": [
105 "concatenate",
106 "prefix"
107 ]
108 },
109 "writer": {
110 "type": "jsonPointer",
111 "path": "/combined-isbn"
112 }
113 }
114 ]
115 ------------------------------------
116
117
118 Then I should get:
119 ------------------------------------
120 {
121 "combined-isbn": "1631403869 978-1631403866"
122 }
123 ------------------------------------
124
125
126Scenario: Mutual exclusion (first reader present)
127
128 When I transform the following json:
129 ------------------------------------
130 {
131 "publishers": {
132 "IDW Publishing": {
133 "books": {
134 "Transformers: Combiner Wars": {
135 "isbn-10": "1631403869",
136 "isbn-13": "978-1631403866",
137 "format": "paperback",
138 "publisher": "IDW Publishing (27 Aug. 2015)",
139 "published": "2015-08-18T23:23:24.140Z",
140 "pages": 152
141 }
142 }
143 }
144 }
145 }
146 ------------------------------------
147
148
149 Using the mapping:
150 ------------------------------------
151 [
152 {
153 "reader": {
154 "type": "serial",
155 "readers": [
156 "/publishers/IDW Publishing/books/Transformers: Combiner Wars/format",
157 "/publishers/IDW Publishing/books/Transformers: Combiner Wars/isbn-13"
158 ]
159 },
160 "transformer": "mutualExclusion",
161 "writer": {
162 "type": "jsonPointer",
163 "path": "/format-or-isbn-13"
164 }
165 }
166 ]
167 ------------------------------------
168
169
170 Then I should get:
171 ------------------------------------
172 {
173 "format-or-isbn-13": "paperback"
174 }
175 ------------------------------------
176
177
178Scenario: Mutual exclusion (second reader present)
179
180 When I transform the following json:
181 ------------------------------------
182 {
183 "publishers": {
184 "IDW Publishing": {
185 "books": {
186 "Transformers: Combiner Wars": {
187 "isbn-10": "1631403869",
188 "isbn-13": "978-1631403866",
189 "format": "paperback",
190 "publisher": "IDW Publishing (27 Aug. 2015)",
191 "published": "2015-08-18T23:23:24.140Z",
192 "pages": 152
193 }
194 }
195 }
196 }
197 }
198 ------------------------------------
199
200
201 Using the mapping:
202 ------------------------------------
203 [
204 {
205 "reader": {
206 "type": "serial",
207 "readers": [
208 "/publishers/IDW Publishing/books/Transformers: Combiner Wars/foo",
209 "/publishers/IDW Publishing/books/Transformers: Combiner Wars/isbn-13"
210 ]
211 },
212 "transformer": "mutualExclusion",
213 "writer": {
214 "type": "jsonPointer",
215 "path": "/format-or-isbn-13"
216 }
217 }
218 ]
219 ------------------------------------
220
221
222 Then I should get:
223 ------------------------------------
224 {
225 "format-or-isbn-13": "978-1631403866"
226 }
227 ------------------------------------
228
229
230Scenario: Guard condition (first reader truthy)
231
232 When I transform the following json:
233 ------------------------------------
234 {
235 "publishers": {
236 "IDW Publishing": {
237 "books": {
238 "Transformers: Combiner Wars": {
239 "isbn-10": "1631403869",
240 "isbn-13": "978-1631403866",
241 "format": "paperback",
242 "publisher": "IDW Publishing (27 Aug. 2015)",
243 "published": "2015-08-18T23:23:24.140Z",
244 "pages": 152
245 }
246 }
247 }
248 }
249 }
250 ------------------------------------
251
252
253 Using the mapping:
254 ------------------------------------
255 [
256 {
257 "reader": {
258 "type": "serial",
259 "readers": [
260 "/publishers/IDW Publishing/books/Transformers: Combiner Wars/format",
261 "/publishers/IDW Publishing/books/Transformers: Combiner Wars/isbn-13"
262 ]
263 },
264 "transformer": "guard",
265 "writer": {
266 "type": "jsonPointer",
267 "path": "/isbn-13"
268 }
269 }
270 ]
271 ------------------------------------
272
273
274 Then I should get:
275 ------------------------------------
276 {
277 }
278 ------------------------------------
279
280
281Scenario: Guard condition (first reader falsey)
282
283 When I transform the following json:
284 ------------------------------------
285 {
286 "publishers": {
287 "IDW Publishing": {
288 "books": {
289 "Transformers: Combiner Wars": {
290 "isbn-10": "1631403869",
291 "isbn-13": "978-1631403866",
292 "format": "paperback",
293 "publisher": "IDW Publishing (27 Aug. 2015)",
294 "published": "2015-08-18T23:23:24.140Z",
295 "pages": 152
296 }
297 }
298 }
299 }
300 }
301 ------------------------------------
302
303
304 Using the mapping:
305 ------------------------------------
306 [
307 {
308 "reader": {
309 "type": "serial",
310 "readers": [
311 "/publishers/IDW Publishing/books/Transformers: Combiner Wars/foo",
312 "/publishers/IDW Publishing/books/Transformers: Combiner Wars/isbn-13"
313 ]
314 },
315 "transformer": "guard",
316 "writer": {
317 "type": "jsonPointer",
318 "path": "/isbn-13"
319 }
320 }
321 ]
322 ------------------------------------
323
324
325 Then I should get:
326 ------------------------------------
327 {
328 "isbn-13": "978-1631403866"
329 }
330 ------------------------------------
331
332
333Scenario: Conditional (first reader truthy)
334
335 When I transform the following json:
336 ------------------------------------
337 {
338 "publishers": {
339 "IDW Publishing": {
340 "books": {
341 "Transformers: Combiner Wars": {
342 "isbn-10": "1631403869",
343 "isbn-13": "978-1631403866",
344 "format": "paperback",
345 "publisher": "IDW Publishing (27 Aug. 2015)",
346 "published": "2015-08-18T23:23:24.140Z",
347 "pages": 152
348 }
349 }
350 }
351 }
352 }
353 ------------------------------------
354
355
356 Using the mapping:
357 ------------------------------------
358 [
359 {
360 "reader": {
361 "type": "serial",
362 "readers": [
363 "/publishers/IDW Publishing/books/Transformers: Combiner Wars/format",
364 "/publishers/IDW Publishing/books/Transformers: Combiner Wars/isbn-13"
365 ]
366 },
367 "transformer": "conditional",
368 "writer": {
369 "type": "jsonPointer",
370 "path": "/isbn-13"
371 }
372 }
373 ]
374 ------------------------------------
375
376
377 Then I should get:
378 ------------------------------------
379 {
380 "isbn-13": "978-1631403866"
381 }
382 ------------------------------------
383
384
385Scenario: Conditional (second reader falsey)
386
387 When I transform the following json:
388 ------------------------------------
389 {
390 "publishers": {
391 "IDW Publishing": {
392 "books": {
393 "Transformers: Combiner Wars": {
394 "isbn-10": "1631403869",
395 "isbn-13": "978-1631403866",
396 "format": "paperback",
397 "publisher": "IDW Publishing (27 Aug. 2015)",
398 "published": "2015-08-18T23:23:24.140Z",
399 "pages": 152
400 }
401 }
402 }
403 }
404 }
405 ------------------------------------
406
407
408 Using the mapping:
409 ------------------------------------
410 [
411 {
412 "reader": {
413 "type": "serial",
414 "readers": [
415 "/publishers/IDW Publishing/books/Transformers: Combiner Wars/foo",
416 "/publishers/IDW Publishing/books/Transformers: Combiner Wars/isbn-13"
417 ]
418 },
419 "transformer": "conditional",
420 "writer": {
421 "type": "jsonPointer",
422 "path": "/isbn-13"
423 }
424 }
425 ]
426 ------------------------------------
427
428
429 Then I should get:
430 ------------------------------------
431 {
432 }
433 ------------------------------------
434
435
436Scenario: Conditional (second reader falsey)
437
438 When I transform the following json:
439 ------------------------------------
440 {
441 "autobots": [
442 "bumble bee",
443 "optimus prime"
444 ]
445 }
446 ------------------------------------
447
448
449 Using the mapping:
450 ------------------------------------
451 [
452 {
453 "reader": "/autobots",
454 "transformer": {
455 "type": "mapSeries",
456 "transformer": {
457 "type": "uppercase"
458 }
459 },
460 "writer": "/autobots"
461 }
462 ]
463 ------------------------------------
464
465
466 Then I should get:
467 ------------------------------------
468 {
469 "autobots": [
470 "BUMBLE BEE",
471 "OPTIMUS PRIME"
472 ]
473 }
474 ------------------------------------