Author: etnu
Date: Tue Oct 21 17:39:55 2008
New Revision: 706822

URL: http://svn.apache.org/viewvc?rev=706822&view=rev
Log:
Extracted interface for ContainerConfig to allow implementations to choose 
alternative configuration mechanisms if their deployment needs them.

We should probably create more generic primitive wrappers for the JSONObject / 
JSONArray, but that would be a very disruptive change.

Since Java 1.6 has native support for javascript, I'd also like to add a 
ContainerConfig variant that allows use of full javascript, making inheritance 
easier as well as allowing for imports and expressions. Since this would be a 
sharp departure from compatibility with the PHP code, that would be a strictly 
separate binding. Maintaining compatibility with the client code is of the 
utmost importance.


Added:
    
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonContainerConfig.java
    
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/JsonContainerConfigTest.java
   (contents, props changed)
      - copied, changed from r706355, 
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/ContainerConfigTest.java
Removed:
    
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/ContainerConfigTest.java
Modified:
    
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/ContainerConfig.java
    
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/auth/BlobCrypterSecurityTokenDecoderTest.java
    
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/auth/DefaultSecurityTokenDecoderTest.java
    
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/DefaultUrlGeneratorTest.java
    
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/process/ProcessorTest.java
    
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/RendererTest.java

Modified: 
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/ContainerConfig.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/ContainerConfig.java?rev=706822&r1=706821&r2=706822&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/ContainerConfig.java
 (original)
+++ 
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/ContainerConfig.java
 Tue Oct 21 17:39:55 2008
@@ -19,302 +19,63 @@
 
 package org.apache.shindig.common;
 
-import org.apache.shindig.common.util.ResourceLoader;
+import com.google.inject.ImplementedBy;
 
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import com.google.inject.name.Named;
-
-import org.apache.commons.lang.StringUtils;
 import org.json.JSONArray;
-import org.json.JSONException;
 import org.json.JSONObject;
 
-import java.io.File;
-import java.io.IOException;
 import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.logging.Logger;
 
 /**
  * Represents a container configuration.
  *
- * See config/container.js for an example configuration.
+ * Container configurations are used to support multiple, independent 
configurations in the same
+ * server instance. Global configuration values are handled via traditional 
mechanisms such as
+ * properties files or command-line flags bound through Guice's @Named 
annotation.
  *
- * We use a cascading model, so you only have to specify attributes in
- * your config that you actually want to change.
+ * The default container configuration implementation is intended to be shared 
with the code found
+ * in the PHP implementation of Shindig. It uses a simple JSON format inteded 
for easy readability.
  */
