com.mockrunner.example.struts.AuthenticationForm Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockrunner-jdk1.3-j2ee1.3 Show documentation
Show all versions of mockrunner-jdk1.3-j2ee1.3 Show documentation
Mockrunner is a lightweight framework for unit testing applications
in the J2EE environment. It supports servlets, filters, tag classes
and Struts actions. It includes a JDBC a JMS and a JCA test
framework and can be used to test EJB based applications.
The newest version!
package com.mockrunner.example.struts;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
/**
* The ActionForm
for the {@link AuthenticationAction}.
* The {@link #validate} method will check if an username and a password
* is present and generates the approriate ActionErrors
.
* See {@link AuthenticationActionTest}.
*/
public class AuthenticationForm extends ActionForm
{
private String username;
private String password;
public String getPassword()
{
return password;
}
public String getUsername()
{
return username;
}
public void setPassword(String password)
{
this.password = password;
}
public void setUsername(String username)
{
this.username = username;
}
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
{
ActionErrors errors = new ActionErrors();
if (null == username || 0 == username.length())
{
addMissingValueError(errors, "username");
}
if (null == password || 0 == password.length())
{
addMissingValueError(errors, "password");
}
return errors;
}
private void addMissingValueError(ActionErrors errors, String field)
{
ActionMessage error = new ActionMessage("field.value.missing", field);
errors.add(ActionMessages.GLOBAL_MESSAGE, error);
}
}