Skip to content

Commit

Permalink
feat: WireMock 3.8.0
Browse files Browse the repository at this point in the history
- Update to WireMock 3.8.0
- Update dependencies, which were stuck due to breaking changes
- Fix issues in code editor and entry to improve performance
- Drop old vkbeautify library. Instead, use JSON and xml-formatter
- Update eslint config and setup, which was a pain
  • Loading branch information
holomekc committed Jul 3, 2024
1 parent 8e6a681 commit 65704b5
Show file tree
Hide file tree
Showing 164 changed files with 8,312 additions and 5,165 deletions.
4 changes: 2 additions & 2 deletions .run/Build WireMock.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<ForceTestExec>false</ForceTestExec>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
</component>
</component>
4 changes: 2 additions & 2 deletions .run/WebApp lint --fix.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<scripts>
<script value="lint:fix" />
</scripts>
<node-interpreter value="$PROJECT_DIR$/.gradle/nodejs/node-v20.10.0-darwin-arm64/bin/node" />
<node-interpreter value="$PROJECT_DIR$/.gradle/nodejs/node-v20.15.0-darwin-arm64/bin/node" />
<package-manager value="$PROJECT_DIR$/.gradle/npm/npm-v10.2.5/lib/node_modules/npm/bin/npm-cli.js" />
<envs />
<method v="2" />
</configuration>
</component>
</component>
4 changes: 2 additions & 2 deletions .run/WebApp lint.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<scripts>
<script value="lint" />
</scripts>
<node-interpreter value="$PROJECT_DIR$/.gradle/nodejs/node-v20.10.0-darwin-arm64/bin/node" />
<node-interpreter value="$PROJECT_DIR$/.gradle/nodejs/node-v20.15.0-darwin-arm64/bin/node" />
<package-manager value="$PROJECT_DIR$/.gradle/npm/npm-v10.2.5/lib/node_modules/npm/bin/npm-cli.js" />
<envs />
<method v="2" />
</configuration>
</component>
</component>
2 changes: 1 addition & 1 deletion .run/WebApp start.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<scripts>
<script value="start" />
</scripts>
<node-interpreter value="$PROJECT_DIR$/.gradle/nodejs/node-v20.10.0-darwin-arm64/bin/node" />
<node-interpreter value="$PROJECT_DIR$/.gradle/nodejs/node-v20.15.0-darwin-arm64/bin/node" />
<package-manager value="$PROJECT_DIR$/.gradle/npm/npm-v10.2.5/lib/node_modules/npm/bin/npm-cli.js" />
<envs />
<method v="2" />
Expand Down
22 changes: 22 additions & 0 deletions .snyk
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
version: v1.25.0
ignore: {}
patch: {}
exclude:
global:
- ./sample-war/**/*:
reason: test only sub-project
expires: 2044-05-23T00:00:00.000Z
created: 2024-05-23T13:24:10.953Z
- ./perf-test/**/*:
reason: test only sub-project
expires: 2044-05-23T00:00:00.000Z
created: 2024-05-23T13:24:46.178Z
- ./test-logging/**/*:
reason: test only sub-project
expires: 2044-05-23T00:00:00.000Z
created: 2024-05-23T13:25:17.519Z
- ./test-extension/**/*:
reason: test only sub-project
expires: 2044-05-23T00:00:00.000Z
created: 2024-05-23T13:25:37.801Z
115 changes: 42 additions & 73 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ plugins {
id 'scala'
id 'signing'
id 'maven-publish'
id 'io.github.gradle-nexus.publish-plugin' version '1.3.0'
id 'io.github.gradle-nexus.publish-plugin' version '2.0.0'
id 'idea'
id 'eclipse'
id 'project-report'
Expand All @@ -25,6 +25,7 @@ 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.github.node-gradle.node' version '7.0.2'
}

