Skip to content

Commit

Permalink
Added stub deletion docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tomakehurst committed Apr 3, 2024
1 parent 5ea3b3f commit 3e2a30c
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions _docs/stubbing.md
Original file line number Diff line number Diff line change
Expand Up @@ -540,15 +540,29 @@ This feature is also available with the standard JAR. To use it, define the file

## Removing stubs

Stub mappings can be deleted via the Java API as follows:
Stub mappings can be deleted via the Java API, either by passing the stub object or the stub ID:

```java
StubMapping stubMapping = stubFor(get(urlEqualTo("/delete-me"))
.willReturn(aResponse().withStatus(200)));

// Do things with the stub
UUID stubId = UUID.randomUUID();
StubMapping stubMapping = stubFor(get("/delete-me")
.withId(stubId)
.willReturn(ok()));

removeStub(stubMapping);

// or

removeStub(stubId);
```

Where stubs have metadata set on them this can be used to remove them:

```java
stubFor(get("/delete-me")
.withMetadata(metadata().attr("tag", "payments"))
.willReturn(ok()));

removeStubsByMetadata(matchingJsonPath("$.tag", equalTo("payments")));
```

They can be deleted via the HTTP API by issuing a `DELETE` to `http://<host>:<port>/__admin/mappings/{id}`
Expand Down

0 comments on commit 3e2a30c

Please sign in to comment.