Search in sources :

Example 36 with IconSet

use of org.xwiki.icon.IconSet in project xwiki-platform by xwiki.

the class DefaultIconSetManagerTest method getCurrentIconSet.

@Test
public void getCurrentIconSet() throws Exception {
    String currentIconTheme = "IconThemes.SilkTheme";
    when(configurationSource.getProperty("iconTheme")).thenReturn(currentIconTheme);
    DocumentReference iconThemeRef = new DocumentReference("xwiki", "IconThemes", "SilkTheme");
    when(documentReferenceResolver.resolve(currentIconTheme)).thenReturn(iconThemeRef);
    when(documentAccessBridge.exists(iconThemeRef)).thenReturn(true);
    IconSet iconSet = new IconSet(currentIconTheme);
    when(iconSetLoader.loadIconSet(iconThemeRef)).thenReturn(iconSet);
    // Test
    IconSet result = mocker.getComponentUnderTest().getCurrentIconSet();
    // Verify
    assertEquals(iconSet, result);
    verify(iconSetCache).put(iconThemeRef, iconSet);
    verify(iconSetCache).put(currentIconTheme, "currentWikiId", iconSet);
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DocumentReference(org.xwiki.model.reference.DocumentReference) IconSet(org.xwiki.icon.IconSet) Test(org.junit.Test)

Example 37 with IconSet

use of org.xwiki.icon.IconSet in project xwiki-platform by xwiki.

the class DefaultIconSetManagerTest method getIconSetWhenInCache.

@Test
public void getIconSetWhenInCache() throws Exception {
    // Mocks
    IconSet iconSet = new IconSet("silk");
    when(iconSetCache.get("silk", "currentWikiId")).thenReturn(iconSet);
    // Test
    assertEquals(iconSet, mocker.getComponentUnderTest().getIconSet("silk"));
    // Verify
    verify(iconSetCache, never()).put(anyString(), any(IconSet.class));
}
Also used : IconSet(org.xwiki.icon.IconSet) Test(org.junit.Test)

Example 38 with IconSet

use of org.xwiki.icon.IconSet in project xwiki-platform by xwiki.

the class DefaultIconSetManagerTest method getIconSetWhenNotInCache.

@Test
public void getIconSetWhenNotInCache() throws Exception {
    // Mocks
    IconSet iconSet = new IconSet("silk");
    Query query = mock(Query.class);
    when(queryManager.createQuery("FROM doc.object(IconThemesCode.IconThemeClass) obj WHERE obj.name = :name", Query.XWQL)).thenReturn(query);
    List<String> results = new ArrayList<>();
    results.add("IconThemes.Silk");
    when(query.<String>execute()).thenReturn(results);
    DocumentReference documentReference = new DocumentReference("wiki", "IconThemes", "Silk");
    when(documentReferenceResolver.resolve("IconThemes.Silk")).thenReturn(documentReference);
    when(iconSetLoader.loadIconSet(documentReference)).thenReturn(iconSet);
    // Test
    assertEquals(iconSet, mocker.getComponentUnderTest().getIconSet("silk"));
    // Verify
    verify(query).bindValue("name", "silk");
    verify(iconSetCache).put(documentReference, iconSet);
    verify(iconSetCache).put("silk", "currentWikiId", iconSet);
}
Also used : Query(org.xwiki.query.Query) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DocumentReference(org.xwiki.model.reference.DocumentReference) IconSet(org.xwiki.icon.IconSet) Test(org.junit.Test)

Aggregations

IconSet (org.xwiki.icon.IconSet)38 Test (org.junit.Test)33 Icon (org.xwiki.icon.Icon)14 DocumentReference (org.xwiki.model.reference.DocumentReference)9 InputStreamReader (java.io.InputStreamReader)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 IconException (org.xwiki.icon.IconException)4 InputStream (java.io.InputStream)2 Reader (java.io.Reader)2 HashMap (java.util.HashMap)2 Query (org.xwiki.query.Query)2 XWiki (com.xpn.xwiki.XWiki)1 XWikiContext (com.xpn.xwiki.XWikiContext)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 Before (org.junit.Before)1 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)1