Author: lfryc(a)redhat.com
Date: 2010-07-29 04:46:46 -0400 (Thu, 29 Jul 2010)
New Revision: 18276
Added:
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataGrid.java
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataGrid/
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataGrid/TestSimple.java
Modified:
root/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/Model.java
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/MetamerProperties.java
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jOutputPanel/TestA4JOutputPanel.java
Log:
added DataGrid test case; fixed passing default value of templates property from maven to
MatrixConfigurator; derived static metod for loading List<Capital> in bean/Model
Modified:
root/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/Model.java
===================================================================
---
root/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/Model.java 2010-07-29
07:39:45 UTC (rev 18275)
+++
root/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/Model.java 2010-07-29
08:46:46 UTC (rev 18276)
@@ -94,13 +94,8 @@
*/
public synchronized List<Capital> getCapitals() {
if (capitalsList == null) {
- ClassLoader ccl = Thread.currentThread().getContextClassLoader();
- URL resource =
ccl.getResource("org/richfaces/tests/metamer/model/capitals.xml");
- JAXBContext context;
try {
- context = JAXBContext.newInstance(CapitalsHolder.class);
- CapitalsHolder capitalsHolder = (CapitalsHolder)
context.createUnmarshaller().unmarshal(resource);
- capitalsList = capitalsHolder.getCapitals();
+ capitalsList = unmarshallCapitals();
} catch (JAXBException e) {
throw new FacesException(e.getMessage(), e);
}
@@ -110,6 +105,22 @@
}
/**
+ * Unmarshalls the list of capitals
+ *
+ * @return the list of capitals
+ * @throws JAXBException
+ * if any unexpected errors occurs during unmarshalling
+ */
+ @SuppressWarnings("restriction")
+ public static final List<Capital> unmarshallCapitals() throws JAXBException {
+ ClassLoader ccl = Thread.currentThread().getContextClassLoader();
+ URL resource =
ccl.getResource("org/richfaces/tests/metamer/model/capitals.xml");
+ JAXBContext context = JAXBContext.newInstance(CapitalsHolder.class);
+ CapitalsHolder capitalsHolder = (CapitalsHolder)
context.createUnmarshaller().unmarshal(resource);
+ return capitalsHolder.getCapitals();
+ }
+
+ /**
* Model containing employees. Can be used to test various components inside
iteration components.
*
* @return list of employees
Modified:
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/MetamerProperties.java
===================================================================
---
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/MetamerProperties.java 2010-07-29
07:39:45 UTC (rev 18275)
+++
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/MetamerProperties.java 2010-07-29
08:46:46 UTC (rev 18276)
@@ -40,7 +40,7 @@
public static List<TemplatesList> getTemplates() {
final String templatesString = System.getProperty("templates");
- if (templatesString == null) {
+ if (templatesString == null || "null".equals(templatesString) ||
"".equals(templatesString)) {
return null;
}
Modified:
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jOutputPanel/TestA4JOutputPanel.java
===================================================================
---
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jOutputPanel/TestA4JOutputPanel.java 2010-07-29
07:39:45 UTC (rev 18275)
+++
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jOutputPanel/TestA4JOutputPanel.java 2010-07-29
08:46:46 UTC (rev 18276)
@@ -72,9 +72,9 @@
public URL getTestUrl() {
return buildUrl(contextPath,
"faces/components/a4jOutputPanel/simple.xhtml");
}
-
+
+ @Test
@Uses({ @Use(field = "event", value = "events"), @Use(field =
"layout", value = "layouts") })
- @Test
public void testEvent() {
JQueryLocator element = null;
Added:
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataGrid.java
===================================================================
---
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataGrid.java
(rev 0)
+++
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataGrid.java 2010-07-29
08:46:46 UTC (rev 18276)
@@ -0,0 +1,37 @@
+package org.richfaces.tests.metamer.ftest.model;
+
+import static org.jboss.test.selenium.locator.reference.ReferencedLocator.ref;
+import static org.jboss.test.selenium.locator.LocatorFactory.*;
+
+import org.jboss.test.selenium.framework.AjaxSelenium;
+import org.jboss.test.selenium.framework.AjaxSeleniumProxy;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.jboss.test.selenium.locator.reference.ReferencedLocator;
+
+public class DataGrid extends AbstractModel<JQueryLocator> {
+
+ AjaxSelenium selenium = AjaxSeleniumProxy.getInstance();
+
+ ReferencedLocator<JQueryLocator> rows = ref(root, "> tbody.rf-dg-body
> tr.rf-dg-r");
+ JQueryLocator rowToColumn = jq("td.rf-dg-c:not(:empty)");
+
+ public DataGrid(JQueryLocator root) {
+ super(root);
+ }
+
+ public int getElementCount() {
+ return selenium.getCount(rows.getChild(rowToColumn));
+ }
+
+ public int getColumnCount() {
+ return selenium.getCount(rows.getNthOccurence(1).getChild(rowToColumn));
+ }
+
+ public int getRowCount() {
+ return selenium.getCount(rows.getChild(rowToColumn).getNthChildElement(1));
+ }
+
+ public JQueryLocator getElement(int row, int column) {
+ return
rows.getNthOccurence(row).getChild(rowToColumn).getNthChildElement(column);
+ }
+}
Added:
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataGrid/TestSimple.java
===================================================================
---
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataGrid/TestSimple.java
(rev 0)
+++
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataGrid/TestSimple.java 2010-07-29
08:46:46 UTC (rev 18276)
@@ -0,0 +1,122 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.richDataGrid;
+
+import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardHttp;
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+
+import java.net.URL;
+import java.util.List;
+
+import javax.xml.bind.JAXBException;
+
+import org.jboss.test.selenium.locator.ElementLocator;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.richfaces.tests.metamer.bean.Model;
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.richfaces.tests.metamer.ftest.annotations.Inject;
+import org.richfaces.tests.metamer.ftest.annotations.Use;
+import org.richfaces.tests.metamer.ftest.model.DataGrid;
+import org.richfaces.tests.metamer.model.Capital;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import static org.jboss.test.selenium.locator.LocatorFactory.*;
+import static org.testng.Assert.*;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class TestSimple extends AbstractMetamerTest {
+
+ private static final int ELEMENTS_TOTAL = 50;
+
+ List<Capital> capitals;
+
+ JQueryLocator attributeColumns = pjq("input[id$=columnsInput]");
+ JQueryLocator attributeElements = pjq("input[id$=elementsInput]");
+
+ DataGrid dataGrid = new DataGrid(jq("table.rf-dg[id$=richDataGrid]"));
+
+ @Inject
+ @Use(ints = { 3 })
+ Integer columns;
+
+ @Inject
+ @Use(empty = true)
+ Integer elements;
+
+ @SuppressWarnings("restriction")
+ public TestSimple() throws JAXBException {
+ capitals = Model.unmarshallCapitals();
+ }
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/richDataGrid/simple.xhtml");
+ }
+
+ @BeforeMethod
+ public void prepareAttributes() {
+ prepareAttribute(attributeColumns, columns);
+ prepareAttribute(attributeElements, elements);
+ }
+
+ private void prepareAttribute(ElementLocator<?> inputLocator, Object value) {
+ String v = value == null ? "" : value.toString();
+ guardHttp(selenium).type(inputLocator, v);
+ }
+
+ @Test
+ @Use(field = "columns", ints = { 1, 3, 11, ELEMENTS_TOTAL / 2,
ELEMENTS_TOTAL })
+ public void testColumnsAttribute() {
+ elements = ELEMENTS_TOTAL;
+ verifyCounts();
+
+ int columnCount = dataGrid.getColumnCount();
+ int rowCount = dataGrid.getRowCount();
+ rowIteration: for (int r = 1; r <= rowCount; r++) {
+ for (int c = 1; c <= columnCount; c++) {
+ final int index = ((r - 1) * columnCount) + c - 1;
+ if (index >= ELEMENTS_TOTAL) {
+ break rowIteration;
+ }
+ String expectedStateName = capitals.get(index).getState();
+ String stateName = selenium.getText(dataGrid.getElement(r,
c).getChild(jq("span")));
+ assertEquals(stateName, expectedStateName);
+ }
+ }
+ }
+
+ @Test
+ @Use(field = "elements", ints = { 0, 1, 3, 5, 7 })
+ public void testElementsAttribute() {
+ assertEquals(dataGrid.getElementCount(), (int) elements);
+ }
+
+ private void verifyCounts() {
+ assertEquals(dataGrid.getElementCount(), (int) elements);
+ assertEquals(dataGrid.getColumnCount(), (int) columns);
+ assertEquals(dataGrid.getRowCount(), (int) Math.ceil((float) elements /
columns));
+ }
+}