/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package com.xpn.xwiki.internal.observation.remote.converter;

import org.xwiki.observation.event.DocumentUpdateEvent;
import org.xwiki.observation.remote.LocalEventData;
import org.xwiki.observation.remote.RemoteEventData;
import org.xwiki.observation.remote.converter.EventConverterManager;

import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.test.AbstractBridgedXWikiComponentTestCase;

/**
 * Validate {@link DocumentEventConverter};
 * 
 * @version $Id$
 */
public class DocumentEventConverterTest extends AbstractBridgedXWikiComponentTestCase
{
    public void testConvertWithOriginalDocNull() throws Exception
    {
        EventConverterManager eventConverterManager = getComponentManager().lookup(EventConverterManager.class);

        LocalEventData localEvent = new LocalEventData();
        localEvent.setEvent(new DocumentUpdateEvent("wiki:space.page"));
        localEvent.setSource(new XWikiDocument("wiki", "space", "page"));
        localEvent.setData(new XWikiContext());

        RemoteEventData remoteEvent = eventConverterManager.createRemoteEventData(localEvent);

        assertFalse(remoteEvent.getSource() instanceof XWikiDocument);
        assertFalse(remoteEvent.getData() instanceof XWikiContext);

        LocalEventData localEvent2 = eventConverterManager.createLocalEventData(remoteEvent);

        assertTrue(localEvent2.getSource() instanceof XWikiDocument);
        assertTrue(localEvent2.getData() instanceof XWikiContext);
        assertEquals("wiki", ((XWikiDocument) localEvent2.getSource()).getWikiName());
        assertEquals("space", ((XWikiDocument) localEvent2.getSource()).getSpaceName());
        assertEquals("page", ((XWikiDocument) localEvent2.getSource()).getPageName());
        assertTrue(((XWikiDocument) localEvent2.getSource()).getOriginalDocument().isNew());
    }
}

@@ -945,24 +945,169 @@
 converter;%0A%0A
+import java.io.ByteArrayInputStream;%0Aimport java.io.ByteArrayOutputStream;%0Aimport java.io.ObjectInputStream;%0Aimport java.io.ObjectOutputStream;%0A%0A
 import org.x
@@ -1146,24 +1146,24 @@
 pdateEvent;%0A
-
 import org.x
@@ -1809,24 +1809,52 @@
 er.class);%0A%0A
+        // local -%3E remote%0A%0A
         Loca
@@ -2254,32 +2254,32 @@
 XWikiDocument);%0A
-
         assertFa
@@ -2327,24 +2327,449 @@
 iContext);%0A%0A
+        // serialize/unserialize%0A        ByteArrayOutputStream sos = new ByteArrayOutputStream();%0A        ObjectOutputStream oos = new ObjectOutputStream(sos);%0A        oos.writeObject(remoteEvent);%0A        ByteArrayInputStream sis = new ByteArrayInputStream(sos.toByteArray());%0A        ObjectInputStream ois = new ObjectInputStream(sis);%0A        remoteEvent = (RemoteEventData) ois.readObject();%0A%0A        // remote -%3E local%0A%0A
         Loca

Make the whole core use Observation component instead of the old notification system * improve unit test