Search in sources :

Example 16 with ExtendedURL

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));
}
Also used : WebJarsResourceReference(org.xwiki.webjars.internal.WebJarsResourceReference) ExtendedURL(org.xwiki.url.ExtendedURL) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 17 with ExtendedURL

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"));
}
Also used : HashMap(java.util.HashMap) List(java.util.List) ExtendedURL(org.xwiki.url.ExtendedURL) Test(org.junit.Test)

Example 18 with ExtendedURL

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));
}
Also used : URLNormalizer(org.xwiki.url.URLNormalizer) HashMap(java.util.HashMap) List(java.util.List) ExtendedURL(org.xwiki.url.ExtendedURL) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Test(org.junit.Test)

Example 19 with ExtendedURL

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);
}
Also used : ArrayList(java.util.ArrayList) ExtendedURL(org.xwiki.url.ExtendedURL)

Example 20 with 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());
}
Also used : HashMap(java.util.HashMap) List(java.util.List) ExtendedURL(org.xwiki.url.ExtendedURL) Test(org.junit.Test)

Aggregations

ExtendedURL (org.xwiki.url.ExtendedURL)46 Test (org.junit.Test)26 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)13 ResourceType (org.xwiki.resource.ResourceType)10 URL (java.net.URL)9 WebJarsResourceReference (org.xwiki.webjars.internal.WebJarsResourceReference)8 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)7 VfsResourceReference (org.xwiki.vfs.VfsResourceReference)7 HashMap (java.util.HashMap)6 List (java.util.List)6 EntityResourceReference (org.xwiki.resource.entity.EntityResourceReference)6 ServletException (javax.servlet.ServletException)5 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)5 IOException (java.io.IOException)4 Type (java.lang.reflect.Type)3 ExtensionId (org.xwiki.extension.ExtensionId)3 InstalledExtension (org.xwiki.extension.InstalledExtension)3 InstalledExtensionRepository (org.xwiki.extension.repository.InstalledExtensionRepository)3 DocumentReference (org.xwiki.model.reference.DocumentReference)3 ResourceReference (org.xwiki.resource.ResourceReference)3