You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by et...@apache.org on 2008/05/27 08:27:14 UTC

svn commit: r660401 - in /incubator/shindig/trunk/java: common/ common/src/main/java/org/apache/shindig/common/util/ common/src/test/java/org/apache/shindig/common/util/ gadgets/ gadgets/src/main/java/org/apache/shindig/gadgets/http/ gadgets/src/main/j...

Author: etnu
Date: Mon May 26 23:27:02 2008
New Revision: 660401

URL: http://svn.apache.org/viewvc?rev=660401&view=rev
Log:
Moved date parsing code into common; replaced most tests in HttpUtil with tests for remaining pieces.


Added:
    incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/util/DateUtil.java
    incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/DateUtilTest.java
Modified:
    incubator/shindig/trunk/java/common/pom.xml
    incubator/shindig/trunk/java/gadgets/pom.xml
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/AbstractHttpCache.java
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpResponse.java
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/HttpUtil.java
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/ProxyHandler.java
    incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicHttpCacheTest.java
    incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/HttpUtilTest.java

Modified: incubator/shindig/trunk/java/common/pom.xml
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/pom.xml?rev=660401&r1=660400&r2=660401&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/pom.xml (original)
+++ incubator/shindig/trunk/java/common/pom.xml Mon May 26 23:27:02 2008
@@ -57,5 +57,13 @@
       <groupId>org.hamcrest</groupId>
       <artifactId>hamcrest-all</artifactId>
     </dependency>
+		<dependency>
+      <groupId>commons-codec</groupId>
+      <artifactId>commons-codec</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>joda-time</groupId>
+      <artifactId>joda-time</artifactId>
+    </dependency>
   </dependencies>
 </project>

Added: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/util/DateUtil.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/util/DateUtil.java?rev=660401&view=auto
==============================================================================
--- incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/util/DateUtil.java (added)
+++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/util/DateUtil.java Mon May 26 23:27:02 2008
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shindig.common.util;
+
+import org.joda.time.DateTimeZone;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+
+import java.util.Date;
+import java.util.Locale;
+
+/**
+ * Date parsing and writing utilities.
+ */
+public class DateUtil {
+
+  private static DateTimeFormatter rfc1123DateFormat = DateTimeFormat
+      .forPattern("EEE, dd MMM yyyy HH:mm:ss 'GMT'")
+      .withLocale(Locale.US)
+      .withZone(DateTimeZone.UTC);
+
+  private DateUtil() {}
+
+  /**
+   * Parses an RFC1123 format date.  Returns null if the date fails to parse for
+   * any reason.
+   *
+   * @param dateStr
+   * @return the date
+   */
+  public static Date parseDate(String dateStr) {
+    try {
+      return rfc1123DateFormat.parseDateTime(dateStr).toDate();
+    } catch (Exception e) {
+      // Don't care.
+      return null;
+    }
+  }
+
+  /**
+   * Formats an RFC 1123 format date.
+   */
+  public static String formatDate(Date date) {
+    return formatDate(date.getTime());
+  }
+
+  /**
+   * Formats an RFC 1123 format date.
+   */
+  public static String formatDate(long timeStamp) {
+    return rfc1123DateFormat.print(timeStamp);
+  }
+}

