Search in sources :

Example 1 with AggregateResultResponse

use of org.molgenis.data.rest.v2.EntityAggregatesResponse.AggregateResultResponse in project molgenis by molgenis.

the class EntityAggregatesResponseTest method testAggregateResultResponseToResponseAggregateResult.

// regression test for https://github.com/molgenis/molgenis/issues/6581
@Test
public void testAggregateResultResponseToResponseAggregateResult() {
    EntityType entityType = mock(EntityType.class);
    Attribute longAttribute = when(mock(Attribute.class).getDataType()).thenReturn(LONG).getMock();
    when(longAttribute.getName()).thenReturn("longAttribute");
    Iterable<Attribute> attributes = singletonList(longAttribute);
    when(entityType.getAtomicAttributes()).thenReturn(attributes);
    Entity entity = mock(Entity.class);
    when(entity.get("longAttribute")).thenReturn(123L);
    when(entity.getEntityType()).thenReturn(entityType);
    List<List<Long>> matrix = emptyList();
    List<Object> xLabels = Collections.singletonList(entity);
    List<Object> yLabels = emptyList();
    AggregateResult aggregateResult = mock(AggregateResult.class);
    when(aggregateResult.getMatrix()).thenReturn(matrix);
    when(aggregateResult.getxLabels()).thenReturn(xLabels);
    when(aggregateResult.getyLabels()).thenReturn(yLabels);
    AggregateResultResponse aggregateResultResponse = AggregateResultResponse.toResponse(aggregateResult);
    assertEquals(aggregateResultResponse.getMatrix(), matrix);
    assertEquals(aggregateResultResponse.getxLabels(), singletonList(singletonMap("longAttribute", "123")));
    assertEquals(aggregateResultResponse.getyLabels(), emptyList());
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Entity(org.molgenis.data.Entity) Attribute(org.molgenis.data.meta.model.Attribute) AggregateResult(org.molgenis.data.aggregation.AggregateResult) List(java.util.List) AggregateResultResponse(org.molgenis.data.rest.v2.EntityAggregatesResponse.AggregateResultResponse) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Aggregations

List (java.util.List)1 Entity (org.molgenis.data.Entity)1 AggregateResult (org.molgenis.data.aggregation.AggregateResult)1 Attribute (org.molgenis.data.meta.model.Attribute)1 EntityType (org.molgenis.data.meta.model.EntityType)1 AggregateResultResponse (org.molgenis.data.rest.v2.EntityAggregatesResponse.AggregateResultResponse)1 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)1 Test (org.testng.annotations.Test)1