How can i mock a multiple page response?

Đang mở
#1,760 4 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
25/100
Loại issue
Tài liệu
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
java, kotlin
Lĩnh vực
api, testing

Hướng nghiên cứu

Bắt đầu với MockHttpTransport.Builder và các dòng 214-220 được liên kết trong SubscriptionsFetcherTest.kt, sau đó theo dõi cách mockResponse được sử dụng qua các yêu cầu lặp lại. Công việc được xem là hoàn tất khi đã lập tài liệu và kiểm thử một cách được hỗ trợ để mô phỏng hai phản hồi YouTube được phân trang, bao gồm cả lỗi quan sát được ở yêu cầu thứ hai.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

type: feature request

Hello,

Sample repro here: https://github.com/TheBestPessimist/Youtube-Subscriptions-Mailer/blob/2bf38ec27b2841102e3e1431b6d318bb378ccd0a/src/test/kotlin/land/tbp/youtube/SubscriptionsFetcherTest.kt#L214-L220

I am trying to test my integration with the Youtube API.
For that one i'm creating a mockHttpTransport with a mockResponse (or a mockRequest, the same issue presented below arises):

        val mockHttpTransport = MockHttpTransport.Builder()
//            .setLowLevelHttpRequest(mockRequest)
            .setLowLevelHttpResponse(mockResponse)
            .build()

        val youtube = YouTube.Builder(
            mockHttpTransport,
            mockGoogleCredential.jsonFactory,
            mockGoogleCredential
        ).build()

I want to get all my subscriptions, but they are more than 50 so I get a paged response ("nextPageToken": "CAUQAA"), so i need to make a second request to execute:

        val request = youtube
            .subscriptions()
            .list(listOf("snippet", "contentDetails"))
            .setMaxResults(5000)
            .setMine(true)
            .setFields("*")
            .setPrettyPrint(true)

        val responseWhichReturnsTheCorrectSubscriptionListPage: SubscriptionListResponse = request.execute()
        println(responseWhichReturnsTheCorrectSubscriptionListPage)

  val responseWhichThrowsIAE: SubscriptionListResponse = request.setPageToken("CAUQAA").execute()
        println(responseWhichThrowsIAE)

Q1: why can't i return the same mock response multiple times? the second iteration throws java.lang.IllegalArgumentException: no JSON input found
Q2: How can i pass multiple different mockResponses to the transport, to simulate that i have to fetch multiple pages from youtube?

I have already tried searching on Stackoverflow, but i had little success: https://stackoverflow.com/search?tab=votes&q=%5bgoogle-cloud-platform%5d%20%20mock.

Ngôn ngữ chính
Java
Star
1.4k
Fork
476
Merge trung bình
10 giờ 47 phút
Pull request đã merge (30 ngày)
3

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của googleapis/google-http-java-client

Tất cả issue của googleapis/google-http-java-client

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.