You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by lr...@apache.org on 2009/02/10 02:53:59 UTC

svn commit: r742816 [3/5] - in /incubator/shindig/trunk/java: common/ common/src/main/java/org/apache/shindig/protocol/ common/src/main/java/org/apache/shindig/protocol/conversion/ common/src/main/java/org/apache/shindig/protocol/conversion/jsonlib/ co...

Added: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/RestfullCollectionConverter.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/RestfullCollectionConverter.java?rev=742816&view=auto
==============================================================================
--- incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/RestfullCollectionConverter.java (added)
+++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/RestfullCollectionConverter.java Tue Feb 10 01:53:52 2009
@@ -0,0 +1,99 @@
+/*
+ * 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.protocol.conversion.xstream;
+
+import org.apache.shindig.protocol.RestfulCollection;
+
+import com.thoughtworks.xstream.converters.MarshallingContext;
+import com.thoughtworks.xstream.converters.UnmarshallingContext;
+import com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter;
+import com.thoughtworks.xstream.io.HierarchicalStreamReader;
+import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+import com.thoughtworks.xstream.mapper.Mapper;
+
+/**
+ * This converter changes the way in which a collection is serialized
+ *
+ */
+public class RestfullCollectionConverter extends AbstractCollectionConverter {
+
+  /**
+   * @param mapper
+   */
+  public RestfullCollectionConverter(Mapper mapper) {
+    super(mapper);
+  }
+
+  /**
+   * {@inheritDoc}
+   *
+   * @see com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter#canConvert(java.lang.Class)
+   */
+  @SuppressWarnings("unchecked")
+  @Override
+  public boolean canConvert(Class clazz) {
+    return (RestfulCollection.class.isAssignableFrom(clazz));
+  }
+
+  /**
+   * {@inheritDoc}
+   *
+   * @see com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter#marshal(java.lang.Object,
+   *      com.thoughtworks.xstream.io.HierarchicalStreamWriter,
+   *      com.thoughtworks.xstream.converters.MarshallingContext)
+   */
+  @Override
+  public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
+
+    RestfulCollection<?> collection = (RestfulCollection<?>) source;
+    writer.startNode("startIndex");
+    writer.setValue(String.valueOf(collection.getStartIndex()));
+    writer.endNode();
+    writer.startNode("totalResults");
+    writer.setValue(String.valueOf(collection.getTotalResults()));
+    writer.endNode();
+    writer.startNode("isFiltered");
+    writer.setValue(String.valueOf(collection.isFiltered()));
+    writer.endNode();
+    writer.startNode("isSorted");
+    writer.setValue(String.valueOf(collection.isSorted()));
+    writer.endNode();
+    writer.startNode("isUpdatedSince");
+    writer.setValue(String.valueOf(collection.isUpdatedSince()));
+    writer.endNode();
+    // TODO: resolve if entry is the container or the name of the object.
+    for (Object o : collection.getEntry()) {
+      writer.startNode("entry");
+      writeItem(o, context, writer);
+      writer.endNode();
+    }
+  }
+
+  /**
+   * {@inheritDoc}
+   *
+   * @see com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter#unmarshal(com.thoughtworks.xstream.io.HierarchicalStreamReader,
+   *      com.thoughtworks.xstream.converters.UnmarshallingContext)
+   */
+  @Override
+  public Object unmarshal(HierarchicalStreamReader arg0, UnmarshallingContext arg1) {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+}

Added: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/StackDriver.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/StackDriver.java?rev=742816&view=auto
==============================================================================
--- incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/StackDriver.java (added)
+++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/StackDriver.java Tue Feb 10 01:53:52 2009
@@ -0,0 +1,117 @@
+/*
+ * 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.protocol.conversion.xstream;
+
+import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
+import com.thoughtworks.xstream.io.HierarchicalStreamReader;
+import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.Map;
+
+/**
+ * A StackDriver wraps other forms of Drivers and updates a WriterStack with the
+ * path into the writer hierarchy.
+ */
+public class StackDriver implements HierarchicalStreamDriver {
+
+  /**
+   * The parent Stream Driver that does the work.
+   */
+  private HierarchicalStreamDriver parent;
+  /**
+   * A Writer Stack implementation that records where the writer is.
+   */
+  private WriterStack writerStack;
+  private Map<String, NamespaceSet> namespaces;
+
+  /**
+   * Create a {@link StackDriver}, wrapping a {@link HierarchicalStreamDriver}
+   * and updating a {@link WriterStack}.
+   *
+   * @param parent
+   *          the driver to be wrapped
+   * @param writerStack
+   *          the thread safe writer stack that records where the writer is.
+   * @param map
+   */
+  public StackDriver(HierarchicalStreamDriver parent, WriterStack writerStack, Map<String, NamespaceSet> map) {
+    this.parent = parent;
+    this.writerStack = writerStack;
+    this.namespaces = map;
+  }
+
+  /**
+   * Create a {@link HierarchicalStreamReader}, using the wrapped
+   * {@link HierarchicalStreamDriver}.
+   *
+   * @param reader
+   *          the Reader that will be used to read from the underlying stream
+   * @return the reader
+   * @see com.thoughtworks.xstream.io.HierarchicalStreamDriver#createReader(java.io.Reader)
+   */
+  public HierarchicalStreamReader createReader(Reader reader) {
+    return parent.createReader(reader);
+  }
+
+  /**
+   * Create a {@link HierarchicalStreamReader}, using the wrapped
+   * {@link HierarchicalStreamDriver}.
+   *
+   * @param inputStream
+   *          the input stream that will be used to read from the underlying
+   *          stream
+   * @return the reader
+   * @see com.thoughtworks.xstream.io.HierarchicalStreamDriver#createReader(java.io.InputStream)
+   */
+  public HierarchicalStreamReader createReader(InputStream inputStream) {
+    return parent.createReader(inputStream);
+  }
+
+  /**
+   * Create a {@link HierarchicalStreamWriter} that tracks the path to the
+   * current element based on a {@link Writer}.
+   *
+   * @param writer
+   *          the underlying writer that will perform the writes.
+   * @return the writer
+   * @see com.thoughtworks.xstream.io.HierarchicalStreamDriver#createWriter(java.io.Writer)
+   */
+  public HierarchicalStreamWriter createWriter(Writer writer) {
+    HierarchicalStreamWriter parentWriter = parent.createWriter(writer);
+    return new StackWriterWrapper(parentWriter, writerStack, namespaces);
+  }
+
+  /**
+   * Create a {@link HierarchicalStreamWriter} that tracks the path to the
+   * current element based on a {@link OutputStream}.
+   *
+   * @param outputStream
+   *          the underlying output stream that will perform the writes.
+   * @return the writer
+   * @see com.thoughtworks.xstream.io.HierarchicalStreamDriver#createWriter(java.io.Writer)
+   */
+  public HierarchicalStreamWriter createWriter(OutputStream outputStream) {
+    HierarchicalStreamWriter parentWriter = parent.createWriter(outputStream);
+    return new StackWriterWrapper(parentWriter, writerStack, namespaces);
+  }
+
+}