Added: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/DateUtilTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/DateUtilTest.java?rev=660401&view=auto
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/DateUtilTest.java (added)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/DateUtilTest.java Mon May 26 23:27:02 2008
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shindig.common.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+
+import java.util.Date;
+import java.util.Locale;
+
+public class DateUtilTest {
+
+  String[] text = new String[] {
+    "Tue, 27 May 2008 05:12:50 GMT",
+    "Wed, 28 May 2008 04:40:48 GMT",
+    "Mon, 30 Jun 3090 03:29:55 GMT",
+    "Fri, 06 Jun 1670 01:57:27 GMT",
+  };
+
+  Date[] timeStamps = new Date[] {
+    new Date(1211865170000L),
+    new Date(1211949648000L),
+    new Date(35359385395000L),
+    new Date(-9453535353000L),
+  };
+
+  @Test
+  public void parse() {
+    for (int i = 0, j = text.length; i < j; ++i) {
+      assertEquals(timeStamps[i].getTime(), DateUtil.parseDate(text[i]).getTime());
+    }
+  }
+
+  @Test
+  public void format() {
+    for (int i = 0, j = timeStamps.length; i < j; ++i) {
+      assertEquals(text[i], DateUtil.formatDate(timeStamps[i].getTime()));
+    }
+  }
+
+  @Test
+  public void formatDate() {
+    for (int i = 0, j = timeStamps.length; i < j; ++i) {
+      assertEquals(text[i], DateUtil.formatDate(timeStamps[i]));
+    }
+  }
+
+  @Test
+  public void parseMalformed() {
+    assertNull(DateUtil.parseDate("Invalid date format"));
+  }
+
+  @Test
+  public void parseWrongTimeZone() {
+    String expires = "Mon, 12 May 2008 09:23:29 PDT";
+    assertNull(DateUtil.parseDate(expires));
+  }
+
+  @Test
+  public void parseRfc1036() {
+    // We don't support this, though RFC 2616 suggests we should
+    String expires = "Sunday, 06-Nov-94 08:49:37 GMT";
+    assertNull(DateUtil.parseDate(expires));
+  }
+
+  @Test
+  public void parseAsctime() {
+    // We don't support this, though RFC 2616 suggests we should
+    String expires = "Sun Nov  6 08:49:37 1994";
+    assertNull(DateUtil.parseDate(expires));
+  }
+
+  @Test
+  public void formatInWrongLocale() {
+    Locale orig = Locale.getDefault();
+    try {
+      Locale.setDefault(Locale.ITALY);
+      formatDate();
+    } finally {
+      Locale.setDefault(orig);
+    }
+  }
+}

Modified: incubator/shindig/trunk/java/gadgets/pom.xml
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/pom.xml?rev=660401&r1=660400&r2=660401&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/pom.xml (original)
+++ incubator/shindig/trunk/java/gadgets/pom.xml Mon May 26 23:27:02 2008
@@ -144,13 +144,5 @@
       <artifactId>commons-lang</artifactId>
       <scope>compile</scope>
     </dependency>
-    <dependency>
-      <groupId>commons-codec</groupId>
-      <artifactId>commons-codec</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>joda-time</groupId>
-      <artifactId>joda-time</artifactId>
-    </dependency>
   </dependencies>
 </project>

Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/AbstractHttpCache.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/AbstractHttpCache.java?rev=660401&r1=660400&r2=660401&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/AbstractHttpCache.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/AbstractHttpCache.java Mon May 26 23:27:02 2008
@@ -17,7 +17,7 @@
  */
 package org.apache.shindig.gadgets.http;
 
-import org.apache.shindig.gadgets.servlet.HttpUtil;
+import org.apache.shindig.common.util.DateUtil;
 
 import java.net.URI;
 import java.util.Arrays;
@@ -110,7 +110,7 @@
 
     String expires = response.getHeader("Expires");
     if (expires != null) {
-      Date expiresDate = HttpUtil.parseDate(expires);
+      Date expiresDate = DateUtil.parseDate(expires);
       if (expiresDate == null) {
         // parse problem
         return null;
@@ -143,7 +143,7 @@
               long maxAgeMs = Long.parseLong(parts[1]) * 1000;
               Date newExpiry = new Date(now + maxAgeMs);
               response.getAllHeaders()
-                  .put("Expires", Arrays.asList(HttpUtil.formatDate(newExpiry)));
+                  .put("Expires", Arrays.asList(DateUtil.formatDate(newExpiry)));
               return response;
             } catch (NumberFormatException e) {
               return null;
@@ -167,7 +167,7 @@
     // if no other directives exist
     Date newExpiry = new Date(now + getDefaultTTL());
     response.getAllHeaders()
-        .put("Expires", Arrays.asList(HttpUtil.formatDate(newExpiry)));
+        .put("Expires", Arrays.asList(DateUtil.formatDate(newExpiry)));
     return response;
   }
 

Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpResponse.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpResponse.java?rev=660401&r1=660400&r2=660401&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpResponse.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/HttpResponse.java Mon May 26 23:27:02 2008
@@ -17,7 +17,7 @@
  */
 package org.apache.shindig.gadgets.http;
 
-import org.apache.shindig.gadgets.servlet.HttpUtil;
+import org.apache.shindig.common.util.DateUtil;
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
@@ -176,7 +176,7 @@
       // Strip BOM if present
       if (responseString.length() > 0 && responseString.codePointAt(0) == 0xFEFF) {
         responseString = responseString.substring(1);
-      } 
+      }
     }
     return responseString;
   }
