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());
}
}
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"));
}
Aggregations