Added: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/StackWriterWrapper.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/StackWriterWrapper.java?rev=742816&view=auto
==============================================================================
--- incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/StackWriterWrapper.java (added)
+++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/StackWriterWrapper.java Tue Feb 10 01:53:52 2009
@@ -0,0 +1,150 @@
+/*
+ * 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.protocol.conversion.xstream;
+
+import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+import com.thoughtworks.xstream.io.WriterWrapper;
+
+import java.util.Map;
+import java.util.Map.Entry;
+
+/**
+ * A Writer that provides a Stack based tracking of the location of the
+ * underlying writer.
+ */
+public class StackWriterWrapper extends WriterWrapper {
+
+  /**
+   * The stack that keeps track of current node.
+   */
+  private WriterStack writerStack;
+  private Map<String, NamespaceSet> namespaces;
+
+  /**
+   * Create a {@link StackWriterWrapper} that wraps a
+   * {@link HierarchicalStreamWriter} and tracks where that writer is in the
+   * hierarchy.
+   *
+   * @param wrapped
+   *          the underlying writer
+   * @param writerStack
+   *          the stack that will record where the writer is.
+   * @param namespaces
+   */
+  public StackWriterWrapper(HierarchicalStreamWriter wrapped,
+      WriterStack writerStack, Map<String, NamespaceSet> namespaces) {
+    super(wrapped);
+    this.writerStack = writerStack;
+    this.namespaces = namespaces;
+  }
+
+  /**
+   * Set attribute values on the current node, but filter out class attributes
+   * from the writer, this is not strictly a feature of this class, but is
+   * required (for shindig to meet the XSD requirements.
+   *
+   * @param name
+   *          the name of attribute
+   * @param value
+   *          the value of the attribute.
+   * @see com.thoughtworks.xstream.io.WriterWrapper#addAttribute(java.lang.String,
+   *      java.lang.String)
+   */
+  @Override
+  public void addAttribute(String name, String value) {
+    if (!"class".equals(name)) {
+      super.addAttribute(name, value);
+    }
+  }
+
+  /**
+   * Begin a new element or node of the supplied name.
+   *
+   * @param name
+   *          the name of the node.
+   *
+   * @see com.thoughtworks.xstream.io.WriterWrapper#startNode(java.lang.String )
+   */
+  @Override
+  public void startNode(String name) {
+    super.startNode(translateName(name));
+    addNamespace(name);
+  }
+
+  /**
+   * Start a node with a specific class. This may invoke
+   * {@link StackWriterWrapper#startNode(String)} so we might have double
+   * recording of the position in the stack. This would be a bug.
+   *
+   * @see com.thoughtworks.xstream.io.WriterWrapper#startNode(java.lang.String ,
+   *      java.lang.Class)
+   */
+  @SuppressWarnings("unchecked")
+  // API is not generic
+  @Override
+  public void startNode(String name, Class clazz) {
+    super.startNode(translateName(name), clazz);
+    addNamespace(name);
+  }
+
+  /**
+   * @param name
+   * @return
+   */
+  private String translateName(String name) {
+    NamespaceSet namespaceSet = namespaces.get(name);
+    NamespaceSet currentNamespace = writerStack.peekNamespace();
+    // specified by not current
+    if (namespaceSet != null &&  namespaceSet != currentNamespace) {
+        return namespaceSet.getElementName(name);
+    }
+    // current has been specified
+    if ( currentNamespace != null ) {
+      return currentNamespace.getElementName(name);
+    }
+    return name;
+
+  }
+
+  /**
+   * @param name
+   */
+  private void addNamespace(String name) {
+    NamespaceSet namespaceSet = namespaces.get(name);
+    NamespaceSet currentNamespace = writerStack.peekNamespace();
+    // specified and not current
+    if ( namespaceSet != null && namespaceSet != currentNamespace ) {
+      for (Entry<String, String> e : namespaceSet.nameSpaceEntrySet()) {
+        super.addAttribute(e.getKey(), e.getValue());
+      }
+      currentNamespace = namespaceSet;
+    }
+    writerStack.push(name, currentNamespace);
+  }
+
+  /**
+   * End the current node, making the parent node the active node.
+   *
+   * @see com.thoughtworks.xstream.io.WriterWrapper#endNode()
+   */
+  @Override
+  public void endNode() {
+    writerStack.pop();
+    super.endNode();
+  }
+}

Added: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/ThreadSafeWriterStack.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/ThreadSafeWriterStack.java?rev=742816&view=auto
==============================================================================
--- incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/ThreadSafeWriterStack.java (added)
+++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/ThreadSafeWriterStack.java Tue Feb 10 01:53:52 2009
@@ -0,0 +1,134 @@
+/*
+ * 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.protocol.conversion.xstream;
+
+import com.google.common.collect.Lists;
+
+import java.util.List;
+
+/**
+ * A simple implementation of a WriterStack that can be shared amongst multiple
+ * threads and will record the state of each thread. This cannot however be
+ * shared amongst multiple writers on multiple threads as this would lead to an
+ * inconsistent state. In the shindig implementation this is not an issue as the
+ * serialization process is atomic below the API.
+ */
+public class ThreadSafeWriterStack implements WriterStack {
+  /**
+   * A thread local holder for the stack.
+   */
+  private ThreadLocal<List<Object[]>> stackHolder = new ThreadLocal<List<Object[]>>() {
+    @Override
+    protected List<Object[]> initialValue() {
+      return Lists.newArrayList();
+    }
+  };
+
+  /**
+   * Create a {@link WriterStack} that is thread safe. The stack will store its
+   * contents on the thread so this class can be shared amongst multiple
+   * threads, but obviously there must be only one instance of the class per
+   * writer per thread.
+   */
+  public ThreadSafeWriterStack() {
+  }
+
+  /**
+   * Add an element name to the stack on the current thread.
+   *
+   * @param name
+   *          the node name just added.
+   */
+  public void push(String name, NamespaceSet namespaceSet) {
+    stackHolder.get().add(new Object[]{name, namespaceSet});
+  }
+
+  /**
+   * Remove a node name from the stack on the current thread.
+   *
+   * @return the node name just ended.
+   */
+  public String pop() {
+    List<Object[]> stack = stackHolder.get();
+    if (stack.isEmpty()) {
+      return null;
+    } else {
+      Object[] o =  stack.remove(stack.size() - 1);
+      if ( o != null && o.length > 0 ) {
+        return (String) o[0];
+      }
+      return null;
+    }
+  }
+
+  /**
+   * {@inheritDoc}
+   * @see WriterStack#peek()
+   */
+  public String peek() {
+    return (String) peek(0);
+  }
+
+  /**
+   * {@inheritDoc}
+   * @see WriterStack#peekNamespace()
+   */
+  public NamespaceSet peekNamespace() {
+    return (NamespaceSet) peek(1);
+  }
+  /**
+   * Look at the node name on the top of the stack on the current thread.
+   *
+   * @return the current node name.
+   */
+  public Object peek(int i) {
+    List<Object[]> stack = stackHolder.get();
+    if (stack.isEmpty()) {
+      return null;
+    } else {
+      Object[] o = stack.get(stack.size() - 1);
+      if ( o != null && o.length > i ) {
+        return o[i];
+      }
+      return null;
+    }
+  }
+
+  /**
+   * Reset the stack back to the default state.
+   *
+   * @see WriterStack#reset()
+   */
+  public void reset() {
+    stackHolder.get().clear();
+  }
+
+  /**
+   * {@inheritDoc}
+   * @see WriterStack#size()
+   */
+  public int size() {
+    List<Object[]> s = stackHolder.get();
+    if ( s == null ) {
+      return 0;
+    } else {
+      return s.size();
+    }
+  }
+
+}

Added: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/WriterStack.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/WriterStack.java?rev=742816&view=auto
==============================================================================
--- incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/WriterStack.java (added)
+++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/WriterStack.java Tue Feb 10 01:53:52 2009
@@ -0,0 +1,67 @@
+/*
+ * 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.protocol.conversion.xstream;
+
+/**
+ * A writer stack is a simple stack that tracks the current location of the
+ * writer.
+ */
+public interface WriterStack {
+
+  /**
+   * Peek into the current location of the writer.
+   *
+   * @return the name of the current node.
+   */
+  String peek();
+
+  /**
+   * @return the current namespace.
+   */
+  NamespaceSet peekNamespace();
+
+  /**
+   * Reset the stack to its default state.
+   */
+  void reset();
+
+  /**
+   * add a node name into the stack indicating that the writer has moved into a
+   * new child element.
+   *
+   * @param name
+   *          the name of the new child element.
+   * @param namespace
+   *          the namespace set associated with the current element.
+   */
+  void push(String name, NamespaceSet namespace);
+
+  /**
+   * Remove and return the current node name, making the parent node the active
+   * node name.
+   * 
+   * @return the node name just removed from the stack.
+   */
+  String pop();
+
+  /**
+   * @return the size of the statck
+   */
+  int size();
+
+}

