Skip to content

Commit

Permalink
Add tests for Server Sent Events
Browse files Browse the repository at this point in the history
  • Loading branch information
cdr-chakotay committed Sep 2, 2024
1 parent 115cc4c commit 24490d9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
23 changes: 12 additions & 11 deletions src/test/java/com/transloadit/sdk/AssemblyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,25 +249,27 @@ public void saveWithTusListenSSE() throws Exception {
mockServerClient.when(request()
.withPath("/ws20013").withMethod("GET").withHeader("Accept", "text/event-stream"))
.respond(HttpResponse.response().withBody(sseBody));

// When the assembly is finished (finished status)
/*mockServerClient.when(HttpRequest.request()
mockServerClient.when(HttpRequest.request()
.withPath("/assemblies/02ce6150ea2811e6a35a8d1e061a5b71").withMethod("GET"))
.respond(HttpResponse.response().withBody(getJson("resumable_assembly_complete.json")));*/
.respond(HttpResponse.response().withBody(getJson("resumable_assembly_complete.json")));

AssemblyResponse response = assembly.save(true);

Assertions.assertEquals(response.json().get("ok"), "ASSEMBLY_UPLOADING");
Assertions.assertEquals(emittedEvents.get("ASSEMBLY_FINISHED"), false);
//Assertions.assertTrue(assembly.emitted.containsKey("assembly_connect"));
// emit that assembly is complete
// assembly.getSocket("").emit("assembly_finished");


HttpRequest[] recordedRequests = mockServerClient.retrieveRecordedRequests(
request()
);
// Wait for the assembly to finish and the SSE events to be processed
Thread.sleep(1000);

System.out.println("lol");
// Check if SSE events triggered the correct events
Assertions.assertEquals(emittedEvents.get("ASSEMBLY_META_DATA_EXTRACTED"), true);
Assertions.assertEquals(emittedEvents.get("ASSEMBLY_INSTRUCTION_UPLOAD_FINISHED"), true);
Assertions.assertEquals(emittedEvents.get("ASSEMBLY_FILE_UPLOAD_FINISHED"), true);
Assertions.assertEquals(emittedEvents.get("ASSEMBLY_PROGRESS"), true);
Assertions.assertEquals(emittedEvents.get("ASSEMBLY_RESULT_FINISHED"), true);
Assertions.assertEquals(emittedEvents.get("ASSEMBLY_FINISHED"), true);

}