Expand All @@ -34,11 +35,11 @@ project.ext {
versions = [
handlebars : '4.3.1',
jetty : '11.0.20',
guava : '33.1.0-jre',
jackson : '2.17.0',
xmlUnit : '2.9.1',
guava : '33.2.1-jre',
jackson : '2.17.1',
xmlUnit : '2.10.0',
jsonUnit : '2.38.0',
junitJupiter: '5.10.2'
junitJupiter: '5.10.3'
]
}

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

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

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

testFixturesApi("org.junit.jupiter:junit-jupiter:$versions.junitJupiter")
testFixturesApi("org.junit.platform:junit-platform-testkit")
Expand All @@ -116,8 +117,8 @@ dependencies {
testFixturesApi('org.junit-pioneer:junit-pioneer:2.2.0')
testFixturesApi "org.hamcrest:hamcrest-core:2.2"
testFixturesApi "org.hamcrest:hamcrest-library:2.2"
testFixturesApi 'org.mockito:mockito-core:5.11.0'
testFixturesApi 'org.mockito:mockito-junit-jupiter:5.11.0'
testFixturesApi 'org.mockito:mockito-core:5.12.0'
testFixturesApi 'org.mockito:mockito-junit-jupiter:5.12.0'
testFixturesApi "net.javacrumbs.json-unit:json-unit:$versions.jsonUnit"
testFixturesApi "org.skyscreamer:jsonassert:1.5.1"
testFixturesApi 'com.toomuchcoding.jsonassert:jsonassert:0.8.0'
Expand All @@ -126,7 +127,7 @@ dependencies {

testImplementation "junit:junit:4.13.2"
testRuntimeOnly("org.junit.vintage:junit-vintage-engine")
testImplementation 'org.scala-lang:scala-library:2.13.13'
testImplementation 'org.scala-lang:scala-library:2.13.14'
testImplementation 'com.tngtech.archunit:archunit-junit5:0.23.1'

testImplementation "org.eclipse.jetty:jetty-client"
Expand Down Expand Up @@ -440,14 +441,14 @@ task addGitTag {
}

node {
version = "20.10.0"
npmVersion = "10.2.5"
version = "20.15.0"
npmVersion = "10.7.0"
nodeProjectDir = file(projectDir.getAbsolutePath() + '/webapp/wiremock')
download = true
}

task npmInstallWebapp(type: NpmTask) {
args = ['install']
args = ['install', "--verbose"]
}

task generateWebapp(type: NpmTask) {
Expand Down Expand Up @@ -495,90 +496,58 @@ task localRelease {
dependsOn clean, assemble, publishToMavenLocal
}

task 'bump-beta-version' {
doLast {
def filesWithVersion = [
'build.gradle' : { "version = '${it}" },
'ui/package.json' : { "\"version\": \"${it}\"" },
'src/main/resources/version.properties' : { "version=${it}" },
'src/main/resources/swagger/wiremock-admin-api.json': { "\"version\": \"${it}\"" },
'src/main/resources/swagger/wiremock-admin-api.yaml': {
"version: ${it}"
}
]
void updateFiles(String currentVersion, String nextVersion) {

def currentVersion = project.version
def nextVersion = "3.0.0-beta-${betaVersion + 1}"
def filesWithVersion = [
'build.gradle' : { "version = '${it}" },
'ui/package.json' : { "\"version\": \"${it}\"" },
'src/main/resources/version.properties' : { "version=${it}" },
'src/main/resources/swagger/wiremock-admin-api.json': { "\"version\": \"${it}\"" },
'src/main/resources/swagger/wiremock-admin-api.yaml': {
"version: ${it}"
}
]

filesWithVersion.each { fileName, lineWithVersionTemplates ->
def file = file(fileName)
def lineWithVersionTemplateList = [lineWithVersionTemplates].flatten()
filesWithVersion.each { fileName, lineWithVersionTemplates ->
def file = file(fileName)
def lineWithVersionTemplateList = [lineWithVersionTemplates].flatten()

lineWithVersionTemplateList.each { lineWithVersionTemplate ->
def oldLine = lineWithVersionTemplate.call(currentVersion)
def newLine = lineWithVersionTemplate.call(nextVersion)
println "Replacing '${oldLine}' with '${newLine}' in ${fileName}"
file.text = file.text.replace(oldLine, newLine)
}
lineWithVersionTemplateList.each { lineWithVersionTemplate ->
def oldLine = lineWithVersionTemplate.call(currentVersion)
def newLine = lineWithVersionTemplate.call(nextVersion)
println "Replacing '${oldLine}' with '${newLine}' in ${fileName}"
file.text = file.text.replace(oldLine, newLine)
}
}
}

task 'bump-patch-version' {
doLast {
def filesWithVersion = [
'build.gradle' : { "version = '${it}" },
'ui/package.json' : { "\"version\": \"${it}\"" },
'src/main/resources/version.properties' : { "version=${it}" },
'src/main/resources/swagger/wiremock-admin-api.json': { "\"version\": \"${it}\"" },
'src/main/resources/swagger/wiremock-admin-api.yaml': {
"version: ${it}"
}
]

def currentVersion = project.version
def nextVersion = "${majorVersion}.${minorVersion}.${patchVersion + 1}"

filesWithVersion.each { fileName, lineWithVersionTemplates ->
def file = file(fileName)
def lineWithVersionTemplateList = [lineWithVersionTemplates].flatten()

lineWithVersionTemplateList.each { lineWithVersionTemplate ->
def oldLine = lineWithVersionTemplate.call(currentVersion)
def newLine = lineWithVersionTemplate.call(nextVersion)
println "Replacing '${oldLine}' with '${newLine}' in ${fileName}"
file.text = file.text.replace(oldLine, newLine)
}
}
updateFiles(currentVersion, nextVersion)
}
}

task 'bump-minor-version' {
doLast {
def filesWithVersion = [
'build.gradle' : { "version = '${it}" },
'ui/package.json' : { "\"version\": \"${it}\"" },
'src/main/resources/version.properties' : { "version=${it}" },
'src/main/resources/swagger/wiremock-admin-api.json': { "\"version\": \"${it}\"" },
'src/main/resources/swagger/wiremock-admin-api.yaml': {
"version: ${it}"
}
]

def currentVersion = project.version
def nextVersion = "${majorVersion}.${minorVersion + 1}.0"

filesWithVersion.each { fileName, lineWithVersionTemplates ->
def file = file(fileName)
def lineWithVersionTemplateList = [lineWithVersionTemplates].flatten()
updateFiles(currentVersion, nextVersion)
}
}

lineWithVersionTemplateList.each { lineWithVersionTemplate ->
def oldLine = lineWithVersionTemplate.call(currentVersion)
def newLine = lineWithVersionTemplate.call(nextVersion)
println "Replacing '${oldLine}' with '${newLine}' in ${fileName}"
file.text = file.text.replace(oldLine, newLine)
}
}
task 'set-snapshot-version' {
doLast {

def currentVersion = project.version
def nextVersion = "${majorVersion}.${minorVersion + 1}.0-SNAPSHOT"

updateFiles(currentVersion, nextVersion)
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ org.gradle.jvmargs=-Xmx3g
org.gradle.parallel=true
org.gradle.workers.max=4
systemProp.org.gradle.internal.http.connectionTimeout=120000
systemProp.org.gradle.internal.http.socketTimeout=120000
systemProp.org.gradle.internal.http.socketTimeout=120000
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2016-2023 Thomas Akehurst
* Copyright (C) 2016-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 @@ -73,9 +73,9 @@ private void initDefaultRoutes(Router router) {
router.add(POST, "/mappings/import", new ImportStubMappingsTask());

router.add(GET, "/files", new GetAllStubFilesTask(stores));
router.add(GET, "/files/**", GetStubFilesTask.class);
router.add(PUT, "/files/**", new EditStubFileTask(stores));
router.add(DELETE, "/files/**", new DeleteStubFileTask(stores));
router.add(GET, "/files/**", new GetStubFileTask(stores));

router.add(GET, "/scenarios", new GetAllScenariosTask());
router.add(POST, "/scenarios/reset", new ResetScenariosTask());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2011-2023 Thomas Akehurst
* Copyright (C) 2016-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 @@ -15,27 +15,31 @@
*/
package com.github.tomakehurst.wiremock.admin.tasks;

import static com.github.tomakehurst.wiremock.core.WireMockApp.FILES_ROOT;
import static java.net.HttpURLConnection.HTTP_OK;

import com.github.tomakehurst.wiremock.admin.AdminTask;
import com.github.tomakehurst.wiremock.common.Errors;
import com.github.tomakehurst.wiremock.common.FileSource;
import com.github.tomakehurst.wiremock.common.TextFile;
import com.github.tomakehurst.wiremock.common.url.PathParams;
import com.github.tomakehurst.wiremock.core.Admin;
import com.github.tomakehurst.wiremock.http.ResponseDefinition;
import com.github.tomakehurst.wiremock.store.Stores;
import com.github.tomakehurst.wiremock.stubbing.ServeEvent;
import java.util.Optional;

public class GetStubFileTask implements AdminTask {

private final Stores stores;

public GetStubFileTask(Stores stores) {
this.stores = stores;
}

public class GetStubFilesTask implements AdminTask {
@Override
public ResponseDefinition execute(
final Admin admin, final ServeEvent serveEvent, final PathParams pathParams) {
try {
final FileSource fileSource = admin.getOptions().filesRoot().child(FILES_ROOT);
final TextFile textFile = fileSource.getTextFileNamed(pathParams.get("0"));
return ResponseDefinition.okForJson(textFile.readContentsAsString());
} catch (final Exception e) {
return ResponseDefinition.badRequest(Errors.single(60, "Could not find specified file."));
}
public ResponseDefinition execute(Admin admin, ServeEvent serveEvent, PathParams pathParams) {
String filename = pathParams.get("0");
Optional<byte[]> fileContents = stores.getFilesBlobStore().get(filename);

return fileContents
.map(bytes -> new ResponseDefinition(HTTP_OK, bytes))
.orElseGet(ResponseDefinition::notFound);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2011-2023 Thomas Akehurst
* Copyright (C) 2011-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 @@ -28,14 +28,7 @@
import com.github.tomakehurst.wiremock.http.Request;
import com.github.tomakehurst.wiremock.http.RequestMethod;
import com.github.tomakehurst.wiremock.http.ResponseDefinition;
import com.github.tomakehurst.wiremock.matching.ContentPattern;
import com.github.tomakehurst.wiremock.matching.MultiValuePattern;
import com.github.tomakehurst.wiremock.matching.MultipartValuePatternBuilder;
import com.github.tomakehurst.wiremock.matching.RequestPattern;
import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder;
import com.github.tomakehurst.wiremock.matching.StringValuePattern;
import com.github.tomakehurst.wiremock.matching.UrlPattern;
import com.github.tomakehurst.wiremock.matching.ValueMatcher;
import com.github.tomakehurst.wiremock.matching.*;
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -282,6 +275,12 @@ public BasicMappingBuilder andMatching(String customRequestMatcherName, Paramete
return this;
}

@Override
public BasicMappingBuilder andMatching(CustomMatcherDefinition matcherDefinition) {
requestPatternBuilder.andMatching(matcherDefinition);
return this;
}

private boolean requiredScenarioExist() {
return scenarioName == null && (requiredScenarioState != null || newScenarioState != null);
}
Expand Down
Loading

0 comments on commit 65704b5

Please sign in to comment.