use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.
the class IntegrationTest method setUpComponents.
@BeforeComponent
public void setUpComponents() throws Exception {
// Isolate from xwiki configuration file
URLConfiguration urlConfiguration = this.componentManager.registerMockComponent(URLConfiguration.class);
when(urlConfiguration.getURLFormatId()).thenReturn("standard");
// Isolate from xwiki configuration file
StandardURLConfiguration standardURLConfiguration = this.componentManager.registerMockComponent(StandardURLConfiguration.class);
when(standardURLConfiguration.getEntityPathPrefix()).thenReturn("bin");
when(standardURLConfiguration.getWikiPathPrefix()).thenReturn("wiki");
when(standardURLConfiguration.isViewActionHidden()).thenReturn(false);
// Isolate from xwiki configuration file
ModelConfiguration modelConfiguration = this.componentManager.registerMockComponent(ModelConfiguration.class);
when(modelConfiguration.getDefaultReferenceValue(EntityType.WIKI)).thenReturn("xwiki");
// Isolate from xwiki's model
WikiDescriptorManager wikiDescriptorManager = this.componentManager.registerMockComponent(WikiDescriptorManager.class);
when(wikiDescriptorManager.getMainWikiId()).thenReturn("xwiki");
// Isolate from Environment
EntityResourceActionLister actionLister = this.componentManager.registerMockComponent(EntityResourceActionLister.class);
when(actionLister.listActions()).thenReturn(Arrays.asList("view"));
// Simulate a configured Execution Context
Execution execution = this.componentManager.registerMockComponent(Execution.class);
when(execution.getContext()).thenReturn(new ExecutionContext());
// For test simplicity consider that Context CM == CM
this.componentManager.registerComponent(ComponentManager.class, "context", this.componentManager);
}
use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.
the class PathWikiReferenceExtractorTest method setUpConfiguration.
private void setUpConfiguration(WikiNotFoundBehavior wikiNotFoundBehavior) throws Exception {
// Simulate a configured Execution Context
Execution execution = mocker.getInstance(Execution.class);
when(execution.getContext()).thenReturn(new ExecutionContext());
StandardURLConfiguration urlConfiguration = mocker.getInstance(StandardURLConfiguration.class);
when(urlConfiguration.getWikiNotFoundBehavior()).thenReturn(wikiNotFoundBehavior);
}
use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.
the class OldCoreHelper method createXWikiContext.
/**
* @param wikiId id of the wiki for which to prepare the XWiki Context (e.g. {@code xwiki})
* @param hibernateConfig the Hibernate config fill containing the database definition (JDBC driver, username and
* password, etc)
* @return a valid XWikiContext using the passed Hibernate configuration and passed database name
* @throws Exception failed to initialize context.
*/
// TODO: Replace the Hibernate config file with a list of parameters required for the packaging operation
private XWikiContext createXWikiContext() throws Exception {
Utils.setComponentManager(this.componentManager);
this.xcontext = new XWikiContext();
this.xcontext.put(ComponentManager.class.getName(), this.componentManager);
// Initialize the Container fields (request, response, session).
try {
ExecutionContext econtext = new ExecutionContext();
// Bridge with old XWiki Context, required for old code.
this.xcontext.declareInExecutionContext(econtext);
this.ecim.initialize(econtext);
} catch (ExecutionContextException e) {
throw new Exception("Failed to initialize Execution Context.", e);
}
this.xcontext.setWikiId(wikiId);
this.xcontext.setMainXWiki(wikiId);
// Use a dummy Request/Response even in daemon mode so that XWiki's initialization can create a Servlet URL
// Factory and any code requiring those objects will work.
this.xcontext.setRequest(new XWikiServletRequestStub());
this.xcontext.setResponse(new XWikiServletResponseStub());
// Use a dummy URL so that XWiki's initialization can create a Servlet URL Factory. We could also have
// registered a custom XWikiURLFactory against XWikiURLFactoryService but it's more work.
this.xcontext.setURL(new URL("http://localhost/xwiki/bin/DummyAction/DumySpace/DummyPage"));
// Set a dummy Document in the context to act as the current document since when a document containing
// objects is imported it'll generate Object diff events and the algorithm to compute an object diff
// currently requires rendering object properties, which requires a current document in the context.
this.xcontext.setDoc(new XWikiDocument(new DocumentReference(wikiId, "dummySpace", "dummyPage")));
XWikiConfig config = new XWikiConfig();
config.put("xwiki.store.class", "com.xpn.xwiki.store.XWikiHibernateStore");
// The XWikiConfig object requires path to be in unix format (i.e. with forward slashes)
String hibernateConfigInUnixFormat = hibernateConfig.getPath().replace('\\', '/');
config.put("xwiki.store.hibernate.path", hibernateConfigInUnixFormat);
config.put("xwiki.store.hibernate.updateschema", "1");
// Enable backlinks so that when documents are imported their backlinks will be saved too
config.put("xwiki.backlinks", "1");
XWiki xwiki = new XWiki(config, this.xcontext, null, true);
this.xcontext.setUserReference(new DocumentReference("xwiki", "XWiki", "superadmin"));
try {
this.xcontext.setURLFactory(new XWikiServletURLFactory(new URL("http://localhost:8080"), "xwiki/", "bin/"));
} catch (MalformedURLException e) {
// doesn't work with external code.
throw new XWikiException(XWikiException.MODULE_XWIKI_PLUGINS, XWikiException.ERROR_XWIKI_UNKNOWN, "Failed to set up URL Factory", e);
}
// Trigger extensions that need to initialize the database (create classes, etc.)
xwiki.initializeWiki(this.xcontext.getMainXWiki(), true, this.xcontext);
return this.xcontext;
}
use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.
the class DefaultDistributionManager method startFarmJob.
@Override
public DefaultDistributionJob startFarmJob() {
try {
this.farmDistributionJob = this.componentManager.getInstance(Job.class, DefaultDistributionJob.HINT);
XWikiContext xcontext = this.xcontextProvider.get();
final DistributionRequest request = new DistributionRequest();
request.setId(getFarmJobId());
request.setWiki(xcontext.getMainXWiki());
request.setUserReference(xcontext.getUserReference());
request.setInteractive(this.configuration.getProperty("distribution.job.interactive", true));
Thread distributionJobThread = new Thread(new Runnable() {
@Override
public void run() {
// Create a clean Execution Context
ExecutionContext context = new ExecutionContext();
try {
executionContextManager.initialize(context);
} catch (ExecutionContextException e) {
throw new RuntimeException("Failed to initialize farm distribution job execution context", e);
}
farmDistributionJob.initialize(request);
farmDistributionJob.run();
}
});
distributionJobThread.setDaemon(true);
distributionJobThread.setName("Farm distribution initialization");
distributionJobThread.start();
// Wait until the job is ready (or finished)
this.farmDistributionJob.awaitReady();
return this.farmDistributionJob;
} catch (Exception e) {
this.logger.error("Failed to create farm distribution job", e);
}
return null;
}
use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.
the class DocumentTitleDisplayerTest method configure.
@Before
public void configure() throws Exception {
// The execution context is expected to have the "xwikicontext" property set.
Execution mockExecution = this.mocker.getInstance(Execution.class);
ExecutionContext executionContext = new ExecutionContext();
executionContext.setProperty("xwikicontext", new HashMap<String, Object>());
Mockito.when(mockExecution.getContext()).thenReturn(executionContext);
}
Aggregations