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);
}
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);
}
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);
}
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));
}
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);
}
}
}
Aggregations