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

File ExtensionPingDataProviderTest.java

 

Code metrics

0
36
2
1
106
67
2
0.06
18
2
1

Classes

Class Line # Actions
ExtensionPingDataProviderTest 48 36 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.util.Arrays;
23    import java.util.Collections;
24    import java.util.Map;
25   
26    import org.junit.Rule;
27    import org.junit.Test;
28    import org.xwiki.activeinstalls.internal.client.data.ExtensionPingDataProvider;
29    import org.xwiki.extension.ExtensionId;
30    import org.xwiki.extension.InstalledExtension;
31    import org.xwiki.extension.repository.InstalledExtensionRepository;
32    import org.xwiki.test.mockito.MockitoComponentMockingRule;
33   
34    import net.sf.json.JSONArray;
35    import net.sf.json.JSONObject;
36   
37    import static org.junit.Assert.assertArrayEquals;
38    import static org.junit.Assert.assertEquals;
39    import static org.mockito.Mockito.mock;
40    import static org.mockito.Mockito.when;
41   
42    /**
43    * Unit tests for {@link org.xwiki.activeinstalls.internal.client.data.ExtensionPingDataProvider}.
44    *
45    * @version $Id: cbd6f08938b39f938e4a37bf854e34f6c5ceadac $
46    * @since 6.1M1
47    */
 
48    public class ExtensionPingDataProviderTest
49    {
50    @Rule
51    public MockitoComponentMockingRule<ExtensionPingDataProvider> mocker =
52    new MockitoComponentMockingRule<>(ExtensionPingDataProvider.class);
53   
 
54  1 toggle @Test
55    public void provideMapping() throws Exception
56    {
57  1 Map<String, Object> mapping = this.mocker.getComponentUnderTest().provideMapping();
58  1 assertEquals(1, mapping.size());
59   
60  1 Map<String, Object> extensionsMapping = (Map<String, Object>) mapping.get("extensions");
61  1 assertEquals(1, extensionsMapping.size());
62   
63  1 Map<String, Object> propertiesMapping = (Map<String, Object>) extensionsMapping.get("properties");
64  1 assertEquals(3, propertiesMapping.size());
65   
66  1 Map<String, Object> propertyMapping = (Map<String, Object>) propertiesMapping.get("id");
67  1 assertEquals(2, propertyMapping.size());
68  1 assertEquals("not_analyzed", propertyMapping.get("index"));
69  1 assertEquals("string", propertyMapping.get("type"));
70   
71  1 propertyMapping = (Map<String, Object>) propertiesMapping.get("version");
72  1 assertEquals(2, propertyMapping.size());
73  1 assertEquals("not_analyzed", propertyMapping.get("index"));
74  1 assertEquals("string", propertyMapping.get("type"));
75   
76  1 propertyMapping = (Map<String, Object>) propertiesMapping.get("features");
77  1 assertEquals(2, propertyMapping.size());
78  1 assertEquals("not_analyzed", propertyMapping.get("index"));
79  1 assertEquals("string", propertyMapping.get("type"));
80    }
81   
 
82  1 toggle @Test
83    public void provideData() throws Exception
84    {
85  1 ExtensionId extensionId = new ExtensionId("extensionid", "1.0");
86  1 InstalledExtension extension = mock(InstalledExtension.class);
87  1 when(extension.getId()).thenReturn(extensionId);
88  1 when(extension.getFeatures()).thenReturn(Arrays.asList("feature1", "feature2"));
89   
90  1 InstalledExtensionRepository repository = this.mocker.getInstance(InstalledExtensionRepository.class);
91  1 when(repository.getInstalledExtensions()).thenReturn(Collections.singletonList(extension));
92   
93  1 Map<String, Object> data = this.mocker.getComponentUnderTest().provideData();
94  1 assertEquals(1, data.size());
95  1 JSONObject[] extensions = (JSONObject[]) data.get("extensions");
96  1 assertEquals(1, extensions.length);
97  1 JSONObject propertiesData = extensions[0];
98  1 assertEquals(3, propertiesData.size());
99  1 assertEquals("extensionid", propertiesData.get("id"));
100  1 assertEquals("1.0", propertiesData.get("version"));
101  1 JSONArray features = (JSONArray) propertiesData.get("features");
102  1 assertEquals(2, features.size());
103  1 assertEquals("feature1", features.get(0));
104  1 assertEquals("feature2", features.get(1));
105    }
106    }