Search in sources :

Example 1 with URLNormalizer

use of org.xwiki.url.URLNormalizer 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 2 with URLNormalizer

use of org.xwiki.url.URLNormalizer in project xwiki-platform by xwiki.

the class VfsResourceReferenceSerializerTest method serializeWhenNoSpecificSchemeSerializer.

@Test
public void serializeWhenNoSpecificSchemeSerializer() throws Exception {
    VfsResourceReference reference = new VfsResourceReference(URI.create("somescheme:wiki:space.page@attachment"), "path1/path2/test.txt");
    ExtendedURL extendedURL = new ExtendedURL(Arrays.asList("vfs", "somescheme:wiki:space.page@attachment", "path1", "path2", "test.txt"));
    URLNormalizer<ExtendedURL> normalizer = this.mocker.getInstance(new DefaultParameterizedType(null, URLNormalizer.class, ExtendedURL.class), "contextpath");
    when(normalizer.normalize(extendedURL)).thenReturn(extendedURL);
    assertEquals("/vfs/somescheme%3Awiki%3Aspace.page%40attachment/path1/path2/test.txt", this.mocker.getComponentUnderTest().serialize(reference).toString());
}
Also used : URLNormalizer(org.xwiki.url.URLNormalizer) VfsResourceReference(org.xwiki.vfs.VfsResourceReference) ExtendedURL(org.xwiki.url.ExtendedURL) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Test(org.junit.Test)

Example 3 with URLNormalizer

use of org.xwiki.url.URLNormalizer in project xwiki-platform by xwiki.

the class AttachVfsResourceReferenceSerializerTest method serialize.

@Test
public void serialize() throws Exception {
    VfsResourceReference reference = new VfsResourceReference(URI.create("attach:attachment"), "path1/path2/test.txt");
    ExtendedURL extendedURL = new ExtendedURL(Arrays.asList("vfs", "attach:wiki:space.page@attachment", "path1", "path2", "test.txt"));
    URLNormalizer<ExtendedURL> normalizer = this.mocker.getInstance(new DefaultParameterizedType(null, URLNormalizer.class, ExtendedURL.class), "contextpath");
    when(normalizer.normalize(extendedURL)).thenReturn(extendedURL);
    AttachmentReferenceResolver<String> attachmentResolver = this.mocker.getInstance(AttachmentReferenceResolver.TYPE_STRING, "current");
    AttachmentReference attachmentReference = new AttachmentReference("attachment", new DocumentReference("wiki", Arrays.asList("space"), "page"));
    when(attachmentResolver.resolve("attachment")).thenReturn(attachmentReference);
    EntityReferenceSerializer<String> entitySerializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING);
    when(entitySerializer.serialize(attachmentReference)).thenReturn("wiki:space.page@attachment");
    assertEquals("/vfs/attach%3Awiki%3Aspace.page%40attachment/path1/path2/test.txt", this.mocker.getComponentUnderTest().serialize(reference).toString());
}
Also used : AttachmentReference(org.xwiki.model.reference.AttachmentReference) URLNormalizer(org.xwiki.url.URLNormalizer) VfsResourceReference(org.xwiki.vfs.VfsResourceReference) ExtendedURL(org.xwiki.url.ExtendedURL) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)3 ExtendedURL (org.xwiki.url.ExtendedURL)3 URLNormalizer (org.xwiki.url.URLNormalizer)3 VfsResourceReference (org.xwiki.vfs.VfsResourceReference)2 HashMap (java.util.HashMap)1 List (java.util.List)1 AttachmentReference (org.xwiki.model.reference.AttachmentReference)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1