Search in sources :

Example 1 with MultipartValuePatternBuilder

use of com.github.tomakehurst.wiremock.matching.MultipartValuePatternBuilder in project spring-bot by finos.

the class TestOboCall method setupWireMock.

@BeforeEach
public void setupWireMock() {
    // session auth / cert login
    wireMockRule.stubFor(post(urlEqualTo("/sessionauth/v1/app/authenticate")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{\"name\": \"some-app-token\", \"token\": \"" + APP_TOKEN + "\"}")));
    wireMockRule.stubFor(post(urlEqualTo("/sessionauth/v1/app/user/1234/authenticate")).withHeader("sessionToken", new EqualToPattern(APP_TOKEN)).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{\"sessionToken\": \"" + OBO_TOKEN + "\"}")));
    // rsa auth
    wireMockRule.stubFor(post(urlEqualTo("/login/pubkey/authenticate")).withRequestBody(new RegexPattern("\\{\"token\":\".*}")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{\"name\": \"some-app-token\", \"token\": \"" + APP_TOKEN + "\"}")));
    wireMockRule.stubFor(post(urlEqualTo("/login/pubkey/app/user/1234/authenticate")).withHeader("sessionToken", new EqualToPattern(APP_TOKEN)).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{\"token\": \"" + OBO_TOKEN + "\"}")));
    // sending the blast message
    wireMockRule.stubFor(post(urlEqualTo("/agent/v4/message/blast")).withMultipartRequestBody(new MultipartValuePatternBuilder("sids").withBody(new EqualToPattern(STREAM_IDS))).withMultipartRequestBody(new MultipartValuePatternBuilder("message").withBody(new EqualToPattern(MESSAGE_CONTENT))).withHeader("sessionToken", new EqualToPattern(OBO_TOKEN)).willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(200)));
    wireMockRule.start();
}
Also used : MultipartValuePatternBuilder(com.github.tomakehurst.wiremock.matching.MultipartValuePatternBuilder) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with MultipartValuePatternBuilder

use of com.github.tomakehurst.wiremock.matching.MultipartValuePatternBuilder in project junit-servers by mjeanroy.

the class WireMockTestUtils method assertUploadRequest.

/**
 * Verify that a given request has been triggered.
 *
 * @param endpoint Request endpoint.
 * @param method Request method.
 */
static void assertUploadRequest(String endpoint, HttpMethod method, File file) {
    UrlPattern urlPattern = urlEqualTo(endpoint);
    RequestMethod rqMethod = new RequestMethod(method.name());
    RequestPatternBuilder rq = new RequestPatternBuilder(rqMethod, urlPattern).withAllRequestBodyParts(new MultipartValuePatternBuilder().withName(file.getName()).withBody(new BinaryEqualToPattern(TestUtils.readFile(file))));
    WireMock.verify(1, rq);
}
Also used : MultipartValuePatternBuilder(com.github.tomakehurst.wiremock.matching.MultipartValuePatternBuilder) RequestMethod(com.github.tomakehurst.wiremock.http.RequestMethod) BinaryEqualToPattern(com.github.tomakehurst.wiremock.matching.BinaryEqualToPattern) RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) UrlPattern(com.github.tomakehurst.wiremock.matching.UrlPattern)

Aggregations

MultipartValuePatternBuilder (com.github.tomakehurst.wiremock.matching.MultipartValuePatternBuilder)2 RequestMethod (com.github.tomakehurst.wiremock.http.RequestMethod)1 BinaryEqualToPattern (com.github.tomakehurst.wiremock.matching.BinaryEqualToPattern)1 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)1 RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)1 RequestPatternBuilder (com.github.tomakehurst.wiremock.matching.RequestPatternBuilder)1 UrlPattern (com.github.tomakehurst.wiremock.matching.UrlPattern)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1