mockserver-client 6.1.0 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44,6 +44,8 @@ module MockServer
44
44
  'http_sse_response' => 'httpSseResponse',
45
45
  'http_websocket_response' => 'httpWebSocketResponse',
46
46
  'template_type' => 'templateType',
47
+ 'template_file' => 'templateFile',
48
+ 'file_path' => 'filePath',
47
49
  'base64_bytes' => 'base64Bytes',
48
50
  'not_body' => 'not',
49
51
  'content_type' => 'contentType',
@@ -61,7 +63,28 @@ module MockServer
61
63
  'base_path' => 'basePath',
62
64
  'id_field' => 'idField',
63
65
  'id_strategy' => 'idStrategy',
64
- 'initial_data' => 'initialData'
66
+ 'initial_data' => 'initialData',
67
+ 'error_status' => 'errorStatus',
68
+ 'error_probability' => 'errorProbability',
69
+ 'drop_connection_probability' => 'dropConnectionProbability',
70
+ 'retry_after' => 'retryAfter',
71
+ 'succeed_first' => 'succeedFirst',
72
+ 'fail_request_count' => 'failRequestCount',
73
+ 'outage_after_millis' => 'outageAfterMillis',
74
+ 'outage_duration_millis' => 'outageDurationMillis',
75
+ 'truncate_body_at_fraction' => 'truncateBodyAtFraction',
76
+ 'malformed_body' => 'malformedBody',
77
+ 'slow_response_chunk_size' => 'slowResponseChunkSize',
78
+ 'slow_response_chunk_delay' => 'slowResponseChunkDelay',
79
+ 'quota_name' => 'quotaName',
80
+ 'quota_limit' => 'quotaLimit',
81
+ 'quota_window_millis' => 'quotaWindowMillis',
82
+ 'quota_error_status' => 'quotaErrorStatus',
83
+ 'degradation_ramp_millis' => 'degradationRampMillis',
84
+ 'http_class_callback' => 'httpClassCallback',
85
+ 'http_object_callback' => 'httpObjectCallback',
86
+ 'failure_policy' => 'failurePolicy',
87
+ 'http_responses' => 'httpResponses'
65
88
  }.freeze
66
89
 
67
90
  REVERSE_FIELD_MAP = FIELD_MAP.invert.freeze
@@ -69,7 +92,7 @@ module MockServer
69
92
  # Known Body type strings used to distinguish Body objects from plain hashes
70
93
  # during deserialization.
71
94
  BODY_TYPES = Set.new(%w[
72
- STRING JSON REGEX XML BINARY JSON_SCHEMA JSON_PATH XPATH XML_SCHEMA JSON_RPC GRAPHQL
95
+ STRING JSON REGEX XML BINARY JSON_SCHEMA JSON_PATH XPATH XML_SCHEMA JSON_RPC GRAPHQL FILE
73
96
  ]).freeze
74
97
 
75
98
  # -------------------------------------------------------------------
@@ -339,9 +362,11 @@ module MockServer
339
362
  end
340
363
 
341
364
  class Body
342
- attr_accessor :type, :string, :json, :base64_bytes, :not_body, :content_type, :charset
365
+ attr_accessor :type, :string, :json, :base64_bytes, :not_body, :content_type, :charset,
366
+ :file_path, :template_type
343
367
 
344
- def initialize(type: nil, string: nil, json: nil, base64_bytes: nil, not_body: nil, content_type: nil, charset: nil)
368
+ def initialize(type: nil, string: nil, json: nil, base64_bytes: nil, not_body: nil,
369
+ content_type: nil, charset: nil, file_path: nil, template_type: nil)
345
370
  @type = type
346
371
  @string = string
347
372
  @json = json
@@ -349,17 +374,21 @@ module MockServer
349
374
  @not_body = not_body
350
375
  @content_type = content_type
351
376
  @charset = charset
377
+ @file_path = file_path
378
+ @template_type = template_type
352
379
  end
353
380
 
354
381
  def to_h
355
382
  result = {}
356
- result['type'] = @type unless @type.nil?
357
- result['string'] = @string unless @string.nil?
358
- result['json'] = @json unless @json.nil?
359
- result['base64Bytes'] = @base64_bytes unless @base64_bytes.nil?
360
- result['not'] = @not_body unless @not_body.nil?
361
- result['contentType'] = @content_type unless @content_type.nil?
362
- result['charset'] = @charset unless @charset.nil?
383
+ result['type'] = @type unless @type.nil?
384
+ result['string'] = @string unless @string.nil?
385
+ result['json'] = @json unless @json.nil?
386
+ result['base64Bytes'] = @base64_bytes unless @base64_bytes.nil?
387
+ result['not'] = @not_body unless @not_body.nil?
388
+ result['contentType'] = @content_type unless @content_type.nil?
389
+ result['charset'] = @charset unless @charset.nil?
390
+ result['filePath'] = @file_path unless @file_path.nil?
391
+ result['templateType'] = @template_type unless @template_type.nil?
363
392
  result
364
393
  end
365
394
 
@@ -367,13 +396,15 @@ module MockServer
367
396
  return nil if data.nil?
368
397
 
