Permalink
Browse files

Totally refactored the matching system to introduce the concept of di…

…stance. Used this to add ability to calculate "nearest misses" - pairs of request and request pattern with the lowest distance. Verification exceptions now print JUnit style diff output that IntelliJ turns into a diff window. JUnit rule now defaults to failing if any requests weren't matched during the test case (or class).
  • Loading branch information...
1 parent f613b86 commit acc9871a6e1648ea7ba26b82de6970c9c836f1b2 @tomakehurst committed Jun 14, 2016
Showing with 5,804 additions and 2,824 deletions.
  1. +1 −0 .gitignore
  2. +13 −4 build.gradle
  3. +3 −3 docs/source/stubbing.rst
  4. +3 −0 notes.txt
  5. +33 −5 src/main/java/com/github/tomakehurst/wiremock/WireMockServer.java
  6. +5 −1 src/main/java/com/github/tomakehurst/wiremock/admin/AdminTasks.java
  7. +18 −0 src/main/java/com/github/tomakehurst/wiremock/admin/FindNearMissesForRequestPatternTask.java
  8. +18 −0 src/main/java/com/github/tomakehurst/wiremock/admin/FindNearMissesForRequestTask.java
  9. +15 −0 src/main/java/com/github/tomakehurst/wiremock/admin/FindNearMissesForUnmatchedTask.java
  10. +1 −4 src/main/java/com/github/tomakehurst/wiremock/admin/FindRequestsTask.java
  11. +24 −0 src/main/java/com/github/tomakehurst/wiremock/admin/FindUnmatchedRequestsTask.java
  12. +2 −4 src/main/java/com/github/tomakehurst/wiremock/admin/GetRequestCountTask.java
  13. +1 −1 src/main/java/com/github/tomakehurst/wiremock/admin/{NewStubMappingTask.java → StubMappingTask.java}
  14. +10 −3 src/main/java/com/github/tomakehurst/wiremock/client/BasicCredentials.java
  15. +55 −27 src/main/java/com/github/tomakehurst/wiremock/client/HttpAdminClient.java
  16. +5 −4 src/main/java/com/github/tomakehurst/wiremock/client/LocalMappingBuilder.java
  17. +0 −56 src/main/java/com/github/tomakehurst/wiremock/client/LocalRequestPatternBuilder.java
  18. +17 −16 src/main/java/com/github/tomakehurst/wiremock/client/MappingBuilder.java
  19. +5 −4 src/main/java/com/github/tomakehurst/wiremock/client/RemoteMappingBuilder.java
  20. +0 −147 src/main/java/com/github/tomakehurst/wiremock/client/RequestPatternBuilder.java
  21. +7 −0 src/main/java/com/github/tomakehurst/wiremock/client/ResponseDefinitionBuilder.java
  22. +0 −49 src/main/java/com/github/tomakehurst/wiremock/client/UrlMatchingStrategy.java
  23. +0 −142 src/main/java/com/github/tomakehurst/wiremock/client/ValueMatchingStrategy.java
  24. +21 −8 src/main/java/com/github/tomakehurst/wiremock/client/VerificationException.java
  25. +167 −126 src/main/java/com/github/tomakehurst/wiremock/client/WireMock.java
  26. +55 −8 src/main/java/com/github/tomakehurst/wiremock/common/Json.java
  27. +41 −0 src/main/java/com/github/tomakehurst/wiremock/common/Xml.java
  28. +11 −4 src/main/java/com/github/tomakehurst/wiremock/core/Admin.java
  29. +2 −1 src/main/java/com/github/tomakehurst/wiremock/core/StubServer.java
  30. +71 −32 src/main/java/com/github/tomakehurst/wiremock/core/WireMockApp.java
  31. +1 −1 src/main/java/com/github/tomakehurst/wiremock/extension/Extension.java
  32. +1 −2 src/main/java/com/github/tomakehurst/wiremock/extension/ExtensionLoader.java
  33. +4 −5 src/main/java/com/github/tomakehurst/wiremock/http/AbstractRequestHandler.java
  34. +4 −2 src/main/java/com/github/tomakehurst/wiremock/http/AdminRequestHandler.java
  35. +16 −0 src/main/java/com/github/tomakehurst/wiremock/http/Cookie.java
  36. +5 −4 src/main/java/com/github/tomakehurst/wiremock/http/HttpClientFactory.java
  37. +15 −10 src/main/java/com/github/tomakehurst/wiremock/http/MultiValue.java
  38. +6 −0 src/main/java/com/github/tomakehurst/wiremock/http/QueryParameter.java
  39. +18 −1 src/main/java/com/github/tomakehurst/wiremock/http/RequestMethod.java
  40. +5 −1 src/main/java/com/github/tomakehurst/wiremock/http/ResponseDefinition.java
  41. +2 −1 src/main/java/com/github/tomakehurst/wiremock/http/StubRequestHandler.java
  42. +1 −1 src/main/java/com/github/tomakehurst/wiremock/junit/LocalStubbing.java
  43. +5 −1 src/main/java/com/github/tomakehurst/wiremock/junit/Stubbing.java
  44. +21 −0 src/main/java/com/github/tomakehurst/wiremock/junit/WireMockRule.java
  45. +15 −0 src/main/java/com/github/tomakehurst/wiremock/matching/AbsentPattern.java
  46. +24 −0 src/main/java/com/github/tomakehurst/wiremock/matching/AbstractRegexPattern.java
  47. +28 −0 src/main/java/com/github/tomakehurst/wiremock/matching/AnythingPattern.java
  48. +19 −0 src/main/java/com/github/tomakehurst/wiremock/matching/ContainsPattern.java
  49. +18 −0 src/main/java/com/github/tomakehurst/wiremock/matching/EagerMatchResult.java
  50. +150 −0 src/main/java/com/github/tomakehurst/wiremock/matching/EqualToJsonPattern.java
  51. +30 −0 src/main/java/com/github/tomakehurst/wiremock/matching/EqualToPattern.java
  52. +115 −0 src/main/java/com/github/tomakehurst/wiremock/matching/EqualToXmlPattern.java
  53. +50 −0 src/main/java/com/github/tomakehurst/wiremock/matching/LocalRequestPatternBuilder.java
  54. +52 −0 src/main/java/com/github/tomakehurst/wiremock/matching/MatchResult.java
  55. +58 −0 src/main/java/com/github/tomakehurst/wiremock/matching/MatchesJsonPathPattern.java
  56. +76 −0 src/main/java/com/github/tomakehurst/wiremock/matching/MatchesXPathPattern.java
  57. +90 −0 src/main/java/com/github/tomakehurst/wiremock/matching/MultiValuePattern.java
  58. +34 −0 src/main/java/com/github/tomakehurst/wiremock/matching/NegativeRegexPattern.java
  59. +18 −0 src/main/java/com/github/tomakehurst/wiremock/matching/RegexPattern.java
  60. +6 −2 src/main/java/com/github/tomakehurst/wiremock/matching/RequestMatcher.java
  61. +12 −9 src/main/java/com/github/tomakehurst/wiremock/matching/RequestMatcherExtension.java
  62. +235 −367 src/main/java/com/github/tomakehurst/wiremock/matching/RequestPattern.java
  63. +117 −0 src/main/java/com/github/tomakehurst/wiremock/matching/RequestPatternBuilder.java
  64. +93 −0 src/main/java/com/github/tomakehurst/wiremock/matching/StringValuePattern.java
  65. +145 −0 src/main/java/com/github/tomakehurst/wiremock/matching/StringValuePatternJsonDeserializer.java
  66. +22 −0 src/main/java/com/github/tomakehurst/wiremock/matching/StringValuePatternJsonSerializer.java
  67. +21 −0 src/main/java/com/github/tomakehurst/wiremock/matching/UrlPathPattern.java
  68. +80 −0 src/main/java/com/github/tomakehurst/wiremock/matching/UrlPattern.java
  69. +14 −0 src/main/java/com/github/tomakehurst/wiremock/matching/ValueMatcher.java
  70. +0 −450 src/main/java/com/github/tomakehurst/wiremock/matching/ValuePattern.java
  71. +3 −3 src/main/java/com/github/tomakehurst/wiremock/standalone/WireMockServerRunner.java
  72. +49 −14 src/main/java/com/github/tomakehurst/wiremock/stubbing/InMemoryStubMappings.java
  73. +62 −0 src/main/java/com/github/tomakehurst/wiremock/stubbing/ServedStub.java
  74. +5 −4 src/main/java/com/github/tomakehurst/wiremock/stubbing/StubMapping.java
  75. +13 −12 src/main/java/com/github/tomakehurst/wiremock/stubbing/StubMappingJsonRecorder.java
  76. +1 −1 src/main/java/com/github/tomakehurst/wiremock/stubbing/StubMappings.java
  77. +158 −0 src/main/java/com/github/tomakehurst/wiremock/verification/Diff.java
  78. +7 −2 src/main/java/com/github/tomakehurst/wiremock/verification/DisabledRequestJournal.java
  79. +20 −0 src/main/java/com/github/tomakehurst/wiremock/verification/FindNearMissesResult.java
  80. +21 −0 src/main/java/com/github/tomakehurst/wiremock/verification/FindServedStubsResult.java
  81. +31 −13 src/main/java/com/github/tomakehurst/wiremock/verification/InMemoryRequestJournal.java
  82. +7 −1 src/main/java/com/github/tomakehurst/wiremock/verification/LoggedRequest.java
  83. +59 −0 src/main/java/com/github/tomakehurst/wiremock/verification/NearMiss.java
  84. +63 −0 src/main/java/com/github/tomakehurst/wiremock/verification/NearMissCalculator.java
  85. +5 −2 src/main/java/com/github/tomakehurst/wiremock/verification/RequestJournal.java
  86. +9 −1 src/test/java/com/github/tomakehurst/wiremock/AcceptanceTestBase.java
  87. +22 −10 src/test/java/com/github/tomakehurst/wiremock/CustomMatchingAcceptanceTest.java
  88. +4 −3 src/test/java/com/github/tomakehurst/wiremock/Examples.java
  89. +7 −0 src/test/java/com/github/tomakehurst/wiremock/MappingsAcceptanceTest.java
  90. +87 −0 src/test/java/com/github/tomakehurst/wiremock/NearMissesAcceptanceTest.java
  91. +78 −0 src/test/java/com/github/tomakehurst/wiremock/NearMissesRuleAcceptanceTest.java
  92. +7 −7 src/test/java/com/github/tomakehurst/wiremock/ResponseDefinitionTransformerAcceptanceTest.java
  93. +3 −3 src/test/java/com/github/tomakehurst/wiremock/ResponseTransformerAcceptanceTest.java
  94. +6 −0 src/test/java/com/github/tomakehurst/wiremock/StubbingAcceptanceTest.java
  95. +110 −53 src/test/java/com/github/tomakehurst/wiremock/VerificationAcceptanceTest.java
  96. +0 −15 src/test/java/com/github/tomakehurst/wiremock/WireMockJUnitRuleTest.java
  97. +1 −2 src/test/java/com/github/tomakehurst/wiremock/admin/EditStubMappingTaskTest.java
  98. +0 −143 src/test/java/com/github/tomakehurst/wiremock/client/MappingBuilderTest.java
  99. +3 −3 src/test/java/com/github/tomakehurst/wiremock/client/RequestDelaySpecTest.java
  100. +11 −12 src/test/java/com/github/tomakehurst/wiremock/client/WireMockClientTest.java
  101. +6 −7 src/test/java/com/github/tomakehurst/wiremock/http/HttpHeaderTest.java
  102. +27 −0 src/test/java/com/github/tomakehurst/wiremock/matching/ContainsPatternTest.java
  103. +353 −0 src/test/java/com/github/tomakehurst/wiremock/matching/EqualToJsonTest.java
  104. +76 −0 src/test/java/com/github/tomakehurst/wiremock/matching/EqualToPatternTest.java
  105. +223 −0 src/test/java/com/github/tomakehurst/wiremock/matching/EqualToXmlPatternTest.java
  106. +99 −0 src/test/java/com/github/tomakehurst/wiremock/matching/MatchesJsonPathPatternTest.java
  107. +141 −0 src/test/java/com/github/tomakehurst/wiremock/matching/MatchesXPathPatternTest.java
  108. +152 −0 src/test/java/com/github/tomakehurst/wiremock/matching/MockRequest.java
  109. +112 −0 src/test/java/com/github/tomakehurst/wiremock/matching/MultiValuePatternTest.java
  110. +39 −0 src/test/java/com/github/tomakehurst/wiremock/matching/RegexValuePatternTest.java
  111. +410 −0 src/test/java/com/github/tomakehurst/wiremock/matching/RequestPatternTest.java
  112. +40 −0 src/test/java/com/github/tomakehurst/wiremock/matching/UrlPatternTest.java
  113. +0 −270 src/test/java/com/github/tomakehurst/wiremock/matching/ValuePatternTest.java
  114. +8 −5 src/test/java/com/github/tomakehurst/wiremock/standalone/CommandLineOptionsTest.java
  115. +10 −9 src/test/java/com/github/tomakehurst/wiremock/stubbing/AdminRequestHandlerTest.java
  116. +161 −171 src/test/java/com/github/tomakehurst/wiremock/stubbing/InMemoryMappingsTest.java
  117. +4 −4 src/test/java/com/github/tomakehurst/wiremock/stubbing/InMemoryStubMappingsTest.java
  118. +43 −0 src/test/java/com/github/tomakehurst/wiremock/stubbing/JsonTest.java
  119. +0 −384 src/test/java/com/github/tomakehurst/wiremock/stubbing/RequestPatternTest.java
  120. +6 −6 src/test/java/com/github/tomakehurst/wiremock/stubbing/ResponseDefinitionTest.java
  121. +3 −1 src/test/java/com/github/tomakehurst/wiremock/stubbing/SortedConcurrentMappingSetTest.java
  122. +12 −10 src/test/java/com/github/tomakehurst/wiremock/stubbing/StubMappingJsonRecorderTest.java
  123. +25 −56 src/test/java/com/github/tomakehurst/wiremock/stubbing/StubRequestHandlerTest.java
  124. +0 −78 src/test/java/com/github/tomakehurst/wiremock/testsupport/RequestResponseMappingBuilder.java
  125. +61 −0 src/test/java/com/github/tomakehurst/wiremock/testsupport/TestNotifier.java
  126. +2 −2 src/test/java/com/github/tomakehurst/wiremock/testsupport/WireMockTestClient.java
  127. +338 −0 src/test/java/com/github/tomakehurst/wiremock/verification/DiffTest.java
  128. +12 −11 src/test/java/com/github/tomakehurst/wiremock/verification/InMemoryRequestJournalTest.java
  129. +137 −0 src/test/java/com/github/tomakehurst/wiremock/verification/NearMissCalculatorTest.java
  130. +101 −0 src/test/java/com/github/tomakehurst/wiremock/verification/NearMissTest.java
  131. +65 −0 src/test/java/ignored/NearMissExampleTest.java
  132. +36 −0 src/test/java/ignored/UnmatchedTest.java
  133. +20 −0 src/test/java/ignored/WireMockRuleFailThenPass.java
  134. 0 src/test/resources/empty/.gitkeep
