2121
2222import static io .simplelocalize .cli .client .dto .DownloadRequest .DownloadRequestBuilder .aDownloadRequest ;
2323import static io .simplelocalize .cli .client .dto .UploadRequest .UploadFileRequestBuilder .anUploadFileRequest ;
24+ import static org .assertj .core .api .Assertions .assertThat ;
2425import static org .mockserver .integration .ClientAndServer .startClientAndServer ;
2526import static org .mockserver .model .HttpRequest .request ;
2627import static org .mockserver .model .HttpResponse .response ;
@@ -251,12 +252,42 @@ void shouldDownloadS3File() throws Exception
251252 DownloadableFile downloadableFile = new DownloadableFile ();
252253 downloadableFile .setUrl (MOCK_SERVER_BASE_URL + "/s3/file" );
253254 downloadableFile .setNamespace ("common" );
254- String downloadPath = "file.json" ;
255+ String downloadPath = "./junit/download-test/ file.json" ;
255256
256257 //when
257258 client .downloadFile (downloadableFile , downloadPath );
258259
259260 //then
261+ assertThat (Path .of (downloadPath )).isRegularFile ();
262+ }
263+
264+ @ Test
265+ void shouldDownloadAndTruncateBeforeWriting () throws Exception
266+ {
267+ //given
268+ SimpleLocalizeClient client = new SimpleLocalizeClient (MOCK_SERVER_BASE_URL , "96a7b6ca75c79d4af4dfd5db2946fdd4" );
269+ mockServer .when (request ()
270+ .withMethod ("GET" )
271+ .withPath ("/s3/file" ),
272+ Times .exactly (1 ))
273+ .respond (
274+ response ()
275+ .withStatusCode (200 )
276+ .withContentType (MediaType .APPLICATION_JSON_UTF_8 )
277+ .withBody ("sample" .getBytes (StandardCharsets .UTF_8 ))
278+ .withDelay (TimeUnit .MILLISECONDS , 200 )
279+ );
280+
281+ DownloadableFile downloadableFile = new DownloadableFile ();
282+ downloadableFile .setUrl (MOCK_SERVER_BASE_URL + "/s3/file" );
283+ downloadableFile .setNamespace ("common" );
284+ String downloadPath = "./junit/truncate/file.json" ;
285+
286+ //when
287+ client .downloadFile (downloadableFile , downloadPath );
288+
289+ //then
290+ assertThat (Path .of (downloadPath )).hasContent ("sample" ).isRegularFile ();
260291 }
261292
262293 @ Test
@@ -280,6 +311,6 @@ void shouldValidateQuality() throws Exception
280311 int validateGate = client .validateGate ();
281312
282313 //then
283- Assertions . assertThat (validateGate ).isEqualTo (200 );
314+ assertThat (validateGate ).isEqualTo (200 );
284315 }
285316}
0 commit comments