当前位置: 首页 > news >正文

做网站一班需要多少钱win主机wordpress

做网站一班需要多少钱,win主机wordpress,管理咨询的主体包括哪些,梵克雅宝中国官网旗舰店WebClient引用其Java文档是Spring Framework的 非阻塞#xff0c;反应式客户端执行HTTP请求#xff0c;通过底层HTTP客户端库#xff08;如Reactor Netty#xff09;公开流利的#xff0c;反应式API 。 在我当前的项目中#xff0c;我广泛使用WebClient进行服务到服务… WebClient引用其Java文档是Spring Framework的 非阻塞反应式客户端执行HTTP请求通过底层HTTP客户端库如Reactor Netty公开流利的反应式API 。 在我当前的项目中我广泛使用WebClient进行服务到服务的调用并发现它是一个了不起的API并且我喜欢使用Fluent接口。 考虑一个返回“城市”列表的远程服务。 使用WebClient的代码如下所示 ... import org.springframework.http.MediaType import org.springframework.web.reactive.function.client.WebClient import org.springframework.web.reactive.function.client.bodyToFlux import org.springframework.web.util.UriComponentsBuilder import reactor.core.publisher.Flux import java.net.URI CitiesClient( class CitiesClient( private val webClientBuilder: WebClient.Builder, private val citiesBaseUrl: String ) { fun getCities(): FluxCity { val buildUri: URI UriComponentsBuilder .fromUriString(citiesBaseUrl) .path( /cities ) .build() .encode() .toUri() val webClient: WebClient this .webClientBuilder.build() return webClient.get() .uri(buildUri) .accept(MediaType.APPLICATION_JSON) .exchange() .flatMapMany { clientResponse - clientResponse.bodyToFluxCity() } } } 但是很难测试使用WebClient的客户端。 在本文中我将介绍使用WebClient和干净的解决方案测试客户端的挑战。 模拟WebClient的挑战 要对“ CitiesClient”类进行有效的单元测试将需要模拟WebClient以及流利的接口链中的每个方法调用包括 val mockWebClientBuilder: WebClient.Builder mock() val mockWebClient: WebClient mock() whenever(mockWebClientBuilder.build()).thenReturn(mockWebClient) val mockRequestSpec: WebClient.RequestBodyUriSpec mock() whenever(mockWebClient.get()).thenReturn(mockRequestSpec) val mockRequestBodySpec: WebClient.RequestBodySpec mock() whenever(mockRequestSpec.uri(anyURI())).thenReturn(mockRequestBodySpec) whenever(mockRequestBodySpec.accept(any())).thenReturn(mockRequestBodySpec) val citiesJson: String this .javaClass.getResource( /sample-cities.json ).readText() val clientResponse: ClientResponse ClientResponse .create(HttpStatus.OK) .header( Content-Type , application/json ) .body(citiesJson).build() whenever(mockRequestBodySpec.exchange()).thenReturn(Mono.just(clientResponse)) val citiesClient CitiesClient(mockWebClientBuilder, http://somebaseurl ) val cities: FluxCity citiesClient.getCities() 这使得测试非常不稳定因为调用顺序的任何更改都将导致需要记录新的模拟。 使用真实端点进行测试 一种行之有效的方法是启动行为类似于客户端目标的真实服务器。 okhttp库和WireMock中的两个模拟服务器运行得很好它们是模拟服务器。 Wiremock的示例如下所示 import com.github.tomakehurst.wiremock.WireMockServer import com.github.tomakehurst.wiremock.client.WireMock import com.github.tomakehurst.wiremock.core.WireMockConfiguration import org.bk.samples.model.City import org.junit.jupiter.api.AfterAll import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.Test import org.springframework.http.HttpStatus import org.springframework.web.reactive.function.client.WebClient import reactor.core.publisher.Flux import reactor.test.StepVerifier WiremockWebClientTest { class WiremockWebClientTest { Test fun testARemoteCall() { val citiesJson this .javaClass.getResource( /sample-cities.json ).readText() WIREMOCK_SERVER.stubFor(WireMock.get(WireMock.urlMatching( /cities )) .withHeader( Accept , WireMock.equalTo( application/json )) .willReturn(WireMock.aResponse() .withStatus(HttpStatus.OK.value()) .withHeader( Content-Type , application/json ) .withBody(citiesJson))) val citiesClient CitiesClient(WebClient.builder(), http://localhost: ${WIREMOCK_SERVER.port()} ) val cities: FluxCity citiesClient.getCities()         StepVerifier .create(cities) .expectNext(City(1L, Portland , USA , 1_600_000L)) .expectNext(City(2L, Seattle , USA , 3_200_000L)) .expectNext(City(3L, SFO , USA , 6_400_000L)) .expectComplete() .verify() } companion object { private val WIREMOCK_SERVER WireMockServer(WireMockConfiguration.wireMockConfig().dynamicPort()) BeforeAll JvmStatic fun beforeAll() { WIREMOCK_SERVER.start() } AfterAll JvmStatic fun afterAll() { WIREMOCK_SERVER.stop() } } } 在这里服务器是通过随机端口启动的然后注入行为然后针对该服务器测试客户端并进行验证。 这种方法有效并且在模拟此行为时不会与WebClient的内部混淆但是从技术上讲这是一个集成测试并且比纯单元测试执行起来要慢。 通过使远程呼叫短路来进行单元测试 我最近使用的一种方法是使用ExchangeFunction短路远程调用。 ExchangeFunction代表进行远程调用的实际机制可以用一种以测试期望的方式响应的方式代替ExchangeFunction import org.junit.jupiter.api.Test import org.springframework.http.HttpStatus import org.springframework.web.reactive.function.client.ClientResponse import org.springframework.web.reactive.function.client.ExchangeFunction import org.springframework.web.reactive.function.client.WebClient import reactor.core.publisher.Flux import reactor.core.publisher.Mono import reactor.test.StepVerifier CitiesWebClientTest { class CitiesWebClientTest { Test fun testCleanResponse() { val citiesJson: String this .javaClass.getResource( /sample-cities.json ).readText() val clientResponse: ClientResponse ClientResponse .create(HttpStatus.OK) .header( Content-Type , application/json ) .body(citiesJson).build() val shortCircuitingExchangeFunction ExchangeFunction { Mono.just(clientResponse) } val webClientBuilder: WebClient.Builder WebClient.builder().exchangeFunction(shortCircuitingExchangeFunction) val citiesClient CitiesClient(webClientBuilder, http://somebaseurl ) val cities: FluxCity citiesClient.getCities() StepVerifier .create(cities) .expectNext(City(1L, Portland , USA , 1_600_000L)) .expectNext(City(2L, Seattle , USA , 3_200_000L)) .expectNext(City(3L, SFO , USA , 6_400_000L)) .expectComplete() .verify() } } WebClient注入了ExchangeFunction该函数仅返回具有远程服务器预期行为的响应。 这使整个远程呼叫短路并允许对客户端进行全面测试。 这种方法取决于对WebClient内部的一点了解。 虽然这是一个不错的妥协但是它的运行速度比使用WireMock进行的测试要快得多。 但是这种方法不是原始的我已经基于用于测试WebClient本身的一些测试来建立此测试例如 此处的 结论 我个人更喜欢最后一种方法它使我能够为使用WebClient进行远程调用的客户端编写相当全面的单元测试。 我的项目具有完整的工作样本 在这里 。 翻译自: https://www.javacodegeeks.com/2019/09/unit-test-springs-webclient.html
http://wiki.neutronadmin.com/news/335014/

