myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcoo...@apache.org
Subject svn commit: r1296364 - in /myfaces/trinidad/branches/1.2.12.7.0-branch: ./ trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/
Date Fri, 02 Mar 2012 18:28:43 GMT
Author: mcooper
Date: Fri Mar  2 18:28:43 2012
New Revision: 1296364

URL: http://svn.apache.org/viewvc?rev=1296364&view=rev
Log:
TRINIDAD-2229 Enhance golden file test framework to support testing outputMode

Thanks to Pavitra for the patch.

Modified:
    myfaces/trinidad/branches/1.2.12.7.0-branch/   (props changed)
    myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/MFacesContext.java
    myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/MRequestContext.java
    myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/RenderKitBootstrap.java
    myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/RenderKitTestCase.java

Propchange: myfaces/trinidad/branches/1.2.12.7.0-branch/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Mar  2 18:28:43 2012
@@ -11,3 +11,12 @@ trinidad-oc4j-app.log.0
 trinidad-oc4j-app.log.0.lck
 trinidad-oc4j-app.xml
 .adf
+relative mtr12 - clean all.app
+relative mtr12 - clean.app
+relative mtr12 - compare golden files.app
+relative mtr12 - install (test-skip).app
+relative mtr12 - install jdev-jdev.app
+relative mtr12 - install.app
+relative mtr12 - jdev-jdev.app
+relative mtr12 - jetty on demo and install.app
+relative mtr12 - jetty on demo.app

Modified: myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/MFacesContext.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/MFacesContext.java?rev=1296364&r1=1296363&r2=1296364&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/MFacesContext.java
(original)
+++ myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/MFacesContext.java
Fri Mar  2 18:28:43 2012
@@ -40,6 +40,7 @@ import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
 import javax.faces.render.RenderKit;
 
+import org.apache.myfaces.trinidad.context.RequestContext;
 import org.apache.myfaces.trinidadinternal.share.config.Configuration;
 import org.apache.myfaces.trinidadbuild.test.MockFacesContext12;
 import org.apache.shale.test.mock.MockExternalContext;
@@ -52,10 +53,15 @@ public class MFacesContext extends MockF
 {
   public MFacesContext(Application application, boolean testMode)
   {
+    this(application, testMode, Collections.EMPTY_MAP);
+  }
+  
+  public MFacesContext(Application application, boolean testMode, Map<String, String>
initParamMap)
+  {
     super(application);
     setCurrentInstance(this);
-    _external = new External(testMode, application);
-  }
+    _external = new External(testMode, application, initParamMap);
+  }  
 
   @Override
   public ResponseWriter getResponseWriter()
@@ -212,12 +218,13 @@ public class MFacesContext extends MockF
   private static final class External
     extends MockExternalContext
   {
-    public External(boolean testMode, Object contextObject)
+    public External(boolean testMode, Object contextObject, Map<String,String> initParamMap)
     {
       super(new MServletContext(), null, null);
 
       _testMode = testMode;
       _contextObject = contextObject;
+      _initParamMap = initParamMap;
 
       File file = null;
       try
@@ -269,6 +276,11 @@ public class MFacesContext extends MockF
       // A hack to disable image generation
       if ("org.apache.myfaces.trinidadinternal.BLOCK_IMAGE_GENERATION".equals(name))
         return "true";
+      
+      if (!_initParamMap.isEmpty())
+      {
+        return (String) _initParamMap.get(name);
+      }
       return null;
     }
 
@@ -308,6 +320,17 @@ public class MFacesContext extends MockF
     @Override
     public Map<String, String> getRequestParameterMap()
     {
+      RequestContext reqContext = RequestContext.getCurrentInstance();
+      String outputMode = reqContext.getOutputMode();
+      if (outputMode != null && !outputMode.isEmpty())
+      {
+        if (outputMode.equals(RequestContext.OutputMode.ATTACHMENT.id()))
+        {
+          Map<String, String> reqParamMap = new HashMap<String, String>(1);
+          reqParamMap.put(_OUTPUT_MODE_PARAM, RequestContext.OutputMode.ATTACHMENT.id());
+          return reqParamMap;
+        }
+      }      
       return Collections.EMPTY_MAP;
     }
 
@@ -374,6 +397,8 @@ public class MFacesContext extends MockF
     private volatile Map<String, Object> _sessionMap = null;
 
     private final boolean _testMode;
+    private final Map<String, String> _initParamMap;
   }
   private static final String _GLOBAL_MESSAGE = "org.apache.myfaces.trinidadinternal.renderkit.MFacesContext.GLOBAL_MESSAGE";
+  static private final String _OUTPUT_MODE_PARAM = "org.apache.myfaces.trinidad.outputMode";
 }

Modified: myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/MRequestContext.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/MRequestContext.java?rev=1296364&r1=1296363&r2=1296364&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/MRequestContext.java
(original)
+++ myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/MRequestContext.java
Fri Mar  2 18:28:43 2012
@@ -33,6 +33,7 @@ import javax.faces.context.FacesContext;
 import javax.faces.event.PhaseId;
 
 import org.apache.myfaces.trinidad.change.ChangeManager;
