1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
|
41 |
|
|
42 |
|
@param |
43 |
|
@version |
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
|
45 |
|
public abstract class AbstractXWikiHibernateStoreTest<T> |
46 |
|
{ |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
protected XWikiContext context = mock(XWikiContext.class); |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
protected Session session = mock(Session.class); |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
protected Transaction transaction = mock(Transaction.class); |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
|
62 |
14 |
@Before... |
63 |
|
public void setUp() throws Exception |
64 |
|
{ |
65 |
|
|
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 |
|
|
80 |
|
|
81 |
14 |
HibernateSessionFactory sessionFactory = getMocker().getInstance(HibernateSessionFactory.class); |
82 |
14 |
when(sessionFactory.getConfiguration()).thenReturn(mock(Configuration.class)); |
83 |
|
|
84 |
|
|
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 |
|
|
92 |
14 |
when(context.get("hibsession")).thenReturn(null, session); |
93 |
14 |
when(context.get("hibtransaction")).thenReturn(null, transaction); |
94 |
|
} |
95 |
|
|
96 |
|
|
97 |
|
@return |
98 |
|
|
99 |
|
protected abstract MockitoComponentMockingRule<T> getMocker(); |
100 |
|
} |