[jboss-cvs] jboss-seam/src/main/org/jboss/seam/mock ...
Peter Muir
peter at bleepbleep.org.uk
Tue Oct 9 09:58:50 EDT 2007
User: pmuir
Date: 07/10/09 09:58:50
Modified: src/main/org/jboss/seam/mock MockRenderKit.java
MockResponseWriter.java MockApplication.java
BaseSeamTest.java
Log:
Initial support for integration testing Seam Mail - yay ( JBSEAM-1833) and a start at tests for the mail example
Revision Changes Path
1.5 +2 -2 jboss-seam/src/main/org/jboss/seam/mock/MockRenderKit.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MockRenderKit.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/mock/MockRenderKit.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- MockRenderKit.java 12 Feb 2007 17:36:20 -0000 1.4
+++ MockRenderKit.java 9 Oct 2007 13:58:50 -0000 1.5
@@ -17,13 +17,13 @@
@Override
public void addRenderer(String x, String y, Renderer renderer)
{
- throw new UnsupportedOperationException();
+ // Do nothing
}
@Override
public Renderer getRenderer(String x, String y)
{
- throw new UnsupportedOperationException();
+ return null;
}
@Override
1.2 +70 -25 jboss-seam/src/main/org/jboss/seam/mock/MockResponseWriter.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MockResponseWriter.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/mock/MockResponseWriter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- MockResponseWriter.java 12 Feb 2007 17:36:20 -0000 1.1
+++ MockResponseWriter.java 9 Oct 2007 13:58:50 -0000 1.2
@@ -1,6 +1,7 @@
-package org.jboss.seam.mock;
+ package org.jboss.seam.mock;
import java.io.IOException;
+import java.io.StringWriter;
import java.io.Writer;
import javax.faces.component.UIComponent;
@@ -9,109 +10,153 @@
public class MockResponseWriter extends ResponseWriter
{
+ private Writer writer;
+
+ public MockResponseWriter(Writer writer)
+ {
+ this.writer = writer;
+ }
+
+ public MockResponseWriter()
+ {
+ this.writer = new StringWriter();
+ }
+
@Override
public ResponseWriter cloneWithWriter(Writer writer)
{
- // TODO Auto-generated method stub
- return null;
+ return new MockResponseWriter(writer);
}
@Override
public void endDocument() throws IOException
{
- // TODO Auto-generated method stub
-
+ // Do nothing
}
@Override
public void endElement(String element) throws IOException
{
- // TODO Auto-generated method stub
-
+ // Do nothing
}
@Override
public void flush() throws IOException
{
- // TODO Auto-generated method stub
+ writer.flush();
}
@Override
public String getCharacterEncoding()
{
- // TODO Auto-generated method stub
return null;
}
@Override
public String getContentType()
{
- // TODO Auto-generated method stub
return null;
}
@Override
public void startDocument() throws IOException
{
- // TODO Auto-generated method stub
-
+ // Do nothing
}
@Override
public void startElement(String element, UIComponent component) throws IOException
{
- // TODO Auto-generated method stub
-
+ // Do nothing
}
@Override
public void writeAttribute(String attribute, Object object, String string) throws IOException
{
- // TODO Auto-generated method stub
-
+ // Do nothing
}
@Override
public void writeComment(Object object) throws IOException
{
- // TODO Auto-generated method stub
+ // TODO Do nothing
}
@Override
- public void writeText(Object text, String string) throws IOException
+ public void writeText(Object value, String string) throws IOException
{
- // TODO Auto-generated method stub
-
+ if (value == null)
+ {
+ throw new NullPointerException("Text must not be null.");
+ }
+ String strValue = value.toString();
+ write(strValue);
}
@Override
public void writeText(char[] chars, int start, int end) throws IOException
{
- // TODO Auto-generated method stub
-
+ if (chars== null)
+ {
+ throw new NullPointerException("cbuf name must not be null");
+ }
+ if (chars.length < start + end)
+ {
+ throw new IndexOutOfBoundsException((start + end) + " > " + chars.length);
+ }
+ String strValue = new String(chars, start, end);
+ write(strValue);
}
@Override
public void writeURIAttribute(String attribute, Object object, String string) throws IOException
{
- // TODO Auto-generated method stub
+ // Do nothing
}
@Override
public void close() throws IOException
{
- // TODO Auto-generated method stub
+ writer.close();
}
@Override
public void write(char[] chars, int start, int end) throws IOException
{
- // TODO Auto-generated method stub
+ writer.write(chars, start, end);
+ }
+
+ @Override
+ public void write(String str) throws IOException
+ {
+ writer.write(str);
+ }
+
+ @Override
+ public void write(int c) throws IOException
+ {
+ writer.write(c);
+ }
+ @Override
+ public void write(char cbuf[]) throws IOException
+ {
+ writer.write(cbuf);
+ }
+
+ @Override
+ public void write(String str, int off, int len) throws IOException
+ {
+ writer.write(str, off, len);
+ }
+
+ public Writer getWriter()
+ {
+ return this.writer;
}
}
1.22 +19 -2 jboss-seam/src/main/org/jboss/seam/mock/MockApplication.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MockApplication.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/mock/MockApplication.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- MockApplication.java 13 Aug 2007 18:03:11 -0000 1.21
+++ MockApplication.java 9 Oct 2007 13:58:50 -0000 1.22
@@ -17,6 +17,7 @@
import javax.faces.application.StateManager;
import javax.faces.application.ViewHandler;
import javax.faces.component.UIComponent;
+import javax.faces.component.UIOutput;
import javax.faces.context.FacesContext;
import javax.faces.convert.BigDecimalConverter;
import javax.faces.convert.BigIntegerConverter;
@@ -244,7 +245,23 @@
@Override
public UIComponent createComponent(String name) throws FacesException
{
- throw new UnsupportedOperationException();
+ // Best guess component creation with a dummy component if it can't be found
+ if (name.startsWith("org.jboss.seam.mail.ui"))
+ {
+ try
+ {
+ return (UIComponent) Class.forName(name).newInstance();
+ }
+ catch (Exception e)
+ {
+ throw new UnsupportedOperationException("Unable to create component " + name);
+ }
+ }
+ else
+ {
+ // Oh well, can't simply create the component so put a dummy one in its place
+ return new UIOutput();
+ }
}
@Override
1.31 +32 -0 jboss-seam/src/main/org/jboss/seam/mock/BaseSeamTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: BaseSeamTest.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/mock/BaseSeamTest.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -b -r1.30 -r1.31
--- BaseSeamTest.java 4 Oct 2007 23:08:09 -0000 1.30
+++ BaseSeamTest.java 9 Oct 2007 13:58:50 -0000 1.31
@@ -18,6 +18,7 @@
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
+import javax.mail.internet.MimeMessage;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.Filter;
@@ -44,9 +45,12 @@
import org.jboss.seam.core.Manager;
import org.jboss.seam.core.Validators;
import org.jboss.seam.faces.FacesMessages;
+import org.jboss.seam.faces.Renderer;
import org.jboss.seam.init.Initialization;
import org.jboss.seam.jsf.SeamApplication;
import org.jboss.seam.jsf.SeamPhaseListener;
+import org.jboss.seam.mail.MailSession;
+import org.jboss.seam.mail.MockTransport;
import org.jboss.seam.pageflow.Pageflow;
import org.jboss.seam.servlet.SeamFilter;
import org.jboss.seam.servlet.ServletSessionMap;
@@ -875,6 +879,34 @@
}
+ public abstract class MailTest extends Request
+ {
+
+ private String viewId;
+
+ public MailTest (String viewId)
+ {
+ this.viewId = viewId;
+ }
+
+ public MailTest (String viewId, String conversationId)
+ {
+ super(conversationId);
+ this.viewId = viewId;
+ }
+
+ protected abstract void testMessage(MimeMessage renderedMessage) throws Exception;
+
+ @Override
+ protected final void invokeApplication() throws Exception
+ {
+ Contexts.getApplicationContext().set(Seam.getComponentName(MailSession.class), new MailSession("mock").create());
+ Renderer.instance().render(viewId);
+ testMessage(MockTransport.getMailMessage());
+ }
+
+ }
+
public void begin()
{
session = new MockHttpSession(servletContext);
More information about the jboss-cvs-commits
mailing list