View
@@ -48,3 +48,4 @@ copy-admin.sh
**/.DS_Store
.vagrant
+tmp*
View
@@ -51,14 +51,16 @@ dependencies {
"com.fasterxml.jackson.core:jackson-annotations:$versions.jackson",
"com.fasterxml.jackson.core:jackson-databind:$versions.jackson"
compile "org.apache.httpcomponents:httpclient:4.5"
- compile "org.skyscreamer:jsonassert:1.2.3"
- compile "xmlunit:xmlunit:1.6"
+ compile 'org.xmlunit:xmlunit-core:2.1.1'
+ compile 'org.xmlunit:xmlunit-legacy:2.1.1'
compile "com.jayway.jsonpath:json-path:2.0.0"
compile "org.slf4j:slf4j-api:1.7.12"
compile "net.sf.jopt-simple:jopt-simple:4.9"
compile("junit:junit:4.12") {
exclude group: "org.hamcrest", module: "hamcrest-core"
}
+ compile 'org.apache.commons:commons-lang3:3.4'
+ compile 'com.flipkart.zjsonpatch:zjsonpatch:0.2.1'
testCompile "org.hamcrest:hamcrest-all:1.3"
testCompile("org.jmock:jmock:2.5.1") {
@@ -71,7 +73,8 @@ dependencies {
exclude group: "org.hamcrest", module: "hamcrest-core"
exclude group: "org.hamcrest", module: "hamcrest-library"
}
- testCompile "net.sf.json-lib:json-lib:2.4:jdk15"
+ testCompile "org.skyscreamer:jsonassert:1.2.3"
+
testCompile "com.googlecode.jarjar:jarjar:1.3"
testCompile "commons-io:commons-io:2.4"
@@ -87,6 +90,8 @@ test {
// Set the timezone for testing somewhere other than my machine to increase the chances of catching timezone bugs
systemProperty 'user.timezone', 'Australia/Sydney'
+ exclude 'ignored/**'
+
maxParallelForks = 3
}
@@ -227,7 +232,7 @@ publishing {
maven {
URL localRepo = new File("${System.getProperty('user.home')}/.m2/repository").toURI().toURL()
URL repoUrl = shouldPublishLocally ? localRepo : URI.create('https://oss.sonatype.org/service/local/staging/deploy/maven2').toURL()
- println "Publishing to $repoUrl"
+
url repoUrl
credentials {
username repoUser
@@ -288,6 +293,10 @@ publishing {
}
}
+publish.doFirst {
+ println "Publishing to $repoUrl"
+}
+
task checkReleasePreconditions << {
println "Using Java version: ${System.getProperty('java.runtime.version')}"
assert System.getProperty('java.runtime.version').startsWith('1.7'), "Must release with Java 7 to avoid collection bug"
@@ -433,9 +433,9 @@ or:
"url": "/xpath",
"bodyPatterns" : [
{ "matchesXPath" : "/stuff:outer/stuff:inner[.=111]" ,
- "withXPathNamespaces" : {
- "stuff" : "http://foo.com/"
- }
+ "xPathNamespaces" : {
+ "stuff" : "http://foo.com/"
+ }
},
]
},
View
@@ -0,0 +1,3 @@
+value: is equal
+object: are all keys present and values equal, recursing into objects?
+array: for each in source array, match each in target array + calc distance, add 1 distance point for each additional target element
@@ -15,7 +15,9 @@
*/
package com.github.tomakehurst.wiremock;
-import com.github.tomakehurst.wiremock.client.*;
+import com.github.tomakehurst.wiremock.client.LocalMappingBuilder;
+import com.github.tomakehurst.wiremock.client.RemoteMappingBuilder;
+import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.common.FatalStartupException;
import com.github.tomakehurst.wiremock.common.FileSource;
import com.github.tomakehurst.wiremock.common.Notifier;
@@ -30,16 +32,17 @@
import com.github.tomakehurst.wiremock.global.GlobalSettingsHolder;
import com.github.tomakehurst.wiremock.http.*;
import com.github.tomakehurst.wiremock.junit.LocalStubbing;
-import com.github.tomakehurst.wiremock.matching.RequestMatcherExtension;
+import com.github.tomakehurst.wiremock.matching.LocalRequestPatternBuilder;
import com.github.tomakehurst.wiremock.matching.RequestPattern;
+import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder;
+import com.github.tomakehurst.wiremock.matching.RequestMatcherExtension;
import com.github.tomakehurst.wiremock.standalone.JsonFileMappingsSource;
import com.github.tomakehurst.wiremock.standalone.MappingsLoader;
import com.github.tomakehurst.wiremock.stubbing.ListStubMappingsResult;
+import com.github.tomakehurst.wiremock.stubbing.ServedStub;
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
import com.github.tomakehurst.wiremock.stubbing.StubMappingJsonRecorder;
-import com.github.tomakehurst.wiremock.verification.FindRequestsResult;
-import com.github.tomakehurst.wiremock.verification.LoggedRequest;
-import com.github.tomakehurst.wiremock.verification.VerificationResult;
+import com.github.tomakehurst.wiremock.verification.*;
import com.google.common.collect.ImmutableList;
import java.util.List;
@@ -277,6 +280,11 @@ public void setGlobalFixedDelay(int milliseconds) {
}
@Override
+ public List<LoggedRequest> findAllUnmatchedRequests() {
+ return client.findAllUnmatchedRequests();
+ }
+
+ @Override
public void addStubMapping(StubMapping stubMapping) {
wireMockApp.addStubMapping(stubMapping);
}
@@ -327,11 +335,31 @@ public FindRequestsResult findRequestsMatching(RequestPattern requestPattern) {
}
@Override
+ public FindRequestsResult findUnmatchedRequests() {
+ return wireMockApp.findUnmatchedRequests();
+ }
+
+ @Override
public void updateGlobalSettings(GlobalSettings newSettings) {
wireMockApp.updateGlobalSettings(newSettings);
}
@Override
+ public FindNearMissesResult findNearMissesForUnmatchedRequests() {
+ return wireMockApp.findNearMissesForUnmatchedRequests();
+ }
+
+ @Override
+ public FindNearMissesResult findNearMissesFor(LoggedRequest loggedRequest) {
+ return wireMockApp.findNearMissesFor(loggedRequest);
+ }
+
+ @Override
+ public FindNearMissesResult findNearMissesFor(RequestPattern requestPattern) {
+ return wireMockApp.findNearMissesFor(requestPattern);
+ }
+
+ @Override
public void shutdownServer() {
shutdown();
}
@@ -31,14 +31,18 @@
.put(requestSpec(GET, "/"), RootTask.class)
.put(requestSpec(GET, ""), RootRedirectTask.class)
.put(requestSpec(POST, "/reset"), ResetTask.class)
- .put(requestSpec(POST, "/mappings/new"), NewStubMappingTask.class)
+ .put(requestSpec(POST, "/mappings/new"), StubMappingTask.class)
.put(requestSpec(POST, "/mappings/edit"), EditStubMappingTask.class)
.put(requestSpec(POST, "/scenarios/reset"), ResetScenariosTask.class)
.put(requestSpec(POST, "/mappings/save"), SaveMappingsTask.class)
.put(requestSpec(POST, "/mappings/reset"), ResetToDefaultMappingsTask.class)
.put(requestSpec(POST, "/requests/reset"), ResetRequestsTask.class)
.put(requestSpec(POST, "/requests/count"), GetRequestCountTask.class)
.put(requestSpec(POST, "/requests/find"), FindRequestsTask.class)
+ .put(requestSpec(GET, "/requests/unmatched"), FindUnmatchedRequestsTask.class)
+ .put(requestSpec(GET, "/requests/unmatched/near-misses"), FindNearMissesForUnmatchedTask.class)
+ .put(requestSpec(POST, "/near-misses/request"), FindNearMissesForRequestTask.class)
+ .put(requestSpec(POST, "/near-misses/request-pattern"), FindNearMissesForRequestPatternTask.class)
.put(requestSpec(POST, "/settings"), GlobalSettingsUpdateTask.class)
.put(requestSpec(POST, "/shutdown"), ShutdownServerTask.class)
.build();
@@ -0,0 +1,18 @@
+package com.github.tomakehurst.wiremock.admin;
+
+import com.github.tomakehurst.wiremock.common.Json;
+import com.github.tomakehurst.wiremock.core.Admin;
+import com.github.tomakehurst.wiremock.http.Request;
+import com.github.tomakehurst.wiremock.http.ResponseDefinition;
+import com.github.tomakehurst.wiremock.matching.RequestPattern;
+import com.github.tomakehurst.wiremock.verification.FindNearMissesResult;
+
+public class FindNearMissesForRequestPatternTask implements AdminTask {
+
+ @Override
+ public ResponseDefinition execute(Admin admin, Request request) {
+ RequestPattern requestPattern = Json.read(request.getBodyAsString(), RequestPattern.class);
+ FindNearMissesResult nearMissesResult = admin.findNearMissesFor(requestPattern);
+ return ResponseDefinition.okForJson(nearMissesResult);
+ }
+}
@@ -0,0 +1,18 @@
+package com.github.tomakehurst.wiremock.admin;
+
+import com.github.tomakehurst.wiremock.common.Json;
+import com.github.tomakehurst.wiremock.core.Admin;
+import com.github.tomakehurst.wiremock.http.Request;
+import com.github.tomakehurst.wiremock.http.ResponseDefinition;
+import com.github.tomakehurst.wiremock.verification.FindNearMissesResult;
+import com.github.tomakehurst.wiremock.verification.LoggedRequest;
+
+public class FindNearMissesForRequestTask implements AdminTask {
+
+ @Override
+ public ResponseDefinition execute(Admin admin, Request request) {
+ LoggedRequest loggedRequest = Json.read(request.getBodyAsString(), LoggedRequest.class);
+ FindNearMissesResult nearMissesResult = admin.findNearMissesFor(loggedRequest);
+ return ResponseDefinition.okForJson(nearMissesResult);
+ }
+}
@@ -0,0 +1,15 @@
+package com.github.tomakehurst.wiremock.admin;
+
+import com.github.tomakehurst.wiremock.core.Admin;
+import com.github.tomakehurst.wiremock.http.Request;
+import com.github.tomakehurst.wiremock.http.ResponseDefinition;
+import com.github.tomakehurst.wiremock.verification.FindNearMissesResult;
+
+public class FindNearMissesForUnmatchedTask implements AdminTask {
+
+ @Override
+ public ResponseDefinition execute(Admin admin, Request request) {
+ FindNearMissesResult nearMissesResult = admin.findNearMissesForUnmatchedRequests();
+ return ResponseDefinition.okForJson(nearMissesResult);
+ }
+}
@@ -17,22 +17,19 @@
import com.github.tomakehurst.wiremock.common.Json;
import com.github.tomakehurst.wiremock.core.Admin;
-import com.github.tomakehurst.wiremock.http.HttpHeaders;
import com.github.tomakehurst.wiremock.http.Request;
import com.github.tomakehurst.wiremock.http.ResponseDefinition;
import com.github.tomakehurst.wiremock.matching.RequestPattern;
import com.github.tomakehurst.wiremock.verification.FindRequestsResult;
import static com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder.responseDefinition;
-import static com.github.tomakehurst.wiremock.http.HttpHeader.httpHeader;
-import static com.github.tomakehurst.wiremock.matching.RequestPattern.buildRequestPatternFrom;
import static java.net.HttpURLConnection.HTTP_OK;
public class FindRequestsTask implements AdminTask {
@Override
public ResponseDefinition execute(Admin admin, Request request) {
- RequestPattern requestPattern = buildRequestPatternFrom(request.getBodyAsString());
+ RequestPattern requestPattern = Json.read(request.getBodyAsString(), RequestPattern.class);
FindRequestsResult result = admin.findRequestsMatching(requestPattern);
return responseDefinition()
@@ -0,0 +1,24 @@
+package com.github.tomakehurst.wiremock.admin;
+
+import com.github.tomakehurst.wiremock.common.Json;
+import com.github.tomakehurst.wiremock.core.Admin;
+import com.github.tomakehurst.wiremock.http.Request;
+import com.github.tomakehurst.wiremock.http.ResponseDefinition;
+import com.github.tomakehurst.wiremock.verification.FindRequestsResult;
+import com.github.tomakehurst.wiremock.verification.FindServedStubsResult;
+
+import static com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder.responseDefinition;
+import static java.net.HttpURLConnection.HTTP_OK;
+
+public class FindUnmatchedRequestsTask implements AdminTask {
+
+ @Override
+ public ResponseDefinition execute(Admin admin, Request request) {
+ FindRequestsResult unmatchedRequests = admin.findUnmatchedRequests();
+ return responseDefinition()
+ .withStatus(HTTP_OK)
+ .withBody(Json.write(unmatchedRequests))
+ .withHeader("Content-Type", "application/json")
+ .build();
+ }
+}
@@ -15,24 +15,22 @@
*/
package com.github.tomakehurst.wiremock.admin;
+import com.github.tomakehurst.wiremock.common.Json;
import com.github.tomakehurst.wiremock.core.Admin;
-import com.github.tomakehurst.wiremock.http.HttpHeaders;
import com.github.tomakehurst.wiremock.http.Request;
import com.github.tomakehurst.wiremock.http.ResponseDefinition;
import com.github.tomakehurst.wiremock.matching.RequestPattern;
import com.github.tomakehurst.wiremock.verification.VerificationResult;
import static com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder.responseDefinition;
import static com.github.tomakehurst.wiremock.common.Json.write;
-import static com.github.tomakehurst.wiremock.http.HttpHeader.httpHeader;
-import static com.github.tomakehurst.wiremock.matching.RequestPattern.buildRequestPatternFrom;
import static java.net.HttpURLConnection.HTTP_OK;
public class GetRequestCountTask implements AdminTask {
@Override
public ResponseDefinition execute(Admin admin, Request request) {
- RequestPattern requestPattern = buildRequestPatternFrom(request.getBodyAsString());
+ RequestPattern requestPattern = Json.read(request.getBodyAsString(), RequestPattern.class);
VerificationResult result = admin.countRequestsMatching(requestPattern);
return responseDefinition()
@@ -20,7 +20,7 @@
import com.github.tomakehurst.wiremock.http.ResponseDefinition;
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
-public class NewStubMappingTask implements AdminTask {
+public class StubMappingTask implements AdminTask {
@Override
public ResponseDefinition execute(Admin admin, Request request) {
@@ -2,9 +2,10 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
-import com.github.tomakehurst.wiremock.matching.ValuePattern;
+import com.github.tomakehurst.wiremock.matching.MultiValuePattern;
import org.apache.commons.codec.binary.Base64;
+import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.google.common.base.Charsets.UTF_8;
public class BasicCredentials {
@@ -23,8 +24,14 @@ public boolean present() {
return username != null && password != null;
}
- public ValuePattern asAuthorizationHeaderValue() {
+ public MultiValuePattern asAuthorizationMultiValuePattern() {
+ return MultiValuePattern.of(
+ equalTo(asAuthorizationHeaderValue())
+ );
+ }
+
+ public String asAuthorizationHeaderValue() {
byte[] usernameAndPassword = (username + ":" + password).getBytes();
- return ValuePattern.equalTo("Basic " + new String(Base64.encodeBase64(usernameAndPassword), UTF_8));
+ return "Basic " + new String(Base64.encodeBase64(usernameAndPassword), UTF_8);
}
}
Oops, something went wrong.

0 comments on commit acc9871

Please sign in to comment.