Search in sources :

Example 1 with OneClickImporterNamingServiceImpl

use of org.molgenis.oneclickimporter.service.impl.OneClickImporterNamingServiceImpl in project molgenis by molgenis.

the class OneClickImporterNamingServiceTest method testGetLabelWithPostFixWhenNoDuplicate.

@Test
public void testGetLabelWithPostFixWhenNoDuplicate() {
    String label = "label";
    when(dataService.findAll(ENTITY_TYPE_META_DATA, new QueryImpl<EntityType>().like(LABEL, label), EntityType.class)).thenReturn(Stream.empty());
    oneClickImporterNamingService = new OneClickImporterNamingServiceImpl(dataService);
    String actual = oneClickImporterNamingService.getLabelWithPostFix(label);
    String expected = "label";
    assertEquals(actual, expected);
}
Also used : QueryImpl(org.molgenis.data.support.QueryImpl) OneClickImporterNamingServiceImpl(org.molgenis.oneclickimporter.service.impl.OneClickImporterNamingServiceImpl) Test(org.testng.annotations.Test)

Example 2 with OneClickImporterNamingServiceImpl

use of org.molgenis.oneclickimporter.service.impl.OneClickImporterNamingServiceImpl in project molgenis by molgenis.

the class OneClickImporterNamingServiceTest method testCreateValidIdFromFileName.

@Test
public void testCreateValidIdFromFileName() {
    oneClickImporterNamingService = new OneClickImporterNamingServiceImpl(dataService);
    assertEquals(oneClickImporterNamingService.createValidIdFromFileName("test-file1.xlsx"), "test_file1");
    assertEquals(oneClickImporterNamingService.createValidIdFromFileName("test-f@#.xlsx"), "test_f_#");
    assertEquals(oneClickImporterNamingService.createValidIdFromFileName("test!##%.xlsx"), "test_##_");
}
Also used : OneClickImporterNamingServiceImpl(org.molgenis.oneclickimporter.service.impl.OneClickImporterNamingServiceImpl) Test(org.testng.annotations.Test)

Example 3 with OneClickImporterNamingServiceImpl

use of org.molgenis.oneclickimporter.service.impl.OneClickImporterNamingServiceImpl 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 4 with OneClickImporterNamingServiceImpl

use of org.molgenis.oneclickimporter.service.impl.OneClickImporterNamingServiceImpl in project molgenis by molgenis.

the class OneClickImporterNamingServiceTest method testGetLabelWithPostFixWhenFiveDuplicate.

@Test
public void testGetLabelWithPostFixWhenFiveDuplicate() {
    EntityType e1 = Mockito.mock(EntityType.class);
    when(e1.getLabel()).thenReturn("label");
    EntityType e2 = Mockito.mock(EntityType.class);
    when(e2.getLabel()).thenReturn("label (1)");
    EntityType e3 = Mockito.mock(EntityType.class);
    when(e3.getLabel()).thenReturn("label (2)");
    EntityType e4 = Mockito.mock(EntityType.class);
    when(e4.getLabel()).thenReturn("label (3)");
    EntityType e5 = Mockito.mock(EntityType.class);
    when(e5.getLabel()).thenReturn("label (4)");
    String label = "label";
    when(dataService.findAll(ENTITY_TYPE_META_DATA, new QueryImpl<EntityType>().like(LABEL, label), EntityType.class)).thenReturn(Stream.of(e1, e2, e3, e4, e5));
    oneClickImporterNamingService = new OneClickImporterNamingServiceImpl(dataService);
    String actual = oneClickImporterNamingService.getLabelWithPostFix(label);
    String expected = "label (5)";
    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 5 with OneClickImporterNamingServiceImpl

use of org.molgenis.oneclickimporter.service.impl.OneClickImporterNamingServiceImpl in project molgenis by molgenis.

the class OneClickImporterNamingServiceTest method testAsValidAttributeName.

@Test
public void testAsValidAttributeName() {
    oneClickImporterNamingService = new OneClickImporterNamingServiceImpl(dataService);
    assertEquals(oneClickImporterNamingService.asValidColumnName("name#!3"), "name#_3");
}
Also used : OneClickImporterNamingServiceImpl(org.molgenis.oneclickimporter.service.impl.OneClickImporterNamingServiceImpl) Test(org.testng.annotations.Test)

Aggregations

OneClickImporterNamingServiceImpl (org.molgenis.oneclickimporter.service.impl.OneClickImporterNamingServiceImpl)6 Test (org.testng.annotations.Test)6 QueryImpl (org.molgenis.data.support.QueryImpl)4 EntityType (org.molgenis.data.meta.model.EntityType)3