use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.
the class CachedModelBridge method getNotificationsPreferences.
@Override
public List<NotificationPreference> getNotificationsPreferences(WikiReference wikiReference) throws NotificationException {
// We need to store the wiki reference in the cache's key
final String specificWikiNotificationsPreferences = String.format(CACHE_KEY_PATTERN, WIKI_NOTIFICATIONS_PREFERENCES, serializer.serialize(wikiReference));
ExecutionContext context = execution.getContext();
if (context.hasProperty(specificWikiNotificationsPreferences)) {
return (List<NotificationPreference>) context.getProperty(specificWikiNotificationsPreferences);
}
List<NotificationPreference> preferences = modelBridge.getNotificationsPreferences(wikiReference);
context.setProperty(specificWikiNotificationsPreferences, preferences);
return preferences;
}
use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.
the class ReferenceUserIteratorTest method setUpBaseMocks.
private void setUpBaseMocks() throws Exception {
this.resolver = this.componentManager.registerMockComponent(DocumentReferenceResolver.TYPE_STRING, "explicit");
this.execution = this.componentManager.registerMockComponent(Execution.class);
this.xwikiContext = mock(XWikiContext.class);
ExecutionContext executionContext = new ExecutionContext();
executionContext.setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, this.xwikiContext);
when(this.execution.getContext()).thenReturn(executionContext);
this.xwiki = mock(XWiki.class);
when(this.xwikiContext.getWiki()).thenReturn(this.xwiki);
}
use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.
the class XWikiStubContextInitializerTest method testWithAndWithoutXWikiContext.
public void testWithAndWithoutXWikiContext() throws Exception {
XWikiContext xcontext = new XWikiContext();
xcontext.put("key", "value");
this.mockXWiki = mock(XWiki.class);
this.mockXWiki.stubs().method("prepareResources");
xcontext.setWiki((XWiki) this.mockXWiki.proxy());
ExecutionContext context = new ExecutionContext();
xcontext.declareInExecutionContext(context);
XWikiStubContextProvider stubContextProvider = getComponentManager().getInstance(XWikiStubContextProvider.class);
stubContextProvider.initialize(xcontext);
final ExecutionContext daemonContext = new ExecutionContext();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
executionContextManager.initialize(daemonContext);
} catch (ExecutionContextException e) {
fail("Failed to initialize execution context: " + e.getStackTrace());
}
}
});
thread.start();
thread.join();
XWikiContext daemonXcontext = (XWikiContext) daemonContext.getProperty("xwikicontext");
assertNotNull(daemonXcontext);
assertNotSame(xcontext, daemonXcontext);
assertEquals("value", daemonXcontext.get("key"));
assertNotNull(daemonXcontext.getWiki());
}
use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.
the class HibernateStoreTest method before.
@Before
public void before() throws ComponentLookupException {
ExecutionContext executionContext = mock(ExecutionContext.class);
Execution execution = this.mocker.getInstance(Execution.class);
when(execution.getContext()).thenReturn(executionContext);
when(executionContext.getProperty("hibtransaction")).thenReturn(transaction);
}
use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.
the class DocumentSolrMetadataExtractorTest method setUp.
@Before
public void setUp() throws Exception {
this.mocker.registerMockComponent(SolrReferenceResolver.class, "document");
// XWikiContext Provider
Provider<XWikiContext> xcontextProvider = this.mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
when(xcontextProvider.get()).thenReturn(this.xcontext);
// XWikiContext trough Execution
ExecutionContext executionContext = new ExecutionContext();
executionContext.setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, this.xcontext);
Execution execution = this.mocker.registerMockComponent(Execution.class);
when(execution.getContext()).thenReturn(executionContext);
// XWiki
XWiki wiki = mock(XWiki.class);
when(this.xcontext.getWiki()).thenReturn(wiki);
// XWikiDocument
when(wiki.getDocument(this.documentReference, this.xcontext)).thenReturn(this.document);
when(this.document.getDocumentReference()).thenReturn(this.documentReference);
when(this.document.isHidden()).thenReturn(false);
when(this.document.getLocale()).thenReturn(Locale.ROOT);
when(this.document.getRealLocale()).thenReturn(Locale.US);
when(this.document.getTranslatedDocument(Locale.FRENCH, this.xcontext)).thenReturn(this.translatedDocument);
when(this.translatedDocument.getRealLocale()).thenReturn(Locale.FRENCH);
when(this.translatedDocument.getLocale()).thenReturn(Locale.FRENCH);
when(this.translatedDocument.getDocumentReference()).thenReturn(this.frenchDocumentReference);
// Field Name Serializer
EntityReferenceSerializer<String> fieldNameSerializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING, "solr");
when(fieldNameSerializer.serialize(any())).then(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
EntityReference reference = (EntityReference) invocation.getArguments()[0];
StringBuilder result = new StringBuilder();
for (EntityReference parent : reference.getReversedReferenceChain()) {
result.append('.').append(parent.getName());
}
return result.substring(1);
}
});
// Field Name Encoder
SolrFieldNameEncoder fieldNameEncoder = this.mocker.getInstance(SolrFieldNameEncoder.class);
when(fieldNameEncoder.encode(any())).then(AdditionalAnswers.returnsFirstArg());
}
Aggregations