Skip to content

Commit 7635af9

Browse files
committed
Add test file truncation test
1 parent 553fcad commit 7635af9

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

junit/truncate/file.json

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

src/test/java/io/simplelocalize/cli/client/SimpleLocalizeClientTest.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import static io.simplelocalize.cli.client.dto.DownloadRequest.DownloadRequestBuilder.aDownloadRequest;
2323
import static io.simplelocalize.cli.client.dto.UploadRequest.UploadFileRequestBuilder.anUploadFileRequest;
24+
import static org.assertj.core.api.Assertions.assertThat;
2425
import static org.mockserver.integration.ClientAndServer.startClientAndServer;
2526
import static org.mockserver.model.HttpRequest.request;
2627
import 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

Comments
 (0)