use of org.xwiki.context.Execution in project xwiki-platform by xwiki.
the class IncludeMacroTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
// Put a fake XWiki context on the execution context.
Execution execution = getComponentManager().getInstance(Execution.class);
execution.getContext().setProperty("xwikicontext", new HashMap<Object, Object>());
}
use of org.xwiki.context.Execution in project xwiki-platform by xwiki.
the class DatabasePingDataProviderTest method provideData.
@Test
public void provideData() throws Exception {
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);
com.xpn.xwiki.XWiki xwiki = mock(com.xpn.xwiki.XWiki.class);
when(xwikiContext.getWiki()).thenReturn(xwiki);
XWikiCacheStoreInterface cacheStore = mock(XWikiCacheStoreInterface.class);
when(xwiki.getStore()).thenReturn(cacheStore);
XWikiHibernateStore store = mock(XWikiHibernateStore.class);
when(cacheStore.getStore()).thenReturn(store);
DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class);
when(store.getDatabaseMetaData()).thenReturn(databaseMetaData);
when(databaseMetaData.getDatabaseProductName()).thenReturn("HSQL Database Engine");
when(databaseMetaData.getDatabaseProductVersion()).thenReturn("2.2.9");
Map<String, Object> data = this.mocker.getComponentUnderTest().provideData();
assertEquals(2, data.size());
assertEquals("HSQL Database Engine", data.get("dbName"));
assertEquals("2.2.9", data.get("dbVersion"));
}
use of org.xwiki.context.Execution 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.Execution in project xwiki-platform by xwiki.
the class AbstractBridgedComponentTestCase method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
// Statically store the component manager in {@link Utils} to be able to access it without
// the context.
Utils.setComponentManager(getComponentManager());
this.context = new XWikiContext();
this.context.setWikiId("xwiki");
this.context.setMainXWiki("xwiki");
// We need to initialize the Component Manager so that the components can be looked up
getContext().put(ComponentManager.class.getName(), getComponentManager());
// Bridge with old XWiki Context, required for old code.
Execution execution = getComponentManager().getInstance(Execution.class);
execution.getContext().setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, this.context);
XWikiStubContextProvider stubContextProvider = getComponentManager().getInstance(XWikiStubContextProvider.class);
stubContextProvider.initialize(this.context);
// Since the oldcore module draws the Servlet Environment in its dependencies we need to ensure it's set up
// correctly with a Servlet Context.
ServletEnvironment environment = (ServletEnvironment) getComponentManager().getInstance(Environment.class);
final ServletContext mockServletContext = getMockery().mock(ServletContext.class);
environment.setServletContext(mockServletContext);
getMockery().checking(new Expectations() {
{
allowing(mockServletContext).getResourceAsStream("/WEB-INF/cache/infinispan/config.xml");
will(returnValue(null));
allowing(mockServletContext).getResourceAsStream("/WEB-INF/xwiki.cfg");
will(returnValue(null));
allowing(mockServletContext).getAttribute("javax.servlet.context.tempdir");
will(returnValue(new File(System.getProperty("java.io.tmpdir"))));
}
});
final CoreConfiguration mockCoreConfiguration = registerMockComponent(CoreConfiguration.class);
getMockery().checking(new Expectations() {
{
allowing(mockCoreConfiguration).getDefaultDocumentSyntax();
will(returnValue(Syntax.XWIKI_1_0));
}
});
}
use of org.xwiki.context.Execution 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