use of org.xwiki.icon.IconException in project xwiki-platform by xwiki.
the class DefaultIconSetManager method getIconSetNames.
@Override
public List<String> getIconSetNames() throws IconException {
try {
String xwql = "SELECT obj.name FROM Document doc, doc.object(IconThemesCode.IconThemeClass) obj " + "ORDER BY obj.name";
Query query = queryManager.createQuery(xwql, Query.XWQL);
return query.execute();
} catch (QueryException e) {
throw new IconException("Failed to get the name of all icon sets.", e);
}
}
use of org.xwiki.icon.IconException in project xwiki-platform by xwiki.
the class DefaultIconSetManager method getDefaultIconSet.
@Override
public IconSet getDefaultIconSet() throws IconException {
XWikiContext xcontext = xcontextProvider.get();
XWiki xwiki = xcontext.getWiki();
IconSet iconSet = iconSetCache.get(DEFAULT_ICONSET_NAME);
if (iconSet == null) {
try {
// lazy loading
iconSet = iconSetLoader.loadIconSet(new InputStreamReader(xwiki.getResourceAsStream("/resources/icons/default.iconset")), DEFAULT_ICONSET_NAME);
iconSetCache.put(DEFAULT_ICONSET_NAME, iconSet);
} catch (IconException | MalformedURLException e) {
throw new IconException("Failed to get the current default icon set.", e);
}
}
return iconSet;
}
use of org.xwiki.icon.IconException in project xwiki-platform by xwiki.
the class DefaultIconSetLoaderTest method loadIconSetFromWikiDocumentWithException.
@Test
public void loadIconSetFromWikiDocumentWithException() throws Exception {
Exception exception = new Exception("test");
when(documentAccessBridge.getDocumentInstance(any(DocumentReference.class))).thenThrow(exception);
// Test
Exception caughException = null;
try {
mocker.getComponentUnderTest().loadIconSet(new DocumentReference("a", "b", "c"));
} catch (IconException e) {
caughException = e;
}
assertNotNull(caughException);
assert (caughException instanceof IconException);
assertEquals(exception, caughException.getCause());
assertEquals("Failed to load the IconSet [a:b.c].", caughException.getMessage());
}
use of org.xwiki.icon.IconException in project xwiki-platform by xwiki.
the class DefaultIconSetManagerTest method getIconSetWhenException.
@Test
public void getIconSetWhenException() throws Exception {
// Mocks
Exception exception = new QueryException("exception in the query", null, null);
when(queryManager.createQuery(any(), any())).thenThrow(exception);
// Test
Exception caughtException = null;
try {
mocker.getComponentUnderTest().getIconSet("silk");
} catch (IconException e) {
caughtException = e;
}
assertNotNull(caughtException);
assertEquals(exception, caughtException.getCause());
assertEquals("Failed to load the icon set [silk].", caughtException.getMessage());
}
use of org.xwiki.icon.IconException in project xwiki-platform by xwiki.
the class VelocityRendererTest method renderWithException.
@Test
public void renderWithException() throws Exception {
// Mocks
Exception exception = new XWikiVelocityException("exception");
when(velocityManager.getVelocityEngine()).thenThrow(exception);
// Test
IconException caughtException = null;
try {
mocker.getComponentUnderTest().render("myCode");
} catch (IconException e) {
caughtException = e;
}
// Verify
assertNotNull(caughtException);
assertEquals("Failed to render the icon.", caughtException.getMessage());
assertEquals(exception, caughtException.getCause());
}
Aggregations