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));
}
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());
}
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());
}
Aggregations