|
| 1 | +package edu.harvard.iq.dataverse.export; |
| 2 | + |
| 3 | +import edu.harvard.iq.dataverse.DataFile; |
| 4 | +import edu.harvard.iq.dataverse.DataTable; |
| 5 | +import edu.harvard.iq.dataverse.DatasetVersion; |
| 6 | +import edu.harvard.iq.dataverse.FileMetadata; |
| 7 | +import jakarta.json.JsonArray; |
| 8 | +import org.junit.jupiter.api.Test; |
| 9 | +import org.mockito.Mockito; |
| 10 | + |
| 11 | +import java.util.ArrayList; |
| 12 | +import java.util.List; |
| 13 | + |
| 14 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 15 | +import static org.mockito.Mockito.when; |
| 16 | + |
| 17 | +public class InternalExportProviderTest { |
| 18 | + |
| 19 | + /** |
| 20 | + * this is a unit-test for seeing why the directory-labels are |
| 21 | + * not showing in the exported data and how best to remedy the case |
| 22 | + */ |
| 23 | + @Test |
| 24 | + public void getDatasetFileDetailsVanilla() throws Exception { |
| 25 | + |
| 26 | + DatasetVersion mockDV = Mockito.mock(DatasetVersion.class); |
| 27 | + List<FileMetadata> metadataList = new ArrayList<>(); |
| 28 | + FileMetadata metadata = new FileMetadata(); |
| 29 | + metadata.setId(1L); |
| 30 | + metadata.setDirectoryLabel("some/directory/label"); |
| 31 | + metadata.setLabel("some-silly-label"); |
| 32 | + |
| 33 | + DataFile datafile = new DataFile(); |
| 34 | + datafile.setId(1L); |
| 35 | + metadata.setDataFile(datafile); |
| 36 | + metadata.setDatasetVersion(mockDV); |
| 37 | + |
| 38 | + List<DataTable> dataTables = new ArrayList<>(); |
| 39 | + DataTable dataTable = new DataTable(); |
| 40 | + dataTable.setOriginalFileName("some_silly_original_file_name"); |
| 41 | + dataTables.add(dataTable); |
| 42 | + |
| 43 | + datafile.setDataTables(dataTables); |
| 44 | + |
| 45 | + metadataList.add(metadata); |
| 46 | + when(mockDV.getFileMetadatas()).thenReturn(metadataList); |
| 47 | + |
| 48 | + InternalExportDataProvider provider = new InternalExportDataProvider(mockDV); |
| 49 | + |
| 50 | + JsonArray json = provider.getDatasetFileDetails(); |
| 51 | + assertTrue(json.toString().contains("some/directory/label")); |
| 52 | + } |
| 53 | + |
| 54 | +} |
0 commit comments