Class: MockServerCLI

Inherits:
Thor
  • Object
show all
Includes:
CLIHelpers, MockServer::Model::DSL, MockServer::UtilityMethods
Defined in:
lib/cli.rb

Overview

CLI for mock server and proxy clients

Constant Summary

Constants included from CLIHelpers

CLIHelpers::LOGGER

Constants included from MockServer

MockServer::CLEAR_ENDPOINT, MockServer::DUMP_LOG_ENDPOINT, MockServer::EXPECTATION_ENDPOINT, MockServer::HTTP_FORWARD, MockServer::HTTP_REQUEST, MockServer::HTTP_RESPONSE, MockServer::HTTP_TIMES, MockServer::RESET_ENDPOINT, MockServer::RETRIEVE_ENDPOINT, MockServer::VERSION

Instance Method Summary collapse

Methods included from MockServer::Model::DSL

#at_least, #body, #cookie, #decode, #delay_by, #exact, #exactly, #expectation, #expectation_from_json, #forward, #header, #once, #parameter, #parameterized, #regex, #request, #request_from_json, #response, #times, #unlimited, #xpath

Methods included from MockServer::UtilityMethods

#camelize, #camelized_hash, #parse_string_to_json, #symbolize_keys

Methods included from CLIHelpers

#error, #execute_command, #mockserver_client, #print_parameters, #proxy_client, #read_file, #to_struct

Instance Method Details

#clearObject



118
119
120
121
122
123
124
# File 'lib/cli.rb', line 118

def clear
  error_message = 'ERROR: No request provided. HINT: Use `clear` to selectively clear requests. Use `reset` to clear all.'
  execute_command(false, true, error_message) do |client, _|
    payload = read_file(options.data)
    client.clear(payload)
  end
end

#dump_logObject



110
111
112
113
114
# File 'lib/cli.rb', line 110

def dump_log
  execute_command do |client, options|
    options.data ? client.dump_log(read_file(options.data), options.java) : client.dump_log(nil, options.java)
  end
end

#registerObject



97
98
99
100
101
102
103
104
105
# File 'lib/cli.rb', line 97

def register
  execute_command(true, true) do |client, options|
    payload          = read_file(options.data)
    mock_expectation = expectation do |expectation|
      expectation.populate_from_payload(payload)
    end
    client.register(mock_expectation)
  end
end

#resetObject



128
129
130
131
132
# File 'lib/cli.rb', line 128

def reset
  execute_command do |client, _|
    client.reset
  end
end

#retrieveObject



88
89
90
91
92
93
# File 'lib/cli.rb', line 88

def retrieve
  execute_command do |client, _|
    result = options.data ? client.retrieve(read_file(options.data)) : client.retrieve
    puts "RESULT:\n".bold + "#{result.to_json}".green
  end
end

#verifyObject



136
137
138
139
140
141
142
143
144
145
# File 'lib/cli.rb', line 136

def verify
  execute_command(false, true) do |client, _|
    payload      = read_file(options.data)
    mock_request = payload[HTTP_REQUEST]
    mock_times   = payload[HTTP_TIMES]

    error 'No request found for verifying against' unless mock_request
    mock_times ? client.verify(mock_request, mock_times) : client.verify(mock_request)
  end
end