369
398
  new(
370
- type: data['type'],
371
- string: data['string'],
372
- json: data['json'],
373
- base64_bytes: data['base64Bytes'],
374
- not_body: data['not'],
375
- content_type: data['contentType'],
376
- charset: data['charset']
399
+ type: data['type'],
400
+ string: data['string'],
401
+ json: data['json'],
402
+ base64_bytes: data['base64Bytes'],
403
+ not_body: data['not'],
404
+ content_type: data['contentType'],
405
+ charset: data['charset'],
406
+ file_path: data['filePath'],
407
+ template_type: data['templateType']
377
408
  )
378
409
  end
379
410
 
@@ -397,6 +428,10 @@ module MockServer
397
428
  new(type: 'XML', string: value)
398
429
  end
399
430
 
431
+ def self.file(file_path, content_type: nil, template_type: nil)
432
+ new(type: 'FILE', file_path: file_path, content_type: content_type, template_type: template_type)
433
+ end
434
+
400
435
  def self.json_rpc(method_name, params_schema: nil)
401
436
  JsonRpcBody.new(method_name: method_name, params_schema: params_schema)
402
437
  end
@@ -404,6 +439,11 @@ module MockServer
404
439
  def self.graphql(query, operation_name: nil, variables_schema: nil)
405
440
  GraphQLBody.new(query: query, operation_name: operation_name, variables_schema: variables_schema)
406
441
  end
442
+
443
+ def with_template_type(template_type)
444
+ @template_type = template_type
445
+ self
446
+ end
407
447
  end
408
448
 
409
449
  class JsonRpcBody
@@ -789,11 +829,12 @@ module MockServer
789
829
  end
790
830
 
791
831
  class HttpTemplate
792
- attr_accessor :template_type, :template, :delay, :primary
832
+ attr_accessor :template_type, :template, :template_file, :delay, :primary
793
833
 
794
- def initialize(template_type: 'JAVASCRIPT', template: nil, delay: nil, primary: nil)
834
+ def initialize(template_type: 'JAVASCRIPT', template: nil, template_file: nil, delay: nil, primary: nil)
795
835
  @template_type = template_type
796
836
  @template = template
837
+ @template_file = template_file
797
838
  @delay = delay
798
839
  @primary = primary
799
840
  end
@@ -802,6 +843,7 @@ module MockServer
802
843
  MockServer.strip_none({
803
844
  'templateType' => @template_type,
804
845
  'template' => @template,
846
+ 'templateFile' => @template_file,
805
847
  'delay' => @delay&.to_h,
806
848
  'primary' => @primary
807
849
  })
@@ -813,13 +855,19 @@ module MockServer
813
855
  new(
814
856
  template_type: data.fetch('templateType', 'JAVASCRIPT'),
815
857
  template: data['template'],
858
+ template_file: data['templateFile'],
816
859
  delay: Delay.from_hash(data['delay']),
817
860
  primary: data['primary']
818
861
  )
819
862
  end
820
863
 
821
- def self.template(template_type, template = nil)
822
- new(template_type: template_type, template: template)
864
+ def self.template(template_type, template = nil, template_file: nil)
865
+ new(template_type: template_type, template: template, template_file: template_file)
866
+ end
867
+
868
+ def with_template_file(template_file)
869
+ @template_file = template_file
870
+ self
823
871
  end
824
872
  end
825
873
 
@@ -1146,14 +1194,396 @@ module MockServer
1146
1194
  end
1147
1195
  end
1148
1196
 
