@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()); }
public Job createWiki(WikiCreationRequest request) { try { XWikiContext xcontext = xcontextProvider.get(); WikiReference mainWikiReference = new WikiReference(wikiDescriptorManager.getMainWikiId()); authorizationManager.checkAccess(Right.CREATE_WIKI, xcontext.getUserReference(), mainWikiReference); if (request.getExtensionId() != null) { if (!isAuthorizedExtension(request.getExtensionId())) { throw new WikiCreationException(String.format("The extension [%s] is not authorized.", request.getExtensionId())); } } return wikiCreator.createWiki(request); } catch (WikiCreationException e) { setLastError(e); logger.warn("Failed to create a new wiki.", e); } catch (AccessDeniedException e) { setLastError(e); } return null; }
WikiCreationJobScriptServices implements ScriptService { public Job createWiki(WikiCreationRequest request) { try { XWikiContext xcontext = xcontextProvider.get(); WikiReference mainWikiReference = new WikiReference(wikiDescriptorManager.getMainWikiId()); authorizationManager.checkAccess(Right.CREATE_WIKI, xcontext.getUserReference(), mainWikiReference); if (request.getExtensionId() != null) { if (!isAuthorizedExtension(request.getExtensionId())) { throw new WikiCreationException(String.format("The extension [%s] is not authorized.", request.getExtensionId())); } } return wikiCreator.createWiki(request); } catch (WikiCreationException e) { setLastError(e); logger.warn("Failed to create a new wiki.", e); } catch (AccessDeniedException e) { setLastError(e); } return null; } }
WikiCreationJobScriptServices implements ScriptService { public Job createWiki(WikiCreationRequest request) { try { XWikiContext xcontext = xcontextProvider.get(); WikiReference mainWikiReference = new WikiReference(wikiDescriptorManager.getMainWikiId()); authorizationManager.checkAccess(Right.CREATE_WIKI, xcontext.getUserReference(), mainWikiReference); if (request.getExtensionId() != null) { if (!isAuthorizedExtension(request.getExtensionId())) { throw new WikiCreationException(String.format("The extension [%s] is not authorized.", request.getExtensionId())); } } return wikiCreator.createWiki(request); } catch (WikiCreationException e) { setLastError(e); logger.warn("Failed to create a new wiki.", e); } catch (AccessDeniedException e) { setLastError(e); } return null; }  }
WikiCreationJobScriptServices implements ScriptService { public Job createWiki(WikiCreationRequest request) { try { XWikiContext xcontext = xcontextProvider.get(); WikiReference mainWikiReference = new WikiReference(wikiDescriptorManager.getMainWikiId()); authorizationManager.checkAccess(Right.CREATE_WIKI, xcontext.getUserReference(), mainWikiReference); if (request.getExtensionId() != null) { if (!isAuthorizedExtension(request.getExtensionId())) { throw new WikiCreationException(String.format("The extension [%s] is not authorized.", request.getExtensionId())); } } return wikiCreator.createWiki(request); } catch (WikiCreationException e) { setLastError(e); logger.warn("Failed to create a new wiki.", e); } catch (AccessDeniedException e) { setLastError(e); } return null; }  Job createWiki(WikiCreationRequest request); ExtensionId getDefaultWikiExtensionId(); JobStatus getJobStatus(String wikiId); WikiCreationRequest newWikiCreationRequest(); Exception getLastError(); }
WikiCreationJobScriptServices implements ScriptService { public Job createWiki(WikiCreationRequest request) { try { XWikiContext xcontext = xcontextProvider.get(); WikiReference mainWikiReference = new WikiReference(wikiDescriptorManager.getMainWikiId()); authorizationManager.checkAccess(Right.CREATE_WIKI, xcontext.getUserReference(), mainWikiReference); if (request.getExtensionId() != null) { if (!isAuthorizedExtension(request.getExtensionId())) { throw new WikiCreationException(String.format("The extension [%s] is not authorized.", request.getExtensionId())); } } return wikiCreator.createWiki(request); } catch (WikiCreationException e) { setLastError(e); logger.warn("Failed to create a new wiki.", e); } catch (AccessDeniedException e) { setLastError(e); } return null; }  Job createWiki(WikiCreationRequest request); ExtensionId getDefaultWikiExtensionId(); JobStatus getJobStatus(String wikiId); WikiCreationRequest newWikiCreationRequest(); Exception getLastError();  }