use of org.xwiki.context.Execution in project xwiki-platform by xwiki.
the class AbstractXWikiHibernateStoreTest method setUp.
@Before
public void setUp() throws Exception {
// For XWikiHibernateBaseStore#initialize()
ExecutionContext executionContext = mock(ExecutionContext.class);
when(executionContext.getProperty("xwikicontext")).thenReturn(xcontext);
Execution execution = getMocker().getInstance(Execution.class);
when(execution.getContext()).thenReturn(executionContext);
Provider<XWikiContext> xcontextProvider = getMocker().registerMockComponent(XWikiContext.TYPE_PROVIDER);
when(xcontextProvider.get()).thenReturn(this.xcontext);
xcontextProvider = getMocker().registerMockComponent(XWikiContext.TYPE_PROVIDER, "readonly");
when(xcontextProvider.get()).thenReturn(this.xcontext);
XWiki wiki = mock(XWiki.class);
when(this.xcontext.getWiki()).thenReturn(wiki);
// For XWikiHibernateBaseStore#initHibernate()
HibernateSessionFactory sessionFactory = getMocker().getInstance(HibernateSessionFactory.class);
when(sessionFactory.getConfiguration()).thenReturn(mock(Configuration.class));
// For XWikiHibernateBaseStore#beginTransaction()
SessionFactory wrappedSessionFactory = mock(SessionFactory.class);
when(sessionFactory.getSessionFactory()).thenReturn(wrappedSessionFactory);
when(wrappedSessionFactory.openSession()).thenReturn(session);
when(session.beginTransaction()).thenReturn(transaction);
// HibernateStore
this.hibernateStore = getMocker().registerMockComponent(HibernateStore.class);
// Return null on first get to force the session/transaction creation.
when(this.hibernateStore.getCurrentSession()).thenReturn(session);
when(this.hibernateStore.getCurrentTransaction()).thenReturn(transaction);
// Default is schema mode
when(this.hibernateStore.isInSchemaMode()).thenReturn(true);
}
use of org.xwiki.context.Execution in project xwiki-platform by xwiki.
the class ReferenceUserIteratorTest method getMembersWhenNoExecutionContext.
@Test
public void getMembersWhenNoExecutionContext() throws Exception {
Execution execution = this.componentManager.registerMockComponent(Execution.class);
DocumentReference userReference = new DocumentReference("userwiki", "XWiki", "userpage");
try {
new ReferenceUserIterator(userReference, null, execution).next();
} catch (RuntimeException expected) {
assertEquals("Aborting member extraction from passed references [[userwiki:XWiki.userpage]] since no " + "XWiki Context was found", expected.getMessage());
}
}
use of org.xwiki.context.Execution in project xwiki-platform by xwiki.
the class ReferenceUserIteratorTest method getMembersWhenNoXWikiContext.
@Test
public void getMembersWhenNoXWikiContext() throws Exception {
Execution execution = this.componentManager.registerMockComponent(Execution.class);
when(execution.getContext()).thenReturn(new ExecutionContext());
DocumentReference userReference = new DocumentReference("userwiki", "XWiki", "userpage");
try {
new ReferenceUserIterator(userReference, null, execution).next();
} catch (RuntimeException expected) {
assertEquals("Aborting member extraction from passed references [[userwiki:XWiki.userpage]] since no " + "XWiki Context was found", expected.getMessage());
}
}
use of org.xwiki.context.Execution in project xwiki-platform by xwiki.
the class CurrentLanguageQueryFilterTest method filterStatement.
@Test
public void filterStatement() 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")).thenReturn(xwikiContext);
com.xpn.xwiki.XWiki xwiki = mock(com.xpn.xwiki.XWiki.class);
when(xwikiContext.getWiki()).thenReturn(xwiki);
when(xwiki.getDefaultLocale(any(XWikiContext.class))).thenReturn(Locale.FRANCE);
String result = this.mocker.getComponentUnderTest().filterStatement("select doc.fullName from XWikiDocument doc where 1=1", Query.HQL);
assertEquals("select doc.fullName from XWikiDocument doc where (doc.language is null or doc.language = '' or " + "doc.language = 'fr_FR') and (1=1)", result);
}
use of org.xwiki.context.Execution in project xwiki-platform by xwiki.
the class DefaultWikiMacroTest method testDefaultParameterNames.
/**
* Makes sure getParameterNames return parameters with source case.
*/
@Test
public void testDefaultParameterNames() throws Exception {
// Velocity Manager mock.
final VelocityManager mockVelocityManager = getMockery().mock(VelocityManager.class);
DefaultComponentDescriptor<VelocityManager> descriptorVM = new DefaultComponentDescriptor<VelocityManager>();
descriptorVM.setRoleType(VelocityManager.class);
getComponentManager().registerComponent(descriptorVM, mockVelocityManager);
// Initialize velocity engine.
final VelocityEngine vEngine = getComponentManager().getInstance(VelocityEngine.class);
Properties properties = new Properties();
properties.setProperty("resource.loader", "file");
vEngine.initialize(properties);
// Hack into velocity context.
Execution execution = getComponentManager().getInstance(Execution.class);
Map<?, ?> xwikiContext = (Map<?, ?>) execution.getContext().getProperty("xwikicontext");
final VelocityContext vContext = new VelocityContext();
vContext.put("xcontext", xwikiContext);
getMockery().checking(new Expectations() {
{
oneOf(mockVelocityManager).getCurrentVelocityContext();
will(returnValue(vContext));
oneOf(mockVelocityManager).evaluate(with(any(Writer.class)), with(any(String.class)), with(any(Reader.class)));
will(new Action() {
@Override
public Object invoke(Invocation invocation) throws Throwable {
return vEngine.evaluate(vContext, (Writer) invocation.getParameter(0), (String) invocation.getParameter(1), (Reader) invocation.getParameter(2));
}
@Override
public void describeTo(Description description) {
}
});
}
});
registerWikiMacro("wikimacro1", "{{velocity}}$xcontext.macro.params.parameterNames{{/velocity}}", Syntax.XWIKI_2_0);
Converter converter = getComponentManager().getInstance(Converter.class);
DefaultWikiPrinter printer = new DefaultWikiPrinter();
converter.convert(new StringReader("{{wikimacro1 paRam1=\"value1\" paraM2=\"value2\"/}}"), Syntax.XWIKI_2_0, Syntax.PLAIN_1_0, printer);
Assert.assertEquals("[paRam1, paraM2]", printer.toString());
}
Aggregations