1197
+ class GrpcStreamMessage
1198
+ attr_accessor :json, :delay
1199
+
1200
+ def initialize(json: nil, delay: nil)
1201
+ @json = json
1202
+ @delay = delay
1203
+ end
1204
+
1205
+ def to_h
1206
+ result = {}
1207
+ result['json'] = @json unless @json.nil?
1208
+ result['delay'] = @delay.to_h if @delay
1209
+ result
1210
+ end
1211
+
1212
+ def self.from_hash(data)
1213
+ return nil if data.nil?
1214
+
1215
+ new(
1216
+ json: data['json'],
1217
+ delay: Delay.from_hash(data['delay'])
1218
+ )
1219
+ end
1220
+ end
1221
+
1222
+ class GrpcStreamResponse
1223
+ attr_accessor :status_name, :status_message, :headers, :messages,
1224
+ :close_connection, :delay, :primary
1225
+
1226
+ def initialize(status_name: nil, status_message: nil, headers: nil,
1227
+ messages: nil, close_connection: nil, delay: nil, primary: nil)
1228
+ @status_name = status_name
1229
+ @status_message = status_message
1230
+ @headers = headers
1231
+ @messages = messages
1232
+ @close_connection = close_connection
1233
+ @delay = delay
1234
+ @primary = primary
1235
+ end
1236
+
1237
+ def to_h
1238
+ result = {}
1239
+ result['statusName'] = @status_name unless @status_name.nil?
1240
+ result['statusMessage'] = @status_message unless @status_message.nil?
1241
+ result['headers'] = MockServer.serialize_key_multi_values(@headers) if @headers
1242
+ result['messages'] = @messages&.map(&:to_h) if @messages
1243
+ result['closeConnection'] = @close_connection unless @close_connection.nil?
1244
+ result['delay'] = @delay.to_h if @delay
1245
+ result['primary'] = @primary unless @primary.nil?
1246
+ result
1247
+ end
1248
+
1249
+ def self.from_hash(data)
1250
+ return nil if data.nil?
1251
+
1252
+ messages_data = data['messages']
1253
+ messages = messages_data&.map { |m| GrpcStreamMessage.from_hash(m) }
1254
+ new(
1255
+ status_name: data['statusName'],
1256
+ status_message: data['statusMessage'],
1257
+ headers: MockServer.deserialize_key_multi_values(data['headers']),
1258
+ messages: messages,
1259
+ close_connection: data['closeConnection'],
1260
+ delay: Delay.from_hash(data['delay']),
1261
+ primary: data['primary']
1262
+ )
1263
+ end
1264
+ end
1265
+
1266
+ class GrpcBidiRule
1267
+ attr_accessor :match_json, :responses
1268
+
1269
+ def initialize(match_json: nil, responses: nil)
1270
+ @match_json = match_json
1271
+ @responses = responses
1272
+ end
1273
+
1274
+ def to_h
1275
+ result = {}
1276
+ result['matchJson'] = @match_json unless @match_json.nil?
1277
+ result['responses'] = @responses&.map(&:to_h) if @responses
1278
+ result
1279
+ end
1280
+
1281
+ def self.from_hash(data)
1282
+ return nil if data.nil?
1283
+
1284
+ responses_data = data['responses']
1285
+ responses = responses_data&.map { |r| GrpcStreamMessage.from_hash(r) }
1286
+ new(
1287
+ match_json: data['matchJson'],
1288
+ responses: responses
1289
+ )
1290
+ end
1291
+ end
1292
+
1293
+ class GrpcBidiResponse
1294
+ attr_accessor :status_name, :status_message, :headers, :messages,
1295
+ :rules, :close_connection, :delay, :primary
1296
+
1297
+ def initialize(status_name: nil, status_message: nil, headers: nil,
1298
+ messages: nil, rules: nil, close_connection: nil, delay: nil, primary: nil)
1299
+ @status_name = status_name
1300
+ @status_message = status_message
1301
+ @headers = headers
1302
+ @messages = messages
1303
+ @rules = rules
1304
+ @close_connection = close_connection
1305
+ @delay = delay
1306
+ @primary = primary
1307
+ end
1308
+
1309
+ def to_h
1310
+ result = {}
1311
+ result['statusName'] = @status_name unless @status_name.nil?
1312
+ result['statusMessage'] = @status_message unless @status_message.nil?
1313
+ result['headers'] = MockServer.serialize_key_multi_values(@headers) if @headers
1314
+ result['messages'] = @messages&.map(&:to_h) if @messages
1315
+ result['rules'] = @rules&.map(&:to_h) if @rules
1316
+ result['closeConnection'] = @close_connection unless @close_connection.nil?
1317
+ result['delay'] = @delay.to_h if @delay
1318
+ result['primary'] = @primary unless @primary.nil?
1319
+ result
1320
+ end
1321
+
1322
+ def self.from_hash(data)
1323
+ return nil if data.nil?
1324
+
1325
+ messages_data = data['messages']
1326
+ messages = messages_data&.map { |m| GrpcStreamMessage.from_hash(m) }
1327
+ rules_data = data['rules']
1328
+ rules = rules_data&.map { |r| GrpcBidiRule.from_hash(r) }
1329
+ new(
1330
+ status_name: data['statusName'],
1331
+ status_message: data['statusMessage'],
1332
+ headers: MockServer.deserialize_key_multi_values(data['headers']),
1333
+ messages: messages,
1334
+ rules: rules,
1335
+ close_connection: data['closeConnection'],
1336
+ delay: Delay.from_hash(data['delay']),
1337
+ primary: data['primary']
1338
+ )
1339
+ end
1340
+ end
1341
+
1342
+ class BinaryResponse
1343
+ attr_accessor :binary_data, :delay, :primary
1344
+
1345
+ def initialize(binary_data: nil, delay: nil, primary: nil)
1346
+ @binary_data = binary_data
1347
+ @delay = delay
1348
+ @primary = primary
1349
+ end
1350
+
1351
+ def to_h
1352
+ result = {}
1353
+ result['binaryData'] = @binary_data unless @binary_data.nil?
1354
+ result['delay'] = @delay.to_h if @delay
1355
+ result['primary'] = @primary unless @primary.nil?
1356
+ result
1357
+ end
1358
+
1359
+ def self.from_hash(data)
1360
+ return nil if data.nil?
1361
+
1362
+ new(
1363
+ binary_data: data['binaryData'],
1364
+ delay: Delay.from_hash(data['delay']),
1365
+ primary: data['primary']
1366
+ )
1367
+ end
1368
+ end
1369
+
1370
+ class DnsRecord
1371
+ attr_accessor :name, :type, :dns_class, :ttl, :value,
1372
+ :priority, :weight, :port
1373
+
1374
+ def initialize(name: nil, type: nil, dns_class: nil, ttl: nil,
1375
+ value: nil, priority: nil, weight: nil, port: nil)
1376
+ @name = name
1377
+ @type = type
1378
+ @dns_class = dns_class
1379
+ @ttl = ttl
1380
+ @value = value
1381
+ @priority = priority
1382
+ @weight = weight
1383
+ @port = port
1384
+ end
1385
+
1386
+ def to_h
1387
+ result = {}
1388
+ result['name'] = @name unless @name.nil?
1389
+ result['type'] = @type unless @type.nil?
1390
+ result['dnsClass'] = @dns_class unless @dns_class.nil?
1391
+ result['ttl'] = @ttl unless @ttl.nil?
1392
+ result['value'] = @value unless @value.nil?
1393
+ result['priority'] = @priority unless @priority.nil?
1394
+ result['weight'] = @weight unless @weight.nil?
1395
+ result['port'] = @port unless @port.nil?
1396
+ result
1397
+ end
1398
+
1399
+ def self.from_hash(data)
1400
+ return nil if data.nil?
1401
+
1402
+ new(
1403
+ name: data['name'],
1404
+ type: data['type'],
1405
+ dns_class: data['dnsClass'],
1406
+ ttl: data['ttl'],
1407
+ value: data['value'],
1408
+ priority: data['priority'],
1409
+ weight: data['weight'],
1410
+ port: data['port']
1411
+ )
1412
+ end
1413
+
1414
+ def self.a_record(name, ip)
1415
+ new(name: name, type: 'A', value: ip)
1416
+ end
1417
+
1418
+ def self.aaaa_record(name, ip)
1419
+ new(name: name, type: 'AAAA', value: ip)
1420
+ end
1421
+
1422
+ def self.cname_record(name, cname)
1423
+ new(name: name, type: 'CNAME', value: cname)
1424
+ end
1425
+
1426
+ def self.mx_record(name, priority, exchange)
1427
+ new(name: name, type: 'MX', priority: priority, value: exchange)
1428
+ end
1429
+
1430
+ def self.srv_record(name, priority, weight, port, target)
1431
+ new(name: name, type: 'SRV', priority: priority, weight: weight, port: port, value: target)
1432
+ end
1433
+
1434
+ def self.txt_record(name, text)
1435
+ new(name: name, type: 'TXT', value: text)
1436
+ end
1437
+
1438
+ def self.ptr_record(name, pointer)
1439
+ new(name: name, type: 'PTR', value: pointer)
1440
+ end
1441
+ end
1442
+
1443
+ class DnsResponse
1444
+ attr_accessor :response_code, :answer_records, :authority_records,
1445
+ :additional_records, :delay, :primary
1446
+
1447
+ def initialize(response_code: nil, answer_records: nil, authority_records: nil,
1448
+ additional_records: nil, delay: nil, primary: nil)
1449
+ @response_code = response_code
1450
+ @answer_records = answer_records
1451
+ @authority_records = authority_records
1452
+ @additional_records = additional_records
1453
+ @delay = delay
1454
+ @primary = primary
1455
+ end
1456
+
1457
+ def to_h
1458
+ result = {}
1459
+ result['responseCode'] = @response_code unless @response_code.nil?
1460
+ result['answerRecords'] = @answer_records.map(&:to_h) if @answer_records
1461
+ result['authorityRecords'] = @authority_records.map(&:to_h) if @authority_records
1462
+ result['additionalRecords'] = @additional_records.map(&:to_h) if @additional_records
1463
+ result['delay'] = @delay.to_h if @delay
1464
+ result['primary'] = @primary unless @primary.nil?
1465
+ result
1466
+ end
1467
+
1468
+ def self.from_hash(data)
1469
+ return nil if data.nil?
1470
+
1471
+ answer_data = data['answerRecords']
1472
+ authority_data = data['authorityRecords']
1473
+ additional_data = data['additionalRecords']
1474
+ new(
1475
+ response_code: data['responseCode'],
1476
+ answer_records: answer_data&.map { |r| DnsRecord.from_hash(r) },
1477
+ authority_records: authority_data&.map { |r| DnsRecord.from_hash(r) },
1478
+ additional_records: additional_data&.map { |r| DnsRecord.from_hash(r) },
1479
+ delay: Delay.from_hash(data['delay']),
1480
+ primary: data['primary']
1481
+ )
1482
+ end
1483
+ end
1484
+
1485
+ class HttpChaosProfile
1486
+ attr_accessor :error_status, :error_probability, :drop_connection_probability,
1487
+ :retry_after, :latency, :seed, :succeed_first, :fail_request_count,
1488
+ :outage_after_millis, :outage_duration_millis,
1489
+ :truncate_body_at_fraction, :malformed_body,
1490
+ :slow_response_chunk_size, :slow_response_chunk_delay,
1491
+ :quota_name, :quota_limit, :quota_window_millis, :quota_error_status,
1492
+ :degradation_ramp_millis
1493
+
1494
+ def initialize(error_status: nil, error_probability: nil, drop_connection_probability: nil,
1495
+ retry_after: nil, latency: nil, seed: nil, succeed_first: nil, fail_request_count: nil,
1496
+ outage_after_millis: nil, outage_duration_millis: nil,
1497
+ truncate_body_at_fraction: nil, malformed_body: nil,
1498
+ slow_response_chunk_size: nil, slow_response_chunk_delay: nil,
1499
+ quota_name: nil, quota_limit: nil, quota_window_millis: nil, quota_error_status: nil,
1500
+ degradation_ramp_millis: nil)
1501
+ @error_status = error_status
1502
+ @error_probability = error_probability
1503
+ @drop_connection_probability = drop_connection_probability
1504
+ @retry_after = retry_after
1505
+ @latency = latency
1506
+ @seed = seed
1507
+ @succeed_first = succeed_first
1508
+ @fail_request_count = fail_request_count
1509
+ @outage_after_millis = outage_after_millis
1510
+ @outage_duration_millis = outage_duration_millis
1511
+ @truncate_body_at_fraction = truncate_body_at_fraction
1512
+ @malformed_body = malformed_body
1513
+ @slow_response_chunk_size = slow_response_chunk_size
1514
+ @slow_response_chunk_delay = slow_response_chunk_delay
1515
+ @quota_name = quota_name
1516
+ @quota_limit = quota_limit
1517
+ @quota_window_millis = quota_window_millis
1518
+ @quota_error_status = quota_error_status
1519
+ @degradation_ramp_millis = degradation_ramp_millis
1520
+ end
1521
+
1522
+ def to_h
1523
+ MockServer.strip_none({
1524
+ 'errorStatus' => @error_status,
1525
+ 'errorProbability' => @error_probability,
1526
+ 'dropConnectionProbability' => @drop_connection_probability,
1527
+ 'retryAfter' => @retry_after,
1528
+ 'latency' => @latency&.to_h,
1529
+ 'seed' => @seed,
1530
+ 'succeedFirst' => @succeed_first,
1531
+ 'failRequestCount' => @fail_request_count,
1532
+ 'outageAfterMillis' => @outage_after_millis,
1533
+ 'outageDurationMillis' => @outage_duration_millis,
1534
+ 'truncateBodyAtFraction' => @truncate_body_at_fraction,
1535
+ 'malformedBody' => @malformed_body,
1536
+ 'slowResponseChunkSize' => @slow_response_chunk_size,
1537
+ 'slowResponseChunkDelay' => @slow_response_chunk_delay&.to_h,
1538
+ 'quotaName' => @quota_name,
1539
+ 'quotaLimit' => @quota_limit,
1540
+ 'quotaWindowMillis' => @quota_window_millis,
1541
+ 'quotaErrorStatus' => @quota_error_status,
1542
+ 'degradationRampMillis' => @degradation_ramp_millis
1543
+ })
1544
+ end
1545
+
1546
+ def self.from_hash(data)
1547
+ return nil if data.nil?
1548
+
1549
+ new(
1550
+ error_status: data['errorStatus'],
1551
+ error_probability: data['errorProbability'],
1552
+ drop_connection_probability: data['dropConnectionProbability'],
1553
+ retry_after: data['retryAfter'],
1554
+ latency: Delay.from_hash(data['latency']),
1555
+ seed: data['seed'],
1556
+ succeed_first: data['succeedFirst'],
1557
+ fail_request_count: data['failRequestCount'],
1558
+ outage_after_millis: data['outageAfterMillis'],
1559
+ outage_duration_millis: data['outageDurationMillis'],
1560
+ truncate_body_at_fraction: data['truncateBodyAtFraction'],
1561
+ malformed_body: data['malformedBody'],
1562
+ slow_response_chunk_size: data['slowResponseChunkSize'],
1563
+ slow_response_chunk_delay: Delay.from_hash(data['slowResponseChunkDelay']),
1564
+ quota_name: data['quotaName'],
1565
+ quota_limit: data['quotaLimit'],
1566
+ quota_window_millis: data['quotaWindowMillis'],
1567
+ quota_error_status: data['quotaErrorStatus'],
1568
+ degradation_ramp_millis: data['degradationRampMillis']
1569
+ )
1570
+ end
1571
+ end
1572
+
1149
1573
  class AfterAction
