wiremock_mapper 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/builders/match_builder.rb +2 -0
- data/lib/builders/url_match_builder.rb +2 -0
- data/lib/configuration.rb +6 -0
- data/lib/wiremock_mapper.rb +7 -1
- data/spec/wiremock_mapper_spec.rb +62 -0
- data/wiremock_mapper.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86a2777faadebed7a325fa8e2511073cffa866f6
|
4
|
+
data.tar.gz: 5591b069dac9203f4389ae0aeaaf351b734c6bad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0233ebdf76153f89d662d7582ed2987210e7b0c08a81defeca637b6ec458ee352bef37cd7dbde02ff8b350d537988eae935bcdc6f765cf9be30b64aee7e5311c
|
7
|
+
data.tar.gz: 15494092a60bd952b260a44f3d81b28783557cde98673abe49efd2e439f9ecdaf2b66629b6f41ede32e858b70243221bf658f14a18265e7a187e7603bed33776
|
data/lib/configuration.rb
CHANGED
@@ -18,6 +18,12 @@ module WireMockMapper
|
|
18
18
|
yield @request_builder, @response_builder, @scenario_builder
|
19
19
|
end
|
20
20
|
|
21
|
+
def reset_global_mappings
|
22
|
+
@request_builder = Builders::RequestBuilder.new
|
23
|
+
@response_builder = Builders::ResponseBuilder.new
|
24
|
+
@scenario_builder = Builders::ScenarioBuilder.new
|
25
|
+
end
|
26
|
+
|
21
27
|
# Set the WireMock url
|
22
28
|
# @param url [String] the url of the WireMock server
|
23
29
|
def set_wiremock_url(url)
|
data/lib/wiremock_mapper.rb
CHANGED
@@ -3,7 +3,11 @@ require_relative 'configuration'
|
|
3
3
|
|
4
4
|
module WireMockMapper
|
5
5
|
class << self
|
6
|
-
def create_mapping(url = Configuration.wiremock_url)
|
6
|
+
def create_mapping(url = Configuration.wiremock_url, &block)
|
7
|
+
create_mapping_with_priority(nil, url, &block)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_mapping_with_priority(priority = nil, url = Configuration.wiremock_url)
|
7
11
|
request_builder = deep_clone(Configuration.request_builder)
|
8
12
|
response_builder = deep_clone(Configuration.response_builder)
|
9
13
|
scenario_builder = deep_clone(Configuration.scenario_builder)
|
@@ -11,6 +15,8 @@ module WireMockMapper
|
|
11
15
|
yield request_builder, response_builder, scenario_builder
|
12
16
|
|
13
17
|
body = { request: request_builder, response: response_builder }.merge(scenario_builder)
|
18
|
+
body[:priority] = priority if priority
|
19
|
+
|
14
20
|
response = send_to_wiremock(url, body)
|
15
21
|
|
16
22
|
JSON.parse(response.body).fetch('id')
|
@@ -1,6 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe WireMockMapper do
|
4
|
+
before(:each) do
|
5
|
+
WireMockMapper::Configuration.reset_global_mappings
|
6
|
+
end
|
7
|
+
|
4
8
|
describe 'create_mapping' do
|
5
9
|
it 'posts the correct json to the wiremock url' do
|
6
10
|
url = 'http://nowhere.com'
|
@@ -58,6 +62,64 @@ describe WireMockMapper do
|
|
58
62
|
end
|
59
63
|
end
|
60
64
|
|
65
|
+
describe 'create_mapping_with_priority' do
|
66
|
+
it 'posts the correct json to the wiremock url' do
|
67
|
+
url = 'http://nowhere.com'
|
68
|
+
expected_request_body = { request: { 'method' => 'POST',
|
69
|
+
'urlPath' => '/some/path',
|
70
|
+
'headers' => { 'some_header' => { 'equalTo' => 'some header value' } },
|
71
|
+
'bodyPatterns' => [
|
72
|
+
{ 'matches' => 'some request body' }
|
73
|
+
] },
|
74
|
+
response: { 'body' => 'some response body' },
|
75
|
+
priority: 2 }
|
76
|
+
|
77
|
+
stub = stub_request(:post, "#{url}/__admin/mappings").with(body: expected_request_body)
|
78
|
+
.to_return(body: { id: 'whatevs' }.to_json)
|
79
|
+
|
80
|
+
WireMockMapper.create_mapping_with_priority(2, url) do |request, respond|
|
81
|
+
request.is_a_post
|
82
|
+
.with_url_path.equal_to('/some/path')
|
83
|
+
.with_header('some_header').equal_to('some header value')
|
84
|
+
.with_body.matching('some request body')
|
85
|
+
|
86
|
+
respond.with_body('some response body')
|
87
|
+
end
|
88
|
+
|
89
|
+
expect(stub).to have_been_requested
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'posts the correct json with configured global mappings to the wiremock url' do
|
93
|
+
url = 'http://nowhere.com'
|
94
|
+
expected_request_body = { request: { 'method' => 'POST',
|
95
|
+
'url' => '/some/url',
|
96
|
+
'headers' => { 'some_global_header' => { 'equalTo' => 'global value' },
|
97
|
+
'some_header' => { 'equalTo' => 'some header value' } },
|
98
|
+
'bodyPatterns' => [
|
99
|
+
{ 'matches' => 'some request body' }
|
100
|
+
] },
|
101
|
+
response: { 'body' => 'some response body' },
|
102
|
+
priority: 1 }
|
103
|
+
|
104
|
+
stub = stub_request(:post, "#{url}/__admin/mappings").with(body: expected_request_body)
|
105
|
+
.to_return(body: { id: 'whatevs' }.to_json)
|
106
|
+
|
107
|
+
WireMockMapper::Configuration.create_global_mapping do |request|
|
108
|
+
request.with_header('some_global_header').equal_to('global value')
|
109
|
+
end
|
110
|
+
|
111
|
+
WireMockMapper.create_mapping_with_priority(1, url) do |request, respond|
|
112
|
+
request.is_a_post
|
113
|
+
.with_url.equal_to('/some/url')
|
114
|
+
.with_header('some_header').equal_to('some header value')
|
115
|
+
.with_body.matching('some request body')
|
116
|
+
respond.with_body('some response body')
|
117
|
+
end
|
118
|
+
|
119
|
+
expect(stub).to have_been_requested
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
61
123
|
describe 'delete_mapping' do
|
62
124
|
it 'issues a DELETE for the supplied mapping id' do
|
63
125
|
mapping_id = 'james-james-james'
|
data/wiremock_mapper.gemspec
CHANGED
@@ -2,7 +2,7 @@ $LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = 'wiremock_mapper'
|
5
|
-
spec.version = '2.
|
5
|
+
spec.version = '2.1.0'
|
6
6
|
spec.platform = Gem::Platform::RUBY
|
7
7
|
spec.required_ruby_version = '>= 2.0.0'
|
8
8
|
spec.authors = ['Isaac Datlof']
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wiremock_mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Isaac Datlof
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: codeclimate-test-reporter
|