Search in sources :

Example 1 with BeanDescriptor

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

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

Example 3 with BeanDescriptor

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);
}
Also used : BeanDescriptor(org.xwiki.properties.BeanDescriptor) BeanManager(org.xwiki.properties.BeanManager) Before(org.junit.Before)

Example 4 with BeanDescriptor

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);
}
Also used : ContextualAuthorizationManager(org.xwiki.security.authorization.ContextualAuthorizationManager) BeanDescriptor(org.xwiki.properties.BeanDescriptor) VelocityMacro(org.xwiki.rendering.internal.macro.velocity.VelocityMacro) Macro(org.xwiki.rendering.macro.Macro) MacroId(org.xwiki.rendering.macro.MacroId) MacroManager(org.xwiki.rendering.macro.MacroManager) BeanManager(org.xwiki.properties.BeanManager) Before(org.junit.Before)

Example 5 with BeanDescriptor

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;
}
Also used : HashMap(java.util.HashMap) BeanDescriptor(org.xwiki.properties.BeanDescriptor) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

BeanDescriptor (org.xwiki.properties.BeanDescriptor)5 BeanManager (org.xwiki.properties.BeanManager)4 Before (org.junit.Before)2 Test (org.junit.Test)2 Execution (org.xwiki.context.Execution)2 ExecutionContext (org.xwiki.context.ExecutionContext)2 DashboardMacroParameters (org.xwiki.rendering.macro.dashboard.DashboardMacroParameters)2 MacroTransformationContext (org.xwiki.rendering.transformation.MacroTransformationContext)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 VelocityMacro (org.xwiki.rendering.internal.macro.velocity.VelocityMacro)1 Macro (org.xwiki.rendering.macro.Macro)1 MacroExecutionException (org.xwiki.rendering.macro.MacroExecutionException)1 MacroId (org.xwiki.rendering.macro.MacroId)1 MacroManager (org.xwiki.rendering.macro.MacroManager)1 DashboardRenderer (org.xwiki.rendering.macro.dashboard.DashboardRenderer)1 GadgetRenderer (org.xwiki.rendering.macro.dashboard.GadgetRenderer)1 ContextualAuthorizationManager (org.xwiki.security.authorization.ContextualAuthorizationManager)1