Search in sources :

Example 1 with Progress

use of org.molgenis.jobs.Progress in project molgenis by molgenis.

the class OneClickImportJobTest method testGetEntityTypeWithZip.

@Test
public void testGetEntityTypeWithZip() throws InvalidFormatException, IOException, URISyntaxException, UnknownFileTypeException, EmptySheetException {
    Progress progress = mock(Progress.class);
    String filename = "simple-valid.zip";
    when(oneClickImporterNamingService.createValidIdFromFileName(filename)).thenReturn("simple_valid");
    File file = loadFile(OneClickImportJobTest.class, "/" + filename);
    when(fileStore.getFile(filename)).thenReturn(file);
    File zipFile1 = loadFile(OneClickImportJobTest.class, "/zip_file_1.csv");
    when(oneClickImporterNamingService.createValidIdFromFileName("zip_file_1.csv")).thenReturn("zip_file_1");
    File zipFile2 = loadFile(OneClickImportJobTest.class, "/zip_file_2.csv");
    when(oneClickImporterNamingService.createValidIdFromFileName("zip_file_2.csv")).thenReturn("zip_file_2");
    File zipFile3 = loadFile(OneClickImportJobTest.class, "/zip_file_3.csv");
    when(oneClickImporterNamingService.createValidIdFromFileName("zip_file_3.csv")).thenReturn("zip_file_3");
    File zipFile4 = loadFile(OneClickImportJobTest.class, "/zip_file_4.csv");
    when(oneClickImporterNamingService.createValidIdFromFileName("zip_file_4.csv")).thenReturn("zip_file_4");
    List<String[]> lines1 = new ArrayList<>();
    lines1.add(new String[] { "name,age", "piet,25" });
    when(csvService.buildLinesFromFile(zipFile1)).thenReturn(lines1);
    List<String[]> lines2 = new ArrayList<>();
    lines2.add(new String[] { "name,age", "klaas,30" });
    when(csvService.buildLinesFromFile(zipFile2)).thenReturn(lines2);
    List<String[]> lines3 = new ArrayList<>();
    lines3.add(new String[] { "name,age", "Jan,35" });
    when(csvService.buildLinesFromFile(zipFile3)).thenReturn(lines3);
    List<String[]> lines4 = new ArrayList<>();
    lines4.add(new String[] { "name,age", "Henk,40" });
    when(csvService.buildLinesFromFile(zipFile4)).thenReturn(lines4);
    DataCollection dataCollection1 = mock(DataCollection.class);
    when(dataCollection1.getName()).thenReturn("zip_file_1");
    when(oneClickImporterService.buildDataCollectionFromCsv("zip_file_1", lines1)).thenReturn(dataCollection1);
    DataCollection dataCollection2 = mock(DataCollection.class);
    when(dataCollection2.getName()).thenReturn("zip_file_2");
    when(oneClickImporterService.buildDataCollectionFromCsv("zip_file_2", lines2)).thenReturn(dataCollection2);
    DataCollection dataCollection3 = mock(DataCollection.class);
    when(dataCollection3.getName()).thenReturn("zip_file_3");
    when(oneClickImporterService.buildDataCollectionFromCsv("zip_file_3", lines3)).thenReturn(dataCollection3);
    DataCollection dataCollection4 = mock(DataCollection.class);
    when(dataCollection4.getName()).thenReturn("zip_file_4");
    when(oneClickImporterService.buildDataCollectionFromCsv("zip_file_4", lines4)).thenReturn(dataCollection4);
    EntityType entityType1 = mock(EntityType.class);
    when(entityService.createEntityType(dataCollection1, "simple_valid")).thenReturn(entityType1);
    EntityType entityType2 = mock(EntityType.class);
    when(entityService.createEntityType(dataCollection2, "simple_valid")).thenReturn(entityType2);
    EntityType entityType3 = mock(EntityType.class);
    when(entityService.createEntityType(dataCollection3, "simple_valid")).thenReturn(entityType3);
    EntityType entityType4 = mock(EntityType.class);
    when(entityService.createEntityType(dataCollection4, "simple_valid")).thenReturn(entityType4);
    oneClickImporterJob = new OneClickImportJob(excelService, csvService, oneClickImporterService, oneClickImporterNamingService, entityService, fileStore);
    oneClickImporterJob.getEntityType(progress, filename);
    verify(progress).status("Preparing import");
    verify(csvService).buildLinesFromFile(zipFile1);
    verify(oneClickImporterService).buildDataCollectionFromCsv("zip_file_1", lines1);
    verify(csvService).buildLinesFromFile(zipFile2);
    verify(oneClickImporterService).buildDataCollectionFromCsv("zip_file_2", lines2);
    verify(csvService).buildLinesFromFile(zipFile3);
    verify(oneClickImporterService).buildDataCollectionFromCsv("zip_file_3", lines3);
    verify(csvService).buildLinesFromFile(zipFile4);
    verify(oneClickImporterService).buildDataCollectionFromCsv("zip_file_4", lines4);
    verify(progress).status("Importing [zip_file_1] into package [simple_valid]");
    verify(entityService).createEntityType(dataCollection1, "simple_valid");
    verify(progress).status("Importing [zip_file_2] into package [simple_valid]");
    verify(entityService).createEntityType(dataCollection2, "simple_valid");
    verify(progress).status("Importing [zip_file_3] into package [simple_valid]");
    verify(entityService).createEntityType(dataCollection3, "simple_valid");
    verify(progress).status("Importing [zip_file_4] into package [simple_valid]");
    verify(entityService).createEntityType(dataCollection4, "simple_valid");
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Progress(org.molgenis.jobs.Progress) DataCollection(org.molgenis.oneclickimporter.model.DataCollection) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) File(java.io.File) OneClickImporterTestUtils.loadFile(org.molgenis.oneclickimporter.service.utils.OneClickImporterTestUtils.loadFile) Test(org.testng.annotations.Test)