相关文章:

  • 做美食网站的背景aaa免费服务器
  • 地方志网站建设自查报告沈阳建设工程信息网举报
  • 怎么做全息网站百度竞价排名什么意思
  • 温州手机网站制作哪家便宜深网站建设
  • 网站字体大小合适新余网站开发
  • 中小型网站建设流程织梦商城模板
  • 写代码做网站需要多好的cpu河北省工程建设造价信息网
  • 中国廉政文化建设网站帮别人做网站交税
  • 聊城做手机网站铜川网站seo
  • 网站开发php jsp单位网站平台建设汇报
  • 佛山网站建设专业定制邵阳市网站建设
  • 徐州网站建设报价wordpress汉字后缀图片不显示
  • 沧州市做网站的网站侵权怎么做公证或证据保存
  • 保险做的好的网站有哪些内容深圳市住房和建设局网站下载
  • 简单html网站模板东莞seo报价
  • 手机能制作网站吗wordpress seo模板
  • 专业做网站电话怎样在网上注册免费的网站
  • 如何入侵自己做的网站北京网站seo排名优化
  • dw做的网站有缝怎么办旅行社 网站系统
  • 企业网站首页设计原则有没有做微场景的网站
  • 游戏是怎么做的视频网站wordpress内容主题模板下载失败
  • 公司网站 域名 cn com淮安注册公司
  • 网站设计外包合同网站内容建设注意事项
  • 企业网站备案 网站服务内容自适应网站模板
  • 怎么做监控直播网站姜堰区住房和城乡建设局网站
  • 北京网站建设公司排行榜自己写小说的网站
  • 剑阁县规划和建设局网站php开发网站怎么做
  • 网站数据搬家网站建设的费用计入
  • 建网站要先建什么软件外包服务内容
  • 微建网站电子商务网站模板html