Skip to content

Commit 9a0d85a

Browse files
committed
Add generated conformance event canary
1 parent 84862fb commit 9a0d85a

2 files changed

Lines changed: 285 additions & 32 deletions

File tree

Lines changed: 285 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
/*
2+
* Code generated from Transloadit API2 TUS protocol contracts; DO NOT EDIT.
3+
* If it looks wrong, please report the issue instead of editing this file by hand;
4+
* the source fix belongs in the protocol contract generator so all TUS clients stay in sync.
5+
*/
6+
7+
package io.tus.java.client;
8+
9+
import org.junit.Test;
10+
11+
import static org.junit.Assert.assertArrayEquals;
12+
import static org.junit.Assert.assertEquals;
13+
14+
/**
15+
* Tests generated TUS client conformance event fixtures.
16+
*/
17+
public class TestGeneratedTusConformanceEvents {
18+
private static final GeneratedTusEventCanaryCase[] CASES =
19+
new GeneratedTusEventCanaryCase[] {
20+
new GeneratedTusEventCanaryCase(
21+
"singleUploadLifecycle",
22+
"singleUploadLifecycle",
23+
new String[] {
24+
"fingerprint:contract-single-fingerprint",
25+
"upload-url-available",
26+
"url-storage-add:contract-single-fingerprint:https://tus.io/uploads/generated-contract",
27+
"progress:0:11",
28+
"progress:11:11",
29+
"chunk-complete:11:11:11",
30+
"success",
31+
"source-close",
32+
}
33+
),
34+
new GeneratedTusEventCanaryCase(
35+
"creationWithUpload",
36+
"creationWithUpload",
37+
new String[] {
38+
"progress:0:11",
39+
"progress:11:11",
40+
"upload-url-available",
41+
"success",
42+
"source-close",
43+
}
44+
),
45+
new GeneratedTusEventCanaryCase(
46+
"creationWithUpload",
47+
"creationWithUploadPartialChunk",
48+
new String[] {
49+
"progress:0:11",
50+
"progress:5:11",
51+
"upload-url-available",
52+
"progress:5:11",
53+
"progress:10:11",
54+
"chunk-complete:5:10:11",
55+
"progress:10:11",
56+
"progress:11:11",
57+
"chunk-complete:1:11:11",
58+
"success",
59+
"source-close",
60+
}
61+
),
62+
new GeneratedTusEventCanaryCase(
63+
"protocolVersionSelection",
64+
"ietfDraft05CreationWithUpload",
65+
new String[] {
66+
"progress:0:11",
67+
"progress:11:11",
68+
"upload-url-available",
69+
"success",
70+
"source-close",
71+
}
72+
),
73+
new GeneratedTusEventCanaryCase(
74+
"protocolVersionSelection",
75+
"ietfDraft03ResumeWithoutKnownLength",
76+
new String[] {
77+
"upload-url-available",
78+
"progress:5:11",
79+
"progress:11:11",
80+
"chunk-complete:6:11:11",
81+
"success",
82+
"source-close",
83+
}
84+
),
85+
new GeneratedTusEventCanaryCase(
86+
"resumeUpload",
87+
"resumeFromPreviousUpload",
88+
new String[] {
89+
"fingerprint:contract-resume-fingerprint",
90+
"url-storage-find:contract-resume-fingerprint:1",
91+
"fingerprint:contract-resume-fingerprint",
92+
"upload-url-available",
93+
"progress:5:11",
94+
"progress:11:11",
95+
"chunk-complete:6:11:11",
96+
"url-storage-remove:tus::contract-resume-fingerprint::1337",
97+
"success",
98+
"source-close",
99+
}
100+
),
101+
new GeneratedTusEventCanaryCase(
102+
"relativeLocationResolution",
103+
"relativeLocationResolution",
104+
new String[] {
105+
"upload-url-available",
106+
"progress:0:11",
107+
"progress:11:11",
108+
"chunk-complete:11:11:11",
109+
"success",
110+
"source-close",
111+
}
112+
),
113+
new GeneratedTusEventCanaryCase(
114+
"inputSources",
115+
"arrayBufferInput",
116+
new String[] {
117+
"source-open:array-buffer:11",
118+
"success",
119+
"source-close",
120+
}
121+
),
122+
new GeneratedTusEventCanaryCase(
123+
"inputSources",
124+
"arrayBufferViewInput",
125+
new String[] {
126+
"source-open:array-buffer-view:11",
127+
"success",
128+
"source-close",
129+
}
130+
),
131+
new GeneratedTusEventCanaryCase(
132+
"inputSources",
133+
"webReadableStreamInput",
134+
new String[] {
135+
"source-open:web-readable-stream:null",
136+
"success",
137+
"source-close",
138+
}
139+
),
140+
new GeneratedTusEventCanaryCase(
141+
"inputSources",
142+
"nodeReadableStreamInput",
143+
new String[] {
144+
"source-open:node-readable-stream:null",
145+
"success",
146+
"source-close",
147+
}
148+
),
149+
new GeneratedTusEventCanaryCase(
150+
"inputSources",
151+
"nodePathInput",
152+
new String[] {
153+
"source-open:node-path-reference:11",
154+
"success",
155+
"source-close",
156+
}
157+
),
158+
new GeneratedTusEventCanaryCase(
159+
"deferredLengthUpload",
160+
"deferredLengthUpload",
161+
new String[] {
162+
"upload-url-available",
163+
"progress:0:11",
164+
"progress:11:11",
165+
"chunk-complete:11:11:11",
166+
"success",
167+
"source-close",
168+
}
169+
),
170+
new GeneratedTusEventCanaryCase(
171+
"parallelUploadConcat",
172+
"parallelUploadConcat",
173+
new String[] {
174+
"progress:5:11",
175+
"chunk-complete:5:5:11",
176+
"progress:11:11",
177+
"chunk-complete:6:11:11",
178+
}
179+
),
180+
new GeneratedTusEventCanaryCase(
181+
"parallelUploadConcat",
182+
"parallelUploadAbortCleanup",
183+
new String[] {
184+
"request-abort:3",
185+
}
186+
),
187+
new GeneratedTusEventCanaryCase(
188+
"retryOffsetRecovery",
189+
"retryPatchAfterOffsetRecovery",
190+
new String[] {
191+
"should-retry:0:true",
192+
"retry-schedule:0",
193+
"should-retry:0:true",
194+
"retry-schedule:0",
195+
}
196+
),
197+
new GeneratedTusEventCanaryCase(
198+
"requestLifecycleHooks",
199+
"requestLifecycleHooks",
200+
new String[] {
201+
"before-request:0",
202+
"after-response:0",
203+
"success",
204+
"source-close",
205+
}
206+
),
207+
new GeneratedTusEventCanaryCase(
208+
"abortUpload",
209+
"abortUpload",
210+
new String[] {
211+
"request-abort:0",
212+
}
213+
),
214+
new GeneratedTusEventCanaryCase(
215+
"abortUpload",
216+
"abortUploadAfterStoredUrl",
217+
new String[] {
218+
"request-abort:1",
219+
}
220+
),
221+
};
222+
223+
/**
224+
* Verifies generated feature-level event keys survive in the Java fixture.
225+
*/
226+
@Test
227+
public void testGeneratedScenarioEventKeys() {
228+
for (GeneratedTusEventCanaryCase testCase : CASES) {
229+
GeneratedTusProtocolContract.GeneratedTusClientConformanceScenario scenario =
230+
findScenario(testCase.scenarioId);
231+
GeneratedTusProtocolContract.GeneratedTusClientFeature feature =
232+
findFeature(testCase.featureId);
233+
234+
assertEquals(testCase.featureId, scenario.featureId);
235+
assertContains(feature.conformance.scenarioIds, scenario.scenarioId);
236+
assertArrayEquals(testCase.eventKeys, scenario.eventKeys);
237+
}
238+
}
239+
240+
private static GeneratedTusProtocolContract.GeneratedTusClientFeature findFeature(
241+
String featureId) {
242+
for (GeneratedTusProtocolContract.GeneratedTusClientFeature feature
243+
: GeneratedTusProtocolContract.CLIENT_FEATURES) {
244+
if (feature.featureId.equals(featureId)) {
245+
return feature;
246+
}
247+
}
248+
249+
throw new AssertionError("Missing generated TUS client feature: " + featureId);
250+
}
251+
252+
private static GeneratedTusProtocolContract.GeneratedTusClientConformanceScenario findScenario(
253+
String scenarioId) {
254+
for (GeneratedTusProtocolContract.GeneratedTusClientConformanceScenario scenario
255+
: GeneratedTusProtocolContract.CLIENT_CONFORMANCE_SCENARIOS) {
256+
if (scenario.scenarioId.equals(scenarioId)) {
257+
return scenario;
258+
}
259+
}
260+
261+
throw new AssertionError("Missing generated TUS client scenario: " + scenarioId);
262+
}
263+
264+
private static void assertContains(String[] values, String expected) {
265+
for (String value : values) {
266+
if (value.equals(expected)) {
267+
return;
268+
}
269+
}
270+
271+
throw new AssertionError("Missing generated value: " + expected);
272+
}
273+
274+
private static final class GeneratedTusEventCanaryCase {
275+
final String featureId;
276+
final String scenarioId;
277+
final String[] eventKeys;
278+
279+
GeneratedTusEventCanaryCase(String featureId, String scenarioId, String[] eventKeys) {
280+
this.featureId = featureId;
281+
this.scenarioId = scenarioId;
282+
this.eventKeys = eventKeys;
283+
}
284+
}
285+
}

