From richfaces-svn-commits at lists.jboss.org Thu Oct 28 12:01:30 2010 Content-Type: multipart/mixed; boundary="===============4864938408032283762==" 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: r19734 - in modules/tests/metamer/trunk/ftest-source: src/main/java/org/jboss/test/selenium and 1 other directory. Date: Thu, 28 Oct 2010 12:01:30 -0400 Message-ID: <201010281601.o9SG1UIJ032722@svn01.web.mwc.hst.phx2.redhat.com> --===============4864938408032283762== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: lfryc(a)redhat.com Date: 2010-10-28 12:01:29 -0400 (Thu, 28 Oct 2010) New Revision: 19734 Added: modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/test/se= lenium/RequestTypeModelGuard.java Modified: modules/tests/metamer/trunk/ftest-source/pom.xml Log: added request type guard for non-atomic selenium operations over model Modified: modules/tests/metamer/trunk/ftest-source/pom.xml =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/pom.xml 2010-10-28 15:26:57 UT= C (rev 19733) +++ modules/tests/metamer/trunk/ftest-source/pom.xml 2010-10-28 16:01:29 UT= C (rev 19734) @@ -60,6 +60,11 @@ ${project.version} classes + + javassist + javassist + 3.12.1.GA + = Added: modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/tes= t/selenium/RequestTypeModelGuard.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/test/s= elenium/RequestTypeModelGuard.java (rev 0) +++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/test/s= elenium/RequestTypeModelGuard.java 2010-10-28 16:01:29 UTC (rev 19734) @@ -0,0 +1,129 @@ +/* + * 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.test.selenium; + +import java.lang.reflect.Method; + +import javassist.util.proxy.MethodHandler; +import javassist.util.proxy.ProxyFactory; +import javassist.util.proxy.ProxyObject; + +import org.jboss.test.selenium.guard.request.RequestTypeGuard; +import org.jboss.test.selenium.request.RequestType; + +/** + * @author Lukas Fryc + * @version $Revision$ + */ +public class RequestTypeModelGuard implements MethodHandler { + private RequestTypeGuard guard; + + private RequestTypeModelGuard(RequestTypeGuard guard) { + this.guard =3D guard; + } + + @SuppressWarnings("unchecked") + private static T guard(T model, RequestType requestE= xpected, boolean interlayed) { + RequestTypeGuard guard =3D new RequestTypeGuard(requestExpected, i= nterlayed); + + ProxyFactory f =3D new ProxyFactory(); + f.setSuperclass(model.getClass()); + Class c =3D f.createClass(); + + T newInstance; + try { + newInstance =3D (T) c.newInstance(); + } catch (Exception e) { + throw new IllegalStateException(e); + } + ((ProxyObject) newInstance).setHandler(new RequestTypeModelGuard(g= uard)); + return newInstance; + } + + @Override + public Object invoke(Object self, Method method, Method proceed, Objec= t[] args) throws Throwable { + guard.doBeforeCommand(); + Object result =3D proceed.invoke(self, args); + guard.doAfterCommand(); + + return result; + } + + /** + * Shortcut for registering a XMLHttpRequest on given selenium object. + * = + * @param selenium + * where should be registered XMLHttpRequest guard + * @return the selenium guarded to use XMLHttpRequest + */ + public static T guardXhr(T model) { + return guard(model, RequestType.XHR, false); + } + + /** + * Shortcut for registering a regular HTTP request on given selenium o= bject. + * = + * @param selenium + * where should be registered regular HTTP request guard + * @return the selenium guarded to use regular HTTP requests + */ + public static T guardHttp(T selenium) { + return guard(selenium, RequestType.HTTP, false); + } + + /** + * Shortcut for registering a guard for no request on given selenium o= bject. + * = + * @param selenium + * where should be registered no request guard + * @return the selenium guarded to use no request during interaction + */ + public static T guardNoRequest(T selenium) { + return guard(selenium, RequestType.NONE, false); + } + + /** + * Shortcut for registering guard waiting for interception of XHR type= request + * = + * @param selenium + * where should be the guard registered + * @return the selenium waiting for interception of XHR type request + */ + public static T waitXhr(T selenium) { + return guard(selenium, RequestType.XHR, true); + } + + /** + * Shortcut for registering guard waiting for interception of HTTP typ= e request + * = + * @param selenium + * selenium where should be the guard registered + * @return the selenium waitinf for interception of HTTP type request + */ + public static T waitHttp(T selenium) { + return guard(selenium, RequestType.HTTP, true); + } + + public interface Model { + } + +} --===============4864938408032283762==--