[jboss-cvs] jboss-seam/src/main/org/jboss/seam/mock ...
Gavin King
gavin.king at jboss.com
Fri Oct 27 08:58:10 EDT 2006
User: gavin
Date: 06/10/27 08:58:10
Modified: src/main/org/jboss/seam/mock MockApplication.java
SeamTest.java
Log:
use a component to persist page-scoped data
change how page parameters are stored
improve test harness
Revision Changes Path
1.9 +23 -4 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.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- MockApplication.java 26 Oct 2006 19:12:39 -0000 1.8
+++ MockApplication.java 27 Oct 2006 12:58:10 -0000 1.9
@@ -179,16 +179,35 @@
converters.put(BigInteger.class, new BigIntegerConverter());
}
+ private final Map<String, Converter> convertersById = new HashMap<String, Converter>();
+ {
+ convertersById.put(IntegerConverter.CONVERTER_ID, new IntegerConverter());
+ convertersById.put(LongConverter.CONVERTER_ID, new LongConverter());
+ convertersById.put(FloatConverter.CONVERTER_ID, new FloatConverter());
+ convertersById.put(DoubleConverter.CONVERTER_ID, new DoubleConverter());
+ convertersById.put(BooleanConverter.CONVERTER_ID, new BooleanConverter());
+ convertersById.put(ShortConverter.CONVERTER_ID, new ShortConverter());
+ convertersById.put(ByteConverter.CONVERTER_ID, new ByteConverter());
+ convertersById.put(CharacterConverter.CONVERTER_ID, new CharacterConverter());
+ convertersById.put(BigDecimalConverter.CONVERTER_ID, new BigDecimalConverter());
+ convertersById.put(BigIntegerConverter.CONVERTER_ID, new BigIntegerConverter());
+ }
+
@Override
public void addConverter(String id, String converterClass) {
- throw new UnsupportedOperationException();
+ convertersById.put( id, instantiateConverter(converterClass) );
}
@Override
public void addConverter(Class type, String converterClass) {
+ converters.put( type, instantiateConverter(converterClass) );
+ }
+
+ private Converter instantiateConverter(String converterClass)
+ {
try
{
- converters.put( type, (Converter) Reflections.classForName(converterClass).newInstance() );
+ return (Converter) Reflections.classForName(converterClass).newInstance();
}
catch (Exception e)
{
@@ -198,7 +217,7 @@
@Override
public Converter createConverter(String id) {
- throw new UnsupportedOperationException();
+ return convertersById.get(id);
}
@Override
@@ -208,7 +227,7 @@
@Override
public Iterator getConverterIds() {
- throw new UnsupportedOperationException();
+ return convertersById.keySet().iterator();
}
@Override
1.49 +26 -8 jboss-seam/src/main/org/jboss/seam/mock/SeamTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SeamTest.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/mock/SeamTest.java,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -b -r1.48 -r1.49
--- SeamTest.java 26 Oct 2006 21:16:19 -0000 1.48
+++ SeamTest.java 27 Oct 2006 12:58:10 -0000 1.49
@@ -24,10 +24,12 @@
import org.hibernate.validator.ClassValidator;
import org.hibernate.validator.InvalidValue;
import org.jboss.seam.Component;
+import org.jboss.seam.Seam;
import org.jboss.seam.contexts.Lifecycle;
import org.jboss.seam.core.FacesMessages;
import org.jboss.seam.core.Init;
import org.jboss.seam.core.Manager;
+import org.jboss.seam.core.FacesPage;
import org.jboss.seam.core.Pageflow;
import org.jboss.seam.core.Validation;
import org.jboss.seam.init.Initialization;
@@ -45,7 +47,7 @@
*
* @author Gavin King
* @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
- * @version $Revision: 1.48 $
+ * @version $Revision: 1.49 $
*/
public class SeamTest
{
@@ -56,12 +58,18 @@
private SeamPhaseListener phases;
private MockHttpSession session;
private Map<String, Map> conversationViewRootAttributes;
+ private Map<String, Object> pageParameters = new HashMap<String, Object>();
protected void setParameter(String name, String value)
{
getParameters().put( name, new String[] {value} );
}
+ protected void setPageParameter(String name, Object value)
+ {
+ pageParameters.put(name, value);
+ }
+
protected Map<String, String[]> getParameters()
{
return ( (MockHttpServletRequest) externalContext.getRequest() ).getParameters();
@@ -344,22 +352,28 @@
UIViewRoot viewRoot = facesContext.getApplication().getViewHandler().createView( facesContext, getViewId() );
facesContext.setViewRoot(viewRoot);
+ Map viewRootAttributes = facesContext.getViewRoot().getAttributes();
if ( conversationId!=null )
{
if ( isGetRequest() )
{
- getParameters().put( Manager.instance().getConversationIdParameter(), new String[] {conversationId} );
+ setParameter( Manager.instance().getConversationIdParameter(), conversationId );
//TODO: what about conversationIsLongRunning????
}
else
{
if ( conversationViewRootAttributes.containsKey(conversationId) )
{
+ //should really only do this if the view id matches (not really possible to implement)
Map state = conversationViewRootAttributes.get(conversationId);
- facesContext.getViewRoot().getAttributes().putAll(state);
+ viewRootAttributes.putAll(state);
}
}
}
+ if ( !isGetRequest() )
+ {
+ viewRootAttributes.putAll(pageParameters);
+ }
phases.afterPhase( new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW, MockLifecycle.INSTANCE) );
@@ -435,14 +449,18 @@
afterRequest();
- Map attributes = facesContext.getViewRoot().getAttributes();
+ Map attributes = viewRootAttributes;
if (attributes!=null)
{
- conversationId = (String) attributes.get(Manager.CONVERSATION_ID);
+ FacesPage facesPage = (FacesPage) attributes.get( Seam.getComponentName(FacesPage.class) );
+ if (facesPage!=null)
+ {
+ conversationId = facesPage.getConversationId();
Map conversationState = new HashMap();
conversationState.putAll(attributes);
conversationViewRootAttributes.put(conversationId, conversationState);
}
+ }
return conversationId;
}
More information about the jboss-cvs-commits
mailing list