Search in sources :

Example 11 with DefaultWikiDescriptor

use of org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor 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 12 with DefaultWikiDescriptor

use of org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor in project xwiki-platform by xwiki.

the class WikiDescriptorCacheTest method remove.

@Test
public void remove() throws Exception {
    DefaultWikiDescriptor descriptor = new DefaultWikiDescriptor("wikiid", "wikialias");
    descriptor.addAlias("alias2");
    this.mocker.getComponentUnderTest().remove(descriptor.getId(), descriptor.getAliases());
    verify(wikiIdCache).remove("wikiid");
    verify(wikiAliasCache).remove("wikialias");
    verify(wikiAliasCache).remove("alias2");
}
Also used : DefaultWikiDescriptor(org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor) Test(org.junit.Test)

Example 13 with DefaultWikiDescriptor

use of org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor in project xwiki-platform by xwiki.

the class DefaultWikiDescriptorBuilder method extractWikiDescriptor.

private DefaultWikiDescriptor extractWikiDescriptor(BaseObject serverClassObject, XWikiDocument document) {
    DefaultWikiDescriptor descriptor = null;
    // If the server property is empty then consider we have an invalid Wiki
    String serverProperty = extractWikiAlias(serverClassObject);
    if (!StringUtils.isBlank(serverProperty)) {
        // If the page name doesn't start with "XWikiServer" then consider we have an invalid Wiki
        String wikiId = extractWikiId(document);
        if (wikiId != null) {
            descriptor = new DefaultWikiDescriptor(wikiId, serverProperty);
        }
    }
    return descriptor;
}
Also used : DefaultWikiDescriptor(org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor)

Example 14 with DefaultWikiDescriptor

use of org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor in project xwiki-platform by xwiki.

the class DefaultWikiCreator method createDescriptor.

private WikiDescriptor createDescriptor(String wikiId, String wikiAlias) throws WikiManagerException {
    // Create the descriptor
    WikiDescriptor descriptor = new DefaultWikiDescriptor(wikiId, wikiAlias);
    try {
        // Build the document
        wikiDescriptorBuilder.save(descriptor);
        // Reload the descriptor from the cache because it should have been seen by the DescriptorListener.
        descriptor = wikiDescriptorManager.getById(wikiId);
    } catch (WikiDescriptorBuilderException e) {
        throw new WikiManagerException("Failed to build the descriptor document.", e);
    }
    return descriptor;
}
Also used : WikiDescriptorBuilderException(org.xwiki.wiki.internal.descriptor.builder.WikiDescriptorBuilderException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) DefaultWikiDescriptor(org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor) DefaultWikiDescriptor(org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor)

Aggregations

DefaultWikiDescriptor (org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor)14 Test (org.junit.Test)9 XWikiContext (com.xpn.xwiki.XWikiContext)5 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)5 BaseObject (com.xpn.xwiki.objects.BaseObject)5 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)4 DocumentDeletedEvent (org.xwiki.bridge.event.DocumentDeletedEvent)3 DocumentUpdatedEvent (org.xwiki.bridge.event.DocumentUpdatedEvent)3 ArrayList (java.util.ArrayList)2 WikiCreatingEvent (org.xwiki.bridge.event.WikiCreatingEvent)2 DocumentReference (org.xwiki.model.reference.DocumentReference)2 Event (org.xwiki.observation.event.Event)2 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)2 WikiCopiedEvent (org.xwiki.bridge.event.WikiCopiedEvent)1 WikiCreateFailedEvent (org.xwiki.bridge.event.WikiCreateFailedEvent)1 WikiCreatedEvent (org.xwiki.bridge.event.WikiCreatedEvent)1 WikiDescriptorBuilderException (org.xwiki.wiki.internal.descriptor.builder.WikiDescriptorBuilderException)1 WikiPropertyGroupManager (org.xwiki.wiki.internal.descriptor.properties.WikiPropertyGroupManager)1 WikiPropertyGroupException (org.xwiki.wiki.properties.WikiPropertyGroupException)1