/*
* JBoss, Home of Professional Open Source
* Copyright 2010-2016, Red Hat, Inc. and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.richfaces.tests.metamer.ftest.richList;
import java.util.Arrays;
import java.util.List;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.richfaces.fragment.dataScroller.RichFacesDataScroller;
import org.richfaces.fragment.list.AbstractListComponent;
import org.richfaces.fragment.list.RichFacesListItem;
import org.richfaces.tests.metamer.ftest.AbstractWebDriverTest;
import org.richfaces.tests.metamer.ftest.extension.attributes.coverage.annotations.CoversAttributes;
import org.testng.Assert;
import org.testng.annotations.Test;
/**
* @author <a href="mailto:jstefek@redhat.com">Jiri Stefek</a>
*/
public class TestListWithScroller2 extends AbstractWebDriverTest {
private static final String ITERATION_STATUS_TEMPLATE = "[ begin= %d, end= %d, index= %d, count= %d, first= %b, last= %b, even= %b, rowCount= 200 ]";
private static final String RANGE_TEMPLATE = "[ firstRow: %s, rows: %s ]";
private static final int ROWS = 20;
private static final String ROWS_STRING = "20";
private static final List<Integer> items = Arrays.asList(0, 1, 10, 18, 19);
private static final List<Integer> pages = Arrays.asList(1, 2, 5, 8, 10);
@FindBy(css = "[id$=richList]")
private TestedList list;
@FindBy(css = "span.rf-ds[id$=scroller2]")
private RichFacesDataScroller scroller;
public void checkIterationStatusVar(TestedListItem li, int index, int item) {
Assert.assertEquals(li.getIterationStatusVarText(),
String.format(ITERATION_STATUS_TEMPLATE, index, index + ROWS - 1, item + index, item + 1, (item == 0), (item == 19), (item % 2 == 1)));
}
public void checkRowKeyVar(TestedListItem li, int index, int item) {
Assert.assertEquals(li.getRowKeyVarText(), String.valueOf(index + item));
}
public void checkStateVar(TestedListItem li, int index, int item) {
Assert.assertEquals(li.getFirstRowFromStateVarText(), String.valueOf(index));
Assert.assertEquals(li.getRowsFromStateVarText(), ROWS_STRING);
Assert.assertEquals(li.getRangeFromStateVarText(), String.format(RANGE_TEMPLATE, String.valueOf(index), ROWS));
}
@Override
public String getComponentTestPagePath() {
return "richList/scroller2.xhtml";
}
@Test
@CoversAttributes({ "iterationStatusVar", "stateVar", "rowKeyVar" })
public void testIterationStatusVar_StateVar_RowKey() {
TestedListItem li;
int index;
for (Integer page : pages) {
if (!page.equals(scroller.getActivePageNumber())) {
scroller.switchTo(page);
}
index = ROWS * (page - 1);
for (Integer item : items) {
li = list.getItems().get(item);
checkIterationStatusVar(li, index, item);
checkRowKeyVar(li, index, item);
checkStateVar(li, index, item);
}
}
}
public static class TestedList extends AbstractListComponent<TestedListItem> {
}
public static class TestedListItem extends RichFacesListItem {
@FindBy(css = "[id$=rowKeyVar]")
private WebElement rowKeyVar;
@FindBy(css = "[id$=iterationStatusVar]")
private WebElement iterationStatusVar;
@FindBy(css = "[id$=rangeFromStateVar]")
private WebElement rangeFromStateVar;
@FindBy(css = "[id$=rowsFromStateVar]")
private WebElement rowsFromStateVar;
@FindBy(css = "[id$=firstRowFromStateVar]")
private WebElement firstRowFromStateVar;
public String getRowKeyVarText() {
return rowKeyVar.getText();
}
public String getIterationStatusVarText() {
return iterationStatusVar.getText();
}
public String getRangeFromStateVarText() {
return rangeFromStateVar.getText();
}
public String getRowsFromStateVarText() {
return rowsFromStateVar.getText();
}
public String getFirstRowFromStateVarText() {
return firstRowFromStateVar.getText();
}
}
}