1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.internal.observation.remote.converter

File DocumentEventConverterTest.java

 

Code metrics

0
21
1
1
82
43
1
0.05
21
1
1

Classes

Class Line # Actions
DocumentEventConverterTest 44 21 0% 1 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.internal.observation.remote.converter;
21   
22    import java.io.ByteArrayInputStream;
23    import java.io.ByteArrayOutputStream;
24    import java.io.ObjectInputStream;
25    import java.io.ObjectOutputStream;
26   
27    import org.junit.Assert;
28    import org.junit.Test;
29    import org.xwiki.bridge.event.DocumentUpdatedEvent;
30    import org.xwiki.model.reference.DocumentReference;
31    import org.xwiki.observation.remote.LocalEventData;
32    import org.xwiki.observation.remote.RemoteEventData;
33    import org.xwiki.observation.remote.converter.EventConverterManager;
34   
35    import com.xpn.xwiki.XWikiContext;
36    import com.xpn.xwiki.doc.XWikiDocument;
37    import com.xpn.xwiki.test.AbstractBridgedComponentTestCase;
38   
39    /**
40    * Validate {@link DocumentEventConverter};
41    *
42    * @version $Id: e6442d99590bc155320e6aa9df39577109a31fe8 $
43    */
 
44    public class DocumentEventConverterTest extends AbstractBridgedComponentTestCase
45    {
 
46  1 toggle @Test
47    public void testConvertWithOriginalDocNull() throws Exception
48    {
49  1 EventConverterManager eventConverterManager = getComponentManager().getInstance(EventConverterManager.class);
50   
51    // local -> remote
52   
53  1 LocalEventData localEvent = new LocalEventData();
54  1 localEvent.setEvent(new DocumentUpdatedEvent(new DocumentReference("wiki","space","page")));
55  1 localEvent.setSource(new XWikiDocument(new DocumentReference("wiki", "space", "page")));
56  1 localEvent.setData(getContext());
57   
58  1 RemoteEventData remoteEvent = eventConverterManager.createRemoteEventData(localEvent);
59   
60  1 Assert.assertFalse(remoteEvent.getSource() instanceof XWikiDocument);
61  1 Assert.assertFalse(remoteEvent.getData() instanceof XWikiContext);
62   
63    // serialize/unserialize
64  1 ByteArrayOutputStream sos = new ByteArrayOutputStream();
65  1 ObjectOutputStream oos = new ObjectOutputStream(sos);
66  1 oos.writeObject(remoteEvent);
67  1 ByteArrayInputStream sis = new ByteArrayInputStream(sos.toByteArray());
68  1 ObjectInputStream ois = new ObjectInputStream(sis);
69  1 remoteEvent = (RemoteEventData) ois.readObject();
70   
71    // remote -> local
72   
73  1 LocalEventData localEvent2 = eventConverterManager.createLocalEventData(remoteEvent);
74   
75  1 Assert.assertTrue(localEvent2.getSource() instanceof XWikiDocument);
76  1 Assert.assertTrue(localEvent2.getData() instanceof XWikiContext);
77  1 Assert.assertEquals("wiki", ((XWikiDocument) localEvent2.getSource()).getWikiName());
78  1 Assert.assertEquals("space", ((XWikiDocument) localEvent2.getSource()).getSpaceName());
79  1 Assert.assertEquals("page", ((XWikiDocument) localEvent2.getSource()).getPageName());
80  1 Assert.assertTrue(((XWikiDocument) localEvent2.getSource()).getOriginalDocument().isNew());
81    }
82    }