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