Search in sources :

Example 1 with WikiCreatingEvent

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

the class DefaultWikiManagerTest method createWhenWikiIdIsValidButFail.

@Test
public void createWhenWikiIdIsValidButFail() throws Exception {
    // The wiki does not already exist
    when(wikiDescriptorManager.exists("wikiid1")).thenReturn(false);
    // The wiki id is valid
    when(xwiki.Param("xwiki.virtual.reserved_wikis")).thenReturn("forbidden");
    // The wiki name is available
    when(store.isWikiNameAvailable(eq("wikiid1"), any(XWikiContext.class))).thenReturn(true);
    DefaultWikiDescriptor descriptor = new DefaultWikiDescriptor("wikiid1", "wikialias1");
    when(wikiCreator.create("wikiid1", "wikialias1")).thenThrow(new WikiManagerException("..."));
    // Create
    boolean exceptionCaught = false;
    try {
        this.mocker.getComponentUnderTest().create("wikiid1", "wikialias1", true);
    } catch (WikiManagerException e) {
        exceptionCaught = true;
    }
    // verify the exception
    assertTrue(exceptionCaught);
    // Verify the events has been sent
    verify(observationManager).notify(new WikiCreatingEvent("wikiid1"), "wikiid1", xcontext);
    verify(observationManager).notify(new WikiCreateFailedEvent("wikiid1"), "wikiid1", xcontext);
}
Also used : WikiCreatingEvent(org.xwiki.bridge.event.WikiCreatingEvent) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) XWikiContext(com.xpn.xwiki.XWikiContext) WikiCreateFailedEvent(org.xwiki.bridge.event.WikiCreateFailedEvent) DefaultWikiDescriptor(org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor) Test(org.junit.Test)

Example 2 with WikiCreatingEvent

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

the class XarExtensionHandlerTest method testCreateNewWiki.

@Test
public void testCreateNewWiki() throws Throwable {
    doReturn(Arrays.asList("wiki1", "wiki2")).when(this.oldcore.getWikiDescriptorManager()).getAllIds();
    install(this.localXarExtensiontId1, null, this.contextUser);
    Assert.assertFalse(this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "space1", "page1"), getXWikiContext()).isNew());
    Assert.assertFalse(this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki2", "space1", "page1"), getXWikiContext()).isNew());
    Assert.assertTrue(this.oldcore.getSpyXWiki().getDocument(new DocumentReference("newwiki", "space1", "page1"), getXWikiContext()).isNew());
    this.observation.notify(new WikiCreatingEvent("newwiki"), null, this.oldcore.getXWikiContext());
    this.observation.notify(new WikiCreatedEvent("newwiki"), null, this.oldcore.getXWikiContext());
    Assert.assertFalse(this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "space1", "page1"), getXWikiContext()).isNew());
    Assert.assertFalse(this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki2", "space1", "page1"), getXWikiContext()).isNew());
    Assert.assertFalse(this.oldcore.getSpyXWiki().getDocument(new DocumentReference("newwiki", "space1", "page1"), getXWikiContext()).isNew());
}
Also used : WikiCreatingEvent(org.xwiki.bridge.event.WikiCreatingEvent) WikiCreatedEvent(org.xwiki.bridge.event.WikiCreatedEvent) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 3 with WikiCreatingEvent

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

the class DefaultWikiManager method create.

@Override
public WikiDescriptor create(String wikiId, String wikiAlias, boolean failOnExist) throws WikiManagerException {
    // Check that the wiki Id is available
    if (failOnExist && !idAvailable(wikiId)) {
        throw new WikiManagerException(String.format("wiki id [%s] is already used and is thus not available", wikiId));
    }
    XWikiContext context = xcontextProvider.get();
    WikiDescriptor descriptor;
    try {
        // Send the begin event
        observationManager.notify(new WikiCreatingEvent(wikiId), wikiId, context);
        // Create the wiki
        descriptor = wikiCreator.create(wikiId, wikiAlias);
        // Send the end event
        observationManager.notify(new WikiCreatedEvent(wikiId), wikiId, context);
    } catch (WikiManagerException e) {
        // Send the failed event
        observationManager.notify(new WikiCreateFailedEvent(wikiId), wikiId, context);
        // Throw the exception
        throw e;
    }
    return descriptor;
}
Also used : WikiCreatingEvent(org.xwiki.bridge.event.WikiCreatingEvent) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiCreatedEvent(org.xwiki.bridge.event.WikiCreatedEvent) XWikiContext(com.xpn.xwiki.XWikiContext) WikiCreateFailedEvent(org.xwiki.bridge.event.WikiCreateFailedEvent) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor)

