Skip to content

Commit

Permalink
http-client-java_add-cadl-ranch-tests (#4368)
Browse files Browse the repository at this point in the history
add cadl-ranch tests

main focus is routes
  • Loading branch information
weidongxu-microsoft authored Sep 10, 2024
1 parent 27c263e commit 99abec9
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 26 deletions.
7 changes: 6 additions & 1 deletion packages/http-client-java/emitter/src/code-model-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export class CodeModelBuilder {
},
language: {
default: {
serializedName: arg.name,
serializedName: arg.serializedName,
},
},
// TODO: deprecate this logic of string/url for x-ms-skip-url-encoding
Expand Down Expand Up @@ -1127,6 +1127,11 @@ export class CodeModelBuilder {
explode = true;
break;
}

if (param.explode && !param.collectionFormat) {
style = SerializationStyle.Form;
explode = true;
}
} else if (param.kind === "header") {
const format = param.collectionFormat;
switch (format) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"type": "module",
"scripts": {
"clean": "rimraf ./node_modules/@typespec/http-client-java ./package-lock.json",
"format": "npm run -s prettier -- --write",
"check-format": "npm run prettier -- --check",
"prettier": "prettier --config ./.prettierrc.yaml **/*.tsp",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,19 @@ Response<Void> primitiveSync(@HostParam("endpoint") String endpoint, @QueryParam
@UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 })
@UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 })
@UnexpectedResponseExceptionType(HttpResponseException.class)
Mono<Response<Void>> array(@HostParam("endpoint") String endpoint, @QueryParam("param") String param,
RequestOptions requestOptions, Context context);
Mono<Response<Void>> array(@HostParam("endpoint") String endpoint,
@QueryParam(value = "param", multipleQueryParams = true) List<String> param, RequestOptions requestOptions,
Context context);

@Get("/routes/query/query-continuation/explode/array?fixed=true")
@ExpectedResponses({ 204 })
@UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 })
@UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 })
@UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 })
@UnexpectedResponseExceptionType(HttpResponseException.class)
Response<Void> arraySync(@HostParam("endpoint") String endpoint, @QueryParam("param") String param,
RequestOptions requestOptions, Context context);
Response<Void> arraySync(@HostParam("endpoint") String endpoint,
@QueryParam(value = "param", multipleQueryParams = true) List<String> param, RequestOptions requestOptions,
Context context);

@Get("/routes/query/query-continuation/explode/record?fixed=true")
@ExpectedResponses({ 204 })
Expand Down Expand Up @@ -161,9 +163,8 @@ public Response<Void> primitiveWithResponse(String param, RequestOptions request
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<Void>> arrayWithResponseAsync(List<String> param, RequestOptions requestOptions) {
String paramConverted = param.stream()
.map(paramItemValue -> Objects.toString(paramItemValue, ""))
.collect(Collectors.joining(","));
List<String> paramConverted
= param.stream().map(item -> Objects.toString(item, "")).collect(Collectors.toList());
return FluxUtil
.withContext(context -> service.array(this.client.getEndpoint(), paramConverted, requestOptions, context));
}
Expand All @@ -181,9 +182,8 @@ public Mono<Response<Void>> arrayWithResponseAsync(List<String> param, RequestOp
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<Void> arrayWithResponse(List<String> param, RequestOptions requestOptions) {
String paramConverted = param.stream()
.map(paramItemValue -> Objects.toString(paramItemValue, ""))
.collect(Collectors.joining(","));
List<String> paramConverted
= param.stream().map(item -> Objects.toString(item, "")).collect(Collectors.toList());
return service.arraySync(this.client.getEndpoint(), paramConverted, requestOptions, Context.NONE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,19 @@ Response<Void> primitiveSync(@HostParam("endpoint") String endpoint, @QueryParam
@UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 })
@UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 })
@UnexpectedResponseExceptionType(HttpResponseException.class)
Mono<Response<Void>> array(@HostParam("endpoint") String endpoint, @QueryParam("param") String param,
RequestOptions requestOptions, Context context);
Mono<Response<Void>> array(@HostParam("endpoint") String endpoint,
@QueryParam(value = "param", multipleQueryParams = true) List<String> param, RequestOptions requestOptions,
Context context);

@Get("/routes/query/query-expansion/explode/array")
@ExpectedResponses({ 204 })
@UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 })
@UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 })
@UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 })
@UnexpectedResponseExceptionType(HttpResponseException.class)
Response<Void> arraySync(@HostParam("endpoint") String endpoint, @QueryParam("param") String param,
RequestOptions requestOptions, Context context);
Response<Void> arraySync(@HostParam("endpoint") String endpoint,
@QueryParam(value = "param", multipleQueryParams = true) List<String> param, RequestOptions requestOptions,
Context context);