Example 2 with Progress

use of org.molgenis.jobs.Progress in project molgenis by molgenis.

the class OneClickImportJobTest method testInvalidFileType.

@Test(expectedExceptions = UnknownFileTypeException.class, expectedExceptionsMessageRegExp = "File \\[unsupported-file-type.nft\\] does not have a valid extension, supported: \\[csv, xlsx, zip, xls\\]")
public void testInvalidFileType() throws InvalidFormatException, IOException, URISyntaxException, UnknownFileTypeException, EmptySheetException {
    Progress progress = mock(Progress.class);
    String filename = "unsupported-file-type.nft";
    File file = loadFile(OneClickImportJobTest.class, "/" + filename);
    when(fileStore.getFile(filename)).thenReturn(file);
    oneClickImporterJob = new OneClickImportJob(excelService, csvService, oneClickImporterService, oneClickImporterNamingService, entityService, fileStore);
    oneClickImporterJob.getEntityType(progress, filename);
}
Also used : Progress(org.molgenis.jobs.Progress) File(java.io.File) OneClickImporterTestUtils.loadFile(org.molgenis.oneclickimporter.service.utils.OneClickImporterTestUtils.loadFile) Test(org.testng.annotations.Test)

Example 3 with Progress

use of org.molgenis.jobs.Progress in project molgenis by molgenis.

the class OneClickImportJobTest method testGetEntityTypeWithExcel.