Added: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/XStreamConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/XStreamConfiguration.java?rev=742816&view=auto
==============================================================================
--- incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/XStreamConfiguration.java (added)
+++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/XStreamConfiguration.java Tue Feb 10 01:53:52 2009
@@ -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.protocol.conversion.xstream;
+
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
+import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
+import com.thoughtworks.xstream.mapper.Mapper;
+
+import java.util.Map;
+
+/**
+ * The configuration for the XStream converter, this class encapsulates the
+ * lists and maps that define the how xstream converts the model.
+ */
+public interface XStreamConfiguration {
+  public static enum ConverterSet {
+    MAP(), COLLECTION(), DEFAULT()
+  }
+
+  public class ConverterConfig {
+    public InterfaceClassMapper mapper;
+    public XStream xstream;
+
+    public ConverterConfig(InterfaceClassMapper mapper, XStream xstream) {
+      this.mapper = mapper;
+      this.xstream = xstream;
+    }
+  }
+
+  /**
+   * Generate the converter config.
+   * 
+   * @param c
+   *          which converter set.
+   * @param rp
+   *          an XStream reflection provider.
+   * @param dmapper
+   *          the XStream mapper.
+   * @param driver
+   *          the XStream driver
+   * @param writerStack
+   *          a hirachical stack recorder.
+   * @return the converter config, used for serialization.
+   */
+  ConverterConfig getConverterConfig(ConverterSet c, ReflectionProvider rp,
+      Mapper dmapper, HierarchicalStreamDriver driver, WriterStack writerStack);
+
+  /**
+   * @return get the namespace mappings used by the driver.
+   */
+  Map<String, NamespaceSet> getNameSpaces();
+
+}

