From 9fcb70e9c652f3ec3821b597b9a612494baa24fa Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Mon, 21 Oct 2019 10:18:13 +0200 Subject: [PATCH] [DELTASPIKE-1393] Reproducer test case for issues with CLIENTWINDOW mode when using POST from non-JSF page to a JSF one --- .../windowhandling/clientwindow/test.html | 32 ++++++ .../TestClientWindowJsfModuleConfig.java | 38 +++++++ .../window/WindowScopedContextPostTest.java | 107 ++++++++++++++++++ .../windowScopedContextTest/test.html | 32 ++++++ 4 files changed, 209 insertions(+) create mode 100644 deltaspike/examples/jsf-playground/src/main/webapp/views/windowhandling/clientwindow/test.html create mode 100644 deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/TestClientWindowJsfModuleConfig.java create mode 100644 deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/window/WindowScopedContextPostTest.java create mode 100644 deltaspike/modules/jsf/impl/src/test/resources/windowScopedContextTest/test.html diff --git a/deltaspike/examples/jsf-playground/src/main/webapp/views/windowhandling/clientwindow/test.html b/deltaspike/examples/jsf-playground/src/main/webapp/views/windowhandling/clientwindow/test.html new file mode 100644 index 000000000..36deaecb6 --- /dev/null +++ b/deltaspike/examples/jsf-playground/src/main/webapp/views/windowhandling/clientwindow/test.html @@ -0,0 +1,32 @@ + + + + + + + test + + + +
+ +
+ + diff --git a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/TestClientWindowJsfModuleConfig.java b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/TestClientWindowJsfModuleConfig.java new file mode 100644 index 000000000..9dd1fbb05 --- /dev/null +++ b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/config/TestClientWindowJsfModuleConfig.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.deltaspike.test.jsf.impl.config; + +import org.apache.deltaspike.jsf.api.config.JsfModuleConfig; +import org.apache.deltaspike.jsf.spi.scope.window.ClientWindowConfig; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Specializes; + +@Specializes +@ApplicationScoped +public class TestClientWindowJsfModuleConfig extends JsfModuleConfig +{ + private static final long serialVersionUID = -7188892423502607762L; + + @Override + public ClientWindowConfig.ClientWindowRenderMode getDefaultWindowMode() + { + return ClientWindowConfig.ClientWindowRenderMode.CLIENTWINDOW; + } +} diff --git a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/window/WindowScopedContextPostTest.java b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/window/WindowScopedContextPostTest.java new file mode 100644 index 000000000..2855c0dc6 --- /dev/null +++ b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/window/WindowScopedContextPostTest.java @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.deltaspike.test.jsf.impl.scope.window; + + +import org.apache.deltaspike.test.category.WebProfileCategory; +import org.apache.deltaspike.test.jsf.impl.config.TestClientWindowJsfModuleConfig; +import org.apache.deltaspike.test.jsf.impl.config.TestJsfModuleConfig; +import org.apache.deltaspike.test.jsf.impl.scope.window.beans.WindowScopedBackingBean; +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.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; +import org.openqa.selenium.support.ui.ExpectedConditions; + +import java.net.URL; +import java.util.logging.Logger; + + +/** + * Test for the DeltaSpike JsfMessage Producer + */ +@RunWith(Arquillian.class) +@Category(WebProfileCategory.class) +public class WindowScopedContextPostTest +{ + private static final Logger log = Logger.getLogger(WindowScopedContextPostTest.class.getName()); + + @Drone + private WebDriver driver; + + @ArquillianResource + private URL contextPath; + + @Deployment + public static WebArchive deploy() + { + return ShrinkWrap + .create(WebArchive.class, "windowScopedContextTest.war") + .addPackage(WindowScopedBackingBean.class.getPackage()) + .addClass(TestClientWindowJsfModuleConfig.class) + .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreAndJsfArchive()) + .addAsLibraries(ArchiveUtils.getDeltaSpikeSecurityArchive()) + .addAsWebInfResource("default/WEB-INF/web.xml", "web.xml") + .addAsWebResource("META-INF/resources/deltaspike/windowhandler.js", + "resources/deltaspike/windowhandler.js") + .addAsWebResource("windowScopedContextTest/test.html", "test.html") + .addAsWebResource("windowScopedContextTest/page.xhtml", "page.xhtml") + .addAsWebResource("windowScopedContextTest/page2.xhtml", "page2.xhtml") + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + + @Test + @RunAsClient + public void testWindowId() throws Exception + { + System.out.println("contextpath= " + contextPath); + + //X comment this in if you like to debug the server + //X I've already reported ARQGRA-213 for it + //X Thread.sleep(600000L); + + driver.get(new URL(contextPath, "test.html").toString()); + + driver.findElement(By.id("btn")).click(); + + WebElement inputField = driver.findElement(By.id("test:valueInput")); + inputField.sendKeys("23"); + + WebElement button = driver.findElement(By.id("test:saveButton")); + button.click(); + + Assert.assertTrue(ExpectedConditions.textToBePresentInElement(By.id("valueOutput"), "23").apply(driver)); + + } + + +} diff --git a/deltaspike/modules/jsf/impl/src/test/resources/windowScopedContextTest/test.html b/deltaspike/modules/jsf/impl/src/test/resources/windowScopedContextTest/test.html new file mode 100644 index 000000000..27917bd08 --- /dev/null +++ b/deltaspike/modules/jsf/impl/src/test/resources/windowScopedContextTest/test.html @@ -0,0 +1,32 @@ + + + + + + + test + + + +
+ +
+ +