Search in sources :

Example 21 with QueryImpl

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);
}
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 22 with QueryImpl

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);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) QueryImpl(org.molgenis.data.support.QueryImpl) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 23 with QueryImpl

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);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) QueryImpl(org.molgenis.data.support.QueryImpl) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) Attribute(org.molgenis.data.meta.model.Attribute) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 24 with QueryImpl

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);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) QueryImpl(org.molgenis.data.support.QueryImpl) Attribute(org.molgenis.data.meta.model.Attribute) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 25 with QueryImpl

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);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) QueryImpl(org.molgenis.data.support.QueryImpl) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) Attribute(org.molgenis.data.meta.model.Attribute) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Aggregations

QueryImpl (org.molgenis.data.support.QueryImpl)98 Test (org.testng.annotations.Test)70 DynamicEntity (org.molgenis.data.support.DynamicEntity)37 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)36 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)36 EntityType (org.molgenis.data.meta.model.EntityType)28 Attribute (org.molgenis.data.meta.model.Attribute)25 Entity (org.molgenis.data.Entity)15 WithMockUser (org.springframework.security.test.context.support.WithMockUser)8 Stream (java.util.stream.Stream)7 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)7 AggregateQueryImpl (org.molgenis.data.support.AggregateQueryImpl)7 Objects.requireNonNull (java.util.Objects.requireNonNull)6 QueryRule (org.molgenis.data.QueryRule)6 AggregateQuery (org.molgenis.data.aggregation.AggregateQuery)6 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)6 BeforeMethod (org.testng.annotations.BeforeMethod)6 Instant (java.time.Instant)5 LocalDate (java.time.LocalDate)5 Operator (org.molgenis.data.QueryRule.Operator)5