Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: wiremock 3.9.1 #321

Merged
merged 212 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
212 commits
Select commit Hold shift + click to select a range
863a7dc
Allow subclasses to get the ExtensionContext
tsmock Oct 12, 2022
121e693
Bump io.github.gradle-nexus.publish-plugin from 1.3.0 to 2.0.0
dependabot[bot] Apr 18, 2024
94e0d99
Added supported-proxy-encodings as a CLI parameter
tomakehurst Apr 25, 2024
ba9d517
Merge pull request #2694 from wiremock/proxy-encodings-cli-parameter
tomakehurst Apr 25, 2024
84bda52
Bump versions.xmlUnit from 2.9.1 to 2.10.0
dependabot[bot] Apr 29, 2024
ab7c0db
Bump org.scala-lang:scala-library from 2.13.13 to 2.13.14
dependabot[bot] Apr 30, 2024
3224efc
Bump com.google.guava:guava from 33.1.0-jre to 33.2.0-jre
dependabot[bot] May 3, 2024
dac943e
Merge pull request #2704 from wiremock/dependabot/gradle/com.google.g…
leeturner May 3, 2024
7c51db8
Merge pull request #2700 from wiremock/dependabot/gradle/org.scala-la…
leeturner May 3, 2024
d8d9c81
Merge pull request #2698 from wiremock/dependabot/gradle/versions.xml…
leeturner May 3, 2024
237d711
fix: handlebars math helper handles large negative integers
RafeArnold May 4, 2024
39fb8c7
use a regexp to check for multipart requests
mufasa1976 May 4, 2024
e29ec8d
fix: fix parsing of date/time query parameter values with an offset a…
papiomytoglou May 2, 2024
f00f78c
Bump com.fasterxml.jackson:jackson-bom from 2.17.0 to 2.17.1
dependabot[bot] May 6, 2024
bc39fcb
Merge pull request #2708 from wiremock/dependabot/gradle/com.fasterxm…
leeturner May 7, 2024
5a51ac9
Merge pull request #2687 from wiremock/dependabot/gradle/io.github.gr…
dieppa May 7, 2024
e8c78fa
Merge pull request #2706 from wiremock/fix-handlebars-math-helper
dieppa May 7, 2024
327b1c8
Bump org.mockito:mockito-core from 5.11.0 to 5.12.0
dependabot[bot] May 13, 2024
7bdcda8
Fixes #2696 - xPath helper returns error message instead of result wh…
tomakehurst Apr 29, 2024
de5620d
try to fix the formatting rules.
mufasa1976 May 14, 2024
d12808a
Merge pull request #1981 from tsmock/patch-1
dieppa May 15, 2024
83ae2df
Merge pull request #2703 from papiomytoglou/fix_offsets_ahead_of_UTC
dieppa May 15, 2024
7a6d721
ignore spaces in front of multicast/
mufasa1976 May 15, 2024
da455b6
test multipart/ with and without leading spaces
mufasa1976 May 15, 2024
4162c1c
Added an overload of andMatching to stub builders taking a defintion …
tomakehurst May 16, 2024
e9653d9
Merge pull request #2721 from wiremock/custom-matcher-sugar
tomakehurst May 16, 2024
885d014
Moved the serve event triggered prior to responding before transforme…
tomakehurst May 16, 2024
3be4a18
Added an object store to the Stores interface plus a default in-memor…
tomakehurst May 16, 2024
a7248f7
Added arrayAdd, arrayRemove and val helpers (#2724)
tomakehurst May 16, 2024
1355bc8
Bumped minor version
tomakehurst May 16, 2024
1681dbf
Add start and stop extension lifecycle methods
leeturner May 16, 2024
3e36d66
Merge pull request #2715 from wiremock/dependabot/gradle/org.mockito-…
leeturner May 16, 2024
aaaa766
Bump org.mockito:mockito-junit-jupiter from 5.11.0 to 5.12.0
dependabot[bot] May 16, 2024
605fe5a
Merge pull request #2716 from wiremock/dependabot/gradle/org.mockito-…
leeturner May 16, 2024
8127220
splitted multipartRequest Test into two Tests
mufasa1976 May 16, 2024
2b4e69c
executed ./gradlew spotlessJavaCheck and afterwards ./gradlew :spotle…
mufasa1976 May 16, 2024
60d6415
Add new CustomMatching tests
leeturner May 17, 2024
f33293e
Add new in memory and file store tests
leeturner May 17, 2024
5471681
Merge pull request #2707 from mufasa1976/master
dieppa May 17, 2024
30a125c
added basic behaviour
dieppa May 17, 2024
05916de
minor change
dieppa May 17, 2024
1eebdb1
Formatting from Spotless
leeturner May 17, 2024
f4392b4
minor change
dieppa May 17, 2024
d19fe06
Rename the test and extend from AcceptanceTestBase
leeturner May 17, 2024
d00f564
Update test name
leeturner May 17, 2024
c775dae
test for no separator
dieppa May 17, 2024
ff9edf3
providing actual arrays
dieppa May 17, 2024
8f2f1d4
covering error cases, plus tests
dieppa May 17, 2024
77385a3
minor changes'
dieppa May 17, 2024
b812e8d
minor changes'
dieppa May 17, 2024
97c526e
minor changes'
dieppa May 17, 2024
25122a1
minor changes'
dieppa May 17, 2024
fa44530
formatting'
dieppa May 17, 2024
a127ecc
Merge pull request #2726 from wiremock/2711-start-stop-hooks-for-exte…
leeturner May 17, 2024
3daa2d6
more tests
dieppa May 17, 2024
01396e3
minor change
dieppa May 17, 2024
3f02154
Merge pull request #2725 from wiremock/join_handlerbars_helper
dieppa May 17, 2024
c9ff422
Spotless apply formatting
leeturner May 20, 2024
31dc5d5
Add new tests for arrayAdd and arrayRemove helpers.
leeturner May 20, 2024
a378ee6
Merge pull request #2717 from wiremock/xpath-helper-single-item-bug
dieppa May 20, 2024
c40fe83
Merge remote-tracking branch 'origin/master' into additional-tests
leeturner May 20, 2024
92b6f16
Add new tests for the val helper
leeturner May 20, 2024
87de44f
Add two new tests for the val helper
leeturner May 20, 2024
03750cf
More conditions added to the val helper tests
leeturner May 20, 2024
00150d4
renamed to 'arrayJoin'plus added support for {{join ',' 'One' 'Two' '…
dieppa May 20, 2024
1dfb67f
added prefix and suffix
dieppa May 20, 2024
29e3ada
added more tests
dieppa May 21, 2024
a76d425
formatting
dieppa May 21, 2024
1d3f0e6
Merge pull request #2729 from wiremock/join_handlerbars_helper_upgrade
dieppa May 21, 2024
db9dc91
Merge pull request #2727 from wiremock/additional-tests
leeturner May 21, 2024
41b37d7
Fix test now that the new join helper has changed its name
leeturner May 21, 2024
e5a4a72
Merge pull request #2732 from wiremock/fix-test
leeturner May 21, 2024
42a5303
Update the gradle task used in the publish
leeturner May 22, 2024
7afb8bb
Added .snyk file, ignoring test paths
tomakehurst May 23, 2024
1ff1a72
Disabled DNS filtering when no custom proxy rules are set
egerix May 23, 2024
db256b2
fix: fix matching of multiple expected zoned date/time values with mu…
papiomytoglou Mar 27, 2024
8e6a5a0
Prevent creating multiple stub mappings with the same ID
RafeArnold May 29, 2024
c91b71f
Merge pull request #2742 from wiremock/duplicate-stub-mapping-ids
RafeArnold May 30, 2024
d7d81cb
feat: add admin api route to get file contents from file store
May 30, 2024
9b9591d
feat: add admin api route to get file contents from file store
May 30, 2024
c917261
Bump com.google.guava:guava from 33.2.0-jre to 33.2.1-jre
dependabot[bot] Jun 3, 2024
cb9cf6b
Attempt at fixing Snyk exclude globs
tomakehurst Jun 4, 2024
316cb34
ignore order of xml nodes on same level when matching request body
viktormelnychuk Jun 5, 2024
54dc559
add parameter to additionally search by node text content
viktormelnychuk Jun 6, 2024
3a918b4
Default the max template cache entries to 1000 instead of infinite
leeturner Jun 11, 2024
615b87a
Make sure we set the default for programmatic startup
leeturner Jun 11, 2024
a8b1bfa
fix: stop showing path parameter non match message incorrectly.
RafeArnold Jun 12, 2024
c05bf82
Merge pull request #2753 from wiremock/path-parameter-diff
RafeArnold Jun 12, 2024
d89fe70
Merge pull request #2745 from wiremock/dependabot/gradle/com.google.g…
leeturner Jun 13, 2024
6b0b5cc
Merge pull request #2743 from pedro37/admin-api-get-file-content
leeturner Jun 13, 2024
9330dc9
Add the serveEvent id as the request.id in the template model
leeturner Jun 17, 2024
5166cd8
Makes sure the request.id is added to the originalRequest
leeturner Jun 17, 2024
236be00
Fixed #2739 - prevent automatic creation of __files dir on startup an…
tomakehurst Jun 18, 2024
12e8a1b
Merge pull request #2760 from wiremock/stop-eager-file-source-dir-cre…
tomakehurst Jun 18, 2024
f86eeec
Merge pull request #2752 from wiremock/set-default-for-max-template-c…
leeturner Jun 18, 2024
0b5f9f6
Add preserveUserAgentProxyHeader to keep User-Agent header when in pr…
raycoarana Jun 18, 2024
75b0b68
spotless apply
viktormelnychuk Jun 18, 2024
9c673db
Use the template engine to populate the model
leeturner Jun 18, 2024
9e8132d
isAllowedAll: change empty rules check
egerix Jun 18, 2024
5610f61
Fix HttpClientBuilder сode and add options for Connection Management …
MuTalKing Jun 19, 2024
8de26ab
Minor rename of new proxy HTTP config parameters
tomakehurst Jun 19, 2024
f15279a
get{Level}Messages return a snapshot
Mahoney Jun 19, 2024
2b0be7e
Fix race condition in getObjectStore
Mahoney Jun 19, 2024
a8cf156
Allow configuring max items of an ObjectStore
Mahoney Jun 19, 2024
b5ba923
Merge pull request #2757 from wiremock/add-the-request-id-to-the-temp…
leeturner Jun 19, 2024
75d714e
Request is now decorated where possible with PathTemplate so that Pat…
tomakehurst Jun 19, 2024
ca68261
Consolidated logic to build request model into TemplateEngine so that…
tomakehurst Jun 19, 2024
23138f7
Revert "Minor rename of new proxy HTTP config parameters"
tomakehurst Jun 19, 2024
65cae1e
Merge branch 'master' into path-params-in-request
tomakehurst Jun 19, 2024
ae14ee5
Add sub events to the webhook success and failure scenarios
leeturner Jun 19, 2024
20c56bb
PathParams are now added to LoggedRequest after matching so that they…
tomakehurst Jun 19, 2024
8e8c6d3
fix test in ResponseDefinitionTransformerV2AcceptanceTest.
RafeArnold Jun 19, 2024
07af5a4
remove unnecessary request decoration from TemplateEngine.
RafeArnold Jun 19, 2024
b841d4e
clean up path parameters in RequestPathParamsDecorator.
RafeArnold Jun 19, 2024
77ccc26
Publish snapshots on merge to master
Mahoney Jun 19, 2024
14a5455
Fix workflow name & job names
Mahoney Jun 19, 2024
3caa952
Now log the whole LoggedRequest and LoggedResponse as the subEvent
leeturner Jun 19, 2024
c0da1cd
Try and publish to sonatype staging
Mahoney Jun 19, 2024
9bf0d43
Allow sub event error messages to validate if a value contains a string
leeturner Jun 19, 2024
e450d5e
NetworkAddressRules: add ALL_RANGES constant
egerix Jun 19, 2024
70b1641
Use a fake http client factory in the test to better control errors.
leeturner Jun 19, 2024
98c5ff9
Bump com.dorongold.task-tree from 3.0.0 to 4.0.0
dependabot[bot] Jun 20, 2024
b7617a7
Merge pull request #2747 from viktormelnychuk/ignore-order-of-same-no…
leeturner Jun 20, 2024
4f71d69
Revert "Minor rename of new proxy HTTP config parameters"
tomakehurst Jun 19, 2024
8cca525
Revert "Try and publish to sonatype staging"
Mahoney Jun 20, 2024
77b05a3
Fix scala warnings
Mahoney Jun 20, 2024
f566870
add id to request model.
RafeArnold Jun 20, 2024
0a08aba
Merged request ID change
tomakehurst Jun 20, 2024
c10690b
Merge pull request #2769 from wiremock/path-params-in-request
tomakehurst Jun 20, 2024
5eebd31
Merge pull request #2737 from egerix/issue-2736-remove-dns-filtering-…
tomakehurst Jun 20, 2024
f5f19c3
WIP DiffDescriptionLine implementation
leeturner Jun 20, 2024
777d9b8
Name the sub events to something webhook specific for non error events
leeturner Jun 20, 2024
8d1f98b
Merge remote-tracking branch 'origin/master' into 2759-Report-webhook…
leeturner Jun 20, 2024
b5bb2e0
Rename the WireMock extension to make it more specific
leeturner Jun 20, 2024
66c7102
Give the successful webhook response sub event its own name
leeturner Jun 20, 2024
ab89046
Merge pull request #2766 from wiremock/2759-Report-webhook-errors-and…
leeturner Jun 20, 2024
dde96b4
Add self-description callbacks for MatchResult in Diff
leeturner Jun 21, 2024
3c754cf
Stop ejecting existing key on read of missing key
Mahoney Jun 21, 2024
2bc2267
The MemoizingMatchResult should just delegate to the wrapped result
leeturner Jun 21, 2024
695c054
Returning null for now as aggregate results are not used in diff reports
leeturner Jun 21, 2024
d81a620
Internal class so doesn't need to be Beta
leeturner Jun 21, 2024
0b2a720
Merge remote-tracking branch 'origin/master' into 2758-self-descripti…
leeturner Jun 21, 2024
2755c2f
Bump minor version
leeturner Jun 21, 2024
6fb5b92
The DiffDescriptionLine is now a class to just show Diff Descriptions
leeturner Jun 25, 2024
cec95bf
Each MatchResult can now hold a list of Diff Descriptions
leeturner Jun 25, 2024
ae4ecfe
When no DiffDescriptions return a single description with the existing
leeturner Jun 25, 2024
9052d80
Now use the DiffDescriptionLine for custom matchers
leeturner Jun 25, 2024
8296367
Now use the DiffDescriptionLine for all items in the diff
leeturner Jun 26, 2024
ba365be
Merge remote-tracking branch 'origin/master' into 2758-self-descripti…
leeturner Jun 26, 2024
652887b
Merge pull request #2650 from papiomytoglou/master
RafeArnold Jun 27, 2024
7a0f8c3
WIP - add multipart request parts to template model when present. 2 t…
tomakehurst Jun 27, 2024
82b2aba
Merge remote-tracking branch 'origin/master' into 2758-self-descripti…
leeturner Jun 27, 2024
e05dfe0
Small update to test data in test
leeturner Jun 27, 2024
6e16a36
Merge pull request #2771 from wiremock/2758-self-description-matchresult
leeturner Jun 28, 2024
c935e63
Add the base64 body representation to the RequestTemplateModel
leeturner Jun 28, 2024
91eda2f
Allow the part headers to be case-insensitive in the model
leeturner Jun 28, 2024
47d31d9
com.networknt:json-schema-validator:1.4.0 -> 1.4.3
Mahoney Jun 28, 2024
8638758
Merge pull request #2781 from wiremock/upgrade-json-schema-validator
Mahoney Jun 28, 2024
0a285a0
Bump versions.junitJupiter from 5.10.2 to 5.10.3
dependabot[bot] Jun 28, 2024
c80195a
Merge pull request #2780 from wiremock/dependabot/gradle/versions.jun…
leeturner Jun 28, 2024
e5613a8
Merge pull request #2782 from wiremock/multipart-request-template-model
leeturner Jun 28, 2024
aaf53bf
Add a toString to the ResponsePartTemplateModel class
leeturner Jun 28, 2024
5961183
Merge pull request #2785 from wiremock/tostring-on-response-part-tran…
leeturner Jun 28, 2024
d3747a2
Bump minor version
leeturner Jun 28, 2024
8e39303
Merge pull request #2767 from wiremock/dependabot/gradle/com.dorongol…
leeturner Jul 1, 2024
3d7b984
Bump versions.jsonUnit from 2.38.0 to 2.39.0
dependabot[bot] Jul 2, 2024
bb0844c
Merge pull request #2787 from wiremock/dependabot/gradle/versions.jso…
leeturner Jul 2, 2024
247640e
Update the urls to https
leeturner Jul 3, 2024
d0561f7
Add health and version admin endpoints
leeturner Jul 3, 2024
7c60314
Add an enum for the status field
leeturner Jul 3, 2024
700e7cc
Add the __admin/files admin endpoints
leeturner Jul 3, 2024
a3333ad
Update the urls and tags in the json version of the spec
leeturner Jul 3, 2024
39cf91f
Add the version and the health endpoints to json specification
leeturner Jul 3, 2024
08ed9f9
Add the file endpoints and reformat
leeturner Jul 3, 2024
a364fc6
Add top level description element
leeturner Jul 3, 2024
5c4d12a
Bump versions.jsonUnit from 2.39.0 to 2.40.0
dependabot[bot] Jul 4, 2024
3122f9a
Merge pull request #2793 from wiremock/dependabot/gradle/versions.jso…
leeturner Jul 4, 2024
2960173
Merge pull request #2791 from wiremock/add-missing-admin-endpoints-to…
leeturner Jul 4, 2024
9299471
Updated and corrected JSON schemas for matcher in the OpenAPI spec
tomakehurst Jul 5, 2024
2bd65bd
Merge pull request #2797 from wiremock/update-openapi-matcher-schemas
tomakehurst Jul 5, 2024
9a08cd1
Further assorted OpenAPI improvements
tomakehurst Jul 5, 2024
1b97b87
Added a few more missing schema properties and improved detail on exi…
tomakehurst Jul 5, 2024
dcd44c8
Merge pull request #2798 from wiremock/openapi-improvements
tomakehurst Jul 5, 2024
7872f9a
Bump com.networknt:json-schema-validator from 1.4.3 to 1.5.0
dependabot[bot] Jul 8, 2024
1e930b1
Bump com.fasterxml.jackson:jackson-bom from 2.17.1 to 2.17.2
dependabot[bot] Jul 8, 2024
81071a3
Merge pull request #2799 from wiremock/dependabot/gradle/com.networkn…
Mahoney Jul 8, 2024
e031496
feat: add support for request matching with dynamic year and dynamic …
papiomytoglou May 26, 2024
ad5a4a7
Merge pull request #2800 from wiremock/dependabot/gradle/com.fasterxm…
leeturner Jul 15, 2024
f35dc70
correctly handle InMemoryObjectStore.compute returning null.
RafeArnold Jul 16, 2024
c3b9b8e
Merge pull request #2804 from wiremock/in-memory-store-compute-null
RafeArnold Jul 16, 2024
134876a
update MatchesJsonSchemaPattern to handle invalid json schemas.
RafeArnold Jul 16, 2024
b8f3756
Merge pull request #2803 from wiremock/invalid-json-schema
RafeArnold Jul 17, 2024
8364617
Merge pull request #2741 from papiomytoglou/fix_matching_with_years
RafeArnold Jul 18, 2024
27e7fa8
Made pickRandom helper return an object rather than its toString() so…
tomakehurst Jul 18, 2024
f50330b
add listener implementation to InMemoryObjectStore.
RafeArnold Jul 18, 2024
162bdaa
Added ability tp specify an optional count parameter to pickRandom so…
tomakehurst Jul 18, 2024
61c39e3
simplify pickRandom count implementation.
RafeArnold Jul 18, 2024
42605f0
rename variable in tests.
RafeArnold Jul 18, 2024
33ddce3
Revert "simplify pickRandom count implementation." as it's probably a…
tomakehurst Jul 18, 2024
0909147
attempt to increase pickRandom efficiency.
RafeArnold Jul 18, 2024
56e826b
replace StoreEventHandler with Consumer.
RafeArnold Jul 18, 2024
f2bb828
use static methods to build StoreEvents.
RafeArnold Jul 18, 2024
97e9da5
Merge pull request #2812 from wiremock/pickRandom-enhancements
tomakehurst Jul 19, 2024
d6a957f
Made StoreEventEmitter a separate interface only implemented by InMem…
tomakehurst Jul 19, 2024
848872f
Fixed some import issues
tomakehurst Jul 19, 2024
55e9c8c
Make StoreEventEmitter more lenient about handler
Mahoney Jul 19, 2024
f18eed8
Merge pull request #2811 from wiremock/store-listener
leeturner Jul 19, 2024
ac84cf8
Bump minor version
leeturner Jul 19, 2024
6d98c1f
disallow json schemas to be invalid json.
RafeArnold Jul 20, 2024
8ae6617
Merge pull request #2814 from wiremock/json-schema-invalid-json
RafeArnold Jul 24, 2024
2ba8a3e
Bump patch version
leeturner Jul 24, 2024
56fb35b
feat: WireMock 3.9.1
holomekc Jul 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/docker-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
PLATFORMS: linux/amd64,linux/arm64,linux/arm/v7
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Checkout sources
uses: actions/checkout@v4
Expand Down
18 changes: 9 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ plugins {
id "org.sonarqube" version "5.0.0.4638"
id 'jacoco'
id "me.champeau.jmh" version "0.7.2"
id 'com.dorongold.task-tree' version '3.0.0'
id 'com.dorongold.task-tree' version '4.0.0'
id 'com.github.node-gradle.node' version '7.0.2'
}

group = 'org.wiremock'

project.ext {
versions = [
handlebars : '4.3.1',
jetty : '11.0.20',
guava : '33.2.1-jre',
jackson : '2.17.1',
xmlUnit : '2.10.0',
jsonUnit : '2.38.0',
junitJupiter: '5.10.3'
handlebars : '4.3.1',
jetty : '11.0.20',
guava : '33.2.1-jre',
jackson : '2.17.2',
xmlUnit : '2.10.0',
jsonUnit : '2.40.0',
junitJupiter : '5.10.3'
]
}

Expand Down Expand Up @@ -108,7 +108,7 @@ dependencies {

api 'commons-fileupload:commons-fileupload:1.5'

api 'com.networknt:json-schema-validator:1.4.3'
api 'com.networknt:json-schema-validator:1.5.0'

testFixturesApi("org.junit.jupiter:junit-jupiter:$versions.junitJupiter")
testFixturesApi("org.junit.platform:junit-platform-testkit")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static com.github.tomakehurst.wiremock.common.Strings.isNotBlank;
import static com.github.tomakehurst.wiremock.security.NoClientAuthenticator.noClientAuthenticator;
import static java.util.Objects.requireNonNull;
import static org.apache.hc.core5.http.HttpHeaders.CONTENT_TYPE;
import static org.apache.hc.core5.http.HttpHeaders.HOST;

import com.github.tomakehurst.wiremock.admin.*;
Expand Down Expand Up @@ -462,12 +463,14 @@ private ProxySettings createProxySettings(String proxyHost, int proxyPort) {

private String postJsonAssertOkAndReturnBody(String url, String json) {
HttpPost post = new HttpPost(url);
post.addHeader(CONTENT_TYPE, "application/json");
post.setEntity(jsonStringEntity(Optional.ofNullable(json).orElse("")));
return safelyExecuteRequest(url, post);
}

private String putJsonAssertOkAndReturnBody(String url, String json) {
HttpPut put = new HttpPut(url);
put.addHeader(CONTENT_TYPE, "application/json");
put.setEntity(jsonStringEntity(Optional.ofNullable(json).orElse("")));
return safelyExecuteRequest(url, put);
}
Expand Down Expand Up @@ -518,6 +521,7 @@ private <B, R> R executeRequest(
if (requestSpec.method().hasEntity()) {
requestBuilder.setEntity(
jsonStringEntity(Optional.ofNullable(requestBody).map(Json::write).orElse("")));
requestBuilder.addHeader(CONTENT_TYPE, "application/json");
}

String responseBodyString = safelyExecuteRequest(url, requestBuilder.build());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Thomas Akehurst
* Copyright (C) 2021-2024 Thomas Akehurst
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -116,6 +116,22 @@ public LocalDate parseLocalDate(String dateTimeString) {
return null;
}

public YearMonth parseYearMonth(String dateTimeString) {
if (dateTimeFormatter != null) {
return YearMonth.parse(dateTimeString, dateTimeFormatter);
}

return null;
}

public Year parseYear(String dateTimeString) {
if (dateTimeFormatter != null) {
return Year.parse(dateTimeString, dateTimeFormatter);
}

return null;
}

public RenderableDate parseDate(String dateTimeString) {
if (isUnix || isEpoch) {
return new RenderableDate(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2023 Thomas Akehurst
* Copyright (C) 2020-2024 Thomas Akehurst
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,9 +17,7 @@

import com.github.jknack.handlebars.Options;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;

public class PickRandomHelper extends HandlebarsHelper<Object> {
Expand All @@ -40,7 +38,16 @@ public Object apply(Object context, Options options) throws IOException {
valueList.addAll(Arrays.asList(options.params));
}

Integer count = (Integer) options.hash.get("count");
if (count != null && count > 0) {
int desiredLength = Math.min(valueList.size(), count);
for (int i = 0; i < desiredLength; i++) {
Collections.swap(valueList, i, ThreadLocalRandom.current().nextInt(i, valueList.size()));
}
return valueList.subList(0, desiredLength);
}

int index = ThreadLocalRandom.current().nextInt(valueList.size());
return valueList.get(index).toString();
return valueList.get(index);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2022 Thomas Akehurst
* Copyright (C) 2021-2024 Thomas Akehurst
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,9 +22,7 @@
import com.github.tomakehurst.wiremock.common.DateTimeParser;
import com.github.tomakehurst.wiremock.common.DateTimeTruncation;
import com.github.tomakehurst.wiremock.common.DateTimeUnit;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.time.*;
import java.time.format.DateTimeParseException;
import java.util.List;

Expand Down Expand Up @@ -271,7 +269,21 @@ private static LocalDateTime parseLocalOrNull(String dateTimeString, DateTimePar
: LocalDate.parse(dateTimeString))
.atStartOfDay();
} catch (DateTimeParseException ignored2) {
return null;
try {
return (parser != null
? parser.parseYearMonth(dateTimeString)
: YearMonth.parse(dateTimeString))
.atDay(1)
.atStartOfDay();
} catch (DateTimeParseException ignored3) {
try {
return (parser != null ? parser.parseYear(dateTimeString) : Year.parse(dateTimeString))
.atDay(1)
.atStartOfDay();
} catch (DateTimeParseException ignored4) {
return null;
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.TextNode;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.common.ClientError;
import com.github.tomakehurst.wiremock.common.Errors;
import com.github.tomakehurst.wiremock.common.Json;
import com.github.tomakehurst.wiremock.common.JsonException;
import com.github.tomakehurst.wiremock.stubbing.SubEvent;
import com.networknt.schema.JsonSchema;
import com.networknt.schema.JsonSchemaFactory;
import com.networknt.schema.SchemaValidatorsConfig;
Expand All @@ -32,6 +35,7 @@ public class MatchesJsonSchemaPattern extends StringValuePattern {
private final JsonSchema schema;
private final WireMock.JsonSchemaVersion schemaVersion;
private final int schemaPropertyCount;
private final Errors invalidSchemaErrors;

public MatchesJsonSchemaPattern(String schemaJson) {
this(schemaJson, WireMock.JsonSchemaVersion.V202012);
Expand All @@ -48,10 +52,24 @@ public MatchesJsonSchemaPattern(

final JsonSchemaFactory schemaFactory =
JsonSchemaFactory.getInstance(schemaVersion.toVersionFlag());
schema = schemaFactory.getSchema(schemaJson, config);
JsonSchema schema;
JsonNode schemaAsJson = Json.read(schemaJson, JsonNode.class);
int schemaPropertyCount;
Errors invalidSchemaErrors;
try {
schema = schemaFactory.getSchema(schemaAsJson, config);
schemaPropertyCount = Json.schemaPropertyCount(schemaAsJson);
invalidSchemaErrors = null;
} catch (Exception e) {
schema = null;
schemaPropertyCount = 0;
invalidSchemaErrors = getInvalidSchemaErrors(e);
}
this.schema = schema;
this.schemaVersion = schemaVersion;

schemaPropertyCount = Json.schemaPropertyCount(Json.read(schemaJson, JsonNode.class));
this.schemaPropertyCount = schemaPropertyCount;
this.invalidSchemaErrors = invalidSchemaErrors;
}

public MatchesJsonSchemaPattern(
Expand All @@ -74,6 +92,9 @@ public String getExpected() {

@Override
public MatchResult match(String json) {
if (schema == null) {
return MatchResult.noMatch(new SubEvent(SubEvent.ERROR, invalidSchemaErrors));
}
if (json == null) {
return MatchResult.noMatch();
}
Expand All @@ -85,7 +106,13 @@ public MatchResult match(String json) {
jsonNode = new TextNode(json);
}

final Set<ValidationMessage> validationMessages = validate(jsonNode, json);
final Set<ValidationMessage> validationMessages;
try {
validationMessages = validate(jsonNode, json);
} catch (Exception e) {
return MatchResult.noMatch(new SubEvent(SubEvent.ERROR, getInvalidSchemaErrors(e)));
}

if (validationMessages.isEmpty()) {
return MatchResult.exactMatch();
}
Expand All @@ -107,6 +134,30 @@ public double getDistance() {
};
}

private static Errors getInvalidSchemaErrors(Exception e) {
Errors invalidSchemaErrors;
if (e instanceof ClientError) {
Errors.Error error = ((ClientError) e).getErrors().first();
invalidSchemaErrors =
Errors.single(
error.getCode(),
error.getSource().getPointer(),
"Invalid JSON Schema",
error.getDetail());
} else {
invalidSchemaErrors =
Errors.singleWithDetail(10, "Invalid JSON Schema", getRootCause(e).getMessage());
}
return invalidSchemaErrors;
}

private static Throwable getRootCause(Throwable e) {
if (e.getCause() != null) {
return getRootCause(e.getCause());
}
return e;
}

private Set<ValidationMessage> validate(JsonNode jsonNode, String originalJson) {
final Set<ValidationMessage> validationMessages = schema.validate(jsonNode);
if (validationMessages.isEmpty() || jsonNode.isTextual() || jsonNode.isContainerNode()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,25 @@
*/
package com.github.tomakehurst.wiremock.store;

import static com.github.tomakehurst.wiremock.common.LocalNotifier.notifier;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Stream;

public class InMemoryObjectStore implements ObjectStore {
public class InMemoryObjectStore implements ObjectStore, StoreEventEmitter<String, Object> {

private final ConcurrentHashMap<String, Object> cache;
private final Queue<String> keyUseOrder = new ConcurrentLinkedQueue<>();
private final int maxItems;
private final List<Consumer<? super StoreEvent<String, Object>>> listeners = new ArrayList<>();

public InMemoryObjectStore(int maxItems) {
this.cache = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -54,23 +61,39 @@ public Stream<String> getAllKeys() {

@Override
public void put(String key, Object content) {
cache.put(key, content);
Object previousValue = cache.put(key, content);
touchAndResize(key);
handleEvent(StoreEvent.set(key, previousValue, content));
}

@Override
@SuppressWarnings("unchecked")
public <T> T compute(String key, Function<T, T> valueFunction) {
final AtomicReference<T> previousValue = new AtomicReference<>();
final T result =
(T) cache.compute(key, (k, currentValue) -> valueFunction.apply((T) currentValue));
touchAndResize(key);
(T)
cache.compute(
key,
(k, currentValue) -> {
previousValue.set((T) currentValue);
return valueFunction.apply((T) currentValue);
});
if (result != null) {
touchAndResize(key);
} else {
keyUseOrder.remove(key);
}
handleEvent(StoreEvent.set(key, previousValue.get(), result));
return result;
}

@Override
public void remove(String key) {
cache.remove(key);
Object previousValue = cache.remove(key);
keyUseOrder.remove(key);
if (previousValue != null) {
handleEvent(StoreEvent.remove(key, previousValue));
}
}

@Override
Expand All @@ -79,6 +102,21 @@ public void clear() {
keyUseOrder.clear();
}

@Override
public void registerEventListener(Consumer<? super StoreEvent<String, Object>> handler) {
listeners.add(handler);
}

private void handleEvent(StoreEvent<String, Object> event) {
for (Consumer<? super StoreEvent<String, Object>> listener : listeners) {
try {
listener.accept(event);
} catch (Exception e) {
notifier().error("Error handling store event", e);
}
}
}

private void touchAndResize(String key) {
touch(key);
resize();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Thomas Akehurst
* Copyright (C) 2022-2024 Thomas Akehurst
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Loading