Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lbownik committed Oct 7, 2024
1 parent 544ca55 commit f76d376
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import edu.harvard.iq.dataverse.persistence.MocksFactory;
import edu.harvard.iq.dataverse.persistence.datafile.DataFile;
Expand All @@ -44,18 +46,16 @@ public class FileAccessIOTest {

private byte[] dataToBeSaved = "tobesaved".getBytes();

private String tempFiles = "/tmp/files";
private File fileToBeSaved;

@Rule
public TemporaryFolder tempFiles= new TemporaryFolder();


@Before
public void setUpClass() throws IOException {

if(System.getProperty("os.name").toLowerCase().contains("win")) {
tempFiles = "c:/tmp/files";
}

fileToBeSaved = new File(tempFiles + "/fileToBeSaved");
fileToBeSaved = this.tempFiles.newFile("fileToBeSaved");

dataverse = MocksFactory.makeDataverse();
dataset = MocksFactory.makeDataset();
Expand All @@ -66,21 +66,21 @@ public void setUpClass() throws IOException {
dataFile.setOwner(dataset);
dataFile.setStorageIdentifier("DataFile");

datasetAccess = new FileAccessIO<>(dataset, tempFiles);
dataFileAccess = new FileAccessIO<>(dataFile, tempFiles);
datasetAccess = new FileAccessIO<>(dataset, tempFiles.getRoot().toString());
dataFileAccess = new FileAccessIO<>(dataFile, tempFiles.getRoot().toString());

FileUtils.writeByteArrayToFile(new File(tempFiles + "/10.1010/FK2/DATASET/Dataset"), datasetAuxFileBytes);
FileUtils.writeByteArrayToFile(new File(tempFiles + "/10.1010/FK2/DATASET/DataFile"), datafileBytes);
FileUtils.writeByteArrayToFile(new File(tempFiles.getRoot().toString() + "/10.1010/FK2/DATASET/Dataset"), datasetAuxFileBytes);
FileUtils.writeByteArrayToFile(new File(tempFiles.getRoot().toString() + "/10.1010/FK2/DATASET/DataFile"), datafileBytes);

FileUtils.writeByteArrayToFile(new File(tempFiles + "/fileToBeSaved"), dataToBeSaved);
FileUtils.writeByteArrayToFile(fileToBeSaved, dataToBeSaved);
}

@After
public void tearDownClass() throws Exception {

this.datasetAccess.close();
this.dataFileAccess.close();
FileUtils.deleteDirectory(new File(tempFiles));
//FileUtils.deleteDirectory(new File(tempFiles));
}

/**
Expand Down Expand Up @@ -133,14 +133,14 @@ public void testGetAuxObjectSize() throws IOException {
@Test
public void testGetAuxObjectAsPath() throws IOException {
assertThat(datasetAccess.getAuxObjectAsPath(datasetAuxObjectName))
.isEqualTo(new File(tempFiles + "/10.1010/FK2/DATASET/" + datasetAuxObjectName).toPath());
.isEqualTo(new File(tempFiles.getRoot().toString() + "/10.1010/FK2/DATASET/" + datasetAuxObjectName).toPath());
}

@Test
public void testBackupAsAux() throws IOException {
dataFileAccess.backupAsAux("auxFileBackup");

assertThat(new File(tempFiles + "/10.1010/FK2/DATASET/DataFile.auxFileBackup")).
assertThat(new File(tempFiles.getRoot().toString() + "/10.1010/FK2/DATASET/DataFile.auxFileBackup")).
hasBinaryContent(datafileBytes);
}

Expand Down Expand Up @@ -174,13 +174,15 @@ public void testGetStorageLocation() {

String location = dataFileAccess.getStorageLocation();
location = location.replace('\\', '/'); // so that is works on both Linux & Windows

assertThat(location).isEqualTo("file://" + tempFiles + "/10.1010/FK2/DATASET/DataFile");

String expected = "file://" + tempFiles.getRoot().toString() + "/10.1010/FK2/DATASET/DataFile";
expected = expected.replace('\\', '/'); // so that is works on both Linux & Windows
assertThat(location).isEqualTo(expected);
}

@Test
public void testGetFileSystemPath() throws IOException {
assertThat(dataFileAccess.getFileSystemPath()).isEqualTo(new File(tempFiles + "/10.1010/FK2/DATASET/DataFile").toPath());
assertThat(dataFileAccess.getFileSystemPath()).isEqualTo(new File(tempFiles.getRoot().toString() + "/10.1010/FK2/DATASET/DataFile").toPath());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import org.jboss.arquillian.transaction.api.annotation.Transactional;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;

import edu.harvard.iq.dataverse.DatasetDao;
Expand Down Expand Up @@ -74,14 +76,16 @@ public class ReplaceFileHandlerIT extends WebappArquillianDeployment {

@EJB
private DatasetDao datasetDao;

@Rule
public TemporaryFolder tempFiles= new TemporaryFolder();


@Before
public void setUp() {

if(isWindows()) {
System.setProperty(SystemConfig.FILES_DIRECTORY, "c:/tmp/files");
}

System.setProperty(SystemConfig.FILES_DIRECTORY, tempFiles.getRoot().toString());
}

private static boolean isWindows() {
Expand Down

0 comments on commit f76d376

Please sign in to comment.