use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.
the class DefaultDocumentMergeImporterTest method setUp.
@Before
public void setUp() throws Exception {
this.xwiki = mock(XWiki.class);
when(this.xcontext.getWiki()).thenReturn(this.xwiki);
// documents
this.previousDocument = mock(XWikiDocument.class, "previous");
when(this.previousDocument.isNew()).thenReturn(false);
when(this.previousDocument.getDocumentReferenceWithLocale()).thenReturn(this.documentReference);
this.currentDocument = mock(XWikiDocument.class, "current");
when(this.currentDocument.isNew()).thenReturn(false);
when(this.currentDocument.getDocumentReferenceWithLocale()).thenReturn(this.documentReference);
when(this.xwiki.getDocument(same(this.documentReference), same(xcontext))).thenReturn(this.currentDocument);
this.nextDocument = mock(XWikiDocument.class, "next");
when(this.nextDocument.isNew()).thenReturn(false);
when(this.nextDocument.getDocumentReferenceWithLocale()).thenReturn(this.documentReference);
this.mergedDocument = mock(XWikiDocument.class, "merged");
when(this.mergedDocument.isNew()).thenReturn(false);
when(this.mergedDocument.getDocumentReferenceWithLocale()).thenReturn(this.documentReference);
when(this.currentDocument.clone()).thenReturn(this.mergedDocument);
// merge
this.configuration = new PackageConfiguration();
this.mergeResult = new MergeResult();
when(this.mergedDocument.merge(same(this.previousDocument), same(this.nextDocument), any(MergeConfiguration.class), any(XWikiContext.class))).thenReturn(this.mergeResult);
// job status
this.jobStatus = mock(JobStatus.class);
this.configuration.setJobStatus(this.jobStatus);
// execution
this.econtext = new ExecutionContext();
this.execution = this.mocker.getInstance(Execution.class);
when(this.execution.getContext()).thenReturn(this.econtext);
}
use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.
the class LESSContextTest method setUp.
@Before
public void setUp() throws Exception {
execution = mocker.getInstance(Execution.class);
executionContext = new ExecutionContext();
when(execution.getContext()).thenReturn(executionContext);
}
use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.
the class VelocityContextInitializerTest method testVelocityBridges.
/**
* Test the presence of velocity bridges.
*
* @throws Exception
*/
@Test
public void testVelocityBridges() throws Exception {
// Make sure the execution context is not null when velocity bridges are initialized.
getComponentManager().<Execution>getInstance(Execution.class).setContext(new ExecutionContext());
VelocityContextFactory factory = getComponentManager().getInstance(VelocityContextFactory.class);
VelocityContext context = factory.createContext();
Assert.assertNotNull(context.get("officeimporter"));
Assert.assertNotNull(context.get("ooconfig"));
Assert.assertNotNull(context.get("oomanager"));
}
use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.
the class CachedModelBridge method getToggeableFilterActivations.
@Override
public Map<String, Boolean> getToggeableFilterActivations(DocumentReference user) throws NotificationException {
// We need to store the user reference in the cache's key, otherwise all users of the same context will share
// the same cache, which can happen when a notification email is triggered.
final String contextEntry = String.format(CONTEXT_KEY_FORMAT, USER_TOGGLEABLE_FILTER_PREFERENCES, serializer.serialize(user));
ExecutionContext context = execution.getContext();
if (context.hasProperty(contextEntry)) {
return (Map<String, Boolean>) context.getProperty(contextEntry);
}
Map<String, Boolean> values = modelBridge.getToggeableFilterActivations(user);
context.setProperty(contextEntry, values);
return values;
}
use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.
the class DefaultVelocityManager method getVelocityEngineMacrosTemplate.
/**
* @return the key used to cache the Velocity Engines. We have one Velocity Engine per skin which has a macros.vm
* file on the filesystem. Right now we don't support macros.vm defined in custom skins in wiki pages.
*/
private Template getVelocityEngineMacrosTemplate() {
Template template = null;
Map<String, Template> templateCache = null;
Skin currentSkin = this.skinManager.getCurrentSkin(true);
// Generating this key is very expensive so we cache it in the context
ExecutionContext econtext = this.execution.getContext();
if (econtext != null) {
templateCache = (Map<String, Template>) econtext.getProperty(VELOCITYENGINE_CACHEKEY_NAME);
if (templateCache == null) {
templateCache = new HashMap<>();
econtext.setProperty(VELOCITYENGINE_CACHEKEY_NAME, templateCache);
} else {
template = templateCache.get(currentSkin.getId());
}
}
if (template == null) {
template = this.templates.get().getTemplate("macros.vm");
if (templateCache != null) {
templateCache.put(currentSkin.getId(), template);
}
}
return template;
}
Aggregations