File tree Expand file tree Collapse file tree
main/java/com/github/tomakehurst/wiremock
test/java/com/github/tomakehurst/wiremock Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -278,6 +278,11 @@ public void removeStubMapping(StubMapping stubMapping) {
278278 wireMockApp .removeStubMapping (stubMapping );
279279 }
280280
281+ @ Override
282+ public void removeStubMapping (UUID id ) {
283+ wireMockApp .removeStubMapping (id );
284+ }
285+
281286 @ Override
282287 public void verify (RequestPatternBuilder requestPatternBuilder ) {
283288 client .verifyThat (requestPatternBuilder );
Original file line number Diff line number Diff line change @@ -160,6 +160,14 @@ public void removeStubMapping(StubMapping stubbMapping) {
160160 postJsonAssertOkAndReturnBody (urlFor (OldRemoveStubMappingTask .class ), Json .write (stubbMapping ));
161161 }
162162
163+ @ Override
164+ public void removeStubMapping (UUID id ) {
165+ executeRequest (
166+ adminRoutes .requestSpecForTask (RemoveStubMappingTask .class ),
167+ PathParams .single ("id" , id ),
168+ Void .class );
169+ }
170+
163171 @ Override
164172 public ListStubMappingsResult listAllStubMappings () {
165173 return executeRequest (
Original file line number Diff line number Diff line change @@ -36,6 +36,8 @@ public interface Admin {
3636
3737 void removeStubMapping (StubMapping stubbMapping );
3838
39+ void removeStubMapping (UUID id );
40+
3941 ListStubMappingsResult listAllStubMappings ();
4042
4143 SingleStubMappingResult getStubMapping (UUID id );
Original file line number Diff line number Diff line change @@ -262,6 +262,14 @@ public void removeStubMapping(StubMapping stubMapping) {
262262 stubMappings .removeMapping (stubMapping );
263263 }
264264
265+ @ Override
266+ public void removeStubMapping (UUID id ) {
267+ final Optional <StubMapping > maybeStub = stubMappings .get (id );
268+ if (maybeStub .isPresent ()) {
269+ removeStubMapping (maybeStub .get ());
270+ }
271+ }
272+
265273 @ Override
266274 public void editStubMapping (StubMapping stubMapping ) {
267275 stubMappings .editMapping (stubMapping );
Original file line number Diff line number Diff line change @@ -55,6 +55,11 @@ public void removeStubMapping(StubMapping stubbMapping) {
5555 admin .removeStubMapping (stubbMapping );
5656 }
5757
58+ @ Override
59+ public void removeStubMapping (UUID id ) {
60+ admin .removeStubMapping (id );
61+ }
62+
5863 @ Override
5964 public ListStubMappingsResult listAllStubMappings () {
6065 return admin .listAllStubMappings ();
Original file line number Diff line number Diff line change @@ -1004,6 +1004,29 @@ public void jsonResponseWithObjectValue() {
10041004 assertThat (response .content (), containsString ("\" Json From Object\" " ));
10051005 }
10061006
1007+ @ Test
1008+ public void removesASingleStubMapping () {
1009+ final UUID id = UUID .randomUUID ();
1010+ stubFor (get ("/stub-to-remove" ).withId (id ).willReturn (aResponse ()));
1011+
1012+ assertThat (testClient .get ("/stub-to-remove" ).statusCode (), is (200 ));
1013+
1014+ StubMapping stub = wireMockServer .getSingleStubMapping (id );
1015+ wireMockServer .removeStubMapping (stub );
1016+ assertThat (testClient .get ("/stub-to-remove" ).statusCode (), is (404 ));
1017+ }
1018+
1019+ @ Test
1020+ public void removesASingleStubMappingById () {
1021+ final UUID id = UUID .randomUUID ();
1022+ stubFor (get ("/stub-to-remove-by-id" ).withId (id ).willReturn (aResponse ()));
1023+
1024+ assertThat (testClient .get ("/stub-to-remove-by-id" ).statusCode (), is (200 ));
1025+
1026+ wireMockServer .removeStubMapping (id );
1027+ assertThat (testClient .get ("/stub-to-remove-by-id" ).statusCode (), is (404 ));
1028+ }
1029+
10071030 private int getStatusCodeUsingJavaUrlConnection (String url ) throws IOException {
10081031 HttpURLConnection connection = (HttpURLConnection ) new URL (url ).openConnection ();
10091032 connection .setRequestMethod ("GET" );
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments