Search in sources :

Example 11 with AggregateQuery

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

the class EntityReferenceResolverDecoratorTest method aggregate.

@Test
public void aggregate() {
    AggregateQuery aggregateQuery = mock(AggregateQuery.class);
    entityReferenceResolverDecorator.aggregate(aggregateQuery);
    verify(delegateRepository, times(1)).aggregate(aggregateQuery);
    verifyZeroInteractions(entityManager);
}
Also used : AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 12 with AggregateQuery

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

the class PlatformIT method runAggregateQuery.

private AggregateResult runAggregateQuery(String attrX, String attrY, String attrDistinct, Query<Entity> query) {
    requireNonNull(attrX);
    requireNonNull(query);
    Attribute x = entityTypeDynamic.getAttribute(attrX);
    Attribute y = attrY != null ? entityTypeDynamic.getAttribute(attrY) : null;
    Attribute distinct = attrDistinct != null ? entityTypeDynamic.getAttribute(attrDistinct) : null;
    AggregateQuery aggregateQuery = new AggregateQueryImpl(x, y, distinct, query);
    return runAsSystem(() -> dataService.aggregate(entityTypeDynamic.getId(), aggregateQuery));
}
Also used : AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) AggregateQueryImpl(org.molgenis.data.support.AggregateQueryImpl)

Example 13 with AggregateQuery

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

the class DataServiceIT method testAggregateTwoDimensionalDistinct.

@WithMockUser(username = USERNAME_READ)
@Test(groups = "readtest")
public void testAggregateTwoDimensionalDistinct() {
    AggregateQuery aggregateQuery = new AggregateQueryImpl().query(new QueryImpl<>()).attrX(entityType.getAttribute(ATTR_BOOL)).attrY(entityType.getAttribute(ATTR_BOOL)).attrDistinct(entityType.getAttribute(ATTR_ENUM));
    AggregateResult result = dataService.aggregate(entityType.getId(), aggregateQuery);
    AggregateResult expectedResult = new AggregateResult(asList(asList(1L, 0L), asList(0L, 1L)), asList(0L, 1L), asList(0L, 1L));
    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 14 with AggregateQuery

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

the class DataServiceIT method testAggregateTwoDimensionalQuery.

@WithMockUser(username = USERNAME_READ)
@Test(groups = "readtest")
public void testAggregateTwoDimensionalQuery() {
    AggregateQuery aggregateQuery = new AggregateQueryImpl().query(new QueryImpl<>()).attrX(entityType.getAttribute(ATTR_BOOL)).attrY(entityType.getAttribute(ATTR_BOOL)).query(new QueryImpl<>().gt(ATTR_INT, 10));
    AggregateResult result = dataService.aggregate(entityType.getId(), aggregateQuery);
    AggregateResult expectedResult = new AggregateResult(asList(asList(1L, 0L), asList(0L, 1L)), asList(0L, 1L), asList(0L, 1L));
    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 15 with AggregateQuery

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

the class DataServiceIT method testAggregateTwoDimensionalQueryDistinct.

@WithMockUser(username = USERNAME_READ)
@Test(groups = "readtest")
public void testAggregateTwoDimensionalQueryDistinct() {
    AggregateQuery aggregateQuery = new AggregateQueryImpl().query(new QueryImpl<>()).attrX(entityType.getAttribute(ATTR_BOOL)).attrY(entityType.getAttribute(ATTR_ENUM)).attrDistinct(entityType.getAttribute(ATTR_ENUM)).query(new QueryImpl<>().gt(ATTR_INT, 1));
    AggregateResult result = dataService.aggregate(entityType.getId(), aggregateQuery);
    AggregateResult expectedResult = new AggregateResult(asList(asList(0L, 1L), asList(1L, 0L)), asList(0L, 1L), asList("option1", "option2"));
    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)

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