Tôi có một khách hàng phun đơn giản:Làm thế nào để thử phản ứng phun-client
val pipeline = sendReceive ~> unmarshal[GoogleApiResult[Elevation]]
val responseFuture = pipeline {Get("http://maps.googleapis.com/maps/api/elevation/jsonlocations=27.988056,86.925278&sensor=false") }
responseFuture onComplete {
case Success(GoogleApiResult(_, Elevation(_, elevation) :: _)) =>
log.info("The elevation of Mt. Everest is: {} m", elevation)
shutdown()
case Failure(error) =>
log.error(error, "Couldn't get elevation")
shutdown()
}
Full mã có thể được tìm thấy here.
Tôi muốn giả lập phản hồi của máy chủ để kiểm tra logic trong các trường hợp Success
và Failure
. Thông tin liên quan duy nhất tôi tìm thấy là here nhưng tôi không thể sử dụng mẫu bánh để thử phương thức sendReceive.
Bất kỳ đề xuất hoặc ví dụ nào sẽ được đánh giá cao.
Chính xác những gì tôi đang tìm kiếm. Cám ơn! – Eleni
Chúng ta chỉ có thể sử dụng 'Future.successful (mockResponse)' thay vì 'Promise.successful (mockResponse) .future'. Tôi cũng sẽ thay 'sendAndReceive' thành đối số' ElevationClient' thay vì sử dụng ghi đè. Sau đó, chúng ta sẽ chuyển qua một mô hình 'Function2 [HttpRequest, Future [HttpResponse]]' cho 'sendAndReceive' của chúng ta. – Alden