Copied: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/model/Enum.java (from r740988, incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Enum.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/model/Enum.java?p2=incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/model/Enum.java&p1=incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Enum.java&r1=740988&r2=742816&rev=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Enum.java (original)
+++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/model/Enum.java Tue Feb 10 01:53:52 2009
@@ -15,7 +15,7 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations under the License.
  */
-package org.apache.shindig.social.opensocial.model;
+package org.apache.shindig.protocol.model;
 
 /**
  * see <a href="http://www.opensocial.org/Technical-Resources/opensocial-spec-v081/opensocial-reference#opensocial.Enum">
@@ -64,241 +64,6 @@
   }
 
   /**
-   * base interface for keyed Enumerators.
-   */
-  public interface EnumKey {
-    String getDisplayValue();
-  }
-
-  /**
-   * public java.lang.Enum for opensocial.Enum.Drinker.
-   */
-  public enum Drinker implements EnumKey {
-    /** Heavy drinker. */
-    HEAVILY("HEAVILY", "Heavily"),
-    /** non drinker. */
-    NO("NO", "No"),
-    /** occasional drinker. */
-    OCCASIONALLY("OCCASIONALLY", "Occasionally"),
-    /** has quit drinking. */
-    QUIT("QUIT", "Quit"),
-    /** in the process of quitting. */
-    QUITTING("QUITTING", "Quitting"),
-    /** regular drinker. */
-    REGULARLY("REGULARLY", "Regularly"),
-    /** drinks socially. */
-    SOCIALLY("SOCIALLY", "Socially"),
-    /** yes, a drinker of alchhol. */
-    YES("YES", "Yes");
-
-    /**
-     * the Json representation.
-     */
-    private final String jsonString;
-
-    /**
-     * the value used for display purposes.
-     */
-    private final String displayValue;
-
-    /**
-     * private internal constructor for the enum.
-     * @param jsonString the json representation.
-     * @param displayValue the display value.
-     */
-    private Drinker(String jsonString, String displayValue) {
-      this.jsonString = jsonString;
-      this.displayValue = displayValue;
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see java.lang.Enum#toString()
-     */
-    @Override
-    public String toString() {
-      return this.jsonString;
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see org.apache.shindig.social.opensocial.model.Enum.EnumKey#getDisplayValue()
-     */
-    public String getDisplayValue() {
-      return displayValue;
-    }
-  }
-
-  /**
-   * public java.lang.Enum for opensocial.Enum.Smoker.
-   */
-  public enum Smoker implements EnumKey {
-    /**  A heavy smoker. */
-    HEAVILY("HEAVILY", "Heavily"),
-    /** Non smoker. */
-    NO("NO", "No"),
-    /** Smokes occasionally. */
-    OCCASIONALLY("OCCASIONALLY", "Ocasionally"),
-    /** Has quit smoking. */
-    QUIT("QUIT", "Quit"),
-    /** in the process of quitting smoking. */
-    QUITTING("QUITTING", "Quitting"),
-    /** regular smoker, but not a heavy smoker. */
-    REGULARLY("REGULARLY", "Regularly"),
-    /** smokes socially. */
-    SOCIALLY("SOCIALLY", "Socially"),
-    /** yes, a smoker. */
-    YES("YES", "Yes");
-
-    /**
-     * The Json representation of the value.
-     */
-    private final String jsonString;
-
-    /**
-     * The value used for display purposes.
-     */
-    private final String displayValue;
-
-    /**
-     * Create a Smoker enumeration.
-     * @param jsonString the json representation of the value.
-     * @param displayValue the value used for display purposes.
-     */
-    private Smoker(String jsonString, String displayValue) {
-      this.jsonString = jsonString;
-      this.displayValue = displayValue;
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see java.lang.Enum#toString()
-     */
-    @Override
-    public String toString() {
-      return this.jsonString;
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see org.apache.shindig.social.opensocial.model.Enum.EnumKey#getDisplayValue()
-     */
-    public String getDisplayValue() {
-      return displayValue;
-    }
-  }
-
-  /**
-   * public java.lang.Enum for opensocial.Enum.NetworkPresence.
-   */
-  public enum NetworkPresence implements EnumKey {
-    /** Currently Online. */
-    ONLINE("ONLINE", "Online"),
-    /** Currently Offline. */
-    OFFLINE("OFFLINE", "Offline"),
-    /** Currently online but away. */
-    AWAY("AWAY", "Away"),
-    /** In a chat or available to chat. */
-    CHAT("CHAT", "Chat"),
-    /** Online, but don't disturb. */
-    DND("DND", "Do Not Disturb"),
-    /** Gone away for a longer period of time. */
-    XA("XA", "Extended Away");
-
-    /**
-     * The Json representation of the value.
-     */
-    private final String jsonString;
-
-    /**
-     * The value used for display purposes.
-     */
-    private final String displayValue;
-
-    /**
-     * Create a network presence enum.
-     * @param jsonString the json value.
-     * @param displayValue the display value.
-     */
-    private NetworkPresence(String jsonString, String displayValue) {
-      this.jsonString = jsonString;
-      this.displayValue = displayValue;
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see java.lang.Enum#toString()
-     */
-    @Override
-    public String toString() {
-      return this.jsonString;
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see org.apache.shindig.social.opensocial.model.Enum.EnumKey#getDisplayValue()
-     */
-    public String getDisplayValue() {
-      return displayValue;
-    }
-  }
-
-  /**
-   * public java.lang.Enum for opensocial.Enum.LookingFor.
-   */
-  public enum LookingFor implements EnumKey {
-    /** Interested in dating. */
-    DATING("DATING", "Dating"),
-    /** Looking for friends. */
-    FRIENDS("FRIENDS", "Friends"),
-    /** Looking for a relationship. */
-    RELATIONSHIP("RELATIONSHIP", "Relationship"),
-    /** Just want to network. */
-    NETWORKING("NETWORKING", "Networking"),
-    /** */
-    ACTIVITY_PARTNERS("ACTIVITY_PARTNERS", "Activity partners"),
-    /** */
-    RANDOM("RANDOM", "Random");
-
-    /**
-     * The Json representation of the value.
-     */
-    private final String jsonString;
-
-    /**
-     * The value used for display purposes.
-     */
-    private final String displayValue;
-
-    /**
-     * Construct a looking for enum.
-     * @param jsonString the json representation of the enum.
-     * @param displayValue the value used for display purposes.
-     */
-    private LookingFor(String jsonString, String displayValue) {
-      this.jsonString = jsonString;
-      this.displayValue = displayValue;
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see java.lang.Enum#toString()
-     */
-    @Override
-    public String toString() {
-      return this.jsonString;
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see org.apache.shindig.social.opensocial.model.Enum.EnumKey#getDisplayValue()
-     */
-    public String getDisplayValue() {
-      return displayValue;
-    }
-  }
-
-  /**
    * Gets the value of this Enum. This is the string displayed to the user. If the container
    * supports localization, the string should be localized.
    *
@@ -327,4 +92,11 @@
    * @param value The value to set.
    */
   void setValue(E value);
+
+  /**
+ * base interface for keyed Enumerators.
+   */
+  public static interface EnumKey {
+    String getDisplayValue();
+  }
 }

Propchange: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/model/Enum.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/model/EnumImpl.java (from r740988, incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/model/EnumImpl.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/model/EnumImpl.java?p2=incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/model/EnumImpl.java&p1=incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/model/EnumImpl.java&r1=740988&r2=742816&rev=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/model/EnumImpl.java (original)
+++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/model/EnumImpl.java Tue Feb 10 01:53:52 2009
@@ -15,9 +15,7 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations under the License.
  */
-package org.apache.shindig.social.core.model;
-
-import org.apache.shindig.social.opensocial.model.Enum;
+package org.apache.shindig.protocol.model;
 
 public final class EnumImpl<E extends Enum.EnumKey> implements Enum<E> {
   private String displayValue;

Propchange: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/model/EnumImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/model/Exportablebean.java (from r740988, incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Exportablebean.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/model/Exportablebean.java?p2=incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/model/Exportablebean.java&p1=incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Exportablebean.java&r1=740988&r2=742816&rev=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Exportablebean.java (original)
+++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/model/Exportablebean.java Tue Feb 10 01:53:52 2009
@@ -15,7 +15,7 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations under the License.
  */
-package org.apache.shindig.social.opensocial.model;
+package org.apache.shindig.protocol.model;
 
 import java.lang.annotation.ElementType;
 import java.lang.annotation.Inherited;

Propchange: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/model/Exportablebean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/model/FilterOperation.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/model/FilterOperation.java?rev=742816&view=auto
==============================================================================
--- incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/model/FilterOperation.java (added)
+++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/model/FilterOperation.java Tue Feb 10 01:53:52 2009
@@ -0,0 +1,25 @@
+/*
+ * 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.protocol.model;
+
+/**
+ * Standard filter operations
+ */
+public enum FilterOperation {
+  contains, equals, startsWith, present;
+}

Added: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/model/SortOrder.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/model/SortOrder.java?rev=742816&view=auto
==============================================================================
--- incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/model/SortOrder.java (added)
+++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/model/SortOrder.java Tue Feb 10 01:53:52 2009
@@ -0,0 +1,25 @@
+/*
+ * 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.protocol.model;
+
+/**
+ * Common sort order definitions
+ */
+public enum SortOrder {
+  ascending, descending;
+}

Added: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/model/TestModel.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/model/TestModel.java?rev=742816&view=auto
==============================================================================
--- incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/model/TestModel.java (added)
+++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/model/TestModel.java Tue Feb 10 01:53:52 2009
@@ -0,0 +1,177 @@
+/*
+ * 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.protocol.model;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Limited model to fully exercise data binding
+ */
+public class TestModel {
+
+  public static class Car {
+    public static final String DEFAULT_JSON =
+        "{\"engine\":[{\"value\":\"GAS\"},{\"value\":\"HYBRID\"}]," +
+            "\"parkingTickets\":{\"TOKYO\":\"250Y\",\"BERKELEY\":\"$120\"}," +
+            "\"passengers\":[{\"gender\":\"male\",\"name\":\"Dick Dastardly\"},{\"gender\":\"female\",\"name\":\"Speed Racer\"}]}";
+
+    public static final String DEFAULT_XML =
+        "<response>" +
+            "<engine>" +
+              "<EnumImpl><value><declaringClass>org.apache.shindig.protocol.model.TestModel$Engine</declaringClass><displayValue>Gas</displayValue></value></EnumImpl>" +
+              "<EnumImpl><value><declaringClass>org.apache.shindig.protocol.model.TestModel$Engine</declaringClass><displayValue>Hybrid</displayValue></value></EnumImpl>" +
+            "</engine>" +
+            "<parkingTickets>" +
+              "<entry><key>TOKYO</key><value>250Y</value></entry>" +
+              "<entry><key>BERKELEY</key><value>$120</value></entry>" +
+            "</parkingTickets>" +
+            "<passengers>" +
+              "<TestModelPassenger>" +
+                "<gender><declaringClass>org.apache.shindig.protocol.model.TestModel$Gender</declaringClass></gender>" +
+                "<name>Dick Dastardly</name>" +
+              "</TestModelPassenger>" +
+              "<TestModelPassenger>" +
+                "<gender><declaringClass>org.apache.shindig.protocol.model.TestModel$Gender</declaringClass></gender>" +
+                "<name>Speed Racer</name>" +
+              "</TestModelPassenger>" +
+            "</passengers></response>";
+
+    private List<Enum<Engine>> engine;
+    private Map<String, String> parkingTickets;
+    private List<Passenger> passengers;
+
+    public Car() {
+      ArrayList<Enum<Engine>> engines = Lists.<Enum<Engine>>newArrayList(
+          new EnumImpl<Engine>(Engine.GAS, null), new EnumImpl<Engine>(Engine.HYBRID, null));
+      engine = engines;
+      parkingTickets = Maps.newHashMap();
+      parkingTickets.put("BERKELEY", "$120");
+      parkingTickets.put("TOKYO", "250Y");
+      passengers = Lists.newArrayList();
+      passengers.add(new Passenger("Dick Dastardly", Gender.male));
+      passengers.add(new Passenger("Speed Racer", Gender.female));
+    }
+
+    public Car(List<Enum<Engine>> engine, Map<String, String> parkingTickets,
+               List<Passenger> passengers) {
+      this.engine = engine;
+      this.parkingTickets = parkingTickets;
+      this.passengers = passengers;
+    }
+
+    public List<Enum<Engine>> getEngine() {
+      return engine;
+    }
+
+    public void setEngine(List<Enum<Engine>> engine) {
+      this.engine = engine;
+    }
+
+    public Map<String, String> getParkingTickets() {
+      return parkingTickets;
+    }
+
+    public void setParkingTickets(Map<String, String> parkingTickets) {
+      this.parkingTickets = parkingTickets;
+    }
+
+    public List<Passenger> getPassengers() {
+      return passengers;
+    }
+
+    public void setPassengers(List<Passenger> passengers) {
+      this.passengers = passengers;
+    }
+  }
+
+  public static class ExpensiveCar extends Car {
+    private int cost = 100000;
+
+    public int getCost() {
+      return cost;
+    }
+
+    public void setCost(int cost) {
+      this.cost = cost;
+    }
+  }
+
+  public static class Passenger {
+    private String name;
+    private Gender gender;
+
+    public Passenger() {
+      name = "Speed Racer";
+      gender = Gender.female;
+    }
+
+    public Passenger(String name, Gender gender) {
+      this.name = name;
+      this.gender = gender;
+    }
+
+    public String getName() {
+      return name;
+    }
+
+    public void setName(String name) {
+      this.name = name;
+    }
+
+    public Gender getGender() {
+      return gender;
+    }
+
+    public void setGender(Gender gender) {
+      this.gender = gender;
+    }
+  }
+
+  public enum Engine implements org.apache.shindig.protocol.model.Enum.EnumKey {
+    DIESEL("DIESEL", "Diesel"),
+    GAS("GAS", "Gas"),
+    HYBRID("HYBRID", "Hybrid"),
+    TURBO("TURBO", "Turbo");
+
+    private final String jsonString;
+    private final String displayValue;
+
+    private Engine(String jsonString, String displayValue) {
+      this.jsonString = jsonString;
+      this.displayValue = displayValue;
+    }
+
+    public String toString() {
+      return this.jsonString;
+    }
+
+    public String getDisplayValue() {
+      return displayValue;
+    }
+  }
+
+  public enum Gender {
+    male,
+    female;
+  }
+}

Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/JsonConversionUtilTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/JsonConversionUtilTest.java?rev=742816&r1=742815&r2=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/JsonConversionUtilTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/JsonConversionUtilTest.java Tue Feb 10 01:53:52 2009
@@ -17,15 +17,13 @@
  */
 package org.apache.shindig.common.util;
 
-import com.google.common.collect.Lists;
 import com.google.common.collect.ImmutableMap;
-
+import com.google.common.collect.Lists;
+import junit.framework.TestCase;
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 
-import junit.framework.TestCase;
-
 import java.util.Iterator;
 
 /**
@@ -102,7 +100,7 @@
         .fromJson(new JSONObject("{a:{b:[{c:\"hello\"},{c:\"hello\"}]}}"));
   }
 
-  private void assertJsonEquals(Object expected, Object actual)
+  public static void assertJsonEquals(Object expected, Object actual)
       throws JSONException {
     if (expected == null) {
       assertNull(actual);

Copied: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/BaseRequestItemTest.java (from r740988, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/BaseRequestItemTest.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/BaseRequestItemTest.java?p2=incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/BaseRequestItemTest.java&p1=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/BaseRequestItemTest.java&r1=740988&r2=742816&rev=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/BaseRequestItemTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/BaseRequestItemTest.java Tue Feb 10 01:53:52 2009
@@ -15,13 +15,11 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations under the License.
  */
-package org.apache.shindig.social.opensocial.service;
+package org.apache.shindig.protocol;
 
 import org.apache.shindig.common.testing.FakeGadgetToken;
-import org.apache.shindig.social.core.util.BeanJsonConverter;
-import org.apache.shindig.social.opensocial.spi.GroupId;
-import org.apache.shindig.social.opensocial.spi.PersonService;
-import org.apache.shindig.social.opensocial.spi.UserId;
+import org.apache.shindig.protocol.conversion.BeanJsonConverter;
+import org.apache.shindig.protocol.model.SortOrder;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
@@ -37,7 +35,6 @@
 
   private static final FakeGadgetToken FAKE_TOKEN = new FakeGadgetToken();
 
-  private static final String DEFAULT_PATH = "/people/john.doe/@self";
   protected BaseRequestItem request;
   protected BeanJsonConverter converter;
 
@@ -48,7 +45,7 @@
     converter = new BeanJsonConverter(Guice.createInjector());
     request = new BaseRequestItem(
         Maps.<String,String[]>newHashMap(),
-        FAKE_TOKEN, converter);
+        FAKE_TOKEN, converter, converter);
   }
 
 
@@ -65,16 +62,6 @@
     assertEquals(FAKE_TOKEN.getAppId(), request.getAppId());
   }
 
-  public void testGetUser() throws Exception {
-    request.setParameter("userId", "@owner");
-    assertEquals(UserId.Type.owner, request.getUsers().iterator().next().getType());
-  }
-
-  public void testGetGroup() throws Exception {
-    request.setParameter("groupId", "@self");
-    assertEquals(GroupId.Type.self, request.getGroup().getType());
-  }
-
   public void testStartIndex() throws Exception {
     request.setParameter("startIndex", null);
     assertEquals(RequestItem.DEFAULT_START_INDEX, request.getStartIndex());
@@ -93,10 +80,10 @@
 
   public void testSortOrder() throws Exception {
     request.setParameter("sortOrder", null);
-    assertEquals(PersonService.SortOrder.ascending, request.getSortOrder());
+    assertEquals(SortOrder.ascending, request.getSortOrder());
 
     request.setParameter("sortOrder", "descending");
-    assertEquals(PersonService.SortOrder.descending, request.getSortOrder());
+    assertEquals(SortOrder.descending, request.getSortOrder());
   }
 
   public void testFields() throws Exception {
@@ -119,7 +106,7 @@
             "userId:john.doe," +
             "groupId:@self," +
             "fields:[huey,dewey,louie]" +
-            "}"), FAKE_TOKEN, converter);
+            "}"), FAKE_TOKEN, converter, converter);
     assertEquals(Lists.newArrayList("huey", "dewey", "louie"), request.getListParameter("fields"));
   }
 

Copied: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DataCollectionTest.java (from r740988, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/spi/DataCollectionTest.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DataCollectionTest.java?p2=incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DataCollectionTest.java&p1=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/spi/DataCollectionTest.java&r1=740988&r2=742816&rev=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/spi/DataCollectionTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DataCollectionTest.java Tue Feb 10 01:53:52 2009
@@ -15,9 +15,7 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations under the License.
  */
-package org.apache.shindig.social.opensocial.spi;
-
-import org.apache.shindig.social.opensocial.spi.DataCollection;
+package org.apache.shindig.protocol;
 
 import com.google.common.collect.Maps;
 import junit.framework.TestCase;

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

Copied: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DataServiceServletTest.java (from r740988, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/DataServiceServletTest.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DataServiceServletTest.java?p2=incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DataServiceServletTest.java&p1=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/DataServiceServletTest.java&r1=740988&r2=742816&rev=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/DataServiceServletTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DataServiceServletTest.java Tue Feb 10 01:53:52 2009
@@ -15,23 +15,17 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations under the License.
  */
-package org.apache.shindig.social.opensocial.service;
+package org.apache.shindig.protocol;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.shindig.auth.AuthInfo;
 import org.apache.shindig.common.testing.FakeGadgetToken;
 import org.apache.shindig.common.testing.FakeHttpServletRequest;
-import org.apache.shindig.social.ResponseError;
-import org.apache.shindig.social.SocialApiTestsGuiceModule;
-import org.apache.shindig.social.core.util.BeanJsonConverter;
-import org.apache.shindig.social.core.util.BeanXStreamAtomConverter;
-import org.apache.shindig.social.core.util.BeanXStreamConverter;
-import org.apache.shindig.social.core.util.xstream.XStream081Configuration;
+import org.apache.shindig.protocol.conversion.BeanConverter;
+import org.apache.shindig.protocol.conversion.BeanJsonConverter;
 
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Lists;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
 import junit.framework.TestCase;
 import org.easymock.IMocksControl;
 import org.easymock.classextension.EasyMock;
@@ -51,6 +45,9 @@
   private HttpServletResponse res;
   private DataServiceServlet servlet;
   private BeanJsonConverter jsonConverter;
+  private BeanConverter xmlConverter;
+  private BeanConverter atomConverter;
+
 
   private IMocksControl mockControl = EasyMock.createNiceControl();
 
@@ -65,15 +62,15 @@
     req = mockControl.createMock(HttpServletRequest.class);
     res = mockControl.createMock(HttpServletResponse.class);
     jsonConverter = mockControl.createMock(BeanJsonConverter.class);
-    BeanXStreamConverter xmlConverter = mockControl.createMock(BeanXStreamConverter.class);
-    BeanXStreamAtomConverter atomConverter = mockControl.createMock(BeanXStreamAtomConverter.class);
+    xmlConverter = mockControl.createMock(BeanConverter.class);
+    atomConverter = mockControl.createMock(BeanConverter.class);
 
     EasyMock.expect(jsonConverter.getContentType()).andReturn("application/json").anyTimes();
     EasyMock.expect(xmlConverter.getContentType()).andReturn("application/xml").anyTimes();
     EasyMock.expect(atomConverter.getContentType()).andReturn("application/atom+xml").anyTimes();
 
     HandlerRegistry registry = new DefaultHandlerRegistry(null,
-        Lists.newArrayList(new TestHandler()));
+        Lists.newArrayList(new TestHandler()), jsonConverter);
 
     servlet.setHandlerRegistry(registry);
 
@@ -118,7 +115,7 @@
     verifyHandlerWasFoundForPathInfo(route, "POST", "GET");
   }
 
-  public void testOverrideGetWithPost() throws Exception {
+  public void  testOverrideGetWithPost() throws Exception {
     String route = "/test";
     verifyHandlerWasFoundForPathInfo(route, "GET", "POST");
   }
@@ -141,8 +138,6 @@
     mockControl.reset();
   }
 
-
-
   private void setupRequest(String pathInfo, String actualMethod, String overrideMethod)
       throws IOException {
     FakeHttpServletRequest fakeReq = new FakeHttpServletRequest("/social/rest", pathInfo, "");
@@ -158,33 +153,19 @@
   }
 
   public void testGetConverterForRequest() throws Exception {
-
-    Injector injector = Guice.createInjector(new SocialApiTestsGuiceModule());
-    BeanJsonConverter json = new BeanJsonConverter(injector);
-    BeanXStreamConverter xml = new BeanXStreamConverter(new XStream081Configuration(injector));
-    BeanXStreamAtomConverter atom = new BeanXStreamAtomConverter(new XStream081Configuration(injector));
-    servlet.setBeanConverters(json, xml, atom);
-
-    assertConverter(atom, "atom");
-    assertConverter(xml, "xml");
-    assertConverter(json, "");
-    assertConverter(json, null);
-    assertConverter(json, "ahhhh!");
+    assertConverter(atomConverter, "atom");
+    assertConverter(xmlConverter, "xml");
+    assertConverter(jsonConverter, "");
+    assertConverter(jsonConverter, null);
+    assertConverter(jsonConverter, "ahhhh!");
   }
 
   public void testGetConverterForRequestContentType() throws Exception {
-    Injector injector = Guice.createInjector(new SocialApiTestsGuiceModule());
-    BeanJsonConverter json = new BeanJsonConverter(injector);
-    BeanXStreamConverter xml = new BeanXStreamConverter(new XStream081Configuration(injector));
-    BeanXStreamAtomConverter atom = new BeanXStreamAtomConverter(new XStream081Configuration(injector));
-    servlet.setBeanConverters(json, xml, atom);
-
-    assertConverterForContentType(atom, "application/atom+xml");
-    assertConverterForContentType(xml, "application/xml");
-    assertConverterForContentType(json, "");
-    assertConverterForContentType(json, null);
-    assertConverterForContentType(json, "abcd!");
-
+    assertConverterForContentType(atomConverter, "application/atom+xml");
+    assertConverterForContentType(xmlConverter, "application/xml");
+    assertConverterForContentType(jsonConverter, "");
+    assertConverterForContentType(jsonConverter, null);
+    assertConverterForContentType(jsonConverter, "abcd!");
   }
 
   private void assertConverter(BeanConverter converter, String format) {

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

Copied: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DefaultHandlerRegistryTest.java (from r740988, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/DefaultHandlerRegistryTest.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DefaultHandlerRegistryTest.java?p2=incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DefaultHandlerRegistryTest.java&p1=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/DefaultHandlerRegistryTest.java&r1=740988&r2=742816&rev=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/DefaultHandlerRegistryTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DefaultHandlerRegistryTest.java Tue Feb 10 01:53:52 2009
@@ -16,14 +16,13 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.shindig.social.opensocial.service;
+package org.apache.shindig.protocol;
 
-import org.apache.shindig.social.ResponseError;
-import org.apache.shindig.social.opensocial.spi.SocialSpiException;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
+import junit.framework.Assert;
 import junit.framework.TestCase;
 import org.json.JSONObject;
 
@@ -42,7 +41,7 @@
   protected void setUp() throws Exception {
     super.setUp();
     registry = new DefaultHandlerRegistry(null,
-        Lists.newArrayList(new TestHandler()));
+        Lists.newArrayList(new TestHandler()), null);
   }
 
   public void testGetHandlerRPC() throws Exception {
@@ -73,8 +72,8 @@
       future.get();
       fail("Expect exception for missing method");
     } catch (ExecutionException t) {
-      assertEquals(t.getCause().getClass(), SocialSpiException.class);
-      assertEquals(((SocialSpiException) t.getCause()).getError(), ResponseError.NOT_IMPLEMENTED);
+      assertEquals(t.getCause().getClass(), ProtocolException.class);
+      Assert.assertEquals(((ProtocolException) t.getCause()).getError(), ResponseError.NOT_IMPLEMENTED);
     } catch (Throwable t) {
       fail("Unexpected exception " + t.toString());
     }
@@ -88,8 +87,8 @@
       future.get();
       fail("Expect exception for missing method");
     } catch (ExecutionException t) {
-      assertEquals(t.getCause().getClass(), SocialSpiException.class);
-      assertEquals(((SocialSpiException) t.getCause()).getError(), ResponseError.NOT_IMPLEMENTED);
+      assertEquals(t.getCause().getClass(), ProtocolException.class);
+      Assert.assertEquals(((ProtocolException) t.getCause()).getError(), ResponseError.NOT_IMPLEMENTED);
     } catch (Throwable t) {
       fail("Unexpected exception " + t.toString());
     }
@@ -131,7 +130,7 @@
       future.get();
       fail("Service method did not produce ExecutionException from Future");
     } catch (ExecutionException ee) {
-      assertEquals(ee.getCause().getClass(), SocialSpiException.class);
+      assertEquals(ee.getCause().getClass(), ProtocolException.class);
     }
   }
 

Added: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/JsonRpcServletTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/JsonRpcServletTest.java?rev=742816&view=auto
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/JsonRpcServletTest.java (added)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/JsonRpcServletTest.java Tue Feb 10 01:53:52 2009
@@ -0,0 +1,194 @@
+/*
+ * 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.protocol;
+
+import org.apache.shindig.common.testing.FakeGadgetToken;
+import org.apache.shindig.protocol.conversion.BeanConverter;
+import org.apache.shindig.protocol.conversion.BeanJsonConverter;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+import junit.framework.TestCase;
+import org.easymock.IMocksControl;
+import org.easymock.classextension.EasyMock;
+import org.json.JSONArray;
+import org.json.JSONObject;
+
+import javax.servlet.ServletInputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+
+/**
+ *
+ */
+public class JsonRpcServletTest extends TestCase {
+
+  private static final FakeGadgetToken FAKE_GADGET_TOKEN = new FakeGadgetToken()
+      .setOwnerId("john.doe").setViewerId("john.doe");
+
+  private HttpServletRequest req;
+  private HttpServletResponse res;
+  private JsonRpcServlet servlet;
+
+  private BeanJsonConverter jsonConverter;
+  private BeanConverter xmlConverter;
+  protected BeanConverter atomConverter;
+
+  private IMocksControl mockControl = EasyMock.createNiceControl();
+
+
+  @Override protected void setUp() throws Exception {
+    servlet = new JsonRpcServlet();
+    req = mockControl.createMock(HttpServletRequest.class);
+    res = mockControl.createMock(HttpServletResponse.class);
+    jsonConverter = mockControl.createMock(BeanJsonConverter.class);
+    xmlConverter = mockControl.createMock(BeanConverter.class);
+    atomConverter = mockControl.createMock(BeanConverter.class);
+
+    HandlerRegistry registry = new DefaultHandlerRegistry(null,
+        Lists.newArrayList(new TestHandler()), jsonConverter);
+
+    servlet.setHandlerRegistry(registry);
+    servlet.setBeanConverters(jsonConverter, xmlConverter, atomConverter);
+  }
+
+  public void testMethodRecognition() throws Exception {
+    setupRequest("{method:test.get,id:id,params:{userId:5,groupId:@self}}");
+
+    EasyMock.expect(jsonConverter.convertToJson(TestHandler.GET_RESPONSE))
+        .andReturn(new JSONObject(ImmutableMap.of("foo", "bar")));
+
+    JSONObject result = new JSONObject();
+    result.put("id", "id");
+    result.put("data", ImmutableMap.of("foo", "bar"));
+    PrintWriter writerMock = mockControl.createMock(PrintWriter.class);
+    EasyMock.expect(res.getWriter()).andReturn(writerMock);
+    writerMock.write(EasyMock.eq(result.toString()));
+    EasyMock.expectLastCall();
+
+    mockControl.replay();
+    servlet.service(req, res);
+    mockControl.verify();
+    mockControl.reset();
+  }
+
+  public void testInvalidService() throws Exception {
+    String json = "{method:junk.get,id:id,params:{userId:5,groupId:@self}}";
+    setupRequest(json);
+
+    JSONObject err = new JSONObject(
+        "{id:id,error:{message:'notImplemented: The method junk.get is not implemented',code:501}}");
+
+    PrintWriter writerMock = mockControl.createMock(PrintWriter.class);
+    EasyMock.expect(res.getWriter()).andReturn(writerMock);
+    writerMock.write(EasyMock.eq(err.toString()));
+    EasyMock.expectLastCall();
+
+    mockControl.replay();
+    servlet.service(req, res);
+    mockControl.verify();
+    mockControl.reset();
+  }
+
+
+  /**
+   * Tests a data handler that returns a failed Future.
+   * @throws Exception on failure
+   */
+  public void testFailedRequest() throws Exception {
+    setupRequest("{id:id,method:test.futureException}");
+
+    JSONObject err = new JSONObject(
+        "{id:id,error:{message:'badRequest: FAILURE_MESSAGE',code:400}}");
+
+    PrintWriter writerMock = mockControl.createMock(PrintWriter.class);
+    EasyMock.expect(res.getWriter()).andReturn(writerMock);
+    writerMock.write(EasyMock.eq(err.toString()));
+    EasyMock.expectLastCall();
+
+    mockControl.replay();
+    servlet.service(req, res);
+    mockControl.verify();
+    mockControl.reset();
+  }
+
+  public void testBasicBatch() throws Exception {
+    String batchJson =
+        "[{method:test.get,id:'1'},{method:test.get,id:'2'}]";
+    setupRequest(batchJson);
+
+    EasyMock.expect(jsonConverter.convertToJson(TestHandler.GET_RESPONSE))
+        .andStubReturn(new JSONObject(ImmutableMap.of("foo", "bar")));
+
+    JSONArray result = new JSONArray("[{id:'1',data:{foo:'bar'}}," + "{id:'2',data:{foo:'bar'}}]");
+    PrintWriter writerMock = mockControl.createMock(PrintWriter.class);
+    EasyMock.expect(res.getWriter()).andReturn(writerMock);
+    writerMock.write(EasyMock.eq(result.toString()));
+    EasyMock.expectLastCall();
+
+    mockControl.replay();
+    servlet.service(req, res);
+    mockControl.verify();
+    mockControl.reset();
+  }
+
+  public void testGetExecution() throws Exception {
+    EasyMock.expect(req.getParameterMap()).andStubReturn(
+        ImmutableMap.of("method", new String[]{"test.get"}, "id", new String[]{"1"}));
+    EasyMock.expect(req.getMethod()).andStubReturn("GET");
+    EasyMock.expect(req.getAttribute(EasyMock.isA(String.class))).andReturn(FAKE_GADGET_TOKEN);
+    EasyMock.expect(req.getCharacterEncoding()).andStubReturn("UTF-8");
+    res.setCharacterEncoding("UTF-8");
+
+    EasyMock.expect(jsonConverter.convertToJson(TestHandler.GET_RESPONSE))
+        .andReturn(new JSONObject(ImmutableMap.of("foo", "bar")));
+
+    JSONObject result = new JSONObject("{id:'1',data:{foo:'bar'}}");
+    PrintWriter writerMock = mockControl.createMock(PrintWriter.class);
+    EasyMock.expect(res.getWriter()).andReturn(writerMock);
+    writerMock.write(EasyMock.eq(result.toString()));
+    EasyMock.expectLastCall();
+
+    mockControl.replay();
+    servlet.service(req, res);
+    mockControl.verify();
+    mockControl.reset();
+  }
+
+  private void setupRequest(String json) throws IOException {
+    final InputStream in = new ByteArrayInputStream(json.getBytes());
+    ServletInputStream stream = new ServletInputStream() {
+      @Override
+      public int read() throws IOException {
+        return in.read();
+      }
+    };
+
+    EasyMock.expect(req.getInputStream()).andStubReturn(stream);
+    EasyMock.expect(req.getMethod()).andStubReturn("POST");
+    EasyMock.expect(req.getAttribute(EasyMock.isA(String.class))).andReturn(FAKE_GADGET_TOKEN);
+    EasyMock.expect(req.getCharacterEncoding()).andStubReturn("UTF-8");
+    res.setCharacterEncoding("UTF-8");
+    res.setContentType("application/json");
+  }
+
+}

Copied: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/RestfulCollectionTest.java (from r740988, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/spi/RestfulCollectionTest.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/RestfulCollectionTest.java?p2=incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/RestfulCollectionTest.java&p1=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/spi/RestfulCollectionTest.java&r1=740988&r2=742816&rev=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/spi/RestfulCollectionTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/RestfulCollectionTest.java Tue Feb 10 01:53:52 2009
@@ -15,9 +15,7 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations under the License.
  */
-package org.apache.shindig.social.opensocial.spi;
-
-import org.apache.shindig.social.opensocial.spi.RestfulCollection;
+package org.apache.shindig.protocol;
 
 import com.google.common.collect.Lists;
 import junit.framework.TestCase;

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

Copied: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/TestHandler.java (from r740988, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/TestHandler.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/TestHandler.java?p2=incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/TestHandler.java&p1=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/TestHandler.java&r1=740988&r2=742816&rev=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/TestHandler.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/TestHandler.java Tue Feb 10 01:53:52 2009
@@ -16,11 +16,9 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.shindig.social.opensocial.service;
+package org.apache.shindig.protocol;
 
 import org.apache.shindig.common.util.ImmediateFuture;
-import org.apache.shindig.social.ResponseError;
-import org.apache.shindig.social.opensocial.spi.SocialSpiException;
 
 import com.google.common.collect.ImmutableMap;
 import org.junit.Ignore;
@@ -81,7 +79,7 @@
     if (mock != null) {
       return mock.futureException(req);
     }
-    return ImmediateFuture.errorInstance(new SocialSpiException(ResponseError.BAD_REQUEST,
+    return ImmediateFuture.errorInstance(new ProtocolException(ResponseError.BAD_REQUEST,
         FAILURE_MESSAGE, new Throwable()));
   }
 

Copied: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonConverterTest.java (from r740988, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanJsonConverterTest.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonConverterTest.java?p2=incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonConverterTest.java&p1=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanJsonConverterTest.java&r1=740988&r2=742816&rev=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanJsonConverterTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonConverterTest.java Tue Feb 10 01:53:52 2009
@@ -15,22 +15,12 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations under the License.
  */
-package org.apache.shindig.social.opensocial.util;
+package org.apache.shindig.protocol.conversion;
 
-import org.apache.shindig.social.SocialApiTestsGuiceModule;
-import org.apache.shindig.social.core.model.ActivityImpl;
-import org.apache.shindig.social.core.model.AddressImpl;
-import org.apache.shindig.social.core.model.ListFieldImpl;
-import org.apache.shindig.social.core.model.MediaItemImpl;
-import org.apache.shindig.social.core.model.NameImpl;
-import org.apache.shindig.social.core.model.PersonImpl;
-import org.apache.shindig.social.core.util.BeanJsonConverter;
-import org.apache.shindig.social.opensocial.model.Activity;
-import org.apache.shindig.social.opensocial.model.Address;
-import org.apache.shindig.social.opensocial.model.ListField;
-import org.apache.shindig.social.opensocial.model.MediaItem;
-import org.apache.shindig.social.opensocial.model.Person;
+import org.apache.shindig.common.util.JsonConversionUtilTest;
+import org.apache.shindig.protocol.model.TestModel;
 
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.inject.Guice;
@@ -38,110 +28,52 @@
 import org.json.JSONArray;
 import org.json.JSONObject;
 
+import java.util.ArrayList;
 import java.util.Map;
 import java.util.Map.Entry;
 
 public class BeanJsonConverterTest extends TestCase {
-  private Person johnDoe;
-  private Activity activity;
-
+  private TestModel.Car car;
   private BeanJsonConverter beanJsonConverter;
 
   @Override
   public void setUp() throws Exception {
     super.setUp();
-    johnDoe = new PersonImpl("johnDoeId", "Johnny", new NameImpl("John Doe"));
-    johnDoe.setPhoneNumbers(Lists.<ListField>newArrayList(
-        new ListFieldImpl("home", "+33H000000000"),
-        new ListFieldImpl("mobile", "+33M000000000"),
-        new ListFieldImpl("work", "+33W000000000")));
-
-    johnDoe.setAddresses(Lists.<Address>newArrayList(new AddressImpl("My home address")));
-
-    johnDoe.setEmails(Lists.<ListField>newArrayList(
-        new ListFieldImpl("work", "john.doe@work.bar"),
-        new ListFieldImpl("home", "john.doe@home.bar")));
-
-    activity = new ActivityImpl("activityId", johnDoe.getId());
-
-    activity.setMediaItems(Lists.<MediaItem>newArrayList(
-        new MediaItemImpl("image/jpg", MediaItem.Type.IMAGE, "http://foo.bar")));
-
-    beanJsonConverter = new BeanJsonConverter(
-        Guice.createInjector(new SocialApiTestsGuiceModule()));
-  }
-
-  public static class SpecialPerson extends PersonImpl {
-    private String newfield;
-
-    public SpecialPerson(String id, String name, String newfield) {
-      super(id, name, new NameImpl(name));
-      this.newfield = newfield;
-    }
-
-    public String getNewfield() {
-      return newfield;
-    }
+    car = new TestModel.Car();
+    beanJsonConverter = new BeanJsonConverter(Guice.createInjector());
   }
 
   public void testToJsonOnInheritedClass() throws Exception {
-    SpecialPerson cassie = new SpecialPerson("5", "robot", "nonsense");
-
-    JSONObject result = (JSONObject) beanJsonConverter.convertToJson(cassie);
-    assertEquals(cassie.getId(), result.getString("id"));
-    assertEquals(cassie.getNewfield(), result.getString("newfield"));
+    TestModel.ExpensiveCar roller = new TestModel.ExpensiveCar();
+    JSONObject result = (JSONObject) beanJsonConverter.convertToJson(roller);
+    assertEquals(roller.getCost(), result.getInt("cost"));
+    assertEquals(roller.getParkingTickets().size(), result.getJSONObject("parkingTickets").length());
   }
 
-  public void testPersonToJson() throws Exception {
-    JSONObject result = (JSONObject) beanJsonConverter.convertToJson(johnDoe);
-
-    assertEquals(johnDoe.getId(), result.getString("id"));
-
-    assertEquals(johnDoe.getName().getFormatted(),
-        result.getJSONObject("name").getString("formatted"));
-
-    assertEquals(johnDoe.getAddresses().get(0).getFormatted(),
-        result.getJSONArray("addresses").getJSONObject(0)
-            .getString("formatted"));
-
-    JSONArray phoneArray = result.getJSONArray("phoneNumbers");
-    assertEquals(3, phoneArray.length());
-
-    for (int i = 0; i < johnDoe.getPhoneNumbers().size(); i++) {
-      ListField expectedPhone = johnDoe.getPhoneNumbers().get(i);
-      JSONObject actualPhone = phoneArray.getJSONObject(i);
-      assertEquals(expectedPhone.getType(), actualPhone.getString("type"));
-      assertEquals(expectedPhone.getValue(), actualPhone.getString("value"));
-    }
-
-    JSONArray emailArray = result.getJSONArray("emails");
-    assertEquals(2, emailArray.length());
-
-    for (int i = 0; i < johnDoe.getEmails().size(); i++) {
-      ListField expectedEmail = johnDoe.getEmails().get(i);
-      JSONObject actualEmail = emailArray.getJSONObject(i);
-      assertEquals(expectedEmail.getType(), actualEmail.getString("type"));
-      assertEquals(expectedEmail.getValue(),
-          actualEmail.getString("value"));
-    }
+  public void testCarToJson() throws Exception {
+    JSONObject result = (JSONObject) beanJsonConverter.convertToJson(car);
+    JsonConversionUtilTest.assertJsonEquals(new JSONObject(TestModel.Car.DEFAULT_JSON), result);
   }
 
-  public void testActivityToJson() throws Exception {
-    JSONObject result = (JSONObject) beanJsonConverter.convertToJson(activity);
 
-    assertEquals(activity.getUserId(), result.getString("userId"));
-    assertEquals(activity.getId(), result.getString("id"));
+  public void testJsonToCar() throws Exception {
+    String carJson = "{engine:[{value:DIESEL},{value:TURBO}],parkingTickets:{SF:$137,NY:'$301'}," +
+            "passengers:[{gender:female,name:'Mum'}, {gender:male,name:'Dad'}]}";
 
-    JSONArray mediaItemsArray = result.getJSONArray("mediaItems");
-    assertEquals(1, mediaItemsArray.length());
+    TestModel.Car car = beanJsonConverter.convertToObject(carJson, TestModel.Car.class);
+    ArrayList<TestModel.Engine> engineInfo = Lists.newArrayList(TestModel.Engine.DIESEL,
+        TestModel.Engine.TURBO);
+    for (int i = 0; i < car.getEngine().size(); i++) {
+      assertEquals(car.getEngine().get(i).getValue(), engineInfo.get(i));
+    }
 
-    MediaItem expectedItem = activity.getMediaItems().get(0);
-    JSONObject actualItem = mediaItemsArray.getJSONObject(0);
-
-    assertEquals(expectedItem.getUrl(), actualItem.getString("url"));
-    assertEquals(expectedItem.getMimeType(), actualItem.getString("mimeType"));
-    assertEquals(expectedItem.getType().toString(),
-        actualItem.getString("type"));
+    assertEquals(car.getParkingTickets(), ImmutableMap.of("SF", "$137", "NY", "$301"));
+    TestModel.Passenger mum = car.getPassengers().get(0);
+    assertEquals(mum.getGender(), TestModel.Gender.female);
+    assertEquals(mum.getName(), "Mum");
+    TestModel.Passenger dad = car.getPassengers().get(1);
+    assertEquals(dad.getGender(), TestModel.Gender.male);
+    assertEquals(dad.getName(), "Dad");
   }
 
   public void testMapsToJson() throws Exception {
@@ -187,26 +119,6 @@
     assertEquals(colors[0], jsonArray.get(0));
   }
 
-  public void testJsonToActivity() throws Exception {
-    String jsonActivity = "{userId : 5, id : 6, mediaItems : ["
-      + "{url : 'hello', mimeType : 'mimey', type : 'video'}"
-      + "]}";
-    // TODO: rename the enums to be lowercase
-    Activity result = beanJsonConverter.convertToObject(jsonActivity,
-        Activity.class);
-
-    assertEquals("5", result.getUserId());
-    assertEquals("6", result.getId());
-
-    assertEquals(1, result.getMediaItems().size());
-
-    MediaItem actualItem = result.getMediaItems().get(0);
-
-    assertEquals("hello", actualItem.getUrl());
-    assertEquals("mimey", actualItem.getMimeType());
-    assertEquals("video", actualItem.getType().toString());
-  }
-
   @SuppressWarnings("unchecked")
   public void testJsonToMap() throws Exception {
     String jsonActivity = "{count : 0, favoriteColor : 'yellow'}";
@@ -226,14 +138,4 @@
       }
     }
   }
-
-  public void testJsonToPerson() throws Exception {
-    String jsonPerson = "{age : '10', hasApp : 'true', isViewer : 'true'}";
-    Person result = beanJsonConverter.convertToObject(jsonPerson, Person.class);
-
-    assertEquals(10, result.getAge().intValue());
-    assertTrue(result.getHasApp().booleanValue());
-    assertTrue(result.getIsViewer());
-  }
-
 }

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