Search in sources :

Example 6 with WikiCreationRequest

use of org.xwiki.platform.wiki.creationjob.WikiCreationRequest in project xwiki-platform by xwiki.

the class ProvisionWikiStepTest method executeWhenSourceIsExtension.

@Test
public void executeWhenSourceIsExtension() throws Exception {
    WikiCreationRequest request = new WikiCreationRequest();
    request.setWikiId("wikiId");
    request.setWikiSource(WikiSource.EXTENSION);
    ExtensionId extensionId = new ExtensionId("id", "version");
    request.setExtensionId(extensionId);
    // Test
    mocker.getComponentUnderTest().execute(request);
    // Verify
    verify(extensionInstaller).installExtension(eq("wikiId"), eq(extensionId));
    verify(observationManager).notify(eq(new WikiProvisioningEvent("wikiId")), eq("wikiId"), eq(xcontext));
    verify(observationManager).notify(eq(new WikiProvisionedEvent("wikiId")), eq("wikiId"), eq(xcontext));
    verifyZeroInteractions(wikiCopier);
}
Also used : WikiProvisionedEvent(org.xwiki.bridge.event.WikiProvisionedEvent) WikiProvisioningEvent(org.xwiki.bridge.event.WikiProvisioningEvent) WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) ExtensionId(org.xwiki.extension.ExtensionId) Test(org.junit.Test)

Example 7 with WikiCreationRequest

use of org.xwiki.platform.wiki.creationjob.WikiCreationRequest in project xwiki-platform by xwiki.

the class ProvisionWikiStepTest method executeWhenSourceIsTemplate.

@Test
public void executeWhenSourceIsTemplate() throws Exception {
    WikiCreationRequest request = new WikiCreationRequest();
    request.setWikiId("wikiId");
    request.setWikiSource(WikiSource.TEMPLATE);
    request.setTemplateId("template");
    // Test
    mocker.getComponentUnderTest().execute(request);
    // Verify
    verify(wikiCopier).copyDocuments(eq("template"), eq("wikiId"), eq(false));
    verify(observationManager).notify(eq(new WikiProvisioningEvent("wikiId")), eq("wikiId"), eq(xcontext));
    verify(observationManager).notify(eq(new WikiCopiedEvent("template", "wikiId")), eq("template"), eq(xcontext));
    verify(observationManager).notify(eq(new WikiProvisionedEvent("wikiId")), eq("wikiId"), eq(xcontext));
    verifyZeroInteractions(extensionInstaller);
}
Also used : WikiCopiedEvent(org.xwiki.bridge.event.WikiCopiedEvent) WikiProvisionedEvent(org.xwiki.bridge.event.WikiProvisionedEvent) WikiProvisioningEvent(org.xwiki.bridge.event.WikiProvisioningEvent) WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) Test(org.junit.Test)

Example 8 with WikiCreationRequest

use of org.xwiki.platform.wiki.creationjob.WikiCreationRequest in project xwiki-platform by xwiki.

the class SaveWikiMetaDataStepTest method execute.

@Test
public void execute() throws Exception {
    WikiCreationRequest request = new WikiCreationRequest();
    request.setWikiId("wikiId");
    request.setDescription("description");
    request.setPrettyName("pretty name");
    request.setOwnerId("ownerId");
    request.setTemplate(false);
    request.setUserScope(UserScope.GLOBAL_ONLY);
    request.setMembershipType(MembershipType.INVITE);
    request.setWikiSource(WikiSource.EXTENSION);
    ExtensionId extensionId = new ExtensionId("id", "version");
    request.setExtensionId(extensionId);
    // Mock
    WikiDescriptor descriptor = new WikiDescriptor("wikiId", "alias");
    when(wikiDescriptorManager.getById("wikiId")).thenReturn(descriptor);
    // Test
    mocker.getComponentUnderTest().execute(request);
    // Verify
    assertEquals("description", descriptor.getDescription());
    assertEquals("pretty name", descriptor.getPrettyName());
    assertEquals("ownerId", descriptor.getOwnerId());
    verify(wikiDescriptorManager).saveDescriptor(descriptor);
    verify(wikiTemplateManager).setTemplate("wikiId", false);
    verify(wikiUserManager).setUserScope("wikiId", UserScope.GLOBAL_ONLY);
    verify(wikiUserManager).setMembershipType("wikiId", MembershipType.INVITE);
}
Also used : WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) ExtensionId(org.xwiki.extension.ExtensionId) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Example 9 with WikiCreationRequest

