use of org.xwiki.lesscss.resources.LESSResourceReference in project xwiki-platform by xwiki.
the class DefaultLESSCompilerTest method compileWhenError.
@Test
public void compileWhenError() throws Exception {
// Mocks
LESSCompilerException expectedException = new LESSCompilerException("an exception");
when(cachedLESSCompiler.compute(any(LESSResourceReference.class), anyBoolean(), anyBoolean(), anyBoolean(), any())).thenThrow(expectedException);
// Test
String result = mocker.getComponentUnderTest().compile(lessResourceReference, false, false, false);
// Asserts
assertTrue(StringUtils.startsWith(result, "/* org.xwiki.lesscss.compiler.LESSCompilerException: an exception"));
assertTrue(StringUtils.endsWith(result, "*/"));
verify(cache).set(eq(lessResourceReference), eq(skinReference), eq(colorThemeReference), eq(result));
verify(mocker.getMockedLogger()).error(eq("Error during the compilation of the resource [{}]."), eq(lessResourceReference), eq(expectedException));
}
use of org.xwiki.lesscss.resources.LESSResourceReference in project xwiki-platform by xwiki.
the class LessCompilerScriptServiceTest method compileSkinFileWithOtherSkin.
@Test
public void compileSkinFileWithOtherSkin() throws Exception {
// Mock
LESSResourceReference style = mock(LESSResourceReference.class);
when(lessResourceReferenceFactory.createReferenceForSkinFile("style.less")).thenReturn(style);
// Test
mocker.getComponentUnderTest().compileSkinFile("style.less", "skin1");
// Verify
verify(lessCompiler).compile(style, false, true, "skin1", false);
// Test
mocker.getComponentUnderTest().compileSkinFile("style.less", "skin2");
// Verify
verify(lessCompiler).compile(style, false, true, "skin2", false);
// Test
mocker.getComponentUnderTest().compileSkinFile("style.less", "skin3", false);
// Verify
verify(lessCompiler).compile(style, false, true, "skin3", false);
// Test
mocker.getComponentUnderTest().compileSkinFile("style.less", "skin4", true);
// Verify
verify(lessCompiler).compile(style, false, true, "skin4", true);
}
use of org.xwiki.lesscss.resources.LESSResourceReference in project xwiki-platform by xwiki.
the class CachedLESSCompilerTest method computeSkinFileWithMainStyleIncluded.
@Test
public void computeSkinFileWithMainStyleIncluded() throws Exception {
// Mocks
LESSResourceReference resource = mock(LESSSkinFileResourceReference.class);
when(resource.getContent(eq("skin"))).thenReturn("Some LESS content");
when(xwiki.evaluateVelocity(eq("@import (reference) \"style.less.vm\";\n" + "Some LESS content"), eq("SomeContextDocument"))).thenReturn("@import (reference) \"style.less.vm\";\n" + "Some Velocity-rendered LESS content");
when(less4jCompiler.compile(eq("@import (reference) \"style.less.vm\";\n" + "Some Velocity-rendered LESS content"), eq("skin"), eq(false))).thenReturn("output");
// Tests
assertEquals("output", mocker.getComponentUnderTest().compute(resource, true, true, true, "skin"));
}
use of org.xwiki.lesscss.resources.LESSResourceReference in project xwiki-platform by xwiki.
the class CachedLESSCompilerTest method computeSkinFileWithoutVelocity.
@Test
public void computeSkinFileWithoutVelocity() throws Exception {
// Mocks
LESSResourceReference resource = mock(LESSSkinFileResourceReference.class);
when(resource.getContent(eq("skin2"))).thenReturn("Some LESS content");
when(less4jCompiler.compile(eq("Some LESS content"), eq("skin2"), eq(false))).thenReturn("output");
// Tests
assertEquals("output", mocker.getComponentUnderTest().compute(resource, false, false, true, "skin2"));
// Verify
verify(xcontext, never()).put(eq("skin"), any());
}
use of org.xwiki.lesscss.resources.LESSResourceReference in project xwiki-platform by xwiki.
the class LessCompilerScriptServiceTest method compileSkinFileWithOtherSkinWhenException.
@Test
public void compileSkinFileWithOtherSkinWhenException() throws Exception {
// Mocks
LESSResourceReference style = mock(LESSResourceReference.class);
when(lessResourceReferenceFactory.createReferenceForSkinFile("style.less")).thenReturn(style);
Exception exception = new LESSCompilerException("Exception with LESS", null);
when(lessCompiler.compile(style, false, true, "flamingo", false)).thenThrow(exception);
// Test
String result = mocker.getComponentUnderTest().compileSkinFile("style.less", "flamingo", false);
// Verify
assertEquals("LESSCompilerException: Exception with LESS", result);
}
Aggregations