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);
}
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);
}
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;
}
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;
}
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);
}
Aggregations