1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.extension.internal

File DefaultExtensionManagerConfigurationTest.java

 

Code metrics

0
20
5
1
117
74
5
0.25
4
5
1

Classes

Class Line # Actions
DefaultExtensionManagerConfigurationTest 48 20 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 3 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.extension.internal;
21   
22    import java.net.URI;
23    import java.net.URISyntaxException;
24    import java.util.ArrayList;
25    import java.util.Arrays;
26    import java.util.Collection;
27   
28    import org.junit.Assert;
29    import org.junit.Before;
30    import org.junit.Rule;
31    import org.junit.Test;
32    import org.slf4j.Logger;
33    import org.xwiki.configuration.internal.MemoryConfigurationSource;
34    import org.xwiki.extension.ExtensionManagerConfiguration;
35    import org.xwiki.extension.repository.DefaultExtensionRepositoryDescriptor;
36    import org.xwiki.extension.repository.ExtensionRepositoryDescriptor;
37    import org.xwiki.test.AllLogRule;
38    import org.xwiki.test.annotation.BeforeComponent;
39    import org.xwiki.test.annotation.ComponentList;
40    import org.xwiki.test.mockito.MockitoComponentMockingRule;
41   
42    /**
43    * Unit test for {@link DefaultExtensionManagerConfiguration}.
44    *
45    * @version $Id: 7bd0eb1c6516ff823ad6a35c9c7cdd5f5dc9ad63 $
46    */
47    @ComponentList({ ExtensionFactory.class })
 
48    public class DefaultExtensionManagerConfigurationTest
49    {
50    @Rule
51    public final MockitoComponentMockingRule<ExtensionManagerConfiguration> componentManager =
52    new MockitoComponentMockingRule<>(DefaultExtensionManagerConfiguration.class, Arrays.asList(Logger.class));
53   
54    @Rule
55    public AllLogRule log = new AllLogRule();
56   
57    private ExtensionManagerConfiguration configuration;
58   
59    private MemoryConfigurationSource source;
60   
 
61  3 toggle @BeforeComponent
62    public void registerComponents() throws Exception
63    {
64    // Register some in-memory Configuration Source for the test
65  3 this.source = this.componentManager.registerMemoryConfigurationSource();
66    }
67   
 
68  3 toggle @Before
69    public void setUp() throws Exception
70    {
71  3 this.configuration = this.componentManager.getComponentUnderTest();
72    }
73   
 
74  1 toggle @Test
75    public void testGetRepositoriesWithInvalid() throws Exception
76    {
77    // We define 2 repositories: a valid one and an invalid one.
78    // The goal is to verify that the invalid one is ignored but a warning is reported in the logs.
79  1 this.source.setProperty("extension.repositories", Arrays.asList("id:type:http://url", "invalid"));
80   
81  1 Assert.assertEquals(
82    Arrays.asList(new DefaultExtensionRepositoryDescriptor("id", "type", new URI("http://url"))),
83    new ArrayList<ExtensionRepositoryDescriptor>(this.configuration.getExtensionRepositoryDescriptors()));
84  1 Assert.assertEquals(1, this.log.size());
85  1 Assert.assertEquals("Ignoring invalid repository configuration [invalid]. Root cause "
86    + "[ExtensionManagerConfigurationException: Invalid repository configuration format for [invalid]. Should "
87    + "have been matching [([^:]+):([^:]+):(.+)].]", this.log.getMessage(0));
88    }
89   
 
90  1 toggle @Test
91    public void testGetExtensionRepositoryDescriptorsEmpty()
92    {
93  1 Assert.assertNull(this.configuration.getExtensionRepositoryDescriptors());
94  1 Assert.assertEquals(0, this.log.size());
95    }
96   
 
97  1 toggle @Test
98    public void testGetExtensionRepositoryDescriptorsWithProperties() throws URISyntaxException
99    {
100  1 this.source.setProperty("extension.repositories", Arrays.asList("id:type:http://url"));
101  1 this.source.setProperty("extension.repositories.id.property", "value");
102  1 this.source.setProperty("extension.repositories.id.property.with.dots", "other value");
103   
104  1 Collection<ExtensionRepositoryDescriptor> descriptors = this.configuration.getExtensionRepositoryDescriptors();
105   
106  1 Assert.assertFalse(descriptors.isEmpty());
107   
108  1 ExtensionRepositoryDescriptor descriptor = descriptors.iterator().next();
109   
110  1 Assert.assertEquals("id", descriptor.getId());
111  1 Assert.assertEquals("type", descriptor.getType());
112  1 Assert.assertEquals(new URI("http://url"), descriptor.getURI());
113  1 Assert.assertEquals("value", descriptor.getProperty("property"));
114  1 Assert.assertEquals("other value", descriptor.getProperty("property.with.dots"));
115  1 Assert.assertEquals(0, this.log.size());
116    }
117    }