Skip to content

Commit

Permalink
Merge pull request #1726 from jakartaee/faces_issue_1702
Browse files Browse the repository at this point in the history
Fix test assertions should not reference mojarra.ab
  • Loading branch information
arjantijms authored Nov 15, 2022
2 parents 1508939 + 5808c7f commit 916ec0b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.junit.Test;

import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;

import ee.jakarta.tck.faces.test.util.arquillian.ITBase;
import jakarta.faces.component.behavior.AjaxBehavior;
Expand All @@ -32,18 +33,15 @@ public class Issue2439IT extends ITBase {
* @see https://github.com/eclipse-ee4j/mojarra/issues/2443
*/
@Test
public void testUpdateAttributeNamedValue() throws Exception {
String expectedString1 = "<input id="+'"'+"form1:input1"+'"'+" type="+'"'+"text"+'"'+" name="+'"'+"form1:input1"+'"'+"/>";

String expectedString2 = "<input id="+'"'+"form1:input2"+'"'+" type="+'"'+"text"+'"'+" name="+'"'+"form1:input2"+'"'+" onchange="+'"'+"faces.util.chain(this,event,'mojarra.ab(this,event,"+"\\"+"'valueChange\\"+"'"+",\\'@this\\',\\'@all\\')')"+'"'+"/>";

String expectedString3 = "<input id="+'"'+"form1:input3"+'"'+" type="+'"'+"text"+'"'+" name="+'"'+"form1:input3"
+'"'+" onchange="+'"'+"faces.util.chain(this,event,'alert(\\'Hello, World!\\');')"+'"'+"/>";

public void testDisabledBehaviors() throws Exception {
HtmlPage page = getPage("disabledBehaviors.xhtml");
assertTrue(page.asXml().contains(expectedString1));
assertTrue(page.asXml().contains(expectedString2));
assertTrue(page.asXml().contains(expectedString3));

HtmlTextInput input1 = (HtmlTextInput) page.getElementById("form1:input1");
HtmlTextInput input2 = (HtmlTextInput) page.getElementById("form1:input2");
HtmlTextInput input3 = (HtmlTextInput) page.getElementById("form1:input3");
assertTrue("input1 has no onchange attribute", input1.getAttribute("onchange").isEmpty());
assertTrue("input2 has onchange attribute", !input2.getAttribute("onchange").isEmpty());
assertTrue("input3 has onchange attribute", !input3.getAttribute("onchange").isEmpty());
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.junit.Test;

import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;

import ee.jakarta.tck.faces.test.util.arquillian.ITBase;
import jakarta.faces.component.behavior.AjaxBehavior;
Expand All @@ -33,9 +34,9 @@ public class Issue2674IT extends ITBase {
*/
@Test
public void testProgrammaticAjaxBehavior() throws Exception {
String expectedString = "<input id="+'"'+"form:input1"+'"'+" type="+'"'+"text"+'"'+" name="+'"'+"form:input1"+'"'+" value="+'"'+"hi"+'"'+" onfocus="+'"'+"mojarra.ab(this,event,'focus',0,0)"+'"';
HtmlPage page = getPage("issue2674.xhtml");
assertTrue(page.asXml().contains(expectedString));
HtmlTextInput input1 = (HtmlTextInput) page.getElementById("form:input1");
assertTrue("input1 has programmatically added onfocus attribute", !input1.getAttribute("onfocus").isEmpty());
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ public void testImplicitThis() throws Exception {
HtmlPage page = webClient.getPage(webUrl + "issue5032IT.xhtml");

HtmlTextInput form1input2 = (HtmlTextInput) page.getElementById("form1:inputs:input2");
assertEquals("f:ajax execute of form1:input2 is implied as @this", "mojarra.ab(this,event,'valueChange',0,'@form')", form1input2.getOnChangeAttribute());

form1input2.setValueAttribute("1");
form1input2.fireEvent("change");
webClient.waitForBackgroundJavaScript(3000);
Expand All @@ -93,8 +91,6 @@ public void testExplicitThis() throws Exception {
HtmlPage page = webClient.getPage(webUrl + "issue5032IT.xhtml");

HtmlTextInput form2input2 = (HtmlTextInput) page.getElementById("form2:inputs:input2");
assertEquals("f:ajax execute of form2:input2 is still @this", "mojarra.ab(this,event,'valueChange','@this','@form')", form2input2.getOnChangeAttribute());

form2input2.setValueAttribute("1");
form2input2.fireEvent("change");
webClient.waitForBackgroundJavaScript(3000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ public void tearDown() {
public void test() throws Exception {
HtmlPage page = webClient.getPage(webUrl + "spec1567IT.xhtml");

validateRenderedMarkup(page, "form1", "form1:messages");
validateRenderedMarkup(page, "form2", "form2:messages");
validateRenderedMarkup(page, "form3", "form3:inputs form3:messages");

// fill form1 input1
HtmlTextInput input1 = (HtmlTextInput) page.getElementById("form1:inputs:input1");
input1.setValueAttribute("1");
Expand Down Expand Up @@ -204,15 +200,4 @@ public void test() throws Exception {
assertEquals("input3 is filled", "setForm3input3:1", messages);
}

private void validateRenderedMarkup(HtmlPage page, String formId, String render) {
HtmlTextInput input1 = (HtmlTextInput) page.getElementById(formId + ":inputs:input1");
assertEquals("input1 and input2 are implied as @this", "mojarra.ab(this,event,'change','" + formId + ":inputs:input1 " + formId + ":inputs:input2','" + render + "')", input1.getOnChangeAttribute());

HtmlTextInput input2 = (HtmlTextInput) page.getElementById(formId + ":inputs:input2");
assertEquals("input1 and input2 are implied as @this", "mojarra.ab(this,event,'change','" + formId + ":inputs:input1 " + formId + ":inputs:input2','" + render + "')", input2.getOnChangeAttribute());

HtmlTextInput input3 = (HtmlTextInput) page.getElementById(formId + ":inputs:input3");
assertEquals("input3 has still its own f:ajax", "mojarra.ab(this,event,'valueChange',0,'@form')", input3.getOnChangeAttribute());
}

}

0 comments on commit 916ec0b

Please sign in to comment.