Skip to content

Commit a7d6717

Browse files
committed
feat: speakeasy configure tests
1 parent 577112f commit a7d6717

File tree

684 files changed

+1953778
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

684 files changed

+1953778
-3
lines changed

.github/workflows/sdk_test.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Test
2+
permissions:
3+
checks: write
4+
contents: write
5+
pull-requests: write
6+
statuses: write
7+
id-token: write
8+
"on":
9+
pull_request:
10+
branches:
11+
- main
12+
paths:
13+
- '**'
14+
workflow_dispatch:
15+
inputs:
16+
target:
17+
description: Provided SDK target to run tests for, (all) is valid
18+
type: string
19+
jobs:
20+
test:
21+
uses: speakeasy-api/sdk-generation-action/.github/workflows/sdk-test.yaml@v15
22+
with:
23+
target: ${{ github.event.inputs.target || 'glean' }}
24+
secrets:
25+
github_access_token: ${{ secrets.GITHUB_TOKEN }}
26+
speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }}

.speakeasy/gen.lock

Lines changed: 775 additions & 3 deletions
Large diffs are not rendered by default.

.speakeasy/gen.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ generation:
1616
auth:
1717
oAuth2ClientCredentialsEnabled: true
1818
oAuth2PasswordEnabled: true
19+
tests:
20+
generateNewTests: true
21+
skipResponseBodyAssertions: false
1922
java:
2023
version: 0.5.1
2124
additionalDependencies: []

.speakeasy/testfiles/example.file

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello world

.speakeasy/tests.arazzo.yaml

Lines changed: 665753 additions & 0 deletions
Large diffs are not rendered by default.

.speakeasy/workflow.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ targets:
2121
labelOverride:
2222
fixedValue: Java (API Client)
2323
blocking: false
24+
testing:
25+
enabled: true

build.gradle

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ plugins {
1515
id 'maven-publish'
1616
id 'signing'
1717
id 'cl.franciscosolis.sonatype-central-upload' version '1.0.3'
18+
id "com.adarshr.test-logger" version "3.2.0"
1819
}
1920

2021
compileJava.options.encoding = "UTF-8"
@@ -147,6 +148,45 @@ if (!project.hasProperty('skip.signing')) {
147148
}
148149

149150

151+
tasks.named('test') {
152+
// Use JUnit Platform for unit tests.
153+
useJUnitPlatform()
154+
}
155+
156+
testlogger {
157+
showStandardStreams true
158+
}
159+
160+
test {
161+
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
162+
finalizedBy 'mergeJUnitReports'
163+
}
164+
165+
configurations {
166+
antJUnit
167+
}
168+
169+
task mergeJUnitReports {
170+
ext {
171+
resultsDir = file("$buildDir/test-results/test")
172+
targetDir = file(".speakeasy/reports")
173+
}
174+
175+
doLast {
176+
ant.taskdef(
177+
name: 'junitreport',
178+
classname: 'org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator',
179+
classpath: configurations.antJUnit.asPath
180+
)
181+
182+
mkdir targetDir
183+
184+
ant.junitreport(todir: targetDir, tofile: 'tests.xml') {
185+
fileset(dir: resultsDir, includes: 'TEST-*.xml')
186+
}
187+
}
188+
}
189+
150190

