1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.activeinstalls.internal.client

File DatabasePingDataProviderTest.java

 

Code metrics

0
29
2
1
93
58
2
0.07
14.5
2
1

Classes

Class Line # Actions
DatabasePingDataProviderTest 46 29 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 2 tests. .

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 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    * Unit tests for {@link org.xwiki.activeinstalls.internal.client.data.DatabasePingDataProvider}.
42    *
43    * @version $Id: 0b7c520e46b1bdbf3b89ddab22b03a8445a9caca $
44    * @since 6.1M1
45    */
 
46    public class DatabasePingDataProviderTest
47    {
48    @Rule
49    public MockitoComponentMockingRule<DatabasePingDataProvider> mocker =
50    new MockitoComponentMockingRule<>(DatabasePingDataProvider.class);
51   
 
52  1 toggle @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   
 
69  1 toggle @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    }