use of org.molgenis.data.support.QueryImpl 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.support.QueryImpl in project molgenis by molgenis.
the class EntityTypeRepositorySecurityDecoratorTest method countQuery.
@WithMockUser(username = USERNAME)
@Test
public void countQuery() {
String entityType0Name = "entity0";
EntityType entityType0 = when(mock(EntityType.class).getId()).thenReturn(entityType0Name).getMock();
String entityType1Name = "entity1";
EntityType entityType1 = when(mock(EntityType.class).getId()).thenReturn(entityType1Name).getMock();
Query q = new QueryImpl<>();
@SuppressWarnings("unchecked") ArgumentCaptor<Query> queryCaptor = forClass(Query.class);
when(delegateRepository.findAll(queryCaptor.capture())).thenReturn(Stream.of(entityType0, entityType1));
doReturn(false).when(permissionService).hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT);
doReturn(true).when(permissionService).hasPermission(new EntityTypeIdentity(entityType1Name), EntityTypePermission.COUNT);
assertEquals(repo.count(q), 1L);
assertEquals(queryCaptor.getValue().getOffset(), 0);
assertEquals(queryCaptor.getValue().getPageSize(), Integer.MAX_VALUE);
}
use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.
the class AttributeRepositorySecurityDecoratorTest method findAllQueryUser.
@WithMockUser(username = USERNAME)
@Test
public void findAllQueryUser() throws Exception {
String entityType0Name = "entity0";
EntityType entityType0 = when(mock(EntityType.class).getId()).thenReturn(entityType0Name).getMock();
String entityType1Name = "entity1";
EntityType entityType1 = when(mock(EntityType.class).getId()).thenReturn(entityType1Name).getMock();
String attr0Name = "entity0attr0";
Attribute attr0 = when(mock(Attribute.class).getName()).thenReturn(attr0Name).getMock();
when(attr0.getEntity()).thenReturn(entityType0);
String attr1Name = "entity1attr0";
Attribute attr1 = when(mock(Attribute.class).getName()).thenReturn(attr1Name).getMock();
when(attr1.getEntity()).thenReturn(entityType1);
Query<Attribute> q = new QueryImpl<>();
@SuppressWarnings("unchecked") ArgumentCaptor<Query<Attribute>> queryCaptor = forClass(Query.class);
when(delegateRepository.findAll(queryCaptor.capture())).thenReturn(Stream.of(attr0, attr1));
when(permissionService.hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT)).thenReturn(false);
when(permissionService.hasPermission(new EntityTypeIdentity(entityType1Name), EntityTypePermission.COUNT)).thenReturn(true);
assertEquals(repo.findAll(q).collect(toList()), singletonList(attr1));
assertEquals(queryCaptor.getValue().getOffset(), 0);
assertEquals(queryCaptor.getValue().getPageSize(), Integer.MAX_VALUE);
}
use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.
the class AttributeRepositorySecurityDecoratorTest method findOneQueryUserPermissionAllowed.
@WithMockUser(username = USERNAME)
@Test
public void findOneQueryUserPermissionAllowed() throws Exception {
String entityType0Name = "entity0";
EntityType entityType0 = when(mock(EntityType.class).getId()).thenReturn(entityType0Name).getMock();
String attr0Name = "entity0attr0";
Attribute attr0 = when(mock(Attribute.class).getName()).thenReturn(attr0Name).getMock();
when(attr0.getEntity()).thenReturn(entityType0);
Query<Attribute> q = new QueryImpl<>();
when(delegateRepository.findOne(q)).thenReturn(attr0);
when(permissionService.hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT)).thenReturn(true);
assertEquals(repo.findOne(q), attr0);
}
use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.
the class AttributeRepositorySecurityDecoratorTest method countQueryUser.
@WithMockUser(username = USERNAME)
@Test
public void countQueryUser() throws Exception {
String entityType0Name = "entity0";
EntityType entityType0 = when(mock(EntityType.class).getId()).thenReturn(entityType0Name).getMock();
String entityType1Name = "entity1";
EntityType entityType1 = when(mock(EntityType.class).getId()).thenReturn(entityType1Name).getMock();
String attr0Name = "entity0attr0";
Attribute attr0 = when(mock(Attribute.class).getName()).thenReturn(attr0Name).getMock();
when(attr0.getEntity()).thenReturn(entityType0);
String attr1Name = "entity1attr0";
Attribute attr1 = when(mock(Attribute.class).getName()).thenReturn(attr1Name).getMock();
when(attr1.getEntity()).thenReturn(entityType1);
Query<Attribute> q = new QueryImpl<>();
@SuppressWarnings("unchecked") ArgumentCaptor<Query<Attribute>> queryCaptor = forClass(Query.class);
when(delegateRepository.findAll(queryCaptor.capture())).thenReturn(Stream.of(attr0, attr1));
when(permissionService.hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT)).thenReturn(false);
when(permissionService.hasPermission(new EntityTypeIdentity(entityType1Name), EntityTypePermission.COUNT)).thenReturn(true);
assertEquals(repo.count(q), 1L);
assertEquals(queryCaptor.getValue().getOffset(), 0);
assertEquals(queryCaptor.getValue().getPageSize(), Integer.MAX_VALUE);
}
Aggregations