Search in sources :

Example 1 with WikiCreationRequest

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

the class DefaultWikiCreatorTest method createWiki.

@Test
public void createWiki() throws Exception {
    WikiCreationRequest request = new WikiCreationRequest();
    request.setWikiId("wikiId");
    // Mock
    Job job = mock(Job.class);
    when(jobExecutor.execute("wikicreationjob", request)).thenReturn(job);
    // Test
    assertEquals(job, mocker.getComponentUnderTest().createWiki(request));
    // Verify
    assertEquals(Arrays.asList("wikicreation", "createandinstall", "wikiId"), request.getId());
}
Also used : WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) Job(org.xwiki.job.Job) Test(org.junit.Test)

Example 2 with WikiCreationRequest

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

the class WikiCreationJobTest method runInternalWithException.

@Test
public void runInternalWithException() throws Exception {
    // Mocks
    WikiCreationStep step1 = mock(WikiCreationStep.class);
    mocker.registerComponent(WikiCreationStep.class, "step1", step1);
    when(step1.getOrder()).thenReturn(100);
    WikiCreationException exception = new WikiCreationException("Error in the step");
    doThrow(exception).when(step1).execute(any(WikiCreationRequest.class));
    // Test
    WikiCreationRequest request = new WikiCreationRequest();
    request.setId(Arrays.asList("myrequest"));
    request.setWikiId("wikiId");
    mocker.getComponentUnderTest().start(request);
    // Verify
    verify(mocker.getMockedLogger()).error(any(Marker.class), eq("Exception thrown during job execution"), eq(new WikiCreationException("Failed to execute creation steps on the wiki [wikiId].", exception)));
}
Also used : WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) Marker(org.slf4j.Marker) WikiCreationStep(org.xwiki.platform.wiki.creationjob.WikiCreationStep) Test(org.junit.Test)

Example 3 with WikiCreationRequest

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

the class AddUsersStepTest method executeWhenException.

@Test
public void executeWhenException() throws Exception {
    WikiCreationRequest request = new WikiCreationRequest();
    request.setWikiId("wikiId");
    List<String> members = new ArrayList<>();
    request.setMembers(members);
    Exception exception = new WikiUserManagerException("Execption in WikiUserManager.");
    doThrow(exception).when(wikiUserManager).addMembers(anyCollection(), any());
    // Test
    WikiCreationException caughtException = null;
    try {
        mocker.getComponentUnderTest().execute(request);
    } catch (WikiCreationException e) {
        caughtException = e;
    }
    // Verify
    assertNotNull(caughtException);
    assertEquals("Failed to add members to the wiki [wikiId].", caughtException.getMessage());
    assertEquals(exception, caughtException.getCause());
}
Also used : WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) ArrayList(java.util.ArrayList) WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) Test(org.junit.Test)

Example 4 with WikiCreationRequest

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

the class CreateWikiStepTest method executeWhenException.

@Test
public void executeWhenException() throws Exception {
    WikiCreationRequest request = new WikiCreationRequest();
    request.setWikiId("wikiId");
    request.setAlias("wikiAlias");
    request.setFailOnExist(true);
    Exception exception = new WikiManagerException("Execption in WikiManager.");
    doThrow(exception).when(wikiManager).create(any(), any(), anyBoolean());
    // Test
    WikiCreationException caughtException = null;
    try {
        mocker.getComponentUnderTest().execute(request);
    } catch (WikiCreationException e) {
        caughtException = e;
    }
    // Verify
    assertNotNull(caughtException);
    assertEquals("Failed to create 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) WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) Test(org.junit.Test)

Example 5 with WikiCreationRequest

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

the class CreateWikiStepTest method execute.

@Test
public void execute() throws Exception {
    WikiCreationRequest request = new WikiCreationRequest();
    request.setWikiId("wikiId");
    request.setAlias("wikiAlias");
    request.setFailOnExist(true);
    // Test
    mocker.getComponentUnderTest().execute(request);
    // Verify
    verify(wikiManager).create("wikiId", "wikiAlias", true);
    // Test 2
    request.setFailOnExist(false);
    mocker.getComponentUnderTest().execute(request);
    // Verify
    verify(wikiManager).create("wikiId", "wikiAlias", false);
}
Also used : WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) 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