How can i mock a multiple page response?
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 25/100
Research direction
Start with MockHttpTransport.Builder and the linked SubscriptionsFetcherTest.kt lines 214-220, then trace how mockResponse is consumed across repeated requests. Done means documenting and testing a supported way to simulate the two paginated YouTube responses, including the observed second-request failure.
Written by the indexing model from the issue text.
Description
Hello,
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.
- Dominant language
- Java
- Stars
- 1.4k
- Forks
- 476
- Avg merge
- 10h 47m
- Merged PRs (30d)
- 3
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from googleapis/google-http-java-client
-
Core: Validate header names and values to prevent CRLF injectionPossibly taken @insaf021 claimed this 106 days ago. Openpriority: p3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Core: XmlPullParser processes external DTD entities (XXE) — disable FEATURE_PROCESS_DOCDECL in Xml#createParser()Possibly taken @insaf021 claimed this 106 days ago. Openpriority: p3
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Core: LowLevelHttpResponse not disconnected when HttpResponse construction throws RuntimeExceptionPossibly taken @insaf021 claimed this 106 days ago. Openpriority: p3
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
type: cleanup
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
org.apache.http.conn.ssl.SSLSocketFactory is deprecatedMay be free again A pull request for this issue was closed without being merged. Openpriority: p2 type: cleanup
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
All issues in googleapis/google-http-java-client
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
Difficulty 2/5 Under an hour Newbie friendliness 84/100
cpp-best-practices/project_validator#251 ·
Maintainers usually reply within 1 day
-
backend enhancement
Difficulty 2/5 Half a day Newbie friendliness 70/100
damodharg6/payledger#16 ·
-
[Bug]: An initiative list with no current entry logs an error on every changePossibly taken @dwizard0 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Maintainers usually reply within 1 day