151191
dependencies {
152192
api 'com.fasterxml.jackson.core:jackson-annotations:2.18.2'
@@ -155,6 +195,10 @@ dependencies {
155195
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.18.2'
156196
api('org.openapitools:jackson-databind-nullable:0.2.6') {exclude group: 'com.fasterxml.jackson.core', module: 'jackson-databind'}
157197
implementation 'commons-io:commons-io:2.18.0'
198+
testImplementation 'org.junit.jupiter:junit-jupiter:5.11.4'
199+
testImplementation 'org.mockito:mockito-core:5.14.2'
200+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.11.4'
201+
antJUnit 'org.apache.ant:ant-junit:1.9.7'
158202
}
159203

160204
apply from: 'build-extras.gradle'
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3+
*/
4+
package com.glean.api_client.glean_api_client;
5+
6+
import static org.junit.jupiter.api.Assertions.assertEquals;
7+
8+
import com.glean.api_client.glean_api_client.models.components.Activity;
9+
import com.glean.api_client.glean_api_client.models.components.ActivityEvent;
10+
import com.glean.api_client.glean_api_client.models.components.ActivityEventAction;
11+
import com.glean.api_client.glean_api_client.models.components.ActivityEventParams;
12+
import com.glean.api_client.glean_api_client.models.components.Event;
13+
import com.glean.api_client.glean_api_client.models.components.Feedback;
14+
import com.glean.api_client.glean_api_client.models.operations.ActivityResponse;
15+
import com.glean.api_client.glean_api_client.models.operations.FeedbackResponse;
16+
import com.glean.api_client.glean_api_client.utils.Utils;
17+
import java.lang.Exception;
18+
import java.time.OffsetDateTime;
19+
import java.util.List;
20+
import org.junit.jupiter.api.Test;
21+
22+
public class ActivityTests {
23+
24+
@Test
25+
public void testActivity_Activity() throws Exception {
26+
27+
var testHttpClient = Utils.createTestHTTPClient("activity");
28+
Glean sdk = Glean.builder()
29+
.serverURL(Utils.environmentVariable("TEST_SERVER_URL", "http://localhost:18080"))
30+
.client(testHttpClient)
31+
.apiToken("<YOUR_BEARER_TOKEN_HERE>")
32+
.build();
33+
34+
Activity req = Activity.builder()
35+
.events(List.of(
36+
ActivityEvent.builder()
37+
.action(ActivityEventAction.HISTORICAL_VIEW)
38+
.timestamp(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
39+
.url("https://example.com/")
40+
.build(),
41+
ActivityEvent.builder()
42+
.action(ActivityEventAction.SEARCH)
43+
.timestamp(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
44+
.url("https://example.com/search?q=query")
45+
.params(ActivityEventParams.builder()
46+
.query("query")
47+
.build())
48+
.build(),
49+
ActivityEvent.builder()
50+
.action(ActivityEventAction.VIEW)
51+
.timestamp(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
52+
.url("https://example.com/")
53+
.params(ActivityEventParams.builder()
54+
.duration(20L)
55+
.referrer("https://example.com/document")
56+
.build())
57+
.build()))
58+
.build();
59+
60+
ActivityResponse res = sdk.client().activity().report()
61+
.request(req)
62+
.call();
63+
assertEquals(200, res.statusCode());
64+
}
65+
66+
@Test
67+
public void testActivity_Feedback() throws Exception {
68+
69+
var testHttpClient = Utils.createTestHTTPClient("feedback");
70+
Glean sdk = Glean.builder()
71+
.serverURL(Utils.environmentVariable("TEST_SERVER_URL", "http://localhost:18080"))
72+
.client(testHttpClient)
73+
.apiToken("<YOUR_BEARER_TOKEN_HERE>")
74+
.build();
75+
76+
FeedbackResponse res = sdk.client().activity().feedback()
77+
.feedback1(Feedback.builder()
78+
.trackingTokens(List.of(
79+
"trackingTokens"))
80+
.event(Event.VIEW)
81+
.build())
82+
.call();
83+
assertEquals(200, res.statusCode());
84+
}
85+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3+
*/
4+
package com.glean.api_client.glean_api_client;
5+
6+
import static org.junit.jupiter.api.Assertions.assertEquals;
7+
8+
import com.glean.api_client.glean_api_client.models.components.Agent;
9+
import com.glean.api_client.glean_api_client.models.components.AgentCapabilities;
10+
import com.glean.api_client.glean_api_client.models.components.AgentRunCreate;
11+
import com.glean.api_client.glean_api_client.models.components.AgentRunWaitResponse;
12+
import com.glean.api_client.glean_api_client.models.components.AgentSchemas;
13+
import com.glean.api_client.glean_api_client.models.components.InputSchema;
14+
import com.glean.api_client.glean_api_client.models.components.OutputSchema;
15+
import com.glean.api_client.glean_api_client.models.components.SearchAgentsRequest;
16+
import com.glean.api_client.glean_api_client.models.operations.CreateAndWaitRunResponse;
17+
import com.glean.api_client.glean_api_client.models.operations.GetAgentResponse;
18+
import com.glean.api_client.glean_api_client.models.operations.GetAgentSchemasResponse;
19+
import com.glean.api_client.glean_api_client.models.operations.SearchAgentsResponse;
20+
import com.glean.api_client.glean_api_client.utils.Utils;
21+
import java.lang.Exception;
22+
import org.junit.jupiter.api.Assumptions;
23+
import org.junit.jupiter.api.Test;
24+
25+
public class AgentsTests {
26+
27+
@Test
28+
public void testAgents_GetAgent() throws Exception {
29+
30+
var testHttpClient = Utils.createTestHTTPClient("getAgent");
31+
Glean sdk = Glean.builder()
32+
.serverURL(Utils.environmentVariable("TEST_SERVER_URL", "http://localhost:18080"))
33+
.client(testHttpClient)
34+
.apiToken("<YOUR_BEARER_TOKEN_HERE>")
35+
.build();
36+
37+
GetAgentResponse res = sdk.client().agents().retrieve()
38+
.agentId("<id>")
39+
.call();
40+
assertEquals(200, res.statusCode());
41+
assertEquals(
42+
Agent.builder()
43+
.agentId("<id>")
44+
.name("<value>")
45+
.capabilities(AgentCapabilities.builder()
46+
.build())
47+
.build(),
48+
res.agent().get());
49+
}
50+
51+
@Test
52+
public void testAgents_GetAgentSchemas() throws Exception {
53+
54+
var testHttpClient = Utils.createTestHTTPClient("getAgentSchemas");
55+
Glean sdk = Glean.builder()
56+
.serverURL(Utils.environmentVariable("TEST_SERVER_URL", "http://localhost:18080"))
57+
.client(testHttpClient)
58+
.apiToken("<YOUR_BEARER_TOKEN_HERE>")
59+
.build();
60+
61+
GetAgentSchemasResponse res = sdk.client().agents().retrieveSchemas()
62+
.agentId("<id>")
63+
.call();
64+
assertEquals(200, res.statusCode());
65+
assertEquals(
66+
AgentSchemas.builder()
67+
.agentId("<id>")
68+
.inputSchema(InputSchema.builder()
69+
.build())
70+
.outputSchema(OutputSchema.builder()
71+
.build())
72+
.build(),
73+
res.agentSchemas().get());
74+
}
75+
76+
@Test
77+
public void testAgents_SearchAgents() throws Exception {
78+
79+
var testHttpClient = Utils.createTestHTTPClient("searchAgents");
80+
Glean sdk = Glean.builder()
81+
.serverURL(Utils.environmentVariable("TEST_SERVER_URL", "http://localhost:18080"))
82+
.client(testHttpClient)
83+
.apiToken("<YOUR_BEARER_TOKEN_HERE>")
84+
.build();
85+
86+
SearchAgentsRequest req = SearchAgentsRequest.builder()
87+
.build();
88+
89+
SearchAgentsResponse res = sdk.client().agents().list()
90+
.request(req)
91+
.call();
92+
assertEquals(200, res.statusCode());
93+
assertEquals(
94+
com.glean.api_client.glean_api_client.models.components.SearchAgentsResponse.builder()
95+
.build(),
96+
res.searchAgentsResponse().get());
97+
}
98+
99+
@Test
100+
public void testAgents_CreateAndStreamRun() throws Exception {
101+
Assumptions.assumeTrue(false, "incomplete test found please make sure to address the following errors: [`workflow step createAndStreamRun.test referencing operation createAndStreamRun is not currently supported`]");
102+
}
103+
104+
@Test
105+
public void testAgents_CreateAndWaitRun() throws Exception {
106+
107+
var testHttpClient = Utils.createTestHTTPClient("createAndWaitRun");
108+
Glean sdk = Glean.builder()
109+
.serverURL(Utils.environmentVariable("TEST_SERVER_URL", "http://localhost:18080"))
110+
.client(testHttpClient)
111+
.apiToken("<YOUR_BEARER_TOKEN_HERE>")
112+
.build();
113+
114+
AgentRunCreate req = AgentRunCreate.builder()
115+
.agentId("<id>")
116+
.build();
117+
118+
CreateAndWaitRunResponse res = sdk.client().agents().run()
119+
.request(req)
120+
.call();
121+
assertEquals(200, res.statusCode());
122+
assertEquals(
123+
AgentRunWaitResponse.builder()
124+
.build(),
125+
res.agentRunWaitResponse().get());
126+
}
127+
}

0 commit comments

Comments
 (0)