1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.activeinstalls.internal.client; |
21 |
|
|
22 |
|
import java.sql.DatabaseMetaData; |
23 |
|
import java.util.Map; |
24 |
|
|
25 |
|
import org.junit.Rule; |
26 |
|
import org.junit.Test; |
27 |
|
import org.xwiki.activeinstalls.internal.client.data.DatabasePingDataProvider; |
28 |
|
import org.xwiki.context.Execution; |
29 |
|
import org.xwiki.context.ExecutionContext; |
30 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
31 |
|
|
32 |
|
import com.xpn.xwiki.XWikiContext; |
33 |
|
import com.xpn.xwiki.store.XWikiCacheStoreInterface; |
34 |
|
import com.xpn.xwiki.store.XWikiHibernateStore; |
35 |
|
|
36 |
|
import static org.junit.Assert.*; |
37 |
|
import static org.mockito.Mockito.mock; |
38 |
|
import static org.mockito.Mockito.when; |
39 |
|
|
40 |
|
|
41 |
|
@link |
42 |
|
|
43 |
|
@version |
44 |
|
@since |
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (31) |
Complexity: 2 |
Complexity Density: 0.07 |
|
46 |
|
public class DatabasePingDataProviderTest |
47 |
|
{ |
48 |
|
@Rule |
49 |
|
public MockitoComponentMockingRule<DatabasePingDataProvider> mocker = |
50 |
|
new MockitoComponentMockingRule<>(DatabasePingDataProvider.class); |
51 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
52 |
1 |
@Test... |
53 |
|
public void provideMapping() throws Exception |
54 |
|
{ |
55 |
1 |
Map<String, Object> mapping = this.mocker.getComponentUnderTest().provideMapping(); |
56 |
1 |
assertEquals(2, mapping.size()); |
57 |
|
|
58 |
1 |
Map<String, Object> propertiesMapping = (Map<String, Object>) mapping.get("dbName"); |
59 |
1 |
assertEquals(2, propertiesMapping.size()); |
60 |
1 |
assertEquals("not_analyzed", propertiesMapping.get("index")); |
61 |
1 |
assertEquals("string", propertiesMapping.get("type")); |
62 |
|
|
63 |
1 |
propertiesMapping = (Map<String, Object>) mapping.get("dbName"); |
64 |
1 |
assertEquals(2, propertiesMapping.size()); |
65 |
1 |
assertEquals("not_analyzed", propertiesMapping.get("index")); |
66 |
1 |
assertEquals("string", propertiesMapping.get("type")); |
67 |
|
} |
68 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
69 |
1 |
@Test... |
70 |
|
public void provideData() throws Exception |
71 |
|
{ |
72 |
1 |
Execution execution = this.mocker.getInstance(Execution.class); |
73 |
1 |
ExecutionContext executionContext = mock(ExecutionContext.class); |
74 |
1 |
when(execution.getContext()).thenReturn(executionContext); |
75 |
1 |
XWikiContext xwikiContext = mock(XWikiContext.class); |
76 |
1 |
when(executionContext.getProperty(XWikiContext.EXECUTIONCONTEXT_KEY)).thenReturn(xwikiContext); |
77 |
1 |
com.xpn.xwiki.XWiki xwiki = mock(com.xpn.xwiki.XWiki.class); |
78 |
1 |
when(xwikiContext.getWiki()).thenReturn(xwiki); |
79 |
1 |
XWikiCacheStoreInterface cacheStore = mock(XWikiCacheStoreInterface.class); |
80 |
1 |
when(xwiki.getStore()).thenReturn(cacheStore); |
81 |
1 |
XWikiHibernateStore store = mock(XWikiHibernateStore.class); |
82 |
1 |
when(cacheStore.getStore()).thenReturn(store); |
83 |
1 |
DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class); |
84 |
1 |
when(store.getDatabaseMetaData()).thenReturn(databaseMetaData); |
85 |
1 |
when(databaseMetaData.getDatabaseProductName()).thenReturn("HSQL Database Engine"); |
86 |
1 |
when(databaseMetaData.getDatabaseProductVersion()).thenReturn("2.2.9"); |
87 |
|
|
88 |
1 |
Map<String, Object> data = this.mocker.getComponentUnderTest().provideData(); |
89 |
1 |
assertEquals(2, data.size()); |
90 |
1 |
assertEquals("HSQL Database Engine", data.get("dbName")); |
91 |
1 |
assertEquals("2.2.9", data.get("dbVersion")); |
92 |
|
} |
93 |
|
} |