Skip to content

Commit b2e7e7a

Browse files
http-client-java: add missing e2e coverage for newly generated scenarios in http-client-generator-test (#10675)
- [x] Identify which new scenarios from PR #10667 apply to `http-client-generator-clientcore-test` (Azure-flavored packages are excluded) - [x] Add `payload/head/HeadTests.java` in clientcore-test - [x] Add `specialwords/ReservedOperationBodyParamsClientTest.java` in clientcore-test - [x] Compile and run new tests with spector server — 2 tests, 0 failures - [x] Run parallel validation — CodeQL clean; code review comments about "add assertions" are not applicable per established test convention (void-returning calls succeed or throw) --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: weidongxu-microsoft <53292327+weidongxu-microsoft@users.noreply.github.com> Co-authored-by: Weidong Xu <weidxu@microsoft.com>
1 parent 14764fc commit b2e7e7a

9 files changed

Lines changed: 147 additions & 0 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: internal
3+
packages:
4+
- "@typespec/http-client-java"
5+
---
6+
7+
Add e2e tests

.github/instructions/http-client-java.instructions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Typical task: `add e2e test case for <package>, scenario is <url-to-tsp-file>`.
3636

3737
- The execution of `mvn` and `npm` command should be done in the test directory `<repository-root>/packages/http-client-java/generator/http-client-generator-test`.
3838
- Only commit Java files written by you. Do not commit any generated files.
39+
- If no scenario URL provided, search the related files in either https://github.com/microsoft/typespec/tree/main/packages/http-specs/specs or https://github.com/Azure/typespec-azure/tree/main/packages/azure-http-specs/specs
3940

4041
0. Run `pwsh Setup.ps1` in `generator/http-client-generator-test` to set up the environment if not done before.
4142
1. The source files for the generated client under test are located in `generator/http-client-generator-test/src/main/java/<package>`.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package payload.head;
5+
6+
import io.clientcore.core.http.models.HttpHeaderName;
7+
import io.clientcore.core.http.models.RequestContext;
8+
import io.clientcore.core.http.models.Response;
9+
import org.junit.jupiter.api.Assertions;
10+
import org.junit.jupiter.api.Test;
11+
12+
public class HeadTests {
13+
14+
private final HeadClient client = new HeadClientBuilder().buildClient();
15+
16+
@Test
17+
public void testResponseHeaders() {
18+
Response<Void> response = client.contentTypeHeaderInResponseWithResponse(RequestContext.none());
19+
Assertions.assertEquals("text/plain; charset=utf-8",
20+
response.getHeaders().getValue(HttpHeaderName.CONTENT_TYPE));
21+
Assertions.assertEquals("hello", response.getHeaders().getValue(HttpHeaderName.fromString("x-ms-meta")));
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package specialwords;
5+
6+
import java.util.Collections;
7+
import org.junit.jupiter.api.Test;
8+
9+
public class ReservedOperationBodyParamsClientTest {
10+
11+
private final ReservedOperationBodyParamsClient client
12+
= new SpecialWordsClientBuilder().buildReservedOperationBodyParamsClient();
13+
14+
@Test
15+
public void testWithItems() {
16+
client.withItems(Collections.singletonList("item"));
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package azure.clientgenerator.core.clientdoc;
5+
6+
import azure.clientgenerator.core.clientdoc.documentation.models.Plant;
7+
import org.junit.jupiter.api.Assertions;
8+
import org.junit.jupiter.api.Test;
9+
10+
public class ClientDocTests {
11+
12+
private final ClientDocClient client = new ClientDocClientBuilder().buildClient();
13+
14+
@Test
15+
public void testHarvest() {
16+
Plant response = client.harvest(new Plant("Rose", "Rosa"));
17+
Assertions.assertEquals("Rose", response.getName());
18+
Assertions.assertEquals("Rosa", response.getSpecies());
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package azure.clientgenerator.core.responseasbool;
5+
6+
import org.junit.jupiter.api.Assertions;
7+
import org.junit.jupiter.api.Test;
8+
9+
public class ResponseAsBoolTests {
10+
11+
private final ResponseAsBoolClient client = new ResponseAsBoolClientBuilder().buildClient();
12+
13+
@Test
14+
public void testHeadAsBool() {
15+
Assertions.assertTrue(client.exists());
16+
Assertions.assertFalse(client.notExists());
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package azure.specialheaders.conditionalrequest;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
public class ConditionalRequestTests {
9+
10+
private final ConditionalRequestClient client = new ConditionalRequestClientBuilder().buildClient();
11+
12+
@Test
13+
public void testConditionalRequestHeaders() {
14+
client.postIfMatch("\"valid\"");
15+
client.postIfNoneMatch("\"invalid\"");
16+
client.postCustomIfMatch("\"valid\"");
17+
client.postCustomIfNoneMatch("\"invalid\"");
18+
}
19+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package payload.head;
5+
6+
import com.azure.core.http.HttpHeaderName;
7+
import com.azure.core.http.rest.RequestOptions;
8+
import com.azure.core.http.rest.Response;
9+
import org.junit.jupiter.api.Assertions;
10+
import org.junit.jupiter.api.Test;
11+
12+
public class HeadTests {
13+
14+
private final HeadClient client = new HeadClientBuilder().buildClient();
15+
16+
@Test
17+
public void testResponseHeaders() {
18+
Response<Void> response = client.contentTypeHeaderInResponseWithResponse(new RequestOptions());
19+
Assertions.assertEquals("text/plain; charset=utf-8",
20+
response.getHeaders().getValue(HttpHeaderName.CONTENT_TYPE));
21+
Assertions.assertEquals("hello", response.getHeaders().getValue("x-ms-meta"));
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package specialwords;
5+
6+
import java.util.Collections;
7+
import org.junit.jupiter.api.Test;
8+
9+
public class ReservedOperationBodyParamsClientTest {
10+
11+
private final ReservedOperationBodyParamsClient client
12+
= new SpecialWordsClientBuilder().buildReservedOperationBodyParamsClient();
13+
14+
@Test
15+
public void testWithItems() {
16+
client.withItems(Collections.singletonList("item"));
17+
}
18+
}

0 commit comments

Comments
 (0)