Repository: deltaspike Updated Branches: refs/heads/master 11a1b1365 -> b62fad9d4
DELTASPIKE-757 - tests for max windowscope per session Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/b62fad9d Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/b62fad9d Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/b62fad9d Branch: refs/heads/master Commit: b62fad9d427a1bc29dcdfd128aa729a9345349aa Parents: 11a1b13 Author: Rafael Benevides <[email protected]> Authored: Wed Oct 29 12:13:45 2014 -0200 Committer: Rafael Benevides <[email protected]> Committed: Wed Oct 29 12:13:45 2014 -0200 ---------------------------------------------------------------------- .../injection/uc004/InjectionDroneTest.java | 3 - .../impl/scope/window/MyWindowScopedBean.java | 28 +++++ .../impl/scope/window/WindowMaxCountTest.java | 120 +++++++++++++++++++ .../META-INF/apache-deltaspike.properties | 1 + .../windowScopedContextTest/windowcount.xhtml | 17 +++ 5 files changed, 166 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b62fad9d/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/injection/uc004/InjectionDroneTest.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/injection/uc004/InjectionDroneTest.java b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/injection/uc004/InjectionDroneTest.java index ff999a4..0649da1 100644 --- a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/injection/uc004/InjectionDroneTest.java +++ b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/injection/uc004/InjectionDroneTest.java @@ -72,13 +72,10 @@ public class InjectionDroneTest public void testValidator() throws MalformedURLException { driver.get(new URL(contextPath, "testValidatorConverter.xhtml").toString()); - System.out.println("Antes do Click:" + driver.getPageSource()); WebElement convertedValue = driver.findElement(By.id("validator:stringValue")); convertedValue.sendKeys("DeltaSpike"); WebElement testConveterButton = driver.findElement(By.id("validator:testValidatorButton")); testConveterButton.click(); - System.out.println("*****************************"); - System.out.println("Depois do Click:" + driver.getPageSource()); Assert.assertTrue(ExpectedConditions.textToBePresentInElement(By.id("messages"), "Worked").apply(driver)); } http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b62fad9d/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/window/MyWindowScopedBean.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/window/MyWindowScopedBean.java b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/window/MyWindowScopedBean.java new file mode 100644 index 0000000..0e6d8f4 --- /dev/null +++ b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/window/MyWindowScopedBean.java @@ -0,0 +1,28 @@ +package org.apache.deltaspike.test.jsf.impl.scope.window; + +import java.io.Serializable; + +import javax.inject.Named; + +import org.apache.deltaspike.core.api.scope.WindowScoped; + +@Named +@WindowScoped +public class MyWindowScopedBean implements Serializable +{ + + private static final long serialVersionUID = 1L; + + private int value = 0; + + public int getValue() + { + return value; + } + + public void count() + { + value++; + } + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b62fad9d/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/window/WindowMaxCountTest.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/window/WindowMaxCountTest.java b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/window/WindowMaxCountTest.java new file mode 100644 index 0000000..8fd224d --- /dev/null +++ b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/window/WindowMaxCountTest.java @@ -0,0 +1,120 @@ +package org.apache.deltaspike.test.jsf.impl.scope.window; + +import java.net.MalformedURLException; +import java.net.URL; + +import org.apache.deltaspike.test.category.WebProfileCategory; +import org.apache.deltaspike.test.jsf.impl.util.ArchiveUtils; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.drone.api.annotation.Drone; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.arquillian.warp.WarpTest; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; + +@WarpTest +@RunWith(Arquillian.class) +@Category(WebProfileCategory.class) +public class WindowMaxCountTest +{ + + @ArquillianResource + private URL contextPath; + + @Drone + private WebDriver driver; + + @Deployment + public static WebArchive deploy() + { + WebArchive archive = ShrinkWrap + .create(WebArchive.class, "windowMaxCountTest.war") + .addPackage(WindowMaxCountTest.class.getPackage()) + .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreAndJsfArchive()) + .addAsLibraries(ArchiveUtils.getDeltaSpikeSecurityArchive()) + .addAsWebResource("windowScopedContextTest/windowcount.xhtml", "/windowcount.xhtml") + .addAsWebInfResource("default/WEB-INF/web.xml", "web.xml") + .addAsWebInfResource("META-INF/apache-deltaspike.properties", + "classes/META-INF/apache-deltaspike.properties") + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); + return archive; + } + + @Test + @RunAsClient + public void maxWindowPerSessionTest() throws MalformedURLException + { + // PAGE 1 - REQUEST 1 + driver.get(new URL(contextPath, "windowcount.xhtml").toString()); + // click once + WebElement button = driver.findElement(By.id("form:count")); + button.click(); + WebElement value = driver.findElement(By.id("form:value")); + Assert.assertEquals("1", value.getText()); + driver.get(driver.getCurrentUrl()); + // click twice + button = driver.findElement(By.id("form:count")); + button.click(); + value = driver.findElement(By.id("form:value")); + Assert.assertEquals("2", value.getText()); + String page1 = driver.getCurrentUrl(); + + // PAGE 2 - REQUEST 2 + driver.get(new URL(contextPath, "windowcount.xhtml").toString()); + // click once + button = driver.findElement(By.id("form:count")); + button.click(); + value = driver.findElement(By.id("form:value")); + Assert.assertEquals("1", value.getText()); + driver.get(driver.getCurrentUrl()); + // click twice + button = driver.findElement(By.id("form:count")); + button.click(); + value = driver.findElement(By.id("form:value")); + Assert.assertEquals("2", value.getText()); + + // PAGE 3 - REQUEST 3 to force the oldest (page 1) WindowScope to drop + driver.get(new URL(contextPath, "windowcount.xhtml").toString()); + // click once + button = driver.findElement(By.id("form:count")); + button.click(); + value = driver.findElement(By.id("form:value")); + Assert.assertEquals("1", value.getText()); + driver.get(driver.getCurrentUrl()); + // click twice + button = driver.findElement(By.id("form:count")); + button.click(); + value = driver.findElement(By.id("form:value")); + Assert.assertEquals("2", value.getText()); + String page3 = driver.getCurrentUrl(); + + // PAGE 1 - REQUEST 4 on previous PAGE 1 page (value should get dropped to 0) + driver.get(new URL(page1).toString()); + // click once + button = driver.findElement(By.id("form:count")); + button.click(); + value = driver.findElement(By.id("form:value")); + // Value should return to 1 + Assert.assertEquals("1", value.getText()); + + // PAGE 3 - REQUEST 5 on previous PAGE 3 page (page 1 and page 3 should be the two active pages) + driver.get(new URL(page3).toString()); + button = driver.findElement(By.id("form:count")); + // click once + button.click(); + value = driver.findElement(By.id("form:value")); + // Value should continue to 3 + Assert.assertEquals("3", value.getText()); + } + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b62fad9d/deltaspike/modules/jsf/impl/src/test/resources/META-INF/apache-deltaspike.properties ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jsf/impl/src/test/resources/META-INF/apache-deltaspike.properties b/deltaspike/modules/jsf/impl/src/test/resources/META-INF/apache-deltaspike.properties new file mode 100644 index 0000000..d438dc6 --- /dev/null +++ b/deltaspike/modules/jsf/impl/src/test/resources/META-INF/apache-deltaspike.properties @@ -0,0 +1 @@ +deltaspike.scope.window.max-count=2 http://git-wip-us.apache.org/repos/asf/deltaspike/blob/b62fad9d/deltaspike/modules/jsf/impl/src/test/resources/windowScopedContextTest/windowcount.xhtml ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jsf/impl/src/test/resources/windowScopedContextTest/windowcount.xhtml b/deltaspike/modules/jsf/impl/src/test/resources/windowScopedContextTest/windowcount.xhtml new file mode 100644 index 0000000..dd974cd --- /dev/null +++ b/deltaspike/modules/jsf/impl/src/test/resources/windowScopedContextTest/windowcount.xhtml @@ -0,0 +1,17 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:ui="http://java.sun.com/jsf/facelets" + xmlns:f="http://java.sun.com/jsf/core" + xmlns:h="http://java.sun.com/jsf/html"> + +<h:head></h:head> +<body> + <h:form id="form"> + Value: <h:outputText id="value" value="#{myWindowScopedBean.value}" /> + <br /> + <h:commandButton action="#{myWindowScopedBean.count()}" value="Count" + id="count" /> + </h:form> + +</body> +</html>