+import org.apache.myfaces.trinidad.change.ComponentChange;
 import org.apache.myfaces.trinidad.config.RegionManager;
 
 import org.apache.myfaces.trinidad.component.visit.VisitContext;
@@ -72,6 +73,19 @@ public class MRequestContext extends Req
   {
     return _agent;
   }
+  
+  // Support setting outputMode so we can render content for an output mode other than 'default'.
+  public void setOutputMode(String outputMode)
+  {
+    _outputMode = outputMode;
+  }
+  
+  @Override
+  public String getOutputMode()
+  {
+    return _outputMode;
+  }
+  
 
   @Override
   public PageResolver getPageResolver()
@@ -140,12 +154,6 @@ public class MRequestContext extends Req
     return false;
   }
 
-  @Override
-  public String getOutputMode()
-  {
-    return null;
-  }
-
   public void setSkinFamily(String skin)
   {
     _skin = skin;
@@ -329,7 +337,8 @@ public class MRequestContext extends Req
   @Override
   public void partialUpdateNotify(UIComponent updated)
   {
-    throw new UnsupportedOperationException("Should not be called during rendering");
+    // in some cases we allow adding partial targets during rendering 
+    // throw new UnsupportedOperationException("Should not be called during rendering");
   }
 
   @Override
@@ -353,7 +362,12 @@ public class MRequestContext extends Req
   @Override
   public ChangeManager getChangeManager()
   {
-    throw new UnsupportedOperationException("Not implemented yet");
+    if (_changeManager == null)
+    {
+      _changeManager = new NoOpChangeManager();
+    }
+    
+    return _changeManager;
   }
 
   @Override
@@ -426,6 +440,19 @@ public class MRequestContext extends Req
 
     return viewMap;
   }
+  
+  // Added merely to have a noop implementation
+  public static class NoOpChangeManager extends ChangeManager
+  {
+
+    @Override
+    public void addComponentChange(FacesContext facesContext,
+                                   UIComponent uIComponent,
+                                   ComponentChange componentChange)
+    {
+      // do nothing
+    }
+  }
 
   private String _skin;
   private Long _maxMemory;
@@ -434,7 +461,9 @@ public class MRequestContext extends Req
   private Accessibility _accMode;
   private AccessibilityProfile _accProfile;
   private ClientValidation _clientValidation = ClientValidation.ALERT;
+  private ChangeManager _changeManager;
   private Agent _agent;
+  private String _outputMode;
   private boolean _rtl = false;
   private boolean _animationEnabled = true;
 

Modified: myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/RenderKitBootstrap.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/RenderKitBootstrap.java?rev=1296364&r1=1296363&r2=1296364&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/RenderKitBootstrap.java
(original)
+++ myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/RenderKitBootstrap.java
Fri Mar  2 18:28:43 2012
@@ -36,6 +36,7 @@ import org.apache.myfaces.trinidad.skin.
 
 import org.apache.myfaces.trinidadinternal.agent.AgentFactoryImpl;
 
+import org.apache.myfaces.trinidadinternal.agent.AgentImpl;
 import org.apache.myfaces.trinidadinternal.skin.SkinFactoryImpl;
 import org.apache.myfaces.trinidadinternal.skin.SkinUtils;
 
@@ -76,6 +77,11 @@ public class RenderKitBootstrap
     return _pocketPCAgent;
   }
 
+  static public Agent getGenericDesktopAgent()
+  {
+    return _genericDesktopAgent;
+  }
+  
   static public RenderKit getRenderKit(FacesContext context)
   {
     RenderKitFactory factory = (RenderKitFactory)
@@ -176,8 +182,24 @@ public class RenderKitBootstrap
     headerMap.put("User-Agent","Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; PPC; 240x320)");
     headerMap.put("UA-pixels","240x320");
     _pocketPCAgent = factory.createAgent(headerMap);
+    
+    // for the genericDesktop agent, we don't care about the user agent 
+    _genericDesktopAgent = _populateGenericDesktopAgentImpl();
   }
  
+  static private Agent _populateGenericDesktopAgentImpl()
+  {
+    AgentImpl agent = new AgentImpl();
+    agent.setType(Agent.TYPE_DESKTOP);
+    // Generic Desktop agent
+    agent.setAgent(Agent.AGENT_GENERIC_DESKTOP);
+    agent.setAgentVersion("0.0"); 
+    agent.setPlatform(Agent.PLATFORM_UNKNOWN);
+    agent.setPlatformVersion(Agent.PLATFORM_VERSION_UNKNOWN);
+    agent.setMakeModel(Agent.MAKE_MODEL_UNKNOWN);
+    
+    return agent;
+  }
 
   private FacesConfigInfo _facesConfigInfo;
   
@@ -189,6 +211,7 @@ public class RenderKitBootstrap
   static private Agent           _ieAgent;
   static private Agent           _safariAgent;
   static private Agent           _pocketPCAgent;
