问题描述 投票:0回答:0

https://shortpixel.com/knowledge-base/article/shortpixel-aptive-images-images-api-parameters/
  • 对于最简单的读取域API,
  • https://kb.shortpixel.com/knowledge-base/article/shortpixels/shortpixels-cdn-api-endpoints/#1-toc-title
  • 要检查域的状态及其配额,您应该使用以下内容。

https://no-cdn.shortpixel.ai/read-domain/example.com

状态可以是

2=全部OK

1=学分几乎筋疲力尽

-1 =学分耗尽

-2 =一段时间以前使用的信用(可以使用例如停止使用CDN链接)
  • -3 =域无法到达
  • I为其创建了以下客户端代码。
  • val domainResult = noCdnWebClient .get().uri(readDomainPath) .awaitExchange { if (it.statusCode().isError) { throw ImageOptimizerException("Failed to check domain $domain on shortpixel, ${it.awaitBody<String>()}") } it.awaitBody(Int::class) }
  • 这里有一些特殊性。我将上述代码放入检查域存在的方法中。如果域不绑定到apikey,请致电
  • @PostConstruct
以绑定它。
当使用以下存根模拟请求/响应时。

/add-domain

当运行测试时,我得到了例外信息,例如:

stubFor( get(urlPathEqualTo(readDomainPath)) .willReturn( aResponse() .withStatus(200) .withBody("-3") ) ) 我担心当组件初始化时,WireMock服务器还没有准备好。

	
问题是在运行测试时,在Reetemock准备就绪之前调用了称为远程API的bean bean。
最简单的方法是稍微调整测试代码,使bean在测试中不受弹簧应用程序上下文管理,然后手动创建一个实例。
HTTP GET http://localhost:9000/read-domain/localhost Response 404 NOT_FOUND Decoded "No response could be served as there are no stub mappings in this WireMock instance."

spring-boot wiremock
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.