use of org.xwiki.extension.job.internal.InstallJob in project xwiki-platform by xwiki.
the class ExtensionInstallerTest method installExtension.
@Test
public void installExtension() throws Exception {
// Mocks
InstallJob installJob = mock(InstallJob.class);
mocker.registerComponent(Job.class, InstallJob.JOBTYPE, installJob);
final InstallRequest[] installRequest = { null };
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
installRequest[0] = (InstallRequest) invocation.getArguments()[0];
return null;
}
}).when(installJob).initialize(any(Request.class));
// Test
mocker.getComponentUnderTest().installExtension("wikiId", new ExtensionId("extensionId", "version"));
// Verify
assertNotNull(installRequest[0]);
assertEquals(Arrays.asList("wiki:wikiId"), installRequest[0].getNamespaces());
assertEquals(Arrays.asList("wikicreation", "install", "wikiId"), installRequest[0].getId());
assertEquals(Arrays.asList(new ExtensionId("extensionId", "version")), installRequest[0].getExtensions());
assertEquals(new DocumentReference("xwiki", "XWiki", "superadmin"), installRequest[0].getProperty("user.reference"));
verify(installJob).run();
}
use of org.xwiki.extension.job.internal.InstallJob in project xwiki-platform by xwiki.
the class ExtensionInstaller method installExtension.
/**
* Install an extension on a wiki.
*
* @param wikiId id of the wiki
* @param extensionId id of the extension to install
* @throws org.xwiki.platform.wiki.creationjob.WikiCreationException if problem occurs
*/
public void installExtension(String wikiId, ExtensionId extensionId) throws WikiCreationException {
try {
// Create the install request
InstallRequest installRequest = new InstallRequest();
installRequest.setId(Arrays.asList(WikiCreationJob.JOB_ID_PREFIX, "install", wikiId));
installRequest.addExtension(extensionId);
installRequest.addNamespace("wiki:" + wikiId);
// To avoid problem with Programming Rights, we install everything with superadmin
installRequest.setProperty(PROPERTY_USERREFERENCE, SUPERADMIN_REFERENCE);
InstallJob job = componentManager.getInstance(Job.class, InstallJob.JOBTYPE);
job.initialize(installRequest);
job.run();
} catch (ComponentLookupException e) {
throw new WikiCreationException(String.format("Failed to install the extension [%s] on the wiki [%s].", extensionId.toString(), wikiId), e);
}
}
use of org.xwiki.extension.job.internal.InstallJob in project xwiki-platform by xwiki.
the class XarExtensionHandlerTest method installOnNamespace.
private XarInstalledExtension installOnNamespace(ExtensionId extensionId, String namespace, DocumentReference user) throws Throwable {
InstallRequest installRequest = new InstallRequest();
if (user != null) {
installRequest.setProperty("user.reference", getXWikiContext().getUserReference());
installRequest.setProperty("checkrights", true);
}
installRequest.addExtension(extensionId);
if (namespace != null) {
installRequest.addNamespace(namespace);
}
Job installJob = this.jobExecutor.execute(InstallJob.JOBTYPE, installRequest);
installJob.join();
List<LogEvent> errors = installJob.getStatus().getLog().getLogsFrom(LogLevel.WARN);
if (!errors.isEmpty()) {
if (errors.get(0).getThrowable() != null) {
throw errors.get(0).getThrowable();
} else {
throw new Exception(errors.get(0).getFormattedMessage());
}
}
return (XarInstalledExtension) this.xarExtensionRepository.resolve(extensionId);
}
Aggregations