Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make RequestOptions immutable and add builder #44498

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.clientcore.core.http.models.HttpHeaders;
import io.clientcore.core.http.models.HttpMethod;
import io.clientcore.core.http.models.HttpRequest;
import io.clientcore.core.http.models.RequestOptionsBuilder;
import io.clientcore.core.http.paging.PagedIterable;
import io.clientcore.core.http.paging.PagedResponse;
import io.clientcore.core.http.models.RequestOptions;
Expand Down Expand Up @@ -43,7 +44,7 @@ public void testListFoo() {
String uri = "https://example.com";
String firstPageUri = uri + "/foos";
String nextLinkUri = uri + "/foos?page=2";
RequestOptions requestOptions = new RequestOptions().setResponseBodyMode(ResponseBodyMode.DESERIALIZE);
RequestOptions requestOptions = RequestOptions.deserializeResponse();
HttpPipeline pipeline = new HttpPipelineBuilder()
.httpClient(request -> {
String requestUri = request.getUri().toString();
Expand Down Expand Up @@ -87,7 +88,7 @@ public void testListFooListResult() {
String uri = "https://example.com";
String firstPageUri = uri + "/foos";
String nextLinkUri = uri + "/foos?page=2";
RequestOptions requestOptions = new RequestOptions().setResponseBodyMode(ResponseBodyMode.DESERIALIZE);
RequestOptions requestOptions = RequestOptions.deserializeResponse();
HttpPipeline pipeline = new HttpPipelineBuilder()
.httpClient(request -> {
String requestUri = request.getUri().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import io.clientcore.annotation.processor.test.implementation.models.HttpBinJSON;
import io.clientcore.core.http.client.HttpClient;
import io.clientcore.core.http.models.RequestOptions;
import io.clientcore.core.http.models.RequestOptionsBuilder;
import io.clientcore.core.http.models.Response;
import io.clientcore.core.http.models.ResponseBodyMode;
import io.clientcore.core.http.pipeline.HttpPipeline;
import io.clientcore.core.http.pipeline.HttpPipelineBuilder;
import io.clientcore.core.models.binarydata.BinaryData;
Expand All @@ -25,7 +25,6 @@
import org.junit.jupiter.api.Test;

import static io.clientcore.core.http.models.ResponseBodyMode.BUFFER;
import static io.clientcore.core.http.models.ResponseBodyMode.DESERIALIZE;
import static io.clientcore.core.http.models.ResponseBodyMode.IGNORE;
import static io.clientcore.core.http.models.ResponseBodyMode.STREAM;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
Expand Down Expand Up @@ -68,7 +67,7 @@ public void testGetFoo() {

HttpPipeline pipeline = new HttpPipelineBuilder().httpClient((request) -> {
// what is the default response body mode?
request.setRequestOptions(new RequestOptions().setResponseBodyMode(ResponseBodyMode.DESERIALIZE));
request.setRequestOptions(RequestOptions.deserializeResponse());
return new MockHttpResponse(request, 200,
BinaryData.fromString(wireValue));
}).build();
Expand Down Expand Up @@ -98,7 +97,7 @@ public void bodyIsEmptyWhenIgnoreBodyIsSet() throws IOException {

TestInterfaceClientService testInterface = TestInterfaceClientService.getNewInstance(pipeline, null);
assertNotNull(testInterface);
RequestOptions requestOptions = new RequestOptions().setResponseBodyMode(IGNORE);
RequestOptions requestOptions = RequestOptions.ignoreResponse();
HttpBinJSON httpBinJSON = testInterface.putConvenience(getServerUri(false), 42, requestOptions);

assertNull(httpBinJSON);
Expand All @@ -115,7 +114,7 @@ public void bodyIsEmptyWhenIgnoreBodyIsSetForStreamResponse() throws IOException
HttpPipeline pipeline = new HttpPipelineBuilder().httpClient(getHttpClient()).build();
TestInterfaceClientService testInterface = TestInterfaceClientService.getNewInstance(pipeline, null);
assertNotNull(testInterface);
RequestOptions requestOptions = new RequestOptions().setResponseBodyMode(IGNORE);
RequestOptions requestOptions = RequestOptions.ignoreResponse();
HttpBinJSON httpBinJSON = testInterface.postStreamConvenience(getServerUri(false), 42, requestOptions);

assertNull(httpBinJSON);
Expand All @@ -133,7 +132,7 @@ public void bodyIsStreamedWhenResponseBodyModeIndicatesIt() throws IOException {
HttpPipeline pipeline = new HttpPipelineBuilder().httpClient(getHttpClient()).build();
TestInterfaceClientService testInterface = TestInterfaceClientService.getNewInstance(pipeline, null);
assertNotNull(testInterface);
RequestOptions requestOptions = new RequestOptions().setResponseBodyMode(STREAM);
RequestOptions requestOptions = new RequestOptionsBuilder().setResponseBodyMode(STREAM).build();

try (
Response<HttpBinJSON> response = testInterface.postStreamResponse(getServerUri(false), 42, requestOptions)) {
Expand All @@ -148,7 +147,7 @@ public void bodyIsBufferedWhenResponseBodyModeIndicatesIt() throws IOException {
HttpPipeline pipeline = new HttpPipelineBuilder().httpClient(getHttpClient()).build();
TestInterfaceClientService testInterface = TestInterfaceClientService.getNewInstance(pipeline, null);
assertNotNull(testInterface);
RequestOptions requestOptions = new RequestOptions().setResponseBodyMode(BUFFER);
RequestOptions requestOptions = new RequestOptionsBuilder().setResponseBodyMode(BUFFER).build();
HttpBinJSON httpBinJSON = testInterface.postStreamConvenience(getServerUri(false), 42, requestOptions);

assertNotNull(httpBinJSON);
Expand All @@ -166,7 +165,7 @@ public void bodyIsDeserializedWhenResponseBodyModeIndicatesIt() throws IOExcepti
HttpPipeline pipeline = new HttpPipelineBuilder().httpClient(getHttpClient()).build();
TestInterfaceClientService testInterface = TestInterfaceClientService.getNewInstance(pipeline, null);
assertNotNull(testInterface);
RequestOptions requestOptions = new RequestOptions().setResponseBodyMode(DESERIALIZE);
RequestOptions requestOptions = RequestOptions.deserializeResponse();
HttpBinJSON httpBinJSON = testInterface.postStreamConvenience(getServerUri(false), 42, requestOptions);

assertNotNull(httpBinJSON);
Expand Down
Loading
Loading