use of org.xwiki.platform.wiki.creationjob.WikiCreationRequest in project xwiki-platform by xwiki.

the class SaveWikiMetaDataStepTest method executeWithException.

@Test
public void executeWithException() throws Exception {
    WikiCreationRequest request = new WikiCreationRequest();
    request.setWikiId("wikiId");
    // Mock
    WikiDescriptor descriptor = new WikiDescriptor("wikiId", "alias");
    when(wikiDescriptorManager.getById("wikiId")).thenReturn(descriptor);
    Exception exception = new WikiManagerException("Exception on WikiManager.");
    doThrow(exception).when(wikiDescriptorManager).saveDescriptor(descriptor);
    // Test
    WikiCreationException caughtException = null;
    try {
        mocker.getComponentUnderTest().execute(request);
    } catch (WikiCreationException e) {
        caughtException = e;
    }
    // Verify
    assertEquals("Failed to set metadata to the wiki [wikiId].", caughtException.getMessage());
    assertEquals(exception, caughtException.getCause());
}
Also used : WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) Test(org.junit.Test)

Example 10 with WikiCreationRequest

use of org.xwiki.platform.wiki.creationjob.WikiCreationRequest in project xwiki-platform by xwiki.

the class SaveWikiMetaDataStepTest method executeWhenSourceIsTemplate.

@Test
public void executeWhenSourceIsTemplate() throws Exception {
    WikiCreationRequest request = new WikiCreationRequest();
    request.setWikiId("wikiId");
    request.setTemplate(false);
    request.setUserScope(UserScope.LOCAL_ONLY);
    request.setMembershipType(MembershipType.OPEN);
    request.setWikiSource(WikiSource.TEMPLATE);
    // Mock
    WikiDescriptor descriptor = new WikiDescriptor("wikiId", "alias");
    when(wikiDescriptorManager.getById("wikiId")).thenReturn(descriptor);
    // Test
    mocker.getComponentUnderTest().execute(request);
    // Verify
    verify(wikiDescriptorManager).saveDescriptor(descriptor);
    verify(wikiUserManager).setUserScope("wikiId", UserScope.LOCAL_ONLY);
    verify(wikiUserManager).setMembershipType("wikiId", MembershipType.OPEN);
}
Also used : WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)17 WikiCreationRequest (org.xwiki.platform.wiki.creationjob.WikiCreationRequest)17 WikiCreationException (org.xwiki.platform.wiki.creationjob.WikiCreationException)6 WikiProvisioningEvent (org.xwiki.bridge.event.WikiProvisioningEvent)3 ExtensionId (org.xwiki.extension.ExtensionId)3 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)3 ArrayList (java.util.ArrayList)2 WikiProvisionedEvent (org.xwiki.bridge.event.WikiProvisionedEvent)2 Job (org.xwiki.job.Job)2 WikiCreationStep (org.xwiki.platform.wiki.creationjob.WikiCreationStep)2 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)2 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)2 InOrder (org.mockito.InOrder)1 Marker (org.slf4j.Marker)1 WikiCopiedEvent (org.xwiki.bridge.event.WikiCopiedEvent)1 WikiProvisioningFailedEvent (org.xwiki.bridge.event.WikiProvisioningFailedEvent)1 JobException (org.xwiki.job.JobException)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 WikiReference (org.xwiki.model.reference.WikiReference)1 WikiUserManagerException (org.xwiki.wiki.user.WikiUserManagerException)1