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

File DefaultExtensionManagerConfigurationTest.java

 

Code metrics

0
23
6
1
125
80
6
0.26
3.83
6
1

Classes

Class Line # Actions
DefaultExtensionManagerConfigurationTest 48 23 0% 6 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.xwiki.configuration.internal.MemoryConfigurationSource;
33    import org.xwiki.environment.Environment;
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.LogRule;
38    import org.xwiki.test.annotation.BeforeComponent;
39    import org.xwiki.test.annotation.ComponentList;
40    import org.xwiki.test.mockito.MockitoComponentManagerRule;
41   
42    /**
43    * Unit test for {@link DefaultExtensionManagerConfiguration}.
44    *
45    * @version $Id: d4f308ee00474989b4c1482e0d91c00244b7f32e $
46    */
47    @ComponentList({ DefaultExtensionManagerConfiguration.class, ExtensionFactory.class })
 
48    public class DefaultExtensionManagerConfigurationTest
49    {
50    @Rule
51    public final MockitoComponentManagerRule componentManager = new MockitoComponentManagerRule();
52   
53    @Rule
54    public final LogRule logCapture = new LogRule()
55    {
 
56  3 toggle {
57  3 record(LogLevel.WARN);
58  3 recordLoggingForType(DefaultExtensionManagerConfiguration.class);
59    }
60    };
61   
62    private ExtensionManagerConfiguration configuration;
63   
64    private MemoryConfigurationSource source;
65   
 
66  3 toggle @BeforeComponent
67    public void registerComponents() throws Exception
68    {
69    // Register a Mocked Environment since we need to provide one.
70  3 this.componentManager.registerMockComponent(Environment.class);
71   
72    // Register some in-memory Configuration Source for the test
73  3 this.source = this.componentManager.registerMemoryConfigurationSource();
74    }
75   
 
76  3 toggle @Before
77    public void setUp() throws Exception
78    {
79  3 this.configuration = this.componentManager.getInstance(ExtensionManagerConfiguration.class);
80    }
81   
 
82  1 toggle @Test
83    public void testGetRepositoriesWithInvalid() throws Exception
84    {
85    // We define 2 repositories: a valid one and an invalid one.
86    // The goal is to verify that the invalid one is ignored but a warning is reported in the logs.
87  1 this.source.setProperty("extension.repositories", Arrays.asList("id:type:http://url", "invalid"));
88   
89  1 Assert.assertEquals(
90    Arrays.asList(new DefaultExtensionRepositoryDescriptor("id", "type", new URI("http://url"))),
91    new ArrayList<ExtensionRepositoryDescriptor>(this.configuration.getExtensionRepositoryDescriptors()));
92  1 Assert.assertEquals(1, this.logCapture.size());
93  1 Assert.assertEquals("Ignoring invalid repository configuration [invalid]. Root cause "
94    + "[ExtensionManagerConfigurationException: Invalid repository configuration format for [invalid]. Should "
95    + "have been matching [([^:]+):([^:]+):(.+)].]", this.logCapture.getMessage(0));
96    }
97   
 
98  1 toggle @Test
99    public void testGetExtensionRepositoryDescriptorsEmpty()
100    {
101  1 Assert.assertEquals(null, this.configuration.getExtensionRepositoryDescriptors());
102  1 Assert.assertEquals(0, this.logCapture.size());
103    }
104   
 
105  1 toggle @Test
106    public void testGetExtensionRepositoryDescriptorsWithProperties() throws URISyntaxException
107    {
108  1 this.source.setProperty("extension.repositories", Arrays.asList("id:type:http://url"));
109  1 this.source.setProperty("extension.repositories.id.property", "value");
110  1 this.source.setProperty("extension.repositories.id.property.with.dots", "other value");
111   
112  1 Collection<ExtensionRepositoryDescriptor> descriptors = this.configuration.getExtensionRepositoryDescriptors();
113   
114  1 Assert.assertFalse(descriptors.isEmpty());
115   
116  1 ExtensionRepositoryDescriptor descriptor = descriptors.iterator().next();
117   
118  1 Assert.assertEquals("id", descriptor.getId());
119  1 Assert.assertEquals("type", descriptor.getType());
120  1 Assert.assertEquals(new URI("http://url"), descriptor.getURI());
121  1 Assert.assertEquals("value", descriptor.getProperty("property"));
122  1 Assert.assertEquals("other value", descriptor.getProperty("property.with.dots"));
123  1 Assert.assertEquals(0, this.logCapture.size());
124    }
125    }