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

File ServletContainerPingDataProviderTest.java

 

Code metrics

0
19
2
1
81
45
2
0.11
9.5
2
1

Classes

Class Line # Actions
ServletContainerPingDataProviderTest 43 19 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   
24    import javax.servlet.ServletContext;
25   
26    import org.junit.Rule;
27    import org.junit.Test;
28    import org.xwiki.activeinstalls.internal.client.data.ServletContainerPingDataProvider;
29    import org.xwiki.component.util.ReflectionUtils;
30    import org.xwiki.environment.internal.ServletEnvironment;
31    import org.xwiki.test.mockito.MockitoComponentMockingRule;
32   
33    import static org.junit.Assert.assertEquals;
34    import static org.mockito.Mockito.mock;
35    import static org.mockito.Mockito.when;
36   
37    /**
38    * Unit tests for {@link org.xwiki.activeinstalls.internal.client.data.ServletContainerPingDataProvider}.
39    *
40    * @version $Id: 85aa8f220339c049b9187719670a02c3e68600c3 $
41    * @since 6.1M1
42    */
 
43    public class ServletContainerPingDataProviderTest
44    {
45    @Rule
46    public MockitoComponentMockingRule<ServletContainerPingDataProvider> mocker =
47    new MockitoComponentMockingRule<>(ServletContainerPingDataProvider.class);
48   
 
49  1 toggle @Test
50    public void provideMapping() throws Exception
51    {
52  1 Map<String, Object> mapping = this.mocker.getComponentUnderTest().provideMapping();
53  1 assertEquals(2, mapping.size());
54   
55  1 Map<String, Object> propertiesMapping = (Map<String, Object>) mapping.get("servletContainerVersion");
56  1 assertEquals(2, propertiesMapping.size());
57  1 assertEquals("not_analyzed", propertiesMapping.get("index"));
58  1 assertEquals("string", propertiesMapping.get("type"));
59   
60  1 propertiesMapping = (Map<String, Object>) mapping.get("servletContainerName");
61  1 assertEquals(2, propertiesMapping.size());
62  1 assertEquals("not_analyzed", propertiesMapping.get("index"));
63  1 assertEquals("string", propertiesMapping.get("type"));
64    }
65   
 
66  1 toggle @Test
67    public void provideData() throws Exception
68    {
69  1 ServletEnvironment servletEnvironment = mock(ServletEnvironment.class);
70  1 ReflectionUtils.setFieldValue(this.mocker.getComponentUnderTest(), "environment", servletEnvironment);
71   
72  1 ServletContext servletContext = mock(ServletContext.class);
73  1 when(servletEnvironment.getServletContext()).thenReturn(servletContext);
74  1 when(servletContext.getServerInfo()).thenReturn("Apache Tomcat/7.0.4 (optional text)");
75   
76  1 Map<String, Object> data = this.mocker.getComponentUnderTest().provideData();
77  1 assertEquals(2, data.size());
78  1 assertEquals("7.0.4", data.get("servletContainerVersion"));
79  1 assertEquals("Apache Tomcat", data.get("servletContainerName"));
80    }
81    }