From fac740cb7a51bb8c2c1898c709f48d14c733d980 Mon Sep 17 00:00:00 2001 From: Bauke Scholtz Date: Sat, 3 Aug 2024 13:22:43 -0400 Subject: [PATCH 1/8] Add minimal configuration for integration tests --- pom.xml | 1 + test/base/pom.xml | 60 ++++++ .../org/eclipse/mojarra/test/base/BaseIT.java | 110 ++++++++++ test/pom.xml | 196 ++++++++++++++++++ 4 files changed, 367 insertions(+) create mode 100644 test/base/pom.xml create mode 100644 test/base/src/main/java/org/eclipse/mojarra/test/base/BaseIT.java create mode 100644 test/pom.xml diff --git a/pom.xml b/pom.xml index ec4c689fb4..2a901ce3a6 100644 --- a/pom.xml +++ b/pom.xml @@ -51,6 +51,7 @@ impl action rest + test diff --git a/test/base/pom.xml b/test/base/pom.xml new file mode 100644 index 0000000000..e9bd597931 --- /dev/null +++ b/test/base/pom.xml @@ -0,0 +1,60 @@ + + + + 4.0.0 + + + org.eclipse.mojarra.test + pom + 4.0.8-SNAPSHOT + + + base + jar + + Mojarra ${project.version} - INTEGRATION TESTS - ${project.artifactId} + + + + org.junit.jupiter + junit-jupiter + 5.10.3 + + + org.jboss.arquillian.junit5 + arquillian-junit5-container + 1.9.1.Final + + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-impl-maven + 3.3.0 + + + org.seleniumhq.selenium + selenium-java + 4.23.0 + + + io.github.bonigarcia + webdrivermanager + 5.9.2 + + + diff --git a/test/base/src/main/java/org/eclipse/mojarra/test/base/BaseIT.java b/test/base/src/main/java/org/eclipse/mojarra/test/base/BaseIT.java new file mode 100644 index 0000000000..a4cc379052 --- /dev/null +++ b/test/base/src/main/java/org/eclipse/mojarra/test/base/BaseIT.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GPL-2.0 with Classpath-exception-2.0 which + * is available at https://openjdk.java.net/legal/gplv2+ce.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 or Apache-2.0 + */ +package org.eclipse.mojarra.test.base; + +import static java.lang.System.getProperty; +import static java.time.Duration.ofSeconds; +import static org.jboss.shrinkwrap.api.ShrinkWrap.create; + +import java.io.File; +import java.net.URL; +import java.util.UUID; +import java.util.function.BooleanSupplier; +import java.util.logging.Level; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.importer.ZipImporter; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +import org.junit.jupiter.api.extension.ExtendWith; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.chrome.ChromeOptions; +import org.openqa.selenium.support.PageFactory; +import org.openqa.selenium.support.ui.WebDriverWait; + +import io.github.bonigarcia.wdm.WebDriverManager; + +@ExtendWith(ArquillianExtension.class) +@TestInstance(Lifecycle.PER_CLASS) +public abstract class BaseIT { + + private WebDriver browser; + + @ArquillianResource + private URL baseURL; + + @Deployment(testable = false) + public static WebArchive createDeployment() { + String warFileName = getProperty("war.file.name") + ".war"; + return create(ZipImporter.class, warFileName) + .importFrom(new File("target/" + warFileName)) + .as(WebArchive.class); + } + + @BeforeAll + public void setup() { + String arquillianBrowser = System.getProperty("arquillian.browser"); + + switch (arquillianBrowser) { + case "chrome": + WebDriverManager.chromedriver().setup(); + ChromeDriver chrome = new ChromeDriver(new ChromeOptions().addArguments("--no-sandbox", "--headless")); + chrome.setLogLevel(Level.INFO); + browser = chrome; + break; + default: + throw new UnsupportedOperationException("arquillian.browser='" + arquillianBrowser + "' is not yet supported"); + } + + PageFactory.initElements(browser, this); + } + + @AfterAll + public void teardown() { + browser.quit(); + } + + protected void open(String resource) { + browser.get(baseURL + resource); + } + + protected String getPageSource() { + return browser.getPageSource(); + } + + protected void guardAjax(Runnable action) { + String uuid = UUID.randomUUID().toString(); + executeScript("window.$ajax = true; faces.ajax.addOnEvent(data => { if (data.status == 'complete') window.$ajax = '" + uuid + "'; })"); + action.run(); + waitUntil(() -> executeScript("return window.$ajax == '" + uuid + "' || (!window.$ajax && document.readyState == 'complete');")); + } + + @SuppressWarnings("unchecked") + private T executeScript(String script) { + return (T) ((JavascriptExecutor) browser).executeScript(script); + } + + private void waitUntil(BooleanSupplier predicate) { + new WebDriverWait(browser, ofSeconds(5)).until($ -> predicate.getAsBoolean()); + } +} diff --git a/test/pom.xml b/test/pom.xml new file mode 100644 index 0000000000..ef33d64866 --- /dev/null +++ b/test/pom.xml @@ -0,0 +1,196 @@ + + + + 4.0.0 + + + org.glassfish + mojarra-parent + 4.0.8-SNAPSHOT + + + org.eclipse.mojarra.test + pom + pom + + Mojarra ${project.version} - INTEGRATION TESTS + + + base + issue5460 + issue5464 + + + + 7.0.16 + chrome + + + + + jakarta.platform + jakarta.jakartaee-web-api + 10.0.0 + provided + + + org.junit.jupiter + junit-jupiter + 5.10.3 + test + + + org.jboss.arquillian.junit5 + arquillian-junit5-container + 1.8.0.Final + test + + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-impl-maven + 3.3.0 + test + + + org.seleniumhq.selenium + selenium-java + 4.23.0 + test + + + io.github.bonigarcia + webdrivermanager + 5.9.2 + test + + + + + + + org.apache.maven.plugins + maven-war-plugin + 3.4.0 + + false + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.7.1 + + ${project.build.directory} + + + + org.apache.maven.plugins + maven-failsafe-plugin + 3.3.1 + + + + integration-test + verify + + + + + + ${arquillian.browser} + ${project.build.finalName} + + + + + + + + + glassfish + + true + + + + org.omnifaces.arquillian + arquillian-glassfish-server-managed + 1.4 + test + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + unpack-glassfish + process-test-classes + + unpack + + + + + org.glassfish.main.distributions + glassfish + ${glassfish.version} + zip + + + + + + update-mojarra + process-test-classes + + copy + + + + + org.glassfish + jakarta.faces + ${project.version} + jar + true + ${project.build.directory}/glassfish7/glassfish/modules + jakarta.faces.jar + + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + ${project.build.directory}/glassfish7 + + + + + + + + From 3ccf81edf7775d9aab01ba37f9ac381c58008274 Mon Sep 17 00:00:00 2001 From: Bauke Scholtz Date: Sat, 3 Aug 2024 13:23:35 -0400 Subject: [PATCH 2/8] Add integration test for #5460 --- test/issue5460/pom.xml | 41 +++++ .../mojarra/test/issue5460/Issue5460Bean.java | 64 ++++++++ .../test/issue5460/Issue5460Component.java | 27 ++++ .../issue5460/src/main/webapp/WEB-INF/web.xml | 17 +++ .../issue5460/src/main/webapp/issue5460.xhtml | 38 +++++ .../resources/components/component.xhtml | 25 ++++ .../mojarra/test/issue5460/Issue5460IT.java | 140 ++++++++++++++++++ 7 files changed, 352 insertions(+) create mode 100644 test/issue5460/pom.xml create mode 100644 test/issue5460/src/main/java/org/eclipse/mojarra/test/issue5460/Issue5460Bean.java create mode 100644 test/issue5460/src/main/java/org/eclipse/mojarra/test/issue5460/Issue5460Component.java create mode 100644 test/issue5460/src/main/webapp/WEB-INF/web.xml create mode 100644 test/issue5460/src/main/webapp/issue5460.xhtml create mode 100644 test/issue5460/src/main/webapp/resources/components/component.xhtml create mode 100644 test/issue5460/src/test/java/org/eclipse/mojarra/test/issue5460/Issue5460IT.java diff --git a/test/issue5460/pom.xml b/test/issue5460/pom.xml new file mode 100644 index 0000000000..3d69571563 --- /dev/null +++ b/test/issue5460/pom.xml @@ -0,0 +1,41 @@ + + + + 4.0.0 + + + org.eclipse.mojarra.test + pom + 4.0.8-SNAPSHOT + + + issue5460 + war + + Mojarra ${project.version} - INTEGRATION TESTS - ${project.artifactId} + + + + org.eclipse.mojarra.test + base + ${project.version} + test + + + diff --git a/test/issue5460/src/main/java/org/eclipse/mojarra/test/issue5460/Issue5460Bean.java b/test/issue5460/src/main/java/org/eclipse/mojarra/test/issue5460/Issue5460Bean.java new file mode 100644 index 0000000000..67b2ebd0e3 --- /dev/null +++ b/test/issue5460/src/main/java/org/eclipse/mojarra/test/issue5460/Issue5460Bean.java @@ -0,0 +1,64 @@ +package org.eclipse.mojarra.test.issue5460; + +import jakarta.enterprise.context.RequestScoped; +import jakarta.inject.Named; + +@Named +@RequestScoped +public class Issue5460Bean { + + private String cc1; + private String cc2; + private String cc3; + private String cc4; + private String cc5; + private String cc6; + + public String getCc1() { + return cc1; + } + + public void setCc1(String cc1) { + this.cc1 = cc1; + } + + public String getCc2() { + return cc2; + } + + public void setCc2(String cc2) { + this.cc2 = cc2; + } + + public String getCc3() { + return cc3; + } + + public void setCc3(String cc3) { + this.cc3 = cc3; + } + + public String getCc4() { + return cc4; + } + + public void setCc4(String cc4) { + this.cc4 = cc4; + } + + public String getCc5() { + return cc5; + } + + public void setCc5(String cc5) { + this.cc5 = cc5; + } + + public String getCc6() { + return cc6; + } + + public void setCc6(String cc6) { + this.cc6 = cc6; + } +} diff --git a/test/issue5460/src/main/java/org/eclipse/mojarra/test/issue5460/Issue5460Component.java b/test/issue5460/src/main/java/org/eclipse/mojarra/test/issue5460/Issue5460Component.java new file mode 100644 index 0000000000..b0f6e0c5ff --- /dev/null +++ b/test/issue5460/src/main/java/org/eclipse/mojarra/test/issue5460/Issue5460Component.java @@ -0,0 +1,27 @@ +package org.eclipse.mojarra.test.issue5460; + +import jakarta.faces.component.FacesComponent; +import jakarta.faces.component.NamingContainer; +import jakarta.faces.component.UIInput; +import jakarta.faces.component.UINamingContainer; +import jakarta.faces.context.FacesContext; + +@FacesComponent("issue5460Component") +public class Issue5460Component extends UIInput implements NamingContainer { + + @Override + public String getFamily() { + return UINamingContainer.COMPONENT_FAMILY; + } + + @Override + public void decode(FacesContext context) { + Object value = getValue(); + setSubmittedValue(value == null ? "" : value); + super.decode(context); + } + + public String getAttributeResults() { + return getAttributes().get("required") + " " + getAttributes().get("styleClass"); + } +} diff --git a/test/issue5460/src/main/webapp/WEB-INF/web.xml b/test/issue5460/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..9bebe39872 --- /dev/null +++ b/test/issue5460/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,17 @@ + + + + facesServlet + jakarta.faces.webapp.FacesServlet + 1 + + + facesServlet + *.xhtml + + \ No newline at end of file diff --git a/test/issue5460/src/main/webapp/issue5460.xhtml b/test/issue5460/src/main/webapp/issue5460.xhtml new file mode 100644 index 0000000000..e488cf69fb --- /dev/null +++ b/test/issue5460/src/main/webapp/issue5460.xhtml @@ -0,0 +1,38 @@ + + + + issue5460 + + + +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ + + +
+
+
+ diff --git a/test/issue5460/src/main/webapp/resources/components/component.xhtml b/test/issue5460/src/main/webapp/resources/components/component.xhtml new file mode 100644 index 0000000000..95c04f7fea --- /dev/null +++ b/test/issue5460/src/main/webapp/resources/components/component.xhtml @@ -0,0 +1,25 @@ + + + + + + + + + +
+ + + + + + +
+
+
diff --git a/test/issue5460/src/test/java/org/eclipse/mojarra/test/issue5460/Issue5460IT.java b/test/issue5460/src/test/java/org/eclipse/mojarra/test/issue5460/Issue5460IT.java new file mode 100644 index 0000000000..08c3c48e76 --- /dev/null +++ b/test/issue5460/src/test/java/org/eclipse/mojarra/test/issue5460/Issue5460IT.java @@ -0,0 +1,140 @@ +package org.eclipse.mojarra.test.issue5460; + +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.eclipse.mojarra.test.base.BaseIT; +import org.junit.jupiter.api.Test; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; + +class Issue5460IT extends BaseIT { + + @FindBy(id = "form:cc1:required") + private WebElement cc1required; + + @FindBy(id = "form:cc1:valid") + private WebElement cc1valid; + + @FindBy(id = "form:cc1:message") + private WebElement cc1message; + + @FindBy(id = "form:cc1:attributeResults") + private WebElement cc1attributeResults; + + @FindBy(id = "form:cc2:required") + private WebElement cc2required; + + @FindBy(id = "form:cc2:valid") + private WebElement cc2valid; + + @FindBy(id = "form:cc2:message") + private WebElement cc2message; + + @FindBy(id = "form:cc2:attributeResults") + private WebElement cc2attributeResults; + + @FindBy(id = "form:cc3:required") + private WebElement cc3required; + + @FindBy(id = "form:cc3:valid") + private WebElement cc3valid; + + @FindBy(id = "form:cc3:message") + private WebElement cc3message; + + @FindBy(id = "form:cc3:attributeResults") + private WebElement cc3attributeResults; + + @FindBy(id = "form:cc4:required") + private WebElement cc4required; + + @FindBy(id = "form:cc4:valid") + private WebElement cc4valid; + + @FindBy(id = "form:cc4:message") + private WebElement cc4message; + + @FindBy(id = "form:cc4:attributeResults") + private WebElement cc4attributeResults; + + @FindBy(id = "form:cc5:required") + private WebElement cc5required; + + @FindBy(id = "form:cc5:valid") + private WebElement cc5valid; + + @FindBy(id = "form:cc5:message") + private WebElement cc5message; + + @FindBy(id = "form:cc5:attributeResults") + private WebElement cc5attributeResults; + + @FindBy(id = "form:cc6:required") + private WebElement cc6required; + + @FindBy(id = "form:cc6:valid") + private WebElement cc6valid; + + @FindBy(id = "form:cc6:message") + private WebElement cc6message; + + @FindBy(id = "form:cc6:attributeResults") + private WebElement cc6attributeResults; + + @FindBy(id = "form:submit") + private WebElement submit; + + /** + * https://github.com/eclipse-ee4j/mojarra/issues/5460 + * https://github.com/eclipse-ee4j/mojarra/issues/5417 + */ + @Test + void test() { + open("issue5460.xhtml"); + + assertAll( + () -> assertEquals("false", cc1required.getText()), () -> assertEquals("true", cc1valid.getText()), + () -> assertEquals("false defaultClass", cc1attributeResults.getText()), + () -> assertEquals("", cc1message.getText()), () -> assertEquals("false", cc2required.getText()), + () -> assertEquals("true", cc2valid.getText()), + () -> assertEquals("false randomClass", cc2attributeResults.getText()), + () -> assertEquals("", cc2message.getText()), () -> assertEquals("true", cc3required.getText()), + () -> assertEquals("true", cc3valid.getText()), + () -> assertEquals("true defaultClass", cc3attributeResults.getText()), + () -> assertEquals("", cc3message.getText()), () -> assertEquals("true", cc4required.getText()), + () -> assertEquals("true", cc4valid.getText()), + () -> assertEquals("true randomClass", cc4attributeResults.getText()), + () -> assertEquals("", cc4message.getText()), () -> assertEquals("true", cc5required.getText()), + () -> assertEquals("true", cc5valid.getText()), + () -> assertEquals("true defaultClass", cc5attributeResults.getText()), + () -> assertEquals("", cc5message.getText()), () -> assertEquals("true", cc6required.getText()), + () -> assertEquals("true", cc6valid.getText()), + () -> assertEquals("true randomClass", cc6attributeResults.getText()), + () -> assertEquals("", cc6message.getText()) + ); + + guardAjax(submit::click); + + assertAll( + () -> assertEquals("false", cc1required.getText()), () -> assertEquals("true", cc1valid.getText()), + () -> assertEquals("false defaultClass", cc1attributeResults.getText()), + () -> assertEquals("", cc1message.getText()), () -> assertEquals("false", cc2required.getText()), + () -> assertEquals("true", cc2valid.getText()), + () -> assertEquals("false randomClass", cc2attributeResults.getText()), + () -> assertEquals("", cc2message.getText()), () -> assertEquals("true", cc3required.getText()), + () -> assertEquals("false", cc3valid.getText()), + () -> assertEquals("true defaultClass", cc3attributeResults.getText()), + () -> assertEquals("form:cc3: Validation Error: Value is required.", cc3message.getText()), + () -> assertEquals("true", cc4required.getText()), () -> assertEquals("false", cc4valid.getText()), + () -> assertEquals("true randomClass", cc4attributeResults.getText()), + () -> assertEquals("form:cc4: Validation Error: Value is required.", cc4message.getText()), + () -> assertEquals("true", cc5required.getText()), () -> assertEquals("false", cc5valid.getText()), + () -> assertEquals("true defaultClass", cc5attributeResults.getText()), + () -> assertEquals("form:cc5: Validation Error: Value is required.", cc5message.getText()), + () -> assertEquals("true", cc6required.getText()), () -> assertEquals("false", cc6valid.getText()), + () -> assertEquals("true randomClass", cc6attributeResults.getText()), + () -> assertEquals("form:cc6: Validation Error: Value is required.", cc6message.getText()) + ); + } +} From 570b0534e6ea5ede7c0d87e4ae86779fb1ee6469 Mon Sep 17 00:00:00 2001 From: Bauke Scholtz Date: Sat, 3 Aug 2024 13:23:39 -0400 Subject: [PATCH 3/8] Add integration test for #5464 --- .../java/com/sun/faces/util/HtmlUtils.java | 4 ++ test/issue5464/pom.xml | 41 ++++++++++++++++++ .../mojarra/test/issue5464/Issue5464Bean.java | 30 +++++++++++++ .../issue5464/src/main/webapp/WEB-INF/web.xml | 17 ++++++++ .../issue5464/src/main/webapp/issue5464.xhtml | 25 +++++++++++ .../mojarra/test/issue5464/Issue5464IT.java | 42 +++++++++++++++++++ 6 files changed, 159 insertions(+) create mode 100644 test/issue5464/pom.xml create mode 100644 test/issue5464/src/main/java/org/eclipse/mojarra/test/issue5464/Issue5464Bean.java create mode 100644 test/issue5464/src/main/webapp/WEB-INF/web.xml create mode 100644 test/issue5464/src/main/webapp/issue5464.xhtml create mode 100644 test/issue5464/src/test/java/org/eclipse/mojarra/test/issue5464/Issue5464IT.java diff --git a/impl/src/main/java/com/sun/faces/util/HtmlUtils.java b/impl/src/main/java/com/sun/faces/util/HtmlUtils.java index 8018751faf..3bec9047a3 100644 --- a/impl/src/main/java/com/sun/faces/util/HtmlUtils.java +++ b/impl/src/main/java/com/sun/faces/util/HtmlUtils.java @@ -128,6 +128,10 @@ private static int writeTextChar(Writer out, boolean escapeUnicode, boolean esca // UNICODE entities: encode as needed nextIndex = _writeDecRef(out, buff, buffIndex, buffLength, ch); } else { + if (forXml && !isAllowedXmlCharacter(ch)) { + return buffIndex; + } + nextIndex = addToBuffer(out, buff, buffIndex, buffLength, ch); } } diff --git a/test/issue5464/pom.xml b/test/issue5464/pom.xml new file mode 100644 index 0000000000..d9242a4135 --- /dev/null +++ b/test/issue5464/pom.xml @@ -0,0 +1,41 @@ + + + + 4.0.0 + + + org.eclipse.mojarra.test + pom + 4.0.8-SNAPSHOT + + + issue5464 + war + + Mojarra ${project.version} - INTEGRATION TESTS - ${project.artifactId} + + + + org.eclipse.mojarra.test + base + ${project.version} + test + + + diff --git a/test/issue5464/src/main/java/org/eclipse/mojarra/test/issue5464/Issue5464Bean.java b/test/issue5464/src/main/java/org/eclipse/mojarra/test/issue5464/Issue5464Bean.java new file mode 100644 index 0000000000..9dca6173c2 --- /dev/null +++ b/test/issue5464/src/main/java/org/eclipse/mojarra/test/issue5464/Issue5464Bean.java @@ -0,0 +1,30 @@ +package org.eclipse.mojarra.test.issue5464; + +import jakarta.enterprise.context.RequestScoped; +import jakarta.inject.Named; + +@Named +@RequestScoped +public class Issue5464Bean { + + private String input; + private String output; + + public void submit() { + + System.out.println("====> retrieved input " + input); + output = "Result: " + input; + } + + public String getInput() { + return input; + } + + public void setInput(String input) { + this.input = input; + } + + public String getOutput() { + return output; + } +} diff --git a/test/issue5464/src/main/webapp/WEB-INF/web.xml b/test/issue5464/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..9bebe39872 --- /dev/null +++ b/test/issue5464/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,17 @@ + + + + facesServlet + jakarta.faces.webapp.FacesServlet + 1 + + + facesServlet + *.xhtml + + \ No newline at end of file diff --git a/test/issue5464/src/main/webapp/issue5464.xhtml b/test/issue5464/src/main/webapp/issue5464.xhtml new file mode 100644 index 0000000000..eb3f133334 --- /dev/null +++ b/test/issue5464/src/main/webapp/issue5464.xhtml @@ -0,0 +1,25 @@ + + + + issue5464 + + + +
+ +
+
+ + + +
+
+ +
+
+
+ diff --git a/test/issue5464/src/test/java/org/eclipse/mojarra/test/issue5464/Issue5464IT.java b/test/issue5464/src/test/java/org/eclipse/mojarra/test/issue5464/Issue5464IT.java new file mode 100644 index 0000000000..626ef02d2b --- /dev/null +++ b/test/issue5464/src/test/java/org/eclipse/mojarra/test/issue5464/Issue5464IT.java @@ -0,0 +1,42 @@ +package org.eclipse.mojarra.test.issue5464; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.eclipse.mojarra.test.base.BaseIT; +import org.junit.jupiter.api.Test; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; + +class Issue5464IT extends BaseIT { + + @FindBy(id = "form:input") + private WebElement input; + + @FindBy(id = "form:submit") + private WebElement submit; + + @FindBy(id = "form:output") + private WebElement output; + + /** + * https://github.com/eclipse-ee4j/mojarra/issues/5464 + */ + @Test + void testFFFE() { + open("issue5464.xhtml"); + input.sendKeys("f\uFFFEoo"); + guardAjax(submit::click); + assertEquals("Result: foo", output.getText()); + } + + /** + * https://github.com/eclipse-ee4j/mojarra/issues/4516 + */ + @Test + void test000C() { + open("issue5464.xhtml"); + input.sendKeys("f\u000Coo"); + guardAjax(submit::click); + assertEquals("Result: foo", output.getText()); + } +} From b3b8c55183f495b77562b05241a6433186745f5a Mon Sep 17 00:00:00 2001 From: Bauke Scholtz Date: Sat, 3 Aug 2024 13:28:01 -0400 Subject: [PATCH 4/8] add missing copyright headers --- .../mojarra/test/issue5460/Issue5460Bean.java | 15 +++++++++++++++ .../test/issue5460/Issue5460Component.java | 15 +++++++++++++++ test/issue5460/src/main/webapp/WEB-INF/web.xml | 17 +++++++++++++++++ test/issue5460/src/main/webapp/issue5460.xhtml | 17 +++++++++++++++++ .../webapp/resources/components/component.xhtml | 17 +++++++++++++++++ .../mojarra/test/issue5460/Issue5460IT.java | 15 +++++++++++++++ .../mojarra/test/issue5464/Issue5464Bean.java | 15 +++++++++++++++ test/issue5464/src/main/webapp/WEB-INF/web.xml | 17 +++++++++++++++++ test/issue5464/src/main/webapp/issue5464.xhtml | 17 +++++++++++++++++ .../mojarra/test/issue5464/Issue5464IT.java | 15 +++++++++++++++ 10 files changed, 160 insertions(+) diff --git a/test/issue5460/src/main/java/org/eclipse/mojarra/test/issue5460/Issue5460Bean.java b/test/issue5460/src/main/java/org/eclipse/mojarra/test/issue5460/Issue5460Bean.java index 67b2ebd0e3..c06fc082fe 100644 --- a/test/issue5460/src/main/java/org/eclipse/mojarra/test/issue5460/Issue5460Bean.java +++ b/test/issue5460/src/main/java/org/eclipse/mojarra/test/issue5460/Issue5460Bean.java @@ -1,3 +1,18 @@ +/* + * Copyright (c) Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GPL-2.0 with Classpath-exception-2.0 which + * is available at https://openjdk.java.net/legal/gplv2+ce.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 or Apache-2.0 + */ package org.eclipse.mojarra.test.issue5460; import jakarta.enterprise.context.RequestScoped; diff --git a/test/issue5460/src/main/java/org/eclipse/mojarra/test/issue5460/Issue5460Component.java b/test/issue5460/src/main/java/org/eclipse/mojarra/test/issue5460/Issue5460Component.java index b0f6e0c5ff..e60626463e 100644 --- a/test/issue5460/src/main/java/org/eclipse/mojarra/test/issue5460/Issue5460Component.java +++ b/test/issue5460/src/main/java/org/eclipse/mojarra/test/issue5460/Issue5460Component.java @@ -1,3 +1,18 @@ +/* + * Copyright (c) Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GPL-2.0 with Classpath-exception-2.0 which + * is available at https://openjdk.java.net/legal/gplv2+ce.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 or Apache-2.0 + */ package org.eclipse.mojarra.test.issue5460; import jakarta.faces.component.FacesComponent; diff --git a/test/issue5460/src/main/webapp/WEB-INF/web.xml b/test/issue5460/src/main/webapp/WEB-INF/web.xml index 9bebe39872..8784690178 100644 --- a/test/issue5460/src/main/webapp/WEB-INF/web.xml +++ b/test/issue5460/src/main/webapp/WEB-INF/web.xml @@ -1,4 +1,21 @@ + + + + Date: Sun, 4 Aug 2024 09:08:22 -0400 Subject: [PATCH 5/8] Remove test sysout --- .../java/org/eclipse/mojarra/test/issue5464/Issue5464Bean.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/issue5464/src/main/java/org/eclipse/mojarra/test/issue5464/Issue5464Bean.java b/test/issue5464/src/main/java/org/eclipse/mojarra/test/issue5464/Issue5464Bean.java index b62fc04812..e112d31356 100644 --- a/test/issue5464/src/main/java/org/eclipse/mojarra/test/issue5464/Issue5464Bean.java +++ b/test/issue5464/src/main/java/org/eclipse/mojarra/test/issue5464/Issue5464Bean.java @@ -26,8 +26,6 @@ public class Issue5464Bean { private String output; public void submit() { - - System.out.println("====> retrieved input " + input); output = "Result: " + input; } From c5143e7c8eefcc4246291763c518c67aec43c608 Mon Sep 17 00:00:00 2001 From: Bauke Scholtz Date: Fri, 6 Sep 2024 07:07:12 -0400 Subject: [PATCH 6/8] Fix #5488: non-action ajax event shouldn't trigger action event; while at it also cleaned up existing code comments --- .../renderkit/html_basic/ButtonRenderer.java | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/impl/src/main/java/com/sun/faces/renderkit/html_basic/ButtonRenderer.java b/impl/src/main/java/com/sun/faces/renderkit/html_basic/ButtonRenderer.java index b2c2b4bf16..e851f26c04 100644 --- a/impl/src/main/java/com/sun/faces/renderkit/html_basic/ButtonRenderer.java +++ b/impl/src/main/java/com/sun/faces/renderkit/html_basic/ButtonRenderer.java @@ -171,29 +171,17 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce */ private static boolean wasClicked(FacesContext context, UIComponent component, String clientId) { - // Was our command the one that caused this submission? - // we don' have to worry about getting the value from request parameter - // because we just need to know if this command caused the submission. We - // can get the command name by calling currentValue. This way we can - // get around the IE bug. - if (clientId == null) { clientId = component.getClientId(context); } if (context.getPartialViewContext().isAjaxRequest()) { - return BEHAVIOR_SOURCE_PARAM.getValue(context).equals(clientId); + return RenderKitUtils.isPartialOrBehaviorAction(context, clientId); } else { Map requestParameterMap = context.getExternalContext().getRequestParameterMap(); if (requestParameterMap.get(clientId) == null) { - - // Check to see whether we've got an action event - // as a result of a partial/behavior postback. - if (RenderKitUtils.isPartialOrBehaviorAction(context, clientId)) { - return true; - } - + // Check to see whether we've got an action event from button of type="image" StringBuilder builder = new StringBuilder(clientId); String xValue = builder.append(".x").toString(); builder.setLength(clientId.length()); From f52249c70fff356fc1a870fdb9f857f5a901b140 Mon Sep 17 00:00:00 2001 From: Bauke Scholtz Date: Fri, 6 Sep 2024 07:37:04 -0400 Subject: [PATCH 7/8] Bump versions --- test/base/pom.xml | 2 +- test/issue5460/pom.xml | 2 +- test/issue5464/pom.xml | 2 +- test/pom.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/base/pom.xml b/test/base/pom.xml index e9bd597931..0b19f63add 100644 --- a/test/base/pom.xml +++ b/test/base/pom.xml @@ -22,7 +22,7 @@ org.eclipse.mojarra.test pom - 4.0.8-SNAPSHOT + 4.0.9-SNAPSHOT base diff --git a/test/issue5460/pom.xml b/test/issue5460/pom.xml index 3d69571563..50c4f35a6c 100644 --- a/test/issue5460/pom.xml +++ b/test/issue5460/pom.xml @@ -22,7 +22,7 @@ org.eclipse.mojarra.test pom - 4.0.8-SNAPSHOT + 4.0.9-SNAPSHOT issue5460 diff --git a/test/issue5464/pom.xml b/test/issue5464/pom.xml index d9242a4135..086548c0f5 100644 --- a/test/issue5464/pom.xml +++ b/test/issue5464/pom.xml @@ -22,7 +22,7 @@ org.eclipse.mojarra.test pom - 4.0.8-SNAPSHOT + 4.0.9-SNAPSHOT issue5464 diff --git a/test/pom.xml b/test/pom.xml index ef33d64866..ba45ae039e 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -22,7 +22,7 @@ org.glassfish mojarra-parent - 4.0.8-SNAPSHOT + 4.0.9-SNAPSHOT org.eclipse.mojarra.test From 25b9aedb566c3a81c0f47adbecd66fe0df790b66 Mon Sep 17 00:00:00 2001 From: Bauke Scholtz Date: Fri, 6 Sep 2024 07:37:55 -0400 Subject: [PATCH 8/8] Add IT for #5488 --- test/issue5488/pom.xml | 41 ++++++ .../mojarra/test/issue5488/Issue5488Bean.java | 41 ++++++ .../issue5488/src/main/webapp/WEB-INF/web.xml | 34 +++++ .../issue5488/src/main/webapp/issue5488.xhtml | 54 ++++++++ .../mojarra/test/issue5488/Issue5488IT.java | 118 ++++++++++++++++++ test/pom.xml | 1 + 6 files changed, 289 insertions(+) create mode 100644 test/issue5488/pom.xml create mode 100644 test/issue5488/src/main/java/org/eclipse/mojarra/test/issue5488/Issue5488Bean.java create mode 100644 test/issue5488/src/main/webapp/WEB-INF/web.xml create mode 100644 test/issue5488/src/main/webapp/issue5488.xhtml create mode 100644 test/issue5488/src/test/java/org/eclipse/mojarra/test/issue5488/Issue5488IT.java diff --git a/test/issue5488/pom.xml b/test/issue5488/pom.xml new file mode 100644 index 0000000000..8709a85197 --- /dev/null +++ b/test/issue5488/pom.xml @@ -0,0 +1,41 @@ + + + + 4.0.0 + + + org.eclipse.mojarra.test + pom + 4.0.9-SNAPSHOT + + + issue5488 + war + + Mojarra ${project.version} - INTEGRATION TESTS - ${project.artifactId} + + + + org.eclipse.mojarra.test + base + ${project.version} + test + + + diff --git a/test/issue5488/src/main/java/org/eclipse/mojarra/test/issue5488/Issue5488Bean.java b/test/issue5488/src/main/java/org/eclipse/mojarra/test/issue5488/Issue5488Bean.java new file mode 100644 index 0000000000..d81d9dd42e --- /dev/null +++ b/test/issue5488/src/main/java/org/eclipse/mojarra/test/issue5488/Issue5488Bean.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GPL-2.0 with Classpath-exception-2.0 which + * is available at https://openjdk.java.net/legal/gplv2+ce.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 or Apache-2.0 + */ +package org.eclipse.mojarra.test.issue5488; + +import static jakarta.faces.component.UIComponent.getCurrentComponent; + +import jakarta.enterprise.context.RequestScoped; +import jakarta.faces.application.FacesMessage; +import jakarta.faces.context.FacesContext; +import jakarta.inject.Named; + +@Named +@RequestScoped +public class Issue5488Bean { + + public void listener() { + addInvokedMessage("listener"); + } + + public void action() { + addInvokedMessage("action"); + } + + private static void addInvokedMessage(String methodName) { + FacesContext context = FacesContext.getCurrentInstance(); + context.addMessage(null, new FacesMessage(methodName + " invoked on " + getCurrentComponent(context).getClientId(context))); + } +} diff --git a/test/issue5488/src/main/webapp/WEB-INF/web.xml b/test/issue5488/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..8784690178 --- /dev/null +++ b/test/issue5488/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,34 @@ + + + + + facesServlet + jakarta.faces.webapp.FacesServlet + 1 + + + facesServlet + *.xhtml + + \ No newline at end of file diff --git a/test/issue5488/src/main/webapp/issue5488.xhtml b/test/issue5488/src/main/webapp/issue5488.xhtml new file mode 100644 index 0000000000..1b33c3c1a4 --- /dev/null +++ b/test/issue5488/src/main/webapp/issue5488.xhtml @@ -0,0 +1,54 @@ + + + + + issue5488 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/issue5488/src/test/java/org/eclipse/mojarra/test/issue5488/Issue5488IT.java b/test/issue5488/src/test/java/org/eclipse/mojarra/test/issue5488/Issue5488IT.java new file mode 100644 index 0000000000..5706e5e0cf --- /dev/null +++ b/test/issue5488/src/test/java/org/eclipse/mojarra/test/issue5488/Issue5488IT.java @@ -0,0 +1,118 @@ +/* + * Copyright (c) Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GPL-2.0 with Classpath-exception-2.0 which + * is available at https://openjdk.java.net/legal/gplv2+ce.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 or Apache-2.0 + */ +package org.eclipse.mojarra.test.issue5488; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.eclipse.mojarra.test.base.BaseIT; +import org.junit.jupiter.api.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; + +class Issue5488IT extends BaseIT { + + @FindBy(id = "form1:input") + private WebElement form1input; + + @FindBy(id = "form1:button") + private WebElement form1button; + + @FindBy(id = "form1:messages") + private WebElement form1messages; + + @FindBy(id = "form2:input") + private WebElement form2input; + + @FindBy(id = "form2:link") + private WebElement form2link; + + @FindBy(id = "form2:messages") + private WebElement form2messages; + + @FindBy(id = "form3:button1") + private WebElement form3button1; + + @FindBy(id = "form3:button2") + private WebElement form3button2; + + @FindBy(id = "form3:messages") + private WebElement form3messages; + + /** + * https://github.com/eclipse-ee4j/mojarra/issues/5488 + */ + @Test + void testCommandButtonBlurred() { + open("issue5488.xhtml"); + form1input.sendKeys(Keys.TAB); + guardAjax(() -> form1button.sendKeys(Keys.TAB)); + + var messages = form1messages.getText(); + assertEquals("listener invoked on form1:button", messages); // and thus not action invoked as well + } + + /** + * https://github.com/eclipse-ee4j/mojarra/issues/5488 + */ + @Test + void testCommandButtonClicked() { + open("issue5488.xhtml"); + guardAjax(form1button::click); + assertEquals("action invoked on form1:button", form1messages.getText()); // and thus not listener invoked as well + } + + /** + * https://github.com/eclipse-ee4j/mojarra/issues/5488 + */ + @Test + void testCommandLinkBlurred() { + open("issue5488.xhtml"); + form2input.sendKeys(Keys.TAB); + guardAjax(() -> form2link.sendKeys(Keys.TAB)); + assertEquals("listener invoked on form2:link", form2messages.getText()); // and thus not action invoked as well + } + + /** + * https://github.com/eclipse-ee4j/mojarra/issues/5488 + */ + @Test + void testCommandLinkClicked() { + open("issue5488.xhtml"); + guardAjax(form2link::click); + assertEquals("action invoked on form2:link", form2messages.getText()); // and thus not listener invoked as well + } + + /** + * https://github.com/eclipse-ee4j/mojarra/issues/3355 + */ + @Test + void testPlainButton1() { + open("issue5488.xhtml"); + guardAjax(form3button1::click); + assertEquals("listener invoked on form3:button1", form3messages.getText()); // and thus not on form3:button2 as well + } + + /** + * https://github.com/eclipse-ee4j/mojarra/issues/3355 + */ + @Test + void testPlainButton2() { + open("issue5488.xhtml"); + guardAjax(form3button2::click); + assertEquals("listener invoked on form3:button2", form3messages.getText()); // and thus not on form3:button1 as well + } +} diff --git a/test/pom.xml b/test/pom.xml index ba45ae039e..5c4dc262c4 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -35,6 +35,7 @@ base issue5460 issue5464 + issue5488