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