1150
- attr_accessor :http_request, :http_class_callback, :http_object_callback, :delay
1574
+ # blocking, timeout and failure_policy are only meaningful for before-actions
1575
+ attr_accessor :http_request, :http_class_callback, :http_object_callback, :delay,
1576
+ :blocking, :timeout, :failure_policy
1151
1577
 
1152
- def initialize(http_request: nil, http_class_callback: nil, http_object_callback: nil, delay: nil)
1578
+ def initialize(http_request: nil, http_class_callback: nil, http_object_callback: nil, delay: nil,
1579
+ blocking: nil, timeout: nil, failure_policy: nil)
1153
1580
  @http_request = http_request
1154
1581
  @http_class_callback = http_class_callback
1155
1582
  @http_object_callback = http_object_callback
1156
1583
  @delay = delay
1584
+ @blocking = blocking
1585
+ @timeout = timeout
1586
+ @failure_policy = failure_policy
1157
1587
  end
1158
1588
 
1159
1589
  def to_h
@@ -1161,7 +1591,10 @@ module MockServer
1161
1591
  'httpRequest' => @http_request&.to_h,
1162
1592
  'httpClassCallback' => @http_class_callback&.to_h,
1163
1593
  'httpObjectCallback' => @http_object_callback&.to_h,
1164
- 'delay' => @delay&.to_h
1594
+ 'delay' => @delay&.to_h,
1595
+ 'blocking' => @blocking,
1596
+ 'timeout' => @timeout&.to_h,
1597
+ 'failurePolicy' => @failure_policy
1165
1598
  })
