Search in sources :

Example 16 with AggregateQuery

use of org.molgenis.data.aggregation.AggregateQuery in project molgenis by molgenis.

the class IndexedRepositoryDecoratorTest method aggregateUnknownIndexExceptionUnrecoverable.

@Test(expectedExceptions = MolgenisDataException.class, expectedExceptionsMessageRegExp = "Error executing query, index for entity type 'My entity type' with id 'entity' does not exist")
public void aggregateUnknownIndexExceptionUnrecoverable() {
    AggregateQuery aggregateQuery = mock(AggregateQuery.class);
    when(searchService.aggregate(repositoryEntityType, aggregateQuery)).thenThrow(new UnknownIndexException("msg"));
    indexedRepositoryDecorator.aggregate(aggregateQuery);
}
Also used : UnknownIndexException(org.molgenis.data.index.exception.UnknownIndexException) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) Test(org.testng.annotations.Test)

Example 17 with AggregateQuery

use of org.molgenis.data.aggregation.AggregateQuery in project molgenis by molgenis.

the class DataServiceIT method testAggregateOneDimensionalDistinct.

@WithMockUser(username = USERNAME_READ)
@Test(groups = "readtest")
public void testAggregateOneDimensionalDistinct() {
    AggregateQuery aggregateQuery = new AggregateQueryImpl().query(new QueryImpl<>()).attrX(entityType.getAttribute(ATTR_BOOL)).attrDistinct(entityType.getAttribute(ATTR_ENUM));
    AggregateResult result = dataService.aggregate(entityType.getId(), aggregateQuery);
    AggregateResult expectedResult = new AggregateResult(asList(singletonList(1L), singletonList(1L)), asList(0L, 1L), emptyList());
    assertEquals(result, expectedResult);
}
Also used : AggregateResult(org.molgenis.data.aggregation.AggregateResult) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) AggregateQueryImpl(org.molgenis.data.support.AggregateQueryImpl) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 18 with AggregateQuery

use of org.molgenis.data.aggregation.AggregateQuery in project molgenis by molgenis.

the class DataServiceIT method testAggregateTwoDimensional.

@WithMockUser(username = USERNAME_READ)
@Test(groups = "readtest")
public void testAggregateTwoDimensional() {
    AggregateQuery aggregateQuery = new AggregateQueryImpl().query(new QueryImpl<>()).attrX(entityType.getAttribute(ATTR_BOOL)).attrY(entityType.getAttribute(ATTR_ENUM));
    AggregateResult result = dataService.aggregate(entityType.getId(), aggregateQuery);
    AggregateResult expectedResult = new AggregateResult(asList(asList(0L, 1L), asList(2L, 0L)), asList(0L, 1L), asList("option1", "option2"));
    assertEquals(result, expectedResult);
}
Also used : AggregateResult(org.molgenis.data.aggregation.AggregateResult) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) AggregateQueryImpl(org.molgenis.data.support.AggregateQueryImpl) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 19 with AggregateQuery

use of org.molgenis.data.aggregation.AggregateQuery in project molgenis by molgenis.

the class DataServiceIT method testAggregateOneDimensional.

@WithMockUser(username = USERNAME_READ)
@Test(groups = "readtest")
public void testAggregateOneDimensional() {
    AggregateQuery aggregateQuery = new AggregateQueryImpl().query(new QueryImpl<>()).attrX(entityType.getAttribute(ATTR_BOOL));
    AggregateResult result = dataService.aggregate(entityType.getId(), aggregateQuery);
    AggregateResult expectedResult = new AggregateResult(asList(singletonList(1L), singletonList(2L)), asList(0L, 1L), emptyList());
    assertEquals(result, expectedResult);
}
Also used : AggregateQueryImpl(org.molgenis.data.support.AggregateQueryImpl) QueryImpl(org.molgenis.data.support.QueryImpl) AggregateResult(org.molgenis.data.aggregation.AggregateResult) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) AggregateQueryImpl(org.molgenis.data.support.AggregateQueryImpl) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 20 with AggregateQuery

use of org.molgenis.data.aggregation.AggregateQuery in project molgenis by molgenis.

the class IndexedRepositoryDecoratorTest method aggregate.

@Test
public void aggregate() {
    when(indexedRepositoryDecorator.getName()).thenReturn("entity");
    Attribute xAttr = when(mock(Attribute.class).getName()).thenReturn("xAttr").getMock();
    Attribute yAttr = when(mock(Attribute.class).getName()).thenReturn("yAttr").getMock();
    Attribute distinctAttr = when(mock(Attribute.class).getName()).thenReturn("distinctAttr").getMock();
    @SuppressWarnings("unchecked") Query<Entity> q = mock(Query.class);
    AggregateQuery aggregateQuery = new AggregateQueryImpl().attrX(xAttr).attrY(yAttr).attrDistinct(distinctAttr).query(q);
    indexedRepositoryDecorator.aggregate(aggregateQuery);
    verify(searchService).aggregate(repositoryEntityType, aggregateQuery);
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) AggregateQueryImpl(org.molgenis.data.support.AggregateQueryImpl) Test(org.testng.annotations.Test)

Aggregations

AggregateQuery (org.molgenis.data.aggregation.AggregateQuery)23 Test (org.testng.annotations.Test)19 AggregateResult (org.molgenis.data.aggregation.AggregateResult)13 WithMockUser (org.springframework.security.test.context.support.WithMockUser)10 AggregateQueryImpl (org.molgenis.data.support.AggregateQueryImpl)8 QueryImpl (org.molgenis.data.support.QueryImpl)4 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)3 UnknownIndexException (org.molgenis.data.index.exception.UnknownIndexException)2 Attribute (org.molgenis.data.meta.model.Attribute)2 EntityType (org.molgenis.data.meta.model.EntityType)1 EntityPager (org.molgenis.data.rest.EntityPager)1 AttributeFilterToFetchConverter.createDefaultAttributeFetch (org.molgenis.data.rest.v2.AttributeFilterToFetchConverter.createDefaultAttributeFetch)1 TransactionDefinition (org.springframework.transaction.TransactionDefinition)1 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)1