Class: MockServer::Expectation

Inherits:
Object
  • Object
show all
Defined in:
lib/mockserver/models.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: nil, priority: nil, percentage: nil, http_request: nil, http_response: nil, http_response_template: nil, http_response_class_callback: nil, http_response_object_callback: nil, http_forward: nil, http_forward_template: nil, http_forward_class_callback: nil, http_forward_object_callback: nil, http_override_forwarded_request: nil, http_error: nil, times: nil, time_to_live: nil, chaos: nil, rate_limit: nil, http_sse_response: nil, http_llm_response: nil, http_websocket_response: nil, grpc_stream_response: nil, grpc_bidi_response: nil, binary_response: nil, dns_response: nil, http_forward_with_fallback: nil, http_forward_validate_action: nil, before_actions: nil, after_actions: nil, http_responses: nil, response_mode: nil, response_weights: nil, switch_after: nil, cross_protocol_scenarios: nil, steps: nil, capture: nil, namespace: nil, scenario_name: nil, scenario_state: nil, new_scenario_state: nil, timestamp: nil) ⇒ Expectation

Returns a new instance of Expectation.



2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
# File 'lib/mockserver/models.rb', line 2385

def initialize(id: nil, priority: nil, percentage: nil, http_request: nil, http_response: nil,
               http_response_template: nil, http_response_class_callback: nil,
               http_response_object_callback: nil, http_forward: nil,
               http_forward_template: nil, http_forward_class_callback: nil,
               http_forward_object_callback: nil, http_override_forwarded_request: nil,
               http_error: nil, times: nil, time_to_live: nil, chaos: nil, rate_limit: nil,
               http_sse_response: nil, http_llm_response: nil, http_websocket_response: nil,
               grpc_stream_response: nil, grpc_bidi_response: nil,
               binary_response: nil, dns_response: nil,
               http_forward_with_fallback: nil, http_forward_validate_action: nil,
               before_actions: nil, after_actions: nil,
               http_responses: nil, response_mode: nil, response_weights: nil,
               switch_after: nil, cross_protocol_scenarios: nil, steps: nil,
               capture: nil, namespace: nil,
               scenario_name: nil, scenario_state: nil, new_scenario_state: nil,
               timestamp: nil)
  @id = id
  @priority = priority
  @percentage = percentage
  @http_request = http_request
  @http_response = http_response
  @http_response_template = http_response_template
  # Route the two class-callback fields through their setters so a bare
  # class-name String passed to the constructor is coerced to an
  # HttpClassCallback (matching the setter / fluent-builder behaviour).
  self.http_response_class_callback = http_response_class_callback
  @http_response_object_callback = http_response_object_callback
  @http_forward = http_forward
  @http_forward_template = http_forward_template
  self.http_forward_class_callback = http_forward_class_callback
  @http_forward_object_callback = http_forward_object_callback
  @http_override_forwarded_request = http_override_forwarded_request
  @http_error = http_error
  @times = times
  @time_to_live = time_to_live
  @chaos = chaos
  @rate_limit = rate_limit
  @http_sse_response = http_sse_response
  @http_llm_response = http_llm_response
  @http_websocket_response = http_websocket_response
  @grpc_stream_response = grpc_stream_response
  @grpc_bidi_response = grpc_bidi_response
  @binary_response = binary_response
  @dns_response = dns_response
  @http_forward_with_fallback = http_forward_with_fallback
  @http_forward_validate_action = http_forward_validate_action
  @before_actions = before_actions
  @after_actions = after_actions
  @http_responses = http_responses
  @response_mode = response_mode
  @response_weights = response_weights
  @switch_after = switch_after
  @cross_protocol_scenarios = cross_protocol_scenarios
  @steps = steps
  @capture = capture
  @namespace = namespace
  @scenario_name = scenario_name
  @scenario_state = scenario_state
  @new_scenario_state = new_scenario_state
  @timestamp = timestamp
end

Instance Attribute Details

#after_actionsObject

Returns the value of attribute after_actions.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def after_actions
  @after_actions
end

#before_actionsObject

Returns the value of attribute before_actions.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def before_actions
  @before_actions
end

#binary_responseObject

Returns the value of attribute binary_response.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def binary_response
  @binary_response
end

#captureObject

Returns the value of attribute capture.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def capture
  @capture
end

#chaosObject

Returns the value of attribute chaos.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def chaos
  @chaos
end

#cross_protocol_scenariosObject

Returns the value of attribute cross_protocol_scenarios.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def cross_protocol_scenarios
  @cross_protocol_scenarios
end

#dns_responseObject

Returns the value of attribute dns_response.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def dns_response
  @dns_response
end

#grpc_bidi_responseObject

Returns the value of attribute grpc_bidi_response.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def grpc_bidi_response
  @grpc_bidi_response
end

#grpc_stream_responseObject

Returns the value of attribute grpc_stream_response.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def grpc_stream_response
  @grpc_stream_response
end

#http_errorObject

Returns the value of attribute http_error.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def http_error
  @http_error
end

#http_forwardObject

Returns the value of attribute http_forward.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def http_forward
  @http_forward
end

