Search in sources :

Example 76 with ExecutionContext

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;
}
Also used : NotificationPreference(org.xwiki.notifications.preferences.NotificationPreference) ExecutionContext(org.xwiki.context.ExecutionContext) List(java.util.List)

Example 77 with ExecutionContext

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);
}
Also used : Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki)

Example 78 with ExecutionContext

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());
}
Also used : XWikiStubContextProvider(com.xpn.xwiki.util.XWikiStubContextProvider) ExecutionContext(org.xwiki.context.ExecutionContext) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) ExecutionContextException(org.xwiki.context.ExecutionContextException)

Example 79 with ExecutionContext

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);
}
Also used : ExecutionContext(org.xwiki.context.ExecutionContext) Execution(org.xwiki.context.Execution) Before(org.junit.Before)

Example 80 with ExecutionContext

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());
}
Also used : SolrFieldNameEncoder(org.xwiki.search.solr.internal.api.SolrFieldNameEncoder) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) ExecutionContext(org.xwiki.context.ExecutionContext) Execution(org.xwiki.context.Execution) InvocationOnMock(org.mockito.invocation.InvocationOnMock) EntityReference(org.xwiki.model.reference.EntityReference) Before(org.junit.Before)

Aggregations

ExecutionContext (org.xwiki.context.ExecutionContext)114 Execution (org.xwiki.context.Execution)62 XWikiContext (com.xpn.xwiki.XWikiContext)47 Before (org.junit.Before)31 Test (org.junit.Test)25 XWiki (com.xpn.xwiki.XWiki)19 DocumentReference (org.xwiki.model.reference.DocumentReference)19 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)15 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)14 ComponentManager (org.xwiki.component.manager.ComponentManager)9 ExecutionContextException (org.xwiki.context.ExecutionContextException)9 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)9 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)8 ExecutionContextManager (org.xwiki.context.ExecutionContextManager)8 List (java.util.List)6 Map (java.util.Map)6 Properties (java.util.Properties)6 Session (javax.mail.Session)6 MimeMessage (javax.mail.internet.MimeMessage)6 XWikiException (com.xpn.xwiki.XWikiException)5