Skip to content

Commit

Permalink
[GEOS-7893] GeoServerTabelPanel shows the correct number of results
Browse files Browse the repository at this point in the history
  • Loading branch information
tbarsballe committed May 26, 2017
1 parent e1c38bb commit b2ab438
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -580,12 +580,10 @@ public PagerDelegate() {
* Updates the label given the current page and filtering status
*/
void updateMatched() {
size = dataProvider.size();
fullSize = dataProvider.fullSize();
first = first(fullSize);
last = last(fullSize);
if (dataProvider.getKeywords() != null) {
size = dataProvider.size();
}
first = first(size);
last = last(size);
}

public IModel<String> model() {
Expand All @@ -598,9 +596,10 @@ public IModel<String> model() {

/**
* User oriented index of the first item in the current page
*
* @param size The total number of items matched by the current filter
*/
long first(long fullSize) {
long size = fullSize;
long first(long size) {
if (dataProvider.getKeywords() != null) {
size = dataView.getDataProvider().size();
}
Expand All @@ -612,16 +611,17 @@ long first(long fullSize) {

/**
* User oriented index of the last item in the current page
*
* @param size The total number of items matched by the current filter
*/
long last(long fullSize) {
long last(long size) {

long count = dataProvider.getKeywords() != null ?
dataView.getPageCount() : optGetPageCount(fullSize);
long count = optGetPageCount(size);
long page = dataView.getCurrentPage();
if (page < (count - 1))
return dataView.getItemsPerPage() * (page + 1);
else {
return dataProvider.getKeywords() != null ? dataView.getDataProvider().size() : fullSize;
return dataProvider.getKeywords() != null ? dataView.getDataProvider().size() : size;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import org.apache.wicket.Component;
Expand All @@ -28,19 +29,17 @@
public class GeoServerTablePanelTest {
WicketTester tester;

static final int TOTAL_ITEMS = 40;
static final int DEFAULT_ITEMS_PER_PAGE = 25;

@Before
public void setUp() throws Exception {
tester = new WicketTester();
}

@Test
public void testBasicTable() throws Exception {
tester.startPage(new FormTestPage(new ComponentBuilder() {

public Component buildComponent(String id) {
return new IntegerTable(id, false);
}
}));
tester.startPage(new FormTestPage((ComponentBuilder) id -> new IntegerTable(id, false)));
tester.assertComponent("form:panel", IntegerTable.class);

// check the contents are as expected
Expand All @@ -50,17 +49,12 @@ public Component buildComponent(String id) {

// check we actually rendered 10 rows
DataView dv = (DataView) tester.getComponentFromLastRenderedPage("form:panel:listContainer:items");
assertEquals(10, dv.size());
assertEquals(DEFAULT_ITEMS_PER_PAGE, dv.size());
}

@Test
public void testFullSelection() throws Exception {
tester.startPage(new FormTestPage(new ComponentBuilder() {

public Component buildComponent(String id) {
return new IntegerTable(id, true);
}
}));
tester.startPage(new FormTestPage((ComponentBuilder) id -> new IntegerTable(id, true)));
tester.assertComponent("form:panel", IntegerTable.class);
IntegerTable table = (IntegerTable) tester.getComponentFromLastRenderedPage("form:panel");

Expand All @@ -75,7 +69,7 @@ public Component buildComponent(String id) {
FormTester ft = tester.newFormTester("form");
ft.setValue("panel:listContainer:selectAllContainer:selectAll", "true");
tester.executeAjaxEvent(selectAllPath, "click");
assertEquals(10, table.getSelection().size());
assertEquals(DEFAULT_ITEMS_PER_PAGE, table.getSelection().size());
assertEquals(new Integer(0), table.getSelection().get(0));

// reset selection
Expand All @@ -85,12 +79,7 @@ public Component buildComponent(String id) {

@Test
public void testSingleSelection() throws Exception {
tester.startPage(new FormTestPage(new ComponentBuilder() {

public Component buildComponent(String id) {
return new IntegerTable(id, true);
}
}));
tester.startPage(new FormTestPage((ComponentBuilder) id -> new IntegerTable(id, true)));
tester.assertComponent("form:panel", IntegerTable.class);
IntegerTable table = (IntegerTable) tester.getComponentFromLastRenderedPage("form:panel");
assertEquals(0, table.getSelection().size());
Expand All @@ -107,12 +96,7 @@ public Component buildComponent(String id) {

@Test
public void testSingleSelectionByObjectAndIndex() throws Exception {
tester.startPage(new FormTestPage(new ComponentBuilder() {

public Component buildComponent(String id) {
return new IntegerTable(id, true);
}
}));
tester.startPage(new FormTestPage((ComponentBuilder) id -> new IntegerTable(id, true)));
tester.assertComponent("form:panel", IntegerTable.class);

IntegerTable table = (IntegerTable) tester.getComponentFromLastRenderedPage("form:panel");
Expand All @@ -128,6 +112,32 @@ public Component buildComponent(String id) {
assertEquals(new Integer(7), table.getSelection().get(1));
}

@Test
public void testFilter() {
tester.startPage(new FormTestPage((ComponentBuilder) id -> new IntegerTable(id, true)));

// verify the initial state
tester.assertComponent("form:panel", IntegerTable.class);

DataView dv = (DataView) tester.getComponentFromLastRenderedPage("form:panel:listContainer:items");
assertEquals(25, dv.size());

String filterLabelPath = "form:panel:filterForm:navigatorTop:filterMatch";
tester.assertComponent(filterLabelPath, Label.class);
tester.assertLabel(filterLabelPath, "1 -&gt; 25 of 40");

// search by "5"
FormTester ft = tester.newFormTester("form:panel:filterForm");
ft.setValue("filter", "5");
ft.submit("submit");

// verify the search returned the expected number of results
dv = (DataView) tester.getComponentFromLastRenderedPage("form:panel:listContainer:items");
assertEquals(4, dv.size());
// verify the label was updated correctly
tester.assertLabel("form:panel:filterForm:navigatorTop:filterMatch", "1 -&gt; 4 of 4/40");
}

static class IntegerTable extends GeoServerTablePanel<Integer> {

public IntegerTable(String id, boolean selectable) {
Expand Down Expand Up @@ -161,12 +171,42 @@ IModel matchedXOutOfY(long first, long last, long size, long fullSize) {

static class IntegerProvider extends GeoServerDataProvider<Integer> {

static final Property<Integer> IDX = new PropertyPlaceholder<Integer>("idx");
static final Property<Integer> IDX = new Property<Integer>() {
@Override
public String getName() {
return "idx";
}

@Override
public Object getPropertyValue(Integer item) {
return item;
}

@Override
public IModel<?> getModel(IModel<Integer> itemModel) {
return null;
}

@Override
public Comparator<Integer> getComparator() {
return null;
}

@Override
public boolean isVisible() {
return true;
}

@Override
public boolean isSearchable() {
return true;
}
};

@Override
protected List<Integer> getItems() {
List<Integer> result = new ArrayList<Integer>();
for (int i = 0; i < 10; i++) {
for (int i = 0; i < TOTAL_ITEMS; i++) {
result.add(i);
}
return result;
Expand Down

0 comments on commit b2ab438

Please sign in to comment.