[EMAIL PROTECTED]
-public class ContainerConfig {
-  private final Map<String, JSONObject> config;
-  public static final char FILE_SEPARATOR = ',';
[EMAIL PROTECTED](JsonContainerConfig.class)
+public interface ContainerConfig {
   public static final String DEFAULT_CONTAINER = "default";
-  public static final String PARENT_KEY = "parent";
-  // TODO: Rename this to simply "container", gadgets.container is unnecessary.
-  public static final String CONTAINER_KEY = "gadgets.container";
-  private static final Logger logger
-      = Logger.getLogger("org.apache.shindig.gadgets");
 
   /**
    * @return The set of all containers that are currently registered.
    */
-  public Collection<String> getContainers() {
-    return Collections.unmodifiableSet(config.keySet());
-  }
+  Collection<String> getContainers();
 
   /**
    * Fetches a configuration parameter as a JSON object, array, string, or
    * number, ensuring that it can be safely passed to javascript without any
    * additional filtering.
    *
-   * @param container
    * @param parameter The value to fetch. May be specified as an x-path like
    *     object reference such as "gadgets/features/views".
    * @return A configuration parameter as a JSON object or null if not set or
    *     can't be interpreted as JSON.
+   *
+   * TODO: Convert to a more generalized object.
    */
-  public Object getJson(String container, String parameter) {
-    JSONObject data = config.get(container);
-    if (data == null) {
-      return null;
-    }
-    if (parameter == null) {
-      return data;
-    }
-
-    try {
-      for (String param : parameter.split("/")) {
-        Object next = data.get(param);
-        if (next instanceof JSONObject) {
-          data = (JSONObject)next;
-        } else {
-          return next;
-        }
-      }
-      return data;
-    } catch (JSONException e) {
-      return null;
-    }
-  }
+  Object getJson(String container, String parameter);
 
   /**
    * Attempts to fetch a parameter for the given container, or the default
    * container if the specified container is not supported.
    *
-   * @param container
-   * @param parameter
    * @return A configuration parameter as a string, or null if not set.
    */
-  public String get(String container, String parameter) {
-    Object data = getJson(container, parameter);
-    return data == null ? null : data.toString();
-  }
+  String get(String container, String parameter);
 
   /**
-   * @param container
-   * @param parameter
    * @return A configuration parameter as a JSON object or null if not set or
    *     can't be interpreted as JSON.
    */
-  public JSONObject getJsonObject(String container, String parameter) {
-    Object data = getJson(container, parameter);
-    if (data instanceof JSONObject) {
-      return (JSONObject)data;
-    }
-    return null;
-  }
+  JSONObject getJsonObject(String container, String parameter);
 
   /**
-   * @param container
-   * @param parameter
    * @return A configuration parameter as a JSON object or null if not set or
    *     can't be interpreted as JSON.
    */
-  public JSONArray getJsonArray(String container, String parameter) {
-    Object data = getJson(container, parameter);
-    if (data instanceof JSONArray) {
-      return (JSONArray)data;
-    }
-    return null;
-  }
-
-  /**
-   * Loads containers from directories recursively.
-   *
-   * Only files with a .js or .json extension will be loaded.
-   *
-   * @param files The files to examine.
-   * @throws ContainerConfigException
-   */
-  private void loadFiles(File[] files) throws ContainerConfigException {
-    try {
-      for (File file : files) {
-        logger.info("Reading container config: " + file.getName());
-        if (file.isDirectory()) {
-          loadFiles(file.listFiles());
-        } else if (file.getName().endsWith(".js") ||
-                   file.getName().endsWith(".json")) {
-          loadFromString(ResourceLoader.getContent(file));
-        }
-      }
-    } catch (IOException e) {
-      throw new ContainerConfigException(e);
-    }
-  }
-
-  /**
-   * Loads resources recursively.
-   * @param files The base paths to look for container.xml
-   * @throws ContainerConfigException
-   */
-  private void loadResources(String[] files)  throws ContainerConfigException {
-    try {
-      for (String entry : files) {
-        logger.info("Reading container config: " + entry);
-        String content = ResourceLoader.getContent(entry);
-        loadFromString(content);
-      }
-    } catch (IOException e) {
-      throw new ContainerConfigException(e);
-    }
-  }
-
-  /**
-   * Merges two JSON objects together (recursively), with values from "merge"
-   * replacing values in "base" to produce a new object.
-   *
-   * @param base The base object that values will be replaced into.
-   * @param merge The object to merge values from.
-   *
-   * @throws JSONException if the two objects can't be merged for some reason.
-   */
-  private JSONObject mergeObjects(JSONObject base, JSONObject merge)
-      throws JSONException {
-    // Clone the initial object (JSONObject doesn't support "clone").
-
-    JSONObject clone = new JSONObject(base, JSONObject.getNames(base));
-    // Walk parameter list for the merged object and merge recursively.
-    String[] fields = JSONObject.getNames(merge);
-    for (String field : fields) {
-      Object existing = clone.opt(field);
-      Object update = merge.get(field);
-      if (existing == null || update == null) {
-        // It's new custom config, not referenced in the prototype, or
-        // it's removing a pre-configured value.
-        clone.put(field, update);
-      } else {
-        // Merge if object type is JSONObject.
-        if (update instanceof JSONObject &&
-            existing instanceof JSONObject) {
-          clone.put(field, mergeObjects((JSONObject)existing,
-                                        (JSONObject)update));
-        } else {
-          // Otherwise we just overwrite it.
-          clone.put(field, update);
-        }
-      }
-    }
-    return clone;
-  }
-
-  /**
-   * Recursively merge values from parent objects in the prototype chain.
-   *
-   * @return The object merged with all parents.
-   *
-   * @throws ContainerConfigException If there is an invalid parent parameter
-   *    in the prototype chain.
-   */
-  private JSONObject mergeParents(String container)
-      throws ContainerConfigException, JSONException {
-    JSONObject base = config.get(container);
-    if (DEFAULT_CONTAINER.equals(container)) {
-      return base;
-    }
-
-    String parent = base.optString(PARENT_KEY, DEFAULT_CONTAINER);
-    if (!config.containsKey(parent)) {
-      throw new ContainerConfigException(
-          "Unable to locate parent '" + parent + "' required by "
-          + base.getString(CONTAINER_KEY));
-    }
-    return mergeObjects(mergeParents(parent), base);
-  }
-
-  /**
-   * Processes a container file.
-   *
-   * @param json
-   * @throws ContainerConfigException
-   */
-  protected void loadFromString(String json) throws ContainerConfigException {
-    try {
-      JSONObject contents = new JSONObject(json);
-      JSONArray containers = contents.getJSONArray(CONTAINER_KEY);
-
-      for (int i = 0, j = containers.length(); i < j; ++i) {
-        // Copy the default object and produce a new one.
-        String container = containers.getString(i);
-        config.put(container, contents);
-      }
-    } catch (JSONException e) {
-      throw new ContainerConfigException(e);
-    }
-  }
-
-  /**
-   * Loads containers from the specified resource. Follows the same rules
-   * as [EMAIL PROTECTED] JsFeatureLoader.loadFeatures} for locating resources.
-   *
-   * @param path
-   * @throws ContainerConfigException
-   */
-  private void loadContainers(String path) throws ContainerConfigException {
-    try {
-      for (String location : StringUtils.split(path, FILE_SEPARATOR)) {
-        if (location.startsWith("res://")) {
-          location = location.substring(6);
-          logger.info("Loading resources from: " + location);
-          if (path.endsWith(".txt")) {
-            
loadResources(ResourceLoader.getContent(location).split("[\r\n]+"));
-          } else {
-            loadResources(new String[]{location});
-          }
-        } else {
-          logger.info("Loading files from: " + location);
-          File file = new File(location);
-          loadFiles(new File[]{file});
-        }
-      }
-
-      // Now that all containers are loaded, we go back through them and merge
-      // recursively. This is done at startup to simplify lookups.
-      Map<String, JSONObject> merged
-          = new HashMap<String, JSONObject>(config.size());
-      for (String container : config.keySet()) {
-        merged.put(container, mergeParents(container));
-      }
-      config.putAll(merged);
-    } catch (IOException e) {
-      throw new ContainerConfigException(e);
-    } catch (JSONException e) {
-      throw new ContainerConfigException(e);
-    }
-  }
-
-  /**
-   * Creates a new, empty configuration.
-   * @param containers
-   * @throws ContainerConfigException
-   */
-  @Inject
-  public ContainerConfig(@Named("shindig.containers.default") String 
containers)
-      throws ContainerConfigException {
-    config = new HashMap<String, JSONObject>();
-    if (containers != null) {
-      loadContainers(containers);
-    }
-  }
+  JSONArray getJsonArray(String container, String parameter);
 }
\ No newline at end of file

Added: 
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonContainerConfig.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonContainerConfig.java?rev=706822&view=auto
==============================================================================
--- 
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonContainerConfig.java
 (added)
+++ 
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonContainerConfig.java
 Tue Oct 21 17:39:55 2008
@@ -0,0 +1,285 @@
+/*
+ * 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;
+
+import org.apache.shindig.common.util.ResourceLoader;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import com.google.inject.name.Named;
+
+import org.apache.commons.lang.StringUtils;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Logger;
+
+/**
+ * Represents a container configuration using JSON notation.
+ *
+ * See config/container.js for an example configuration.
+ *
+ * We use a cascading model, so you only have to specify attributes in
+ * your config that you actually want to change.
+ */
[EMAIL PROTECTED]
+public class JsonContainerConfig implements ContainerConfig {
+  private static final Logger LOG = 
Logger.getLogger(JsonContainerConfig.class.getName());
+  public static final char FILE_SEPARATOR = ',';
+  public static final String PARENT_KEY = "parent";
+  // TODO: Rename this to simply "container", gadgets.container is unnecessary.
+  public static final String CONTAINER_KEY = "gadgets.container";
+
+  private final Map<String, JSONObject> config;
+
+  /**
+   * Creates a new, empty configuration.
+   * @param containers
+   * @throws ContainerConfigException
+   */
+  @Inject
+  public JsonContainerConfig(@Named("shindig.containers.default") String 
containers)
+      throws ContainerConfigException {
+    config = new HashMap<String, JSONObject>();
+    if (containers != null) {
+      loadContainers(containers);
+    }
+  }
+
+  public Collection<String> getContainers() {
+    return Collections.unmodifiableSet(config.keySet());
+  }
+
+  public Object getJson(String container, String parameter) {
+    JSONObject data = config.get(container);
+    if (data == null) {
+      return null;
+    }
+    if (parameter == null) {
+      return data;
+    }
+
+    try {
+      for (String param : parameter.split("/")) {
+        Object next = data.get(param);
+        if (next instanceof JSONObject) {
+          data = (JSONObject)next;
+        } else {
+          return next;
+        }
+      }
+      return data;
+    } catch (JSONException e) {
+      return null;
+    }
+  }
+
+  public String get(String container, String parameter) {
+    Object data = getJson(container, parameter);
+    return data == null ? null : data.toString();
+  }
+
+  public JSONObject getJsonObject(String container, String parameter) {
+    Object data = getJson(container, parameter);
+    if (data instanceof JSONObject) {
+      return (JSONObject)data;
+    }
+    return null;
+  }
+
+  public JSONArray getJsonArray(String container, String parameter) {
+    Object data = getJson(container, parameter);
+    if (data instanceof JSONArray) {
+      return (JSONArray)data;
+    }
+    return null;
+  }
+
+  /**
+   * Loads containers from directories recursively.
+   *
+   * Only files with a .js or .json extension will be loaded.
+   *
+   * @param files The files to examine.
+   * @throws ContainerConfigException
+   */
+  private void loadFiles(File[] files) throws ContainerConfigException {
+    try {
+      for (File file : files) {
+        LOG.info("Reading container config: " + file.getName());
+        if (file.isDirectory()) {
+          loadFiles(file.listFiles());
+        } else if (file.getName().endsWith(".js") ||
+                   file.getName().endsWith(".json")) {
+          loadFromString(ResourceLoader.getContent(file));
+        }
+      }
+    } catch (IOException e) {
+      throw new ContainerConfigException(e);
+    }
+  }
+
+  /**
+   * Loads resources recursively.
+   * @param files The base paths to look for container.xml
+   * @throws ContainerConfigException
+   */
+  private void loadResources(String[] files)  throws ContainerConfigException {
+    try {
+      for (String entry : files) {
+        LOG.info("Reading container config: " + entry);
+        String content = ResourceLoader.getContent(entry);
+        loadFromString(content);
+      }
+    } catch (IOException e) {
+      throw new ContainerConfigException(e);
+    }
+  }
+
+  /**
+   * Merges two JSON objects together (recursively), with values from "merge"
+   * replacing values in "base" to produce a new object.
+   *
+   * @param base The base object that values will be replaced into.
+   * @param merge The object to merge values from.
+   *
+   * @throws JSONException if the two objects can't be merged for some reason.
+   */
+  private JSONObject mergeObjects(JSONObject base, JSONObject merge)
+      throws JSONException {
+    // Clone the initial object (JSONObject doesn't support "clone").
+
+    JSONObject clone = new JSONObject(base, JSONObject.getNames(base));
+    // Walk parameter list for the merged object and merge recursively.
+    String[] fields = JSONObject.getNames(merge);
+    for (String field : fields) {
+      Object existing = clone.opt(field);
+      Object update = merge.get(field);
+      if (existing == null || update == null) {
+        // It's new custom config, not referenced in the prototype, or
+        // it's removing a pre-configured value.
+        clone.put(field, update);
+      } else {
+        // Merge if object type is JSONObject.
+        if (update instanceof JSONObject &&
+            existing instanceof JSONObject) {
+          clone.put(field, mergeObjects((JSONObject)existing,
+                                        (JSONObject)update));
+        } else {
+          // Otherwise we just overwrite it.
+          clone.put(field, update);
+        }
+      }
+    }
+    return clone;
+  }
+
+  /**
+   * Recursively merge values from parent objects in the prototype chain.
+   *
+   * @return The object merged with all parents.
+   *
+   * @throws ContainerConfigException If there is an invalid parent parameter
+   *    in the prototype chain.
+   */
+  private JSONObject mergeParents(String container)
+      throws ContainerConfigException, JSONException {
+    JSONObject base = config.get(container);
+    if (DEFAULT_CONTAINER.equals(container)) {
+      return base;
+    }
+
+    String parent = base.optString(PARENT_KEY, DEFAULT_CONTAINER);
+    if (!config.containsKey(parent)) {
+      throw new ContainerConfigException(
+          "Unable to locate parent '" + parent + "' required by "
+          + base.getString(CONTAINER_KEY));
+    }
+    return mergeObjects(mergeParents(parent), base);
+  }
+
+  /**
+   * Processes a container file.
+   *
+   * @param json
+   * @throws ContainerConfigException
+   */
+  protected void loadFromString(String json) throws ContainerConfigException {
+    try {
+      JSONObject contents = new JSONObject(json);
+      JSONArray containers = contents.getJSONArray(CONTAINER_KEY);
+
+      for (int i = 0, j = containers.length(); i < j; ++i) {
+        // Copy the default object and produce a new one.
+        String container = containers.getString(i);
+        config.put(container, contents);
+      }
+    } catch (JSONException e) {
+      throw new ContainerConfigException(e);
+    }
+  }
+
+  /**
+   * Loads containers from the specified resource. Follows the same rules
+   * as [EMAIL PROTECTED] JsFeatureLoader.loadFeatures} for locating resources.
+   *
+   * @param path
+   * @throws ContainerConfigException
+   */
+  private void loadContainers(String path) throws ContainerConfigException {
+    try {
+      for (String location : StringUtils.split(path, FILE_SEPARATOR)) {
+        if (location.startsWith("res://")) {
+          location = location.substring(6);
+          LOG.info("Loading resources from: " + location);
+          if (path.endsWith(".txt")) {
+            
loadResources(ResourceLoader.getContent(location).split("[\r\n]+"));
+          } else {
+            loadResources(new String[]{location});
+          }
+        } else {
+          LOG.info("Loading files from: " + location);
+          File file = new File(location);
+          loadFiles(new File[]{file});
+        }
+      }
+
+      // Now that all containers are loaded, we go back through them and merge
+      // recursively. This is done at startup to simplify lookups.
+      Map<String, JSONObject> merged
+          = new HashMap<String, JSONObject>(config.size());
+      for (String container : config.keySet()) {
+        merged.put(container, mergeParents(container));
+      }
+      config.putAll(merged);
+    } catch (IOException e) {
+      throw new ContainerConfigException(e);
+    } catch (JSONException e) {
+      throw new ContainerConfigException(e);
+    }
+  }
+}
\ No newline at end of file

Modified: 
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/auth/BlobCrypterSecurityTokenDecoderTest.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/auth/BlobCrypterSecurityTokenDecoderTest.java?rev=706822&r1=706821&r2=706822&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/auth/BlobCrypterSecurityTokenDecoderTest.java
 (original)
+++ 
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/auth/BlobCrypterSecurityTokenDecoderTest.java
 Tue Oct 21 17:39:55 2008
@@ -22,14 +22,16 @@
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-
 import org.apache.shindig.common.ContainerConfig;
+import org.apache.shindig.common.JsonContainerConfig;
 import org.apache.shindig.common.crypto.BasicBlobCrypter;
 import org.apache.shindig.common.crypto.BlobCrypter;
 import org.apache.shindig.common.util.CharsetUtil;
 import org.apache.shindig.common.util.FakeTimeSource;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
 import org.junit.Before;
 import org.junit.Test;
 
@@ -44,11 +46,11 @@
 public class BlobCrypterSecurityTokenDecoderTest {
 
   private BlobCrypterSecurityTokenDecoder decoder;
-  private FakeTimeSource timeSource = new FakeTimeSource();
+  private final FakeTimeSource timeSource = new FakeTimeSource();
 
   @Before
   public void setUp() throws Exception {
-    ContainerConfig config = new ContainerConfig(null) {
+    ContainerConfig config = new JsonContainerConfig(null) {
       @Override
       public String get(String container, String name) {
         if 
(BlobCrypterSecurityTokenDecoder.SECURITY_TOKEN_KEY_FILE.equals(name)) {
@@ -59,7 +61,7 @@
         }
         throw new RuntimeException("Mock not smart enough, unknown name " + 
name);
       }
-      
+
       @Override
       public Collection<String> getContainers() {
         return Lists.newArrayList("container", "example");
@@ -67,17 +69,17 @@
     };
     decoder = new DecoderWithLoadStubbedOut(config);
   }
-  
+
   private String getContainerKey(String container) {
     return "KEY FOR CONTAINER " + container;
   }
-  
+
   private BlobCrypter getBlobCrypter(String fileName) {
     BasicBlobCrypter c = new 
BasicBlobCrypter(CharsetUtil.getUtf8Bytes(fileName));
     c.timeSource = timeSource;
     return c;
   }
-  
+
   /**
    * Stubs out loading the key file.
    */
@@ -86,7 +88,7 @@
     public DecoderWithLoadStubbedOut(ContainerConfig config) {
       super(config);
     }
-    
+
     /**
      * @return a crypter based on the name of the file passed in, rather than 
the contents
      */
@@ -98,7 +100,7 @@
       return getBlobCrypter(file.getPath());
     }
   }
-  
+
   @Test
   public void testCreateToken() throws Exception {
     BlobCrypterSecurityToken t = new BlobCrypterSecurityToken(
@@ -109,10 +111,10 @@
     t.setViewerId("viewer");
     t.setTrustedJson("trusted");
     String encrypted = t.encrypt();
-    
+
     SecurityToken t2 = decoder.createToken(
         Maps.immutableMap(SecurityTokenDecoder.SECURITY_TOKEN_NAME, 
encrypted));
-    
+
     assertEquals("http://www.example.com/gadget.xml";, t2.getAppId());
     assertEquals("http://www.example.com/gadget.xml";, t2.getAppUrl());
     assertEquals("container.com", t2.getDomain());
@@ -121,7 +123,7 @@
     assertEquals("viewer", t2.getViewerId());
     assertEquals("trusted", t2.getTrustedJson());
   }
-  
+
   @Test
   public void testUnknownContainer() throws Exception {
     BlobCrypterSecurityToken t = new BlobCrypterSecurityToken(
@@ -133,7 +135,7 @@
     t.setTrustedJson("trusted");
     String encrypted = t.encrypt();
     encrypted = encrypted.replace("container:", "other:");
-    
+
     try {
       
decoder.createToken(Maps.immutableMap(SecurityTokenDecoder.SECURITY_TOKEN_NAME, 
encrypted));
       fail("should have reported that container was unknown");
@@ -141,7 +143,7 @@
       assertTrue(e.getMessage(), e.getMessage().contains("Unknown container"));
     }
   }
-  
+
   @Test
   public void testWrongContainer() throws Exception {
     BlobCrypterSecurityToken t = new BlobCrypterSecurityToken(
@@ -153,7 +155,7 @@
     t.setTrustedJson("trusted");
     String encrypted = t.encrypt();
     encrypted = encrypted.replace("container:", "example:");
-    
+
     try {
       
decoder.createToken(Maps.immutableMap(SecurityTokenDecoder.SECURITY_TOKEN_NAME, 
encrypted));
       fail("should have tried to decrypt with wrong key");
@@ -161,7 +163,7 @@
       assertTrue(e.getMessage(), e.getMessage().contains("Invalid token 
signature"));
     }
   }
-  
+
   @Test
   public void testExpired() throws Exception {
     BlobCrypterSecurityToken t = new BlobCrypterSecurityToken(
@@ -172,7 +174,7 @@
     t.setViewerId("viewer");
     t.setTrustedJson("trusted");
     String encrypted = t.encrypt();
-    
+
     timeSource.incrementSeconds(3600 + 181); // one hour plus clock skew
     try {
       
decoder.createToken(Maps.immutableMap(SecurityTokenDecoder.SECURITY_TOKEN_NAME, 
encrypted));
@@ -181,7 +183,7 @@
       assertTrue(e.getMessage(), e.getMessage().contains("Blob expired"));
     }
   }
-  
+
   @Test
   public void testMalformed() throws Exception {
     try {
@@ -191,21 +193,21 @@
       assertTrue(e.getMessage(), e.getMessage().contains("Invalid security 
token foo"));
     }
   }
-  
+
   @Test
   public void testAnonymous() throws Exception {
     SecurityToken t = decoder.createToken(
         Maps.immutableMap(SecurityTokenDecoder.SECURITY_TOKEN_NAME, "   "));
     assertTrue(t.isAnonymous());
-    
+
     Map<String, String> empty = Maps.immutableMap();
     t = decoder.createToken(empty);
     assertTrue(t.isAnonymous());
   }
-    
+
   @Test
   public void testLoadFailure() throws Exception {
-    ContainerConfig config = new ContainerConfig(null) {
+    ContainerConfig config = new JsonContainerConfig(null) {
       @Override
       public String get(String container, String name) {
         if 
(BlobCrypterSecurityTokenDecoder.SECURITY_TOKEN_KEY_FILE.equals(name)) {
@@ -216,13 +218,13 @@
         }
         throw new RuntimeException("Mock not smart enough, unknown name " + 
name);
       }
-      
+
       @Override
       public Collection<String> getContainers() {
         return Lists.newArrayList("container", "example", "failure");
       }
     };
-    
+
     try {
       new DecoderWithLoadStubbedOut(config);
       fail("Should have failed to load crypter");

Modified: 
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/auth/DefaultSecurityTokenDecoderTest.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/auth/DefaultSecurityTokenDecoderTest.java?rev=706822&r1=706821&r2=706822&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/auth/DefaultSecurityTokenDecoderTest.java
 (original)
+++ 
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/auth/DefaultSecurityTokenDecoderTest.java
 Tue Oct 21 17:39:55 2008
@@ -22,10 +22,11 @@
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import org.apache.shindig.common.ContainerConfigException;
+import org.apache.shindig.common.JsonContainerConfig;
+
 import com.google.common.collect.Lists;
 
-import org.apache.shindig.common.ContainerConfig;
-import org.apache.shindig.common.ContainerConfigException;
 import org.junit.Test;
 
 import java.util.Collection;
@@ -37,14 +38,14 @@
  */
 public class DefaultSecurityTokenDecoderTest {
 
-  private static class FakeContainerConfig extends ContainerConfig {
+  private static class FakeContainerConfig extends JsonContainerConfig {
     private final String tokenType;
 
     public FakeContainerConfig(String tokenType) throws 
ContainerConfigException {
       super(null);
       this.tokenType = tokenType;
     }
-    
+
     @Override
     public String get(String container, String parameter) {
       if ("gadgets.securityTokenType".equals(parameter)) {
@@ -56,13 +57,13 @@
       }
       return null;
     }
-    
+
     @Override
     public Collection<String> getContainers() {
       return Lists.newArrayList("somecontainer");
     }
   }
-  
+
   @Test
   public void testBasicDecoder() throws Exception {
     DefaultSecurityTokenDecoder decoder = new DefaultSecurityTokenDecoder(
@@ -75,7 +76,7 @@
     assertEquals("v", st.getViewerId());
     assertEquals("appurl", st.getAppUrl());
   }
-  
+
   @Test
   public void testInvalidDecoder() throws Exception {
     try {
@@ -85,7 +86,7 @@
       assertTrue("exception should contain garbage: " + e, 
e.getMessage().contains("garbage"));
     }
   }
-  
+
   @Test
   public void testNullDecoder() throws Exception {
     try {
@@ -95,7 +96,7 @@
       assertTrue("exception should contain null: " + e, 
e.getMessage().contains("null"));
     }
   }
-  
+
   @Test
   public void testRealDecoder() throws Exception {
     // Just verifies that "secure" tokens get routed to the right decoder 
class.
@@ -105,6 +106,6 @@
     } catch (RuntimeException e) {
       assertTrue("root cause should have been FileNotFoundException: " + e,
           e.getMessage().contains("FileNotFoundException: container key file: 
somecontainer"));
-    }    
+    }
   }
 }

Copied: 
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/JsonContainerConfigTest.java
 (from r706355, 
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/ContainerConfigTest.java)
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/JsonContainerConfigTest.java?p2=incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/JsonContainerConfigTest.java&p1=incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/ContainerConfigTest.java&r1=706355&r2=706822&rev=706822&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/ContainerConfigTest.java
 (original)
+++ 
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/JsonContainerConfigTest.java
 Tue Oct 21 17:39:55 2008
@@ -19,9 +19,9 @@
 
 package org.apache.shindig.common;
 
-import static org.apache.shindig.common.ContainerConfig.CONTAINER_KEY;
 import static org.apache.shindig.common.ContainerConfig.DEFAULT_CONTAINER;
-import static org.apache.shindig.common.ContainerConfig.PARENT_KEY;
+import static org.apache.shindig.common.JsonContainerConfig.CONTAINER_KEY;
+import static org.apache.shindig.common.JsonContainerConfig.PARENT_KEY;
 import static org.junit.Assert.assertEquals;
 
 import org.json.JSONArray;
@@ -32,7 +32,7 @@
 import java.io.File;
 import java.io.FileWriter;
 
-public class ContainerConfigTest {
+public class JsonContainerConfigTest {
 
   private static final String TOP_LEVEL_NAME = "Top level name";
   private static final String TOP_LEVEL_VALUE = "Top level value";
@@ -77,8 +77,7 @@
 
   @Test
   public void parseBasicConfig() throws Exception {
-    ContainerConfig config
-        = new ContainerConfig(createDefaultContainer().getAbsolutePath());
+    ContainerConfig config = new 
JsonContainerConfig(createDefaultContainer().getAbsolutePath());
 
     assertEquals(1, config.getContainers().size());
     for (String container : config.getContainers()) {
@@ -104,8 +103,8 @@
     File parentFile = createDefaultContainer();
     File childFile = createContainer(json);
 
-    ContainerConfig config = new ContainerConfig(childFile.getAbsolutePath() +
-        ContainerConfig.FILE_SEPARATOR + parentFile.getAbsolutePath());
+    ContainerConfig config = new 
JsonContainerConfig(childFile.getAbsolutePath() +
+        JsonContainerConfig.FILE_SEPARATOR + parentFile.getAbsolutePath());
 
     assertEquals(NESTED_VALUE, config.get(CONTAINER_A, NESTED_KEY));
     assertEquals(NESTED_VALUE, config.get(CONTAINER_B, NESTED_KEY));
@@ -126,8 +125,8 @@
 
     File childFile = createContainer(json);
     File parentFile = createDefaultContainer();
-    ContainerConfig config = new ContainerConfig(childFile.getAbsolutePath() +
-        ContainerConfig.FILE_SEPARATOR + parentFile.getAbsolutePath());
+    ContainerConfig config = new 
JsonContainerConfig(childFile.getAbsolutePath() +
+        JsonContainerConfig.FILE_SEPARATOR + parentFile.getAbsolutePath());
 
     String value = config.get(CHILD_CONTAINER, TOP_LEVEL_NAME);
     assertEquals(TOP_LEVEL_VALUE, value);
@@ -154,12 +153,12 @@
     json.put(PARENT_KEY, "bad bad bad parent!");
     json.put(ARRAY_NAME, ARRAY_ALT_VALUE);
 
-    new ContainerConfig(createContainer(json).getAbsolutePath());
+    new JsonContainerConfig(createContainer(json).getAbsolutePath());
   }
 
-  public void testPathQuery() throws Exception {
-    ContainerConfig config
-        = new ContainerConfig(createDefaultContainer().getAbsolutePath());
+  @Test
+  public void pathQuery() throws Exception {
+    ContainerConfig config = new 
JsonContainerConfig(createDefaultContainer().getAbsolutePath());
     String path = NESTED_KEY + '/' + NESTED_NAME;
     String data = config.get(DEFAULT_CONTAINER, path);
     assertEquals(NESTED_VALUE, data);

Propchange: 
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/JsonContainerConfigTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/JsonContainerConfigTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev

Modified: 
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/DefaultUrlGeneratorTest.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/DefaultUrlGeneratorTest.java?rev=706822&r1=706821&r2=706822&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/DefaultUrlGeneratorTest.java
 (original)
+++ 
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/DefaultUrlGeneratorTest.java
 Tue Oct 21 17:39:55 2008
@@ -23,7 +23,6 @@
 import static org.easymock.EasyMock.isA;
 
 import org.apache.shindig.common.ContainerConfig;
-import org.apache.shindig.common.ContainerConfigException;
 import org.apache.shindig.common.uri.Uri;
 import org.apache.shindig.gadgets.spec.GadgetSpec;
 
@@ -32,6 +31,8 @@
 import junitx.framework.StringAssert;
 
 import org.apache.commons.lang.StringEscapeUtils;
+import org.json.JSONArray;
+import org.json.JSONObject;
 
 import java.net.URI;
 import java.util.ArrayList;
@@ -61,7 +62,7 @@
 
   private final GadgetContext context = mock(GadgetContext.class);
   private final LockedDomainService lockedDomainService = 
mock(LockedDomainService.class);
-  private FakeContainerConfig config;
+  private final FakeContainerConfig config = new FakeContainerConfig();
   private DefaultUrlGenerator realUrlGenerator;
 
   @Override
@@ -76,7 +77,6 @@
     expect(context.getModuleId()).andReturn(MODULE_ID).anyTimes();
     expect(context.getView()).andReturn(VIEW).anyTimes();
 
-    config = new FakeContainerConfig();
     config.properties.put(DefaultUrlGenerator.IFRAME_URI_PARAM, IFR_BASE);
     config.properties.put(DefaultUrlGenerator.JS_URI_PARAM, JS_BASE);
     realUrlGenerator = new DefaultUrlGenerator(config, lockedDomainService, 
registry);
@@ -211,21 +211,27 @@
     StringAssert.assertContains("mid=" + MODULE_ID, iframeUrl.getQuery());
   }
 
-  private static class FakeContainerConfig extends ContainerConfig {
+  private static class FakeContainerConfig implements ContainerConfig {
     private final Map<String, String> properties = Maps.newHashMap();
 
-    public FakeContainerConfig() throws ContainerConfigException {
-      super(null);
-    }
-
-    @Override
     public String get(String container, String property) {
       return properties.get(property);
     }
 
-    @Override
     public Collection<String> getContainers() {
       return Arrays.asList(CONTAINER);
     }
+
+    public Object getJson(String container, String parameter) {
+      return null;
+    }
+
+    public JSONArray getJsonArray(String container, String parameter) {
+      return null;
+    }
+
+    public JSONObject getJsonObject(String container, String parameter) {
+      return null;
+    }
   }
 }

Modified: 
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/process/ProcessorTest.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/process/ProcessorTest.java?rev=706822&r1=706821&r2=706822&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/process/ProcessorTest.java
 (original)
+++ 
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/process/ProcessorTest.java
 Tue Oct 21 17:39:55 2008
@@ -21,8 +21,8 @@
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
-import org.apache.shindig.common.ContainerConfig;
 import org.apache.shindig.common.ContainerConfigException;
+import org.apache.shindig.common.JsonContainerConfig;
 import org.apache.shindig.common.uri.Uri;
 import org.apache.shindig.gadgets.Gadget;
 import org.apache.shindig.gadgets.GadgetBlacklist;
@@ -156,7 +156,7 @@
     }
   }
 
-  private static class FakeContainerConfig extends ContainerConfig {
+  private static class FakeContainerConfig extends JsonContainerConfig {
     private final JSONObject json = new JSONObject();
 
     public FakeContainerConfig() throws ContainerConfigException {

Modified: 
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/RendererTest.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/RendererTest.java?rev=706822&r1=706821&r2=706822&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/RendererTest.java
 (original)
+++ 
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/RendererTest.java
 Tue Oct 21 17:39:55 2008
@@ -23,8 +23,8 @@
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
-import org.apache.shindig.common.ContainerConfig;
 import org.apache.shindig.common.ContainerConfigException;
+import org.apache.shindig.common.JsonContainerConfig;
 import org.apache.shindig.common.uri.Uri;
 import org.apache.shindig.gadgets.Gadget;
 import org.apache.shindig.gadgets.GadgetContext;
@@ -155,7 +155,7 @@
     assertNull(results.getRedirect());
   }
 
-  private static class FakeContainerConfig extends ContainerConfig {
+  private static class FakeContainerConfig extends JsonContainerConfig {
     private final JSONObject json = new JSONObject();
 
     public FakeContainerConfig() throws ContainerConfigException {


Reply via email to