use of org.hisp.dhis.common.GridHeader in project dhis2-core by dhis2.
the class GridTest method testKeepOnlyThese.
@Test
void testKeepOnlyThese() {
// Given
final GridHeader headerA = new GridHeader("headerA", "Header A");
final GridHeader headerB = new GridHeader("headerB", "Header B");
final GridHeader headerC = new GridHeader("headerC", "Header C");
final Grid grid = new ListGrid();
grid.addHeader(headerA);
grid.addHeader(headerB);
grid.addHeader(headerC);
grid.addRow().addValue(1).addValue("a").addValue("a-1");
grid.addRow().addValue(2).addValue("b").addValue("b-1");
grid.addRow().addValue(3).addValue("c").addValue("c-1");
final Set<String> headers = new LinkedHashSet<>(List.of("headerA", "headerB"));
// When
grid.keepOnlyThese(headers);
// Then
assertThat(grid.getHeaderWidth(), is(equalTo(2)));
assertThat(grid.getHeaders().get(0).getName(), is(equalTo("headerA")));
assertThat(grid.getHeaders().get(1).getName(), is(equalTo("headerB")));
}
use of org.hisp.dhis.common.GridHeader in project dhis2-core by dhis2.
the class GridTest method testAddHeaderList.
@Test
void testAddHeaderList() {
Grid grid = new ListGrid();
GridHeader headerA = new GridHeader("DataElementA", "Data element A");
GridHeader headerB = new GridHeader("DataElementB", "Data element B");
GridHeader headerC = new GridHeader("DataElementC", "Data element C");
GridHeader headerD = new GridHeader("DataElementC", "Data element D");
GridHeader headerE = new GridHeader("DataElementC", "Data element E");
grid.addHeader(headerA);
grid.addHeader(headerB);
assertEquals(2, grid.getHeaders().size());
List<GridHeader> headers = Lists.newArrayList(headerC, headerD, headerE);
grid.addHeaders(1, headers);
assertEquals(5, grid.getHeaders().size());
assertEquals(headerA, grid.getHeaders().get(0));
assertEquals(headerC, grid.getHeaders().get(1));
assertEquals(headerD, grid.getHeaders().get(2));
assertEquals(headerE, grid.getHeaders().get(3));
assertEquals(headerB, grid.getHeaders().get(4));
}
use of org.hisp.dhis.common.GridHeader in project dhis2-core by dhis2.
the class GridTest method testRepositionHeadersUsingInvalidHeader.
@Test
void testRepositionHeadersUsingInvalidHeader() {
// Given
final GridHeader headerA = new GridHeader("headerA", "Header A");
final GridHeader headerB = new GridHeader("headerB", "Header B");
final GridHeader headerC = new GridHeader("headerC", "Header C");
final Grid grid = new ListGrid();
grid.addHeader(headerA);
grid.addHeader(headerB);
grid.addHeader(headerC);
grid.addRow().addValue(1).addValue("a").addValue("a-1");
grid.addRow().addValue(2).addValue("b").addValue("b-1");
grid.addRow().addValue(3).addValue("c").addValue("c-1");
final Set<String> headers = new LinkedHashSet<>(List.of("invalidHeader", "headerB", "headerA"));
// When
final IllegalQueryException expectedException = assertThrows(IllegalQueryException.class, () -> grid.repositionHeaders(headers));
// Then
assertThat(expectedException.getMessage(), is(equalTo("Header param `invalidHeader` does not exist")));
assertThat(expectedException.getErrorCode(), is(equalTo(E7230)));
}
use of org.hisp.dhis.common.GridHeader in project dhis2-core by dhis2.
the class GridTest method repositionColumns.
@Test
void repositionColumns() {
// Given
final GridHeader headerA = new GridHeader("headerA", "Header A");
final GridHeader headerB = new GridHeader("headerB", "Header B");
final GridHeader headerC = new GridHeader("headerC", "Header C");
final Grid grid = new ListGrid();
grid.addHeader(headerA);
grid.addHeader(headerB);
grid.addHeader(headerC);
// first
grid.addRow().addValue(1).addValue("a").addValue("a-1");
// row +
// columns
grid.addRow().addValue(2).addValue("b").addValue("b-1");
grid.addRow().addValue(3).addValue("c").addValue("c-1");
final Set<String> headers = new LinkedHashSet<>(List.of("headerC", "headerB", "headerA"));
final Set<Integer> newColumnIndexes = grid.repositionHeaders(headers);
// When
grid.repositionColumns(newColumnIndexes);
// Then
assertThat(grid.getHeaderWidth(), is(equalTo(3)));
// first row + repositioned columns
assertThat(grid.getRow(0).get(0), is(equalTo("a-1")));
assertThat(grid.getRow(0).get(1), is(equalTo("a")));
assertThat(grid.getRow(0).get(2), is(equalTo(1)));
// second row + repositioned columns
assertThat(grid.getRow(1).get(0), is(equalTo("b-1")));
assertThat(grid.getRow(1).get(1), is(equalTo("b")));
assertThat(grid.getRow(1).get(2), is(equalTo(2)));
// third row + repositioned columns
assertThat(grid.getRow(2).get(0), is(equalTo("c-1")));
assertThat(grid.getRow(2).get(1), is(equalTo("c")));
assertThat(grid.getRow(2).get(2), is(equalTo(3)));
}
use of org.hisp.dhis.common.GridHeader in project dhis2-core by dhis2.
the class GridTest method testRepositionHeaders.
@Test
void testRepositionHeaders() {
// Given
final GridHeader headerA = new GridHeader("headerA", "Header A");
final GridHeader headerB = new GridHeader("headerB", "Header B");
final GridHeader headerC = new GridHeader("headerC", "Header C");
final Grid grid = new ListGrid();
grid.addHeader(headerA);
grid.addHeader(headerB);
grid.addHeader(headerC);
grid.addRow().addValue(1).addValue("a").addValue("a-1");
grid.addRow().addValue(2).addValue("b").addValue("b-1");
grid.addRow().addValue(3).addValue("c").addValue("c-1");
final Set<String> headers = new LinkedHashSet<>(List.of("headerC", "headerB", "headerA"));
// When
grid.repositionHeaders(headers);
// Then
assertThat(grid.getHeaderWidth(), is(equalTo(3)));
assertThat(grid.getHeaders().get(0).getName(), is(equalTo("headerC")));
assertThat(grid.getHeaders().get(1).getName(), is(equalTo("headerB")));
assertThat(grid.getHeaders().get(2).getName(), is(equalTo("headerA")));
}
Aggregations