|
32 | 32 | import static org.hamcrest.Matchers.hasItems; |
33 | 33 | import static org.hamcrest.Matchers.hasKey; |
34 | 34 | import static org.hamcrest.Matchers.hasSize; |
| 35 | +import static org.hamcrest.Matchers.hasToString; |
35 | 36 | import static org.hamcrest.Matchers.is; |
36 | 37 | import static org.hamcrest.Matchers.not; |
37 | 38 | import static org.hamcrest.Matchers.notNullValue; |
@@ -312,10 +313,10 @@ public void testAPIResponse(String type) { |
312 | 313 | vr.body("paths.'/user/username/{username}'.delete.responses.'404'.description", equalTo("User not found")); |
313 | 314 |
|
314 | 315 | // @APIResponse at class level combined with method level |
315 | | - vr.body("paths.'/user/username/{username}'.patch.responses", aMapWithSize(2)); |
316 | | - vr.body("paths.'/user/username/{username}'.patch.responses.'200'.description", |
317 | | - equalTo("Password was changed successfully")); |
318 | | - vr.body("paths.'/user/username/{username}'.patch.responses.'400'.description", equalTo("Invalid request")); |
| 316 | + vr.body("paths.'/user/logout'.get.responses", aMapWithSize(2)); |
| 317 | + vr.body("paths.'/user/logout'.get.responses.'200'.description", |
| 318 | + equalTo("Successful user logout.")); |
| 319 | + vr.body("paths.'/user/logout'.get.responses.'400'.description", equalTo("Invalid request")); |
319 | 320 | } |
320 | 321 |
|
321 | 322 | @Test(dataProvider = "formatProvider") |
@@ -832,6 +833,27 @@ public void testExampleObject(String type) { |
832 | 833 | equalTo("bsmith")); |
833 | 834 | } |
834 | 835 |
|
| 836 | + @Test(dataProvider = "formatProvider") |
| 837 | + public void testExamplesInHeaders(String type) { |
| 838 | + ValidatableResponse vr = callEndpoint(type); |
| 839 | + |
| 840 | + // Multiple examples in Header |
| 841 | + vr.body("paths.'/user/username/{username}'.patch.responses.'200'.headers.'X-Password-Strength'", |
| 842 | + hasKey("examples")); |
| 843 | + |
| 844 | + // Implementations MAY parse the example to the data type of the schema, so here we leniently test |
| 845 | + // the value as a string using String#valueOf (via hasToString). |
| 846 | + |
| 847 | + vr.body("paths.'/user/username/{username}'.patch.responses.'200'.headers.'X-Password-Strength'.examples", allOf( |
| 848 | + hasEntry(equalTo("strong"), hasEntry(equalTo("value"), hasToString("10"))), |
| 849 | + hasEntry(equalTo("adequate"), hasEntry(equalTo("value"), hasToString("8.5"))), |
| 850 | + hasEntry(equalTo("weak"), hasEntry(equalTo("value"), hasToString("5.1"))))); |
| 851 | + |
| 852 | + // Single example in header |
| 853 | + vr.body("paths.'/user/username/{username}'.patch.responses.'400'.headers.'X-Password-Strength'", |
| 854 | + hasEntry(equalTo("example"), hasToString("0"))); |
| 855 | + } |
| 856 | + |
835 | 857 | @Test(dataProvider = "formatProvider") |
836 | 858 | public void testContentExampleAttribute(String type) { |
837 | 859 | ValidatableResponse vr = callEndpoint(type); |
|
0 commit comments