@Test
public void testGetEntityTypeWithExcel() throws InvalidFormatException, IOException, URISyntaxException, UnknownFileTypeException, EmptySheetException {
    Progress progress = mock(Progress.class);
    String filename = "simple-valid.xlsx";
    when(oneClickImporterNamingService.createValidIdFromFileName(filename)).thenReturn("simple_valid");
    File file = loadFile(OneClickImportJobTest.class, "/" + filename);
    when(fileStore.getFile(filename)).thenReturn(file);
    List<Sheet> sheets = new ArrayList<>();
    when(excelService.buildExcelSheetsFromFile(file)).thenReturn(sheets);
    DataCollection dataCollection = mock(DataCollection.class);
    when(dataCollection.getName()).thenReturn("Sheet1");
    when(oneClickImporterService.buildDataCollectionsFromExcel(sheets)).thenReturn(newArrayList(dataCollection));
    EntityType entityType = mock(EntityType.class);
    when(entityService.createEntityType(dataCollection, "simple_valid")).thenReturn(entityType);
    oneClickImporterJob = new OneClickImportJob(excelService, csvService, oneClickImporterService, oneClickImporterNamingService, entityService, fileStore);
    oneClickImporterJob.getEntityType(progress, filename);
    verify(progress).status("Preparing import");
    verify(excelService).buildExcelSheetsFromFile(file);
    verify(oneClickImporterService).buildDataCollectionsFromExcel(sheets);
    verify(progress).status("Importing [Sheet1] into package [simple_valid]");
    verify(entityService).createEntityType(dataCollection, "simple_valid");
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Progress(org.molgenis.jobs.Progress) DataCollection(org.molgenis.oneclickimporter.model.DataCollection) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) File(java.io.File) OneClickImporterTestUtils.loadFile(org.molgenis.oneclickimporter.service.utils.OneClickImporterTestUtils.loadFile) Sheet(org.apache.poi.ss.usermodel.Sheet) Test(org.testng.annotations.Test)

Example 4 with Progress

use of org.molgenis.jobs.Progress in project molgenis by molgenis.

the class OneClickImportJobTest method testInvalidZipContent.

@Test(expectedExceptions = UnknownFileTypeException.class, expectedExceptionsMessageRegExp = "Zip file contains files which are not of type CSV")
public void testInvalidZipContent() throws InvalidFormatException, IOException, URISyntaxException, UnknownFileTypeException, EmptySheetException {
    Progress progress = mock(Progress.class);
    String filename = "unsupported-file-zip.zip";
    File file = loadFile(OneClickImportJobTest.class, "/" + filename);
    when(fileStore.getFile(filename)).thenReturn(file);
    oneClickImporterJob = new OneClickImportJob(excelService, csvService, oneClickImporterService, oneClickImporterNamingService, entityService, fileStore);
    oneClickImporterJob.getEntityType(progress, filename);
}
Also used : Progress(org.molgenis.jobs.Progress) File(java.io.File) OneClickImporterTestUtils.loadFile(org.molgenis.oneclickimporter.service.utils.OneClickImporterTestUtils.loadFile) Test(org.testng.annotations.Test)

Example 5 with Progress

use of org.molgenis.jobs.Progress in project molgenis by molgenis.

the class OneClickImportJobTest method testInvalidZipContentWithImage.

@Test(expectedExceptions = UnknownFileTypeException.class, expectedExceptionsMessageRegExp = "Zip file contains files which are not of type CSV")
public void testInvalidZipContentWithImage() throws InvalidFormatException, IOException, URISyntaxException, UnknownFileTypeException, EmptySheetException {
    Progress progress = mock(Progress.class);
    String filename = "unsupported-file-zip2.zip";
    File file = loadFile(OneClickImportJobTest.class, "/" + filename);
    when(fileStore.getFile(filename)).thenReturn(file);
    oneClickImporterJob = new OneClickImportJob(excelService, csvService, oneClickImporterService, oneClickImporterNamingService, entityService, fileStore);
    oneClickImporterJob.getEntityType(progress, filename);
}
Also used : Progress(org.molgenis.jobs.Progress) File(java.io.File) OneClickImporterTestUtils.loadFile(org.molgenis.oneclickimporter.service.utils.OneClickImporterTestUtils.loadFile) Test(org.testng.annotations.Test)

Aggregations

Progress (org.molgenis.jobs.Progress)8 Test (org.testng.annotations.Test)8 File (java.io.File)6 OneClickImporterTestUtils.loadFile (org.molgenis.oneclickimporter.service.utils.OneClickImporterTestUtils.loadFile)6 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)5 ArrayList (java.util.ArrayList)3 EntityType (org.molgenis.data.meta.model.EntityType)3 DataCollection (org.molgenis.oneclickimporter.model.DataCollection)3 Lists (com.google.common.collect.Lists)2 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Collections.emptyList (java.util.Collections.emptyList)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 Set (java.util.Set)2 Consumer (java.util.function.Consumer)2 Collectors.toSet (java.util.stream.Collectors.toSet)2 Stream (java.util.stream.Stream)2 org.mockito (org.mockito)2