1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.url.internal.standard; |
21 |
|
|
22 |
|
import java.net.URL; |
23 |
|
import java.util.Arrays; |
24 |
|
import java.util.Collections; |
25 |
|
|
26 |
|
import org.junit.Before; |
27 |
|
import org.junit.Rule; |
28 |
|
import org.junit.Test; |
29 |
|
import org.xwiki.component.manager.ComponentManager; |
30 |
|
import org.xwiki.component.util.DefaultParameterizedType; |
31 |
|
import org.xwiki.context.Execution; |
32 |
|
import org.xwiki.context.ExecutionContext; |
33 |
|
import org.xwiki.model.EntityType; |
34 |
|
import org.xwiki.model.ModelConfiguration; |
35 |
|
import org.xwiki.model.internal.reference.DefaultEntityReferenceProvider; |
36 |
|
import org.xwiki.model.internal.reference.DefaultReferenceEntityReferenceResolver; |
37 |
|
import org.xwiki.model.reference.DocumentReference; |
38 |
|
import org.xwiki.resource.ResourceReference; |
39 |
|
import org.xwiki.resource.ResourceReferenceResolver; |
40 |
|
import org.xwiki.resource.ResourceType; |
41 |
|
import org.xwiki.resource.ResourceTypeResolver; |
42 |
|
import org.xwiki.resource.entity.EntityResourceAction; |
43 |
|
import org.xwiki.resource.entity.EntityResourceReference; |
44 |
|
import org.xwiki.resource.internal.entity.EntityResourceActionLister; |
45 |
|
import org.xwiki.resource.resources.ResourcesResourceReference; |
46 |
|
import org.xwiki.resource.skins.SkinsResourceReference; |
47 |
|
import org.xwiki.test.annotation.BeforeComponent; |
48 |
|
import org.xwiki.test.annotation.ComponentList; |
49 |
|
import org.xwiki.test.mockito.MockitoComponentManagerRule; |
50 |
|
import org.xwiki.url.ExtendedURL; |
51 |
|
import org.xwiki.url.URLConfiguration; |
52 |
|
import org.xwiki.url.internal.DefaultResourceReferenceResolver; |
53 |
|
import org.xwiki.url.internal.DefaultResourceTypeResolver; |
54 |
|
import org.xwiki.url.internal.DefaultStringResourceTypeResolver; |
55 |
|
import org.xwiki.url.internal.GenericResourceReferenceResolver; |
56 |
|
import org.xwiki.url.internal.GenericStringResourceTypeResolver; |
57 |
|
import org.xwiki.url.internal.standard.resources.ResourcesResourceReferenceResolver; |
58 |
|
import org.xwiki.url.internal.standard.skins.SkinsResourceReferenceResolver; |
59 |
|
import org.xwiki.wiki.descriptor.WikiDescriptorManager; |
60 |
|
|
61 |
|
import static org.junit.Assert.assertEquals; |
62 |
|
import static org.mockito.Mockito.when; |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
@version |
68 |
|
@since |
69 |
|
|
70 |
|
@ComponentList({ |
71 |
|
DefaultResourceTypeResolver.class, |
72 |
|
DefaultResourceReferenceResolver.class, |
73 |
|
GenericResourceReferenceResolver.class, |
74 |
|
StandardExtendedURLResourceTypeResolver.class, |
75 |
|
StandardExtendedURLResourceReferenceResolver.class, |
76 |
|
DefaultStringResourceTypeResolver.class, |
77 |
|
GenericStringResourceTypeResolver.class, |
78 |
|
DomainWikiReferenceExtractor.class, |
79 |
|
PathWikiReferenceExtractor.class, |
80 |
|
DefaultEntityReferenceProvider.class, |
81 |
|
DefaultReferenceEntityReferenceResolver.class, |
82 |
|
StandardStringResourceTypeResolver.class, |
83 |
|
ResourcesResourceReferenceResolver.class, |
84 |
|
SkinsResourceReferenceResolver.class |
85 |
|
}) |
|
|
| 100% |
Uncovered Elements: 0 (31) |
Complexity: 4 |
Complexity Density: 0.15 |
|
86 |
|
public class IntegrationTest |
87 |
|
{ |
88 |
|
@Rule |
89 |
|
public MockitoComponentManagerRule componentManager = new MockitoComponentManagerRule(); |
90 |
|
|
91 |
|
private ResourceTypeResolver<ExtendedURL> resourceTypeResolver; |
92 |
|
|
93 |
|
private ResourceReferenceResolver<ExtendedURL> resourceReferenceResolver; |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
|
95 |
1 |
@BeforeComponent... |
96 |
|
public void setUpComponents() throws Exception |
97 |
|
{ |
98 |
|
|
99 |
1 |
URLConfiguration urlConfiguration = this.componentManager.registerMockComponent(URLConfiguration.class); |
100 |
1 |
when(urlConfiguration.getURLFormatId()).thenReturn("standard"); |
101 |
|
|
102 |
|
|
103 |
1 |
StandardURLConfiguration standardURLConfiguration = this.componentManager.registerMockComponent( |
104 |
|
StandardURLConfiguration.class); |
105 |
1 |
when(standardURLConfiguration.getEntityPathPrefix()).thenReturn("bin"); |
106 |
1 |
when(standardURLConfiguration.getWikiPathPrefix()).thenReturn("wiki"); |
107 |
1 |
when(standardURLConfiguration.isViewActionHidden()).thenReturn(false); |
108 |
|
|
109 |
|
|
110 |
1 |
ModelConfiguration modelConfiguration = this.componentManager.registerMockComponent(ModelConfiguration.class); |
111 |
1 |
when(modelConfiguration.getDefaultReferenceValue(EntityType.WIKI)).thenReturn("xwiki"); |
112 |
|
|
113 |
|
|
114 |
1 |
WikiDescriptorManager wikiDescriptorManager = |
115 |
|
this.componentManager.registerMockComponent(WikiDescriptorManager.class); |
116 |
1 |
when(wikiDescriptorManager.getMainWikiId()).thenReturn("xwiki"); |
117 |
|
|
118 |
|
|
119 |
1 |
EntityResourceActionLister actionLister = |
120 |
|
this.componentManager.registerMockComponent(EntityResourceActionLister.class); |
121 |
1 |
when(actionLister.listActions()).thenReturn(Arrays.asList("view")); |
122 |
|
|
123 |
|
|
124 |
1 |
Execution execution = this.componentManager.registerMockComponent(Execution.class); |
125 |
1 |
when(execution.getContext()).thenReturn(new ExecutionContext()); |
126 |
|
|
127 |
|
|
128 |
1 |
this.componentManager.registerComponent(ComponentManager.class, "context", this.componentManager); |
129 |
|
} |
130 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
131 |
1 |
@Before... |
132 |
|
public void setUp() throws Exception |
133 |
|
{ |
134 |
1 |
this.resourceTypeResolver = this.componentManager.getInstance( |
135 |
|
new DefaultParameterizedType(null, ResourceTypeResolver.class, ExtendedURL.class)); |
136 |
1 |
this.resourceReferenceResolver = this.componentManager.getInstance( |
137 |
|
new DefaultParameterizedType(null, ResourceReferenceResolver.class, ExtendedURL.class)); |
138 |
|
} |
139 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
140 |
1 |
@Test... |
141 |
|
public void extractResourceReference() throws Exception |
142 |
|
{ |
143 |
|
|
144 |
1 |
assertURL("http://localhost:8080/xwiki/bin/view/space/page", EntityResourceReference.TYPE, |
145 |
|
new EntityResourceReference(new DocumentReference("xwiki", "space", "page"), EntityResourceAction.VIEW)); |
146 |
1 |
assertURL("http://localhost:8080/xwiki/wiki/mywiki/view/space/page", new ResourceType("wiki"), |
147 |
|
new EntityResourceReference(new DocumentReference("mywiki", "space", "page"), EntityResourceAction.VIEW)); |
148 |
|
|
149 |
|
|
150 |
1 |
assertURL("http://localhost:8080/xwiki/resources/js/prototype/prototype.js", ResourcesResourceReference.TYPE, |
151 |
|
new ResourcesResourceReference()); |
152 |
|
|
153 |
|
|
154 |
1 |
assertURL("http://localhost:8080/xwiki/resources/js/xwiki/wysiwyg/xwe/MacroService.gwtrpc", |
155 |
|
EntityResourceReference.TYPE, new EntityResourceReference(new DocumentReference("xwiki", |
156 |
|
Arrays.asList("js", "xwiki", "wysiwyg", "xwe"), "MacroService.gwtrpc"), |
157 |
|
new EntityResourceAction("resources"))); |
158 |
|
|
159 |
|
|
160 |
1 |
assertURL("http://localhost:8080/xwiki/skins/flamingo/logo.png", SkinsResourceReference.TYPE, |
161 |
|
new SkinsResourceReference()); |
162 |
|
|
163 |
|
} |
164 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
165 |
5 |
private void assertURL(String url, ResourceType expectedType, ResourceReference expectedReference) throws Exception... |
166 |
|
{ |
167 |
5 |
ExtendedURL extendedURL = new ExtendedURL(new URL(url), "xwiki"); |
168 |
5 |
ResourceType resourceType = |
169 |
|
this.resourceTypeResolver.resolve(extendedURL, Collections.<String, Object>emptyMap()); |
170 |
5 |
assertEquals(expectedType.getId(), resourceType.getId()); |
171 |
|
|
172 |
5 |
ResourceReference reference = this.resourceReferenceResolver.resolve( |
173 |
|
extendedURL, resourceType, Collections.<String, Object>emptyMap()); |
174 |
5 |
assertEquals(expectedReference, reference); |
175 |
|
} |
176 |
|
} |