Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ public boolean checkControllerIsBusy() {
return busy;
}

public String getZIP_EXTENSION() {
public String getZipExtension() {
return ".zip";
}

public String getTXT_EXTENSION() {
public String getTxtExtension() {
return ".txt";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public File extractToCsv(ExtractionController extractionController) throws IOExc
new FileOutputStream(
FileNamesUtil.getFilePath(
extractionController.getWorkingDirectory(),
getFileNameWithExtension(extractionController.getZIP_EXTENSION())
getFileNameWithExtension(extractionController.getZipExtension())
)
)
);
Expand All @@ -409,18 +409,19 @@ public File extractToCsv(ExtractionController extractionController) throws IOExc
Files.move(
Path.of(FileNamesUtil.getFilePath(
extractionController.getWorkingDirectory(),
getFileNameWithExtension(extractionController.getZIP_EXTENSION()))),
getFileNameWithExtension(extractionController.getZipExtension()))),
Path.of(FileNamesUtil.getFilePath(
extractionController.getFilesDirectory(),
getFileNameWithExtension(extractionController.getZIP_EXTENSION()))));
getFileNameWithExtension(extractionController.getZipExtension()))));

log.info("File at " + FileNamesUtil.getFilePath(extractionController.getWorkingDirectory(),
getFileNameWithExtension(extractionController.getZIP_EXTENSION()))
+ " moved to " + FileNamesUtil.getFilePath(extractionController.getFilesDirectory(),
getFileNameWithExtension(extractionController.getZIP_EXTENSION())));
log.info("File at {} moved to {}",
FileNamesUtil.getFilePath(extractionController.getWorkingDirectory(),
getFileNameWithExtension(extractionController.getZipExtension())),
FileNamesUtil.getFilePath(extractionController.getFilesDirectory(),
getFileNameWithExtension(extractionController.getZipExtension())));

return FileNamesUtil.getLatestExtract(extractionController.getFilesDirectory(),
getFileNameWithExtension(extractionController.getZIP_EXTENSION()));
getFileNameWithExtension(extractionController.getZipExtension()));
}

private void writeDigestEntry(final ZipOutputStream zos, MessageDigest extractEntryDigester) throws IOException {
Expand All @@ -434,7 +435,7 @@ private void writeDigestEntry(final ZipOutputStream zos, MessageDigest extractEn
}

private MessageDigest writeExtractEntry(ExtractionController extractionController, final ZipOutputStream zos, final InputStream fileContent) throws IOException, NoSuchAlgorithmException {
ZipEntry zipEntry = new ZipEntry(getFileNameWithExtension(extractionController.getTXT_EXTENSION()));
ZipEntry zipEntry = new ZipEntry(getFileNameWithExtension(extractionController.getTxtExtension()));
zipEntry.setTime(System.currentTimeMillis());
zos.putNextEntry(zipEntry);
byte[] buffer=new byte[4096];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static void cleanup(String filesDirectory, String exceptFile) {
listOfFiles.removeIf(file -> file.getName().contains(exceptFile));
listOfFiles.sort(FileNamesUtil::compare);

if (listOfFiles.size() > 0) {
if (!listOfFiles.isEmpty()) {
listOfFiles.remove(listOfFiles.size() - 1);
}

Expand Down
46 changes: 11 additions & 35 deletions src/test/java/fr/ans/psc/pscextract/ExtractionControllerTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
Expand Down Expand Up @@ -107,18 +109,23 @@ private void Clean() {
await().until(controllerIsReady(controller));
}

@Test
void singlePageExtractionAndResultConformityTest() throws Exception {
@ParameterizedTest
@CsvSource({
"multiple-work-situations.json, multiple-work-situations-result",
"empty-ps.json, empty-ps-result",
"very-empty-ps.json, very-empty-ps-result"
})
void singlePageExtractionAndResultConformityTest(String inputFile, String expectedResultFile) throws Exception {

httpMockServer.stubFor(get("/v2/ps?page=0&size=1").willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBodyFile("multiple-work-situations.json")));
httpMockServer.stubFor(get("/v2/ps?page=0&size=1").willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBodyFile(inputFile)));
httpMockServer.stubFor(get("/v2/ps?page=1&size=1").willReturn(aResponse().withStatus(410)));

controller.generateExtract(null);
await().until(controllerIsReady(controller));

ResponseEntity<FileSystemResource> response = controller.getFile();

String expected = getContentAsString("multiple-work-situations-result");
String expected = getContentAsString(expectedResultFile);
String actual = getDataEntryAsString(response);
Assertions.assertEquals(expected, actual);
}
Expand Down Expand Up @@ -153,38 +160,7 @@ void noPagesExtractionTest() {
Assertions.assertThrows(NullPointerException.class, () -> System.out.println(Objects.requireNonNull(response.getBody())));
}

@Test
// @Disabled //FIXME please tell why !!! Disabled tests hsould disappear or get fixed, prefably the latter.
void emptyPsExtractionTest() throws Exception {

httpMockServer.stubFor(get("/v2/ps?page=0&size=1").willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBodyFile("empty-ps.json")));
httpMockServer.stubFor(get("/v2/ps?page=1&size=1").willReturn(aResponse().withStatus(410)));

controller.generateExtract(null);
await().until(controllerIsReady(controller));

ResponseEntity<FileSystemResource> response = controller.getFile();

String expected = getContentAsString("empty-ps-result");
String actual = getDataEntryAsString(response);
Assertions.assertEquals(expected, actual);
}

@Test
void fullyEmptyPsExtractionTest() throws Exception {

httpMockServer.stubFor(get("/v2/ps?page=0&size=1").willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBodyFile("very-empty-ps.json")));
httpMockServer.stubFor(get("/v2/ps?page=1&size=1").willReturn(aResponse().withStatus(410)));

controller.generateExtract(null);
await().until(controllerIsReady(controller));

ResponseEntity<FileSystemResource> response = controller.getFile();

String expected = getContentAsString("very-empty-ps-result");
String actual = getDataEntryAsString(response);
Assertions.assertEquals(expected, actual);
}

@Test
void testUploadDemoExtractFile() throws Exception {
Expand Down
Loading