You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2010/08/28 20:59:24 UTC
svn commit: r990408 [4/10] - in /myfaces/test/trunk:
test12/src/main/java/org/apache/myfaces/test/base/
test12/src/main/java/org/apache/myfaces/test/base/junit4/
test12/src/main/java/org/apache/myfaces/test/cargo/
test12/src/main/java/org/apache/myface...
Modified: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockFacesContext12.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockFacesContext12.java?rev=990408&r1=990407&r2=990408&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockFacesContext12.java (original)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockFacesContext12.java Sat Aug 28 18:59:21 2010
@@ -34,66 +34,67 @@ import org.apache.myfaces.test.el.MockEL
*
* @since 1.0.0
*/
-public class MockFacesContext12 extends MockFacesContext {
-
+public class MockFacesContext12 extends MockFacesContext
+{
// ------------------------------------------------------------ Constructors
-
- public MockFacesContext12() {
+ public MockFacesContext12()
+ {
super();
setCurrentInstance(this);
}
-
- public MockFacesContext12(ExternalContext externalContext) {
+ public MockFacesContext12(ExternalContext externalContext)
+ {
super(externalContext);
}
-
- public MockFacesContext12(ExternalContext externalContext, Lifecycle lifecycle) {
+ public MockFacesContext12(ExternalContext externalContext,
+ Lifecycle lifecycle)
+ {
super(externalContext, lifecycle);
}
-
// ----------------------------------------------------- Mock Object Methods
-
/**
* <p>Set the <code>ELContext</code> instance for this instance.</p>
*
* @param elContext The new ELContext
*/
- public void setELContext(ELContext elContext) {
+ public void setELContext(ELContext elContext)
+ {
this.elContext = elContext;
}
-
// ------------------------------------------------------ Instance Variables
-
private ELContext elContext = null;
-
// ---------------------------------------------------- FacesContext Methods
-
/** {@inheritDoc} */
- public ELContext getELContext() {
+ public ELContext getELContext()
+ {
- if (this.elContext == null) {
+ if (this.elContext == null)
+ {
// Initialize a new ELContext
this.elContext = new MockELContext();
this.elContext.putContext(FacesContext.class, this);
// Notify interested listeners that this ELContext was created
- ELContextListener[] listeners = getApplication().getELContextListeners();
- if ((listeners != null) && (listeners.length > 0)) {
+ ELContextListener[] listeners = getApplication()
+ .getELContextListeners();
+ if ((listeners != null) && (listeners.length > 0))
+ {
ELContextEvent event = new ELContextEvent(this.elContext);
- for (int i = 0; i < listeners.length; i++) {
+ for (int i = 0; i < listeners.length; i++)
+ {
listeners[i].contextCreated(event);
}
}
@@ -103,12 +104,11 @@ public class MockFacesContext12 extends
}
-
/** {@inheritDoc} */
- public void release() {
+ public void release()
+ {
super.release();
this.elContext = null;
}
-
}
Modified: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockFacesContextFactory.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockFacesContextFactory.java?rev=990408&r1=990407&r2=990408&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockFacesContextFactory.java (original)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockFacesContextFactory.java Sat Aug 28 18:59:21 2010
@@ -33,143 +33,171 @@ import javax.servlet.http.HttpServletRes
* $Id$
* @since 1.0.0
*/
-public class MockFacesContextFactory extends FacesContextFactory {
-
+public class MockFacesContextFactory extends FacesContextFactory
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Look up the constructor we will use for creating <code>MockFacesContext</code>
* instances.</p>
*/
- public MockFacesContextFactory() {
+ public MockFacesContextFactory()
+ {
Class clazz = null;
// Try to load the 1.2 version of our mock FacesContext class
- try {
- clazz = this.getClass().getClassLoader().loadClass("org.apache.myfaces.test.mock.MockFacesContext12");
+ try
+ {
+ clazz = this.getClass().getClassLoader().loadClass(
+ "org.apache.myfaces.test.mock.MockFacesContext12");
constructor = clazz.getConstructor(facesContextSignature);
jsf12 = true;
- } catch (NoClassDefFoundError e) {
+ }
+ catch (NoClassDefFoundError e)
+ {
// We are not running on JSF 1.2, so go to our fallback
clazz = null;
constructor = null;
- } catch (ClassNotFoundException e) {
+ }
+ catch (ClassNotFoundException e)
+ {
// Same as above
clazz = null;
constructor = null;
- } catch (RuntimeException e) {
+ }
+ catch (RuntimeException e)
+ {
throw e;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
// Fall back to the 1.1 version if we could not load the 1.2 version
- try {
- if (clazz == null) {
- clazz = this.getClass().getClassLoader().loadClass("org.apache.myfaces.test.mock.MockFacesContext");
+ try
+ {
+ if (clazz == null)
+ {
+ clazz = this.getClass().getClassLoader().loadClass(
+ "org.apache.myfaces.test.mock.MockFacesContext");
constructor = clazz.getConstructor(facesContextSignature);
jsf12 = false;
}
- } catch (RuntimeException e) {
+ }
+ catch (RuntimeException e)
+ {
throw e;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
}
-
// ----------------------------------------------------- Mock Object Methods
-
// ------------------------------------------------------ Instance Variables
-
/**
* <p>The constructor for creating a <code>FacesContext</code> instance,
* taking an <code>ExternalContext</code> and <code>Lifecycle</code>.</p>
*/
private Constructor constructor = null;
-
/**
* <p>The parameter signature of the ExternalContext constructor we wish to call.</p>
*/
private static Class[] externalContextSignature = new Class[] {
- ServletContext.class, HttpServletRequest.class, HttpServletResponse.class
- };
-
+ ServletContext.class, HttpServletRequest.class,
+ HttpServletResponse.class };
/**
* <p>The parameter signature of the FacesContext constructor we wish to call.</p>
*/
private static Class[] facesContextSignature = new Class[] {
- ExternalContext.class, Lifecycle.class
- };
-
+ ExternalContext.class, Lifecycle.class };
/**
* <p>Flag indicating that we are running in a JSF 1.2 environment.</p>
*/
private boolean jsf12 = false;
-
// --------------------------------------------- FacesContextFactory Methods
-
/** {@inheritDoc} */
public FacesContext getFacesContext(Object context, Object request,
- Object response,
- Lifecycle lifecycle) throws FacesException {
+ Object response, Lifecycle lifecycle) throws FacesException
+ {
// Select the appropriate MockExternalContext implementation class
Class clazz = MockExternalContext.class;
- if (jsf12) {
- try {
- clazz = this.getClass().getClassLoader().loadClass
- ("org.apache.myfaces.test.mock.MockExternalContext12");
- } catch (RuntimeException e) {
+ if (jsf12)
+ {
+ try
+ {
+ clazz = this.getClass().getClassLoader().loadClass(
+ "org.apache.myfaces.test.mock.MockExternalContext12");
+ }
+ catch (RuntimeException e)
+ {
throw e;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
}
// Select the constructor we wish to call
Constructor mecConstructor = null;
- try {
+ try
+ {
mecConstructor = clazz.getConstructor(externalContextSignature);
- } catch (RuntimeException e) {
+ }
+ catch (RuntimeException e)
+ {
throw e;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
// Construct an appropriate MockExternalContext instance
MockExternalContext externalContext = null;
- try {
- externalContext = (MockExternalContext) mecConstructor.newInstance
- (new Object[] { context, request, response });
- } catch (RuntimeException e) {
+ try
+ {
+ externalContext = (MockExternalContext) mecConstructor
+ .newInstance(new Object[] { context, request, response });
+ }
+ catch (RuntimeException e)
+ {
throw e;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
// Construct an appropriate MockFacesContext instance and return it
- try {
- return (MockFacesContext)
- constructor.newInstance(new Object[] { externalContext, lifecycle });
- } catch (RuntimeException e) {
+ try
+ {
+ return (MockFacesContext) constructor.newInstance(new Object[] {
+ externalContext, lifecycle });
+ }
+ catch (RuntimeException e)
+ {
throw e;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
throw new FacesException(e);
}
}
-
}
Modified: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpServletRequest.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpServletRequest.java?rev=990408&r1=990407&r2=990408&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpServletRequest.java (original)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpServletRequest.java Sat Aug 28 18:59:21 2010
@@ -46,47 +46,44 @@ import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
-
/**
* <p>Mock implementation of <code>HttpServletContext</code>.</p>
*
* $Id$
* @since 1.0.0
*/
-public class MockHttpServletRequest implements HttpServletRequest {
-
+public class MockHttpServletRequest implements HttpServletRequest
+{
// ------------------------------------------------------------ Constructors
-
- public MockHttpServletRequest() {
+ public MockHttpServletRequest()
+ {
super();
}
-
- public MockHttpServletRequest(HttpSession session) {
+ public MockHttpServletRequest(HttpSession session)
+ {
super();
setHttpSession(session);
}
-
public MockHttpServletRequest(String contextPath, String servletPath,
- String pathInfo, String queryString) {
+ String pathInfo, String queryString)
+ {
super();
setPathElements(contextPath, servletPath, pathInfo, queryString);
}
-
-
public MockHttpServletRequest(String contextPath, String servletPath,
- String pathInfo, String queryString,
- HttpSession session) {
+ String pathInfo, String queryString, HttpSession session)
+ {
super();
setPathElements(contextPath, servletPath, pathInfo, queryString);
@@ -94,70 +91,70 @@ public class MockHttpServletRequest impl
}
-
// ----------------------------------------------------- Mock Object Methods
-
/**
* <p>Add a new listener instance that should be notified about
* attribute changes.</p>
*
* @param listener The new listener to register
*/
- public void addAttributeListener(ServletRequestAttributeListener listener) {
+ public void addAttributeListener(ServletRequestAttributeListener listener)
+ {
attributeListeners.add(listener);
}
-
/**
* <p>Add a date-valued header for this request.</p>
*
* @param name Header name
* @param value Header value
*/
- public void addDateHeader(String name, long value) {
+ public void addDateHeader(String name, long value)
+ {
headers.add(name + ": " + formatDate(value));
}
-
/**
* <p>Add a String-valued header for this request.</p>
*
* @param name Header name
* @param value Header value
*/
- public void addHeader(String name, String value) {
+ public void addHeader(String name, String value)
+ {
headers.add(name + ": " + value);
}
-
/**
* <p>Add an integer-valued header for this request.</p>
*
* @param name Header name
* @param value Header value
*/
- public void addIntHeader(String name, int value) {
+ public void addIntHeader(String name, int value)
+ {
headers.add(name + ": " + value);
}
-
/**
* <p>Add a request parameter for this request.</p>
*
* @param name Parameter name
* @param value Parameter value
*/
- public void addParameter(String name, String value) {
+ public void addParameter(String name, String value)
+ {
String[] values = (String[]) parameters.get(name);
- if (values == null) {
+ if (values == null)
+ {
String[] results = new String[] { value };
parameters.put(name, results);
return;
@@ -168,12 +165,12 @@ public class MockHttpServletRequest impl
parameters.put(name, results);
}
-
+
public void addCookie(Cookie c)
{
for (int i = 0; i < cookies.size(); i++)
{
- if ( ((Cookie)cookies.get(i)).getName().equals(c.getName()) )
+ if (((Cookie) cookies.get(i)).getName().equals(c.getName()))
{
cookies.set(i, c);
return;
@@ -186,37 +183,37 @@ public class MockHttpServletRequest impl
* <p>Return the <code>ServletContext</code> associated with
* this request.</p>
*/
- public ServletContext getServletContext() {
+ public ServletContext getServletContext()
+ {
return this.servletContext;
}
-
/**
* <p>Set the <code>HttpSession</code> associated with this request.</p>
*
* @param session The new session
*/
- public void setHttpSession(HttpSession session) {
+ public void setHttpSession(HttpSession session)
+ {
this.session = session;
}
-
/**
* <p>Set the <code>Locale</code> associated with this request.</p>
*
* @param locale The new locale
*/
- public void setLocale(Locale locale) {
+ public void setLocale(Locale locale)
+ {
this.locale = locale;
}
-
/**
* <p>Set the parsed path elements associated with this request.</p>
*
@@ -226,7 +223,8 @@ public class MockHttpServletRequest impl
* @param queryString The query string
*/
public void setPathElements(String contextPath, String servletPath,
- String pathInfo, String queryString) {
+ String pathInfo, String queryString)
+ {
this.contextPath = contextPath;
this.servletPath = servletPath;
@@ -235,34 +233,32 @@ public class MockHttpServletRequest impl
}
-
/**
* <p>Set the <code>ServletContext</code> associated with this request.</p>
*
* @param servletContext The new servlet context
*/
- public void setServletContext(ServletContext servletContext) {
+ public void setServletContext(ServletContext servletContext)
+ {
this.servletContext = servletContext;
}
-
/**
* <p>Set the <code>Principal</code> associated with this request.</p>
*
* @param principal The new Principal
*/
- public void setUserPrincipal(Principal principal) {
+ public void setUserPrincipal(Principal principal)
+ {
this.principal = principal;
}
-
// ------------------------------------------------------ Instance Variables
-
private List attributeListeners = new ArrayList();
private HashMap attributes = new HashMap();
private String contextPath = null;
@@ -278,29 +274,29 @@ public class MockHttpServletRequest impl
private String characterEncoding = null;
private ServletInputStream inputStream = null;
private List cookies = new ArrayList();
- private Vector locales = null;
+ private Vector locales = null;
// ---------------------------------------------- HttpServletRequest Methods
-
/** {@inheritDoc} */
- public String getAuthType() {
+ public String getAuthType()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getContextPath() {
+ public String getContextPath()
+ {
return contextPath;
}
-
/** {@inheritDoc} */
- public Cookie[] getCookies() {
+ public Cookie[] getCookies()
+ {
Cookie[] array = new Cookie[cookies.size()];
for (int i = 0; i < cookies.size(); i++)
@@ -310,15 +306,17 @@ public class MockHttpServletRequest impl
return array;
}
-
/** {@inheritDoc} */
- public long getDateHeader(String name) {
+ public long getDateHeader(String name)
+ {
String match = name + ":";
Iterator headers = this.headers.iterator();
- while (headers.hasNext()) {
+ while (headers.hasNext())
+ {
String header = (String) headers.next();
- if (header.startsWith(match)) {
+ if (header.startsWith(match))
+ {
return parseDate(header.substring(match.length() + 1).trim());
}
}
@@ -326,15 +324,17 @@ public class MockHttpServletRequest impl
}
-
/** {@inheritDoc} */
- public String getHeader(String name) {
+ public String getHeader(String name)
+ {
String match = name + ":";
Iterator headers = this.headers.iterator();
- while (headers.hasNext()) {
+ while (headers.hasNext())
+ {
String header = (String) headers.next();
- if (header.startsWith(match)) {
+ if (header.startsWith(match))
+ {
return header.substring(match.length() + 1).trim();
}
}
@@ -342,18 +342,21 @@ public class MockHttpServletRequest impl
}
-
/** {@inheritDoc} */
- public Enumeration getHeaderNames() {
+ public Enumeration getHeaderNames()
+ {
Vector values = new Vector();
Iterator headers = this.headers.iterator();
- while (headers.hasNext()) {
+ while (headers.hasNext())
+ {
String header = (String) headers.next();
int colon = header.indexOf(':');
- if (colon >= 0) {
+ if (colon >= 0)
+ {
String name = header.substring(0, colon).trim();
- if (!values.contains(name)) {
+ if (!values.contains(name))
+ {
values.add(name);
}
}
@@ -362,16 +365,18 @@ public class MockHttpServletRequest impl
}
-
/** {@inheritDoc} */
- public Enumeration getHeaders(String name) {
+ public Enumeration getHeaders(String name)
+ {
String match = name + ":";
Vector values = new Vector();
Iterator headers = this.headers.iterator();
- while (headers.hasNext()) {
+ while (headers.hasNext())
+ {
String header = (String) headers.next();
- if (header.startsWith(match)) {
+ if (header.startsWith(match))
+ {
values.add(header.substring(match.length() + 1).trim());
}
}
@@ -379,557 +384,583 @@ public class MockHttpServletRequest impl
}
-
/** {@inheritDoc} */
- public int getIntHeader(String name) {
+ public int getIntHeader(String name)
+ {
String match = name + ":";
Iterator headers = this.headers.iterator();
- while (headers.hasNext()) {
+ while (headers.hasNext())
+ {
String header = (String) headers.next();
- if (header.startsWith(match)) {
- return Integer.parseInt(header.substring(match.length() + 1).trim());
+ if (header.startsWith(match))
+ {
+ return Integer.parseInt(header.substring(match.length() + 1)
+ .trim());
}
}
return -1;
}
-
/** {@inheritDoc} */
- public String getMethod() {
+ public String getMethod()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getPathInfo() {
+ public String getPathInfo()
+ {
return pathInfo;
}
-
/** {@inheritDoc} */
- public String getPathTranslated() {
+ public String getPathTranslated()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getQueryString() {
+ public String getQueryString()
+ {
return queryString;
}
-
/** {@inheritDoc} */
- public String getRemoteUser() {
+ public String getRemoteUser()
+ {
- if (principal != null) {
+ if (principal != null)
+ {
return principal.getName();
- } else {
+ }
+ else
+ {
return null;
}
}
-
/** {@inheritDoc} */
- public String getRequestedSessionId() {
+ public String getRequestedSessionId()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getRequestURI() {
+ public String getRequestURI()
+ {
StringBuffer sb = new StringBuffer();
- if (contextPath != null) {
+ if (contextPath != null)
+ {
sb.append(contextPath);
}
- if (servletPath != null) {
+ if (servletPath != null)
+ {
sb.append(servletPath);
}
- if (pathInfo != null) {
+ if (pathInfo != null)
+ {
sb.append(pathInfo);
}
- if (sb.length() > 0) {
+ if (sb.length() > 0)
+ {
return sb.toString();
}
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public StringBuffer getRequestURL() {
+ public StringBuffer getRequestURL()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getServletPath() {
+ public String getServletPath()
+ {
return (servletPath);
}
-
/** {@inheritDoc} */
- public HttpSession getSession() {
+ public HttpSession getSession()
+ {
return getSession(true);
}
-
/** {@inheritDoc} */
- public HttpSession getSession(boolean create) {
+ public HttpSession getSession(boolean create)
+ {
- if (create && (session == null)) {
+ if (create && (session == null))
+ {
this.session = new MockHttpSession(this.servletContext);
}
return session;
}
-
/** {@inheritDoc} */
- public Principal getUserPrincipal() {
+ public Principal getUserPrincipal()
+ {
return principal;
}
-
/** {@inheritDoc} */
- public boolean isRequestedSessionIdFromCookie() {
+ public boolean isRequestedSessionIdFromCookie()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public boolean isRequestedSessionIdFromUrl() {
+ public boolean isRequestedSessionIdFromUrl()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public boolean isRequestedSessionIdFromURL() {
+ public boolean isRequestedSessionIdFromURL()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public boolean isRequestedSessionIdValid() {
+ public boolean isRequestedSessionIdValid()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public boolean isUserInRole(String role) {
+ public boolean isUserInRole(String role)
+ {
throw new UnsupportedOperationException();
}
-
// ------------------------------------------------- ServletRequest Methods
-
/** {@inheritDoc} */
- public Object getAttribute(String name) {
+ public Object getAttribute(String name)
+ {
return attributes.get(name);
}
-
/** {@inheritDoc} */
- public Enumeration getAttributeNames() {
+ public Enumeration getAttributeNames()
+ {
return new MockEnumeration(attributes.keySet().iterator());
}
-
/** {@inheritDoc} */
- public String getCharacterEncoding() {
+ public String getCharacterEncoding()
+ {
return characterEncoding;
}
-
/** {@inheritDoc} */
- public int getContentLength() {
+ public int getContentLength()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getContentType() {
+ public String getContentType()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
public ServletInputStream getInputStream()
{
return this.inputStream;
}
-
+
public void setInputStream(MockServletInputStream stream)
{
this.inputStream = stream;
}
/** {@inheritDoc} */
- public Locale getLocale() {
+ public Locale getLocale()
+ {
return locale;
}
-
/** {@inheritDoc} */
public Enumeration getLocales()
{
if (this.locales == null)
{
- locales = new Vector(Arrays.asList(Locale
- .getAvailableLocales()));
+ locales = new Vector(Arrays.asList(Locale.getAvailableLocales()));
}
return this.locales.elements();
}
-
/** {@inheritDoc} */
- public String getLocalAddr() {
+ public String getLocalAddr()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getLocalName() {
+ public String getLocalName()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public int getLocalPort() {
+ public int getLocalPort()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getParameter(String name) {
+ public String getParameter(String name)
+ {
String[] values = (String[]) parameters.get(name);
- if (values != null) {
+ if (values != null)
+ {
return values[0];
- } else {
+ }
+ else
+ {
return null;
}
}
-
/** {@inheritDoc} */
- public Map getParameterMap() {
+ public Map getParameterMap()
+ {
return parameters;
}
-
/** {@inheritDoc} */
- public Enumeration getParameterNames() {
+ public Enumeration getParameterNames()
+ {
return new MockEnumeration(parameters.keySet().iterator());
}
-
/** {@inheritDoc} */
- public String[] getParameterValues(String name) {
+ public String[] getParameterValues(String name)
+ {
return (String[]) parameters.get(name);
}
-
/** {@inheritDoc} */
- public String getProtocol() {
+ public String getProtocol()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
public BufferedReader getReader()
{
- if (this.inputStream != null) {
- try{
+ if (this.inputStream != null)
+ {
+ try
+ {
Reader sourceReader = (this.characterEncoding != null) ? new InputStreamReader(
this.inputStream, this.characterEncoding)
: new InputStreamReader(this.inputStream);
return new BufferedReader(sourceReader);
}
- catch(UnsupportedEncodingException e)
+ catch (UnsupportedEncodingException e)
{
throw new RuntimeException(e);
}
- } else {
+ }
+ else
+ {
return null;
}
}
-
/** {@inheritDoc} */
- public String getRealPath(String path) {
+ public String getRealPath(String path)
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getRemoteAddr() {
+ public String getRemoteAddr()
+ {
// i figure testing never assumes a specific remote - so anything works
return "1.2.3.4";
}
-
/** {@inheritDoc} */
- public String getRemoteHost() {
+ public String getRemoteHost()
+ {
// i figure testing never assumes a specific remote - so anything works
return "MyfacesServer";
}
-
/** {@inheritDoc} */
- public int getRemotePort() {
+ public int getRemotePort()
+ {
// i figure testing never assumes a specific remote - so anything works
return 46123;
}
-
/** {@inheritDoc} */
public RequestDispatcher getRequestDispatcher(String path)
{
return servletContext.getRequestDispatcher(path);
}
-
/** {@inheritDoc} */
- public String getScheme() {
+ public String getScheme()
+ {
return ("http");
}
-
/** {@inheritDoc} */
- public String getServerName() {
+ public String getServerName()
+ {
return ("localhost");
}
-
/** {@inheritDoc} */
- public int getServerPort() {
+ public int getServerPort()
+ {
return (8080);
}
-
/** {@inheritDoc} */
- public boolean isSecure() {
+ public boolean isSecure()
+ {
return false;
}
-
/** {@inheritDoc} */
- public void removeAttribute(String name) {
+ public void removeAttribute(String name)
+ {
- if (attributes.containsKey(name)) {
+ if (attributes.containsKey(name))
+ {
Object value = attributes.remove(name);
fireAttributeRemoved(name, value);
}
}
-
/** {@inheritDoc} */
- public void setAttribute(String name, Object value) {
+ public void setAttribute(String name, Object value)
+ {
- if (name == null) {
+ if (name == null)
+ {
throw new IllegalArgumentException("Attribute name cannot be null");
}
- if (value == null) {
+ if (value == null)
+ {
removeAttribute(name);
return;
}
- if (attributes.containsKey(name)) {
+ if (attributes.containsKey(name))
+ {
Object oldValue = attributes.get(name);
attributes.put(name, value);
fireAttributeReplaced(name, oldValue);
- } else {
+ }
+ else
+ {
attributes.put(name, value);
fireAttributeAdded(name, value);
}
}
-
/** {@inheritDoc} */
- public void setCharacterEncoding(String characterEncoding) {
+ public void setCharacterEncoding(String characterEncoding)
+ {
this.characterEncoding = characterEncoding;
}
-
// --------------------------------------------------------- Private Methods
-
/**
* <p>Fire an attribute added event to interested listeners.</p>
*
* @param key Attribute key whose value was added
* @param value The new attribute value
*/
- private void fireAttributeAdded(String key, Object value) {
- if (attributeListeners.size() < 1) {
+ private void fireAttributeAdded(String key, Object value)
+ {
+ if (attributeListeners.size() < 1)
+ {
return;
}
- ServletRequestAttributeEvent event =
- new ServletRequestAttributeEvent(getServletContext(), this, key, value);
+ ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(
+ getServletContext(), this, key, value);
Iterator listeners = attributeListeners.iterator();
- while (listeners.hasNext()) {
- ServletRequestAttributeListener listener =
- (ServletRequestAttributeListener) listeners.next();
+ while (listeners.hasNext())
+ {
+ ServletRequestAttributeListener listener = (ServletRequestAttributeListener) listeners
+ .next();
listener.attributeAdded(event);
}
}
-
/**
* <p>Fire an attribute removed event to interested listeners.</p>
*
* @param key Attribute key whose value was removed
* @param value Attribute value that was removed
*/
- private void fireAttributeRemoved(String key, Object value) {
- if (attributeListeners.size() < 1) {
+ private void fireAttributeRemoved(String key, Object value)
+ {
+ if (attributeListeners.size() < 1)
+ {
return;
}
- ServletRequestAttributeEvent event =
- new ServletRequestAttributeEvent(getServletContext(), this, key, value);
+ ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(
+ getServletContext(), this, key, value);
Iterator listeners = attributeListeners.iterator();
- while (listeners.hasNext()) {
- ServletRequestAttributeListener listener =
- (ServletRequestAttributeListener) listeners.next();
+ while (listeners.hasNext())
+ {
+ ServletRequestAttributeListener listener = (ServletRequestAttributeListener) listeners
+ .next();
listener.attributeRemoved(event);
}
}
-
/**
* <p>Fire an attribute replaced event to interested listeners.</p>
*
* @param key Attribute key whose value was replaced
* @param value The original value
*/
- private void fireAttributeReplaced(String key, Object value) {
- if (attributeListeners.size() < 1) {
+ private void fireAttributeReplaced(String key, Object value)
+ {
+ if (attributeListeners.size() < 1)
+ {
return;
}
- ServletRequestAttributeEvent event =
- new ServletRequestAttributeEvent(getServletContext(), this, key, value);
+ ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(
+ getServletContext(), this, key, value);
Iterator listeners = attributeListeners.iterator();
- while (listeners.hasNext()) {
- ServletRequestAttributeListener listener =
- (ServletRequestAttributeListener) listeners.next();
+ while (listeners.hasNext())
+ {
+ ServletRequestAttributeListener listener = (ServletRequestAttributeListener) listeners
+ .next();
listener.attributeReplaced(event);
}
}
-
/**
* <p>The date formatting helper we will use in <code>httpTimestamp()</code>.
* Note that usage of this helper must be synchronized.</p>
*/
- private static SimpleDateFormat format =
- new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
- static {
+ private static SimpleDateFormat format = new SimpleDateFormat(
+ "EEE, dd MMM yyyy HH:mm:ss zzz");
+ static
+ {
format.setTimeZone(TimeZone.getTimeZone("GMT"));
}
-
/**
* <p>Return a properly formatted String version of the specified
* date/time, formatted as required by the HTTP specification.</p>
*
* @param date Date/time, expressed as milliseconds since the epoch
*/
- private String formatDate(long date) {
+ private String formatDate(long date)
+ {
return format.format(new Date(date));
}
-
/**
* <p>Return a date/time value, parsed from the specified String.</p>
*
* @param date Date/time, expressed as a String
*/
- private long parseDate(String date) {
- try {
+ private long parseDate(String date)
+ {
+ try
+ {
return format.parse(date).getTime();
- } catch (ParseException e) {
+ }
+ catch (ParseException e)
+ {
throw new IllegalArgumentException(date);
}
}
-
}
Modified: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpServletResponse.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpServletResponse.java?rev=990408&r1=990407&r2=990408&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpServletResponse.java (original)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpServletResponse.java Sat Aug 28 18:59:21 2010
@@ -41,60 +41,62 @@ import javax.servlet.http.HttpServletRes
* $Id$
* @since 1.0.0
*/
-public class MockHttpServletResponse implements HttpServletResponse {
-
+public class MockHttpServletResponse implements HttpServletResponse
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Return a default instance.</p>
*/
- public MockHttpServletResponse() { }
-
+ public MockHttpServletResponse()
+ {
+ }
// ----------------------------------------------------- Mock Object Methods
-
/**
* <p>Retrieve the first value that was set for the specified header,
* if any. Otherwise, return <code>null</code>.</p>
*
* @param name Header name to look up
*/
- public String getHeader(String name) {
+ public String getHeader(String name)
+ {
String match = name + ":";
Iterator headers = this.headers.iterator();
- while (headers.hasNext()) {
+ while (headers.hasNext())
+ {
String header = (String) headers.next();
- if (header.startsWith(match)) {
+ if (header.startsWith(match))
+ {
return header.substring(match.length() + 1).trim();
}
}
return null;
}
-
+
public Cookie getCookie(String name)
{
- return (Cookie)cookies.get(name);
+ return (Cookie) cookies.get(name);
}
-
+
/**
* <p>Return the text message for the HTTP status that was set.</p>
*/
- public String getMessage() {
+ public String getMessage()
+ {
return this.message;
}
-
/**
* <p>Return the HTTP status code that was set.</p>
*/
- public int getStatus() {
+ public int getStatus()
+ {
return this.status;
}
-
/**
* <p>Set the <code>ServletOutputStream</code> to be returned by a call to
* <code>getOutputStream()</code>.</p>
@@ -104,11 +106,11 @@ public class MockHttpServletResponse imp
* @deprecated Let the <code>getOutputStream()</code> method create and
* return an instance of <code>MockServletOutputStream</code> for you
*/
- public void setOutputStream(ServletOutputStream stream) {
+ public void setOutputStream(ServletOutputStream stream)
+ {
this.stream = stream;
}
-
/**
* <p>Set the <code>PrintWriter</code> to be returned by a call to
* <code>getWriter()</code>.</p>
@@ -118,14 +120,13 @@ public class MockHttpServletResponse imp
* @deprecated Let the <code>getWriter()</code> method create and return
* an instance of <code>MockPrintWriter</code> for you
*/
- public void setWriter(PrintWriter writer) {
+ public void setWriter(PrintWriter writer)
+ {
this.writer = writer;
}
-
// ------------------------------------------------------ Instance Variables
-
private String encoding = "ISO-8859-1";
private String contentType = "text/html";
private List headers = new ArrayList();
@@ -133,7 +134,7 @@ public class MockHttpServletResponse imp
private int status = HttpServletResponse.SC_OK;
private ServletOutputStream stream = null;
private PrintWriter writer = null;
-
+
private boolean committed = false;
private long contentLength = 0;
private int bufferSize = 0;
@@ -142,78 +143,76 @@ public class MockHttpServletResponse imp
// -------------------------------------------- HttpServletResponse Methods
-
/** {@inheritDoc} */
public void addCookie(Cookie cookie)
{
cookies.put(cookie.getName(), cookie);
}
-
/** {@inheritDoc} */
- public void addDateHeader(String name, long value) {
+ public void addDateHeader(String name, long value)
+ {
headers.add(name + ": " + formatDate(value));
}
-
/** {@inheritDoc} */
- public void addHeader(String name, String value) {
+ public void addHeader(String name, String value)
+ {
headers.add(name + ": " + value);
}
-
/** {@inheritDoc} */
- public void addIntHeader(String name, int value) {
+ public void addIntHeader(String name, int value)
+ {
headers.add(name + ": " + value);
}
-
/** {@inheritDoc} */
- public boolean containsHeader(String name) {
+ public boolean containsHeader(String name)
+ {
return getHeader(name) != null;
}
-
/** {@inheritDoc} */
- public String encodeRedirectUrl(String url) {
+ public String encodeRedirectUrl(String url)
+ {
return encodeRedirectURL(url);
}
-
/** {@inheritDoc} */
- public String encodeRedirectURL(String url) {
+ public String encodeRedirectURL(String url)
+ {
return url;
}
-
/** {@inheritDoc} */
- public String encodeUrl(String url) {
+ public String encodeUrl(String url)
+ {
return encodeURL(url);
}
-
/** {@inheritDoc} */
- public String encodeURL(String url) {
+ public String encodeURL(String url)
+ {
return url;
}
-
/** {@inheritDoc} */
public void sendError(int status)
{
@@ -225,7 +224,6 @@ public class MockHttpServletResponse imp
this.committed = true;
}
-
/** {@inheritDoc} */
public void sendError(int status, String message)
{
@@ -238,10 +236,11 @@ public class MockHttpServletResponse imp
this.committed = true;
}
-
/** {@inheritDoc} */
- public void sendRedirect(String location) {
- if (this.committed) {
+ public void sendRedirect(String location)
+ {
+ if (this.committed)
+ {
throw new IllegalStateException("Response is already committed");
}
this.status = HttpServletResponse.SC_MOVED_TEMPORARILY;
@@ -249,93 +248,92 @@ public class MockHttpServletResponse imp
this.committed = true;
}
-
/** {@inheritDoc} */
- public void setDateHeader(String name, long value) {
+ public void setDateHeader(String name, long value)
+ {
removeHeader(name);
addDateHeader(name, value);
}
-
/** {@inheritDoc} */
- public void setHeader(String name, String value) {
+ public void setHeader(String name, String value)
+ {
removeHeader(name);
addHeader(name, value);
}
-
/** {@inheritDoc} */
- public void setIntHeader(String name, int value) {
+ public void setIntHeader(String name, int value)
+ {
removeHeader(name);
addIntHeader(name, value);
}
-
/** {@inheritDoc} */
public void setStatus(int status)
{
this.status = status;
}
-
/** {@inheritDoc} */
- public void setStatus(int status, String message) {
+ public void setStatus(int status, String message)
+ {
this.status = status;
this.message = message;
}
-
// ------------------------------------------------ ServletResponse Methods
-
/** {@inheritDoc} */
public void flushBuffer()
{
-
- }
+ }
/** {@inheritDoc} */
- public int getBufferSize() {
+ public int getBufferSize()
+ {
return bufferSize;
}
-
/** {@inheritDoc} */
- public String getCharacterEncoding() {
+ public String getCharacterEncoding()
+ {
return this.encoding;
}
-
/** {@inheritDoc} */
- public String getContentType() {
+ public String getContentType()
+ {
return this.contentType;
}
-
/** {@inheritDoc} */
public Locale getLocale()
{
return this.locale;
}
-
/** {@inheritDoc} */
- public ServletOutputStream getOutputStream() throws IOException {
+ public ServletOutputStream getOutputStream() throws IOException
+ {
- if (stream == null) {
- if (writer != null) {
- throw new IllegalStateException("Cannot call getOutputStream() after getWriter() has been called");
+ if (stream == null)
+ {
+ if (writer != null)
+ {
+ throw new IllegalStateException(
+ "Cannot call getOutputStream() after getWriter() has been called");
}
stream = new MockServletOutputStream(new ByteArrayOutputStream());
}
@@ -343,13 +341,16 @@ public class MockHttpServletResponse imp
}
-
/** {@inheritDoc} */
- public PrintWriter getWriter() throws IOException {
+ public PrintWriter getWriter() throws IOException
+ {
- if (writer == null) {
- if (stream != null) {
- throw new IllegalStateException("Cannot call getWriter() after getOutputStream() was called");
+ if (writer == null)
+ {
+ if (stream != null)
+ {
+ throw new IllegalStateException(
+ "Cannot call getWriter() after getOutputStream() was called");
}
writer = new MockPrintWriter(new CharArrayWriter());
}
@@ -357,104 +358,98 @@ public class MockHttpServletResponse imp
}
-
/** {@inheritDoc} */
public boolean isCommitted()
{
return committed;
}
-
/** {@inheritDoc} */
public void reset()
{
}
-
/** {@inheritDoc} */
public void resetBuffer()
{
}
-
/** {@inheritDoc} */
public void setBufferSize(int size)
{
this.bufferSize = size;
}
-
/** {@inheritDoc} */
- public void setCharacterEncoding(String charset) {
+ public void setCharacterEncoding(String charset)
+ {
this.encoding = charset;
}
-
/** {@inheritDoc} */
public void setContentLength(int length)
{
this.contentLength = length;
}
-
/** {@inheritDoc} */
- public void setContentType(String type) {
+ public void setContentType(String type)
+ {
contentType = type;
}
-
/** {@inheritDoc} */
public void setLocale(Locale locale)
{
this.locale = locale;
}
-
// --------------------------------------------------------- Private Methods
-
/**
* <p>The date formatting helper we will use in <code>httpTimestamp()</code>.
* Note that usage of this helper must be synchronized.</p>
*/
- private static SimpleDateFormat format =
- new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
- static {
+ private static SimpleDateFormat format = new SimpleDateFormat(
+ "EEE, dd MMM yyyy HH:mm:ss zzz");
+ static
+ {
format.setTimeZone(TimeZone.getTimeZone("GMT"));
}
-
/**
* <p>Return a properly formatted String version of the specified
* date/time, formatted as required by the HTTP specification.</p>
*
* @param date Date/time, expressed as milliseconds since the epoch
*/
- private String formatDate(long date) {
+ private String formatDate(long date)
+ {
return format.format(new Date(date));
}
-
/**
* <p>Remove any header that has been set with the specific name.</p>
*
* @param name Header name to look up
*/
- private void removeHeader(String name) {
+ private void removeHeader(String name)
+ {
String match = name + ":";
Iterator headers = this.headers.iterator();
- while (headers.hasNext()) {
+ while (headers.hasNext())
+ {
String header = (String) headers.next();
- if (header.startsWith(match)) {
+ if (header.startsWith(match))
+ {
headers.remove();
return;
}
}
}
-
}
Modified: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpSession.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpSession.java?rev=990408&r1=990407&r2=990408&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpSession.java (original)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpSession.java Sat Aug 28 18:59:21 2010
@@ -35,90 +35,85 @@ import javax.servlet.http.HttpSessionCon
* $Id$
* @since 1.0.0
*/
-public class MockHttpSession implements HttpSession {
-
+public class MockHttpSession implements HttpSession
+{
// ------------------------------------------------------------ Constructors
-
/**
* <p>Configure a default instance.</p>
*/
- public MockHttpSession() {
+ public MockHttpSession()
+ {
super();
}
-
/**
* <p>Configure a session instance associated with the specified
* servlet context.</p>
*
* @param servletContext The associated servlet context
*/
- public MockHttpSession(ServletContext servletContext) {
+ public MockHttpSession(ServletContext servletContext)
+ {
super();
setServletContext(servletContext);
}
-
// ----------------------------------------------------- Mock Object Methods
-
/**
* <p>Add a new listener instance that should be notified about
* attribute changes.</p>
*
* @param listener The new listener to be added
*/
- public void addAttributeListener(HttpSessionAttributeListener listener) {
+ public void addAttributeListener(HttpSessionAttributeListener listener)
+ {
attributeListeners.add(listener);
}
-
/**
* <p>Set the ServletContext associated with this session.</p>
*
* @param servletContext The associated servlet context
*/
- public void setServletContext(ServletContext servletContext) {
+ public void setServletContext(ServletContext servletContext)
+ {
this.servletContext = servletContext;
}
-
// ------------------------------------------------------ Instance Variables
-
private List attributeListeners = new ArrayList();
private HashMap attributes = new HashMap();
private String id = "123";
private ServletContext servletContext = null;
private boolean invalid = false;
-
// ---------------------------------------------------------- Public Methods
-
/**
* <p>Set the session identifier of this session.</p>
*
* @param id The new session identifier
*/
- public void setId(String id) {
+ public void setId(String id)
+ {
this.id = id;
}
-
// ----------------------------------------------------- HttpSession Methods
-
/** {@inheritDoc} */
- public Object getAttribute(String name) {
+ public Object getAttribute(String name)
+ {
assertValidity();
@@ -126,9 +121,9 @@ public class MockHttpSession implements
}
-
/** {@inheritDoc} */
- public Enumeration getAttributeNames() {
+ public Enumeration getAttributeNames()
+ {
assertValidity();
@@ -136,222 +131,232 @@ public class MockHttpSession implements
}
-
/** {@inheritDoc} */
- public long getCreationTime() {
+ public long getCreationTime()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getId() {
+ public String getId()
+ {
return this.id;
}
-
/** {@inheritDoc} */
- public long getLastAccessedTime() {
+ public long getLastAccessedTime()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public int getMaxInactiveInterval() {
+ public int getMaxInactiveInterval()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public ServletContext getServletContext() {
+ public ServletContext getServletContext()
+ {
return this.servletContext;
}
-
/** {@inheritDoc} */
- public HttpSessionContext getSessionContext() {
+ public HttpSessionContext getSessionContext()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public Object getValue(String name) {
+ public Object getValue(String name)
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String[] getValueNames() {
+ public String[] getValueNames()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public void invalidate() {
-
+ public void invalidate()
+ {
+
assertValidity();
attributes.clear();
invalid = true;
}
-
/** {@inheritDoc} */
- public boolean isNew() {
+ public boolean isNew()
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public void putValue(String name, Object value) {
+ public void putValue(String name, Object value)
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public void removeAttribute(String name) {
+ public void removeAttribute(String name)
+ {
assertValidity();
- if (attributes.containsKey(name)) {
+ if (attributes.containsKey(name))
+ {
Object value = attributes.remove(name);
fireAttributeRemoved(name, value);
}
}
-
/** {@inheritDoc} */
- public void removeValue(String name) {
+ public void removeValue(String name)
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public void setAttribute(String name, Object value) {
+ public void setAttribute(String name, Object value)
+ {
assertValidity();
- if (name == null) {
+ if (name == null)
+ {
throw new IllegalArgumentException("Attribute name cannot be null");
}
- if (value == null) {
+ if (value == null)
+ {
removeAttribute(name);
return;
}
- if (attributes.containsKey(name)) {
+ if (attributes.containsKey(name))
+ {
Object oldValue = attributes.get(name);
attributes.put(name, value);
fireAttributeReplaced(name, oldValue);
- } else {
+ }
+ else
+ {
attributes.put(name, value);
fireAttributeAdded(name, value);
}
}
-
/** {@inheritDoc} */
- public void setMaxInactiveInterval(int interval) {
+ public void setMaxInactiveInterval(int interval)
+ {
throw new UnsupportedOperationException();
}
-
// --------------------------------------------------------- Support Methods
-
/**
* <p>Fire an attribute added event to interested listeners.</p>
*
* @param key Attribute whose value was added
* @param value The new value
*/
- private void fireAttributeAdded(String key, Object value) {
- if (attributeListeners.size() < 1) {
+ private void fireAttributeAdded(String key, Object value)
+ {
+ if (attributeListeners.size() < 1)
+ {
return;
}
- HttpSessionBindingEvent event =
- new HttpSessionBindingEvent(this, key, value);
+ HttpSessionBindingEvent event = new HttpSessionBindingEvent(this, key,
+ value);
Iterator listeners = attributeListeners.iterator();
- while (listeners.hasNext()) {
- HttpSessionAttributeListener listener =
- (HttpSessionAttributeListener) listeners.next();
+ while (listeners.hasNext())
+ {
+ HttpSessionAttributeListener listener = (HttpSessionAttributeListener) listeners
+ .next();
listener.attributeAdded(event);
}
}
-
/**
* <p>Fire an attribute removed event to interested listeners.</p>
*
* @param key Attribute whose value was removed
* @param value The removed value
*/
- private void fireAttributeRemoved(String key, Object value) {
- if (attributeListeners.size() < 1) {
+ private void fireAttributeRemoved(String key, Object value)
+ {
+ if (attributeListeners.size() < 1)
+ {
return;
}
- HttpSessionBindingEvent event =
- new HttpSessionBindingEvent(this, key, value);
+ HttpSessionBindingEvent event = new HttpSessionBindingEvent(this, key,
+ value);
Iterator listeners = attributeListeners.iterator();
- while (listeners.hasNext()) {
- HttpSessionAttributeListener listener =
- (HttpSessionAttributeListener) listeners.next();
+ while (listeners.hasNext())
+ {
+ HttpSessionAttributeListener listener = (HttpSessionAttributeListener) listeners
+ .next();
listener.attributeRemoved(event);
}
}
-
/**
* <p>Fire an attribute replaced event to interested listeners.</p>
*
* @param key Attribute whose value was replaced
* @param value The original value
*/
- private void fireAttributeReplaced(String key, Object value) {
- if (attributeListeners.size() < 1) {
+ private void fireAttributeReplaced(String key, Object value)
+ {
+ if (attributeListeners.size() < 1)
+ {
return;
}
- HttpSessionBindingEvent event =
- new HttpSessionBindingEvent(this, key, value);
+ HttpSessionBindingEvent event = new HttpSessionBindingEvent(this, key,
+ value);
Iterator listeners = attributeListeners.iterator();
- while (listeners.hasNext()) {
- HttpSessionAttributeListener listener =
- (HttpSessionAttributeListener) listeners.next();
+ while (listeners.hasNext())
+ {
+ HttpSessionAttributeListener listener = (HttpSessionAttributeListener) listeners
+ .next();
listener.attributeReplaced(event);
}
}
-
/**
* <p>Throws an {@link IllegalStateException} if this session is invalid.</p>
*/
- private void assertValidity()
+ private void assertValidity()
{
- if (invalid)
+ if (invalid)
{
throw new IllegalStateException("Session is invalid.");
}
Modified: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockMethodBinding.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockMethodBinding.java?rev=990408&r1=990407&r2=990408&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockMethodBinding.java (original)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockMethodBinding.java Sat Aug 28 18:59:21 2010
@@ -43,18 +43,18 @@ import javax.faces.el.ValueBinding;
* @since 1.0.0
*/
-public class MockMethodBinding extends MethodBinding implements StateHolder {
-
+public class MockMethodBinding extends MethodBinding implements StateHolder
+{
// ------------------------------------------------------------ Constructors
/**
* <p>Construct a default instance.</p>
*/
- public MockMethodBinding() {
+ public MockMethodBinding()
+ {
}
-
/**
* <p>Construct a configured instance.</p>
*
@@ -62,89 +62,101 @@ public class MockMethodBinding extends M
* @param ref Method binding expression to be parsed
* @param args Signature of this method
*/
- public MockMethodBinding(Application application, String ref,
- Class[] args) {
+ public MockMethodBinding(Application application, String ref, Class[] args)
+ {
this.application = application;
this.args = args;
- if (ref.startsWith("#{") && ref.endsWith("}")) {
+ if (ref.startsWith("#{") && ref.endsWith("}"))
+ {
ref = ref.substring(2, ref.length() - 1);
}
this.ref = ref;
int period = ref.lastIndexOf(".");
- if (period < 0) {
+ if (period < 0)
+ {
throw new ReferenceSyntaxException(ref);
}
vb = application.createValueBinding(ref.substring(0, period));
name = ref.substring(period + 1);
- if (name.length() < 1) {
+ if (name.length() < 1)
+ {
throw new ReferenceSyntaxException(ref);
}
}
-
// ------------------------------------------------------ Instance Variables
-
private Application application;
private Class args[];
private String name;
private String ref;
private ValueBinding vb;
-
// --------------------------------------------------- MethodBinding Methods
-
/** {@inheritDoc} */
public Object invoke(FacesContext context, Object[] params)
- throws EvaluationException, MethodNotFoundException {
+ throws EvaluationException, MethodNotFoundException
+ {
- if (context == null) {
+ if (context == null)
+ {
throw new NullPointerException();
}
Object base = vb.getValue(context);
- if (base == null) {
- throw new EvaluationException("Cannot find object via expression \""
- + vb.getExpressionString() + "\"");
+ if (base == null)
+ {
+ throw new EvaluationException(
+ "Cannot find object via expression \""
+ + vb.getExpressionString() + "\"");
}
Method method = method(base);
- try {
+ try
+ {
return (method.invoke(base, params));
- } catch (IllegalAccessException e) {
+ }
+ catch (IllegalAccessException e)
+ {
throw new EvaluationException(e);
- } catch (InvocationTargetException e) {
+ }
+ catch (InvocationTargetException e)
+ {
throw new EvaluationException(e.getTargetException());
}
}
-
/** {@inheritDoc} */
- public Class getType(FacesContext context) {
+ public Class getType(FacesContext context)
+ {
Object base = vb.getValue(context);
Method method = method(base);
Class returnType = method.getReturnType();
- if ("void".equals(returnType.getName())) {
+ if ("void".equals(returnType.getName()))
+ {
return (null);
- } else {
+ }
+ else
+ {
return (returnType);
}
}
/** {@inheritDoc} */
- public String getExpressionString() {
+ public String getExpressionString()
+ {
return "#{" + ref + "}";
}
// ----------------------------------------------------- StateHolder Methods
-
/** {@inheritDoc} */
- public Object saveState(FacesContext context) {
+ public Object saveState(FacesContext context)
+ {
Object values[] = new Object[4];
values[0] = name;
values[1] = ref;
@@ -153,57 +165,65 @@ public class MockMethodBinding extends M
return (values);
}
-
/** {@inheritDoc} */
- public void restoreState(FacesContext context, Object state) {
+ public void restoreState(FacesContext context, Object state)
+ {
Object values[] = (Object[]) state;
name = (String) values[0];
ref = (String) values[1];
- vb = (ValueBinding) UIComponentBase.restoreAttachedState(context,
- values[2]);
- args = (Class []) values[3];
+ vb = (ValueBinding) UIComponentBase.restoreAttachedState(context,
+ values[2]);
+ args = (Class[]) values[3];
}
-
/**
* <p>Flag indicating this is a transient instance.</p>
*/
private boolean transientFlag = false;
-
/** {@inheritDoc} */
- public boolean isTransient() {
+ public boolean isTransient()
+ {
return (this.transientFlag);
}
-
/** {@inheritDoc} */
- public void setTransient(boolean transientFlag) {
+ public void setTransient(boolean transientFlag)
+ {
this.transientFlag = transientFlag;
}
/** {@inheritDoc} */
- public int hashCode() {
- if (ref == null) {
+ public int hashCode()
+ {
+ if (ref == null)
+ {
return 0;
- } else {
+ }
+ else
+ {
return ref.hashCode();
}
}
/** {@inheritDoc} */
- public boolean equals(Object otherObj) {
+ public boolean equals(Object otherObj)
+ {
MockMethodBinding other = null;
- if (!(otherObj instanceof MockMethodBinding)) {
+ if (!(otherObj instanceof MockMethodBinding))
+ {
return false;
}
other = (MockMethodBinding) otherObj;
// test object reference equality
- if (this.ref != other.ref) {
+ if (this.ref != other.ref)
+ {
// test object equality
- if (null != this.ref && null != other.ref) {
- if (!this.ref.equals(other.ref)) {
+ if (null != this.ref && null != other.ref)
+ {
+ if (!this.ref.equals(other.ref))
+ {
return false;
}
}
@@ -211,13 +231,18 @@ public class MockMethodBinding extends M
}
// no need to test name, since it flows from ref.
// test our args array
- if (this.args != other.args) {
- if (this.args.length != other.args.length) {
+ if (this.args != other.args)
+ {
+ if (this.args.length != other.args.length)
+ {
return false;
}
- for (int i = 0, len = this.args.length; i < len; i++) {
- if (this.args[i] != other.args[i]) {
- if (!this.ref.equals(other.ref)) {
+ for (int i = 0, len = this.args.length; i < len; i++)
+ {
+ if (this.args[i] != other.args[i])
+ {
+ if (!this.ref.equals(other.ref))
+ {
return false;
}
}
@@ -226,26 +251,26 @@ public class MockMethodBinding extends M
return true;
}
-
// --------------------------------------------------------- Private Methods
-
/**
* <p>Return the <code>Method</code> to be called.</p>
*
* @param base Base object from which to extract the method reference
*/
- Method method(Object base) {
+ Method method(Object base)
+ {
Class clazz = base.getClass();
- try {
+ try
+ {
return (clazz.getMethod(name, args));
- } catch (NoSuchMethodException e) {
+ }
+ catch (NoSuchMethodException e)
+ {
throw new MethodNotFoundException(ref + ": " + e.getMessage());
}
}
-
-
}
Modified: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockNavigationHandler.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockNavigationHandler.java?rev=990408&r1=990407&r2=990408&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockNavigationHandler.java (original)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockNavigationHandler.java Sat Aug 28 18:59:21 2010
@@ -32,47 +32,43 @@ import javax.faces.context.FacesContext;
* @since 1.0.0
*/
-public class MockNavigationHandler extends NavigationHandler {
-
+public class MockNavigationHandler extends NavigationHandler
+{
// ------------------------------------------------------------ Constructors
/**
* <p>Construct a default instance.</p>
*/
- public MockNavigationHandler() {
+ public MockNavigationHandler()
+ {
}
-
// ----------------------------------------------------- Mock Object Methods
-
/**
* <p>Add a outcome-viewId pair to the destinations map.</p>
*
* @param outcome Logical outcome string
* @param viewId Destination view identifier
*/
- public void addDestination(String outcome, String viewId) {
+ public void addDestination(String outcome, String viewId)
+ {
destinations.put(outcome, viewId);
}
-
// ------------------------------------------------------ Instance Variables
-
/**
* <p>Set of destination view ids, keyed by logical outcome String
* that will cause navigation to that view id.</p>
*/
private Map destinations = new HashMap();
-
// ----------------------------------------------- NavigationHandler Methods
-
/**
* <p>Process the specified navigation request.</p>
*
@@ -80,32 +76,33 @@ public class MockNavigationHandler exten
* @param action Action method being executed
* @param outcome Logical outcome from this action method
*/
- public void handleNavigation(FacesContext context,
- String action, String outcome) {
+ public void handleNavigation(FacesContext context, String action,
+ String outcome)
+ {
// Navigate solely based on outcome, if we get a match
String viewId = (String) destinations.get(outcome);
- if (viewId != null) {
- UIViewRoot view = getViewHandler(context).createView(context, viewId);
+ if (viewId != null)
+ {
+ UIViewRoot view = getViewHandler(context).createView(context,
+ viewId);
context.setViewRoot(view);
}
}
-
// --------------------------------------------------------- Private Methods
-
/**
* <p>Return the <code>ViewHandler</code> instance for this application.</p>
*
* @param context <code>FacesContext</code> for the current request
*/
- private ViewHandler getViewHandler(FacesContext context) {
+ private ViewHandler getViewHandler(FacesContext context)
+ {
return context.getApplication().getViewHandler();
}
-
}
Modified: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockPortletContext.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockPortletContext.java?rev=990408&r1=990407&r2=990408&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockPortletContext.java (original)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockPortletContext.java Sat Aug 28 18:59:21 2010
@@ -36,7 +36,8 @@ import javax.portlet.PortletRequestDispa
* $Id$
* @since 1.0.0
*/
-public class MockPortletContext implements PortletContext {
+public class MockPortletContext implements PortletContext
+{
// ----------------------------------------------------- Mock Object Methods
@@ -47,13 +48,13 @@ public class MockPortletContext implemen
* @param name Parameter name
* @param value Parameter value
*/
- public void addInitParameter(String name, String value) {
+ public void addInitParameter(String name, String value)
+ {
parameters.put(name, value);
}
-
/**
* <p>Add a new MIME type mapping to the set of mappings recognized by this
* instance.</p>
@@ -61,20 +62,21 @@ public class MockPortletContext implemen
* @param extension Extension to check for (without the period)
* @param contentType Corresponding content type
*/
- public void addMimeType(String extension, String contentType) {
+ public void addMimeType(String extension, String contentType)
+ {
mimeTypes.put(extension, contentType);
}
-
/**
* <p>Set the document root for <code>getRealPath()</code> resolution.
* This parameter <strong>MUST</strong> represent a directory.</p>
*
* @param documentRoot The new base directory
*/
- public void setDocumentRoot(File documentRoot) {
+ public void setDocumentRoot(File documentRoot)
+ {
this.documentRoot = documentRoot;
@@ -87,55 +89,55 @@ public class MockPortletContext implemen
private Hashtable mimeTypes = new Hashtable();
private Hashtable parameters = new Hashtable();
-
// -------------------------------------------------- PortletContext Methods
-
/** {@inheritDoc} */
- public Object getAttribute(String name) {
+ public Object getAttribute(String name)
+ {
return attributes.get(name);
}
-
/** {@inheritDoc} */
- public Enumeration getAttributeNames() {
+ public Enumeration getAttributeNames()
+ {
return attributes.keys();
}
-
/** {@inheritDoc} */
- public String getInitParameter(String name) {
+ public String getInitParameter(String name)
+ {
return (String) parameters.get(name);
}
-
/** {@inheritDoc} */
- public Enumeration getInitParameterNames() {
+ public Enumeration getInitParameterNames()
+ {
return parameters.keys();
}
-
/** {@inheritDoc} */
- public int getMajorVersion() {
+ public int getMajorVersion()
+ {
return 1;
}
-
/** {@inheritDoc} */
- public String getMimeType(String path) {
+ public String getMimeType(String path)
+ {
int period = path.lastIndexOf('.');
- if (period < 0) {
+ if (period < 0)
+ {
return null;
}
String extension = path.substring(period + 1);
@@ -143,114 +145,136 @@ public class MockPortletContext implemen
}
-
- public int getMinorVersion() {
+ public int getMinorVersion()
+ {
// TODO Auto-generated method stub
return 0;
}
-
- public PortletRequestDispatcher getNamedDispatcher(String arg0) {
+ public PortletRequestDispatcher getNamedDispatcher(String arg0)
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public String getPortletContextName() {
+ public String getPortletContextName()
+ {
return "MockPortletContext";
}
-
/** {@inheritDoc} */
- public String getRealPath(String path) {
+ public String getRealPath(String path)
+ {
- if (documentRoot != null) {
- if (!path.startsWith("/")) {
+ if (documentRoot != null)
+ {
+ if (!path.startsWith("/"))
+ {
throw new IllegalArgumentException("The specified path ('"
+ path + "') does not start with a '/' character");
}
File resolved = new File(documentRoot, path.substring(1));
- try {
+ try
+ {
return resolved.getCanonicalPath();
- } catch (IOException e) {
+ }
+ catch (IOException e)
+ {
return resolved.getAbsolutePath();
}
- } else {
+ }
+ else
+ {
return null;
}
}
-
/** {@inheritDoc} */
- public PortletRequestDispatcher getRequestDispatcher(String arg0) {
+ public PortletRequestDispatcher getRequestDispatcher(String arg0)
+ {
throw new UnsupportedOperationException();
}
-
/** {@inheritDoc} */
- public URL getResource(String path) throws MalformedURLException {
+ public URL getResource(String path) throws MalformedURLException
+ {
- if (documentRoot != null) {
- if (!path.startsWith("/")) {
+ if (documentRoot != null)
+ {
+ if (!path.startsWith("/"))
+ {
throw new MalformedURLException("The specified path ('" + path
+ "') does not start with a '/' character");
}
File resolved = new File(documentRoot, path.substring(1));
- if (resolved.exists()) {
+ if (resolved.exists())
+ {
return resolved.toURL();
- } else {
+ }
+ else
+ {
return null;
}
- } else {
+ }
+ else
+ {
return null;
}
}
-
/** {@inheritDoc} */
- public InputStream getResourceAsStream(String path) {
+ public InputStream getResourceAsStream(String path)
+ {
- try {
+ try
+ {
URL url = getResource(path);
- if (url != null) {
+ if (url != null)
+ {
return url.openStream();
}
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
;
}
return null;
}
-
/** {@inheritDoc} */
- public Set getResourcePaths(String path) {
+ public Set getResourcePaths(String path)
+ {
- if (documentRoot == null) {
+ if (documentRoot == null)
+ {
return null;
}
// Enforce the leading slash restriction
- if (!path.startsWith("/")) {
+ if (!path.startsWith("/"))
+ {
throw new IllegalArgumentException("The specified path ('" + path
+ "') does not start with a '/' character");
}
// Locate the File node for this path's directory (if it exists)
File node = new File(documentRoot, path.substring(1));
- if (!node.exists()) {
+ if (!node.exists())
+ {
return null;
}
- if (!node.isDirectory()) {
+ if (!node.isDirectory())
+ {
return null;
}
@@ -258,13 +282,16 @@ public class MockPortletContext implemen
// directory
Set set = new HashSet();
String[] files = node.list();
- if (files == null) {
+ if (files == null)
+ {
return null;
}
- for (int i = 0; i < files.length; i++) {
+ for (int i = 0; i < files.length; i++)
+ {
String subfile = path + files[i];
File subnode = new File(node, files[i]);
- if (subnode.isDirectory()) {
+ if (subnode.isDirectory())
+ {
subfile += "/";
}
set.add(subfile);
@@ -275,48 +302,51 @@ public class MockPortletContext implemen
}
-
/** {@inheritDoc} */
- public String getServerInfo() {
+ public String getServerInfo()
+ {
return "MockPortletContext";
}
-
/** {@inheritDoc} */
- public void log(String message) {
+ public void log(String message)
+ {
System.out.println(message);
}
-
/** {@inheritDoc} */
- public void log(String message, Throwable exception) {
+ public void log(String message, Throwable exception)
+ {
System.out.println(message);
exception.printStackTrace();
}
-
/** {@inheritDoc} */
- public void removeAttribute(String name) {
+ public void removeAttribute(String name)
+ {
- if (attributes.containsKey(name)) {
+ if (attributes.containsKey(name))
+ {
attributes.remove(name);
}
}
-
/** {@inheritDoc} */
- public void setAttribute(String name, Object value) {
+ public void setAttribute(String name, Object value)
+ {
- if (name == null) {
+ if (name == null)
+ {
throw new IllegalArgumentException("Attribute name cannot be null");
}
- if (value == null) {
+ if (value == null)
+ {
removeAttribute(name);
return;
}