use of org.xwiki.observation.remote.converter.EventConverterManager in project xwiki-platform by xwiki.
the class DocumentEventConverterTest method testConvertWithOriginalDocNull.
@Test
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);
Assert.assertFalse(remoteEvent.getSource() instanceof XWikiDocument);
Assert.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);
Assert.assertTrue(localEvent2.getSource() instanceof XWikiDocument);
Assert.assertTrue(localEvent2.getData() instanceof XWikiContext);
Assert.assertEquals("wiki", ((XWikiDocument) localEvent2.getSource()).getWikiName());
Assert.assertEquals("space", ((XWikiDocument) localEvent2.getSource()).getSpaceName());
Assert.assertEquals("page", ((XWikiDocument) localEvent2.getSource()).getPageName());
Assert.assertTrue(((XWikiDocument) localEvent2.getSource()).getOriginalDocument().isNew());
}
Aggregations