/*
 * 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 java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import org.xwiki.bridge.event.DocumentUpdatedEvent;
import org.xwiki.model.reference.DocumentReference;
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().getInstance(EventConverterManager.class);

        // local -> remote

        LocalEventData localEvent = new LocalEventData();
        localEvent.setEvent(new DocumentUpdatedEvent(new DocumentReference("wiki","space","page")));
        localEvent.setSource(new XWikiDocument(new DocumentReference("wiki", "space", "page")));
        localEvent.setData(getContext());

        RemoteEventData remoteEvent = eventConverterManager.createRemoteEventData(localEvent);

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

        // serialize/unserialize
        ByteArrayOutputStream sos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(sos);
        oos.writeObject(remoteEvent);
        ByteArrayInputStream sis = new ByteArrayInputStream(sos.toByteArray());
        ObjectInputStream ois = new ObjectInputStream(sis);
        remoteEvent = (RemoteEventData) ois.readObject();

        // remote -> local

        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());
    }
}

@@ -1094,16 +1094,64 @@
 tream;%0A%0A
+import org.junit.Assert;%0Aimport org.junit.Test;%0A
 import o
@@ -1529,37 +1529,32 @@
 .AbstractBridged
-XWiki
 ComponentTestCas
@@ -1693,21 +1693,16 @@
 tBridged
-XWiki
 Componen
@@ -1713,16 +1713,26 @@
 tCase%0A%7B%0A
+    @Test%0A
     publ
@@ -2337,32 +2337,39 @@
 vent);%0A%0A        
+Assert.
 assertFalse(remo
@@ -2419,24 +2419,31 @@
 t);%0A        
+Assert.
 assertFalse(
@@ -3011,32 +3011,39 @@
 vent);%0A%0A        
+Assert.
 assertTrue(local
@@ -3088,32 +3088,39 @@
 ument);%0A        
+Assert.
 assertTrue(local
@@ -3162,32 +3162,39 @@
 ntext);%0A        
+Assert.
 assertEquals(%22wi
@@ -3256,32 +3256,39 @@
 ame());%0A        
+Assert.
 assertEquals(%22sp
@@ -3356,24 +3356,31 @@
 ));%0A        
+Assert.
 assertEquals
@@ -3454,16 +3454,23 @@
         
+Assert.
 assertTr

Update test