Search in sources :

Example 1 with BeanManager

use of org.xwiki.properties.BeanManager 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 BeanManager

use of org.xwiki.properties.BeanManager 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 BeanManager

use of org.xwiki.properties.BeanManager in project xwiki-platform by xwiki.

the class SignableMacroTest method setUp.

@Before
public void setUp() throws Exception {
    BeanManager beanManager = mocker.getInstance(BeanManager.class);
    when(beanManager.getBeanDescriptor(Object.class)).thenReturn(new DefaultBeanDescriptor(Object.class));
    store = mocker.registerMockComponent(SignatureStore.class);
    when(store.retrieve(BLOCK_REFERENCE)).thenReturn(SIGNATURE);
    BlockSignatureGenerator signer = mocker.registerMockComponent(BlockSignatureGenerator.class, "macro");
    when(signer.generate(BLOCK, PARAMETERS)).thenReturn(SIGNATURE);
    BlockSignatureVerifier verifier = mocker.registerMockComponent(BlockSignatureVerifier.class, "macro");
    when(verifier.verify(SIGNATURE, BLOCK, null)).thenReturn(VERIFIED);
    BlockReferenceResolver<Block> resolver = mocker.registerMockComponent(new DefaultParameterizedType(null, BlockReferenceResolver.class, Block.class), "currentsignedmacro");
    when(resolver.resolve(BLOCK)).thenReturn(BLOCK_REFERENCE);
    macro = mocker.getComponentUnderTest();
}
Also used : SignatureStore(org.xwiki.crypto.store.SignatureStore) BlockSignatureGenerator(org.xwiki.rendering.signature.BlockSignatureGenerator) DefaultBeanDescriptor(org.xwiki.properties.internal.DefaultBeanDescriptor) Block(org.xwiki.rendering.block.Block) MacroBlock(org.xwiki.rendering.block.MacroBlock) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) BeanManager(org.xwiki.properties.BeanManager) BlockSignatureVerifier(org.xwiki.rendering.signature.BlockSignatureVerifier) BlockReferenceResolver(org.xwiki.model.reference.BlockReferenceResolver) Before(org.junit.Before)

Example 4 with BeanManager

use of org.xwiki.properties.BeanManager 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 5 with BeanManager

use of org.xwiki.properties.BeanManager 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)

Aggregations

BeanManager (org.xwiki.properties.BeanManager)5 BeanDescriptor (org.xwiki.properties.BeanDescriptor)4 Before (org.junit.Before)3 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 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)1 SignatureStore (org.xwiki.crypto.store.SignatureStore)1 BlockReferenceResolver (org.xwiki.model.reference.BlockReferenceResolver)1 DefaultBeanDescriptor (org.xwiki.properties.internal.DefaultBeanDescriptor)1 Block (org.xwiki.rendering.block.Block)1 MacroBlock (org.xwiki.rendering.block.MacroBlock)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