Search in sources :

Example 1 with LESSSkinFileResourceReference

use of org.xwiki.lesscss.internal.resources.LESSSkinFileResourceReference in project xwiki-platform by xwiki.

the class DefaultLESSResourcesCacheTest method clearFromSkin.

@Test
public void clearFromSkin() throws Exception {
    // Mocks
    LESSSkinFileResourceReference file1 = createLESSSkinFileResourceReference("file1");
    LESSSkinFileResourceReference file2 = createLESSSkinFileResourceReference("file2");
    when(cacheKeyFactory.getCacheKey(eq(file1), eq(new FSSkinReference("skin1")), eq(new NamedColorThemeReference("colorTheme")), eq(true))).thenReturn("k1");
    when(cacheKeyFactory.getCacheKey(eq(file1), eq(new FSSkinReference("skin2")), eq(new NamedColorThemeReference("colorTheme")), eq(true))).thenReturn("k3");
    when(cacheKeyFactory.getCacheKey(eq(file2), eq(new FSSkinReference("skin1")), eq(new NamedColorThemeReference("colorTheme")), eq(true))).thenReturn("k4");
    // Add the first one twice
    mocker.getComponentUnderTest().set(createLESSSkinFileResourceReference("file1"), new FSSkinReference("skin1"), new NamedColorThemeReference("colorTheme"), "css1");
    mocker.getComponentUnderTest().set(createLESSSkinFileResourceReference("file1"), new FSSkinReference("skin1"), new NamedColorThemeReference("colorTheme"), "css1");
    // Others
    mocker.getComponentUnderTest().set(createLESSSkinFileResourceReference("file1"), new FSSkinReference("skin2"), new NamedColorThemeReference("colorTheme"), "css2");
    mocker.getComponentUnderTest().set(createLESSSkinFileResourceReference("file2"), new FSSkinReference("skin1"), new NamedColorThemeReference("colorTheme"), "css3");
    // Test
    mocker.getComponentUnderTest().clearFromSkin(new FSSkinReference("skin1"));
    // Verify
    verify(cache, times(1)).remove("k1");
    verify(cache).remove("k4");
    verify(cache, never()).remove("k3");
}
Also used : NamedColorThemeReference(org.xwiki.lesscss.internal.colortheme.NamedColorThemeReference) FSSkinReference(org.xwiki.lesscss.internal.skin.FSSkinReference) LESSSkinFileResourceReference(org.xwiki.lesscss.internal.resources.LESSSkinFileResourceReference) Test(org.junit.Test)

Example 2 with LESSSkinFileResourceReference

use of org.xwiki.lesscss.internal.resources.LESSSkinFileResourceReference in project xwiki-platform by xwiki.

the class DefaultLESSResourcesCacheTest method setUp.

@Before
public void setUp() throws Exception {
    cacheManager = mocker.getInstance(CacheManager.class);
    cache = mock(Cache.class);
    CacheFactory cacheFactory = mock(CacheFactory.class);
    when(cacheManager.getCacheFactory()).thenReturn(cacheFactory);
    CacheConfiguration configuration = new CacheConfiguration("lesscss.skinfiles.cache");
    when(cacheFactory.<String>newCache(eq(configuration))).thenReturn(cache);
    cacheKeyFactory = mocker.getInstance(CacheKeyFactory.class);
    LESSSkinFileResourceReference lessSkinFileResourceReference = new LESSSkinFileResourceReference("lessResource", null, null);
    when(cacheKeyFactory.getCacheKey(eq(lessSkinFileResourceReference), eq(new FSSkinReference("skin")), eq(new NamedColorThemeReference("colorTheme")), eq(true))).thenReturn("12_lessResource_4_skin_10_colorTheme");
}
Also used : NamedColorThemeReference(org.xwiki.lesscss.internal.colortheme.NamedColorThemeReference) CacheManager(org.xwiki.cache.CacheManager) FSSkinReference(org.xwiki.lesscss.internal.skin.FSSkinReference) CacheFactory(org.xwiki.cache.CacheFactory) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration) Cache(org.xwiki.cache.Cache) LESSSkinFileResourceReference(org.xwiki.lesscss.internal.resources.LESSSkinFileResourceReference) Before(org.junit.Before)

Example 3 with LESSSkinFileResourceReference

use of org.xwiki.lesscss.internal.resources.LESSSkinFileResourceReference in project xwiki-platform by xwiki.

the class DefaultLESSResourcesCacheTest method set.

@Test
public void set() throws Exception {
    // Test
    mocker.getComponentUnderTest().set(new LESSSkinFileResourceReference("lessResource", null, null), new FSSkinReference("skin"), new NamedColorThemeReference("colorTheme"), "css");
    // Verify
    verify(cache).set(eq("12_lessResource_4_skin_10_colorTheme"), eq("css"));
}
Also used : NamedColorThemeReference(org.xwiki.lesscss.internal.colortheme.NamedColorThemeReference) FSSkinReference(org.xwiki.lesscss.internal.skin.FSSkinReference) LESSSkinFileResourceReference(org.xwiki.lesscss.internal.resources.LESSSkinFileResourceReference) Test(org.junit.Test)

Example 4 with LESSSkinFileResourceReference

use of org.xwiki.lesscss.internal.resources.LESSSkinFileResourceReference in project xwiki-platform by xwiki.

the class DefaultLESSResourcesCacheTest method clearFromColorTheme.

