| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 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 |
|
@link |
| 44 |
|
|
| 45 |
|
@version |
| 46 |
|
|
| 47 |
|
@AllComponents |
| |
|
| 100% |
Uncovered Elements: 0 (27) |
Complexity: 2 |
Complexity Density: 0.08 |
|
| 48 |
|
public class ExtensionConverterTest |
| 49 |
|
{ |
| 50 |
|
@Rule |
| 51 |
|
public MockitoComponentMockingRule<ConverterManager> mocker = |
| 52 |
|
new MockitoComponentMockingRule<ConverterManager>(DefaultConverterManager.class); |
| 53 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
| 54 |
1 |
@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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
| 84 |
1 |
@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 |
|
} |