1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.extension.repository.local; |
21 |
|
|
22 |
|
import java.io.ByteArrayInputStream; |
23 |
|
import java.io.ByteArrayOutputStream; |
24 |
|
import java.net.MalformedURLException; |
25 |
|
import java.net.URL; |
26 |
|
import java.util.ArrayList; |
27 |
|
import java.util.Arrays; |
28 |
|
import java.util.Collections; |
29 |
|
import java.util.HashSet; |
30 |
|
|
31 |
|
import javax.xml.parsers.ParserConfigurationException; |
32 |
|
import javax.xml.transform.TransformerException; |
33 |
|
|
34 |
|
import org.junit.Assert; |
35 |
|
import org.junit.Rule; |
36 |
|
import org.junit.Test; |
37 |
|
import org.xwiki.component.manager.ComponentLookupException; |
38 |
|
import org.xwiki.extension.DefaultExtensionAuthor; |
39 |
|
import org.xwiki.extension.DefaultExtensionDependency; |
40 |
|
import org.xwiki.extension.DefaultExtensionIssueManagement; |
41 |
|
import org.xwiki.extension.DefaultExtensionScm; |
42 |
|
import org.xwiki.extension.DefaultExtensionScmConnection; |
43 |
|
import org.xwiki.extension.ExtensionId; |
44 |
|
import org.xwiki.extension.ExtensionLicense; |
45 |
|
import org.xwiki.extension.InvalidExtensionException; |
46 |
|
import org.xwiki.extension.internal.ExtensionFactory; |
47 |
|
import org.xwiki.extension.repository.internal.DefaultExtensionSerializer; |
48 |
|
import org.xwiki.extension.repository.internal.ExtensionSerializer; |
49 |
|
import org.xwiki.extension.repository.internal.local.DefaultLocalExtension; |
50 |
|
import org.xwiki.extension.version.internal.DefaultVersionConstraint; |
51 |
|
import org.xwiki.test.annotation.ComponentList; |
52 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
53 |
|
|
54 |
|
@ComponentList(ExtensionFactory.class) |
|
|
| 94.5% |
Uncovered Elements: 3 (55) |
Complexity: 4 |
Complexity Density: 0.08 |
|
55 |
|
public class DefaultExtensionSerializerTest |
56 |
|
{ |
57 |
|
@Rule |
58 |
|
public final MockitoComponentMockingRule<ExtensionSerializer> componentManager = |
59 |
|
new MockitoComponentMockingRule<ExtensionSerializer>(DefaultExtensionSerializer.class); |
60 |
|
|
|
|
| 89.7% |
Uncovered Elements: 3 (29) |
Complexity: 3 |
Complexity Density: 0.12 |
|
61 |
1 |
private DefaultLocalExtension serializeAndUnserialize(DefaultLocalExtension extension)... |
62 |
|
throws ParserConfigurationException, TransformerException, InvalidExtensionException, ComponentLookupException |
63 |
|
{ |
64 |
1 |
ByteArrayOutputStream os = new ByteArrayOutputStream(); |
65 |
|
|
66 |
1 |
this.componentManager.getComponentUnderTest().saveExtensionDescriptor(extension, os); |
67 |
|
|
68 |
1 |
ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray()); |
69 |
|
|
70 |
1 |
DefaultLocalExtension unserializedExtension = |
71 |
|
this.componentManager.getComponentUnderTest().loadLocalExtensionDescriptor(null, is); |
72 |
|
|
73 |
1 |
Assert.assertEquals(extension, unserializedExtension); |
74 |
1 |
Assert.assertEquals(extension.getDescription(), unserializedExtension.getDescription()); |
75 |
1 |
Assert.assertEquals(extension.getName(), unserializedExtension.getName()); |
76 |
1 |
Assert.assertEquals(extension.getCategory(), unserializedExtension.getCategory()); |
77 |
1 |
Assert.assertEquals(extension.getSummary(), unserializedExtension.getSummary()); |
78 |
1 |
Assert.assertEquals(extension.getWebSite(), unserializedExtension.getWebSite()); |
79 |
1 |
Assert.assertEquals(extension.getAuthors(), unserializedExtension.getAuthors()); |
80 |
1 |
Assert.assertEquals(new ArrayList<ExtensionId>(extension.getExtensionFeatures()), |
81 |
|
new ArrayList<ExtensionId>(unserializedExtension.getExtensionFeatures())); |
82 |
1 |
Assert.assertEquals(new ArrayList<String>(extension.getFeatures()), |
83 |
|
new ArrayList<String>(unserializedExtension.getFeatures())); |
84 |
1 |
Assert.assertEquals(new ArrayList<String>(extension.getAllowedNamespaces()), |
85 |
|
new ArrayList<String>(unserializedExtension.getAllowedNamespaces())); |
86 |
1 |
Assert.assertEquals(new ArrayList<ExtensionLicense>(extension.getLicenses()), |
87 |
|
new ArrayList<ExtensionLicense>(unserializedExtension.getLicenses())); |
88 |
1 |
Assert.assertEquals(extension.getScm(), unserializedExtension.getScm()); |
89 |
1 |
Assert.assertEquals(extension.getIssueManagement(), unserializedExtension.getIssueManagement()); |
90 |
1 |
Assert.assertEquals(extension.getProperties(), unserializedExtension.getProperties()); |
91 |
|
|
92 |
2 |
for (int i = 0; i < extension.getDependencies().size(); ++i) { |
93 |
1 |
Assert.assertEquals(extension.getDependencies().get(i), unserializedExtension.getDependencies().get(i)); |
94 |
1 |
Assert.assertEquals(extension.getDependencies().get(i).getProperties(), |
95 |
|
unserializedExtension.getDependencies().get(i).getProperties()); |
96 |
|
} |
97 |
|
|
98 |
1 |
for (int i = 0; i < extension.getManagedDependencies().size(); ++i) { |
99 |
0 |
Assert.assertEquals(extension.getManagedDependencies().get(i), |
100 |
|
unserializedExtension.getManagedDependencies().get(i)); |
101 |
0 |
Assert.assertEquals(extension.getManagedDependencies().get(i).getProperties(), |
102 |
|
unserializedExtension.getManagedDependencies().get(i).getProperties()); |
103 |
|
} |
104 |
|
|
105 |
1 |
return unserializedExtension; |
106 |
|
} |
107 |
|
|
108 |
|
|
109 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
110 |
1 |
@Test... |
111 |
|
public void testSerialize() throws ParserConfigurationException, TransformerException, InvalidExtensionException, |
112 |
|
MalformedURLException, ComponentLookupException |
113 |
|
{ |
114 |
1 |
DefaultLocalExtension extension = |
115 |
|
new DefaultLocalExtension(null, new ExtensionId("extensionid", "extensionversion"), "type"); |
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
1 |
DefaultExtensionDependency dependency = |
121 |
|
new DefaultExtensionDependency("dependencyid", new DefaultVersionConstraint("dependencyversion")); |
122 |
1 |
extension.addDependency(dependency); |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
1 |
extension.setDescription("description"); |
128 |
1 |
extension.setSummary("summary"); |
129 |
1 |
extension.setWebsite("website"); |
130 |
1 |
extension.setName("name"); |
131 |
|
|
132 |
1 |
extension.setCategory("category"); |
133 |
|
|
134 |
1 |
extension.putProperty("key1", "value1"); |
135 |
1 |
extension.putProperty("key2", true); |
136 |
1 |
extension.putProperty("key3", 42); |
137 |
1 |
extension.putProperty("key4", Arrays.asList("list1", "list2")); |
138 |
1 |
extension.putProperty("key5", new HashSet<String>(Arrays.asList("list1", "list2"))); |
139 |
1 |
extension.putProperty("key6", Collections.<String, Object>singletonMap("key", "value")); |
140 |
1 |
extension.putProperty("key7", Collections.<String, Object>singletonMap("key", |
141 |
|
Collections.<String, Object>singletonMap("subkey", "subvalue"))); |
142 |
|
|
143 |
1 |
extension.addAuthor(new DefaultExtensionAuthor("authorname", new URL("http://authorurl"))); |
144 |
1 |
extension.addFeature("feature1"); |
145 |
1 |
extension.addExtensionFeature(new ExtensionId("feature2", "version")); |
146 |
1 |
extension.addAllowedNamespace("namespae1"); |
147 |
1 |
extension.addLicense(new ExtensionLicense("licensename", Arrays.asList("license content"))); |
148 |
1 |
dependency.setProperties(Collections.<String, Object>singletonMap("dependencykey", "dependencyvalue")); |
149 |
|
|
150 |
1 |
extension.setScm(new DefaultExtensionScm("url", new DefaultExtensionScmConnection("system", "path"), |
151 |
|
new DefaultExtensionScmConnection("system2", "path2"))); |
152 |
1 |
extension.setIssueManagement(new DefaultExtensionIssueManagement("system", "url")); |
153 |
|
|
154 |
|
|
155 |
1 |
serializeAndUnserialize(extension); |
156 |
|
} |
157 |
|
} |