WireMock使用错误的__files目录进行多目录映射配置

时间:2018-09-17 22:00:49

标签: java junit spring-cloud wiremock spring-cloud-contract

我正在使用带有spring-cloud-contract-wiremockcom.github.tomakehurst.wiremock依赖项的Spring Boot。 我的Wiremock定义存储在json文件中。像这样:

目录A / 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"
    }
  }
}

目录A / __ files / detail.json

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

目录B / 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"
    }
  }
}

目录B / __ files / search-123.json

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

我有标准的JUnit测试类,它带有以下注释:

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

此文件看起来可以被Wiremock正确识别,并且可以正确解析所有定义,但是问题在于分配正确的主体文件以进行请求: 当应用程序尝试执行请求时:

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

然后我得到了错误:

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

所以...问题是,有线窃听在目录 directoryA而非目录B中的映射定义的bodyFileName部分(目录B / mappings / search-mapping-123.json)中定义文件。 strong>,使用映射文件的位置。如果会使用

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

然后一切正常...

有人有类似的问题吗?我不确定这是我的配置还是Wiremock库中的错误。

1 个答案:

答案 0 :(得分:1)

尝试从注释@AutoConfigureWireMock中排除“存根”和“文件”参数,并将映射/文件放在src / test / resources中,默认情况下,wiremock从这些路径获取