Search in sources :

Example 1 with RssMacroParameters

use of org.xwiki.rendering.macro.rss.RssMacroParameters in project xwiki-platform by xwiki.

the class RssMacroTest method testInvalidDocument.

/**
 * Tests the macro's behavior when the server hosting the feeds doesn't respond.
 */
@Test(expected = MacroExecutionException.class)
public void testInvalidDocument() throws Exception {
    // Use a Mock SyndFeedInput to control what it returns for the test.
    Mockery context = new Mockery();
    final RomeFeedFactory mockFactory = context.mock(RomeFeedFactory.class);
    final RssMacroParameters parameters = new RssMacroParameters();
    context.checking(new Expectations() {

        {
            oneOf(mockFactory).createFeed(with(same(parameters)));
            will(throwException(new MacroExecutionException("Error")));
        }
    });
    this.macro.setFeedFactory(mockFactory);
    // Dummy URL since a feed URL is mandatory
    parameters.setFeed("http://www.xwiki.org");
    this.macro.execute(parameters, null, null);
}
Also used : Expectations(org.jmock.Expectations) RssMacroParameters(org.xwiki.rendering.macro.rss.RssMacroParameters) MacroExecutionException(org.xwiki.rendering.macro.MacroExecutionException) Mockery(org.jmock.Mockery) Test(org.junit.Test)

Example 2 with RssMacroParameters

use of org.xwiki.rendering.macro.rss.RssMacroParameters in project xwiki-platform by xwiki.

the class RssMacroTest method testRequiredParameterMissing.

/**
 * Tests whether the macro throws the appropriate exception
 * in cases where the required 'feed' parameter is missing.
 */
@Test
public void testRequiredParameterMissing() throws Exception {
    try {
        this.macro.execute(new RssMacroParameters(), null, null);
        Assert.fail("Should have thrown an exception");
    } catch (MacroExecutionException expected) {
        Assert.assertEquals("The required 'feed' parameter is missing", expected.getMessage());
    }
}
Also used : RssMacroParameters(org.xwiki.rendering.macro.rss.RssMacroParameters) MacroExecutionException(org.xwiki.rendering.macro.MacroExecutionException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 MacroExecutionException (org.xwiki.rendering.macro.MacroExecutionException)2 RssMacroParameters (org.xwiki.rendering.macro.rss.RssMacroParameters)2 Expectations (org.jmock.Expectations)1 Mockery (org.jmock.Mockery)1