@Test
public void getVisualizationGridByUserWhenItHasOrganisationUnitLevels()
{

    // Given
    final String anyVisualizationUid = "adbet5RTs";
    final Date anyRelativePeriodDate = new Date();
    final String anyOrganisationUnitUid = "ouiRzW5e";
    final User userStub = userStub();
    final List<Integer> orgUnitLevels = asList( 1, 2 );
    final List<OrganisationUnit> orgUnits = asList( new OrganisationUnit() );
    final Map<String, Object> valueMap = valueMapStub();
    final Visualization visualizationStub = visualizationStub( "abc123xy" );
    visualizationStub.setOrganisationUnitLevels( orgUnitLevels );
    visualizationStub.setOrganisationUnits( orgUnits );
    final Visualization visualizationSpy = spy( visualizationStub );
    // When
    when( visualizationStore.getByUid( anyVisualizationUid ) ).thenReturn( visualizationSpy );
    when( analyticsService.getAggregatedDataValueMapping( visualizationSpy ) ).thenReturn( valueMap );
    final Grid expectedGrid = defaultVisualizationService.getVisualizationGridByUser( anyVisualizationUid,
        anyRelativePeriodDate, anyOrganisationUnitUid, userStub );
    // Then
    assertThat( expectedGrid.getRows(), hasSize( 1 ) );
    assertThat( expectedGrid.getRows().get( 0 ), hasSize( 7 ) );
    assertThat( expectedGrid.getRows().get( 0 ), hasItem( "abc123xy" ) );
    assertThat( expectedGrid.getHeaders(), hasSize( 7 ) );
    assertThat( expectedGrid.getMetaColumnIndexes(), hasSize( 7 ) );
    assertThatHeadersAreTheExpectedOnes( expectedGrid );
    verify( organisationUnitService, times( 1 ) ).getOrganisationUnitsAtLevels( orgUnitLevels, orgUnits );
    verify( visualizationSpy, times( 1 ) ).clearTransientState();
}