#http_forward_class_callbackObject

Returns the value of attribute http_forward_class_callback.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def http_forward_class_callback
  @http_forward_class_callback
end

#http_forward_object_callbackObject

Returns the value of attribute http_forward_object_callback.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def http_forward_object_callback
  @http_forward_object_callback
end

#http_forward_templateObject

Returns the value of attribute http_forward_template.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def http_forward_template
  @http_forward_template
end

#http_forward_validate_actionObject

Returns the value of attribute http_forward_validate_action.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def http_forward_validate_action
  @http_forward_validate_action
end

#http_forward_with_fallbackObject

Returns the value of attribute http_forward_with_fallback.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def http_forward_with_fallback
  @http_forward_with_fallback
end

#http_llm_responseObject

Returns the value of attribute http_llm_response.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def http_llm_response
  @http_llm_response
end

#http_override_forwarded_requestObject

Returns the value of attribute http_override_forwarded_request.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def http_override_forwarded_request
  @http_override_forwarded_request
end

#http_requestObject

Returns the value of attribute http_request.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def http_request
  @http_request
end

#http_responseObject

Returns the value of attribute http_response.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def http_response
  @http_response
end

#http_response_class_callbackObject

Returns the value of attribute http_response_class_callback.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def http_response_class_callback
  @http_response_class_callback
end

#http_response_object_callbackObject

Returns the value of attribute http_response_object_callback.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def http_response_object_callback
  @http_response_object_callback
end

#http_response_templateObject

Returns the value of attribute http_response_template.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def http_response_template
  @http_response_template
end

#http_responsesObject

Returns the value of attribute http_responses.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def http_responses
  @http_responses
end

#http_sse_responseObject

Returns the value of attribute http_sse_response.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def http_sse_response
  @http_sse_response
end

#http_websocket_responseObject

Returns the value of attribute http_websocket_response.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def http_websocket_response
  @http_websocket_response
end

#idObject

Returns the value of attribute id.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def id
  @id
end

#namespaceObject

Returns the value of attribute namespace.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def namespace
  @namespace
end

#new_scenario_stateObject

Returns the value of attribute new_scenario_state.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def new_scenario_state
  @new_scenario_state
end

#percentageObject

Returns the value of attribute percentage.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def percentage
  @percentage
end

#priorityObject

Returns the value of attribute priority.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def priority
  @priority
end

#rate_limitObject

Returns the value of attribute rate_limit.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def rate_limit
  @rate_limit
end

#response_modeObject

Returns the value of attribute response_mode.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def response_mode
  @response_mode
end

#response_weightsObject

Returns the value of attribute response_weights.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def response_weights
  @response_weights
end

#scenario_nameObject

Returns the value of attribute scenario_name.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def scenario_name
  @scenario_name
end

#scenario_stateObject

Returns the value of attribute scenario_state.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def scenario_state
  @scenario_state
end

#stepsObject

Returns the value of attribute steps.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def steps
  @steps
end

#switch_afterObject

Returns the value of attribute switch_after.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def switch_after
  @switch_after
end

#time_to_liveObject

Returns the value of attribute time_to_live.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def time_to_live
  @time_to_live
end

#timesObject

Returns the value of attribute times.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def times
  @times
end

#timestampObject

Returns the value of attribute timestamp.



2370
2371
2372
# File 'lib/mockserver/models.rb', line 2370

def timestamp
  @timestamp
end

Class Method Details

.from_hash(data) ⇒ Object



2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
# File 'lib/mockserver/models.rb', line 2523

