Seam SVN: r11929 - branches/enterprise/JBPAPP_5_0/src/test/ftest.
by seam-commits@lists.jboss.org
Author: mgencur(a)redhat.com
Date: 2010-01-07 08:05:26 -0500 (Thu, 07 Jan 2010)
New Revision: 11929
Modified:
branches/enterprise/JBPAPP_5_0/src/test/ftest/ftest.properties
Log:
JBPAPP-3348 added url for cluster
Modified: branches/enterprise/JBPAPP_5_0/src/test/ftest/ftest.properties
===================================================================
--- branches/enterprise/JBPAPP_5_0/src/test/ftest/ftest.properties 2010-01-07 13:00:28 UTC (rev 11928)
+++ branches/enterprise/JBPAPP_5_0/src/test/ftest/ftest.properties 2010-01-07 13:05:26 UTC (rev 11929)
@@ -29,6 +29,7 @@
#selenium.browser=*iexploreproxy
selenium.browser.port=8080
selenium.browser.url=http://127.0.0.1:8080
+selenium.browser.url.cluster=http://127.0.0.1:8180
selenium.speed=0
selenium.timeout=120000
14 years, 11 months
Seam SVN: r11928 - in branches/enterprise/JBPAPP_5_0/src/test/ftest: examples and 5 other directories.
by seam-commits@lists.jboss.org
Author: mgencur(a)redhat.com
Date: 2010-01-07 08:00:28 -0500 (Thu, 07 Jan 2010)
New Revision: 11928
Added:
branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/booking/jboss5cluster.xml
branches/enterprise/JBPAPP_5_0/src/test/ftest/src/main/org/jboss/seam/example/common/test/booking/cluster/
branches/enterprise/JBPAPP_5_0/src/test/ftest/src/main/org/jboss/seam/example/common/test/booking/cluster/selenium/
branches/enterprise/JBPAPP_5_0/src/test/ftest/src/main/org/jboss/seam/example/common/test/booking/cluster/selenium/FailoverTest.java
Modified:
branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/build.xml
branches/enterprise/JBPAPP_5_0/src/test/ftest/readme.txt
branches/enterprise/JBPAPP_5_0/src/test/ftest/src/main/org/jboss/seam/example/common/test/selenium/SeamSeleniumTest.java
Log:
JBPAPP-3348 created automated test for booking example in cluster environment
Added: branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/booking/jboss5cluster.xml
===================================================================
--- branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/booking/jboss5cluster.xml (rev 0)
+++ branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/booking/jboss5cluster.xml 2010-01-07 13:00:28 UTC (rev 11928)
@@ -0,0 +1,26 @@
+<!--
+ JBoss, Home of Professional Open Source Copyright 2008, Red Hat
+ Middleware LLC, 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.
+-->
+<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
+<suite name="Booking example" verbose="2" parallel="false">
+ <test name="booking_jboss5_cluster">
+ <parameter name="PROPERTY_FILE"
+ value="/org/jboss/seam/example/booking/test/selenium/booking.properties" />
+ <classes>
+ <class name="org.jboss.seam.example.common.test.booking.cluster.selenium.FailoverTest" />
+ </classes>
+ </test>
+</suite>
Modified: branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/build.xml
===================================================================
--- branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/build.xml 2010-01-07 11:35:55 UTC (rev 11927)
+++ branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/build.xml 2010-01-07 13:00:28 UTC (rev 11928)
@@ -41,6 +41,8 @@
<!-- default deployment targets -->
<property name="jboss5.deploy.target" value="deploy" />
<property name="jboss5.undeploy.target" value="undeploy" />
+ <property name="jboss5.farm.target" value="farm" />
+ <property name="jboss5.unfarm.target" value="unfarm" />
<!-- default context paths -->
<property name="jboss5.context.path" value="/seam-${example.name}" />
@@ -97,10 +99,18 @@
<target name="selenium.test" depends="build, container.properties" description="Run Tests">
<taskdef resource="testngtasks" classpathref="classpath.test" />
<mkdir dir="${test.output.dir}" />
-
+
+ <condition property="clusterxml" value="cluster">
+ <equals arg1="${cluster}" arg2="true"/>
+ </condition>
+ <condition property="clusterxml" value="">
+ <not>
+ <equals arg1="${cluster}" arg2="true"/>
+ </not>
+ </condition>
<!-- execute testng tests -->
<testng haltonfailure="false" outputdir="${test.output.dir}" classpathref="classpath.test" listener="${functional.listener}">
- <xmlfileset file="${container}.xml" />
+ <xmlfileset file="${container}${clusterxml}.xml" />
<sysproperty key="selenium.server.port" value="${selenium.server.port}" />
<sysproperty key="selenium.host" value="${selenium.host}" />
<sysproperty key="selenium.browser" value="${selenium.browser}" />
@@ -111,13 +121,14 @@
<sysproperty key="openid.account" value="${openid.account}" />
<sysproperty key="openid.password" value="${openid.password}" />
<sysproperty key="seam.dir" value="${seam.dir}" />
+ <sysproperty key="jboss.home" value="${jboss.home}" />
</testng>
</target>
- <target name="test" depends="build, container.properties" description="Run Tests">
+ <target name="simpletest" depends="build, container.properties" description="Run Tests" unless="cluster">
<!-- TODO all of these jboss commands must be optional with checks -->
<!-- TODO go get JBoss and extract -->
-
+ <echo message="executing..."/>
<!-- TODO start JBoss -->
<!-- clean example -->
<ant antfile="${seam.dir}/examples/${example.name}/build.xml" target="clean" inheritall="false" dir="${seam.dir}/examples/${example.name}" />
@@ -136,6 +147,16 @@
<!-- TODO remove jboss -->
</target>
+ <target name="clustertest" depends="build, container.properties" description="Run Tests in a cluster environment" if="cluster">
+ <echo message="executing..."/>
+ <ant antfile="${seam.dir}/examples/${example.name}/build.xml" target="clean" inheritall="false" dir="${seam.dir}/examples/${example.name}" />
+ <antcall target="farm.example" />
+ <antcall target="selenium.test" />
+ <antcall target="unfarm.example" />
+ </target>
+
+ <target name="test" depends="simpletest, clustertest"/>
+
<!-- TODO get this to next level too - how to combine into one report -->
<target name="testreport" depends="test" description="generate html report">
<mkdir dir="${test.report.dir}" />
@@ -166,6 +187,26 @@
</and>
</waitfor>
</target>
+
+ <target name="farm.example" depends="container.properties">
+ <property name="absolute.wait.url" value="${selenium.browser.url.cluster}${wait.url}" />
+ <echo>Deploying ${example.name} example to farm directory of ${container} using ${farm.target} target</echo>
+ <ant antfile="${seam.dir}/examples/${example.name}/build.xml" target="${farm.target}" inheritall="false" dir="${seam.dir}/examples/${example.name}">
+ <property name="jboss.home" value="${container.home}" />
+ <property name="session.replication" value="true" />
+ <property name="distributable" value="true" />
+ <propertyset refid="deploy.properties" />
+ </ant>
+ <!-- wait for the application to be active -->
+ <!-- TODO is there a better way? -->
+ <echo>Waiting ${wait.time} seconds for ${absolute.wait.url}</echo>
+ <waitfor maxwait="${wait.time}" maxwaitunit="second">
+ <and>
+ <!-- wait for the application to not throw 404 -->
+ <http url="${absolute.wait.url}" errorsBeginAt="404" />
+ </and>
+ </waitfor>
+ </target>
<target name="undeploy.example" depends="container.properties">
<echo>Undeploying example ${example.name} from ${container} using ${undeploy.target} target</echo>
@@ -173,6 +214,13 @@
<property name="jboss.home" value="${container.home}" />
</ant>
</target>
+
+ <target name="unfarm.example" depends="container.properties">
+ <echo>Undeploying example ${example.name} from farm directory of ${container} using ${unfarm.target} target</echo>
+ <ant antfile="${seam.dir}/examples/${example.name}/build.xml" target="${unfarm.target}" inheritall="false" dir="${seam.dir}/examples/${example.name}">
+ <property name="jboss.home" value="${container.home}" />
+ </ant>
+ </target>
<target name="container.properties" depends="set.deploy.properties" unless="container.home">
<set.container.properties container="${container}" />
@@ -187,6 +235,8 @@
<property name="container.jvm.arguments" value="${(a){container}.jvm.arguments}" />
<property name="deploy.target" value="${(a){container}.deploy.target}" />
<property name="undeploy.target" value="${(a){container}.undeploy.target}" />
+ <property name="farm.target" value="${(a){container}.farm.target}" />
+ <property name="unfarm.target" value="${(a){container}.unfarm.target}" />
<property name="context.path" value="${(a){container}.context.path}" />
<property name="wait.url" value="${context.path}" />
<property name="wait.time" value="${(a){container}.deploy.waittime}" />
Modified: branches/enterprise/JBPAPP_5_0/src/test/ftest/readme.txt
===================================================================
--- branches/enterprise/JBPAPP_5_0/src/test/ftest/readme.txt 2010-01-07 11:35:55 UTC (rev 11927)
+++ branches/enterprise/JBPAPP_5_0/src/test/ftest/readme.txt 2010-01-07 13:00:28 UTC (rev 11928)
@@ -37,6 +37,27 @@
To run functional tests for single example run:
* "ant test -Dtest=example_name" for JBoss AS 5
+How To Test Cluster Environment:
+--------------------------------
+* Currently there is one test for cluster environment - booking. The main goal of this test is
+* to simulate recovery from breakdown. Two instances of JBoss AS are being used. First part of
+* the test is executed at first (master) instance. Then the first instance is killed and a second (slave)
+* instance takes over executing of the application.
+* This test should be executed autonomously (not as a part of test bundle).
+
+* Prior to executing of this test it is needed to start both JBoss AS instances manually.
+* For example (assuming you have created second "all" configuration ("all2")):
+* JBOSS_HOME/bin/run.sh -c all -g DocsPartition -u 239.255.101.101 -b localhost -Djboss.messaging.ServerPeerID=1
+* -Djboss.service.binding.set=ports-default
+* JBOSS_HOME/bin/run.sh -c all2 -g DocsPartition -u 239.255.101.101 -b localhost -Djboss.messaging.ServerPeerID=2
+* -Djboss.service.binding.set=ports-01
+* The configuration "all" is considered to be master jboss instance (related to
+* jboss.service.binding.set=ports-default) and the application is deployed to server/all/farm
+* directory at "jboss5.home" location specified in ftest.properties
+
+To run cluster test for booking example:
+ant test -Dtest=booking -Dcluster=true
+
Known Limitations:
---------------------
* Only tested on Firefox and IE
Added: branches/enterprise/JBPAPP_5_0/src/test/ftest/src/main/org/jboss/seam/example/common/test/booking/cluster/selenium/FailoverTest.java
===================================================================
--- branches/enterprise/JBPAPP_5_0/src/test/ftest/src/main/org/jboss/seam/example/common/test/booking/cluster/selenium/FailoverTest.java (rev 0)
+++ branches/enterprise/JBPAPP_5_0/src/test/ftest/src/main/org/jboss/seam/example/common/test/booking/cluster/selenium/FailoverTest.java 2010-01-07 13:00:28 UTC (rev 11928)
@@ -0,0 +1,303 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, 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.seam.example.common.test.booking.cluster.selenium;
+
+import java.io.IOException;
+import java.text.MessageFormat;
+
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+import static org.testng.AssertJUnit.*;
+
+import org.jboss.seam.example.common.test.selenium.SeamSelenium;
+import org.jboss.seam.example.common.test.selenium.SeamSeleniumTest;
+
+import com.thoughtworks.selenium.Wait;
+
+/**
+ * This class tests booking functionality of the example. Two instances of JBoss AS are
+ * being used. First part of test is executed at first (master) instance. Then the first
+ * instance is killed and a second (slave) instance takes over executing of the application.
+ * This behaviour simulates recovery from breakdown.
+ *
+ * Prior to executing this test it is needed to start both JBoss AS instances manually.
+ * For example (assuming you have created second "all" configuration ("all2")):
+ * ./run.sh -c all -g DocsPartition -u 239.255.101.101 -b localhost -Djboss.messaging.ServerPeerID=1
+ * -Djboss.service.binding.set=ports-default
+ * ./run.sh -c all2 -g DocsPartition -u 239.255.101.101 -b localhost -Djboss.messaging.ServerPeerID=2
+ * -Djboss.service.binding.set=ports-01
+ * The configuration all is considered to be master jboss instance (related to
+ * jboss.service.binding.set=ports-default) and the application is deployed to server/all/farm directory
+ * at "jboss5.home" location specified in ftest.properties
+ *
+ *
+ * @author mgencur
+ * @author jharting
+ *
+ */
+public class FailoverTest extends SeamSeleniumTest
+{
+ private final String HOTEL_NAME = "W Hotel";
+ private final String DEFAULT_USERNAME = "demo";
+ private final String DEFAULT_PASSWORD = "demo";
+ private final String EXPECTED_NAME = "Demo User";
+ private final String CREDIT_CARD = "0123456789012345";
+ private final String CREDIT_CARD_NAME = "visa";
+ private final long JBOSS_SHUTDOWN_TIMEOUT = 20000;
+ private final int SECOND_BROWSER_PORT = 8180;
+ private final String SECOND_INSTANCE_BROWSER_URL = "http://localhost:" + SECOND_BROWSER_PORT;
+
+ private SeamSelenium browser2;
+
+ @Override
+ @BeforeMethod
+ public void setUp()
+ {
+ super.setUp();
+ deleteCookies(browser);
+ browser2 = startSecondBrowser();
+ deleteCookies(browser2);
+ assertTrue("Login failed.", login(browser));
+ }
+
+ @Override
+ @AfterMethod
+ public void tearDown()
+ {
+ logout(browser2);
+ super.tearDown();
+ stopSecondBrowser();
+ }
+
+
+
+ /**
+ * Simply books hotel with failover during booking.
+ */
+ @Test
+ public void simpleBookingWithFailoverTest()
+ {
+ preFailurePart(browser);
+
+ String newAddress = getAddressForSecondInstance(browser);
+
+ shutdownMasterJBossInstance();
+
+ postFailurePart(browser2, newAddress);
+
+ // main page
+ String message = browser2.getText(getProperty("HOTEL_MESSAGE"));
+ assertTrue("Booking failed. Confirmation message does not match.", message.matches(
+ MessageFormat.format(getProperty("BOOKING_CONFIRMATION_MESSAGE"), EXPECTED_NAME, HOTEL_NAME)));
+ }
+
+
+
+ public void shutdownMasterJBossInstance()
+ {
+ String command = JBOSS_HOME + "/bin/shutdown.sh -s localhost:1099 -S";
+ //System.out.println("Command:" + command);
+ try
+ {
+ Process process = Runtime.getRuntime().exec(command);
+ process.waitFor();
+ Thread.sleep(JBOSS_SHUTDOWN_TIMEOUT);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e.getCause());
+ }
+ catch (InterruptedException e)
+ {
+ }
+ }
+
+ public void preFailurePart(SeamSelenium browser)
+ {
+ if (!isLoggedIn(browser))
+ fail();
+ if (!browser.isElementPresent(getProperty("SEARCH_SUBMIT"))) {
+ browser.open(CONTEXT_PATH + getProperty("MAIN_PAGE"));
+ browser.waitForPageToLoad(TIMEOUT);
+ }
+ enterSearchQueryUsingAJAX(browser, HOTEL_NAME);
+ browser.click(getProperty("SEARCH_RESULT_TABLE_FIRST_ROW_LINK"));
+ browser.waitForPageToLoad(TIMEOUT);
+ // go to booking page
+ browser.click(getProperty("BOOKING_BOOK"));
+ browser.waitForPageToLoad(TIMEOUT);
+ }
+
+
+ public void postFailurePart(SeamSelenium browser, String newAddress)
+ {
+ browser2.open(newAddress);
+
+ //booking page
+ populateBookingFields(browser);
+
+ //a jsessionid cookie has to be deleted because at this moment there already exists one
+ deleteCookies(browser);
+
+ browser.click(getProperty("HOTEL_PROCEED"));
+ browser.waitForPageToLoad(TIMEOUT);
+
+ deleteCookies(browser);
+
+ // confirm page
+ browser.click(getProperty("HOTEL_CONFIRM"));
+ browser.waitForPageToLoad(TIMEOUT);
+ }
+
+ public SeamSelenium startSecondBrowser()
+ {
+ BROWSER_URL = SECOND_INSTANCE_BROWSER_URL;
+ //System.out.println("host: " + HOST + ", port: " + PORT + ", browser_url: " + BROWSER_URL);
+ return super.startBrowser();
+ }
+
+ public void stopSecondBrowser()
+ {
+ browser2.stop();
+ }
+
+ public String getAddressForSecondInstance(SeamSelenium browser)
+ {
+ String[] parsedStrings = browser.getLocation().split("/");
+ StringBuilder sb = new StringBuilder();
+ for (int i = 3; i != parsedStrings.length; i++){
+ sb.append("/").append(parsedStrings[i]);
+ }
+ String sid = browser.getCookieByName("JSESSIONID");
+ String newAddress = sb.toString();
+ String firstPart = newAddress.substring(0, newAddress.indexOf("?"));
+ String secondPart = newAddress.substring(newAddress.indexOf("?") , newAddress.length());
+
+ newAddress = firstPart + ";jsessionid=" + sid + secondPart;
+
+ return newAddress;
+ }
+
+ protected void populateBookingFields(SeamSelenium browser)
+ {
+ populateBookingFields(browser, 2, 0, CREDIT_CARD, CREDIT_CARD_NAME);
+ }
+
+ protected void populateBookingFields(SeamSelenium browser, int bed, int smoking, String creditCard, String creditCardName)
+ {
+ browser.select(getProperty("HOTEL_BED_FIELD"),
+ getProperty("HOTEL_BED_FIELD_SELECT_CRITERIA") + bed);
+ if (smoking == 1) {
+ browser.check(getProperty("HOTEL_SMOKING_1"));
+ } else {
+ browser.check(getProperty("HOTEL_SMOKING_2"));
+ }
+ browser.type(getProperty("HOTEL_CREDIT_CARD"), creditCard);
+ browser.type(getProperty("HOTEL_CREDIT_CARD_NAME"), creditCardName);
+ }
+
+ private void deleteCookies(SeamSelenium browser)
+ {
+ browser.deleteCookie("JSESSIONID", "path=" + CONTEXT_PATH + ", domain=localhost, recurse=true");
+ }
+
+ public boolean login(SeamSelenium browser)
+ {
+ return login(browser, DEFAULT_USERNAME, DEFAULT_PASSWORD);
+ }
+
+ public boolean login(SeamSelenium browser, String username, String password)
+ {
+ if (isLoggedIn(browser))
+ {
+ fail("User already logged in.");
+ }
+
+ browser.open(CONTEXT_PATH + getProperty("HOME_PAGE"));
+ browser.waitForPageToLoad(TIMEOUT);
+
+ if (!browser.getTitle().equals(getProperty("PAGE_TITLE")))
+ {
+ return false;
+ }
+
+ browser.type(getProperty("LOGIN_USERNAME_FIELD"), username);
+ browser.type(getProperty("LOGIN_PASSWORD_FIELD"), password);
+ browser.click(getProperty("LOGIN_SUBMIT"));
+ browser.waitForPageToLoad(TIMEOUT);
+
+ return isLoggedIn(browser);
+ }
+
+ public void logout(SeamSelenium browser)
+ {
+ if (isLoggedIn(browser))
+ {
+ browser.click(getProperty("LOGOUT"));
+ browser.waitForPageToLoad(TIMEOUT);
+ }
+ }
+
+ public boolean isLoggedIn(SeamSelenium browser)
+ {
+ return browser.isElementPresent(getProperty("LOGOUT"));
+ }
+
+ public void enterSearchQueryUsingAJAX(final SeamSelenium browser, String query)
+ {
+ browser.type(getProperty("SEARCH_STRING_FIELD"), "");
+ browser.type(getProperty("SEARCH_STRING_FIELD"), query.substring(0, query.length() - 1));
+ browser.typeKeys(getProperty("SEARCH_STRING_FIELD"), query.substring(query.length() - 1));
+
+ browser.click(getProperty("SEARCH_SUBMIT"));
+
+ // wait for javascript to show spinner
+ try
+ {
+ Thread.sleep(1000);
+ }
+ catch (InterruptedException e)
+ {
+ }
+
+ // wait for page to get updated
+ new Wait()
+ {
+ @Override
+ public boolean until()
+ {
+ return !browser.isVisible(getProperty("SPINNER"));
+ }
+ }.wait("Spinner hasn't come out.");
+
+ new Wait()
+ {
+ @Override
+ public boolean until()
+ {
+ return (browser.isElementPresent(getProperty("SEARCH_RESULT_TABLE")) ||
+ browser.isElementPresent(getProperty("NO_HOTELS_FOUND")));
+ }
+ }.wait("Search results not found.");
+ }
+}
Property changes on: branches/enterprise/JBPAPP_5_0/src/test/ftest/src/main/org/jboss/seam/example/common/test/booking/cluster/selenium/FailoverTest.java
___________________________________________________________________
Name: svn:executable
+ *
Modified: branches/enterprise/JBPAPP_5_0/src/test/ftest/src/main/org/jboss/seam/example/common/test/selenium/SeamSeleniumTest.java
===================================================================
--- branches/enterprise/JBPAPP_5_0/src/test/ftest/src/main/org/jboss/seam/example/common/test/selenium/SeamSeleniumTest.java 2010-01-07 11:35:55 UTC (rev 11927)
+++ branches/enterprise/JBPAPP_5_0/src/test/ftest/src/main/org/jboss/seam/example/common/test/selenium/SeamSeleniumTest.java 2010-01-07 13:00:28 UTC (rev 11928)
@@ -40,11 +40,11 @@
*/
public abstract class SeamSeleniumTest {
- private static String HOST;
- private static int PORT;
- private static String BROWSER;
- private static String BROWSER_URL;
- private static String SPEED;
+ protected static String HOST;
+ protected static int PORT;
+ protected static String BROWSER;
+ protected static String BROWSER_URL;
+ protected static String SPEED;
public static String TIMEOUT;
private static String PROPERTY_FILE;
protected String CONTEXT_PATH = "";
@@ -54,16 +54,18 @@
protected static String SEAM_DIR;
protected static String APP_NAME;
protected static String OUTPUT_DIR;
+ protected static String JBOSS_HOME;
+
//protected SeamSelenium
public static SeamSelenium browser;
@BeforeClass
@Parameters( { "selenium.host", "selenium.server.port", "selenium.browser",
"selenium.browser.url", "selenium.speed", "selenium.timeout",
- "PROPERTY_FILE", "example.context.path", "seam.dir" })
+ "PROPERTY_FILE", "example.context.path", "seam.dir", "jboss.home" })
public void setParameters(String host, String port, String browser,
- String browserUrl, String speed, String timeout, String propertyFile, @Optional("") String contextPath, String seamDir) {
+ String browserUrl, String speed, String timeout, String propertyFile, @Optional("") String contextPath, String seamDir, String jbossHome) {
HOST = host;
PORT = Integer.parseInt(port);
BROWSER = browser;
@@ -74,6 +76,7 @@
CONTEXT_PATH = APP_NAME = contextPath;
SEAM_DIR = seamDir;
OUTPUT_DIR = SEAM_DIR + "/test-output/functional-framework";
+ JBOSS_HOME = jbossHome;
}
@BeforeMethod
@@ -96,14 +99,12 @@
return newBrowser;
}
-
- public void stopBrowser()
- {
- if (browser != null)
- {
- browser.stop();
- }
- }
+ public void stopBrowser() {
+ if (browser != null)
+ {
+ browser.stop();
+ }
+ }
public String getProperty(String key) {
if (!propertiesLoaded) {
14 years, 11 months
Seam SVN: r11927 - in branches/community/Seam_2_2/src/test/ftest: examples and 5 other directories.
by seam-commits@lists.jboss.org
Author: mgencur(a)redhat.com
Date: 2010-01-07 06:35:55 -0500 (Thu, 07 Jan 2010)
New Revision: 11927
Added:
branches/community/Seam_2_2/src/test/ftest/examples/booking/jboss5cluster.xml
branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/booking/cluster/
branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/booking/cluster/selenium/
branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/booking/cluster/selenium/FailoverTest.java
Modified:
branches/community/Seam_2_2/src/test/ftest/examples/build.xml
branches/community/Seam_2_2/src/test/ftest/readme.txt
branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/selenium/SeamSeleniumTest.java
Log:
JBSEAM-4518 created automated test of booking example in a cluster to test failover
Added: branches/community/Seam_2_2/src/test/ftest/examples/booking/jboss5cluster.xml
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/examples/booking/jboss5cluster.xml (rev 0)
+++ branches/community/Seam_2_2/src/test/ftest/examples/booking/jboss5cluster.xml 2010-01-07 11:35:55 UTC (rev 11927)
@@ -0,0 +1,26 @@
+<!--
+ JBoss, Home of Professional Open Source Copyright 2008, Red Hat
+ Middleware LLC, 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.
+-->
+<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
+<suite name="Booking example" verbose="2" parallel="false">
+ <test name="booking_jboss5_cluster">
+ <parameter name="PROPERTY_FILE"
+ value="/org/jboss/seam/example/booking/test/selenium/booking.properties" />
+ <classes>
+ <class name="org.jboss.seam.example.common.test.booking.cluster.selenium.FailoverTest" />
+ </classes>
+ </test>
+</suite>
Modified: branches/community/Seam_2_2/src/test/ftest/examples/build.xml
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/examples/build.xml 2010-01-07 09:34:59 UTC (rev 11926)
+++ branches/community/Seam_2_2/src/test/ftest/examples/build.xml 2010-01-07 11:35:55 UTC (rev 11927)
@@ -42,6 +42,8 @@
<property name="jboss4.deploy.target" value="deploy" />
<property name="jboss5.deploy.target" value="${jboss4.deploy.target}" />
<property name="jboss4.undeploy.target" value="undeploy" />
+ <property name="jboss5.farm.target" value="farm" />
+ <property name="jboss5.unfarm.target" value="unfarm" />
<property name="jboss5.undeploy.target" value="${jboss4.undeploy.target}" />
<property name="jboss-embedded.deploy.target" value="tomcat.deploy" />
<property name="jboss-embedded.undeploy.target" value="tomcat.undeploy" />
@@ -111,10 +113,19 @@
<target name="selenium.test" depends="build, container.properties" description="Run Tests">
<taskdef resource="testngtasks" classpathref="classpath.test" />
<mkdir dir="${test.output.dir}" />
-
+
+ <condition property="clusterxml" value="cluster">
+ <equals arg1="${cluster}" arg2="true"/>
+ </condition>
+ <condition property="clusterxml" value="">
+ <not>
+ <equals arg1="${cluster}" arg2="true"/>
+ </not>
+ </condition>
+
<!-- execute testng tests -->
<testng haltonfailure="false" outputdir="${test.output.dir}" classpathref="classpath.test" listener="${functional.listener}">
- <xmlfileset file="${container}.xml" />
+ <xmlfileset file="${container}${clusterxml}.xml" />
<sysproperty key="selenium.server.port" value="${selenium.server.port}" />
<sysproperty key="selenium.host" value="${selenium.host}" />
<sysproperty key="selenium.browser" value="${selenium.browser}" />
@@ -125,13 +136,14 @@
<sysproperty key="openid.account" value="${openid.account}" />
<sysproperty key="openid.password" value="${openid.password}" />
<sysproperty key="seam.dir" value="${seam.dir}" />
+ <sysproperty key="jboss.home" value="${jboss.home}" />
</testng>
</target>
- <target name="test" depends="build, container.properties" description="Run Tests">
+ <target name="simpletest" depends="build, container.properties" description="Run Tests" unless="cluster">
<!-- TODO all of these jboss commands must be optional with checks -->
<!-- TODO go get JBoss and extract -->
-
+ <echo message="executing..."/>
<!-- TODO start JBoss -->
<!-- clean example -->
<ant antfile="${seam.dir}/examples/${example.name}/build.xml" target="clean" inheritall="false" dir="${seam.dir}/examples/${example.name}" />
@@ -148,7 +160,17 @@
<!-- TODO stop jboss -->
<!-- TODO remove jboss -->
+ </target>
+
+ <target name="clustertest" depends="build, container.properties" description="Run Tests in a cluster environment" if="cluster">
+ <echo message="executing..."/>
+ <ant antfile="${seam.dir}/examples/${example.name}/build.xml" target="clean" inheritall="false" dir="${seam.dir}/examples/${example.name}" />
+ <antcall target="farm.example" />
+ <antcall target="selenium.test" />
+ <antcall target="unfarm.example" />
</target>
+
+ <target name="test" depends="simpletest, clustertest"/>
<!-- TODO get this to next level too - how to combine into one report -->
<target name="testreport" depends="test" description="generate html report">
@@ -181,6 +203,27 @@
</and>
</waitfor>
</target>
+
+ <target name="farm.example" depends="container.properties">
+ <property name="absolute.wait.url" value="${selenium.browser.url.cluster}${wait.url}" />
+ <echo>Deploying ${example.name} example to farm directory of ${container} using ${farm.target} target</echo>
+ <ant antfile="${seam.dir}/examples/${example.name}/build.xml" target="${farm.target}" inheritall="false" dir="${seam.dir}/examples/${example.name}">
+ <property name="jboss.home" value="${container.home}" />
+ <property name="tomcat.home" value="${container.home}" />
+ <property name="session.replication" value="true" />
+ <property name="distributable" value="true" />
+ <propertyset refid="deploy.properties" />
+ </ant>
+ <!-- wait for the application to be active -->
+ <!-- TODO is there a better way? -->
+ <echo>Waiting ${wait.time} seconds for ${absolute.wait.url}</echo>
+ <waitfor maxwait="${wait.time}" maxwaitunit="second">
+ <and>
+ <!-- wait for the application to not throw 404 -->
+ <http url="${absolute.wait.url}" errorsBeginAt="404" />
+ </and>
+ </waitfor>
+ </target>
<target name="undeploy.example" depends="container.properties">
<echo>Undeploying example ${example.name} from ${container} using ${undeploy.target} target</echo>
@@ -189,6 +232,14 @@
<property name="tomcat.home" value="${container.home}" />
</ant>
</target>
+
+ <target name="unfarm.example" depends="container.properties">
+ <echo>Undeploying example ${example.name} from farm directory of ${container} using ${unfarm.target} target</echo>
+ <ant antfile="${seam.dir}/examples/${example.name}/build.xml" target="${unfarm.target}" inheritall="false" dir="${seam.dir}/examples/${example.name}">
+ <property name="jboss.home" value="${container.home}" />
+ <property name="tomcat.home" value="${container.home}" />
+ </ant>
+ </target>
<target name="container.properties" depends="set.deploy.properties" unless="container.home">
<set.container.properties container="${container}" />
@@ -202,6 +253,8 @@
<property name="container.profile" value="${(a){container}.profile}" />
<property name="container.jvm.arguments" value="${(a){container}.jvm.arguments}" />
<property name="deploy.target" value="${(a){container}.deploy.target}" />
+ <property name="farm.target" value="${(a){container}.farm.target}" />
+ <property name="unfarm.target" value="${(a){container}.unfarm.target}" />
<property name="undeploy.target" value="${(a){container}.undeploy.target}" />
<property name="context.path" value="${(a){container}.context.path}" />
<property name="wait.url" value="${context.path}" />
Modified: branches/community/Seam_2_2/src/test/ftest/readme.txt
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/readme.txt 2010-01-07 09:34:59 UTC (rev 11926)
+++ branches/community/Seam_2_2/src/test/ftest/readme.txt 2010-01-07 11:35:55 UTC (rev 11927)
@@ -43,7 +43,28 @@
* "ant test.jboss4 -Dtest=example_name" for JBoss AS 4.2
* "ant test.jboss-embedded -Dtest=example_name" for Tomcat + JBoss Embedded
* "ant test.tomcat6 -Dtest=example_name" for Tomcat6
+
+How To Test Cluster Environment:
+--------------------------------
+* Currently there is one test for cluster environment - booking. The main goal of this test is
+* to simulate recovery from breakdown. Two instances of JBoss AS are being used. First part of
+* the test is executed at first (master) instance. Then the first instance is killed and a second (slave)
+* instance takes over executing of the application.
+* This test should be executed autonomously (not as a part of test bundle).
+* Prior to executing of this test it is needed to start both JBoss AS instances manually.
+* For example (assuming you have created second "all" configuration ("all2")):
+* JBOSS_HOME/bin/run.sh -c all -g DocsPartition -u 239.255.101.101 -b localhost -Djboss.messaging.ServerPeerID=1
+* -Djboss.service.binding.set=ports-default
+* JBOSS_HOME/bin/run.sh -c all2 -g DocsPartition -u 239.255.101.101 -b localhost -Djboss.messaging.ServerPeerID=2
+* -Djboss.service.binding.set=ports-01
+* The configuration "all" is considered to be master jboss instance (related to
+* jboss.service.binding.set=ports-default) and the application is deployed to server/all/farm
+* directory at "jboss5.home" location specified in ftest.properties
+
+To run cluster test for booking example:
+ant test -Dtest=booking -Dcluster=true
+
Known Limitations:
---------------------
* Only tested on Firefox and IE
Added: branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/booking/cluster/selenium/FailoverTest.java
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/booking/cluster/selenium/FailoverTest.java (rev 0)
+++ branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/booking/cluster/selenium/FailoverTest.java 2010-01-07 11:35:55 UTC (rev 11927)
@@ -0,0 +1,303 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, 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.seam.example.common.test.booking.cluster.selenium;
+
+import java.io.IOException;
+import java.text.MessageFormat;
+
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+import static org.testng.AssertJUnit.*;
+
+import org.jboss.seam.example.common.test.selenium.SeamSelenium;
+import org.jboss.seam.example.common.test.selenium.SeamSeleniumTest;
+
+import com.thoughtworks.selenium.Wait;
+
+/**
+ * This class tests booking functionality of the example. Two instances of JBoss AS are
+ * being used. First part of test is executed at first (master) instance. Then the first
+ * instance is killed and a second (slave) instance takes over executing of the application.
+ * This behaviour simulates recovery from breakdown.
+ *
+ * Prior to executing this test it is needed to start both JBoss AS instances manually.
+ * For example (assuming you have created second "all" configuration ("all2")):
+ * ./run.sh -c all -g DocsPartition -u 239.255.101.101 -b localhost -Djboss.messaging.ServerPeerID=1
+ * -Djboss.service.binding.set=ports-default
+ * ./run.sh -c all2 -g DocsPartition -u 239.255.101.101 -b localhost -Djboss.messaging.ServerPeerID=2
+ * -Djboss.service.binding.set=ports-01
+ * The configuration all is considered to be master jboss instance (related to
+ * jboss.service.binding.set=ports-default) and the application is deployed to server/all/farm directory
+ * at "jboss5.home" location specified in ftest.properties
+ *
+ *
+ * @author mgencur
+ * @author jharting
+ *
+ */
+public class FailoverTest extends SeamSeleniumTest
+{
+ private final String HOTEL_NAME = "W Hotel";
+ private final String DEFAULT_USERNAME = "demo";
+ private final String DEFAULT_PASSWORD = "demo";
+ private final String EXPECTED_NAME = "Demo User";
+ private final String CREDIT_CARD = "0123456789012345";
+ private final String CREDIT_CARD_NAME = "visa";
+ private final long JBOSS_SHUTDOWN_TIMEOUT = 20000;
+ private final int SECOND_BROWSER_PORT = 8180;
+ private final String SECOND_INSTANCE_BROWSER_URL = "http://localhost:" + SECOND_BROWSER_PORT;
+
+ private SeamSelenium browser2;
+
+ @Override
+ @BeforeMethod
+ public void setUp()
+ {
+ super.setUp();
+ deleteCookies(browser);
+ browser2 = startSecondBrowser();
+ deleteCookies(browser2);
+ assertTrue("Login failed.", login(browser));
+ }
+
+ @Override
+ @AfterMethod
+ public void tearDown()
+ {
+ logout(browser2);
+ super.tearDown();
+ stopSecondBrowser();
+ }
+
+
+
+ /**
+ * Simply books hotel with failover during booking.
+ */
+ @Test
+ public void simpleBookingWithFailoverTest()
+ {
+ preFailurePart(browser);
+
+ String newAddress = getAddressForSecondInstance(browser);
+
+ shutdownMasterJBossInstance();
+
+ postFailurePart(browser2, newAddress);
+
+ // main page
+ String message = browser2.getText(getProperty("HOTEL_MESSAGE"));
+ assertTrue("Booking failed. Confirmation message does not match.", message.matches(
+ MessageFormat.format(getProperty("BOOKING_CONFIRMATION_MESSAGE"), EXPECTED_NAME, HOTEL_NAME)));
+ }
+
+
+
+ public void shutdownMasterJBossInstance()
+ {
+ String command = JBOSS_HOME + "/bin/shutdown.sh -s localhost:1099 -S";
+ //System.out.println("Command:" + command);
+ try
+ {
+ Process process = Runtime.getRuntime().exec(command);
+ process.waitFor();
+ Thread.sleep(JBOSS_SHUTDOWN_TIMEOUT);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e.getCause());
+ }
+ catch (InterruptedException e)
+ {
+ }
+ }
+
+ public void preFailurePart(SeamSelenium browser)
+ {
+ if (!isLoggedIn(browser))
+ fail();
+ if (!browser.isElementPresent(getProperty("SEARCH_SUBMIT"))) {
+ browser.open(CONTEXT_PATH + getProperty("MAIN_PAGE"));
+ browser.waitForPageToLoad(TIMEOUT);
+ }
+ enterSearchQueryUsingAJAX(browser, HOTEL_NAME);
+ browser.click(getProperty("SEARCH_RESULT_TABLE_FIRST_ROW_LINK"));
+ browser.waitForPageToLoad(TIMEOUT);
+ // go to booking page
+ browser.click(getProperty("BOOKING_BOOK"));
+ browser.waitForPageToLoad(TIMEOUT);
+ }
+
+
+ public void postFailurePart(SeamSelenium browser, String newAddress)
+ {
+ browser2.open(newAddress);
+
+ //booking page
+ populateBookingFields(browser);
+
+ //a jsessionid cookie has to be deleted because at this moment there already exists one
+ deleteCookies(browser);
+
+ browser.click(getProperty("HOTEL_PROCEED"));
+ browser.waitForPageToLoad(TIMEOUT);
+
+ deleteCookies(browser);
+
+ // confirm page
+ browser.click(getProperty("HOTEL_CONFIRM"));
+ browser.waitForPageToLoad(TIMEOUT);
+ }
+
+ public SeamSelenium startSecondBrowser()
+ {
+ BROWSER_URL = SECOND_INSTANCE_BROWSER_URL;
+ //System.out.println("host: " + HOST + ", port: " + PORT + ", browser_url: " + BROWSER_URL);
+ return super.startBrowser();
+ }
+
+ public void stopSecondBrowser()
+ {
+ browser2.stop();
+ }
+
+ public String getAddressForSecondInstance(SeamSelenium browser)
+ {
+ String[] parsedStrings = browser.getLocation().split("/");
+ StringBuilder sb = new StringBuilder();
+ for (int i = 3; i != parsedStrings.length; i++){
+ sb.append("/").append(parsedStrings[i]);
+ }
+ String sid = browser.getCookieByName("JSESSIONID");
+ String newAddress = sb.toString();
+ String firstPart = newAddress.substring(0, newAddress.indexOf("?"));
+ String secondPart = newAddress.substring(newAddress.indexOf("?") , newAddress.length());
+
+ newAddress = firstPart + ";jsessionid=" + sid + secondPart;
+
+ return newAddress;
+ }
+
+ protected void populateBookingFields(SeamSelenium browser)
+ {
+ populateBookingFields(browser, 2, 0, CREDIT_CARD, CREDIT_CARD_NAME);
+ }
+
+ protected void populateBookingFields(SeamSelenium browser, int bed, int smoking, String creditCard, String creditCardName)
+ {
+ browser.select(getProperty("HOTEL_BED_FIELD"),
+ getProperty("HOTEL_BED_FIELD_SELECT_CRITERIA") + bed);
+ if (smoking == 1) {
+ browser.check(getProperty("HOTEL_SMOKING_1"));
+ } else {
+ browser.check(getProperty("HOTEL_SMOKING_2"));
+ }
+ browser.type(getProperty("HOTEL_CREDIT_CARD"), creditCard);
+ browser.type(getProperty("HOTEL_CREDIT_CARD_NAME"), creditCardName);
+ }
+
+ private void deleteCookies(SeamSelenium browser)
+ {
+ browser.deleteCookie("JSESSIONID", "path=" + CONTEXT_PATH + ", domain=localhost, recurse=true");
+ }
+
+ public boolean login(SeamSelenium browser)
+ {
+ return login(browser, DEFAULT_USERNAME, DEFAULT_PASSWORD);
+ }
+
+ public boolean login(SeamSelenium browser, String username, String password)
+ {
+ if (isLoggedIn(browser))
+ {
+ fail("User already logged in.");
+ }
+
+ browser.open(CONTEXT_PATH + getProperty("HOME_PAGE"));
+ browser.waitForPageToLoad(TIMEOUT);
+
+ if (!browser.getTitle().equals(getProperty("PAGE_TITLE")))
+ {
+ return false;
+ }
+
+ browser.type(getProperty("LOGIN_USERNAME_FIELD"), username);
+ browser.type(getProperty("LOGIN_PASSWORD_FIELD"), password);
+ browser.click(getProperty("LOGIN_SUBMIT"));
+ browser.waitForPageToLoad(TIMEOUT);
+
+ return isLoggedIn(browser);
+ }
+
+ public void logout(SeamSelenium browser)
+ {
+ if (isLoggedIn(browser))
+ {
+ browser.click(getProperty("LOGOUT"));
+ browser.waitForPageToLoad(TIMEOUT);
+ }
+ }
+
+ public boolean isLoggedIn(SeamSelenium browser)
+ {
+ return browser.isElementPresent(getProperty("LOGOUT"));
+ }
+
+ public void enterSearchQueryUsingAJAX(final SeamSelenium browser, String query)
+ {
+ browser.type(getProperty("SEARCH_STRING_FIELD"), "");
+ browser.type(getProperty("SEARCH_STRING_FIELD"), query.substring(0, query.length() - 1));
+ browser.typeKeys(getProperty("SEARCH_STRING_FIELD"), query.substring(query.length() - 1));
+
+ browser.click(getProperty("SEARCH_SUBMIT"));
+
+ // wait for javascript to show spinner
+ try
+ {
+ Thread.sleep(1000);
+ }
+ catch (InterruptedException e)
+ {
+ }
+
+ // wait for page to get updated
+ new Wait()
+ {
+ @Override
+ public boolean until()
+ {
+ return !browser.isVisible(getProperty("SPINNER"));
+ }
+ }.wait("Spinner hasn't come out.");
+
+ new Wait()
+ {
+ @Override
+ public boolean until()
+ {
+ return (browser.isElementPresent(getProperty("SEARCH_RESULT_TABLE")) ||
+ browser.isElementPresent(getProperty("NO_HOTELS_FOUND")));
+ }
+ }.wait("Search results not found.");
+ }
+}
Property changes on: branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/booking/cluster/selenium/FailoverTest.java
___________________________________________________________________
Name: svn:executable
+ *
Modified: branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/selenium/SeamSeleniumTest.java
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/selenium/SeamSeleniumTest.java 2010-01-07 09:34:59 UTC (rev 11926)
+++ branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/selenium/SeamSeleniumTest.java 2010-01-07 11:35:55 UTC (rev 11927)
@@ -40,11 +40,11 @@
*/
public abstract class SeamSeleniumTest {
- private static String HOST;
- private static int PORT;
- private static String BROWSER;
- private static String BROWSER_URL;
- private static String SPEED;
+ protected static String HOST;
+ protected static int PORT;
+ protected static String BROWSER;
+ protected static String BROWSER_URL;
+ protected static String SPEED;
public static String TIMEOUT;
private static String PROPERTY_FILE;
protected String CONTEXT_PATH = "";
@@ -54,16 +54,18 @@
protected static String SEAM_DIR;
protected static String APP_NAME;
protected static String OUTPUT_DIR;
+ protected static String JBOSS_HOME;
+
//protected SeamSelenium
public static SeamSelenium browser;
@BeforeClass
@Parameters( { "selenium.host", "selenium.server.port", "selenium.browser",
"selenium.browser.url", "selenium.speed", "selenium.timeout",
- "PROPERTY_FILE", "example.context.path", "seam.dir" })
+ "PROPERTY_FILE", "example.context.path", "seam.dir", "jboss.home" })
public void setParameters(String host, String port, String browser,
- String browserUrl, String speed, String timeout, String propertyFile, @Optional("") String contextPath, String seamDir) {
+ String browserUrl, String speed, String timeout, String propertyFile, @Optional("") String contextPath, String seamDir, String jbossHome) {
HOST = host;
PORT = Integer.parseInt(port);
BROWSER = browser;
@@ -74,6 +76,7 @@
CONTEXT_PATH = APP_NAME = contextPath;
SEAM_DIR = seamDir;
OUTPUT_DIR = SEAM_DIR + "/test-output/functional-framework";
+ JBOSS_HOME = jbossHome;
}
@BeforeMethod
14 years, 11 months
Seam SVN: r11926 - modules/remoting/trunk/examples/model/src/main/webapp.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2010-01-07 04:34:59 -0500 (Thu, 07 Jan 2010)
New Revision: 11926
Modified:
modules/remoting/trunk/examples/model/src/main/webapp/model.html
Log:
implement create new person function
Modified: modules/remoting/trunk/examples/model/src/main/webapp/model.html
===================================================================
--- modules/remoting/trunk/examples/model/src/main/webapp/model.html 2010-01-07 09:34:32 UTC (rev 11925)
+++ modules/remoting/trunk/examples/model/src/main/webapp/model.html 2010-01-07 09:34:59 UTC (rev 11926)
@@ -89,13 +89,15 @@
var person = model.getValue("person");
document.getElementById("firstName").value = person.getFirstName();
document.getElementById("lastName").value = person.getLastName();
- document.getElementById("dob").value = person.getDateOfBirth().toLocaleString();
+ document.getElementById("dob").value = person.dateOfBirth != null ? person.dateOfBirth.toLocaleString() : "";
var addressDiv = document.getElementById("addresses");
clearElement(addressDiv);
addressDiv.appendChild(createLinkRow("Load addresses", "loadAddresses()"));
document.getElementById("personDetail").style.display = "block";
+
+ if (person.addresses) loadAddressesCallback();
}
function loadAddresses() {
14 years, 11 months
Seam SVN: r11925 - in modules/remoting/trunk/src/main: resources/org/jboss/seam/remoting and 1 other directory.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2010-01-07 04:34:32 -0500 (Thu, 07 Jan 2010)
New Revision: 11925
Modified:
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java
modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js
Log:
call context should be model-scoped
Modified: modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java
===================================================================
--- modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java 2010-01-07 09:04:32 UTC (rev 11924)
+++ modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java 2010-01-07 09:34:32 UTC (rev 11925)
@@ -226,21 +226,24 @@
{
model.getCallContext().getInRefs().put("" + i, model.getCallContext().getOutRefs().get(i));
}
-
- List<Wrapper> newRefs = new ArrayList<Wrapper>();
-
+
Element refsElement = modelElement.element("refs");
- for (Element ref : (List<Element>) refsElement.elements("ref"))
+ if (refsElement != null)
{
- newRefs.add(model.getCallContext().createWrapperFromElement(ref));
+ List<Wrapper> newRefs = new ArrayList<Wrapper>();
+
+ for (Element ref : (List<Element>) refsElement.elements("ref"))
+ {
+ newRefs.add(model.getCallContext().createWrapperFromElement(ref));
+ }
+
+ // Unmarshal any new ref values
+ for (Wrapper w : newRefs)
+ {
+ w.unmarshal();
+ }
}
- // Unmarshal any new ref values
- for (Wrapper w : newRefs)
- {
- w.unmarshal();
- }
-
Element delta = modelElement.element("delta");
if (delta != null)
{
Modified: modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js
===================================================================
--- modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js 2010-01-07 09:04:32 UTC (rev 11924)
+++ modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js 2010-01-07 09:34:32 UTC (rev 11925)
@@ -359,10 +359,11 @@
return {data: d, id: callId, callback: callback, exceptionHandler: exceptionHandler, handler: Seam.preProcessCallResponse};
};
-Seam.createHeader = function(callId) {
+Seam.createHeader = function(callId, ctx) {
var h = "<context><callId>" + callId + "</callId>";
- if (Seam.context.getConversationId()) {
- h += "<conversationId>" + Seam.context.getConversationId() + "</conversationId>";
+ if (!ctx) ctx = Seam.context;
+ if (ctx.getConversationId()) {
+ h += "<conversationId>" + ctx.getConversationId() + "</conversationId>";
}
h += "</context>";
return h;
@@ -580,7 +581,10 @@
var b = cn(call.response.documentElement, "body");
if (b) {
var n = cn(b, "model");
- if (call.model) call.model.processExpandResponse(n, call.refId, call.property, call.callback);
+ if (call.model) {
+ call.model.context.setConversationId(call.context.conversationId);
+ call.model.processExpandResponse(n, call.refId, call.property, call.callback);
+ }
}
};
@@ -590,7 +594,10 @@
var b = cn(call.response.documentElement, "body");
if (b) {
var n = cn(b, "model");
- if (call.model) call.model.processResponse(n, call.callback);
+ if (call.model) {
+ call.model.context.setConversationId(call.context.conversationId);
+ call.model.processResponse(n, call.callback);
+ }
}
};
@@ -925,6 +932,7 @@
this.values = [];
this.sourceRefs = [];
this.workingRefs = [];
+ this.context = new Seam.Context();
Seam.Model.prototype.addExpression = function(alias, expr) {
this.expressions.push({alias: alias, expr: expr});
@@ -963,7 +971,7 @@
Seam.Model.prototype.fetch = function(action, cb) {
var r = this.createFetchRequest(action, cb);
- var env = Seam.createEnvelope(Seam.createHeader(r.id), r.data);
+ var env = Seam.createEnvelope(Seam.createHeader(r.id, this.context), r.data);
Seam.pendingCalls.put(r.id, r);
Seam.sendAjaxRequest(env, Seam.PATH_MODEL, Seam.processResponse, false);
};
@@ -1041,7 +1049,7 @@
d.scanForChanges(this.values[i].value);
}
var r = this.createApplyRequest(a, d, cb);
- var env = Seam.createEnvelope(Seam.createHeader(r.id), r.data);
+ var env = Seam.createEnvelope(Seam.createHeader(r.id, this.context), r.data);
Seam.pendingCalls.put(r.id, r);
Seam.sendAjaxRequest(env, Seam.PATH_MODEL, Seam.processResponse, false);
};
@@ -1121,7 +1129,7 @@
if (v[p] != undefined) return;
var refId = this.getRefId(v);
var r = this.createExpandRequest(refId, p, cb);
- var env = Seam.createEnvelope(Seam.createHeader(r.id), r.data);
+ var env = Seam.createEnvelope(Seam.createHeader(r.id, this.context), r.data);
Seam.pendingCalls.put(r.id, r);
Seam.sendAjaxRequest(env, Seam.PATH_MODEL, Seam.processResponse, false);
};
14 years, 11 months
Seam SVN: r11924 - in modules/remoting/trunk/examples/model/src/main: webapp and 1 other directory.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2010-01-07 04:04:32 -0500 (Thu, 07 Jan 2010)
New Revision: 11924
Modified:
modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Person.java
modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/PersonAction.java
modules/remoting/trunk/examples/model/src/main/webapp/model.html
modules/remoting/trunk/examples/model/src/main/webapp/style.css
Log:
example improvements
Modified: modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Person.java
===================================================================
--- modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Person.java 2010-01-07 07:39:41 UTC (rev 11923)
+++ modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/Person.java 2010-01-07 09:04:32 UTC (rev 11924)
@@ -4,6 +4,7 @@
import java.util.Collection;
import java.util.Date;
+import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
@@ -63,7 +64,7 @@
this.dateOfBirth = dateOfBirth;
}
- @OneToMany(fetch = FetchType.LAZY, mappedBy = "person")
+ @OneToMany(fetch = FetchType.LAZY, mappedBy = "person", cascade = CascadeType.ALL)
public Collection<Address> getAddresses()
{
return addresses;
Modified: modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/PersonAction.java
===================================================================
--- modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/PersonAction.java 2010-01-07 07:39:41 UTC (rev 11923)
+++ modules/remoting/trunk/examples/model/src/main/java/org/jboss/seam/remoting/examples/model/PersonAction.java 2010-01-07 09:04:32 UTC (rev 11924)
@@ -1,6 +1,7 @@
package org.jboss.seam.remoting.examples.model;
import java.io.Serializable;
+import java.util.ArrayList;
import javax.enterprise.context.Conversation;
import javax.enterprise.context.ConversationScoped;
@@ -24,6 +25,7 @@
{
conversation.begin();
person = new Person();
+ person.setAddresses(new ArrayList<Address>());
}
@WebRemote
Modified: modules/remoting/trunk/examples/model/src/main/webapp/model.html
===================================================================
--- modules/remoting/trunk/examples/model/src/main/webapp/model.html 2010-01-07 07:39:41 UTC (rev 11923)
+++ modules/remoting/trunk/examples/model/src/main/webapp/model.html 2010-01-07 09:04:32 UTC (rev 11924)
@@ -23,12 +23,15 @@
var model = null;
+ // Clears all the child elements of the specified element
function clearElement(e) {
while (e.hasChildNodes()) {
e.removeChild(e.firstChild);
}
}
+ // Creates an anchor element inside a div with the specified text
+ // and optional onclick event
function createLinkRow(text, onclick) {
var link = document.createElement("a");
link.href = "#";
@@ -39,6 +42,7 @@
return div;
}
+ // Loads the full list of People entities via a remoting call
function loadPeople() {
var personList = document.getElementById("personList");
@@ -58,8 +62,18 @@
function getElementValue(elementName) {
var value = document.getElementById(elementName).value;
return (value.trim().length > 0) ? value : null;
- }
+ }
+ function createPerson() {
+ var action = new Seam.Action()
+ .setBeanType("org.jboss.seam.remoting.examples.model.PersonAction")
+ .setMethod("createPerson");
+
+ model = new Seam.Model();
+ model.addBeanProperty("person", "org.jboss.seam.remoting.examples.model.PersonAction", "person");
+ model.fetch(action, fetchCallback);
+ }
+
function editPerson(personId) {
var action = new Seam.Action()
.setBeanType("org.jboss.seam.remoting.examples.model.PersonAction")
@@ -75,11 +89,13 @@
var person = model.getValue("person");
document.getElementById("firstName").value = person.getFirstName();
document.getElementById("lastName").value = person.getLastName();
- document.getElementById("dob").value = person.getDateOfBirth();
+ document.getElementById("dob").value = person.getDateOfBirth().toLocaleString();
var addressDiv = document.getElementById("addresses");
clearElement(addressDiv);
addressDiv.appendChild(createLinkRow("Load addresses", "loadAddresses()"));
+
+ document.getElementById("personDetail").style.display = "block";
}
function loadAddresses() {
@@ -136,12 +152,23 @@
}
function apply() {
+ var person = model.getValue("person");
+ person.firstName = document.getElementById("firstName").value;
+ person.lastName = document.getElementById("lastName").value;
+ person.dateOfBirth = new Date(document.getElementById("dob").value);
+
var action = new Seam.Action()
.setBeanType("org.jboss.seam.remoting.examples.model.PersonAction")
.setMethod("savePerson");
- model.applyUpdates(action);
+ model.applyUpdates(action, applyCallback);
}
+ function applyCallback() {
+ loadPeople();
+ alert("Changes applied");
+ document.getElementById("personDetail").style.display = "none";
+ }
+
function createDeleteAddressLink(address, div) {
var link = document.createElement("a");
link.href = "#";
@@ -191,16 +218,16 @@
</script>
<div class="listContainer">
- <div class="sectionHeader">People</div>
+ <div class="sectionHeader">People - click to edit</div>
<div id="personList"></div>
<div>
- <a href="#" onclick="javascript:alert('new person')">Create new person</a>
+ <a href="#" onclick="createPerson()">Create new person</a>
</div>
</div>
- <div class="personDetail">
+ <div id="personDetail" style="display:none">
<div class="sectionHeader">Details</div>
<div class="formRow">
Modified: modules/remoting/trunk/examples/model/src/main/webapp/style.css
===================================================================
--- modules/remoting/trunk/examples/model/src/main/webapp/style.css 2010-01-07 07:39:41 UTC (rev 11923)
+++ modules/remoting/trunk/examples/model/src/main/webapp/style.css 2010-01-07 09:04:32 UTC (rev 11924)
@@ -20,7 +20,7 @@
font-weight: bold;
}
-div.personDetail {
+#personDetail {
margin-left: 4px;
background-color: #eeeeee;
float: left;
14 years, 11 months
Seam SVN: r11923 - modules/remoting/trunk/examples/model/src/main/webapp.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2010-01-07 02:39:41 -0500 (Thu, 07 Jan 2010)
New Revision: 11923
Modified:
modules/remoting/trunk/examples/model/src/main/webapp/model.html
Log:
added address add/remove functions
Modified: modules/remoting/trunk/examples/model/src/main/webapp/model.html
===================================================================
--- modules/remoting/trunk/examples/model/src/main/webapp/model.html 2010-01-07 07:39:07 UTC (rev 11922)
+++ modules/remoting/trunk/examples/model/src/main/webapp/model.html 2010-01-07 07:39:41 UTC (rev 11923)
@@ -10,7 +10,7 @@
<body onload="loadPeople()">
- <h1>Seam Remoting - Model Example</h1>
+ <h1>Seam Remoting - Model API Example</h1>
<script type="text/javascript" src="seam/resource/remoting/resource/remote.js"></script>
<script type="text/javascript" src="seam/resource/remoting/interface.js?personSearch"></script>
@@ -80,8 +80,6 @@
var addressDiv = document.getElementById("addresses");
clearElement(addressDiv);
addressDiv.appendChild(createLinkRow("Load addresses", "loadAddresses()"));
-
- document.getElementById("applyChanges").disabled = false;
}
function loadAddresses() {
@@ -105,8 +103,23 @@
} else {
addressDiv.appendChild(document.createTextNode("No addresses found"));
}
+
+ addressDiv.appendChild(createLinkRow("Create new address", "createAddress()"));
}
+ function createAddress() {
+ var address = Seam.createBean("org.jboss.seam.remoting.examples.model.Address");
+ address.person = model.getValue("person");
+ address.streetNo = "";
+ address.streetName = "";
+ address.suburb = "";
+ address.postCode = "";
+ address.country = "";
+ address.person.addresses.push(address);
+ var addressesDiv = document.getElementById("addresses");
+ addressesDiv.insertBefore(createAddressEditor(address), addressesDiv.lastChild);
+ }
+
function createLabel(text) {
var lbl = document.createElement("label");
lbl.appendChild(document.createTextNode(text));
@@ -122,12 +135,11 @@
return input;
}
- function apply() {
- document.getElementById("applyChanges").disabled = true;
-
- // TODO apply person changes here
-
- model.applyUpdates();
+ function apply() {
+ var action = new Seam.Action()
+ .setBeanType("org.jboss.seam.remoting.examples.model.PersonAction")
+ .setMethod("savePerson");
+ model.applyUpdates(action);
}
function createDeleteAddressLink(address, div) {
@@ -211,7 +223,7 @@
</div>
<div class="personAction">
- <button id="applyChanges" onclick="apply()" disabled="true">Apply changes</button>
+ <button id="applyChanges" onclick="apply()">Apply changes</button>
</div>
<br class="clear"/>
14 years, 11 months
Seam SVN: r11922 - in modules/remoting/trunk/src/main: resources/org/jboss/seam/remoting and 1 other directory.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2010-01-07 02:39:07 -0500 (Thu, 07 Jan 2010)
New Revision: 11922
Modified:
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java
modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js
Log:
fixed collection processing for model apply update requests
Modified: modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java
===================================================================
--- modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java 2010-01-07 07:31:16 UTC (rev 11921)
+++ modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java 2010-01-07 07:39:07 UTC (rev 11922)
@@ -6,6 +6,7 @@
import java.io.StringReader;
import java.lang.reflect.Array;
import java.lang.reflect.Type;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -20,7 +21,6 @@
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.jboss.seam.remoting.Call;
-import org.jboss.seam.remoting.CallContext;
import org.jboss.seam.remoting.MarshalUtils;
import org.jboss.seam.remoting.RequestContext;
import org.jboss.seam.remoting.RequestHandler;
@@ -226,15 +226,21 @@
{
model.getCallContext().getInRefs().put("" + i, model.getCallContext().getOutRefs().get(i));
}
+
+ List<Wrapper> newRefs = new ArrayList<Wrapper>();
- CallContext ctx = new CallContext(beanManager);
-
Element refsElement = modelElement.element("refs");
for (Element ref : (List<Element>) refsElement.elements("ref"))
{
- ctx.createWrapperFromElement(ref);
+ newRefs.add(model.getCallContext().createWrapperFromElement(ref));
}
+ // Unmarshal any new ref values
+ for (Wrapper w : newRefs)
+ {
+ w.unmarshal();
+ }
+
Element delta = modelElement.element("delta");
if (delta != null)
{
@@ -421,7 +427,14 @@
for (int i = 0; i < sourceList.size(); i++)
{
- targetList.set(i, sourceList.get(i));
+ if (targetList.size() < i + 1)
+ {
+ targetList.add(i, sourceList.get(i));
+ }
+ else if (targetList.get(i) != sourceList.get(i))
+ {
+ targetList.set(i, sourceList.get(i));
+ }
}
return true;
}
Modified: modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js
===================================================================
--- modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js 2010-01-07 07:31:16 UTC (rev 11921)
+++ modules/remoting/trunk/src/main/resources/org/jboss/seam/remoting/remote.js 2010-01-07 07:39:07 UTC (rev 11922)
@@ -908,12 +908,13 @@
return null;
};
- Seam.Delta.prototype.buildRefs = function() {
- var refs = [];
+ Seam.Delta.prototype.getNewRefs = function() {
+ var nr = [];
for (var i=0; i<this.refs.elements.length; i++) {
- if (this.refs.elements[i].value) refs.push(this.refs.elements[i]);
+ var key = this.refs.elements[i].key;
+ if (Seam.getBeanType(key) && this.model.getRefId(key) == -1) nr.push(key);
}
- return refs;
+ return nr;
};
};
@@ -1047,8 +1048,11 @@
Seam.Model.prototype.createApplyRequest = function(a, delta, cb) {
var callId = "" + Seam.__callId++;
+ var refs = [];
+ for (var i=0; i<this.workingRefs.length; i++) {
+ refs[i] = this.workingRefs[i];
+ }
var d = "<model id=\"" + this.id + "\" operation=\"apply\">";
- var refs = delta.buildRefs();
if (a) {
d += "<action>";
if (a.beanType) {
@@ -1071,13 +1075,13 @@
for (var i=0; i<delta.refs.elements.length; i++) {
var k = delta.refs.elements[i].key;
var v = delta.refs.elements[i].value;
- var refId = this.getRefId(k);
if (v) {
+ var refId = this.getRefId(k);
d += "<changeset refid=\"" + refId + "\">";
if (v instanceof Seam.Changeset) {
for (var j=0; j<v.propertyChange.elements.length; j++) {
d += "<member name=\"" + v.propertyChange.elements[j].key + "\">";
- d += Seam.serializeValue(v.propertyChange.elements[j].value, null, this.workingRefs);
+ d += Seam.serializeValue(v.propertyChange.elements[j].value, null, refs);
d += "</member>";
}
} else {
@@ -1087,13 +1091,18 @@
}
}
d += "</delta>";
- if (refs.length > 0) {
+ var newRefs = delta.getNewRefs();
+ if (newRefs.length > 0) {
d += "<refs>";
- var idx = this.workingRefs.length;
- for (var i=0; i<refs.length; i++) {
- if (this.getRefId(refs[i]) != -1) {
- d += "<ref id=\"" + ++idx + "\">" + Seam.serializeType(refs[i], refs) + "</ref>";
+ for (var i=0; i<newRefs.length; i++) {
+ var idx = refs.length;
+ for (var j=0; j<refs.length; j++) {
+ if (refs[j] == newRefs[i]) {
+ idx = j;
+ break;
+ }
}
+ d += "<ref id=\"" + idx + "\">" + Seam.serializeType(newRefs[i], refs) + "</ref>";
}
d += "</refs>";
}
14 years, 11 months
Seam SVN: r11921 - modules/drools/trunk/src/main/java/org/jboss/seam/drools.
by seam-commits@lists.jboss.org
Author: tsurdilovic
Date: 2010-01-07 02:31:16 -0500 (Thu, 07 Jan 2010)
New Revision: 11921
Added:
modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeBaseManagerConfig.java
Modified:
modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeBaseManager.java
modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeSessionManager.java
Log:
Drools 5 integration.
Modified: modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeBaseManager.java
===================================================================
--- modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeBaseManager.java 2010-01-07 03:58:59 UTC (rev 11920)
+++ modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeBaseManager.java 2010-01-07 07:31:16 UTC (rev 11921)
@@ -3,12 +3,9 @@
import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
-import java.util.Properties;
-import java.util.regex.Pattern;
import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.context.Dependent;
import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.Bean;
@@ -17,10 +14,8 @@
import javax.security.auth.login.Configuration;
import org.drools.KnowledgeBase;
-import org.drools.KnowledgeBaseConfiguration;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.KnowledgeBuilder;
-import org.drools.builder.KnowledgeBuilderConfiguration;
import org.drools.builder.KnowledgeBuilderError;
import org.drools.builder.KnowledgeBuilderErrors;
import org.drools.builder.KnowledgeBuilderFactory;
@@ -38,28 +33,23 @@
*
* @author Tihomir Surdilovic
*/
-@Dependent
public class KnowledgeBaseManager
{
private static final Logger log = LoggerFactory.getLogger(KnowledgeBaseManager.class);
-
- private static final Pattern DIVIDER = Pattern.compile(";");
- private static final int RESOURCE_PATH = 0;
- private static final int RESOURCE = 1;
- private static final int RESOURCE_TYPE = 2;
- private static final int RESOURCE_TEMPLATE_DATA = 3;
private static final String RESOURCE_TYPE_URL = "url";
private static final String RESOURCE_TYPE_FILE = "file";
private static final String RESOURCE_TYPE_CLASSPATH = "classpath";
-
- private String knowledgeBuilderConfig;
- private String knowledgeBaseConfig;
- private String[] ruleResources;
- private String[] eventListeners;
+
+ private KnowledgeBaseManagerConfig kbaseManagerConfig;
private KnowledgeBase kbase;
@Inject
BeanManager manager;
+
+ @Inject
+ public KnowledgeBaseManager(KnowledgeBaseManagerConfig kbaseManagerConfig) {
+ this.kbaseManagerConfig = kbaseManagerConfig;
+ }
@Produces
@ApplicationScoped
@@ -76,32 +66,13 @@
@PostConstruct
private void createKBase() throws Exception
{
- KnowledgeBuilderConfiguration kbuilderconfig = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
- // Only allow resource for .properties files
- if (knowledgeBuilderConfig != null && knowledgeBuilderConfig.endsWith(".properties"))
+ KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(kbaseManagerConfig.getKnowledgeBuilderConfiguration());
+
+ for (String nextResource : kbaseManagerConfig.getRuleResources())
{
- Properties kbuilderProp = new Properties();
- InputStream in = this.getClass().getClassLoader().getResourceAsStream(knowledgeBuilderConfig);
- if (in == null)
- {
- throw new IllegalStateException("Could not locate knowledgeBuilderConfig: " + knowledgeBuilderConfig);
- }
- kbuilderProp.load(in);
- in.close();
- kbuilderconfig = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(kbuilderProp, null);
- log.debug("KnowledgeBuilderConfiguration loaded: " + knowledgeBuilderConfig);
+ addResource(kbuilder, nextResource);
}
-
- KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(kbuilderconfig);
-
- if (ruleResources != null)
- {
- for (String nextResource : ruleResources)
- {
- addResource(kbuilder, nextResource);
- }
- }
-
+
KnowledgeBuilderErrors kbuildererrors = kbuilder.getErrors();
if (kbuildererrors.size() > 0)
{
@@ -112,29 +83,12 @@
manager.fireEvent(new KnowledgeBuilderErrorsEvent(kbuildererrors));
}
- KnowledgeBaseConfiguration kbaseconfig = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
-
- // Only allow resource for .properties files
- if (knowledgeBaseConfig != null && knowledgeBaseConfig.endsWith(".properties"))
- {
- Properties kbaseProp = new Properties();
- InputStream in = this.getClass().getClassLoader().getResourceAsStream(knowledgeBaseConfig);
- if (in == null)
- {
- throw new IllegalStateException("Could not locate knowledgeBaseConfig: " + knowledgeBaseConfig);
- }
- kbaseProp.load(in);
- in.close();
- kbaseconfig = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(kbaseProp, null);
- log.debug("KnowledgeBaseConfiguration loaded: " + knowledgeBaseConfig);
- }
-
- kbase = KnowledgeBaseFactory.newKnowledgeBase(kbaseconfig);
+ kbase = KnowledgeBaseFactory.newKnowledgeBase(kbaseManagerConfig.getKnowledgeBaseConfiguration());
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
- if (eventListeners != null)
+ if (kbaseManagerConfig.getEventListeners() != null)
{
- for (String eventListener : eventListeners)
+ for (String eventListener : kbaseManagerConfig.getEventListeners())
{
addEventListener(kbase, eventListener);
}
@@ -159,27 +113,18 @@
protected void addResource(KnowledgeBuilder kbuilder, String resource) throws Exception
{
- String[] resourceParts = DIVIDER.split(resource.trim());
-
- if (resourceParts.length < 3)
- {
- log.error("Invalid resource definition: " + resource);
- }
- else
- {
- ResourceType resourceType = ResourceType.getResourceType(resourceParts[RESOURCE_TYPE]);
-
- if (resourceParts.length == 4)
- {
+ if(kbaseManagerConfig.isValidResource(resource)) {
+ ResourceType resourceType = ResourceType.getResourceType(kbaseManagerConfig.getResourceType(resource));
+ if(kbaseManagerConfig.isRuleTemplate(resource)) {
@SuppressWarnings("unchecked")
- Bean<TemplateDataProvider> templateDataProviderBean = (Bean<TemplateDataProvider>) manager.getBeans(resourceParts[RESOURCE_TEMPLATE_DATA]).iterator().next();
+ Bean<TemplateDataProvider> templateDataProviderBean = (Bean<TemplateDataProvider>) manager.getBeans(kbaseManagerConfig.getTemplateData(resource)).iterator().next();
TemplateDataProvider templateDataProvider = (TemplateDataProvider) manager.getReference(templateDataProviderBean, Configuration.class, manager.createCreationalContext(templateDataProviderBean));
- InputStream templateStream = this.getClass().getClassLoader().getResourceAsStream(resourceParts[RESOURCE]);
+ InputStream templateStream = this.getClass().getClassLoader().getResourceAsStream(kbaseManagerConfig.getRuleResource(resource));
if (templateStream == null)
{
- throw new IllegalStateException("Could not locate rule resource: " + resourceParts[RESOURCE]);
+ throw new IllegalStateException("Could not locate rule resource: " + kbaseManagerConfig.getRuleResource(resource));
}
ObjectDataCompiler converter = new ObjectDataCompiler();
@@ -189,75 +134,29 @@
Reader rdr = new StringReader(drl);
kbuilder.add(ResourceFactory.newReaderResource(rdr), resourceType);
- }
- else
- {
- if (resourceParts[RESOURCE_PATH].equals(RESOURCE_TYPE_URL))
+ } else {
+ if (kbaseManagerConfig.getResourcePath(resource).equals(RESOURCE_TYPE_URL))
{
- kbuilder.add(ResourceFactory.newUrlResource(resourceParts[RESOURCE]), resourceType);
- manager.fireEvent(new RuleResourceAddedEvent(resourceParts[RESOURCE]));
+ kbuilder.add(ResourceFactory.newUrlResource(kbaseManagerConfig.getRuleResource(resource)), resourceType);
+ manager.fireEvent(new RuleResourceAddedEvent(kbaseManagerConfig.getRuleResource(resource)));
}
- else if (resourceParts[RESOURCE_PATH].equals(RESOURCE_TYPE_FILE))
+ else if (kbaseManagerConfig.getResourcePath(resource).equals(RESOURCE_TYPE_FILE))
{
- kbuilder.add(ResourceFactory.newFileResource(resourceParts[RESOURCE]), resourceType);
- manager.fireEvent(new RuleResourceAddedEvent(resourceParts[RESOURCE]));
+ kbuilder.add(ResourceFactory.newFileResource(kbaseManagerConfig.getRuleResource(resource)), resourceType);
+ manager.fireEvent(new RuleResourceAddedEvent(kbaseManagerConfig.getRuleResource(resource)));
}
- else if (resourceParts[RESOURCE_PATH].equals(RESOURCE_TYPE_CLASSPATH))
+ else if (kbaseManagerConfig.getResourcePath(resource).equals(RESOURCE_TYPE_CLASSPATH))
{
- kbuilder.add(ResourceFactory.newClassPathResource(resourceParts[RESOURCE]), resourceType);
- manager.fireEvent(new RuleResourceAddedEvent(resourceParts[RESOURCE]));
+ kbuilder.add(ResourceFactory.newClassPathResource(kbaseManagerConfig.getRuleResource(resource)), resourceType);
+ manager.fireEvent(new RuleResourceAddedEvent(kbaseManagerConfig.getRuleResource(resource)));
}
else
{
- log.error("Invalid resource path: " + resourceParts[RESOURCE_PATH]);
+ log.error("Invalid resource path: " + kbaseManagerConfig.getResourcePath(resource));
}
}
+ } else {
+ log.error("Invalid resource definition: " + resource);
}
}
-
- public String getKnowledgeBuilderConfig()
- {
- return knowledgeBuilderConfig;
- }
-
- @Inject
- public void setKnowledgeBuilderConfig(String knowledgeBuilderConfig)
- {
- this.knowledgeBuilderConfig = knowledgeBuilderConfig;
- }
-
- public String getKnowledgeBaseConfig()
- {
- return knowledgeBaseConfig;
- }
-
- @Inject
- public void setKnowledgeBaseConfig(String knowledgeBaseConfig)
- {
- this.knowledgeBaseConfig = knowledgeBaseConfig;
- }
-
- public String[] getRuleResources()
- {
- return ruleResources;
- }
-
- @Inject
- public void setRuleResources(String[] ruleResources)
- {
- this.ruleResources = ruleResources;
- }
-
- public String[] getEventListeners()
- {
- return eventListeners;
- }
-
- @Inject
- public void setEventListeners(String[] eventListeners)
- {
- this.eventListeners = eventListeners;
- }
-
-
-}
+}
\ No newline at end of file
Added: modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeBaseManagerConfig.java
===================================================================
--- modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeBaseManagerConfig.java (rev 0)
+++ modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeBaseManagerConfig.java 2010-01-07 07:31:16 UTC (rev 11921)
@@ -0,0 +1,139 @@
+package org.jboss.seam.drools;
+
+import java.io.InputStream;
+import java.util.Properties;
+import java.util.regex.Pattern;
+
+import org.drools.KnowledgeBaseConfiguration;
+import org.drools.KnowledgeBaseFactory;
+import org.drools.builder.KnowledgeBuilderConfiguration;
+import org.drools.builder.KnowledgeBuilderFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Drools KnowledgeBaseManager Configuration.
+ *
+ * @author Tihomir Surdilovic
+ */
+public class KnowledgeBaseManagerConfig
+{
+ private static final Logger log = LoggerFactory.getLogger(KnowledgeBaseManagerConfig.class);
+
+ private static final Pattern DIVIDER = Pattern.compile(";");
+ private static final int RESOURCE_PATH = 0;
+ private static final int RESOURCE = 1;
+ private static final int RESOURCE_TYPE = 2;
+ private static final int RESOURCE_TEMPLATE_DATA = 3;
+
+ private String knowledgeBuilderConfig;
+ private String knowledgeBaseConfig;
+ private String[] ruleResources;
+ private String[] eventListeners;
+
+ public KnowledgeBuilderConfiguration getKnowledgeBuilderConfiguration() throws Exception
+ {
+ KnowledgeBuilderConfiguration kbuilderconfig = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
+ // Only allow resource for .properties files
+ if (knowledgeBuilderConfig != null && knowledgeBuilderConfig.endsWith(".properties"))
+ {
+ Properties kbuilderProp = new Properties();
+ InputStream in = this.getClass().getClassLoader().getResourceAsStream(knowledgeBuilderConfig);
+ if (in == null)
+ {
+ throw new IllegalStateException("Could not locate knowledgeBuilderConfig: " + knowledgeBuilderConfig);
+ }
+ kbuilderProp.load(in);
+ in.close();
+ kbuilderconfig = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(kbuilderProp, null);
+ log.debug("KnowledgeBuilderConfiguration loaded: " + knowledgeBuilderConfig);
+ }
+ return kbuilderconfig;
+ }
+
+ public KnowledgeBaseConfiguration getKnowledgeBaseConfiguration() throws Exception
+ {
+ KnowledgeBaseConfiguration kbaseconfig = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
+
+ // Only allow resource for .properties files
+ if (knowledgeBaseConfig != null && knowledgeBaseConfig.endsWith(".properties"))
+ {
+ Properties kbaseProp = new Properties();
+ InputStream in = this.getClass().getClassLoader().getResourceAsStream(knowledgeBaseConfig);
+ if (in == null)
+ {
+ throw new IllegalStateException("Could not locate knowledgeBaseConfig: " + knowledgeBaseConfig);
+ }
+ kbaseProp.load(in);
+ in.close();
+ kbaseconfig = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(kbaseProp, null);
+ log.debug("KnowledgeBaseConfiguration loaded: " + knowledgeBaseConfig);
+ }
+ return kbaseconfig;
+ }
+
+ public boolean isValidResource(String resource) {
+ return DIVIDER.split(resource.trim()).length >= 3;
+ }
+
+ public boolean isRuleTemplate(String resource) {
+ return DIVIDER.split(resource.trim()).length == 4;
+ }
+
+ public String getResourceType(String resource) {
+ return DIVIDER.split(resource.trim())[RESOURCE_TYPE];
+ }
+
+ public String getRuleResource(String resource) {
+ return DIVIDER.split(resource.trim())[RESOURCE];
+ }
+
+ public String getTemplateData(String resource) {
+ return DIVIDER.split(resource.trim())[RESOURCE_TEMPLATE_DATA];
+ }
+
+ public String getResourcePath(String resource) {
+ return DIVIDER.split(resource.trim())[RESOURCE_PATH];
+ }
+
+ public String getKnowledgeBuilderConfig()
+ {
+ return knowledgeBuilderConfig;
+ }
+
+ public void setKnowledgeBuilderConfig(String knowledgeBuilderConfig)
+ {
+ this.knowledgeBuilderConfig = knowledgeBuilderConfig;
+ }
+
+ public String getKnowledgeBaseConfig()
+ {
+ return knowledgeBaseConfig;
+ }
+
+ public void setKnowledgeBaseConfig(String knowledgeBaseConfig)
+ {
+ this.knowledgeBaseConfig = knowledgeBaseConfig;
+ }
+
+ public String[] getRuleResources()
+ {
+ return ruleResources;
+ }
+
+ public void setRuleResources(String[] ruleResources)
+ {
+ this.ruleResources = ruleResources;
+ }
+
+ public String[] getEventListeners()
+ {
+ return eventListeners;
+ }
+
+ public void setEventListeners(String[] eventListeners)
+ {
+ this.eventListeners = eventListeners;
+ }
+
+}
Modified: modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeSessionManager.java
===================================================================
--- modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeSessionManager.java 2010-01-07 03:58:59 UTC (rev 11920)
+++ modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeSessionManager.java 2010-01-07 07:31:16 UTC (rev 11921)
@@ -16,7 +16,6 @@
*
* @author Tihomir Surdilovic
*/
-@Dependent
public class KnowledgeSessionManager
{
private static final Logger log = LoggerFactory.getLogger(KnowledgeSessionManager.class);
14 years, 11 months
Seam SVN: r11920 - modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2010-01-06 22:58:59 -0500 (Wed, 06 Jan 2010)
New Revision: 11920
Modified:
modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java
Log:
fix NPE
Modified: modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java
===================================================================
--- modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java 2010-01-07 03:28:27 UTC (rev 11919)
+++ modules/remoting/trunk/src/main/java/org/jboss/seam/remoting/model/ModelHandler.java 2010-01-07 03:58:59 UTC (rev 11920)
@@ -220,6 +220,13 @@
Model model = registry.getModel(modelElement.attributeValue("id"));
model.setAction(null);
+ // We clone the outRefs to the inRefs so that the context can locate
+ // already-loaded refs when unmarshalling
+ for (int i = 0; i < model.getCallContext().getOutRefs().size(); i++)
+ {
+ model.getCallContext().getInRefs().put("" + i, model.getCallContext().getOutRefs().get(i));
+ }
+
CallContext ctx = new CallContext(beanManager);
Element refsElement = modelElement.element("refs");
@@ -262,7 +269,7 @@
else
{
Type t = ((BeanWrapper) target).getBeanPropertyType(name);
- if (!cloneBagContents(source.convert(t), targetBag))
+ if (!cloneBagContents(source.convert(t), ((Wrapper) targetBag).getValue()));
{
((BeanWrapper) target).setBeanProperty(name, source);
}
14 years, 11 months