Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WireMock uses wrong __files directory for multi-directory mappings configuration

I'm using Spring Boot with spring-cloud-contract-wiremock and com.github.tomakehurst.wiremock dependencies. My wiremock definitions are stored in json files. Like that:

directoryA/mappings/detail-mapping-123.json:

{
  "request" : {
    "urlPath" : "/detail/123",
    "method" : "GET"
  },
  "response" : {
    "status" : 200,
    "bodyFileName" : "detail.json",
    "headers" : {
      "Content-Type" : "application/json;charset=UTF-8"
    }
  }
}

directoryA/__files/detail.json:

{
  "id": "123",
  "name": "name-123"
}

directoryB/mappings/search-mapping-123.json:

{
  "request" : {
    "urlPath" : "/service/usa/search",
    "queryParameters" : {
      "query": {
        "equalTo": "123"
      }
    },
    "method" : "GET"
  },
  "response" : {
    "status" : 200,
    "bodyFileName" : "search-123.json",
    "headers" : {
      "Content-Type" : "application/json;charset=UTF-8"
    }
  }
}

directoryB/__files/search-123.json:

{
  "count": 1,
  "units": [
    {
      "name": "A123"
    }
  ]
}

I have standard JUnit test class which is annotated with:

@AutoConfigureWireMock(stubs = {"classpath:/directoryA/mappings", "classpath:/directoryB/mappings"},
        files = {"classpath:/directoryA", "classpath:/directoryB"},
        port = 18081)

This files looks like are recognized correctly by wiremock and all definitions are parsed correctly, but the problem is with assigning correct body file to request: When application try to execute request:

GET http://localhost:18081/service/usa/search?query=123 HTTP/1.1

Then I'm getting error:

java.lang.RuntimeException: java.io.FileNotFoundException: /home/my-project-dir/target/test-classes/directoryA/__files/search-123.json (Not found such file or directory) 

So... The problem is that wiremock search for file defined in bodyFileName part of mapping definition (directoryB/mappings/search-mapping-123.json) in directory directoryA instead of directoryB, from where mapping file was used. If there will be used

/home/my-project-dir/target/test-classes/directoryB/__files/search-123.json

then everything should work fine...

Does somebody had similar problem? I'm not sure if this is a bug in my configuration or in wiremock library.

like image 338
Krzysiek Avatar asked Nov 07 '22 02:11

Krzysiek


1 Answers

Try to exclude the "stubs" and "files" arguments from annotation @AutoConfigureWireMock, and put your mappings/files in src/test/resources, wiremock gets by default from these path

like image 152
Vitor Farias Avatar answered Nov 14 '22 23:11

Vitor Farias