use of com.xpn.xwiki.internal.store.hibernate.HibernateStore 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);
}
Aggregations