Search in sources :

Example 41 with EntityType

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");
}
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 42 with EntityType

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);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) QueryImpl(org.molgenis.data.support.QueryImpl) OneClickImporterNamingServiceImpl(org.molgenis.oneclickimporter.service.impl.OneClickImporterNamingServiceImpl) Test(org.testng.annotations.Test)

Example 43 with EntityType

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)));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EditorEntityTypeIdentifier(org.molgenis.metadata.manager.model.EditorEntityTypeIdentifier) Test(org.testng.annotations.Test)

Example 44 with EntityType

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);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Test(org.testng.annotations.Test)

Example 45 with EntityType

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));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Test(org.testng.annotations.Test)

Aggregations

EntityType (org.molgenis.data.meta.model.EntityType)581 Test (org.testng.annotations.Test)367 Attribute (org.molgenis.data.meta.model.Attribute)315 Entity (org.molgenis.data.Entity)98 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)71 DynamicEntity (org.molgenis.data.support.DynamicEntity)61 Stream (java.util.stream.Stream)44 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)43 WithMockUser (org.springframework.security.test.context.support.WithMockUser)40 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)36 QueryImpl (org.molgenis.data.support.QueryImpl)33 Package (org.molgenis.data.meta.model.Package)32 Objects.requireNonNull (java.util.Objects.requireNonNull)22 Collectors.toList (java.util.stream.Collectors.toList)22 BeforeMethod (org.testng.annotations.BeforeMethod)20 AttributeType (org.molgenis.data.meta.AttributeType)19 List (java.util.List)17 String.format (java.lang.String.format)16 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)16 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)15