Search in sources :

Example 11 with WikiCreationRequest

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

the class WikiCreationJobScriptServicesTest method createWikiWhenNoCreateWikiRight.

@Test
public void createWikiWhenNoCreateWikiRight() throws Exception {
    DocumentReference currentUser = new DocumentReference("xwiki", "XWiki", "User");
    when(xcontext.getUserReference()).thenReturn(currentUser);
    AccessDeniedException exception = new AccessDeniedException(Right.CREATE_WIKI, currentUser, new WikiReference("mainWikiId"));
    doThrow(exception).when(authorizationManager).checkAccess(eq(Right.CREATE_WIKI), eq(currentUser), eq(new WikiReference("mainWikiId")));
    WikiCreationRequest wikiCreationRequest = new WikiCreationRequest();
    wikiCreationRequest.setExtensionId("authorized-extension", "1.0");
    assertNull(mocker.getComponentUnderTest().createWiki(wikiCreationRequest));
    Exception lastError = mocker.getComponentUnderTest().getLastError();
    assertNotNull(lastError);
    assertEquals(exception, lastError);
}
Also used : AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) Test(org.junit.Test)

Example 12 with WikiCreationRequest

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

the class WikiCreationJobScriptServicesTest method createWiki.

@Test
public void createWiki() throws Exception {
    Job job = mock(Job.class);
    when(wikiCreator.createWiki(any(WikiCreationRequest.class))).thenReturn(job);
    WikiCreationRequest wikiCreationRequest = new WikiCreationRequest();
    wikiCreationRequest.setExtensionId("authorized-extension", "1.0");
    assertEquals(job, mocker.getComponentUnderTest().createWiki(wikiCreationRequest));
    assertNull(mocker.getComponentUnderTest().getLastError());
}
Also used : WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) Job(org.xwiki.job.Job) Test(org.junit.Test)

Example 13 with WikiCreationRequest

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

the class WikiCreationJobScriptServicesTest method createWikiWhenExtensionIsNotAuthorized.

@Test
public void createWikiWhenExtensionIsNotAuthorized() throws Exception {
    WikiCreationRequest wikiCreationRequest = new WikiCreationRequest();
    wikiCreationRequest.setExtensionId("badExtension", "version");
    assertNull(mocker.getComponentUnderTest().createWiki(wikiCreationRequest));
    Exception lastError = mocker.getComponentUnderTest().getLastError();
    assertNotNull(lastError);
    assertEquals("The extension [badExtension/version] is not authorized.", lastError.getMessage());
    verify(mocker.getMockedLogger()).warn("Failed to create a new wiki.", lastError);
}
Also used : WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) Test(org.junit.Test)

Example 14 with WikiCreationRequest

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

the class DefaultWikiCreatorTest method createWikiWithException.

@Test
public void createWikiWithException() throws Exception {
    WikiCreationRequest request = new WikiCreationRequest();
    request.setWikiId("wikiId");
    // Mock
    JobException jobException = new JobException("Error in JobException");
    when(jobExecutor.execute("wikicreationjob", request)).thenThrow(jobException);
    // Test
    WikiCreationException caughtException = null;
    try {
        mocker.getComponentUnderTest().createWiki(request);
    } catch (WikiCreationException e) {
        caughtException = e;
    }
    // Verify
    assertNotNull(caughtException);
}
Also used : JobException(org.xwiki.job.JobException) WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) Test(org.junit.Test)

Example 15 with WikiCreationRequest

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

the class WikiCreationJobTest method runInternal.

@Test
public void runInternal() throws Exception {
    // Mocks
    WikiCreationStep step1 = mock(WikiCreationStep.class);
    WikiCreationStep step2 = mock(WikiCreationStep.class);
    WikiCreationStep step3 = mock(WikiCreationStep.class);
    when(step1.getOrder()).thenReturn(100);
    when(step2.getOrder()).thenReturn(50);
    when(step3.getOrder()).thenReturn(75);
    mocker.registerComponent(WikiCreationStep.class, "step1", step1);
    mocker.registerComponent(WikiCreationStep.class, "step2", step2);
    mocker.registerComponent(WikiCreationStep.class, "step3", step3);
    // Test
    WikiCreationRequest request = new WikiCreationRequest();
    request.setId(Arrays.asList("myrequest"));
    mocker.getComponentUnderTest().start(request);
    // Verify
    InOrder inOrder = inOrder(step1, step2, step3, progressManager);
    // Verify that the steps are executed in the good order
    inOrder.verify(progressManager).pushLevelProgress(eq(3), any(Object.class));
    inOrder.verify(progressManager, calls(1)).startStep(any(Object.class));
    inOrder.verify(step2).execute(any(WikiCreationRequest.class));
    inOrder.verify(progressManager, calls(1)).startStep(any(Object.class));
    inOrder.verify(step3).execute(any(WikiCreationRequest.class));
    inOrder.verify(progressManager, calls(1)).startStep(any(Object.class));
    inOrder.verify(step1).execute(any(WikiCreationRequest.class));
    inOrder.verify(progressManager).popLevelProgress(any(Object.class));
}
Also used : InOrder(org.mockito.InOrder) WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) WikiCreationStep(org.xwiki.platform.wiki.creationjob.WikiCreationStep) 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