Search in sources :

Example 1 with HibernateStore

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);
}
Also used : SessionFactory(org.hibernate.SessionFactory) HibernateSessionFactory(com.xpn.xwiki.store.hibernate.HibernateSessionFactory) ExecutionContext(org.xwiki.context.ExecutionContext) Execution(org.xwiki.context.Execution) HibernateStore(com.xpn.xwiki.internal.store.hibernate.HibernateStore) Configuration(org.hibernate.cfg.Configuration) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) HibernateSessionFactory(com.xpn.xwiki.store.hibernate.HibernateSessionFactory) Before(org.junit.Before)

Aggregations

XWiki (com.xpn.xwiki.XWiki)1 XWikiContext (com.xpn.xwiki.XWikiContext)1 HibernateStore (com.xpn.xwiki.internal.store.hibernate.HibernateStore)1 HibernateSessionFactory (com.xpn.xwiki.store.hibernate.HibernateSessionFactory)1 SessionFactory (org.hibernate.SessionFactory)1 Configuration (org.hibernate.cfg.Configuration)1 Before (org.junit.Before)1 Execution (org.xwiki.context.Execution)1 ExecutionContext (org.xwiki.context.ExecutionContext)1