src/test/java/io/tus/java/client/TestGeneratedTusProtocolContract.java

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,6 @@ public void testSingleUploadLifecycleFeatureReferencesProtocolOperations() {
7070
assertContains(feature.primitives, "emit-progress");
7171
}
7272

73-
/**
74-
* Verifies generated high-level conformance scenarios expose projected event keys.
75-
*/
76-
@Test
77-
public void testConformanceScenarioCarriesProjectedEventKeys() {
78-
GeneratedTusProtocolContract.GeneratedTusClientFeature feature =
79-
findFeature("creationWithUpload");
80-
GeneratedTusProtocolContract.GeneratedTusClientConformanceScenario scenario =
81-
findScenario("creationWithUploadPartialChunk");
82-
83-
assertContains(feature.conformance.scenarioIds, scenario.scenarioId);
84-
assertEquals("creation-with-upload-partial-chunk", scenario.behavior);
85-
assertEquals("success", scenario.completionKind);
86-
assertContains(scenario.operationIds, "createTusUpload");
87-
assertContains(scenario.operationIds, "patchTusUpload");
88-
assertContains(scenario.primitives, "upload-during-creation");
89-
assertContains(scenario.eventKeys, "chunk-complete:5:10:11");
90-
assertContains(scenario.eventKeys, "chunk-complete:1:11:11");
91-
}
92-
9373
private static GeneratedTusProtocolContract.GeneratedTusProtocolOperation findOperation(
9474
String operationId) {
9575
for (GeneratedTusProtocolContract.GeneratedTusProtocolOperation operation
@@ -114,18 +94,6 @@ private static GeneratedTusProtocolContract.GeneratedTusClientFeature findFeatur
11494
throw new AssertionError("Missing generated TUS client feature: " + featureId);
11595
}
11696

117-
private static GeneratedTusProtocolContract.GeneratedTusClientConformanceScenario findScenario(
118-
String scenarioId) {
119-
for (GeneratedTusProtocolContract.GeneratedTusClientConformanceScenario scenario
120-
: GeneratedTusProtocolContract.CLIENT_CONFORMANCE_SCENARIOS) {
121-
if (scenario.scenarioId.equals(scenarioId)) {
122-
return scenario;
123-
}
124-
}
125-
126-
throw new AssertionError("Missing generated TUS client scenario: " + scenarioId);
127-
}
128-
12997
private static boolean hasRequiredHeader(
13098
GeneratedTusProtocolContract.GeneratedTusHeaderVariant variant,
13199
String headerName) {

0 commit comments

Comments
 (0)