use of org.xwiki.properties.BeanDescriptor 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.properties.BeanDescriptor 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"));
}
use of org.xwiki.properties.BeanDescriptor in project xwiki-platform by xwiki.
the class ContextMacroTest method setUp.
@Before
public void setUp() throws Exception {
// Macro Descriptor set up
BeanManager beanManager = this.mocker.getInstance(BeanManager.class);
BeanDescriptor descriptor = mock(BeanDescriptor.class);
when(descriptor.getProperties()).thenReturn(Collections.emptyList());
when(beanManager.getBeanDescriptor(any())).thenReturn(descriptor);
}
use of org.xwiki.properties.BeanDescriptor in project xwiki-platform by xwiki.
the class VelocityMacroSecurityTest method setUp.
@Before
public void setUp() throws Exception {
authorizationManager = mocker.registerMockComponent(ContextualAuthorizationManager.class);
BeanDescriptor mockBeanDescriptor = mock(BeanDescriptor.class);
when(mockBeanDescriptor.getProperties()).thenReturn(Collections.EMPTY_LIST);
BeanManager beanManager = mocker.getInstance(BeanManager.class);
when(beanManager.getBeanDescriptor(any(Class.class))).thenReturn(mockBeanDescriptor);
Macro velocityMacro = mocker.getComponentUnderTest();
MacroManager mockMacroManager = mocker.registerMockComponent(MacroManager.class);
when(mockMacroManager.getMacro(any(MacroId.class))).thenReturn(velocityMacro);
}
use of org.xwiki.properties.BeanDescriptor in project xwiki-platform by xwiki.
the class QuestionJobResourceReferenceHandler method extractParameters.
private Map<String, Object> extractParameters(HttpServletRequest request, Object question) {
Map<String, Object> parameters = new HashMap<>();
BeanDescriptor descriptor = this.beans.getBeanDescriptor(question.getClass());
for (Map.Entry<String, String[]> entry : request.getParameterMap().entrySet()) {
if (entry.getKey().startsWith(QPROPERTY_PREFIX) && entry.getValue() != null && entry.getValue().length > 0) {
String parameterKey = entry.getKey().substring(QPROPERTY_PREFIX.length());
if (parameterKey.endsWith(QPROPERTY_ARRAY_SUFFIX)) {
parameterKey = parameterKey.substring(0, parameterKey.length() - QPROPERTY_ARRAY_SUFFIX.length());
parameters.put(parameterKey, entry.getValue());
} else {
addValue(descriptor, parameterKey, parameters, entry.getValue());
}
}
}
return parameters;
}
Aggregations