+  static private Agent           _genericDesktopAgent;
 
   static
   {

Modified: myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/RenderKitTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/RenderKitTestCase.java?rev=1296364&r1=1296363&r2=1296364&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/RenderKitTestCase.java
(original)
+++ myfaces/trinidad/branches/1.2.12.7.0-branch/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/RenderKitTestCase.java
Fri Mar  2 18:28:43 2012
@@ -35,6 +35,7 @@ import java.util.logging.LogRecord;
 import java.util.logging.Logger;
 import java.util.logging.SimpleFormatter;
 
+import javax.faces.application.Application;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIViewRoot;
 import javax.faces.context.FacesContext;
@@ -109,7 +110,8 @@ abstract public class RenderKitTestCase 
            definition.getSkin(),
            definition.getAgent(),
            definition.getAccessibilityMode(),
-           definition.isRightToLeft());
+           definition.isRightToLeft(),
+           definition.getOutputMode());
     }
 
 
@@ -118,13 +120,15 @@ abstract public class RenderKitTestCase 
                     String skin,
                     Agent agent,
                     RequestContext.Accessibility accMode,
-                    boolean rightToLeft)
+                    boolean rightToLeft,
+                    String outputMode)
     {
       super(name + "-" + categoryName);
       _skin = skin;
       _agent = agent;
       _accMode = accMode;
       _rightToLeft = rightToLeft;
+      _outputMode = outputMode;
     }
 
     @Override
@@ -152,10 +156,11 @@ abstract public class RenderKitTestCase 
     @Override
     protected void setUp() throws IOException  
     {
-      _facesContext = new MFacesContext(MApplication.sharedInstance(), true);
+      _facesContext = createMockFacesContext(MApplication.sharedInstance(), true);
       _requestContext = new MRequestContext();
       _requestContext.setSkinFamily(_skin);
       _requestContext.setAgent(_agent);
+      _requestContext.setOutputMode(_outputMode);
       _requestContext.setRightToLeft(_rightToLeft);
       _requestContext.setAccessibilityMode(_accMode);
 
@@ -170,6 +175,13 @@ abstract public class RenderKitTestCase 
         service.encodeBegin(_facesContext);
         
     }
+    
+    protected MFacesContext createMockFacesContext(
+      Application mockApplication,
+      boolean testMode)
+    {
+      return new MFacesContext(mockApplication, testMode);
+    }
 
     @Override
     protected void tearDown() throws IOException  
@@ -252,10 +264,11 @@ abstract public class RenderKitTestCase 
     private TestResult    _result;
     private MFacesContext _facesContext;
     private MRequestContext _requestContext;
-    private String           _skin;
-    private Agent            _agent;
+    private String          _skin;
+    private String          _outputMode; 
+    private Agent           _agent;
     private RequestContext.Accessibility  _accMode;
-    private boolean          _rightToLeft;
+    private boolean         _rightToLeft;
   }
 
 
@@ -526,19 +539,25 @@ abstract public class RenderKitTestCase 
         {
           if (first)
           {
-            addTest(new RendererTest(name,
-                                     definition,
-                                     false));
+            addRendererTest(name, definition, false);
             first = false;
           }
           else
           {
-            addTest(new RendererTest(name, definition, lenient));
+            addRendererTest(name, definition, lenient);
           }
         }
       }
     }
   }
+  
+  protected void addRendererTest(
+    String name, 
+    SuiteDefinition definition, 
+    boolean lenient) throws IOException, SAXException
+  {
+    addTest(new RendererTest(name, definition, lenient));
+  }
 
   protected abstract UIComponent populateDefaultComponentTree(
     UIViewRoot root,
@@ -556,12 +575,24 @@ abstract public class RenderKitTestCase 
       Agent  agent,
       boolean rightToLeft)
     {
+      this(category, skin, accessibilityMode, agent, rightToLeft, null);
+    }
+    
+    public SuiteDefinition(
+      String category,
+      String skin,
+      RequestContext.Accessibility accessibilityMode,
+      Agent  agent,
+      boolean rightToLeft,
+      String outputMode)
+    {
       _category = category;
       _skin     = skin;
       _accessibilityMode  = accessibilityMode;
       _agent    = agent;
       _rightToLeft = rightToLeft;
-    }
+      _outputMode = outputMode;
+    }    
 
     public String getCategory()
     {
@@ -572,6 +603,11 @@ abstract public class RenderKitTestCase 
     {
       return _skin;
     }
+    
+    public String getOutputMode()
+    {
+      return _outputMode;
+    }
 
     public RequestContext.Accessibility getAccessibilityMode()
     {
@@ -591,6 +627,7 @@ abstract public class RenderKitTestCase 
 
     private String _category;
     private String _skin;
+    private String _outputMode;
     private RequestContext.Accessibility _accessibilityMode;
     private Agent _agent;
     private boolean _rightToLeft;



Mime
View raw message