Author: lfryc(a)redhat.com
Date: 2010-09-23 05:32:03 -0400 (Thu, 23 Sep 2010)
New Revision: 19321
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jRegion/
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jRegion/NestedRegionModel.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jRegion/TestNestedRegion.java
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JRegionBean.java
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jRegion/nested.xhtml
Log:
initial tests for a4j:region - nested sample (RFPL-724)
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JRegionBean.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JRegionBean.java 2010-09-23
09:30:45 UTC (rev 19320)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JRegionBean.java 2010-09-23
09:32:03 UTC (rev 19321)
@@ -47,9 +47,10 @@
public class A4JRegionBean implements Serializable {
private static final long serialVersionUID = -1L;
- private static final SelectItem[] AVAILABLE_EXECUTE_OPTIONS = new SelectItem[]{
- new SelectItem(null, "default"), new SelectItem("@region"),
new SelectItem("@all"), new SelectItem("@this")
- };
+ private static final SelectItem[] AVAILABLE_EXECUTE_OPTIONS = new SelectItem[] { new
SelectItem(null, "default"),
+ new SelectItem("@all"), new SelectItem("@form"), new
SelectItem("@region"), new SelectItem("@this"),
+ new SelectItem("outerValueInput", "Outer"), new
SelectItem("regionValueInput", "Region"),
+ new SelectItem("nestedRegionValueInput", "Nested region") };
private static Logger logger;
// for page simple.xhtml
private Attributes attributes;
@@ -151,12 +152,10 @@
}
public String getOuterExecute() {
- logger.error("getOuterExecute " + outerExecute);
return outerExecute;
}
public void setOuterExecute(String outerExecute) {
- logger.error("setOuterExecute " + outerExecute);
this.outerExecute = outerExecute;
}
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jRegion/nested.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jRegion/nested.xhtml 2010-09-23
09:30:45 UTC (rev 19320)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jRegion/nested.xhtml 2010-09-23
09:32:03 UTC (rev 19321)
@@ -64,19 +64,22 @@
<a4j:ajax event="change" render="outerSelect,
regionSelect, nestedRegionSelect" execute="@this"/>
</h:selectOneMenu>
- <h:outputLabel id="outerSelectLabel" value="Out of
region" for="outerSelect"/>
- <h:selectOneMenu id="outerSelect"
value="#{a4jRegionBean.outerExecute}" onchange="submit()">
+ <h:outputLabel id="outerSelectLabel" value="Outer"
for="outerSelect"/>
+ <h:selectOneMenu id="outerSelect"
value="#{a4jRegionBean.outerExecute}">
<f:selectItems value="#{a4jRegionBean.executeOptions}"
/>
+ <a4j:ajax event="change" render="outerSelect"
execute="@this"/>
</h:selectOneMenu>
<h:outputLabel id="regionSelectLabel"
value="Region" for="regionSelect"/>
- <h:selectOneMenu id="regionSelect"
value="#{a4jRegionBean.execute}" onchange="submit()">
+ <h:selectOneMenu id="regionSelect"
value="#{a4jRegionBean.execute}">
<f:selectItems value="#{a4jRegionBean.executeOptions}"
/>
+ <a4j:ajax event="change" render="regionSelect"
execute="@this"/>
</h:selectOneMenu>
<h:outputLabel id="nestedRegionSelectLabel"
value="Nested region" for="nestedRegionSelect" />
- <h:selectOneMenu id="nestedRegionSelect"
value="#{a4jRegionBean.nestedExecute}" onchange="submit()">
+ <h:selectOneMenu id="nestedRegionSelect"
value="#{a4jRegionBean.nestedExecute}">
<f:selectItems value="#{a4jRegionBean.executeOptions}"
/>
+ <a4j:ajax event="change"
render="nestedRegionSelect" execute="@this"/>
</h:selectOneMenu>
</h:panelGrid>
@@ -103,7 +106,7 @@
<h:inputText id="outerValueInput"
value="#{a4jRegionBean.outerValue}" />
- <h:commandLink id="outerValueLink" value="Out of
region">
+ <h:commandLink id="outerValueLink" value="Outer">
<a4j:ajax id="outerValueAjax"
listener="#{a4jRegionBean.handleBehavior}"
execute="#{a4jRegionBean.outerExecute}" render="outputValues" />
</h:commandLink>
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jRegion/NestedRegionModel.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jRegion/NestedRegionModel.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jRegion/NestedRegionModel.java 2010-09-23
09:32:03 UTC (rev 19321)
@@ -0,0 +1,127 @@
+/*******************************************************************************
+ * 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.a4jRegion;
+
+import org.apache.commons.lang.WordUtils;
+import org.jboss.test.selenium.dom.Event;
+import org.jboss.test.selenium.framework.AjaxSelenium;
+import org.jboss.test.selenium.framework.AjaxSeleniumProxy;
+import org.jboss.test.selenium.locator.ElementLocator;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.jboss.test.selenium.locator.option.OptionLocator;
+
+import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.waitXhr;
+import static org.richfaces.tests.metamer.ftest.AbstractMetamerTest.pjq;
+import static org.testng.Assert.assertTrue;
+import static org.jboss.test.selenium.locator.option.OptionLocatorFactory.optionLabel;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class NestedRegionModel {
+
+ private static AjaxSelenium selenium = AjaxSeleniumProxy.getInstance();
+
+ private static ThreadLocal<Integer> sequence = new ThreadLocal<Integer>()
{
+ protected Integer initialValue() {
+ return 0;
+ };
+ };
+
+ private JQueryLocator selectDefaults = pjq("select[id$=defaultsSelect]");
+
+ public void setDefaultExecute(Execute execute) {
+ selectOrFireChange(selectDefaults, execute.option);
+ }
+
+ public void setExecute(Component component, Execute execute) {
+ selectOrFireChange(component.select, execute.option);
+ }
+
+ private void selectOrFireChange(ElementLocator<?> selectLocator,
OptionLocator<?> optionLocator) {
+ if
(optionLocator.getRawLocator().equals(selenium.getSelectedLabel(selectLocator))) {
+ waitXhr(selenium).fireEvent(selectLocator, Event.CHANGE);
+ } else {
+ waitXhr(selenium).select(selectLocator, optionLocator);
+ }
+ }
+
+ public void changeInputs() {
+ sequence.set(sequence.get() + 1);
+ for (Component component : Component.values()) {
+ selenium.type(component.input, Integer.toString(sequence.get()));
+ }
+ }
+
+ public enum Component {
+ OUTER("Outer"), REGION("Region"), NESTED("Nested
region");
+
+ public final JQueryLocator select;
+ public final JQueryLocator output;
+ public final JQueryLocator input;
+ public final JQueryLocator link;
+ public final OptionLocator<?> executeOption;
+
+ private Component(String name) {
+ String id = name.substring(0, 1).toLowerCase() +
WordUtils.capitalize(name).replace(" ", "").substring(1);
+
+ this.select = pjq("select[id$={0}Select]").format(id);
+ this.output = pjq("span[id$={0}ValueOutput]").format(id);
+ this.input = pjq("input:text[id$={0}ValueInput]").format(id);
+ this.link = pjq("a[id$={0}ValueLink]").format(id);
+ this.executeOption = optionLabel(name);
+ }
+
+ public void fireAction() {
+ waitXhr(selenium).click(link);
+ }
+
+ public boolean isChanged() {
+ final String out = selenium.getText(output);
+ assertTrue("".equals(out) ||
Integer.toString(sequence.get()).equals(out));
+ return Integer.toString(sequence.get()).equals(out);
+ }
+ }
+
+ public enum Execute {
+ DEFAULT("default"), ALL("@all"), REGION("@region"),
FORM("@form"), THIS("@this"), COMPONENT_OUTER(
+ Component.OUTER), COMPONENT_REGION(Component.REGION),
COMPONENT_NESTED(Component.NESTED);
+
+ public final OptionLocator<?> option;
+ public final Component componentBase;
+
+ private Execute(String label) {
+ this.option = optionLabel(label);
+ this.componentBase = null;
+ }
+
+ private Execute(Component component) {
+ this.option = component.executeOption;
+ this.componentBase = component;
+ }
+
+ public boolean isComponentBased() {
+ return componentBase != null;
+ }
+ }
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jRegion/TestNestedRegion.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jRegion/TestNestedRegion.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jRegion/TestNestedRegion.java 2010-09-23
09:32:03 UTC (rev 19321)
@@ -0,0 +1,132 @@
+package org.richfaces.tests.metamer.ftest.a4jRegion;
+
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+/*******************************************************************************
+ * 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.
+ *******************************************************************************/
+import static org.jboss.test.selenium.utils.text.SimplifiedFormat.format;
+import static org.testng.Assert.assertEquals;
+
+import java.net.URL;
+import java.util.EnumSet;
+
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.richfaces.tests.metamer.ftest.a4jRegion.NestedRegionModel.Component;
+import org.richfaces.tests.metamer.ftest.a4jRegion.NestedRegionModel.Execute;
+import org.richfaces.tests.metamer.ftest.annotations.Inject;
+import org.richfaces.tests.metamer.ftest.annotations.Use;
+import org.testng.annotations.Test;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class TestNestedRegion extends AbstractMetamerTest {
+
+ NestedRegionModel model = new NestedRegionModel();
+
+ @Inject
+ @Use("components")
+ Component component;
+ Component[] components = Component.values();
+
+ @Inject
+ @Use("executes")
+ Execute execute;
+ Execute[] executes = Execute.values();
+
+ EnumSet<Component> expectedChanges;
+ EnumSet<Component> actualChanges;
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/a4jRegion/nested.xhtml");
+ }
+
+ @Test
+ public void test() {
+ model.setExecute(component, execute);
+ model.changeInputs();
+ component.fireAction();
+
+ countExpectedChanges();
+ obtainActualChanges();
+ checkChanged();
+ }
+
+ private void countExpectedChanges() {
+ expectedChanges = EnumSet.noneOf(Component.class);
+
+ if (execute == Execute.DEFAULT) {
+ if (component == Component.OUTER) {
+ execute = Execute.THIS;
+ } else {
+ execute = Execute.REGION;
+ }
+ }
+
+ if (execute == Execute.ALL || execute == Execute.FORM) {
+ expectedChanges = EnumSet.allOf(Component.class);
+ }
+
+ if (execute == Execute.REGION) {
+ if (component == Component.REGION) {
+ expectedChanges.add(Component.REGION);
+ expectedChanges.add(Component.NESTED);
+ } else if (component == Component.NESTED) {
+ expectedChanges.add(Component.NESTED);
+ }
+ }
+
+ if (execute.isComponentBased()) {
+ expectedChanges.add(execute.componentBase);
+ }
+ }
+
+ private void obtainActualChanges() {
+ actualChanges = EnumSet.noneOf(Component.class);
+ for (Component component : Component.values()) {
+ if (component.isChanged()) {
+ actualChanges.add(component);
+ }
+ }
+ }
+
+ private void checkChanged() {
+ EnumSet<Component> missing = EnumSet.copyOf(expectedChanges);
+ missing.removeAll(actualChanges);
+
+ EnumSet<Component> redundant = EnumSet.complementOf(expectedChanges);
+ redundant.retainAll(actualChanges);
+
+ StringBuilder message = new StringBuilder(format("Component: {0}, Execute:
{1}; ", component, execute));
+
+ if (!missing.isEmpty()) {
+ message.append("Expected to change: " + missing + "; ");
+ }
+
+ if (!redundant.isEmpty()) {
+ message.append("Expected to not change: " + redundant + ";
");
+ }
+
+ assertEquals(actualChanges, expectedChanges, message.toString());
+ }
+}