Search in sources :

Example 1 with DashboardMacroParameters

use of org.xwiki.rendering.macro.dashboard.DashboardMacroParameters in project xwiki-platform by xwiki.

the class DashboardMacroTest method executeWhenInsideDashboardMacro.

@Test
public void executeWhenInsideDashboardMacro() throws Exception {
    BeanManager beanManager = this.mocker.getInstance(BeanManager.class);
    BeanDescriptor descriptor = mock(BeanDescriptor.class);
    when(beanManager.getBeanDescriptor(any())).thenReturn(descriptor);
    when(descriptor.getProperties()).thenReturn(Collections.emptyList());
    Execution execution = this.mocker.getInstance(Execution.class);
    ExecutionContext ec = new ExecutionContext();
    when(execution.getContext()).thenReturn(ec);
    ec.setProperty("dashboardMacroCalls", 1);
    DashboardMacroParameters parameters = new DashboardMacroParameters();
    MacroTransformationContext macroContext = new MacroTransformationContext();
    try {
        this.mocker.getComponentUnderTest().execute(parameters, "", macroContext);
        fail("Exception should have been raised here");
    } catch (MacroExecutionException expected) {
        assertEquals("Dashboard macro recursion detected. Don't call the Dashboard macro inside of itself...", expected.getMessage());
    }
}
Also used : Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) BeanDescriptor(org.xwiki.properties.BeanDescriptor) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) MacroExecutionException(org.xwiki.rendering.macro.MacroExecutionException) DashboardMacroParameters(org.xwiki.rendering.macro.dashboard.DashboardMacroParameters) BeanManager(org.xwiki.properties.BeanManager) Test(org.junit.Test)

Example 2 with DashboardMacroParameters

use of org.xwiki.rendering.macro.dashboard.DashboardMacroParameters in project xwiki-platform by xwiki.

the class DashboardMacroTest method executeWhenNotInsideDashboardMacro.

@Test
public void executeWhenNotInsideDashboardMacro() throws Exception {
    BeanManager beanManager = this.mocker.getInstance(BeanManager.class);
    BeanDescriptor descriptor = mock(BeanDescriptor.class);
    when(beanManager.getBeanDescriptor(any())).thenReturn(descriptor);
    when(descriptor.getProperties()).thenReturn(Collections.emptyList());
    DashboardRenderer renderer = this.mocker.registerMockComponent(DashboardRenderer.class, "columns");
    GadgetRenderer gadgetRenderer = this.mocker.registerMockComponent(GadgetRenderer.class);
    Execution execution = this.mocker.getInstance(Execution.class);
    ExecutionContext ec = new ExecutionContext();
    when(execution.getContext()).thenReturn(ec);
    DashboardMacroParameters parameters = new DashboardMacroParameters();
    MacroTransformationContext macroContext = new MacroTransformationContext();
    this.mocker.getComponentUnderTest().execute(parameters, "", macroContext);
    // We verify that the counter ends up at 0 so that calls to subsequent dashboard macros can succeed.
    assertEquals(0, ec.getProperty("dashboardMacroCalls"));
}
Also used : Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) BeanDescriptor(org.xwiki.properties.BeanDescriptor) DashboardRenderer(org.xwiki.rendering.macro.dashboard.DashboardRenderer) GadgetRenderer(org.xwiki.rendering.macro.dashboard.GadgetRenderer) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) DashboardMacroParameters(org.xwiki.rendering.macro.dashboard.DashboardMacroParameters) BeanManager(org.xwiki.properties.BeanManager) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 Execution (org.xwiki.context.Execution)2 ExecutionContext (org.xwiki.context.ExecutionContext)2 BeanDescriptor (org.xwiki.properties.BeanDescriptor)2 BeanManager (org.xwiki.properties.BeanManager)2 DashboardMacroParameters (org.xwiki.rendering.macro.dashboard.DashboardMacroParameters)2 MacroTransformationContext (org.xwiki.rendering.transformation.MacroTransformationContext)2 MacroExecutionException (org.xwiki.rendering.macro.MacroExecutionException)1 DashboardRenderer (org.xwiki.rendering.macro.dashboard.DashboardRenderer)1 GadgetRenderer (org.xwiki.rendering.macro.dashboard.GadgetRenderer)1