Search in sources :

Example 11 with IconException

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

the class DefaultIconSetLoaderTest method loadIconSetWithException.

@Test
public void loadIconSetWithException() throws Exception {
    Reader content = mock(Reader.class);
    IOException exception = new IOException("test");
    when(content.read(any(char[].class))).thenThrow(exception);
    // Test
    Exception caughException = null;
    try {
        mocker.getComponentUnderTest().loadIconSet(content, "FontAwesome");
    } catch (IconException e) {
        caughException = e;
    }
    assertNotNull(caughException);
    assert (caughException instanceof IconException);
    assertEquals(exception, caughException.getCause());
    assertEquals("Failed to load the IconSet [FontAwesome].", caughException.getMessage());
}
Also used : Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) IOException(java.io.IOException) IconException(org.xwiki.icon.IconException) IconException(org.xwiki.icon.IconException) Test(org.junit.Test)

Example 12 with IconException

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

the class DefaultIconSetManagerTest method getDefaultIconWithException.

@Test
public void getDefaultIconWithException() throws Exception {
    // Mocks
    Exception exception = new MalformedURLException();
    when(xwiki.getResourceAsStream(any())).thenThrow(exception);
    // Test
    Exception exceptionCaught = null;
    try {
        mocker.getComponentUnderTest().getDefaultIconSet();
    } catch (IconException e) {
        exceptionCaught = e;
    }
    // Verify
    assertNotNull(exceptionCaught);
    assertEquals(exception, exceptionCaught.getCause());
    assertEquals("Failed to get the current default icon set.", exceptionCaught.getMessage());
}
Also used : MalformedURLException(java.net.MalformedURLException) QueryException(org.xwiki.query.QueryException) IconException(org.xwiki.icon.IconException) MalformedURLException(java.net.MalformedURLException) IconException(org.xwiki.icon.IconException) Test(org.junit.Test)

Example 13 with IconException

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

the class DefaultIconSetManagerTest method getIconSetNamesWhenException.

@Test
public void getIconSetNamesWhenException() throws Exception {
    // Mocks
    QueryException exception = new QueryException("exception in the query", null, null);
    when(queryManager.createQuery(any(), eq(Query.XWQL))).thenThrow(exception);
    // Test
    IconException caughtException = null;
    try {
        mocker.getComponentUnderTest().getIconSetNames();
    } catch (IconException e) {
        caughtException = e;
    }
    // Verify
    assertNotNull(caughtException);
    assertEquals("Failed to get the name of all icon sets.", caughtException.getMessage());
    assertEquals(exception, caughtException.getCause());
}
Also used : QueryException(org.xwiki.query.QueryException) IconException(org.xwiki.icon.IconException) Test(org.junit.Test)

Example 14 with IconException

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

the class VelocityRendererTest method renderWhenEvaluateReturnsFalse.

@Test
public void renderWhenEvaluateReturnsFalse() throws Exception {
    // Mocks
    VelocityEngine engine = mock(VelocityEngine.class);
    when(velocityManager.getVelocityEngine()).thenReturn(engine);
    when(engine.evaluate(any(VelocityContext.class), any(Writer.class), any(), eq("myCode"))).thenReturn(false);
    // Test
    IconException caughtException = null;
    try {
        mocker.getComponentUnderTest().render("myCode");
    } catch (IconException e) {
        caughtException = e;
    }
    // Verify
    assertNotNull(caughtException);
    assertEquals("Failed to render the icon. See the Velocity runtime log.", caughtException.getMessage());
    verify(engine).startedUsingMacroNamespace("IconVelocityRenderer_" + Thread.currentThread().getId());
    verify(engine).stoppedUsingMacroNamespace("IconVelocityRenderer_" + Thread.currentThread().getId());
}
Also used : VelocityEngine(org.xwiki.velocity.VelocityEngine) VelocityContext(org.apache.velocity.VelocityContext) Writer(java.io.Writer) IconException(org.xwiki.icon.IconException) Test(org.junit.Test)

Aggregations

IconException (org.xwiki.icon.IconException)14 Test (org.junit.Test)8 QueryException (org.xwiki.query.QueryException)5 IOException (java.io.IOException)4 IconSet (org.xwiki.icon.IconSet)4 MalformedURLException (java.net.MalformedURLException)3 DocumentReference (org.xwiki.model.reference.DocumentReference)3 InputStreamReader (java.io.InputStreamReader)2 VelocityContext (org.apache.velocity.VelocityContext)2 Icon (org.xwiki.icon.Icon)2 Query (org.xwiki.query.Query)2 VelocityEngine (org.xwiki.velocity.VelocityEngine)2 XWikiVelocityException (org.xwiki.velocity.XWikiVelocityException)2 XWiki (com.xpn.xwiki.XWiki)1 XWikiContext (com.xpn.xwiki.XWikiContext)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 Properties (java.util.Properties)1