From richfaces-svn-commits at lists.jboss.org Wed Jan 19 13:42:02 2011
Content-Type: multipart/mixed; boundary="===============8418081812939568010=="
MIME-Version: 1.0
From: richfaces-svn-commits at lists.jboss.org
To: richfaces-svn-commits at lists.jboss.org
Subject: [richfaces-svn-commits] JBoss Rich Faces SVN: r21100 - in
modules/tests/metamer/trunk/ftest-source/src/main/java/org:
richfaces/tests/metamer/ftest/richJQuery and 1 other directory.
Date: Wed, 19 Jan 2011 13:42:02 -0500
Message-ID: <201101191842.p0JIg2W4022864@svn01.web.mwc.hst.phx2.redhat.com>
--===============8418081812939568010==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Author: lfryc(a)redhat.com
Date: 2011-01-19 13:42:01 -0500 (Wed, 19 Jan 2011)
New Revision: 21100
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/cheiron=
/retriever/ColorRetriever.java
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tes=
ts/metamer/ftest/richJQuery/TestSimple.java
Log:
fixed the jquery tests by introducing color conversion mechanism
Added: modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/che=
iron/retriever/ColorRetriever.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/cheiro=
n/retriever/ColorRetriever.java (rev 0)
+++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/cheiro=
n/retriever/ColorRetriever.java 2011-01-19 18:42:01 UTC (rev 21100)
@@ -0,0 +1,109 @@
+/*
+ * 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.jboss.cheiron.retriever;
+
+import java.awt.Color;
+
+import org.apache.commons.lang.Validate;
+import org.jboss.test.selenium.css.CssProperty;
+import org.jboss.test.selenium.encapsulated.JavaScript;
+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.utils.ColorUtils;
+import org.jboss.test.selenium.waiting.conversion.Convertor;
+import org.jboss.test.selenium.waiting.conversion.PassOnConvertor;
+import org.jboss.test.selenium.waiting.retrievers.AbstractRetriever;
+import org.jboss.test.selenium.waiting.retrievers.Retriever;
+
+import static org.jboss.test.selenium.utils.text.SimplifiedFormat.format;
+import static org.jboss.test.selenium.encapsulated.JavaScript.js;
+
+/**
+ * @author Lukas Fryc
+ * @version $Revision$
+ */
+public class ColorRetriever extends AbstractRetriever implements Re=
triever {
+
+ private AjaxSelenium selenium =3D AjaxSeleniumProxy.getInstance();
+
+ private ElementLocator> elementLocator;
+
+ public ColorRetriever() {
+ }
+
+ public Color retrieve() {
+ Validate.notNull(elementLocator);
+
+ String value =3D selenium.getStyle(elementLocator, CssProperty.COL=
OR);
+ return ColorUtils.convertToAWTColor(value);
+ }
+
+ public JavaScript getJavaScriptRetrieve() {
+ final String colorPropertyName =3D CssProperty.COLOR.getPropertyNa=
me();
+ return js(format("selenium.getStyle('{0}', '{1}')", elementLocator=
.getAsString(), colorPropertyName));
+ }
+
+ public static ColorRetriever getInstance() {
+ return new ColorRetriever();
+ }
+
+ public ColorRetriever locator(ElementLocator> elementLocator) {
+ Validate.notNull(elementLocator);
+
+ ColorRetriever copy =3D copy();
+ copy.elementLocator =3D elementLocator;
+
+ return copy;
+ }
+
+ /**
+ * Returns a copy of this textRetriever with exactly same settings.
+ * =
+ * Keeps the immutability of this class.
+ * =
+ * @return the exact copy of this textRetriever
+ */
+ private ColorRetriever copy() {
+ ColorRetriever copy =3D new ColorRetriever();
+ copy.elementLocator =3D elementLocator;
+ return copy;
+ }
+
+ /**
+ * Uses {@link PassOnConvertor} to pass the JavaScript result to resul=
t value.
+ */
+ public Convertor getConvertor() {
+ return new ColorConvertor();
+ }
+
+ public static class ColorConvertor implements Convertor=
{
+ @Override
+ public String forwardConversion(Color object) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Color backwardConversion(String object) {
+ return ColorUtils.convertToAWTColor(object);
+ }
+ }
+}
Modified: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfa=
ces/tests/metamer/ftest/richJQuery/TestSimple.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/te=
sts/metamer/ftest/richJQuery/TestSimple.java 2011-01-19 18:32:36 UTC (rev 2=
1099)
+++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/te=
sts/metamer/ftest/richJQuery/TestSimple.java 2011-01-19 18:42:01 UTC (rev 2=
1100)
@@ -26,9 +26,10 @@
import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
import static org.testng.Assert.assertEquals;
=
+import java.awt.Color;
import java.net.URL;
=
-import org.jboss.test.selenium.css.CssProperty;
+import org.jboss.cheiron.retriever.ColorRetriever;
import org.jboss.test.selenium.locator.JQueryLocator;
import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
import org.testng.annotations.Test;
@@ -46,6 +47,8 @@
=
RichJQueryAttributes attributes =3D new RichJQueryAttributes();
=
+ ColorRetriever buttonColorRetriver =3D new ColorRetriever().locator(bu=
tton);
+
@Override
public URL getTestUrl() {
return buildUrl(contextPath, "faces/components/richJQuery/simple.x=
html");
@@ -55,20 +58,21 @@
public void testDefaultTiming() {
setupDomReadyTypeAttributes();
attributes.setTiming(null);
- assertEquals("red", selenium.getStyle(button, CssProperty.COLOR));
+ assertEquals(buttonColorRetriver.retrieve(), Color.RED);
}
=
@Test
public void testTimingImmediate() {
setupImmediateTypeAttributes();
+ buttonColorRetriver.initializeValue();
selenium.click(button);
- waitGui.until(styleEquals.locator(button).property(CssProperty.COL=
OR).value("red"));
+ assertEquals(waitModel.waitForChangeAndReturn(buttonColorRetriver)=
, Color.RED);
}
=
@Test
public void testTimingDomReady() {
setupDomReadyTypeAttributes();
- assertEquals("red", selenium.getStyle(button, CssProperty.COLOR));
+ assertEquals(buttonColorRetriver.retrieve(), Color.RED);
}
=
@Test
--===============8418081812939568010==--