def self.from_hash(data)
  return nil if data.nil?

  before_actions_data = data['beforeActions']
  before_actions = if before_actions_data.is_a?(Array)
                     before_actions_data.map { |a| AfterAction.from_hash(a) }
                   elsif before_actions_data
                     [AfterAction.from_hash(before_actions_data)]
                   end

  after_actions_data = data['afterActions']
  after_actions = if after_actions_data.is_a?(Array)
                    after_actions_data.map { |a| AfterAction.from_hash(a) }
                  elsif after_actions_data
                    [AfterAction.from_hash(after_actions_data)]
                  end

  new(
    id:                              data['id'],
    priority:                        data['priority'],
    percentage:                      data['percentage'],
    http_request:                    HttpRequest.from_hash(data['httpRequest']),
    http_response:                   HttpResponse.from_hash(data['httpResponse']),
    http_response_template:          HttpTemplate.from_hash(data['httpResponseTemplate']),
    http_response_class_callback:    HttpClassCallback.from_hash(data['httpResponseClassCallback']),
    http_response_object_callback:   HttpObjectCallback.from_hash(data['httpResponseObjectCallback']),
    http_forward:                    HttpForward.from_hash(data['httpForward']),
    http_forward_template:           HttpTemplate.from_hash(data['httpForwardTemplate']),
    http_forward_class_callback:     HttpClassCallback.from_hash(data['httpForwardClassCallback']),
    http_forward_object_callback:    HttpObjectCallback.from_hash(data['httpForwardObjectCallback']),
    http_override_forwarded_request: HttpOverrideForwardedRequest.from_hash(data['httpOverrideForwardedRequest']),
    http_forward_validate_action:    HttpForwardValidateAction.from_hash(data['httpForwardValidateAction']),
    http_forward_with_fallback:      HttpForwardWithFallback.from_hash(data['httpForwardWithFallback']),
    http_error:                      HttpError.from_hash(data['httpError']),
    http_sse_response:               HttpSseResponse.from_hash(data['httpSseResponse']),
    http_llm_response:               data['httpLlmResponse'],
    http_websocket_response:         HttpWebSocketResponse.from_hash(data['httpWebSocketResponse']),
    grpc_stream_response:            GrpcStreamResponse.from_hash(data['grpcStreamResponse']),
    grpc_bidi_response:              GrpcBidiResponse.from_hash(data['grpcBidiResponse']),
    binary_response:                 BinaryResponse.from_hash(data['binaryResponse']),
    dns_response:                    DnsResponse.from_hash(data['dnsResponse']),
    before_actions:                  before_actions,
    after_actions:                   after_actions,
    http_responses:                  data['httpResponses']&.map { |r| HttpResponse.from_hash(r) },
    response_mode:                   data['responseMode'],
    response_weights:                data['responseWeights'],
    switch_after:                    data['switchAfter'],
    cross_protocol_scenarios:        data['crossProtocolScenarios']&.map { |c| CrossProtocolScenario.from_hash(c) },
    steps:                           data['steps']&.map { |s| ExpectationStep.from_hash(s) },
    capture:                         data['capture']&.map { |c| CaptureRule.from_hash(c) },
    rate_limit:                      RateLimit.from_hash(data['rateLimit']),
    namespace:                       data['namespace'],
    times:                           Times.from_hash(data['times']),
    time_to_live:                    TimeToLive.from_hash(data['timeToLive']),
    chaos:                           HttpChaosProfile.from_hash(data['chaos']),
    scenario_name:                   data['scenarioName'],
    scenario_state:                  data['scenarioState'],
    new_scenario_state:              data['newScenarioState'],
    timestamp:                       data['timestamp']
  )
end

Instance Method Details

#to_hObject



2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
# File 'lib/mockserver/models.rb', line 2463

def to_h
  before_actions_h = nil
  if @before_actions.is_a?(Array)
    before_actions_h = @before_actions.map(&:to_h) unless @before_actions.empty?
  elsif @before_actions
    before_actions_h = @before_actions.to_h
  end

  after_actions_h = nil
  if @after_actions.is_a?(Array)
    after_actions_h = @after_actions.map(&:to_h) unless @after_actions.empty?
  elsif @after_actions
    after_actions_h = @after_actions.to_h
  end

  MockServer.strip_none({
    'id'                           => @id,
    'priority'                     => @priority,
    'percentage'                   => @percentage,
    'httpRequest'                  => @http_request&.to_h,
    'httpResponse'                 => @http_response&.to_h,
    'httpResponseTemplate'         => @http_response_template&.to_h,
    'httpResponseClassCallback'    => @http_response_class_callback&.to_h,
    'httpResponseObjectCallback'   => @http_response_object_callback&.to_h,
    'httpForward'                  => @http_forward&.to_h,
    'httpForwardTemplate'          => @http_forward_template&.to_h,
    'httpForwardClassCallback'     => @http_forward_class_callback&.to_h,
    'httpForwardObjectCallback'    => @http_forward_object_callback&.to_h,
    'httpOverrideForwardedRequest' => @http_override_forwarded_request&.to_h,
    'httpForwardValidateAction'    => @http_forward_validate_action&.to_h,
    'httpForwardWithFallback'      => @http_forward_with_fallback&.to_h,
    'httpError'                    => @http_error&.to_h,
    'httpSseResponse'              => @http_sse_response&.to_h,
    'httpLlmResponse'              => MockServer.serialize_value(@http_llm_response),
    'httpWebSocketResponse'        => @http_websocket_response&.to_h,
    'grpcStreamResponse'           => @grpc_stream_response&.to_h,
    'grpcBidiResponse'             => @grpc_bidi_response&.to_h,
    'binaryResponse'               => @binary_response&.to_h,
    'dnsResponse'                  => @dns_response&.to_h,
    'beforeActions'                => before_actions_h,
    'afterActions'                 => after_actions_h,
    'httpResponses'                => @http_responses&.map(&:to_h),
    'responseMode'                 => @response_mode,
    'responseWeights'              => @response_weights,
    'switchAfter'                  => @switch_after,
    'crossProtocolScenarios'       => @cross_protocol_scenarios&.map(&:to_h),
    'steps'                        => @steps&.map(&:to_h),
    'capture'                      => @capture&.map(&:to_h),
    'rateLimit'                    => @rate_limit&.to_h,
    'namespace'                    => @namespace,
    'times'                        => @times&.to_h,
    'timeToLive'                   => @time_to_live&.to_h,
    'chaos'                        => @chaos&.to_h,
    'scenarioName'                 => @scenario_name,
    'scenarioState'                => @scenario_state,
    'newScenarioState'             => @new_scenario_state,
    'timestamp'                    => @timestamp
  })
end