use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.
the class DefaultWikiDescriptorBuilderTest method buildDescriptorObject.
@Test
public void buildDescriptorObject() throws Exception {
// Mocks
List<BaseObject> objects = new ArrayList<>();
BaseObject object1 = mock(BaseObject.class);
BaseObject object2 = mock(BaseObject.class);
BaseObject object3 = mock(BaseObject.class);
// Make sure that the first object is null to also verify this case since it can happen that we get holes
// with the XWikiDocument.getXObjects() API...
objects.add(null);
objects.add(object1);
objects.add(object2);
objects.add(null);
objects.add(object3);
XWikiDocument document = mock(XWikiDocument.class);
DocumentReference documentReference = new DocumentReference("mainWiki", "XWiki", "XWikiServerSubwiki1");
when(document.getDocumentReference()).thenReturn(documentReference);
when(object1.getStringValue(XWikiServerClassDocumentInitializer.FIELD_SERVER)).thenReturn("subwiki1");
when(object2.getStringValue(XWikiServerClassDocumentInitializer.FIELD_SERVER)).thenReturn("alias1");
when(object3.getStringValue(XWikiServerClassDocumentInitializer.FIELD_SERVER)).thenReturn("alias2");
DocumentReference mainPageReference = new DocumentReference("subwiki1", "Space", "MainPage");
when(object1.getStringValue(XWikiServerClassDocumentInitializer.FIELD_HOMEPAGE)).thenReturn("Space.MainPage");
when(referenceResolver.resolve("Space.MainPage")).thenReturn(mainPageReference);
when(object1.getStringValue(XWikiServerClassDocumentInitializer.FIELD_WIKIPRETTYNAME)).thenReturn("myPrettyName");
when(object1.getStringValue(XWikiServerClassDocumentInitializer.FIELD_OWNER)).thenReturn("myOwner");
when(object1.getStringValue(XWikiServerClassDocumentInitializer.FIELD_DESCRIPTION)).thenReturn("myDescription");
DocumentReference ownerRef = new DocumentReference("subwiki1", "XWiki", "myOwner");
when(userReferenceResolver.resolve("myOwner", new WikiReference("subwiki1"))).thenReturn(ownerRef);
when(referenceSerializer.serialize(ownerRef)).thenReturn("subwiki1:XWiki.myOwner");
// Test
WikiDescriptor result = mocker.getComponentUnderTest().buildDescriptorObject(objects, document);
assertEquals("subwiki1", result.getId());
assertEquals(3, result.getAliases().size());
assertEquals("subwiki1", result.getAliases().get(0));
assertEquals("alias1", result.getAliases().get(1));
assertEquals("alias2", result.getAliases().get(2));
assertEquals(mainPageReference, result.getMainPageReference());
assertEquals("myPrettyName", result.getPrettyName());
assertEquals("subwiki1:XWiki.myOwner", result.getOwnerId());
assertEquals("myDescription", result.getDescription());
// Verify
wikiPropertyGroupManager.loadForDescriptor(any(WikiDescriptor.class));
}
use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.
the class DefaultWikiCreatorTest method create.
@Test
public void create() throws Exception {
// Other mocks
DefaultWikiDescriptor descriptor = new DefaultWikiDescriptor("wikiid1", "wikialias1");
XWikiDocument descriptorDocument = mock(XWikiDocument.class);
when(wikiDescriptorBuilder.save(eq(descriptor))).thenReturn(descriptorDocument);
when(wikiDescriptorManager.getById("wikiid1")).thenReturn(descriptor);
when(store.isWikiNameAvailable(any(String.class), any(XWikiContext.class))).thenReturn(true);
// Create
WikiDescriptor newWikiDescriptor = this.mocker.getComponentUnderTest().create("wikiid1", "wikialias1");
assertNotNull(newWikiDescriptor);
// Verify that the wiki descriptor is an instance of DefaultWikiDescriptor
assertTrue(newWikiDescriptor instanceof DefaultWikiDescriptor);
// Verify that the wiki has been created
verify(store).createWiki(eq("wikiid1"), any(XWikiContext.class));
// Verify that the wiki has been updated
verify(xwiki).initializeWiki(eq("wikiid1"), eq(true), any(XWikiContext.class));
// Verify that the descriptor document has been saved
verify(wikiDescriptorBuilder).save(eq(descriptor));
// Verify that the descriptor has been reloaded after being saved
assertTrue(descriptor == newWikiDescriptor);
}
use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.
the class DefaultWikiManagerTest method copyWhenWikiAvailable.
@Test
public void copyWhenWikiAvailable() throws Exception {
// The wiki does not already exist
when(wikiDescriptorManager.exists("wikiid1")).thenReturn(false);
// The new 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);
// Other mocks
DefaultWikiDescriptor descriptor = new DefaultWikiDescriptor("wikiid1", "wikialias1");
when(wikiCreator.create("wikiid1", "wikialias1")).thenReturn(descriptor);
// Copy
WikiDescriptor newWikiDescriptor = this.mocker.getComponentUnderTest().copy("wikiid", "wikiid1", "wikialias1", true, true, true);
assertNotNull(newWikiDescriptor);
// Verify that the wiki has been created
verify(wikiCreator).create("wikiid1", "wikialias1");
// Verify that the wiki has been copied
verify(wikiCopier).copyDocuments(eq("wikiid"), eq("wikiid1"), eq(true));
// Verify that deleted documents has been copied too
verify(wikiCopier).copyDeletedDocuments(eq("wikiid"), eq("wikiid1"));
// Verify that events has been sent
verify(observationManager).notify(new WikiCopiedEvent("wikiid", "wikiid1"), "wikiid", xcontext);
}
use of org.xwiki.wiki.descriptor.WikiDescriptor 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);
}
use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.
the class DefaultWikiManagerREST method createWiki.
@Override
@POST
public Response createWiki(@QueryParam("template") String template, Wiki wiki) throws XWikiRestException {
XWikiContext xcontext = getXWikiContext();
WikiDescriptor descriptor = null;
try {
// Create the wiki
descriptor = wikiManager.create(wiki.getId(), wiki.getId(), true);
// Change the descriptor
if (wiki.getOwner() != null) {
descriptor.setOwnerId(wiki.getOwner());
} else {
descriptor.setOwnerId(entityReferenceSerializer.serialize(xcontext.getUserReference()));
}
descriptor.setPrettyName(wiki.getName());
descriptor.setDescription(wiki.getDescription());
// Save the descriptor
wikiDescriptorManager.saveDescriptor(descriptor);
// Apply a template (if needed)
if (template != null) {
WikiProvisioningJob job = wikiTemplateManager.applyTemplate(descriptor.getId(), template);
job.join();
}
// Build the response
Wiki result = createWiki(objectFactory, uriInfo.getBaseUri(), wiki.getId(), wiki.getOwner(), wiki.getDescription());
// Add a link to the WebHome of the newly created wiki.
Link home = objectFactory.createLink();
home.setRel(Relations.HOME);
home.setHref(xcontext.getWiki().getURL(descriptor.getMainPageReference(), "view", xcontext));
result.getLinks().add(home);
// Return the final response
return Response.created(UriBuilder.fromUri(uriInfo.getBaseUri()).path(WikiResource.class).build(wiki.getId())).entity(result).build();
} catch (Exception e) {
throw new XWikiRestException(e);
}
}
Aggregations