1166
1599
  end
1167
1600
 
@@ -1172,7 +1605,77 @@ module MockServer
1172
1605
  http_request: HttpRequest.from_hash(data['httpRequest']),
1173
1606
  http_class_callback: HttpClassCallback.from_hash(data['httpClassCallback']),
1174
1607
  http_object_callback: HttpObjectCallback.from_hash(data['httpObjectCallback']),
1175
- delay: Delay.from_hash(data['delay'])
1608
+ delay: Delay.from_hash(data['delay']),
1609
+ blocking: data['blocking'],
1610
+ timeout: Delay.from_hash(data['timeout']),
1611
+ failure_policy: data['failurePolicy']
1612
+ )
1613
+ end
1614
+ end
1615
+
1616
+ # A single step in an ordered multi-action expectation pipeline.
1617
+ #
1618
+ # Each step carries exactly ONE action target and a +responder+ flag.
1619
+ # Steps without +responder = true+ are side-effects (fire-and-forget
1620
+ # webhooks/callbacks). Exactly one step in the list must be marked as the
1621
+ # responder; that step's action produces the HTTP response.
1622
+ class ExpectationStep
1623
+ attr_accessor :http_request, :http_class_callback, :http_object_callback,
1624
+ :http_forward, :http_override_forwarded_request,
1625
+ :http_response, :http_error,
1626
+ :responder, :delay, :blocking, :timeout, :failure_policy
1627
+
1628
+ def initialize(http_request: nil, http_class_callback: nil, http_object_callback: nil,
1629
+ http_forward: nil, http_override_forwarded_request: nil,
1630
+ http_response: nil, http_error: nil,
1631
+ responder: nil, delay: nil, blocking: nil, timeout: nil, failure_policy: nil)
1632
+ @http_request = http_request
1633
+ @http_class_callback = http_class_callback
1634
+ @http_object_callback = http_object_callback
1635
+ @http_forward = http_forward
1636
+ @http_override_forwarded_request = http_override_forwarded_request
1637
+ @http_response = http_response
1638
+ @http_error = http_error
1639
+ @responder = responder
1640
+ @delay = delay
1641
+ @blocking = blocking
1642
+ @timeout = timeout
1643
+ @failure_policy = failure_policy
1644
+ end
1645
+
1646
+ def to_h
1647
+ MockServer.strip_none({
1648
+ 'httpRequest' => @http_request&.to_h,
1649
+ 'httpClassCallback' => @http_class_callback&.to_h,
1650
+ 'httpObjectCallback' => @http_object_callback&.to_h,
1651
+ 'httpForward' => @http_forward&.to_h,
1652
+ 'httpOverrideForwardedRequest' => @http_override_forwarded_request&.to_h,
1653
+ 'httpResponse' => @http_response&.to_h,
1654
+ 'httpError' => @http_error&.to_h,
1655
+ 'responder' => @responder,
1656
+ 'delay' => @delay&.to_h,
1657
+ 'blocking' => @blocking,
1658
+ 'timeout' => @timeout&.to_h,
1659
+ 'failurePolicy' => @failure_policy
1660
+ })
1661
+ end
1662
+
1663
+ def self.from_hash(data)
1664
+ return nil if data.nil?
1665
+
1666
+ new(
1667
+ http_request: HttpRequest.from_hash(data['httpRequest']),
1668
+ http_class_callback: HttpClassCallback.from_hash(data['httpClassCallback']),
1669
+ http_object_callback: HttpObjectCallback.from_hash(data['httpObjectCallback']),
1670
+ http_forward: HttpForward.from_hash(data['httpForward']),
1671
+ http_override_forwarded_request: HttpOverrideForwardedRequest.from_hash(data['httpOverrideForwardedRequest']),
1672
+ http_response: HttpResponse.from_hash(data['httpResponse']),
1673
+ http_error: HttpError.from_hash(data['httpError']),
1674
+ responder: data['responder'],
1675
+ delay: Delay.from_hash(data['delay']),
1676
+ blocking: data['blocking'],
1677
+ timeout: Delay.from_hash(data['timeout']),
1678
+ failure_policy: data['failurePolicy']
1176
1679
  )
