use of org.xwiki.webjars.internal.WebJarsResourceReference in project xwiki-platform by xwiki.
the class WebJarsScriptServiceTest method computeURLWithVersion.
@Test
public void computeURLWithVersion() throws Exception {
WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("math");
WebJarsResourceReference resourceReference = new WebJarsResourceReference("wiki:math", Arrays.asList("ang:ular", "2.1.11", "angular.css"));
// Test that colon is not interpreted as groupId/artifactId separator (for backwards compatibility).
when(this.serializer.serialize(resourceReference)).thenReturn(new ExtendedURL(Arrays.asList("xwiki", "ang:ular", "2.1.11", "angular.css")));
assertEquals("/xwiki/ang%3Aular/2.1.11/angular.css", this.mocker.getComponentUnderTest().url("ang:ular/2.1.11/angular.css"));
}
use of org.xwiki.webjars.internal.WebJarsResourceReference in project xwiki-platform by xwiki.
the class WebJarsScriptServiceTest method computeURLWithoutVersionAndNoExtensionMatchingWebJarId.
@Test
public void computeURLWithoutVersionAndNoExtensionMatchingWebJarId() throws Exception {
WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("math");
WebJarsResourceReference resourceReference = new WebJarsResourceReference("wiki:math", Arrays.asList("angular", "angular.css"));
when(this.serializer.serialize(resourceReference)).thenReturn(new ExtendedURL(Arrays.asList("xwiki", "angular", "angular.css")));
assertEquals("/xwiki/angular/angular.css", this.mocker.getComponentUnderTest().url("angular", "angular.css"));
}
use of org.xwiki.webjars.internal.WebJarsResourceReference 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.webjars.internal.WebJarsResourceReference in project xwiki-platform by xwiki.
the class WebJarsScriptService method getResourceReference.
private WebJarsResourceReference getResourceReference(String artifactId, Object version, String namespace, String path, Map<String, Object> urlParams) {
List<String> segments = new ArrayList<>();
segments.add(artifactId);
// given WebJar id.
if (version != null) {
segments.add((String) version);
}
segments.addAll(Arrays.asList(path.split(RESOURCE_SEPARATOR)));
// suffix is specified and there is no query string (thus preventing RequireJS from requesting ".js.js").
if (path.endsWith(".js") && urlParams.isEmpty()) {
urlParams.put("r", "1");
}
WebJarsResourceReference resourceReference = new WebJarsResourceReference(resolveNamespace(namespace), segments);
for (Map.Entry<String, Object> parameterEntry : urlParams.entrySet()) {
resourceReference.addParameter(parameterEntry.getKey(), parameterEntry.getValue());
}
return resourceReference;
}
use of org.xwiki.webjars.internal.WebJarsResourceReference in project xwiki-platform by xwiki.
the class WebJarResourceReferenceTest method testEqualsAndHashCode.
@Test
public void testEqualsAndHashCode() {
WebJarsResourceReference reference1 = new WebJarsResourceReference("namespace", Arrays.asList("one", "two"));
reference1.addParameter("key1", "value1");
reference1.addParameter("key2", new String[] { "value2", "value3" });
WebJarsResourceReference reference2 = new WebJarsResourceReference("namespace", Arrays.asList("one", "two"));
reference2.addParameter("key1", "value1");
reference2.addParameter("key2", new String[] { "value2", "value3" });
WebJarsResourceReference reference3 = new WebJarsResourceReference("namespace", Arrays.asList("one", "two"));
WebJarsResourceReference reference4 = new WebJarsResourceReference("namespace2", Arrays.asList("one", "two"));
assertEquals(reference2, reference1);
assertEquals(reference2.hashCode(), reference1.hashCode());
assertFalse(reference3.equals(reference1));
assertFalse(reference3.hashCode() == reference1.hashCode());
assertFalse(reference4.equals(reference3));
assertFalse(reference4.hashCode() == reference3.hashCode());
}
Aggregations