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/08/31 03:23:03 UTC

svn commit: r690625 - in /incubator/shindig/trunk/java/gadgets/src: main/java/org/apache/shindig/gadgets/ main/java/org/apache/shindig/gadgets/servlet/ test/java/org/apache/shindig/gadgets/servlet/

Author: etnu
Date: Sat Aug 30 18:23:03 2008
New Revision: 690625

URL: http://svn.apache.org/viewvc?rev=690625&view=rev
Log:
Added generic parameter extraction for GadgetContext. This is done to allow GadgetContexts to propagate servlet request information deep into the call stack so that rewriters, preloaders, and other facilities can be built in a more flexible way.


Modified:
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetContext.java
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/GadgetRenderingTask.java
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/HttpGadgetContext.java
    incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/JsonRpcGadgetContext.java
    incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/HttpGadgetContextTest.java
    incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/JsonRpcGadgetContextTest.java

Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetContext.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetContext.java?rev=690625&r1=690624&r2=690625&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetContext.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetContext.java Sat Aug 30 18:23:03 2008
@@ -29,6 +29,15 @@
  * data.
  */
 public class GadgetContext {
+
+  /**
+   * @param name The parameter to get data for.
+   * @return The parameter set under the given name, or null.
+   */
+  public String getParameter(String name) {
+    return null;
+  }
+
   /**
    * @return The url for this gadget.
    */

Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/GadgetRenderingTask.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/GadgetRenderingTask.java?rev=690625&r1=690624&r2=690625&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/GadgetRenderingTask.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/GadgetRenderingTask.java Sat Aug 30 18:23:03 2008
@@ -72,7 +72,6 @@
 public class GadgetRenderingTask {
 
   protected static final int DEFAULT_CACHE_TTL = 60 * 5;
-
   protected static final String CAJA_PARAM = "caja";
 
   protected static final String LIBS_PARAM_NAME = "libs";

Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/HttpGadgetContext.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/HttpGadgetContext.java?rev=690625&r1=690624&r2=690625&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/HttpGadgetContext.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/HttpGadgetContext.java Sat Aug 30 18:23:03 2008
@@ -41,84 +41,84 @@
  * Implements GadgetContext using an HttpServletRequest
  */
 public class HttpGadgetContext extends GadgetContext {
-
   public static final String USERPREF_PARAM_PREFIX = "up_";
 
+  private final HttpServletRequest request;
+  private final SecurityTokenDecoder tokenDecoder;
+
+  private final String container;
+  private final Boolean debug;
+  private final Boolean ignoreCache;
+  private final Locale locale;
+  private final Integer moduleId;
+  private final RenderingContext renderingContext;
+  private final String tokenString;
   private final URI url;
+  private final UserPrefs userPrefs;
+  private final String view;
+
+  public HttpGadgetContext(HttpServletRequest request, SecurityTokenDecoder tokenDecoder) {
+    this.request = request;
+    this.tokenDecoder = tokenDecoder;
+
+    container = getContainer(request);
+    debug = getDebug(request);
+    ignoreCache = getIgnoreCache(request);
+    locale = getLocale(request);
+    moduleId = getModuleId(request);
+    renderingContext = getRenderingContext(request);
+    // TODO: This shouldn't be depending on MakeRequest at all.
+    tokenString = request.getParameter(MakeRequestHandler.SECURITY_TOKEN_PARAM);
+    url = getUrl(request);
+    userPrefs = getUserPrefs(request);
+    view = getView(request);
+  }
+
   @Override
-  public URI getUrl() {
-    if (url == null) {
-      return super.getUrl();
-    }
-    return url;
+  public String getParameter(String name) {
+    return request.getParameter(name);
   }
 
-  private final Integer moduleId;
   @Override
-  public int getModuleId() {
-    if (moduleId == null) {
-      return super.getModuleId();
+  public String getContainer() {
+    if (container == null) {
+      return super.getContainer();
     }
-    return moduleId;
+    return container;
   }
 
-
-  private final Locale locale;
   @Override
-  public Locale getLocale() {
-    if (locale == null) {
-      return super.getLocale();
+  public boolean getDebug() {
+    if (debug == null) {
+      return super.getDebug();
     }
-    return locale;
+    return debug;
   }
 
-  /**
-   * @param req
-   * @return The ignore cache setting, if appropriate params are set, or null.
-   */
-  private static URI getUrl(HttpServletRequest req) {
-    String url = req.getParameter("url");
-    if (url == null) {
-      return null;
-    }
-    try {
-      return new URI(url);
-    } catch (URISyntaxException e) {
-      return null;
+  @Override
+  public boolean getIgnoreCache() {
+    if (ignoreCache == null) {
+      return super.getIgnoreCache();
     }
+    return ignoreCache;
   }
 
-  /**
-   * @param req
-   * @return module id, if specified
-   */
-  private static Integer getModuleId(HttpServletRequest req) {
-    String mid = req.getParameter("mid");
-    if (mid == null) {
-      return null;
+  @Override
+  public Locale getLocale() {
+    if (locale == null) {
+      return super.getLocale();
     }
-    return Integer.parseInt(mid);
+    return locale;
   }
 
-
-  /**
-   * @param req
-   * @return The locale, if appropriate parameters are set, or null.
-   */
-  private static Locale getLocale(HttpServletRequest req) {
-    String language = req.getParameter("lang");
-    String country = req.getParameter("country");
-    if (language == null && country == null) {
-      return null;
-    } else if (language == null) {
-      language = "all";
-    } else if (country == null) {
-      country = "ALL";
+  @Override
+  public int getModuleId() {
+    if (moduleId == null) {
+      return super.getModuleId();
     }
-    return new Locale(language, country);
+    return moduleId;
   }
 
-  private final RenderingContext renderingContext;
   @Override
   public RenderingContext getRenderingContext() {
     if (renderingContext == null) {
@@ -127,48 +127,44 @@
     return renderingContext;
   }
 
-  /**
-   * @param req
-   * @return The rendering context, if appropriate params are set, or null.
-   */
-  private static RenderingContext getRenderingContext(HttpServletRequest req) {
-    String c = req.getParameter("c");
-    if (c == null) {
-      return null;
+  @Override
+  public SecurityToken getToken() throws GadgetException {
+    if (tokenString == null || tokenString.length() == 0) {
+      return super.getToken();
+    } else {
+      try {
+        Map<String, String> tokenMap
+            = Collections.singletonMap(SecurityTokenDecoder.SECURITY_TOKEN_NAME, tokenString);
+        return tokenDecoder.createToken(tokenMap);
+      } catch (SecurityTokenException e) {
+        throw new GadgetException(
+            GadgetException.Code.INVALID_SECURITY_TOKEN, e);
+      }
     }
-    return c.equals("1") ? RenderingContext.CONTAINER : RenderingContext.GADGET;
   }
 
-  private final Boolean ignoreCache;
   @Override
-  public boolean getIgnoreCache() {
-    if (ignoreCache == null) {
-      return super.getIgnoreCache();
+  public URI getUrl() {
+    if (url == null) {
+      return super.getUrl();
     }
-    return ignoreCache;
+    return url;
   }
 
-  /**
-   * @param req
-   * @return The ignore cache setting, if appropriate params are set, or null.
-   */
-  private static Boolean getIgnoreCache(HttpServletRequest req) {
-    String ignoreCache = req.getParameter("nocache");
-    if (ignoreCache == null) {
-      return null;
-    } else if ("0".equals(ignoreCache)) {
-      return Boolean.FALSE;
+  @Override
+  public UserPrefs getUserPrefs() {
+    if (userPrefs == null) {
+      return super.getUserPrefs();
     }
-    return Boolean.TRUE;
+    return userPrefs;
   }
 
-  private final String container;
   @Override
-  public String getContainer() {
-    if (container == null) {
-      return super.getContainer();
+  public String getView() {
+    if (view == null) {
+      return super.getView();
     }
-    return container;
+    return view;
   }
 
   /**
@@ -184,15 +180,6 @@
     return container;
   }
 
-  private final Boolean debug;
-  @Override
-  public boolean getDebug() {
-    if (debug == null) {
-      return super.getDebug();
-    }
-    return debug;
-  }
-
   /**
    * @param req
    * @return Debug setting, if set, or null.
@@ -207,30 +194,75 @@
     return Boolean.TRUE;
   }
 
-  private final String view;
-  @Override
-  public String getView() {
-    if (view == null) {
-      return super.getView();
+  /**
+   * @param req
+   * @return The ignore cache setting, if appropriate params are set, or null.
+   */
+  private static Boolean getIgnoreCache(HttpServletRequest req) {
+    String ignoreCache = req.getParameter("nocache");
+    if (ignoreCache == null) {
+      return null;
+    } else if ("0".equals(ignoreCache)) {
+      return Boolean.FALSE;
     }
-    return view;
+    return Boolean.TRUE;
   }
 
   /**
    * @param req
-   * @return The view, if specified, or null.
+   * @return The locale, if appropriate parameters are set, or null.
    */
-  private static String getView(HttpServletRequest req) {
-    return req.getParameter("view");
+  private static Locale getLocale(HttpServletRequest req) {
+    String language = req.getParameter("lang");
+    String country = req.getParameter("country");
+    if (language == null && country == null) {
+      return null;
+    } else if (language == null) {
+      language = "all";
+    } else if (country == null) {
+      country = "ALL";
+    }
+    return new Locale(language, country);
   }
 
-  private final UserPrefs userPrefs;
-  @Override
-  public UserPrefs getUserPrefs() {
-    if (userPrefs == null) {
-      return super.getUserPrefs();
+  /**
+   * @param req
+   * @return module id, if specified
+   */
+  private static Integer getModuleId(HttpServletRequest req) {
+    String mid = req.getParameter("mid");
+    if (mid == null) {
+      return null;
+    }
+    return Integer.parseInt(mid);
+  }
+
+  /**
+   * @param req
+   * @return The rendering context, if appropriate params are set, or null.
+   */
+  private static RenderingContext getRenderingContext(HttpServletRequest req) {
+    String c = req.getParameter("c");
+    if (c == null) {
+      return null;
+    }
+    return c.equals("1") ? RenderingContext.CONTAINER : RenderingContext.GADGET;
+  }
+
+  /**
+   * @param req
+   * @return The ignore cache setting, if appropriate params are set, or null.
+   */
+  private static URI getUrl(HttpServletRequest req) {
+    String url = req.getParameter("url");
+    if (url == null) {
+      return null;
+    }
+    try {
+      return new URI(url);
+    } catch (URISyntaxException e) {
+      return null;
     }
-    return userPrefs;
   }
 
   /**
@@ -254,35 +286,11 @@
     return new UserPrefs(prefs);
   }
 
-  private final String tokenString;
-  private final SecurityTokenDecoder tokenDecoder;
-  @Override
-  public SecurityToken getToken() throws GadgetException {
-    if (tokenString == null || tokenString.length() == 0) {
-      return super.getToken();
-    } else {
-      try {
-        return tokenDecoder.createToken(Collections.singletonMap(SecurityTokenDecoder.SECURITY_TOKEN_NAME, tokenString));
-      } catch (SecurityTokenException e) {
-        throw new GadgetException(
-            GadgetException.Code.INVALID_SECURITY_TOKEN, e);
-      }
-    }
-  }
-
-  public HttpGadgetContext(HttpServletRequest request,
-      SecurityTokenDecoder tokenDecoder) {
-    url = getUrl(request);
-    moduleId = getModuleId(request);
-    locale = getLocale(request);
-    renderingContext = getRenderingContext(request);
-    ignoreCache = getIgnoreCache(request);
-    container = getContainer(request);
-    debug = getDebug(request);
-    view = getView(request);
-    userPrefs = getUserPrefs(request);
-    // TODO: This shouldn't be depending on MakeRequest at all.
-    tokenString = request.getParameter(MakeRequestHandler.SECURITY_TOKEN_PARAM);
-    this.tokenDecoder = tokenDecoder;
+  /**
+   * @param req
+   * @return The view, if specified, or null.
+   */
+  private static String getView(HttpServletRequest req) {
+    return req.getParameter("view");
   }
 }

Modified: incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/JsonRpcGadgetContext.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/JsonRpcGadgetContext.java?rev=690625&r1=690624&r2=690625&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/JsonRpcGadgetContext.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/JsonRpcGadgetContext.java Sat Aug 30 18:23:03 2008
@@ -36,26 +36,70 @@
  * Extracts context from JSON input.
  */
 public class JsonRpcGadgetContext extends GadgetContext {
+  private final JSONObject context;
+  private final JSONObject gadget;
+
+  private final String container;
+  private final Boolean debug;
+  private final Boolean ignoreCache;
+  private final Locale locale;
+  private final Integer moduleId;
+  private final RenderingContext renderingContext;
   private final URI url;
+  private final UserPrefs userPrefs;
+  private final String view;
+
+  /**
+   * @param context Request global parameters.
+   * @param gadget Values for the gadget being rendered.
+   * @throws JSONException If parameters can't be extracted or aren't correctly formed.
+   */
+  public JsonRpcGadgetContext(JSONObject context, JSONObject gadget) throws JSONException {
+    this.context = context;
+    this.gadget = gadget;
+
+    url = getUrl(gadget);
+    moduleId = getModuleId(gadget);
+    userPrefs = getUserPrefs(gadget);
+    locale = getLocale(context);
+    view = context.optString("view");
+    ignoreCache = context.optBoolean("ignoreCache");
+    container = context.optString("container");
+    debug = context.optBoolean("debug");
+    renderingContext = RenderingContext.METADATA;
+  }
+
   @Override
-  public URI getUrl() {
-    if (url == null) {
-      return super.getUrl();
+  public String getParameter(String name) {
+    if (gadget.has(name)) {
+      return gadget.optString(name);
     }
-    return url;
+    return context.optString(name, null);
   }
 
-  private final Integer moduleId;
   @Override
-  public int getModuleId() {
-    if (moduleId == null) {
-      return super.getModuleId();
+  public String getContainer() {
+    if (container == null) {
+      return super.getContainer();
     }
-    return moduleId;
+    return container;
   }
 
+  @Override
+  public boolean getDebug() {
+    if (debug == null) {
+      return super.getDebug();
+    }
+    return debug;
+  }
+  @Override
+  public boolean getIgnoreCache() {
+    if (ignoreCache == null) {
+      return super.getIgnoreCache();
+    }
+    return ignoreCache;
+  }
 
-  private final Locale locale;
   @Override
   public Locale getLocale() {
     if (locale == null) {
@@ -63,21 +107,14 @@
     }
     return locale;
   }
-
-  /**
-   * @param obj
-   * @return The locale, if appropriate parameters are set, or null.
-   */
-  private static Locale getLocale(JSONObject obj) {
-    String language = obj.optString("language");
-    String country = obj.optString("country");
-    if (language == null || country == null) {
-      return null;
+  @Override
+  public int getModuleId() {
+    if (moduleId == null) {
+      return super.getModuleId();
     }
-    return new Locale(language, country);
+    return moduleId;
   }
 
-  private final RenderingContext renderingContext;
   @Override
   public RenderingContext getRenderingContext() {
     if (renderingContext == null) {
@@ -85,35 +122,21 @@
     }
     return renderingContext;
   }
-
-  private final Boolean ignoreCache;
-  @Override
-  public boolean getIgnoreCache() {
-    if (ignoreCache == null) {
-      return super.getIgnoreCache();
-    }
-    return ignoreCache;
-  }
-
-  private final String container;
   @Override
-  public String getContainer() {
-    if (container == null) {
-      return super.getContainer();
+  public URI getUrl() {
+    if (url == null) {
+      return super.getUrl();
     }
-    return container;
+    return url;
   }
 
-  private final Boolean debug;
   @Override
-  public boolean getDebug() {
-    if (debug == null) {
-      return super.getDebug();
+  public UserPrefs getUserPrefs() {
+    if (userPrefs == null) {
+      return super.getUserPrefs();
     }
-    return debug;
+    return userPrefs;
   }
-
-  private final String view;
   @Override
   public String getView() {
     if (view == null) {
@@ -122,33 +145,29 @@
     return view;
   }
 
-  private final UserPrefs userPrefs;
-  @Override
-  public UserPrefs getUserPrefs() {
-    if (userPrefs == null) {
-      return super.getUserPrefs();
+  /**
+   * @param obj
+   * @return The locale, if appropriate parameters are set, or null.
+   */
+  private static Locale getLocale(JSONObject obj) {
+    String language = obj.optString("language");
+    String country = obj.optString("country");
+    if (language == null || country == null) {
+      return null;
     }
-    return userPrefs;
+    return new Locale(language, country);
   }
 
   /**
    * @param json
-   * @return UserPrefs, if any are set for this request.
+   * @return module id from the request, or null if not present
    * @throws JSONException
    */
-  @SuppressWarnings("unchecked")
-  private static UserPrefs getUserPrefs(JSONObject json) throws JSONException {
-    JSONObject prefs = json.optJSONObject("prefs");
-    if (prefs == null) {
-      return null;
-    }
-    Map<String, String> p = new HashMap<String, String>();
-    Iterator i = prefs.keys();
-    while (i.hasNext()) {
-      String key = (String)i.next();
-      p.put(key, prefs.getString(key));
+  private static Integer getModuleId(JSONObject json) throws JSONException {
+    if (json.has("moduleId")) {
+      return Integer.valueOf(json.getInt("moduleId"));
     }
-    return new UserPrefs(p);
+    return null;
   }
 
   /**
@@ -168,32 +187,21 @@
 
   /**
    * @param json
-   * @return module id from the request, or null if not present
+   * @return UserPrefs, if any are set for this request.
    * @throws JSONException
    */
-  private static Integer getModuleId(JSONObject json) throws JSONException {
-    if (json.has("moduleId")) {
-      return Integer.valueOf(json.getInt("moduleId"));
+  @SuppressWarnings("unchecked")
+  private static UserPrefs getUserPrefs(JSONObject json) throws JSONException {
+    JSONObject prefs = json.optJSONObject("prefs");
+    if (prefs == null) {
+      return null;
     }
-    return null;
-  }
-
-  /**
-   * @param context
-   * @param gadget
-   * @throws JSONException
-   */
-  public JsonRpcGadgetContext(JSONObject context, JSONObject gadget)
-      throws JSONException {
-    url = getUrl(gadget);
-    moduleId = getModuleId(gadget);
-    userPrefs = getUserPrefs(gadget);
-
-    locale = getLocale(context);
-    view = context.optString("view");
-    ignoreCache = context.optBoolean("ignoreCache");
-    container = context.optString("container");
-    debug = context.optBoolean("debug");
-    renderingContext = RenderingContext.METADATA;
+    Map<String, String> p = new HashMap<String, String>();
+    Iterator i = prefs.keys();
+    while (i.hasNext()) {
+      String key = (String)i.next();
+      p.put(key, prefs.getString(key));
+    }
+    return new UserPrefs(p);
   }
 }

Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/HttpGadgetContextTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/HttpGadgetContextTest.java?rev=690625&r1=690624&r2=690625&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/HttpGadgetContextTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/HttpGadgetContextTest.java Sat Aug 30 18:23:03 2008
@@ -26,21 +26,17 @@
 
 public class HttpGadgetContextTest extends GadgetTestFixture {
   public void testIgnoreCacheParam() {
-    expect(request.getParameter("nocache")).andReturn(
-        Integer.toString(Integer.MAX_VALUE));
+    expect(request.getParameter("nocache")).andReturn(Integer.toString(Integer.MAX_VALUE));
     replay();
     GadgetContext context = new HttpGadgetContext(request, securityTokenDecoder);
-    verify();
     assertEquals(true, context.getIgnoreCache());
   }
 
   public void testLocale() {
     expect(request.getParameter("lang")).andReturn(Locale.CHINA.getLanguage());
-    expect(request.getParameter("country")).andReturn(
-        Locale.CHINA.getCountry());
+    expect(request.getParameter("country")).andReturn(Locale.CHINA.getCountry());
     replay();
     GadgetContext context = new HttpGadgetContext(request, securityTokenDecoder);
-    verify();
     assertEquals(Locale.CHINA, context.getLocale());
   }
 
@@ -48,7 +44,13 @@
     expect(request.getParameter("debug")).andReturn("1");
     replay();
     GadgetContext context = new HttpGadgetContext(request, securityTokenDecoder);
-    verify();
     assertEquals(true, context.getDebug());
   }
+
+  public void testGetParameter() {
+    expect(request.getParameter("foo")).andReturn("bar");
+    replay();
+    GadgetContext context = new HttpGadgetContext(request, securityTokenDecoder);
+    assertEquals("bar", context.getParameter("foo"));
+  }
 }
\ No newline at end of file

Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/JsonRpcGadgetContextTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/JsonRpcGadgetContextTest.java?rev=690625&r1=690624&r2=690625&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/JsonRpcGadgetContextTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/JsonRpcGadgetContextTest.java Sat Aug 30 18:23:03 2008
@@ -18,10 +18,12 @@
  */
 package org.apache.shindig.gadgets.servlet;
 
-import org.json.JSONObject;
+import org.apache.shindig.gadgets.GadgetContext;
 
 import junit.framework.TestCase;
 
+import org.json.JSONObject;
+
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
@@ -42,14 +44,15 @@
     JSONObject gadget = new JSONObject()
         .put("url", SPEC_URL)
         .put("moduleId", SPEC_ID)
-        .put("prefs", prefs);
+        .put("prefs", prefs)
+        .put("gadget-field", "gadget-value");
 
     JSONObject context = new JSONObject()
         .put("language", Locale.US.getLanguage())
-        .put("country", Locale.US.getCountry().toUpperCase());
+        .put("country", Locale.US.getCountry().toUpperCase())
+        .put("context-field", "context-value");
 
-    JsonRpcGadgetContext jsonContext
-        = new JsonRpcGadgetContext(context, gadget);
+    GadgetContext jsonContext = new JsonRpcGadgetContext(context, gadget);
     assertEquals(SPEC_URL, jsonContext.getUrl().toString());
     assertEquals(SPEC_ID, jsonContext.getModuleId());
     assertEquals(Locale.US.getLanguage(),
@@ -60,5 +63,8 @@
       String value = jsonContext.getUserPrefs().getPref(key);
       assertEquals(prefs.get(key), value);
     }
+
+    assertEquals("gadget-value", jsonContext.getParameter("gadget-field"));
+    assertEquals("context-value", jsonContext.getParameter("context-field"));
   }
 }