1177
1680
  end
1178
1681
  end
@@ -1183,9 +1686,12 @@ module MockServer
1183
1686
  :http_response_object_callback, :http_forward,
1184
1687
  :http_forward_template, :http_forward_class_callback,
1185
1688
  :http_forward_object_callback, :http_override_forwarded_request,
1186
- :http_error, :times, :time_to_live,
1187
- :http_sse_response, :http_websocket_response, :after_actions,
1188
- :http_responses, :response_mode,
1689
+ :http_error, :times, :time_to_live, :chaos,
1690
+ :http_sse_response, :http_websocket_response,
1691
+ :grpc_stream_response, :grpc_bidi_response,
1692
+ :binary_response, :dns_response,
1693
+ :before_actions, :after_actions,
1694
+ :http_responses, :response_mode, :steps,
1189
1695
  :scenario_name, :scenario_state, :new_scenario_state
1190
1696
 
1191
1697
  def initialize(id: nil, priority: nil, percentage: nil, http_request: nil, http_response: nil,
@@ -1193,9 +1699,12 @@ module MockServer
1193
1699
  http_response_object_callback: nil, http_forward: nil,
1194
1700
  http_forward_template: nil, http_forward_class_callback: nil,
1195
1701
  http_forward_object_callback: nil, http_override_forwarded_request: nil,
1196
- http_error: nil, times: nil, time_to_live: nil,
1197
- http_sse_response: nil, http_websocket_response: nil, after_actions: nil,
1198
- http_responses: nil, response_mode: nil,
1702
+ http_error: nil, times: nil, time_to_live: nil, chaos: nil,
1703
+ http_sse_response: nil, http_websocket_response: nil,
1704
+ grpc_stream_response: nil, grpc_bidi_response: nil,
1705
+ binary_response: nil, dns_response: nil,
1706
+ before_actions: nil, after_actions: nil,
1707
+ http_responses: nil, response_mode: nil, steps: nil,
1199
1708
  scenario_name: nil, scenario_state: nil, new_scenario_state: nil)
