Search in sources :

Example 16 with DocumentUpdatedEvent

use of org.xwiki.bridge.event.DocumentUpdatedEvent in project xwiki-platform by xwiki.

the class DefaultDocumentCacheTest method testEventBasedCleanup.

@Test
public void testEventBasedCleanup() throws Exception {
    this.cache.set("data", this.document.getDocumentReference());
    this.cache.set("data", this.document.getDocumentReference(), "ext1", "ext2");
    ObservationManager observationManager = getComponentManager().getInstance(ObservationManager.class);
    observationManager.notify(new DocumentUpdatedEvent(this.document.getDocumentReference()), this.document, getContext());
    Assert.assertNull(this.cache.get(this.document.getDocumentReference()));
    Assert.assertNull(this.cache.get(this.document.getDocumentReference(), "ext1", "ext2"));
}
Also used : ObservationManager(org.xwiki.observation.ObservationManager) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) Test(org.junit.Test)

Example 17 with DocumentUpdatedEvent

use of org.xwiki.bridge.event.DocumentUpdatedEvent in project xwiki-platform by xwiki.

the class DefaultRenderingCacheTest method testGetSetRenderedContent.

@Test
public void testGetSetRenderedContent() throws Exception {
    MockConfigurationSource source = getConfigurationSource();
    source.setProperty("core.renderingcache.documents", Collections.singletonList(this.document.getPrefixedFullName()));
    this.renderingCache.setRenderedContent(this.document.getDocumentReference(), "source", "renderedContent", getContext());
    Assert.assertEquals("renderedContent", this.renderingCache.getRenderedContent(this.document.getDocumentReference(), "source", getContext()));
    this.parameters.put("param", new String[] { "value1", "value2" });
    Assert.assertNull(this.renderingCache.getRenderedContent(this.document.getDocumentReference(), "source", getContext()));
    this.parameters.remove("param");
    Assert.assertEquals("renderedContent", this.renderingCache.getRenderedContent(this.document.getDocumentReference(), "source", getContext()));
    ObservationManager observationManager = getComponentManager().getInstance(ObservationManager.class);
    observationManager.notify(new DocumentUpdatedEvent(this.document.getDocumentReference()), this.document, getContext());
    Assert.assertNull(this.renderingCache.getRenderedContent(this.document.getDocumentReference(), "source", getContext()));
}
Also used : MockConfigurationSource(org.xwiki.test.internal.MockConfigurationSource) ObservationManager(org.xwiki.observation.ObservationManager) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) Test(org.junit.Test)

Example 18 with DocumentUpdatedEvent

use of org.xwiki.bridge.event.DocumentUpdatedEvent in project xwiki-platform by xwiki.

the class XObjectEventGeneratorListenerTest method testModifiedDocumentXObjectPropertyModified.

@Test
public void testModifiedDocumentXObjectPropertyModified() throws ComponentLookupException {
    this.xobject.setStringValue("updatedproperty", "propertyvalue");
    BaseObject xobjectModified = this.xobject.clone();
    xobjectModified.setStringValue("updatedproperty", "propertyvaluemodified");
    this.document.addXObject(this.xobject);
    this.documentOrigin.addXObject(xobjectModified);
    final Event event = new XObjectPropertyUpdatedEvent(this.xobject.getField("updatedproperty").getReference());
    this.mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(this.document.getDocumentReference()), this.document, this.oldcore.getXWikiContext());
    // Make sure the listener generated a xobject property updated event
    verify(this.mockObservation).notify(eq(event), same(this.document), same(this.oldcore.getXWikiContext()));
}
Also used : DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) Event(org.xwiki.observation.event.Event) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 19 with DocumentUpdatedEvent

use of org.xwiki.bridge.event.DocumentUpdatedEvent in project xwiki-platform by xwiki.

the class XObjectEventGeneratorListenerTest method testModifiedDocumentXObjectAdded.

@Test
public void testModifiedDocumentXObjectAdded() throws ComponentLookupException {
    this.document.addXObject(this.xobject);
    final Event event = new XObjectAddedEvent(this.xobject.getReference());
    this.mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(this.document.getDocumentReference()), this.document, this.oldcore.getXWikiContext());
    // Make sure the listener generated a xobject added event
    verify(this.mockObservation).notify(eq(event), same(this.document), same(this.oldcore.getXWikiContext()));
}
Also used : DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) Event(org.xwiki.observation.event.Event) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) Test(org.junit.Test)

Example 20 with DocumentUpdatedEvent

use of org.xwiki.bridge.event.DocumentUpdatedEvent in project xwiki-platform by xwiki.

the class SolrIndexEventListenerTest method onDocumentTranslationUpdated.

@Test
public void onDocumentTranslationUpdated() throws Exception {
    XWikiDocument translation = mock(XWikiDocument.class);
    DocumentReference translationReference = new DocumentReference("wiki", "Path", "Page", Locale.FRENCH);
    when(translation.getDocumentReferenceWithLocale()).thenReturn(translationReference);
    this.mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(), translation, null);
    verify(this.indexer).index(translationReference, false);
    verify(this.indexer, times(1)).index(any(EntityReference.class), any(Boolean.class));
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) EntityReference(org.xwiki.model.reference.EntityReference) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

DocumentUpdatedEvent (org.xwiki.bridge.event.DocumentUpdatedEvent)45 Test (org.junit.Test)30 DocumentDeletedEvent (org.xwiki.bridge.event.DocumentDeletedEvent)26 DocumentCreatedEvent (org.xwiki.bridge.event.DocumentCreatedEvent)25 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)16 DocumentReference (org.xwiki.model.reference.DocumentReference)13 Event (org.xwiki.observation.event.Event)13 XWikiContext (com.xpn.xwiki.XWikiContext)9 ArrayList (java.util.ArrayList)6 UntypedRecordableEventDescriptor (org.xwiki.eventstream.UntypedRecordableEventDescriptor)5 BaseObject (com.xpn.xwiki.objects.BaseObject)4 ObservationManager (org.xwiki.observation.ObservationManager)4 DocumentUpdatingEvent (org.xwiki.bridge.event.DocumentUpdatingEvent)3 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)2 AttachmentAddedEvent (com.xpn.xwiki.internal.event.AttachmentAddedEvent)2 AttachmentDeletedEvent (com.xpn.xwiki.internal.event.AttachmentDeletedEvent)2 AttachmentUpdatedEvent (com.xpn.xwiki.internal.event.AttachmentUpdatedEvent)2 Date (java.util.Date)2 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)2 ActionExecutedEvent (org.xwiki.bridge.event.ActionExecutedEvent)2