Search in sources :

Example 6 with LESSResourceReference

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));
}
Also used : LESSResourceReference(org.xwiki.lesscss.resources.LESSResourceReference) LESSCompilerException(org.xwiki.lesscss.compiler.LESSCompilerException) Test(org.junit.Test)

Example 7 with LESSResourceReference

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);
}
Also used : LESSResourceReference(org.xwiki.lesscss.resources.LESSResourceReference) Test(org.junit.Test)

Example 8 with LESSResourceReference

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"));
}
Also used : LESSResourceReference(org.xwiki.lesscss.resources.LESSResourceReference) Test(org.junit.Test)

Example 9 with LESSResourceReference

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());
}
Also used : LESSResourceReference(org.xwiki.lesscss.resources.LESSResourceReference) Test(org.junit.Test)

Example 10 with LESSResourceReference

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);
}
Also used : LESSResourceReference(org.xwiki.lesscss.resources.LESSResourceReference) LESSCompilerException(org.xwiki.lesscss.compiler.LESSCompilerException) LESSCompilerException(org.xwiki.lesscss.compiler.LESSCompilerException) Test(org.junit.Test)

Aggregations

LESSResourceReference (org.xwiki.lesscss.resources.LESSResourceReference)14 Test (org.junit.Test)12 LESSCompilerException (org.xwiki.lesscss.compiler.LESSCompilerException)5 BaseObject (com.xpn.xwiki.objects.BaseObject)2 ColorThemeReference (org.xwiki.lesscss.internal.colortheme.ColorThemeReference)2 SkinReference (org.xwiki.lesscss.internal.skin.SkinReference)2 ObjectPropertyReference (org.xwiki.model.reference.ObjectPropertyReference)2 Less4jException (com.github.sommeri.less4j.Less4jException)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 BaseObjectReference (com.xpn.xwiki.objects.BaseObjectReference)1 StringWriter (java.io.StringWriter)1 VelocityContext (org.apache.velocity.VelocityContext)1 LESSCompiler (org.xwiki.lesscss.compiler.LESSCompiler)1 LESSResourceReferenceFactory (org.xwiki.lesscss.resources.LESSResourceReferenceFactory)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 VelocityManager (org.xwiki.velocity.VelocityManager)1 XWikiVelocityException (org.xwiki.velocity.XWikiVelocityException)1