1200
1709
  @id = id
1201
1710
  @priority = priority
@@ -1213,17 +1722,31 @@ module MockServer
1213
1722
  @http_error = http_error
1214
1723
  @times = times
1215
1724
  @time_to_live = time_to_live
1725
+ @chaos = chaos
1216
1726
  @http_sse_response = http_sse_response
1217
1727
  @http_websocket_response = http_websocket_response
1728
+ @grpc_stream_response = grpc_stream_response
1729
+ @grpc_bidi_response = grpc_bidi_response
1730
+ @binary_response = binary_response
1731
+ @dns_response = dns_response
1732
+ @before_actions = before_actions
1218
1733
  @after_actions = after_actions
1219
1734
  @http_responses = http_responses
1220
1735
  @response_mode = response_mode
1736
+ @steps = steps
1221
1737
  @scenario_name = scenario_name
1222
1738
  @scenario_state = scenario_state
1223
1739
  @new_scenario_state = new_scenario_state
1224
1740
  end
1225
1741
 
1226
1742
  def to_h
1743
+ before_actions_h = nil
1744
+ if @before_actions.is_a?(Array)
1745
+ before_actions_h = @before_actions.map(&:to_h) unless @before_actions.empty?
1746
+ elsif @before_actions
1747
+ before_actions_h = @before_actions.to_h
1748
+ end
1749
+
1227
1750
  after_actions_h = nil
1228
1751
  if @after_actions.is_a?(Array)
1229
1752
  after_actions_h = @after_actions.map(&:to_h) unless @after_actions.empty?
@@ -1248,11 +1771,18 @@ module MockServer
1248
1771
  'httpError' => @http_error&.to_h,
1249
1772
  'httpSseResponse' => @http_sse_response&.to_h,
1250
1773
  'httpWebSocketResponse' => @http_websocket_response&.to_h,
1774
+ 'grpcStreamResponse' => @grpc_stream_response&.to_h,
1775
+ 'grpcBidiResponse' => @grpc_bidi_response&.to_h,
1776
+ 'binaryResponse' => @binary_response&.to_h,
1777
+ 'dnsResponse' => @dns_response&.to_h,
1778
+ 'beforeActions' => before_actions_h,
1251
1779
  'afterActions' => after_actions_h,
1252
1780
  'httpResponses' => @http_responses&.map(&:to_h),
1253
1781
  'responseMode' => @response_mode,
1782
+ 'steps' => @steps&.map(&:to_h),
1254
1783
  'times' => @times&.to_h,
1255
1784
  'timeToLive' => @time_to_live&.to_h,
1785
+ 'chaos' => @chaos&.to_h,
1256
1786
  'scenarioName' => @scenario_name,
1257
1787
  'scenarioState' => @scenario_state,
1258
1788
  'newScenarioState' => @new_scenario_state
@@ -1262,11 +1792,18 @@ module MockServer
1262
1792
  def self.from_hash(data)
1263
1793
  return nil if data.nil?
1264
1794
 
1795
+ before_actions_data = data['beforeActions']
1796
+ before_actions = if before_actions_data.is_a?(Array)
1797
+ before_actions_data.map { |a| AfterAction.from_hash(a) }
1798
+ elsif before_actions_data
1799
+ [AfterAction.from_hash(before_actions_data)]
1800
+ end
1801
+
1265
1802
  after_actions_data = data['afterActions']
1266
1803
  after_actions = if after_actions_data.is_a?(Array)
1267
1804
  after_actions_data.map { |a| AfterAction.from_hash(a) }
1268
1805
  elsif after_actions_data
1269
- AfterAction.from_hash(after_actions_data)
1806
+ [AfterAction.from_hash(after_actions_data)]
1270
1807
  end
1271
1808
 
