| 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.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 |
|
@link |
| 39 |
|
|
| 40 |
|
@version |
| 41 |
|
@since |
| 42 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 2 |
Complexity Density: 0.11 |
|
| 43 |
|
public class ServletContainerPingDataProviderTest |
| 44 |
|
{ |
| 45 |
|
@Rule |
| 46 |
|
public MockitoComponentMockingRule<ServletContainerPingDataProvider> mocker = |
| 47 |
|
new MockitoComponentMockingRule<>(ServletContainerPingDataProvider.class); |
| 48 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
| 49 |
1 |
@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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
| 66 |
1 |
@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 |
|
} |