shale-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mat...@apache.org
Subject svn commit: r573267 - in /shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock: MockExternalContext.java MockHttpServletRequest.java MockResponseWriter.java MockViewHandler.java
Date Thu, 06 Sep 2007 14:00:20 GMT
Author: matzew
Date: Thu Sep  6 07:00:19 2007
New Revision: 573267

URL: http://svn.apache.org/viewvc?rev=573267&view=rev
Log:
SHALE-465
SHALE-466
SHALE-467
SHALE-468

thx to Bernd Bohmän (bommel@apache.org), for creating these patches.

Modified:
    shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockExternalContext.java
    shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockHttpServletRequest.java
    shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockResponseWriter.java
    shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockViewHandler.java

Modified: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockExternalContext.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockExternalContext.java?rev=573267&r1=573266&r2=573267&view=diff
==============================================================================
--- shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockExternalContext.java
(original)
+++ shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockExternalContext.java
Thu Sep  6 07:00:19 2007
@@ -82,6 +82,7 @@
     protected HttpServletResponse response = null;
     private Map sessionMap = null;
     private Map requestCookieMap = new HashMap();
+    private Map requestHeaderMap = new HashMap();
     private Map requestParameterMap = new HashMap();
 
 
@@ -128,6 +129,29 @@
         requestParameterMap = map;
     }
 
+    /**
+     * <p>Add the specified request header for this request.</p>
+     *
+     * @param key Parameter name
+     * @param value Parameter value
+     */
+    public void addRequestHeader(String key, String value) {
+        requestHeaderMap.put(key, value);
+    }
+
+
+    /**
+     * <p>Set the request header map for this request.</p>
+     *
+     * @param map The new request header map
+     */
+    public void setRequestHeaderMap(Map map) {
+        requestHeaderMap = map;
+    }
+
+
+
+
 
     // ------------------------------------------------- ExternalContext Methods
 
@@ -246,7 +270,7 @@
     /** {@inheritDoc} */
     public Map getRequestHeaderMap() {
 
-        throw new UnsupportedOperationException();
+        return requestHeaderMap;
 
     }
 

Modified: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockHttpServletRequest.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockHttpServletRequest.java?rev=573267&r1=573266&r2=573267&view=diff
==============================================================================
--- shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockHttpServletRequest.java
(original)
+++ shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockHttpServletRequest.java
Thu Sep  6 07:00:19 2007
@@ -258,6 +258,7 @@
     private ServletContext servletContext = null;
     private String servletPath = null;
     private HttpSession session = null;
+    private String characterEncoding = null;
 
 
     // ---------------------------------------------- HttpServletRequest Methods
@@ -550,7 +551,7 @@
     /** {@inheritDoc} */
     public String getCharacterEncoding() {
 
-        throw new UnsupportedOperationException();
+        return characterEncoding;
 
     }
 
@@ -781,9 +782,9 @@
 
 
     /** {@inheritDoc} */
-    public void setCharacterEncoding(String name) {
+    public void setCharacterEncoding(String characterEncoding) {
 
-        throw new UnsupportedOperationException();
+        this.characterEncoding = characterEncoding;
 
     }
 

Modified: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockResponseWriter.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockResponseWriter.java?rev=573267&r1=573266&r2=573267&view=diff
==============================================================================
--- shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockResponseWriter.java
(original)
+++ shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockResponseWriter.java
Thu Sep  6 07:00:19 2007
@@ -51,6 +51,7 @@
     private String characterEncoding = null;
     private String contentType = "text/html";
     private boolean open = false; // Is an element currently open?
+    private UIComponent component;
     private Writer writer = null;
 
 
@@ -91,6 +92,7 @@
             writer.write(name);
             writer.write(">");
         }
+        component = null;
     }
 
 
@@ -127,26 +129,27 @@
         writer.write('<');
         writer.write(name);
         open = true;
+        this.component = component;
     }
 
 
     /** {@inheritDoc} */
     public void writeAttribute(String name, Object value, String property) throws IOException
{
-        if ((name == null) || (value == null)) {
+        if (name == null) {
             throw new NullPointerException();
         }
         if (!open) {
             throw new IllegalStateException();
         }
-        writer.write(" ");
-        writer.write(name);
-        writer.write("=\"");
-        if (value instanceof String) {
-            string((String) value);
-        } else {
-            string(value.toString());
+        String attribute = findValue(value, property);
+        if (attribute != null) {
+          writer.write(" ");
+          writer.write(name);
+          writer.write("=\"");
+          string(attribute);
+
+          writer.write("\"");
         }
-        writer.write("\"");
     }
 
 
@@ -172,11 +175,11 @@
             throw new NullPointerException();
         }
         finish();
-        if (text instanceof String) {
-            string((String) text);
-        } else {
-            string(text.toString());
+        String value = findValue(text, property);
+        if (value != null) {
+          string(value);
         }
+
     }
 
 
@@ -195,21 +198,21 @@
 
     /** {@inheritDoc} */
     public void writeURIAttribute(String name, Object value, String property) throws IOException
{
-        if ((name == null) || (value == null)) {
+        if (name == null) {
             throw new NullPointerException();
         }
         if (!open) {
             throw new IllegalStateException();
         }
-        writer.write(" ");
-        writer.write(name);
-        writer.write("=\"");
-        if (value instanceof String) {
-            string((String) value);
-        } else {
-            string(value.toString());
+        String attribute = findValue(value, property);
+        if (attribute != null) {
+          writer.write(" ");
+          writer.write(name);
+          writer.write("=\"");
+
+          string(attribute);
+          writer.write("\"");
         }
-        writer.write("\"");
     }
 
 
@@ -331,7 +334,6 @@
      * @exception IOException if an input/output error occurs
      */
     private void string(String s) throws IOException {
-
         for (int i = 0; i < s.length(); i++) {
             character(s.charAt(i));
         }
@@ -349,5 +351,21 @@
 
     }
 
+    private String findValue(final Object value, final String property) {
+        if (value != null) {
+            return value instanceof String ? (String) value : value.toString();
+        } else if (property != null) {
+            if (component != null) {
+                final Object object = component.getAttributes().get(property);
+                if (object != null) {
+                    return object instanceof String ? (String) object : object.toString();
+                } else {
+                    return null;
+                }
+            }
+
+        }
+        return null;
+    }
 
 }

Modified: shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockViewHandler.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockViewHandler.java?rev=573267&r1=573266&r2=573267&view=diff
==============================================================================
--- shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockViewHandler.java
(original)
+++ shale/framework/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockViewHandler.java
Thu Sep  6 07:00:19 2007
@@ -146,8 +146,6 @@
     /** {@inheritDoc} */
     public void writeState(FacesContext context) {
 
-        throw new UnsupportedOperationException();
-
     }
 
 



Mime
View raw message