forked from IQSS/dataverse
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
src/test/java/edu/harvard/iq/dataverse/engine/command/impl/CreateNewDataFilesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package edu.harvard.iq.dataverse.engine.command.impl; | ||
|
||
import edu.harvard.iq.dataverse.Dataset; | ||
import edu.harvard.iq.dataverse.DatasetVersion; | ||
import edu.harvard.iq.dataverse.engine.command.CommandContext; | ||
import edu.harvard.iq.dataverse.engine.command.DataverseRequest; | ||
import edu.harvard.iq.dataverse.engine.command.exception.CommandException; | ||
import edu.harvard.iq.dataverse.settings.JvmSettings; | ||
import edu.harvard.iq.dataverse.storageuse.UploadSessionQuotaLimit; | ||
import edu.harvard.iq.dataverse.util.SystemConfig; | ||
import edu.harvard.iq.dataverse.util.file.CreateDataFileResult; | ||
import edu.harvard.iq.dataverse.util.testing.JvmSetting; | ||
import edu.harvard.iq.dataverse.util.testing.LocalJvmSettings; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.NoSuchFileException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import static org.apache.commons.io.file.FilesUncheck.createDirectory; | ||
import static org.apache.commons.io.file.PathUtils.deleteDirectory; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
@LocalJvmSettings | ||
public class CreateNewDataFilesTest { | ||
@BeforeEach | ||
public void cleanTmpDir() throws IOException { | ||
var tmpDir = Paths.get("target/test/tmp"); | ||
if(tmpDir.toFile().exists()) | ||
deleteDirectory(tmpDir); | ||
Files.createDirectories(tmpDir); | ||
} | ||
|
||
@Test | ||
@JvmSetting(key = JvmSettings.FILES_DIRECTORY, value = "target/test/tmp") | ||
public void execute_fails_to_upload_when_tmp_does_not_exist() throws FileNotFoundException { | ||
var dsVersion = Mockito.mock(DatasetVersion.class); | ||
Mockito.when(dsVersion.getDataset()).thenReturn(Mockito.mock(Dataset.class)); | ||
|
||
// TODO fix copilot suggestion | ||
JvmSettings mockFilesDirectory = Mockito.mock(JvmSettings.class); | ||
Mockito.when(mockFilesDirectory.lookup()).thenReturn("/mocked/path"); | ||
|
||
var cmd = new CreateNewDataFilesCommand( | ||
Mockito.mock(DataverseRequest.class), | ||
dsVersion, | ||
new FileInputStream("scripts/search/data/shape/shapefile.zip"), | ||
"example.zip", | ||
"application/zip", | ||
null, | ||
new UploadSessionQuotaLimit(1000L, 500L), | ||
"sha"); | ||
|
||
var ctxt = Mockito.mock(CommandContext.class); | ||
var sysCfg = Mockito.mock(SystemConfig.class); | ||
Mockito.when(ctxt.systemConfig()).thenReturn(sysCfg); | ||
Mockito.when(sysCfg.isStorageQuotasEnforced()).thenReturn(true); | ||
|
||
assertThatThrownBy(() -> cmd.execute(ctxt)) | ||
.isInstanceOf(CommandException.class) | ||
.hasMessageContaining("Failed to save the upload as a temp file (temp disk space?)") | ||
.hasRootCauseInstanceOf(NoSuchFileException.class) | ||
.getRootCause() | ||
.hasMessageStartingWith("target/test/tmp/temp/tmp"); | ||
} | ||
|
||
} |