use of org.xwiki.url.ExtendedURL in project xwiki-platform by xwiki.
the class WebJarsScriptServiceTest method computeURLWithParameters.
@Test
public void computeURLWithParameters() throws Exception {
WebJarsResourceReference resourceReference = new WebJarsResourceReference("wiki:wiki", Arrays.asList("angular", "2.1.11", "angular.js"));
resourceReference.addParameter("evaluate", "true");
resourceReference.addParameter("list", Arrays.asList("one", "two"));
ExtendedURL extendedURL = new ExtendedURL(Arrays.asList("xwiki", "angular", "2.1.11", "angular.js"), resourceReference.getParameters());
when(this.serializer.serialize(resourceReference)).thenReturn(extendedURL);
Map<String, Object> params = new LinkedHashMap<>();
params.put("version", "2.1.11");
params.put("evaluate", true);
params.put("list", new String[] { "one", "two" });
assertEquals("/xwiki/angular/2.1.11/angular.js?evaluate=true&list=one&list=two", this.mocker.getComponentUnderTest().url("angular", "wiki:wiki", "angular.js", params));
}
use of org.xwiki.url.ExtendedURL in project xwiki-platform by xwiki.
the class WebJarsResourceReferenceResolverTest method resolve.
@Test
public void resolve() throws Exception {
Map<String, List<String>> parameters = new HashMap<>();
parameters.put("key1", Arrays.asList("value1"));
parameters.put("key2", Arrays.asList("value2", "value3"));
ExtendedURL extendedURL = new ExtendedURL(Arrays.asList("namespace", "one", "two"), parameters);
WebJarsResourceReference reference = this.mocker.getComponentUnderTest().resolve(extendedURL, WebJarsResourceReference.TYPE, Collections.<String, Object>emptyMap());
assertEquals("namespace", reference.getNamespace());
assertEquals("one/two", reference.getResourceName());
assertEquals("value1", reference.getParameterValue("key1"));
assertEquals(Arrays.asList("value2", "value3"), reference.getParameterValues("key2"));
}
use of org.xwiki.url.ExtendedURL in project xwiki-platform by xwiki.
the class WebJarsResourceReferenceSerializerTest method serialize.
@Test
public void serialize() throws Exception {
URLNormalizer<ExtendedURL> normalizer = this.mocker.getInstance(new DefaultParameterizedType(null, URLNormalizer.class, ExtendedURL.class), "contextpath");
Map<String, List<String>> parameters = new HashMap<>();
parameters.put("key1", Arrays.asList("value1"));
parameters.put("key2", Arrays.asList("value2", "value3"));
ExtendedURL partialURL = new ExtendedURL(Arrays.asList("webjars", "namespace", "one", "two"), parameters);
ExtendedURL expectedURL = new ExtendedURL(Arrays.asList("xwiki", "webjars", "namespace", "one", "two"), parameters);
when(normalizer.normalize(partialURL)).thenReturn(expectedURL);
WebJarsResourceReference reference = new WebJarsResourceReference("namespace", Arrays.asList("one", "two"));
reference.addParameter("key1", "value1");
reference.addParameter("key2", new String[] { "value2", "value3" });
assertEquals(expectedURL, this.mocker.getComponentUnderTest().serialize(reference));
}
use of org.xwiki.url.ExtendedURL in project xwiki-platform by xwiki.
the class WebjarsResourceReferenceSerializer method serialize.
@Override
public ExtendedURL serialize(WebJarsResourceReference resourceReference) throws SerializeResourceReferenceException, UnsupportedResourceReferenceException {
List<String> segments = new ArrayList<>();
// Add the resource type segment.
segments.add("webjars");
// Add the namespace
segments.add(resourceReference.getNamespace());
// Add the resource path segments
segments.addAll(resourceReference.getResourceSegments());
// Add all optional parameters
ExtendedURL extendedURL = new ExtendedURL(segments, resourceReference.getParameters());
// Normalize the URL to add the Context Path since we want a full relative URL to be returned.
return this.extendedURLNormalizer.normalize(extendedURL);
}
use of org.xwiki.url.ExtendedURL in project xwiki-platform by xwiki.
the class ContextAndActionURLNormalizerTest method normalizePreservesParameters.
@Test
public void normalizePreservesParameters() throws Exception {
when(this.xwikiCfg.getProperty("xwiki.webapppath")).thenReturn("xwiki");
Map<String, List<String>> params = new HashMap<>();
params.put("age", Arrays.asList("32"));
params.put("colors", Arrays.asList("red", "blue"));
ExtendedURL extendedURL = new ExtendedURL(Arrays.asList("one", "two"), params);
assertSame(params, this.mocker.getComponentUnderTest().normalize(extendedURL).getParameters());
}
Aggregations