@Get("/routes/query/query-expansion/explode/record")
@ExpectedResponses({ 204 })
Expand Down Expand Up @@ -161,9 +163,8 @@ public Response<Void> primitiveWithResponse(String param, RequestOptions request
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<Void>> arrayWithResponseAsync(List<String> param, RequestOptions requestOptions) {
String paramConverted = param.stream()
.map(paramItemValue -> Objects.toString(paramItemValue, ""))
.collect(Collectors.joining(","));
List<String> paramConverted
= param.stream().map(item -> Objects.toString(item, "")).collect(Collectors.toList());
return FluxUtil
.withContext(context -> service.array(this.client.getEndpoint(), paramConverted, requestOptions, context));
}
Expand All @@ -181,9 +182,8 @@ public Mono<Response<Void>> arrayWithResponseAsync(List<String> param, RequestOp
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<Void> arrayWithResponse(List<String> param, RequestOptions requestOptions) {
String paramConverted = param.stream()
.map(paramItemValue -> Objects.toString(paramItemValue, ""))
.collect(Collectors.joining(","));
List<String> paramConverted
= param.stream().map(item -> Objects.toString(item, "")).collect(Collectors.toList());
return service.arraySync(this.client.getEndpoint(), paramConverted, requestOptions, Context.NONE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package com._specs_.azure.core.basic;

import com._specs_.azure.core.basic.models.User;
import com._specs_.azure.core.basic.models.UserList;
import com.azure.core.http.HttpClient;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
Expand Down Expand Up @@ -116,6 +117,11 @@ public void testAction() {
})
.expectComplete()
.verify();

UserList userList = syncClient.exportAllUsers("json");
Assertions.assertEquals(2, userList.getUsers().size());
Assertions.assertEquals("Madge", userList.getUsers().get(0).getName());
Assertions.assertEquals("John", userList.getUsers().get(1).getName());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public class PageTests {
public void testListNoModel() {
// verification here is that there is no Page or CustomPage class generated in models

client.listWithPage();
client.listWithPage().stream().count();

client.listWithCustomPageModel();
client.listWithCustomPageModel().stream().count();
}

@Test
Expand All @@ -34,9 +34,7 @@ public void testListTwoModels() {
}

@Test
public void testPage() {
client.listWithPage().forEach(u -> {});

public void testPageRequestBody() {
client.listWithParameters(new ListItemInputBody("Madge"), ListItemInputExtensibleEnum.SECOND).stream().count();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.encode.numeric.models.SafeintAsStringProperty;
import com.encode.numeric.models.Uint32AsStringProperty;
import com.encode.numeric.models.Uint8AsStringProperty;
import org.junit.jupiter.api.Test;

public class StringEncodeTests {
Expand All @@ -16,5 +17,7 @@ public void testIntEncodedAsString() {
client.safeintAsString(new SafeintAsStringProperty(10000000000L));

client.uint32AsStringOptional(new Uint32AsStringProperty().setValue(1));

client.uint8AsString(new Uint8AsStringProperty(255));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.routes;

import org.junit.jupiter.api.Test;

import java.util.List;

public class RouteTests {

@Test
public void testFixed() {
new RoutesClientBuilder().buildClient().fixed();

new RoutesClientBuilder().buildInInterfaceClient().fixed();
}

@Test
public void testPath() {
var client = new RoutesClientBuilder().buildPathParametersClient();

client.templateOnly("a");

client.explicit("a");

client.annotationOnly("a");
}

@Test
public void testPathReservedExpansion() {
var client = new RoutesClientBuilder().buildPathParametersReservedExpansionClient();

// TODO, need enhancement in core or codegen
client.template("foo/bar baz".replace(" ", "%20"));
client.annotation("foo/bar baz".replace(" ", "%20"));
}

@Test
public void testQuery() {
var client = new RoutesClientBuilder().buildQueryParametersClient();

client.templateOnly("a");

client.explicit("a");

client.annotationOnly("a");
}

@Test
public void testQueryExpansionStandard() {
var client = new RoutesClientBuilder().buildQueryParametersQueryExpansionStandardClient();

client.primitive("a");

client.array(List.of("a", "b"));
}

@Test
public void testQueryExpansionContinuationStandard() {
var client = new RoutesClientBuilder().buildQueryParametersQueryContinuationStandardClient();

client.primitive("a");

client.array(List.of("a", "b"));
}

@Test
public void testQueryExpansionExplode() {
var client = new RoutesClientBuilder().buildQueryParametersQueryExpansionExplodeClient();

client.primitive("a");

// client.array(List.of("a", "b"));
}

@Test
public void buildQueryParametersQueryContinuationExplode() {
var client = new RoutesClientBuilder().buildQueryParametersQueryContinuationExplodeClient();

client.primitive("a");

// client.array(List.of("a", "b"));
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
package com.specialheaders.conditionalrequest;

import com.azure.core.util.DateTimeRfc1123;
import org.junit.jupiter.api.Test;

import java.time.OffsetDateTime;

public class ConditionalTests {

private final ConditionalRequestClient client = new ConditionalRequestClientBuilder().buildClient();

private static final OffsetDateTime DATE_TIME = new DateTimeRfc1123("Fri, 26 Aug 2022 14:38:00 GMT").getDateTime();

@Test
public void testConditional() {
client.postIfMatch("\"valid\"");

client.postIfNoneMatch("\"invalid\"");

client.headIfModifiedSince(DATE_TIME);

client.postIfUnmodifiedSince(DATE_TIME);
}
}

0 comments on commit 99abec9

Please sign in to comment.