use of org.xwiki.webjars.internal.WebJarsResourceReference in project xwiki-platform by xwiki.
the class WebJarsResourceReferenceHandlerTest method failingResourceEvaluation.
@Test
public void failingResourceEvaluation() throws Exception {
WebJarsResourceReference reference = new WebJarsResourceReference("wiki:wiki", Arrays.asList("angular", "2.1.11", "angular.js"));
reference.addParameter("evaluate", "true");
ByteArrayInputStream resourceStream = new ByteArrayInputStream("content".getBytes());
when(this.classLoader.getResourceAsStream("META-INF/resources/webjars/angular/2.1.11/angular.js")).thenReturn(resourceStream);
VelocityManager velocityManager = this.componentManager.getInstance(VelocityManager.class);
VelocityEngine velocityEngine = mock(VelocityEngine.class);
when(velocityManager.getVelocityEngine()).thenReturn(velocityEngine);
when(velocityEngine.evaluate(any(), any(), eq("angular/2.1.11/angular.js"), any(Reader.class))).thenThrow(new VelocityException("Bad code!"));
this.handler.handle(reference, this.chain);
// Verify the exception is logged.
verify(this.componentManager.getMockedLogger()).error(eq("Failed to evaluate the Velocity code from WebJar resource [angular/2.1.11/angular.js]"), any(ResourceReferenceHandlerException.class));
// Verify that the client is properly notified about the failure.
verify(this.response.getHttpServletResponse()).sendError(500, "Failed to evaluate the Velocity code from WebJar resource [angular/2.1.11/angular.js]");
// The next handlers are still called.
verify(this.chain).handleNext(reference);
}
use of org.xwiki.webjars.internal.WebJarsResourceReference in project xwiki-platform by xwiki.
the class WebJarsScriptServiceTest method computeURLWithoutVersion.
@Test
public void computeURLWithoutVersion() throws Exception {
WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("math");
InstalledExtensionRepository installedExtensionRepository = this.mocker.getInstance(InstalledExtensionRepository.class);
InstalledExtension extension = mock(InstalledExtension.class);
when(installedExtensionRepository.getInstalledExtension("org.webjars:angular", "wiki:math")).thenReturn(extension);
when(extension.getId()).thenReturn(new ExtensionId("bar", "2.1.11"));
WebJarsResourceReference resourceReference = new WebJarsResourceReference("wiki:math", Arrays.asList("angular", "2.1.11", "angular.css"));
when(this.serializer.serialize(resourceReference)).thenReturn(new ExtendedURL(Arrays.asList("xwiki", "angular", "2.1.11", "angular.css")));
assertEquals("/xwiki/angular/2.1.11/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 computeURLWithParametersAndWikiIsNotSpecifiedInParameter.
@Test
public void computeURLWithParametersAndWikiIsNotSpecifiedInParameter() throws Exception {
WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("math");
InstalledExtensionRepository installedExtensionRepository = this.mocker.getInstance(InstalledExtensionRepository.class);
InstalledExtension extension = mock(InstalledExtension.class);
when(installedExtensionRepository.getInstalledExtension("org.webjars:angular", "wiki:math")).thenReturn(extension);
when(extension.getId()).thenReturn(new ExtensionId("bar", "2.1.11"));
WebJarsResourceReference resourceReference = new WebJarsResourceReference("wiki:math", Arrays.asList("angular", "2.1.11", "angular.css"));
when(this.serializer.serialize(resourceReference)).thenReturn(new ExtendedURL(Arrays.asList("xwiki", "angular", "2.1.11", "angular.css")));
assertEquals("/xwiki/angular/2.1.11/angular.css", this.mocker.getComponentUnderTest().url("angular", "angular.css", Collections.<String, Object>emptyMap()));
}
use of org.xwiki.webjars.internal.WebJarsResourceReference in project xwiki-platform by xwiki.
the class WebJarsScriptServiceTest method computeURLForBackwardCompatibilityWhenWikiIsSpecifiedAsParameter.
@Test
public void computeURLForBackwardCompatibilityWhenWikiIsSpecifiedAsParameter() throws Exception {
InstalledExtensionRepository installedExtensionRepository = this.mocker.getInstance(InstalledExtensionRepository.class);
InstalledExtension extension = mock(InstalledExtension.class);
when(installedExtensionRepository.getInstalledExtension("org.webjars:angular", "wiki:math")).thenReturn(extension);
when(extension.getId()).thenReturn(new ExtensionId("bar", "2.1.11"));
WebJarsResourceReference resourceReference = new WebJarsResourceReference("wiki:math", Arrays.asList("angular", "2.1.11", "angular.css"));
when(this.serializer.serialize(resourceReference)).thenReturn(new ExtendedURL(Arrays.asList("xwiki", "angular", "2.1.11", "angular.css")));
assertEquals("/xwiki/angular/2.1.11/angular.css", this.mocker.getComponentUnderTest().url("angular", "angular.css", Collections.singletonMap("wiki", "math")));
}
use of org.xwiki.webjars.internal.WebJarsResourceReference in project xwiki-platform by xwiki.
the class WebJarsScriptServiceTest method computeJavaScriptURLWithSuffixAndNoParameters.
@Test
public void computeJavaScriptURLWithSuffixAndNoParameters() throws Exception {
WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("math");
WebJarsResourceReference resourceReference = new WebJarsResourceReference("wiki:math", Arrays.asList("angular", "angular.js"));
resourceReference.addParameter("r", "1");
when(this.serializer.serialize(resourceReference)).thenReturn(new ExtendedURL(Arrays.asList("xwiki", "angular", "angular.js"), resourceReference.getParameters()));
assertEquals("/xwiki/angular/angular.js?r=1", this.mocker.getComponentUnderTest().url("angular", "angular.js"));
}
Aggregations