Skip to content

Commit

Permalink
4433 fix servlet30 tests round 1 (#4434)
Browse files Browse the repository at this point in the history
First batch of fixes

Signed-off-by: arjantijms <arjan.tijms@gmail.com>
  • Loading branch information
arjantijms authored Aug 1, 2018
1 parent fd3f3d5 commit 75f1708
Show file tree
Hide file tree
Showing 380 changed files with 4,253 additions and 7,623 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

package com.sun.faces.test.servlet30.ajax;

import javax.enterprise.context.RequestScoped;
import javax.inject.Named;

@Named
@RequestScoped
public class AjaxScriptErrorBean {

private Boolean renderedScript;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@
import java.util.ArrayList;
import java.util.List;

import javax.enterprise.context.RequestScoped;
import javax.inject.Named;

@Named
@RequestScoped
public class Issue2636Bean {

private String actionText;

public List<String> getValues() {
List<String> values = new ArrayList<String>();
values.add("test");
Expand All @@ -38,7 +42,7 @@ public void linkAction2() {
actionText = "linkAction2";
}

private String actionText = null;


public String getActionText() {
return actionText;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

@Named
@Named("ajaxselect")
@SessionScoped
public class SelectBean implements Serializable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.PrintWriter;
import java.io.Writer;
import java.lang.reflect.Constructor;

import javax.faces.context.PartialResponseWriter;
import javax.faces.context.ResponseWriter;
import javax.servlet.Filter;
Expand All @@ -31,28 +32,21 @@
import javax.servlet.http.HttpServletResponse;

public class BeforeFilter implements Filter {

private FilterConfig filterConfig = null;

public BeforeFilter() {
}


@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException {


public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

try {
HttpServletResponse resp = (HttpServletResponse) response;
PrintWriter pw = resp.getWriter();

ResponseWriter responseWriter;
Class htmlResponseWriterClass = Class.forName("com.sun.faces.renderkit.html_basic.HtmlResponseWriter");
Constructor ctor = htmlResponseWriterClass.getConstructor(Writer.class, String.class, String.class);

responseWriter = (ResponseWriter) ctor.newInstance(pw, "text/xml", "UTF-8");

PartialResponseWriter partialResponseWriter = new PartialResponseWriter(responseWriter);
// partialResponseWriter.writePreamble("<?xml version='1.0' encoding='UTF-8'?>\n");
partialResponseWriter.startDocument();
partialResponseWriter.startUpdate("foo");
partialResponseWriter.endUpdate();
Expand All @@ -74,24 +68,25 @@ public void doFilter(ServletRequest request, ServletResponse response,
indent = indentBuilder.toString();
pw.print("<p>" + indent + " Exception: " + cause.getClass().getName() + "</p>");
pw.print("<p>" + indent + " Exception Message: " + cause.getLocalizedMessage() + "</p>");
pw.print("<code><pre>");
cause.printStackTrace(pw);
pw.print("</pre></code>");
pw.print("<code><pre>");
cause.printStackTrace(pw);
pw.print("</pre></code>");
} while (null != (cause = cause.getCause()));
pw.print("</body></html>");
resp.setStatus(200);
pw.close();
} catch (Exception e) {
}
}

}

public void destroy() {
@Override
public void destroy() {
}

public void init(FilterConfig filterConfig) {
this.filterConfig = filterConfig;
@Override
public void init(FilterConfig filterConfig) {
}

}
3 changes: 3 additions & 0 deletions test/servlet30/ajax/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/behavior-taglib.xml;/WEB-INF/taglib.xml</param-value>
</context-param>

<filter>
<filter-name>BeforeFilter</filter-name>
<filter-class>com.sun.faces.test.servlet30.ajax.filter.BeforeFilter</filter-class>
Expand All @@ -46,6 +47,7 @@
<filter-name>BeforeFilter</filter-name>
<url-pattern>/BeforeFilter</url-pattern>
</filter-mapping>

<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
Expand All @@ -55,6 +57,7 @@
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>

<session-config>
<session-timeout>30</session-timeout>
</session-config>
Expand Down
14 changes: 9 additions & 5 deletions test/servlet30/ajax/src/main/webapp/ajaxScriptError.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,24 @@

<h:body>
<p><span id="exceptionDuringRender"/>&nbsp;</p>

<script type="text/javascript">
var handleError = function handleError(data) {
var errorMessageString = "Error from " + data.source.id;
var span = document.getElementById("exceptionDuringRender");
span.innerHTML = errorMessageString;
};
var handleError =
function handleError(data) {
var errorMessageString = "Error from " + data.source.id;
var span = document.getElementById("exceptionDuringRender");
span.innerHTML = errorMessageString;
};

jsf.ajax.addOnError(handleError);
</script>

<h:form id="form">
<h:commandButton id="commandButton" value="throw on render in script">
<f:ajax listener="#{ajaxScriptErrorBean.setRenderedScript(true)}" render="script"/>
</h:commandButton>
</h:form>

<h:panelGroup id="script">
<ui:fragment rendered="#{ajaxScriptErrorBean.renderedScript}">
<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,25 @@

package com.sun.faces.test.servlet30.ajax;

import static org.junit.Assert.assertTrue;

import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import java.util.List;

import org.junit.*;
import static org.junit.Assert.*;

public class Issue2636IT {

/**
* Stores the web URL.
*/
private String webUrl;

/**
* Stores the web client.
*/
Expand All @@ -52,23 +57,26 @@ public void tearDown() {
public void testCommandLinksInRepeat() throws Exception {
HtmlPage page = webClient.getPage(webUrl + "faces/issue2636.xhtml");
webClient.waitForBackgroundJavaScript(60000);
List anchors = page.getAnchors();
List<HtmlAnchor> anchors = page.getAnchors();

HtmlAnchor anchor1 = (HtmlAnchor) anchors.get(0);
HtmlAnchor anchor1 = anchors.get(0);
page = anchor1.click();
webClient.waitForBackgroundJavaScript(60000);

System.out.println(page.asXml());

assertTrue(page.asXml().contains("linkAction1"));

anchors = page.getAnchors();

HtmlAnchor anchor2 = (HtmlAnchor) anchors.get(1);
HtmlAnchor anchor2 = anchors.get(1);
page = anchor2.click();
webClient.waitForBackgroundJavaScript(60000);
assertTrue(page.asXml().contains("linkAction2"));

anchors = page.getAnchors();

anchor1 = (HtmlAnchor) anchors.get(0);
anchor1 = anchors.get(0);
page = anchor1.click();
webClient.waitForBackgroundJavaScript(60000);
assertTrue(page.asXml().contains("linkAction1"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@

package com.sun.faces.test.servlet30.ajax;

import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import static org.junit.Assert.assertTrue;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;

import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

public class Issue3473IT {

Expand All @@ -47,8 +49,10 @@ public void testButtonOnlySubmitsOne() throws Exception {
HtmlPage page = webClient.getPage(webUrl + "faces/ajaxScriptError.xhtml");
HtmlElement button = page.getHtmlElementById("form:commandButton");
webClient.waitForBackgroundJavaScript(60000);

page = button.click();
webClient.waitForBackgroundJavaScript(60000);

assertTrue(page.asXml().contains("Error from form:commandButton"));
}
}
12 changes: 5 additions & 7 deletions test/servlet30/ajaxNamespace/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,20 @@
-->

<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>
<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>com.sun.faces.test.servlet30</groupId>
<artifactId>pom</artifactId>
<version>3.0.0-m01-SNAPSHOT</version>
</parent>

<artifactId>ajaxNamespace</artifactId>
<packaging>war</packaging>
<name>Mojarra ${project.version} - Test - Servlet 3.0 - Ajax Namespace</name>

<build>
<finalName>test-servlet30-ajaxNamespace</finalName>
</build>
<properties>
<netbeans.hint.deploy.server>gfv3ee6</netbeans.hint.deploy.server>
</properties>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,27 @@
import java.util.Date;
import java.util.Map;

import javax.enterprise.context.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.validator.ValidatorException;
import javax.inject.Named;

@ManagedBean
@Named
@SessionScoped
public class AjaxNamespaceBean implements Serializable {


private static final long serialVersionUID = 1L;

protected String firstName = "Duke";
protected String lastName = "Java";
protected Date dob;
protected String sex = "Unknown";
protected String email;
protected String serviceLevel = "medium";

public AjaxNamespaceBean() {}


public String getFirstName() {
return firstName;
Expand Down Expand Up @@ -88,33 +89,27 @@ public String getServiceLevel() {
public void setServiceLevel(String serviceLevel) {
this.serviceLevel = serviceLevel;
}

public void validateEmail(FacesContext context, UIComponent toValidate,
Object value) throws ValidatorException {

public void validateEmail(FacesContext context, UIComponent toValidate, Object value) throws ValidatorException {
String emailStr = (String) value;
if (-1 == emailStr.indexOf("@")) {
FacesMessage message = new FacesMessage("Invalid email address");
throw new ValidatorException(message);
if (emailStr.indexOf("@") == -1) {
throw new ValidatorException(new FacesMessage("Invalid email address"));
}
}

public String addConfirmedUser() {
// This method would call a database or other service and add the
// confirmed user information.
// This method would call a database or other service and add the confirmed user information.
// For now, we just place an informative message in request scope
FacesMessage doneMessage =
new FacesMessage("Successfully added new user");
FacesContext.getCurrentInstance().addMessage(null, doneMessage);
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Successfully added new user"));
return "done";
}

public void paramActionListener (ActionEvent actionEvent) {
Map<String, String> params =
FacesContext.getCurrentInstance().getExternalContext().
getRequestParameterMap();
public void paramActionListener(ActionEvent actionEvent) {
Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();

String paramValue = params.get("param");
if (paramValue != null) {
this.lastName = this.lastName + " " + params.get("param");
lastName = lastName + " " + params.get("param");
}
}
}
Loading

0 comments on commit 75f1708

Please sign in to comment.