Skip to content

Commit

Permalink
Add IT for #5488
Browse files Browse the repository at this point in the history
  • Loading branch information
BalusC committed Sep 6, 2024
1 parent f52249c commit 25b9aed
Show file tree
Hide file tree
Showing 6 changed files with 289 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/issue5488/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) Contributors to 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
http://www.eclipse.org/legal/epl-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: GNU General Public License,
version 2 with the GNU Classpath Exception, which is available at
https://www.gnu.org/software/classpath/license.html.
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.eclipse.mojarra.test</groupId>
<artifactId>pom</artifactId>
<version>4.0.9-SNAPSHOT</version>
</parent>

<artifactId>issue5488</artifactId>
<packaging>war</packaging>

<name>Mojarra ${project.version} - INTEGRATION TESTS - ${project.artifactId}</name>

<dependencies>
<dependency>
<groupId>org.eclipse.mojarra.test</groupId>
<artifactId>base</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -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)));
}
}
34 changes: 34 additions & 0 deletions test/issue5488/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) Contributors to 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
http://www.eclipse.org/legal/epl-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: GNU General Public License,
version 2 with the GNU Classpath Exception, which is available at
https://www.gnu.org/software/classpath/license.html.
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
-->
<web-app
xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"
version="5.0"
>
<servlet>
<servlet-name>facesServlet</servlet-name>
<servlet-class>jakarta.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>facesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>
54 changes: 54 additions & 0 deletions test/issue5488/src/main/webapp/issue5488.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<!--
Copyright (c) Contributors to 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
http://www.eclipse.org/legal/epl-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: GNU General Public License,
version 2 with the GNU Classpath Exception, which is available at
https://www.gnu.org/software/classpath/license.html.
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
-->
<html lang="en"
xmlns:h="jakarta.faces.html"
xmlns:f="jakarta.faces.core"
xmlns:ui="jakarta.faces.facelets"
>
<h:head>
<title>issue5488</title>
</h:head>
<h:body>
<h:form id="form1"> <!-- This basically verifies that the specified issue is fixed in h:commandButton for good. -->
<h:inputText id="input" />
<h:commandButton id="button" value="submit" action="#{issue5488Bean.action}">
<f:ajax event="blur" listener="#{issue5488Bean.listener}" render="messages" />
<f:ajax execute="@form" render="messages"/>
</h:commandButton>
<h:messages id="messages" />
</h:form>
<h:form id="form2"> <!-- This basically reconfirms that the specified issue doesn't and won't ever happen in h:commandLink. -->
<h:inputText id="input" />
<h:commandLink id="link" value="submit" action="#{issue5488Bean.action}">
<f:ajax event="blur" listener="#{issue5488Bean.listener}" render="messages" />
<f:ajax execute="@form" render="messages"/>
</h:commandLink>
<h:messages id="messages" />
</h:form>
<h:form id="form3"> <!-- This basically reassess that issue3355 (issue3351IT) remains fixed as it caused the regression in h:commandButton. -->
<h:commandButton id="button1" type="button" value="button1" actionListener="#{issue5488Bean.listener}">
<f:ajax execute="@form" render="messages"/>
</h:commandButton>
<h:commandButton id="button2" type="button" value="button2" actionListener="#{issue5488Bean.listener}">
<f:ajax execute="@form" render="messages"/>
</h:commandButton>
<h:messages id="messages" />
</h:form>
</h:body>
</html>
Original file line number Diff line number Diff line change
@@ -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
}
}
1 change: 1 addition & 0 deletions test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<module>base</module>
<module>issue5460</module>
<module>issue5464</module>
<module>issue5488</module>
</modules>

<properties>
Expand Down

0 comments on commit 25b9aed

Please sign in to comment.