Example 4 with WikiCreatingEvent

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

the class DefaultWikiManagerTest method createWhenWikiIdIsValid.

@Test
public void createWhenWikiIdIsValid() throws Exception {
    // The wiki does not already exist
    when(wikiDescriptorManager.exists("wikiid1")).thenReturn(false);
    // The wiki id is valid
    when(xwiki.Param("xwiki.virtual.reserved_wikis")).thenReturn("forbidden");
    // The wiki name is available
    when(store.isWikiNameAvailable(eq("wikiid1"), any(XWikiContext.class))).thenReturn(true);
    DefaultWikiDescriptor descriptor = new DefaultWikiDescriptor("wikiid1", "wikialias1");
    when(wikiCreator.create("wikiid1", "wikialias1")).thenReturn(descriptor);
    // Create
    WikiDescriptor newWikiDescriptor = this.mocker.getComponentUnderTest().create("wikiid1", "wikialias1", true);
    // Verify a descriptor has been returned
    assertNotNull(newWikiDescriptor);
    // Verify that the wiki descriptor is an instance of DefaultWikiDescriptor
    assertTrue(newWikiDescriptor instanceof DefaultWikiDescriptor);
    // Verify that the wiki has been created
    verify(wikiCreator).create("wikiid1", "wikialias1");
    // Verify the events has been sent
    verify(observationManager).notify(new WikiCreatingEvent("wikiid1"), "wikiid1", xcontext);
    verify(observationManager).notify(new WikiCreatedEvent("wikiid1"), "wikiid1", xcontext);
}
Also used : WikiCreatingEvent(org.xwiki.bridge.event.WikiCreatingEvent) WikiCreatedEvent(org.xwiki.bridge.event.WikiCreatedEvent) XWikiContext(com.xpn.xwiki.XWikiContext) DefaultWikiDescriptor(org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor) DefaultWikiDescriptor(org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Example 5 with WikiCreatingEvent

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

the class AutomaticWatchModeListenerTest method onEventWhenInContextOfWikiCreatingEvent.

/**
 * Verify that we don't do anything when the current event is inside a WikiCreatingEvent.
 */
@Test
public void onEventWhenInContextOfWikiCreatingEvent() throws Exception {
    // We simulate a WikiCreatingEvent in the Execution Context
    this.observationContextListener.onEvent(new WikiCreatingEvent(), null, null);
    mocker.getComponentUnderTest().onEvent(new DocumentCreatedEvent(), null, null);
    verify(mockStore, never()).getAutomaticWatchMode(any());
    verify(mockStore, never()).addWatchedElement(any(), any(), any(WatchedElementType.class));
}
Also used : WatchedElementType(org.xwiki.watchlist.internal.api.WatchedElementType) WikiCreatingEvent(org.xwiki.bridge.event.WikiCreatingEvent) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) Test(org.junit.Test)

Aggregations

WikiCreatingEvent (org.xwiki.bridge.event.WikiCreatingEvent)5 Test (org.junit.Test)4 XWikiContext (com.xpn.xwiki.XWikiContext)3 WikiCreatedEvent (org.xwiki.bridge.event.WikiCreatedEvent)3 WikiCreateFailedEvent (org.xwiki.bridge.event.WikiCreateFailedEvent)2 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)2 DefaultWikiDescriptor (org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor)2 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)2 DocumentCreatedEvent (org.xwiki.bridge.event.DocumentCreatedEvent)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)1 WatchedElementType (org.xwiki.watchlist.internal.api.WatchedElementType)1