1272
1809
  new(
@@ -1286,11 +1823,18 @@ module MockServer
1286
1823
  http_error: HttpError.from_hash(data['httpError']),
1287
1824
  http_sse_response: HttpSseResponse.from_hash(data['httpSseResponse']),
1288
1825
  http_websocket_response: HttpWebSocketResponse.from_hash(data['httpWebSocketResponse']),
1826
+ grpc_stream_response: GrpcStreamResponse.from_hash(data['grpcStreamResponse']),
1827
+ grpc_bidi_response: GrpcBidiResponse.from_hash(data['grpcBidiResponse']),
1828
+ binary_response: BinaryResponse.from_hash(data['binaryResponse']),
1829
+ dns_response: DnsResponse.from_hash(data['dnsResponse']),
1830
+ before_actions: before_actions,
1289
1831
  after_actions: after_actions,
1290
1832
  http_responses: data['httpResponses']&.map { |r| HttpResponse.from_hash(r) },
1291
1833
  response_mode: data['responseMode'],
1834
+ steps: data['steps']&.map { |s| ExpectationStep.from_hash(s) },
1292
1835
  times: Times.from_hash(data['times']),
1293
1836
  time_to_live: TimeToLive.from_hash(data['timeToLive']),
1837
+ chaos: HttpChaosProfile.from_hash(data['chaos']),
1294
1838
  scenario_name: data['scenarioName'],
1295
1839
  scenario_state: data['scenarioState'],
1296
1840
  new_scenario_state: data['newScenarioState']
@@ -1394,12 +1938,13 @@ module MockServer
1394
1938
  end
1395
1939
 
1396
1940
  class Verification
1397
- attr_accessor :http_request, :expectation_id, :times,
1941
+ attr_accessor :http_request, :http_response, :expectation_id, :times,
1398
1942
  :maximum_number_of_request_to_return_in_verification_failure
1399
1943
 
1400
- def initialize(http_request: nil, expectation_id: nil, times: nil,
1944
+ def initialize(http_request: nil, http_response: nil, expectation_id: nil, times: nil,
1401
1945
  maximum_number_of_request_to_return_in_verification_failure: nil)
1402
1946
  @http_request = http_request
1947
+ @http_response = http_response
1403
1948
  @expectation_id = expectation_id
1404
1949
  @times = times
1405
1950
  @maximum_number_of_request_to_return_in_verification_failure = maximum_number_of_request_to_return_in_verification_failure
@@ -1408,6 +1953,7 @@ module MockServer
1408
1953
  def to_h
1409
1954
  MockServer.strip_none({
1410
1955
  'httpRequest' => @http_request&.to_h,
1956
+ 'httpResponse' => @http_response&.to_h,
1411
1957
  'expectationId' => @expectation_id&.to_h,
1412
1958
  'times' => @times&.to_h,
1413
1959
  'maximumNumberOfRequestToReturnInVerificationFailure' => @maximum_number_of_request_to_return_in_verification_failure
@@ -1419,6 +1965,7 @@ module MockServer
1419
1965
 
1420
1966
  new(
1421
1967
  http_request: HttpRequest.from_hash(data['httpRequest']),
1968
+ http_response: HttpResponse.from_hash(data['httpResponse']),
1422
1969
  expectation_id: ExpectationId.from_hash(data['expectationId']),
1423
1970
  times: VerificationTimes.from_hash(data['times']),
1424
1971
  maximum_number_of_request_to_return_in_verification_failure: data['maximumNumberOfRequestToReturnInVerificationFailure']
@@ -1427,16 +1974,18 @@ module MockServer
1427
1974
  end
1428
1975
 
1429
1976
  class VerificationSequence
1430
- attr_accessor :http_requests, :expectation_ids
1977
+ attr_accessor :http_requests, :http_responses, :expectation_ids
1431
1978
 
1432
- def initialize(http_requests: nil, expectation_ids: nil)
1979
+ def initialize(http_requests: nil, http_responses: nil, expectation_ids: nil)
1433
1980
  @http_requests = http_requests
1981
+ @http_responses = http_responses
1434
1982
  @expectation_ids = expectation_ids
1435
1983
  end
1436
1984
 
1437
1985
  def to_h
1438
1986
  MockServer.strip_none({
1439
1987
  'httpRequests' => @http_requests&.map(&:to_h),
1988
+ 'httpResponses' => @http_responses&.map(&:to_h),
1440
1989
  'expectationIds' => @expectation_ids&.map(&:to_h)
1441
1990
  })
1442
1991
  end
@@ -1445,9 +1994,11 @@ module MockServer
1445
1994
  return nil if data.nil?
1446
1995
 
1447
1996
  http_requests_data = data['httpRequests']
1997
+ http_responses_data = data['httpResponses']
1448
1998
  expectation_ids_data = data['expectationIds']
1449
1999
  new(
1450
- http_requests: http_requests_data&.map { |r| HttpRequest.from_hash(r) },
2000
+ http_requests: http_requests_data&.map { |r| HttpRequest.from_hash(r) },
2001
+ http_responses: http_responses_data&.map { |r| HttpResponse.from_hash(r) },
1451
2002
  expectation_ids: expectation_ids_data&.map { |e| ExpectationId.from_hash(e) }
1452
2003
  )
1453
2004
  end