Expand Down Expand Up @@ -320,7 +322,6 @@ public void onFileUploadProgress(long uploadedBytes, long totalBytes) {

@Override
public void onAssemblyProgress(double combinedProgress, JSONObject progressPerOriginalFile) {
System.out.println("Boeing707-800");
emittedEvents.put("ASSEMBLY_PROGRESS", true);
}

Expand Down
17 changes: 9 additions & 8 deletions src/test/resources/__files/sse_response_body
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
id: 3c951d1310dd4f829a6fb696a48a43e1
id: 2b7beaddf0a046e2ada603346f2cbee1

event: assembly_execution_progress
data: {"progress_combined":null,"progress_per_original_file":[]}
event: assembly_upload_finished
data: {"id":"e48cdd96971c4485976bce09cbc32a78","name":"both-anthems.mp3","basename":"both-anthems","ext":"mp3","size":932929,"mime":"audio/mpeg","type":"audio","field":"file","md5hash":"0dcc80c8656f453985c8ca42cd8e6202","original_id":"e48cdd96971c4485976bce09cbc32a78","original_basename":"both-anthems","original_name":"both-anthems.mp3","original_path":"/","original_md5hash":"0dcc80c8656f453985c8ca42cd8e6202","from_batch_import":false,"is_tus_file":true,"tus_upload_url":"https://api2-berlin8.transloadit.com/resumable/files/2b7beaddf0a046e2ada603346f2cbee1_e49a39492c57ef94f9aebd15d73b211d","url":"http://tmp-eu-west-1.transloadit.net/2ffcb91ab9bb40cfb070f39a0111c772/2b7beaddf0a046e2ada603346f2cbee1/e48cdd96971c4485976bce09cbc32a78.mp3","ssl_url":"https://tmp-eu-west-1.transloadit.net/2ffcb91ab9bb40cfb070f39a0111c772/2b7beaddf0a046e2ada603346f2cbee1/e48cdd96971c4485976bce09cbc32a78.mp3","meta":{"duration":58.044,"mean_volume":null,"audio_bitrate":128000,"overall_bitrate":128000,"audio_samplerate":44100,"audio_channels":2,"audio_codec":"ffmp3float","encoder":null,"beats_per_minute":null,"bit_depth":null,"album":null,"year":null,"genre":"Other","artist":null,"comment":"%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20","performer":null,"lyrics":null,"title":"Het%20Wilhelmus%20-%20The%20Nederlands","band":null,"disc":null,"track":null,"has_artwork":false},"user_meta":{"filetype":"audio/mpeg","name":"both-anthems.mp3","relativePath":"null","type":"audio/mpeg"},"as":null,"is_temp_url":true}

data: assembly_uploading_finished

event: assembly_execution_progress
data: {"progress_combined":null,"progress_per_original_file":[]}
event: assembly_result_finished
data: ["waveformed",{"id":"8197cd2434784ec4b63340c6a06169eb","name":"both-anthems.png","basename":"both-anthems","ext":"png","size":12224,"mime":"image/png","type":"image","field":"file","md5hash":"5d24d47ec4fc3580e22d3be0d36a3630","original_id":"e48cdd96971c4485976bce09cbc32a78","original_basename":"both-anthems","original_name":"both-anthems.mp3","original_path":"/","original_md5hash":"0dcc80c8656f453985c8ca42cd8e6202","from_batch_import":false,"is_tus_file":false,"tus_upload_url":null,"url":"http://tmp-eu-west-1.transloadit.net/2ffcb91ab9bb40cfb070f39a0111c772/2b7beaddf0a046e2ada603346f2cbee1/8197cd2434784ec4b63340c6a06169eb.png","ssl_url":"https://tmp-eu-west-1.transloadit.net/2ffcb91ab9bb40cfb070f39a0111c772/2b7beaddf0a046e2ada603346f2cbee1/8197cd2434784ec4b63340c6a06169eb.png","meta":{"width":1364,"height":410,"svgViewBoxWidth":null,"svgViewBoxHeight":null,"date_recorded":null,"date_file_created":null,"date_file_modified":"2024/08/28 13:26:57 GMT","title":null,"description":null,"duration":null,"location":null,"aspect_ratio":3.327,"city":null,"state":null,"country":null,"country_code":null,"keywords":null,"aperture":null,"exposure_compensation":null,"exposure_mode":null,"exposure_time":null,"flash":null,"focal_length":null,"f_number":null,"iso":null,"light_value":null,"metering_mode":null,"shutter_speed":null,"white_balance":null,"device_name":null,"device_vendor":null,"device_software":null,"latitude":null,"longitude":null,"orientation":null,"has_clipping_path":false,"creator":null,"author":null,"copyright":null,"copyright_notice":null,"frame_count":1,"colorspace":"RGB","has_transparency":null,"dominant_colors":null,"average_color":"#dbe9f6","xp_title":null,"xp_comment":null,"xp_keywords":null,"xp_subject":null},"user_meta":{"filetype":"audio/mpeg","name":"both-anthems.mp3","relativePath":"null","type":"audio/mpeg"},"as":null,"queue":"live","queue_time":0.01,"exec_time":0.4,"cost":1048576,"is_temp_url":true}]

event: assembly_upload_finished
data: {"id":"77bfd6d1378a4289a83ff8777848dce8","name":"lesereihe.doc","basename":"lesereihe","ext":"doc","size":61440,"mime":"application/msword","type":"office","field":"file","md5hash":"154a9349b8f9111865a07ed0a7050f55","original_id":"77bfd6d1378a4289a83ff8777848dce8","original_basename":"lesereihe","original_name":"lesereihe.doc","original_path":"/","original_md5hash":"154a9349b8f9111865a07ed0a7050f55","from_batch_import":false,"is_tus_file":true,"tus_upload_url":"https://api2-samho.transloadit.com/resumable/files/3c951d1310dd4f829a6fb696a48a43e1_38f7dd7616eb554ca069264d3e0ee17a","url":"http://tmp-eu-west-1.transloadit.net/6ed8698028ac11e4a6abc57a5f066e81/3c951d1310dd4f829a6fb696a48a43e1/77bfd6d1378a4289a83ff8777848dce8.doc","ssl_url":"https://tmp-eu-west-1.transloadit.net/6ed8698028ac11e4a6abc57a5f066e81/3c951d1310dd4f829a6fb696a48a43e1/77bfd6d1378a4289a83ff8777848dce8.doc","meta":{},"user_meta":{},"as":null,"is_temp_url":true}
data: {"id":"99757ab201334bf8b04ae0a3474c523c","name":"german_anthem.mp3","basename":"german_anthem","ext":"mp3","size":1252668,"mime":"audio/mpeg","type":"audio","field":"file","md5hash":"2e491d861e00e7a4020c938c58306ee0","original_id":"99757ab201334bf8b04ae0a3474c523c","original_basename":"german_anthem","original_name":"german_anthem.mp3","original_path":"/","original_md5hash":"2e491d861e00e7a4020c938c58306ee0","from_batch_import":false,"is_tus_file":true,"tus_upload_url":"https://api2-artur6.transloadit.com/resumable/files/2b7beaddf0a046e2ada603346f2cbee1_87342bd4b100bb2d7f621ae4160ef3b2","url":"http://tmp-eu-west-1.transloadit.net/2ffcb91ab9bb40cfb070f39a0111c772/2b7beaddf0a046e2ada603346f2cbee1/99757ab201334bf8b04ae0a3474c523c.mp3","ssl_url":"https://tmp-eu-west-1.transloadit.net/2ffcb91ab9bb40cfb070f39a0111c772/2b7beaddf0a046e2ada603346f2cbee1/99757ab201334bf8b04ae0a3474c523c.mp3","meta":{"duration":78.028,"mean_volume":null,"audio_bitrate":128000,"overall_bitrate":128000,"audio_samplerate":44100,"audio_channels":2,"audio_codec":"ffmp3float","encoder":null,"beats_per_minute":null,"bit_depth":null,"album":null,"year":null,"genre":"Other","artist":null,"comment":"%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20","performer":null,"lyrics":null,"title":"up_germany0","band":null,"disc":null,"track":null,"has_artwork":false},"user_meta":{"filetype":"audio/mpeg","name":"german_anthem.mp3","relativePath":"null","type":"audio/mpeg"},"as":null,"is_temp_url":true}

data: assembly_upload_meta_data_extracted

event: assembly_execution_progress
data: {"progress_combined":0,"progress_per_original_file":[{"original_id":"77bfd6d1378a4289a83ff8777848dce8","progress":0}]}
data: {"progress_combined":50,"progress_per_original_file":[{"original_id":"e48cdd96971c4485976bce09cbc32a78","progress":100},{"original_id":"99757ab201334bf8b04ae0a3474c523c","progress":0}]}

event: assembly_result_finished
data: ["avatar",{"id":"1ddf6ddf086444e6894717aebe0757e7","name":"lesereihe.pdf","basename":"lesereihe","ext":"pdf","size":126266,"mime":"application/pdf","type":"pdf","field":"file","md5hash":"3ec28058ac524ed8cff0d4da477913a6","original_id":"77bfd6d1378a4289a83ff8777848dce8","original_basename":"lesereihe","original_name":"lesereihe.doc","original_path":"/","original_md5hash":"154a9349b8f9111865a07ed0a7050f55","from_batch_import":false,"is_tus_file":false,"tus_upload_url":null,"url":"http://tmp-eu-west-1.transloadit.net/6ed8698028ac11e4a6abc57a5f066e81/3c951d1310dd4f829a6fb696a48a43e1/1ddf6ddf086444e6894717aebe0757e7.pdf","ssl_url":"https://tmp-eu-west-1.transloadit.net/6ed8698028ac11e4a6abc57a5f066e81/3c951d1310dd4f829a6fb696a48a43e1/1ddf6ddf086444e6894717aebe0757e7.pdf","meta":{"page_count":2,"width":1238,"height":1750,"page_size":"595.304 x 841.89 pts (A4)","title":"Lesereihe%202007%3A","author":"Lugsteinhof","producer":"LibreOffice 7.5","creator":"Writer","create_date":"2024:08:14 13:43:02Z","modify_date":null},"user_meta":{},"as":null,"queue":"live","queue_time":0,"exec_time":2.86,"cost":1048576,"is_temp_url":true}]
data: ["waveformed",{"id":"e5f6cd5256b94b88bbfad872a0ba1cb3","name":"german_anthem.png","basename":"german_anthem","ext":"png","size":12528,"mime":"image/png","type":"image","field":"file","md5hash":"16ad7da3254f158a3ba06881e9755dd9","original_id":"99757ab201334bf8b04ae0a3474c523c","original_basename":"german_anthem","original_name":"german_anthem.mp3","original_path":"/","original_md5hash":"2e491d861e00e7a4020c938c58306ee0","from_batch_import":false,"is_tus_file":false,"tus_upload_url":null,"url":"http://tmp-eu-west-1.transloadit.net/2ffcb91ab9bb40cfb070f39a0111c772/2b7beaddf0a046e2ada603346f2cbee1/e5f6cd5256b94b88bbfad872a0ba1cb3.png","ssl_url":"https://tmp-eu-west-1.transloadit.net/2ffcb91ab9bb40cfb070f39a0111c772/2b7beaddf0a046e2ada603346f2cbee1/e5f6cd5256b94b88bbfad872a0ba1cb3.png","meta":{"width":1364,"height":410,"svgViewBoxWidth":null,"svgViewBoxHeight":null,"date_recorded":null,"date_file_created":null,"date_file_modified":"2024/08/28 13:26:58 GMT","title":null,"description":null,"duration":null,"location":null,"aspect_ratio":3.327,"city":null,"state":null,"country":null,"country_code":null,"keywords":null,"aperture":null,"exposure_compensation":null,"exposure_mode":null,"exposure_time":null,"flash":null,"focal_length":null,"f_number":null,"iso":null,"light_value":null,"metering_mode":null,"shutter_speed":null,"white_balance":null,"device_name":null,"device_vendor":null,"device_software":null,"latitude":null,"longitude":null,"orientation":null,"has_clipping_path":false,"creator":null,"author":null,"copyright":null,"copyright_notice":null,"frame_count":1,"colorspace":"RGB","has_transparency":null,"dominant_colors":null,"average_color":"#d2e4f4","xp_title":null,"xp_comment":null,"xp_keywords":null,"xp_subject":null},"user_meta":{"filetype":"audio/mpeg","name":"german_anthem.mp3","relativePath":"null","type":"audio/mpeg"},"as":null,"queue":"live","queue_time":0,"exec_time":0.82,"cost":1265196,"is_temp_url":true}]

event: assembly_execution_progress
data: {"progress_combined":100,"progress_per_original_file":[]}

data: assembly_finished

0 comments on commit 24490d9

Please sign in to comment.