use of org.molgenis.data.meta.model.EntityType 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");
}
use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.
the class OneClickImporterNamingServiceTest method testGetLabelWithPostFixWhenOneDuplicate.
@Test
public void testGetLabelWithPostFixWhenOneDuplicate() {
EntityType e1 = Mockito.mock(EntityType.class);
when(e1.getLabel()).thenReturn("label");
String label = "label";
when(dataService.findAll(ENTITY_TYPE_META_DATA, new QueryImpl<EntityType>().like(LABEL, label), EntityType.class)).thenReturn(Stream.of(e1));
oneClickImporterNamingService = new OneClickImporterNamingServiceImpl(dataService);
String actual = oneClickImporterNamingService.getLabelWithPostFix(label);
String expected = "label (1)";
assertEquals(actual, expected);
}
use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.
the class EntityTypeReferenceMapperTest method testToEditorEntityTypeIdentifiers.
@Test
public void testToEditorEntityTypeIdentifiers() {
String id = "id";
String label = "label";
EntityType entityType = mock(EntityType.class);
when(entityType.getId()).thenReturn(id);
when(entityType.getLabel()).thenReturn(label);
List<EditorEntityTypeIdentifier> editorEntityTypeIdentifiers = entityTypeReferenceMapper.toEditorEntityTypeIdentifiers(of(entityType));
assertEquals(editorEntityTypeIdentifiers, of(EditorEntityTypeIdentifier.create(id, label)));
}
use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.
the class EntityTypeReferenceMapperTest method testToEntityTypeReference.
@Test
public void testToEntityTypeReference() throws Exception {
String id = "id";
EntityType entityType = entityTypeReferenceMapper.toEntityTypeReference(id);
assertEquals(entityType.getIdValue(), id);
}
use of org.molgenis.data.meta.model.EntityType in project molgenis by molgenis.
the class MetadataManagerServiceTest method testUpsertEntityType.
@Test
public void testUpsertEntityType() {
EditorEntityType editorEntityType = mock(EditorEntityType.class);
EntityType entityType = mock(EntityType.class);
when(entityTypeMapper.toEntityType(editorEntityType)).thenReturn(entityType);
metadataManagerService.upsertEntityType(editorEntityType);
verify(metaDataService, times(1)).upsertEntityTypes(newArrayList(entityType));
}
Aggregations