Search in sources :

Example 46 with ExecutionContext

use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.

the class WikiCreationJobScriptServicesTest method setUp.

@Before
public void setUp() throws Exception {
    wikiCreator = mocker.getInstance(WikiCreator.class);
    execution = mocker.getInstance(Execution.class);
    authorizationManager = mocker.getInstance(AuthorizationManager.class);
    wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class);
    distributionManager = mocker.getInstance(DistributionManager.class);
    xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
    xcontext = mock(XWikiContext.class);
    when(xcontextProvider.get()).thenReturn(xcontext);
    xwiki = mock(XWiki.class);
    when(xcontext.getWiki()).thenReturn(xwiki);
    when(wikiDescriptorManager.getMainWikiId()).thenReturn("mainWikiId");
    ExecutionContext executionContext = new ExecutionContext();
    when(execution.getContext()).thenReturn(executionContext);
    ExtensionId extensionId = new ExtensionId("authorized-extension", "1.0");
    when(distributionManager.getWikiUIExtensionId()).thenReturn(extensionId);
}
Also used : Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) WikiCreator(org.xwiki.platform.wiki.creationjob.WikiCreator) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) ExtensionId(org.xwiki.extension.ExtensionId) AuthorizationManager(org.xwiki.security.authorization.AuthorizationManager) DistributionManager(org.xwiki.extension.distribution.internal.DistributionManager) Before(org.junit.Before)

Example 47 with ExecutionContext

use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.

the class DefaultWikiComponentBridgeTest method configure.

@Before
public void configure() throws Exception {
    getMockery().setImposteriser(ClassImposteriser.INSTANCE);
    Utils.setComponentManager(getComponentManager());
    final Execution execution = registerMockComponent(Execution.class);
    final ExecutionContext context = new ExecutionContext();
    final Provider<XWikiContext> xcontextProvider = registerMockComponent(XWikiContext.TYPE_PROVIDER);
    this.xwiki = getMockery().mock(XWiki.class);
    this.xwikiContext = new XWikiContext();
    this.xwikiContext.setWikiId("xwiki");
    this.xwikiContext.setWiki(this.xwiki);
    context.setProperty("xwikicontext", this.xwikiContext);
    this.componentDoc = getMockery().mock(XWikiDocument.class);
    this.componentObject = getMockery().mock(BaseObject.class, "component");
    getMockery().checking(new Expectations() {

        {
            allowing(xcontextProvider).get();
            will(returnValue(xwikiContext));
            allowing(execution).getContext();
            will(returnValue(context));
            allowing(xwiki).getDocument(DOC_REFERENCE, xwikiContext);
            will(returnValue(componentDoc));
        }
    });
    this.bridge = getComponentManager().getInstance(WikiComponentBridge.class);
}
Also used : Expectations(org.jmock.Expectations) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) DefaultWikiComponentBridge(org.xwiki.component.wiki.internal.bridge.DefaultWikiComponentBridge) WikiComponentBridge(org.xwiki.component.wiki.internal.bridge.WikiComponentBridge) BaseObject(com.xpn.xwiki.objects.BaseObject) Before(org.junit.Before)

Example 48 with ExecutionContext

use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.

the class DefaultTranslationBundleContext method getBundlesInternal.

/**
 * @return the current bundles
 */
private Map<String, SortedSet<TranslationBundle>> getBundlesInternal() {
    Map<String, SortedSet<TranslationBundle>> bundles;
    ExecutionContext context = this.execution.getContext();
    if (context != null) {
        bundles = (Map<String, SortedSet<TranslationBundle>>) context.getProperty(CKEY_BUNDLES);
        if (bundles == null) {
            // Register the Execution Context property with an empty map that will be populated for each wiki.
            bundles = new HashMap<>();
            context.newProperty(CKEY_BUNDLES).inherited().cloneValue().initial(bundles).declare();
        }
    } else {
        bundles = new HashMap<>();
    }
    return bundles;
}
Also used : ExecutionContext(org.xwiki.context.ExecutionContext) SortedSet(java.util.SortedSet)

Example 49 with ExecutionContext

use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.

the class CachedModelBridge method getNotificationsPreferences.

@Override
public List<NotificationPreference> getNotificationsPreferences(DocumentReference userReference) 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 specificUserNotificationsPreferences = String.format(CACHE_KEY_PATTERN, USER_NOTIFICATIONS_PREFERENCES, serializer.serialize(userReference));
    ExecutionContext context = execution.getContext();
    if (context.hasProperty(specificUserNotificationsPreferences)) {
        return (List<NotificationPreference>) context.getProperty(specificUserNotificationsPreferences);
    }
    List<NotificationPreference> preferences = modelBridge.getNotificationsPreferences(userReference);
    context.setProperty(specificUserNotificationsPreferences, preferences);
    return preferences;
}
Also used : NotificationPreference(org.xwiki.notifications.preferences.NotificationPreference) ExecutionContext(org.xwiki.context.ExecutionContext) List(java.util.List)

Example 50 with ExecutionContext

use of org.xwiki.context.ExecutionContext in project xwiki-platform by xwiki.

the class HqlQueryExecutorTest method before.

@Before
public void before() throws Exception {
    HibernateSessionFactory sessionFactory = this.mocker.getInstance(HibernateSessionFactory.class);
    when(sessionFactory.getConfiguration()).thenReturn(new Configuration());
    this.executor = this.mocker.getComponentUnderTest();
    this.authorization = this.mocker.getInstance(ContextualAuthorizationManager.class);
    when(this.authorization.hasAccess(Right.PROGRAM)).then(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            return hasProgrammingRight;
        }
    });
    this.hasProgrammingRight = true;
    // Actual Hibernate query
    Execution execution = this.mocker.getInstance(Execution.class);
    ExecutionContext executionContext = mock(ExecutionContext.class);
    when(execution.getContext()).thenReturn(executionContext);
    XWikiContext xwikiContext = mock(XWikiContext.class);
    when(executionContext.getProperty(XWikiContext.EXECUTIONCONTEXT_KEY)).thenReturn(xwikiContext);
    when(xwikiContext.getWikiId()).thenReturn("currentwikid");
    com.xpn.xwiki.XWiki xwiki = mock(com.xpn.xwiki.XWiki.class);
    when(xwikiContext.getWiki()).thenReturn(xwiki);
    this.store = mock(XWikiHibernateStore.class);
    when(xwiki.getHibernateStore()).thenReturn(store);
}
Also used : ContextualAuthorizationManager(org.xwiki.security.authorization.ContextualAuthorizationManager) Configuration(org.hibernate.cfg.Configuration) XWikiContext(com.xpn.xwiki.XWikiContext) Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) XWikiHibernateStore(com.xpn.xwiki.store.XWikiHibernateStore) InvocationOnMock(org.mockito.invocation.InvocationOnMock) HibernateSessionFactory(com.xpn.xwiki.store.hibernate.HibernateSessionFactory) 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