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

File DistributionPingDataProviderTest.java

 

Code metrics

0
27
2
1
92
56
2
0.07
13.5
2
1

Classes

Class Line # Actions
DistributionPingDataProviderTest 45 27 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.Map;
23    import java.util.UUID;
24   
25    import org.junit.Rule;
26    import org.junit.Test;
27    import org.xwiki.activeinstalls.internal.client.data.DistributionPingDataProvider;
28    import org.xwiki.extension.CoreExtension;
29    import org.xwiki.extension.ExtensionId;
30    import org.xwiki.extension.repository.CoreExtensionRepository;
31    import org.xwiki.instance.InstanceId;
32    import org.xwiki.instance.InstanceIdManager;
33    import org.xwiki.test.mockito.MockitoComponentMockingRule;
34   
35    import static org.junit.Assert.assertEquals;
36    import static org.mockito.Mockito.mock;
37    import static org.mockito.Mockito.when;
38   
39    /**
40    * Unit tests for {@link org.xwiki.activeinstalls.internal.client.data.DistributionPingDataProvider}.
41    *
42    * @version $Id: dc0c8928f5a9e5ea7b5be29ad7e7a8e16336b063 $
43    * @since 6.1M1
44    */
 
45    public class DistributionPingDataProviderTest
46    {
47    @Rule
48    public MockitoComponentMockingRule<DistributionPingDataProvider> mocker =
49    new MockitoComponentMockingRule<>(DistributionPingDataProvider.class);
50   
 
51  1 toggle @Test
52    public void provideMapping() throws Exception
53    {
54  1 Map<String, Object> mapping = this.mocker.getComponentUnderTest().provideMapping();
55  1 assertEquals(4, mapping.size());
56   
57  1 Map<String, Object> propertiesMapping = (Map<String, Object>) mapping.get("distributionId");
58  1 assertEquals(2, propertiesMapping.size());
59  1 assertEquals("not_analyzed", propertiesMapping.get("index"));
60  1 assertEquals("string", propertiesMapping.get("type"));
61   
62  1 propertiesMapping = (Map<String, Object>) mapping.get("distributionVersion");
63  1 assertEquals(2, propertiesMapping.size());
64  1 assertEquals("not_analyzed", propertiesMapping.get("index"));
65  1 assertEquals("string", propertiesMapping.get("type"));
66   
67  1 propertiesMapping = (Map<String, Object>) mapping.get("instanceId");
68  1 assertEquals(2, propertiesMapping.size());
69  1 assertEquals("not_analyzed", propertiesMapping.get("index"));
70  1 assertEquals("string", propertiesMapping.get("type"));
71    }
72   
 
73  1 toggle @Test
74    public void provideData() throws Exception
75    {
76  1 InstanceId id = new InstanceId(UUID.randomUUID().toString());
77  1 InstanceIdManager idManager = this.mocker.getInstance(InstanceIdManager.class);
78  1 when(idManager.getInstanceId()).thenReturn(id);
79   
80  1 ExtensionId environmentExtensionId = new ExtensionId("environmentextensionid", "2.0");
81  1 CoreExtension environmentExtension = mock(CoreExtension.class);
82  1 when(environmentExtension.getId()).thenReturn(environmentExtensionId);
83  1 CoreExtensionRepository CoreExtensionRepository = this.mocker.getInstance(CoreExtensionRepository.class);
84  1 when(CoreExtensionRepository.getEnvironmentExtension()).thenReturn(environmentExtension);
85   
86  1 Map<String, Object> data = this.mocker.getComponentUnderTest().provideData();
87  1 assertEquals(3, data.size());
88  1 assertEquals("environmentextensionid", data.get("distributionId"));
89  1 assertEquals("2.0", data.get("distributionVersion"));
90  1 assertEquals(id.getInstanceId(), data.get("instanceId"));
91    }
92    }