Hi all - wanted to know if we have an official guideline on when to create a
JIRA issue vs. just committing a change.

My instinct is that you should open a JIRA issue for changes that have a
significant design portion or that affect APIs that are exposed by a
library, and to commit when you are making minor changes or refactorings.

For discussion purposes, I've attached a patch that I would think is well
below the JIRA threshhold.

Evan
### Eclipse Workspace Patch 1.0
#P Shindig5
Index: java/common/src/main/java/org/apache/shindig/common/testing/FakeGadgetToken.java
===================================================================
--- java/common/src/main/java/org/apache/shindig/common/testing/FakeGadgetToken.java	(revision 671378)
+++ java/common/src/main/java/org/apache/shindig/common/testing/FakeGadgetToken.java	(working copy)
@@ -18,43 +18,82 @@
  */
 package org.apache.shindig.common.testing;
 
+import com.google.common.collect.Maps;
+
 import org.apache.shindig.common.SecurityToken;
+import org.apache.shindig.common.SecurityTokenDecoder;
+
+import java.util.Map;
 
 /**
  * A fake SecurityToken implementation to help testing.
  */
 public class FakeGadgetToken implements SecurityToken {
 
-  private String updatedToken;
-  private String trustedJson;
+  private String updatedToken = null;
+  private String trustedJson = null;
+  
+  private String ownerId = null;
+  private String viewerId = null;
+  private String appId = null;
+  private String domain = null;
+  private String appUrl = null;
+  private int moduleId = 0;
+
+  public FakeGadgetToken setUpdatedToken(String updatedToken) {
+    this.updatedToken = updatedToken;
+    return this;
+  }
+
+  public FakeGadgetToken setTrustedJson(String trustedJson) {
+    this.trustedJson = trustedJson;
+    return this;
+  }
 
-  public FakeGadgetToken() {
-    this(null, null);
+  public FakeGadgetToken setOwnerId(String ownerId) {
+    this.ownerId = ownerId;
+    return this;
   }
 
-  public FakeGadgetToken(String updatedToken) {
-    this(updatedToken, null);
+  public FakeGadgetToken setViewerId(String viewerId) {
+    this.viewerId = viewerId;
+    return this;
   }
 
-  public FakeGadgetToken(String updatedToken, String trustedJson) {
-    this.updatedToken = updatedToken;
-    this.trustedJson = trustedJson;
+  public FakeGadgetToken setAppId(String appId) {
+    this.appId = appId;
+    return this;
+  }
+
+  public FakeGadgetToken setDomain(String domain) {
+    this.domain = domain;
+    return this;
+  }
+
+  public FakeGadgetToken setAppUrl(String appUrl) {
+    this.appUrl = appUrl;
+    return this;
+  }
+
+  public FakeGadgetToken setModuleId(int moduleId) {
+    this.moduleId = moduleId;
+    return this;
   }
 
   public String getOwnerId() {
-    return "owner";
+    return ownerId;
   }
 
   public String getViewerId() {
-    return "viewer";
+    return viewerId;
   }
 
   public String getAppId() {
-    return "app1234";
+    return appId;
   }
 
   public String getDomain() {
-    return "domain";
+    return domain;
   }
 
   public String toSerialForm() {
@@ -62,11 +101,11 @@
   }
 
   public String getAppUrl() {
-    return "http://www.example.com/app.xml";;
+    return appUrl;
   }
 
   public long getModuleId() {
-    return 0;
+    return moduleId;
   }
 
   public String getUpdatedToken() {
@@ -76,4 +115,65 @@
   public String getTrustedJson() {
     return trustedJson;
   }
+  
+  /**
+   * Create a fake security token parameter string, allows passing around a 
+   * security token of format key=value&key2=value2, where key is one of:
+   * ownerId, viewerId, domain, appUrl, appId, trustedJson, module.
+   * 
+   * Useful for creating tokens that can be decoded with FakeGadgetToken.Decoder
+   * 
+   * @param tokenString the parameter string
+   * @return The fake token
+   */
+  public static SecurityToken createToken(String tokenString)  {
+    String keyValuePairs[] = tokenString.split("&");
+    Map<String, String> paramMap = Maps.newHashMap();
+    
+    for (String keyValuePair : keyValuePairs) {
+      String[] keyAndValue = keyValuePair.split("=");
+      if (keyAndValue.length == 2) {
+        paramMap.put(keyAndValue[0], keyAndValue[1]);
+      }
+    }
+    
+    return createToken(paramMap);
+  }
+  
+  /**
+   * Create a fake security token from a map of parameter strings, keys are one of:
+   * ownerId, viewerId, domain, appUrl, appId, trustedJson, module
+   * 
+   * @param paramMap
+   * @return The fake token
+   */
+  public static SecurityToken createToken(Map<String, String> paramMap) {
+    FakeGadgetToken fakeToken = new FakeGadgetToken();
+    
+    fakeToken.setAppId(paramMap.get("appId"));
+    fakeToken.setAppUrl(paramMap.get("appUrl"));
+    fakeToken.setDomain(paramMap.get("domain"));
+    fakeToken.setOwnerId(paramMap.get("ownerId"));
+    fakeToken.setTrustedJson(paramMap.get("trustedJson"));
+    fakeToken.setViewerId(paramMap.get("viewerId"));
+    
+    String moduleIdStr = paramMap.get("module");
+    if (moduleIdStr != null) {
+      fakeToken.setModuleId(Integer.parseInt(moduleIdStr));
+    }
+    
+    return fakeToken;
+  }
+  
+  /**
+   * SecurityTokenDecoder for testing - this allows passing around a 
+   * security token of format key=value&key2=value2, where key is one of:
+   * ownerId, viewerId, domain, appUrl, appId, trustedJson, module
+   */
+  public static class Decoder implements SecurityTokenDecoder {
+    public SecurityToken createToken(String tokenString)  {
+      return FakeGadgetToken.createToken(tokenString);
+    }
+  }
+  
 }
Index: java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/GadgetRenderingTaskTest.java
===================================================================
--- java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/GadgetRenderingTaskTest.java	(revision 671378)
+++ java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/GadgetRenderingTaskTest.java	(working copy)
@@ -210,7 +210,8 @@
   public void testAuthTokenInjection_allparams() throws Exception {
     expect(fixture.request.getParameter("st")).andReturn("fake-token");
     expect(securityTokenDecoder.createToken("fake-token")).andReturn(
-        new FakeGadgetToken("updated-token", "{ \"foo\" : \"bar\" }"));
+        new FakeGadgetToken().setUpdatedToken("updated-token")
+        .setTrustedJson("{ \"foo\" : \"bar\" }"));
     String content = parseBasicGadget(GadgetSpec.DEFAULT_VIEW);
     JSONObject auth = parseShindigAuthConfig(content);
     assertEquals("updated-token", auth.getString("authToken"));
@@ -229,7 +230,7 @@
   public void testAuthTokenInjection_trustedJson() throws Exception {
     expect(fixture.request.getParameter("st")).andReturn("fake-token");
     expect(securityTokenDecoder.createToken("fake-token")).andReturn(
-        new FakeGadgetToken(null, "trusted"));
+        new FakeGadgetToken().setTrustedJson("trusted"));
     String content = parseBasicGadget(GadgetSpec.DEFAULT_VIEW);
     JSONObject auth = parseShindigAuthConfig(content);
     assertEquals(1, auth.length());
@@ -239,7 +240,7 @@
   public void testAuthTokenInjection_updatedToken() throws Exception {
     expect(fixture.request.getParameter("st")).andReturn("fake-token");
     expect(securityTokenDecoder.createToken("fake-token")).andReturn(
-        new FakeGadgetToken("updated-token", null));
+        new FakeGadgetToken().setUpdatedToken("updated-token"));
     String content = parseBasicGadget(GadgetSpec.DEFAULT_VIEW);
     JSONObject auth = parseShindigAuthConfig(content);
     assertEquals(1, auth.length());
Index: java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/MakeRequestHandlerTest.java
===================================================================
--- java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/MakeRequestHandlerTest.java	(revision 671378)
+++ java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/MakeRequestHandlerTest.java	(working copy)
@@ -287,7 +287,7 @@
     // Doesn't actually sign since it returns the standard fetcher.
     // Signing tests are in SigningFetcherTest
     expectGetAndReturnBody(fixture.signingFetcher, RESPONSE_BODY);
-    FakeGadgetToken authToken = new FakeGadgetToken("updated");
+    FakeGadgetToken authToken = new FakeGadgetToken().setUpdatedToken("updated");
     expect(fixture.securityTokenDecoder.createToken("fake-token")).andReturn(authToken);
     expect(fixture.request.getParameter(MakeRequestHandler.SECURITY_TOKEN_PARAM))
         .andReturn("fake-token").atLeastOnce();
@@ -307,7 +307,7 @@
     // Doesn't actually do oauth dance since it returns the standard fetcher.
     // OAuth tests are in OAuthFetcherTest
     expectGetAndReturnBody(fixture.oauthFetcher, RESPONSE_BODY);
-    FakeGadgetToken authToken = new FakeGadgetToken("updated");
+    FakeGadgetToken authToken = new FakeGadgetToken().setUpdatedToken("updated");
     expect(fixture.securityTokenDecoder.createToken("fake-token")).andReturn(authToken);
     expect(fixture.request.getParameter(MakeRequestHandler.SECURITY_TOKEN_PARAM))
         .andReturn("fake-token").atLeastOnce();
Index: java/social-api/src/test/java/org/apache/shindig/social/dataservice/UserIdTest.java
===================================================================
--- java/social-api/src/test/java/org/apache/shindig/social/dataservice/UserIdTest.java	(revision 671378)
+++ java/social-api/src/test/java/org/apache/shindig/social/dataservice/UserIdTest.java	(working copy)
@@ -25,10 +25,10 @@
 
   public void testGetUserId() throws Exception {
     UserId owner = new UserId(UserId.Type.owner, "hello");
-    assertEquals("owner", owner.getUserId(new FakeGadgetToken()));
+    assertEquals("owner", owner.getUserId(new FakeGadgetToken().setOwnerId("owner")));
 
     UserId viewer = new UserId(UserId.Type.viewer, "hello");
-    assertEquals("viewer", viewer.getUserId(new FakeGadgetToken()));
+    assertEquals("viewer", viewer.getUserId(new FakeGadgetToken().setViewerId("viewer")));
 
     UserId user = new UserId(UserId.Type.userId, "hello");
     assertEquals("hello", user.getUserId(new FakeGadgetToken()));

Reply via email to