Stubbing with Wiremock - WithBodyFile Location other than _files

Ragini picture Ragini · Jan 11, 2018 · Viewed 7.9k times · Source

Wiremock Documentation states that the location of the file specified in withBodyFile should be in src/test/resources/__files. I would like to have file in src/test/resources/Testing_ABC/Testcase2/myfile.xml.

Is there any way I can achieve this ? I tried following, but it does not seem to work !

stubFor(get(urlPathEqualTo("/abc")).willReturn
                (aResponse().withHeader("Content-Type",
                        "text/xml; charset=utf-8").withHeader
                        ("Content-Encoding",
                                "gzip")
                        .withBodyFile
                                ("src/test/resources/Testing_ABC/Testcase2/myfile.xml)));

However, when I put my file in src/test/resources/__files/myfile.xml and change the path accordingly, it works fine.

I am just wondering if I can make wiremock look in some other directory in resources other than __files just in order to have nice resource structure in project.

Answer

Arthur Kazemi picture Arthur Kazemi · Aug 27, 2018

I'm using this Kotlin Config class to customize the Root Directory. It still requires response file to be in the __files directory.

@Configuration
class Config: WireMockConfigurationCustomizer {
    override fun customize(config: WireMockConfiguration?) {
        config!!.withRootDirectory("customer-client/src/test/resources")
    }
}

@AutoConfigureWireMock