@@ -264,7 +264,7 @@
   public long getExpiration() {
     String expires = getHeader("Expires");
     if (expires != null) {
-      Date expiresDate = HttpUtil.parseDate(expires);
+      Date expiresDate = DateUtil.parseDate(expires);
       if (expiresDate != null) {
         return expiresDate.getTime();
       }

Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/HttpUtil.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/HttpUtil.java?rev=660401&r1=660400&r2=660401&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/HttpUtil.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/HttpUtil.java Mon May 26 23:27:02 2008
@@ -23,19 +23,11 @@
 import org.apache.shindig.gadgets.GadgetContext;
 import org.apache.shindig.gadgets.spec.GadgetSpec;
 import org.apache.shindig.gadgets.spec.View;
-import org.joda.time.DateTimeZone;
-import org.joda.time.format.DateTimeFormat;
-import org.joda.time.format.DateTimeFormatter;
+
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 
-import java.util.Arrays;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
 import java.util.Set;
 
 import javax.servlet.http.HttpServletResponse;
@@ -48,11 +40,6 @@
   // 1 year.
   private static final int DEFAULT_TTL = 60 * 60 * 24 * 365;
 
-  private static DateTimeFormatter httpDateFormatter = DateTimeFormat
-      .forPattern("EEE, dd MMM yyyy HH:mm:ss 'GMT'")
-      .withLocale(Locale.US)
-      .withZone(DateTimeZone.UTC);
-
   /**
    * Sets default caching Headers (Expires, Cache-Control, Last-Modified)
    *
@@ -88,98 +75,6 @@
   }
 
   /**
-   * Parses an HTTP date.  Returns null if the date fails to parse for any
-   * reason.
-   *
-   * @param dateStr
-   * @return the date
-   */
-  public static Date parseDate(String dateStr) {
-    try {
-      return httpDateFormatter.parseDateTime(dateStr).toDate();
-    } catch (Exception e) {
-      // Don't care.
-      return null;
-    }
-  }
-
-  /**
-   * Formats a date for use in HTTP headers.
-   *
-   * @param date
-   * @return HTTP date string.
-   */
-  public static String formatDate(Date date) {
-    return httpDateFormatter.print(date.getTime());
-  }
-
-
-  /**
-   * Takes a set of recevied HTTP headers and adjusts them to enforce
-   * a desired cache lifetime
-   */
-  public static Map<String, List<String>> enforceCachePolicy(
-      Map<String, List<String>> originalHeaders,
-      long age,
-      boolean ignoreOriginalCacheControl) {
-
-    Map<String, List<String>> newHeaders = new HashMap<String, List<String>>(
-        originalHeaders);
-
-    long originalAge = 0L;
-    if (newHeaders.containsKey("Expires")) {
-      Date date = parseDate(originalHeaders.get("Expires").get(0));
-      if (date != null) {
-        originalAge = date.getTime() - System.currentTimeMillis();
-      }
-    }
-
-    if (newHeaders.containsKey("Cache-Control")) {
-      try {
-        String cacheControl = originalHeaders.get("Cache-Control").get(0);
-        if (cacheControl != null) {
-          String[] directives = cacheControl.split(",");
-          for (String directive : directives) {
-            directive = directive.trim();
-            // boolean params
-            if (directive.equals("no-cache") || directive.equals("no-store")) {
-              // Always respect no-cache or no-store no matter what
-              return newHeaders;
-            }
-            if (directive.startsWith("max-age")) {
-              String[] parts = directive.split("=");
-              if (parts.length == 2) {
-                // Record the max-age and store it in the content as an
-                // absolute expiration
-                originalAge = Long.parseLong(parts[1]) * 1000;
-              }
-            }
-          }
-        }
-      } catch (Exception e) {
-        // Dont care
-      }
-    }
-
-    if (!ignoreOriginalCacheControl && age < originalAge) {
-      age = originalAge;
-    }
-
-    // Strip the original
-    newHeaders.remove("Expires");
-    newHeaders.remove("Cache-Control");
-
-    // Replace with new consistent headers
-    newHeaders.put("Expires", Arrays.asList(
-        formatDate(new Date(age + System.currentTimeMillis()))));
-
-    newHeaders.put("Cache-Control",
-        Arrays.asList("public, max-age=" + (age / 1000L)));
-
-    return newHeaders;
-  }
-
-  /**
    * Fetches js configuration for the given feature set & container
    * @param config
    * @param context

Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/ProxyHandler.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/ProxyHandler.java?rev=660401&r1=660400&r2=660401&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/ProxyHandler.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/ProxyHandler.java Mon May 26 23:27:02 2008
@@ -314,30 +314,14 @@
     HttpRequest rcr = buildHttpRequest(request);
     HttpResponse results = contentFetcherFactory.get().fetch(rcr);
 
-    // Default interval of 1 hour
-    int refreshInterval = 60 * 60;
+    // Caching headers
+    int refreshInterval = 0;
     if (request.getParameter(REFRESH_PARAM) != null) {
       refreshInterval =  Integer.valueOf(request.getParameter(REFRESH_PARAM));
     }
+    HttpUtil.setCachingHeaders(response, refreshInterval);
 
-    int status = results.getHttpStatusCode();
-    response.setStatus(status);
-    if (status == HttpServletResponse.SC_OK) {
-      Map<String, List<String>> headers = HttpUtil.enforceCachePolicy(
-          results.getAllHeaders(), refreshInterval * 1000L, false);
-      for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
-        String name = entry.getKey();
-        List<String> values = entry.getValue();
-        if (name != null && values != null
-            && !DISALLOWED_RESPONSE_HEADERS.contains(name.toLowerCase())) {
-          for (String value : values) {
-            response.addHeader(name, value);
-          }
-        }
-      }
-      response.getOutputStream().write(
-          IOUtils.toByteArray(results.getResponse()));
-    }
+    response.getOutputStream().write(IOUtils.toByteArray(results.getResponse()));
   }
 
   /**

Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicHttpCacheTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicHttpCacheTest.java?rev=660401&r1=660400&r2=660401&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicHttpCacheTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicHttpCacheTest.java Mon May 26 23:27:02 2008
@@ -17,7 +17,7 @@
  */
 package org.apache.shindig.gadgets.http;
 
-import org.apache.shindig.gadgets.servlet.HttpUtil;
+import org.apache.shindig.common.util.DateUtil;
 
 import junit.framework.TestCase;
 
@@ -66,7 +66,7 @@
 
   private HttpResponse createExpiresResponse(int statusCode, long expiration) {
     Date newExpiry = new Date(expiration);
-    return createResponse(statusCode, "Expires", HttpUtil.formatDate(newExpiry));
+    return createResponse(statusCode, "Expires", DateUtil.formatDate(newExpiry));
   }
 
   private HttpResponse createMaxAgeResponse(int statusCode, long age) {

Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/HttpUtilTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/HttpUtilTest.java?rev=660401&r1=660400&r2=660401&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/HttpUtilTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/HttpUtilTest.java Mon May 26 23:27:02 2008
@@ -18,55 +18,78 @@
  */
 package org.apache.shindig.gadgets.servlet;
 
-import junit.framework.TestCase;
-
-import java.util.Date;
-import java.util.Locale;
-
-public class HttpUtilTest extends TestCase {
-
-  public void testFormatInWrongLocale() {
-    Locale orig = Locale.getDefault();
-    try {
-      Locale.setDefault(Locale.ITALY);
-      testFormatDate();
-    } finally {
-      Locale.setDefault(orig);
+import static org.easymock.EasyMock.anyLong;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.classextension.EasyMock.createNiceMock;
+import static org.easymock.classextension.EasyMock.replay;
+import static org.easymock.classextension.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import org.apache.shindig.gadgets.ContainerConfig;
+import org.apache.shindig.gadgets.GadgetContext;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.junit.Test;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.servlet.http.HttpServletResponse;
+
+public class HttpUtilTest {
+
+  @Test
+  public void setCachingHeaders() {
+    HttpServletResponse response = createNiceMock(HttpServletResponse.class);
+    int ttl = 10;
+    response.setDateHeader(eq("Expires"), anyLong());
+    response.setHeader("Cache-Control", "public,max-age=" + ttl);
+    response.setDateHeader(eq("Last-Modified"), anyLong());
+    replay(response);
+    HttpUtil.setCachingHeaders(response, ttl);
+    verify(response);
+  }
+
+  private void assertJsonEquals(JSONObject lhs, JSONObject rhs) throws JSONException {
+    for (String key : JSONObject.getNames(lhs)) {
+      Object obj = lhs.get(key);
+      if (obj instanceof String) {
+        assertEquals(obj, rhs.get(key));
+      } else if (obj instanceof JSONObject) {
+        assertJsonEquals((JSONObject)obj, rhs.getJSONObject(key));
+      } else {
+        fail("Unsupported type: " + obj.getClass());
+      }
     }
   }
 
-  public void testParseDate_rfc1123() {
-    String expires = "Sun, 06 Nov 1994 08:49:37 GMT";
-    Date date = HttpUtil.parseDate(expires);
-    assertEquals(784111777000L, date.getTime());
-
-    date = HttpUtil.parseDate("Mon, 12 May 2008 17:00:18 GMT");
-    assertEquals(1210611618000L, date.getTime());
-  }
-
-  public void testParseDate_wrongTimeZone() {
-    String expires = "Mon, 12 May 2008 09:23:29 PDT";
-    assertNull(HttpUtil.parseDate(expires));
-  }
-
-  public void testParseDate_rfc1036() {
-    // We don't support this, though RFC 2616 suggests we should
-    String expires = "Sunday, 06-Nov-94 08:49:37 GMT";
-    assertNull(HttpUtil.parseDate(expires));
-  }
+  @Test
+  public void getJsConfig() throws JSONException {
+    String feature0 = "featureZero";
+    String feature1 = "featureOne";
+
+    JSONObject features = new JSONObject()
+        .put(feature0, "config")
+        .put(feature1, "other config");
+
+    String container = "container";
+
+    ContainerConfig config = createNiceMock(ContainerConfig.class);
+    GadgetContext context = createNiceMock(GadgetContext.class);
+    Set<String> needed = new HashSet<String>();
+    needed.add(feature0);
+    needed.add(feature1);
+
+    expect(context.getContainer()).andReturn(container);
+    expect(config.getJsonObject(container, "gadgets.features"))
+        .andReturn(features);
 
-  public void testParseDate_asctime() {
-    // We don't support this, though RFC 2616 suggests we should
-    String expires = "Sun Nov  6 08:49:37 1994";
-    assertNull(HttpUtil.parseDate(expires));
-  }
-
-  public void testFormatDate() {
-    Date date = new Date(784111777000L);
-    assertEquals("Sun, 06 Nov 1994 08:49:37 GMT", HttpUtil.formatDate(date));
+    replay(context);
+    replay(config);
 
-    date = new Date(1210611618000L);
-    assertEquals("Mon, 12 May 2008 17:00:18 GMT", HttpUtil.formatDate(date));
+    assertJsonEquals(features, HttpUtil.getJsConfig(config, context, needed));
   }
-
 }