Last active
May 24, 2024 20:34
-
-
Save pavelfomin/42e3289f6d697fba7504d6f82ae46626 to your computer and use it in GitHub Desktop.
Pass `com.github.tomakehurst.wiremock.matching.StringValuePattern` to `com.github.tomakehurst.wiremock.client.MappingBuilder#withHeader(java.lang.String, com.github.tomakehurst.wiremock.matching.StringValuePattern)` from Spock's `where` clause to test header value set and absent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def "fetch file info"() { | |
given: | |
UUID fileId = UUID.randomUUID() | |
FileMetadata response = new FileMetadata(fileId, "/somePath", "someFileName.xls", 100) | |
wireMockServer.stubFor( | |
get(urlPathTemplate(uri)) | |
.withPathParam("fileId", equalTo(fileId.toString())) | |
.withHeader(AUTHORIZATION_HEADER, expectedAuthorization) | |
.withHeader(USER_ID_HEADER, expectedPassedUserId) | |
.willReturn(okJson(json(response))) | |
) | |
when: | |
Optional<FileMetadata> result = metadataFetcher.fetchFileInfo(portalType, fileId, authorization, passedUserId) | |
then: | |
result | |
!wireMockServer.findUnmatchedRequests().requests | |
where: | |
authorization | expectedAuthorization | passedUserId | expectedPassedUserId | |
null | absent() | null | absent() | |
null | absent() | "user" | equalTo(passedUserId) | |
"Bearer token" | equalTo(authorization) | null | absent() | |
"Bearer token" | equalTo(authorization) | "user" | equalTo(passedUserId) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment