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

File ExtensionConverterTest.java

 

Code metrics

0
25
2
1
98
62
2
0.08
12.5
2
1

Classes

Class Line # Actions
ExtensionConverterTest 48 25 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.extension.internal.converter;
21   
22    import java.net.URI;
23    import java.net.URISyntaxException;
24    import java.util.ArrayList;
25    import java.util.Arrays;
26   
27    import org.apache.maven.model.Model;
28    import org.apache.maven.model.Repository;
29    import org.junit.Rule;
30    import org.junit.Test;
31    import org.xwiki.component.manager.ComponentLookupException;
32    import org.xwiki.extension.Extension;
33    import org.xwiki.extension.repository.DefaultExtensionRepositoryDescriptor;
34    import org.xwiki.properties.ConverterManager;
35    import org.xwiki.properties.internal.DefaultConverterManager;
36    import org.xwiki.test.annotation.AllComponents;
37    import org.xwiki.test.mockito.MockitoComponentMockingRule;
38   
39    import static org.junit.Assert.assertEquals;
40    import static org.junit.Assert.assertNull;
41   
42    /**
43    * Validate {@link ExtensionConverter} component.
44    *
45    * @version $Id: 1d6e49ac27e40e9498387a5cb8b7f0fd34912e19 $
46    */
47    @AllComponents
 
48    public class ExtensionConverterTest
49    {
50    @Rule
51    public MockitoComponentMockingRule<ConverterManager> mocker =
52    new MockitoComponentMockingRule<ConverterManager>(DefaultConverterManager.class);
53   
 
54  1 toggle @Test
55    public void testConvertFromExtension() throws SecurityException, ComponentLookupException, URISyntaxException
56    {
57  1 Model model = new Model();
58   
59  1 model.setGroupId("groupid");
60  1 model.setArtifactId("artifactid");
61  1 model.setVersion("version");
62  1 model.addProperty(Extension.IKEYPREFIX + Extension.FIELD_CATEGORY, "category");
63  1 model.addProperty(Extension.IKEYPREFIX + Extension.FIELD_NAMESPACES,
64    "namespace1, namespace2,\r\n\t {root}, \"namespace3\", 'namespace4'");
65  1 Repository repository = new Repository();
66  1 repository.setId("repository-id");
67  1 repository.setUrl("http://url");
68  1 model.addRepository(repository);
69   
70  1 Extension extension = this.mocker.getComponentUnderTest().convert(Extension.class, model);
71   
72  1 assertEquals(model.getGroupId() + ':' + model.getArtifactId(), extension.getId().getId());
73  1 assertEquals(model.getVersion(), extension.getId().getVersion().getValue());
74  1 assertEquals("category", extension.getCategory());
75  1 assertNull(extension.getProperty(Extension.IKEYPREFIX + Extension.FIELD_CATEGORY));
76  1 assertEquals(Arrays.asList("namespace1", "namespace2", "{root}", "namespace3", "namespace4"),
77    new ArrayList<>(extension.getAllowedNamespaces()));
78  1 assertNull(extension.getProperty(Extension.IKEYPREFIX + Extension.FIELD_NAMESPACES));
79  1 assertEquals(
80    Arrays.asList(new DefaultExtensionRepositoryDescriptor("repository-id", "maven", new URI("http://url"))),
81    extension.getRepositories());
82    }
83   
 
84  1 toggle @Test
85    public void testConvertFromExtensionAllowedOnRoot() throws SecurityException, ComponentLookupException
86    {
87  1 Model model = new Model();
88   
89  1 model.setGroupId("groupid");
90  1 model.setArtifactId("artifactid");
91  1 model.setVersion("version");
92  1 model.addProperty(Extension.IKEYPREFIX + Extension.FIELD_NAMESPACES, "{root}");
93   
94  1 Extension extension = this.mocker.getComponentUnderTest().convert(Extension.class, model);
95   
96  1 assertEquals(Arrays.asList("{root}"), new ArrayList<>(extension.getAllowedNamespaces()));
97    }
98    }