@Test
public void clearFromColorTheme() throws Exception {
    // Mocks
    LESSSkinFileResourceReference file1 = createLESSSkinFileResourceReference("file1");
    LESSSkinFileResourceReference file2 = createLESSSkinFileResourceReference("file2");
    when(cacheKeyFactory.getCacheKey(eq(file1), eq(new FSSkinReference("skin1")), eq(new NamedColorThemeReference("colorTheme1")), eq(true))).thenReturn("k1");
    when(cacheKeyFactory.getCacheKey(eq(file1), eq(new FSSkinReference("skin1")), eq(new NamedColorThemeReference("colorTheme2")), eq(true))).thenReturn("k3");
    when(cacheKeyFactory.getCacheKey(eq(file2), eq(new FSSkinReference("skin2")), eq(new NamedColorThemeReference("colorTheme1")), eq(true))).thenReturn("k4");
    // Add the first one twice
    mocker.getComponentUnderTest().set(createLESSSkinFileResourceReference("file1"), new FSSkinReference("skin1"), new NamedColorThemeReference("colorTheme1"), "css1");
    mocker.getComponentUnderTest().set(createLESSSkinFileResourceReference("file1"), new FSSkinReference("skin1"), new NamedColorThemeReference("colorTheme1"), "css1");
    // Others
    mocker.getComponentUnderTest().set(createLESSSkinFileResourceReference("file1"), new FSSkinReference("skin1"), new NamedColorThemeReference("colorTheme2"), "css2");
    mocker.getComponentUnderTest().set(createLESSSkinFileResourceReference("file2"), new FSSkinReference("skin2"), new NamedColorThemeReference("colorTheme1"), "css3");
    // Test
    mocker.getComponentUnderTest().clearFromColorTheme(new NamedColorThemeReference("colorTheme1"));
    // Verify
    verify(cache, times(1)).remove("k1");
    verify(cache).remove("k4");
    verify(cache, never()).remove("k3");
}
Also used : NamedColorThemeReference(org.xwiki.lesscss.internal.colortheme.NamedColorThemeReference) FSSkinReference(org.xwiki.lesscss.internal.skin.FSSkinReference) LESSSkinFileResourceReference(org.xwiki.lesscss.internal.resources.LESSSkinFileResourceReference) Test(org.junit.Test)

Example 5 with LESSSkinFileResourceReference

use of org.xwiki.lesscss.internal.resources.LESSSkinFileResourceReference in project xwiki-platform by xwiki.

the class DefaultLESSColorThemeConverterTest method getColorThemeFromSkinFileWhenInCache.

@Test
public void getColorThemeFromSkinFileWhenInCache() throws Exception {
    // Mocks
    ColorTheme cachedColorTheme = new ColorTheme();
    cachedColorTheme.put("key", "value1");
    LESSSkinFileResourceReference lessSkinFileResourceReference = new LESSSkinFileResourceReference("file", null, null);
    when(lessResourceReferenceFactory.createReferenceForSkinFile("file")).thenReturn(lessSkinFileResourceReference);
    when(cache.get(eq(lessSkinFileResourceReference), eq(new FSSkinReference("skin")), eq(new NamedColorThemeReference("colorTheme")))).thenReturn(cachedColorTheme);
    // Test
    ColorTheme result = mocker.getComponentUnderTest().getColorThemeFromSkinFile("file", "skin", false);
    // Verify
    assertEquals(cachedColorTheme, result);
    // Verify that the returned value is not the instance stored in the cache (that the end-user would wrongly be
    // able to modify)
    assertTrue(result != cachedColorTheme);
    // Be extra-sure :)
    result.put("key", "value2");
    assertNotEquals("value2", cachedColorTheme.get("key"));
}
Also used : ColorTheme(org.xwiki.lesscss.internal.colortheme.ColorTheme) NamedColorThemeReference(org.xwiki.lesscss.internal.colortheme.NamedColorThemeReference) FSSkinReference(org.xwiki.lesscss.internal.skin.FSSkinReference) LESSSkinFileResourceReference(org.xwiki.lesscss.internal.resources.LESSSkinFileResourceReference) Test(org.junit.Test)

Aggregations

LESSSkinFileResourceReference (org.xwiki.lesscss.internal.resources.LESSSkinFileResourceReference)10 NamedColorThemeReference (org.xwiki.lesscss.internal.colortheme.NamedColorThemeReference)8 FSSkinReference (org.xwiki.lesscss.internal.skin.FSSkinReference)8 Test (org.junit.Test)7 StringWriter (java.io.StringWriter)2 Before (org.junit.Before)2 Less4jException (com.github.sommeri.less4j.Less4jException)1 LessCompiler (com.github.sommeri.less4j.LessCompiler)1 DefaultLessCompiler (com.github.sommeri.less4j.core.DefaultLessCompiler)1 XWiki (com.xpn.xwiki.XWiki)1 XWikiContext (com.xpn.xwiki.XWikiContext)1 Cache (org.xwiki.cache.Cache)1 CacheFactory (org.xwiki.cache.CacheFactory)1 CacheManager (org.xwiki.cache.CacheManager)1 CacheConfiguration (org.xwiki.cache.config.CacheConfiguration)1 LESSCompilerException (org.xwiki.lesscss.compiler.LESSCompilerException)1 ColorThemeCache (org.xwiki.lesscss.internal.cache.ColorThemeCache)1 ColorTheme (org.xwiki.lesscss.internal.colortheme.ColorTheme)1 ColorThemeReferenceFactory (org.xwiki.lesscss.internal.colortheme.ColorThemeReferenceFactory)1 CurrentColorThemeGetter (org.xwiki.lesscss.internal.colortheme.CurrentColorThemeGetter)1