1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
@link |
41 |
|
|
42 |
|
@version |
43 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 1 |
Complexity Density: 0.05 |
|
44 |
|
public class DocumentEventConverterTest extends AbstractBridgedComponentTestCase |
45 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
46 |
1 |
@Test... |
47 |
|
public void testConvertWithOriginalDocNull() throws Exception |
48 |
|
{ |
49 |
1 |
EventConverterManager eventConverterManager = getComponentManager().getInstance(EventConverterManager.class); |
50 |
|
|
51 |
|
|
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 |
|
|
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 |
|
|
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 |
|
} |