Search in sources :

Example 1 with DefaultWikiDescriptor

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

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

the class WikiDescriptorCacheTest method add.

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

Example 3 with DefaultWikiDescriptor

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

the class WikiDescriptorListenerTest method onDocumentUpdatedEvent.

@Test
public void onDocumentUpdatedEvent() throws Exception {
    XWikiDocument document = mock(XWikiDocument.class);
    XWikiDocument originalDocument = mock(XWikiDocument.class);
    when(document.getOriginalDocument()).thenReturn(originalDocument);
    Event event = new DocumentUpdatedEvent();
    List<BaseObject> objects = new ArrayList<>();
    BaseObject object = mock(BaseObject.class);
    objects.add(object);
    when(originalDocument.getXObjects(WikiDescriptorListener.SERVER_CLASS)).thenReturn(objects);
    DocumentReference documentReference = new DocumentReference("mainWiki", "XWiki", "XWikiServerSubwikiA");
    when(originalDocument.getDocumentReference()).thenReturn(documentReference);
    when(wikiDescriptorDocumentHelper.getWikiIdFromDocumentReference(documentReference)).thenReturn("subwikia");
    DefaultWikiDescriptor descriptor = new DefaultWikiDescriptor("subwikia", "alias");
    when(cache.getFromId("subwikia")).thenReturn(descriptor);
    // New objects
    List<BaseObject> newObjects = new ArrayList<>();
    BaseObject newObject = mock(BaseObject.class);
    newObjects.add(newObject);
    when(document.getXObjects(WikiDescriptorListener.SERVER_CLASS)).thenReturn(newObjects);
    DefaultWikiDescriptor newDescriptor = new DefaultWikiDescriptor("subwikia", "newAlias");
    when(builder.buildDescriptorObject(newObjects, document)).thenReturn(newDescriptor);
    // Test
    mocker.getComponentUnderTest().onEvent(event, document, null);
    // Verify
    verify(cache).remove(descriptor.getId(), descriptor.getAliases());
    verify(cache).add(newDescriptor);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ArrayList(java.util.ArrayList) Event(org.xwiki.observation.event.Event) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) DefaultWikiDescriptor(org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 4 with DefaultWikiDescriptor

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

the class WikiDescriptorListenerTest method onDocumentDeletedEvent.

@Test
public void onDocumentDeletedEvent() throws Exception {
    XWikiDocument document = mock(XWikiDocument.class);
    XWikiDocument originalDocument = mock(XWikiDocument.class);
    when(document.getOriginalDocument()).thenReturn(originalDocument);
    Event event = new DocumentDeletedEvent();
    List<BaseObject> objects = new ArrayList<>();
    BaseObject object = mock(BaseObject.class);
    objects.add(object);
    when(originalDocument.getXObjects(WikiDescriptorListener.SERVER_CLASS)).thenReturn(objects);
    DocumentReference documentReference = new DocumentReference("mainWiki", "XWiki", "XWikiServerSubwikiA");
    when(originalDocument.getDocumentReference()).thenReturn(documentReference);
    when(wikiDescriptorDocumentHelper.getWikiIdFromDocumentReference(documentReference)).thenReturn("subwikia");
    DefaultWikiDescriptor descriptor = new DefaultWikiDescriptor("subwikia", "alias");
    when(cache.getFromId("subwikia")).thenReturn(descriptor);
    // Test
    mocker.getComponentUnderTest().onEvent(event, document, null);
    // Verify
    verify(cache).remove(descriptor.getId(), descriptor.getAliases());
    verify(cache, never()).add(any(DefaultWikiDescriptor.class));
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) ArrayList(java.util.ArrayList) Event(org.xwiki.observation.event.Event) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) DefaultWikiDescriptor(org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 5 with DefaultWikiDescriptor

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

the class WikiDescriptorListener method removeExistingDescriptor.

private void removeExistingDescriptor(XWikiDocument document) {
    List<BaseObject> existingServerClassObjects = document.getXObjects(SERVER_CLASS);
    if (existingServerClassObjects != null && !existingServerClassObjects.isEmpty()) {
        String wikiId = this.wikiDescriptorDocumentHelper.getWikiIdFromDocumentReference(document.getDocumentReference());
        DefaultWikiDescriptor existingDescriptor = this.cache.getFromId(wikiId);
        if (existingDescriptor != null) {
            this.cache.remove(wikiId, existingDescriptor.getAliases());
            this.cache.setWikiIds(null);
        }
    }
}
Also used : DefaultWikiDescriptor(org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor) BaseObject(com.xpn.xwiki.objects.BaseObject)

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