1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.store

File AbstractXWikiHibernateStoreTest.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

0
16
1
1
100
41
1
0.06
16
1
1

Classes

Class Line # Actions
AbstractXWikiHibernateStoreTest 45 16 0% 1 0
1.0100%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.store;
21   
22    import static org.mockito.Mockito.*;
23   
24    import javax.inject.Provider;
25   
26    import org.hibernate.SessionFactory;
27    import org.hibernate.Transaction;
28    import org.hibernate.cfg.Configuration;
29    import org.hibernate.classic.Session;
30    import org.junit.Before;
31    import org.xwiki.context.Execution;
32    import org.xwiki.context.ExecutionContext;
33    import org.xwiki.test.mockito.MockitoComponentMockingRule;
34   
35    import com.xpn.xwiki.XWiki;
36    import com.xpn.xwiki.XWikiContext;
37    import com.xpn.xwiki.store.hibernate.HibernateSessionFactory;
38   
39    /**
40    * Base class for Hibernate store unit tests.
41    *
42    * @param <T> the store type
43    * @version $Id: e51fc22af9afd687fc94ce23054ec9e3d20e8f29 $
44    */
 
45    public abstract class AbstractXWikiHibernateStoreTest<T>
46    {
47    /**
48    * The mock XWiki context.
49    */
50    protected XWikiContext context = mock(XWikiContext.class);
51   
52    /**
53    * The Hibernate session.
54    */
55    protected Session session = mock(Session.class);
56   
57    /**
58    * The Hibernate transaction.
59    */
60    protected Transaction transaction = mock(Transaction.class);
61   
 
62  14 toggle @Before
63    public void setUp() throws Exception
64    {
65    // For XWikiHibernateBaseStore#initialize()
66   
67  14 ExecutionContext executionContext = mock(ExecutionContext.class);
68  14 when(executionContext.getProperty("xwikicontext")).thenReturn(context);
69   
70  14 Execution execution = getMocker().getInstance(Execution.class);
71  14 when(execution.getContext()).thenReturn(executionContext);
72   
73  14 Provider<XWikiContext> xcontextProvider = getMocker().registerMockComponent(XWikiContext.TYPE_PROVIDER);
74  14 when(xcontextProvider.get()).thenReturn(this.context);
75   
76  14 XWiki wiki = mock(XWiki.class);
77  14 when(context.getWiki()).thenReturn(wiki);
78   
79    // For XWikiHibernateBaseStore#initHibernate()
80   
81  14 HibernateSessionFactory sessionFactory = getMocker().getInstance(HibernateSessionFactory.class);
82  14 when(sessionFactory.getConfiguration()).thenReturn(mock(Configuration.class));
83   
84    // For XWikiHibernateBaseStore#beginTransaction()
85   
86  14 SessionFactory wrappedSessionFactory = mock(SessionFactory.class);
87  14 when(sessionFactory.getSessionFactory()).thenReturn(wrappedSessionFactory);
88  14 when(wrappedSessionFactory.openSession()).thenReturn(session);
89  14 when(session.beginTransaction()).thenReturn(transaction);
90   
91    // Return null on first get to force the session/transaction creation.
92  14 when(context.get("hibsession")).thenReturn(null, session);
93  14 when(context.get("hibtransaction")).thenReturn(null, transaction);
94    }
95   
96    /**
97    * @return the component manager
98    */
99    protected abstract MockitoComponentMockingRule<T> getMocker();
100    }