
    >>> from ftw.publisher.receiver import tests
    >>> from ftw.publisher.receiver.decoder import Decoder
    >>> from Products.PloneTestCase.setup import portal_owner
    >>> import os.path

    >>> decoder = Decoder(self.portal)

    >>> def get_json_from_file(filename):
    ...     directory = os.path.dirname(tests.__file__)
    ...     return open(os.path.join(directory, 'jobs', filename)).read()

Test decoding json data:

    >>> decoder.decodeJson('erroneous data')
    Traceback (most recent call last):
    ...
    DecodeError: No JSON object could be decoded

When the sender encodes to JSON, it prefixes all strings with
the encoding, since some tools and components in plone need to
utf8-encoded strings, others need unicode, etc.

    >>> decoder.decodeJson('["unicode:foo", "utf8:bar"]')
    [u'foo', 'bar']

We don't need to test that further, since the function which
converts the strings is tested in ftw.publisher.core package.


The validation assures, that the needed metadata are provided

    >>> decoder.data = dict(metadata={
    ...     'UID': 'foobar123',
    ...     'id': 'foo',
    ...     'portal_type': 'Folder',
    ...     'action': 'push',
    ...     'physicalPath': '/platform/foo',
    ...     'sibling_positions': []
    ...     })
    >>> decoder.validate()

    >>> del decoder.data['metadata']['portal_type']
    >>> decoder.validate()
    Traceback (most recent call last):
    ...
    PartialError: Missing "metadata.portal_type"

    >>> decoder.data = dict()
    >>> decoder.validate()
    Traceback (most recent call last):
    ...
    PartialError: Missing "metadata"


For getting the schema and unserializing the fields, the
object is already created. So let's create the object for
testing those methods.

    >>> jsondata = get_json_from_file('basic_folder.json')
    >>> decoder = Decoder(self.portal)
    >>> foo = decoder(jsondata)

    >>> obj = self.folder.get(self.folder.invokeFactory('Folder', 'foo'))
    >>> obj._setUID(decoder.data['metadata']['UID'])

    >>> schema = decoder.getSchema(obj)
    >>> schema
    <Products.Archetypes.Schema.Schema object at ...>

    >>> self.folder.manage_delObjects(['foo'])

