@Test public void should_autogenerate_table_from_the_ajax_criterias() { request.addParameter("columns[0][data]", "id"); request.addParameter("columns[1][data]", "firstName"); request.addParameter("columns[2][data]", "lastName"); request.addParameter("columns[3][data]", "mail"); DatatablesCriterias criteria = DatatablesCriterias.getFromRequest(request); HtmlTable table = new HtmlTableBuilder<Person>() .newBuilder("tableId", persons, request, null) .auto(criteria) .build(); assertThat(table.getBodyRows()).hasSize(10); assertThat(table.getBodyRows().get(0).getColumns()).hasSize(4); assertThat(table.getBodyRows().get(0).getColumns().get(0).getContent().toString()) .isEqualTo("1"); assertThat(table.getBodyRows().get(0).getColumns().get(1).getContent().toString()) .isEqualTo("firstName1"); assertThat(table.getBodyRows().get(0).getColumns().get(2).getContent().toString()) .isEqualTo("lastName1"); assertThat(table.getBodyRows().get(0).getColumns().get(3).getContent().toString()) .isEqualTo("mail1"); assertThat(table.getBodyRows().get(9).getColumns().get(0).getContent().toString()) .isEqualTo("10"); assertThat(table.getBodyRows().get(9).getColumns().get(1).getContent().toString()) .isEqualTo("firstName10"); assertThat(table.getBodyRows().get(9).getColumns().get(2).getContent().toString()) .isEqualTo("lastName10"); assertThat(table.getBodyRows().get(9).getColumns().get(3).getContent().toString()) .isEqualTo("mail10"); }
@Test public void should_generate_table_by_extracting_property_from_the_ajax_criterias() { request.addParameter("columns[0][data]", "id"); request.addParameter("columns[1][data]", "firstName"); request.addParameter("columns[2][data]", "lastName"); request.addParameter("columns[3][data]", "mail"); DatatablesCriterias criteria = DatatablesCriterias.getFromRequest(request); HtmlTable table = new HtmlTableBuilder<Person>() .newBuilder("tableId", persons, request, null) .column() .fillFromCriteria(criteria) .title("Id") .column() .fillFromCriteria(criteria) .title("Firtname") .column() .fillFromCriteria(criteria) .title("Lastname") .column() .fillFromCriteria(criteria, "formatted-{0}") .title("Mail") .build(); assertThat(table.getBodyRows()).hasSize(10); assertThat(table.getBodyRows().get(0).getColumns()).hasSize(4); assertThat(table.getBodyRows().get(0).getColumns().get(0).getContent().toString()) .isEqualTo("1"); assertThat(table.getBodyRows().get(0).getColumns().get(1).getContent().toString()) .isEqualTo("firstName1"); assertThat(table.getBodyRows().get(0).getColumns().get(2).getContent().toString()) .isEqualTo("lastName1"); assertThat(table.getBodyRows().get(0).getColumns().get(3).getContent().toString()) .isEqualTo("formatted-mail1"); assertThat(table.getBodyRows().get(9).getColumns().get(0).getContent().toString()) .isEqualTo("10"); assertThat(table.getBodyRows().get(9).getColumns().get(1).getContent().toString()) .isEqualTo("firstName10"); assertThat(table.getBodyRows().get(9).getColumns().get(2).getContent().toString()) .isEqualTo("lastName10"); assertThat(table.getBodyRows().get(9).getColumns().get(3).getContent().toString()) .isEqualTo("formatted-mail10"); }