[Java RESTEasy client] updating test to use the Java RESTEasy echo api client (#17367) (#17470)

* updating test to use the Java RESTEasy echo api client (#17367)

* regenerated samples

* set source and target to 1.8 to fix workflow failure, adapted parser
This commit is contained in:
Milad
2023-12-26 02:32:51 +01:00
committed by GitHub
parent a67e07e132
commit 8c014372aa
275 changed files with 9144 additions and 19842 deletions

View File

@@ -349,6 +349,114 @@ public class BodyApi {
}
return localVarRequestBuilder;
}
/**
* Test single binary in multipart mime
* Test single binary in multipart mime
* @param myFile (optional)
* @return String
* @throws ApiException if fails to make API call
*/
public String testBodyMultipartFormdataSingleBinary(File myFile) throws ApiException {
ApiResponse<String> localVarResponse = testBodyMultipartFormdataSingleBinaryWithHttpInfo(myFile);
return localVarResponse.getData();
}
/**
* Test single binary in multipart mime
* Test single binary in multipart mime
* @param myFile (optional)
* @return ApiResponse&lt;String&gt;
* @throws ApiException if fails to make API call
*/
public ApiResponse<String> testBodyMultipartFormdataSingleBinaryWithHttpInfo(File myFile) throws ApiException {
HttpRequest.Builder localVarRequestBuilder = testBodyMultipartFormdataSingleBinaryRequestBuilder(myFile);
try {
HttpResponse<InputStream> localVarResponse = memberVarHttpClient.send(
localVarRequestBuilder.build(),
HttpResponse.BodyHandlers.ofInputStream());
if (memberVarResponseInterceptor != null) {
memberVarResponseInterceptor.accept(localVarResponse);
}
try {
if (localVarResponse.statusCode()/ 100 != 2) {
throw getApiException("testBodyMultipartFormdataSingleBinary", localVarResponse);
}
// for plain text response
if (localVarResponse.headers().map().containsKey("Content-Type") &&
"text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) {
java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A");
String responseBodyText = s.hasNext() ? s.next() : "";
return new ApiResponse<String>(
localVarResponse.statusCode(),
localVarResponse.headers().map(),
responseBodyText
);
} else {
throw new RuntimeException("Error! The response Content-Type is supposed to be `text/plain` but it's not: " + localVarResponse);
}
} finally {
}
} catch (IOException e) {
throw new ApiException(e);
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new ApiException(e);
}
}
private HttpRequest.Builder testBodyMultipartFormdataSingleBinaryRequestBuilder(File myFile) throws ApiException {
HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();
String localVarPath = "/body/application/octetstream/single_binary";
localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath));
localVarRequestBuilder.header("Accept", "text/plain");
MultipartEntityBuilder multiPartBuilder = MultipartEntityBuilder.create();
boolean hasFiles = false;
multiPartBuilder.addBinaryBody("my-file", myFile);
hasFiles = true;
HttpEntity entity = multiPartBuilder.build();
HttpRequest.BodyPublisher formDataPublisher;
if (hasFiles) {
Pipe pipe;
try {
pipe = Pipe.open();
} catch (IOException e) {
throw new RuntimeException(e);
}
new Thread(() -> {
try (OutputStream outputStream = Channels.newOutputStream(pipe.sink())) {
entity.writeTo(outputStream);
} catch (IOException e) {
e.printStackTrace();
}
}).start();
formDataPublisher = HttpRequest.BodyPublishers.ofInputStream(() -> Channels.newInputStream(pipe.source()));
} else {
ByteArrayOutputStream formOutputStream = new ByteArrayOutputStream();
try {
entity.writeTo(formOutputStream);
} catch (IOException e) {
throw new RuntimeException(e);
}
formDataPublisher = HttpRequest.BodyPublishers
.ofInputStream(() -> new ByteArrayInputStream(formOutputStream.toByteArray()));
}
localVarRequestBuilder
.header("Content-Type", entity.getContentType().getValue())
.method("POST", formDataPublisher);
if (memberVarReadTimeout != null) {
localVarRequestBuilder.timeout(memberVarReadTimeout);
}
if (memberVarInterceptor != null) {
memberVarInterceptor.accept(localVarRequestBuilder);
}
return localVarRequestBuilder;
}
/**
* Test body parameter(s)
* Test body parameter(s)