Search in sources :

Example 1 with MacroManager

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

the class RenderingScriptServiceTest method getMacroDescriptors.

@Test
public void getMacroDescriptors() throws Exception {
    MacroManager macroManager = this.mocker.registerMockComponent(MacroManager.class);
    MacroId macroId = new MacroId("macroid");
    when(macroManager.getMacroIds(Syntax.XWIKI_2_1)).thenReturn(Collections.singleton(macroId));
    Macro macro = mock(Macro.class);
    when(macroManager.getMacro(macroId)).thenReturn(macro);
    MacroDescriptor descriptor = mock(MacroDescriptor.class);
    when(macro.getDescriptor()).thenReturn(descriptor);
    List<MacroDescriptor> descriptors = this.mocker.getComponentUnderTest().getMacroDescriptors(Syntax.XWIKI_2_1);
    assertEquals(1, descriptors.size());
    assertSame(descriptor, descriptors.get(0));
}
Also used : MacroDescriptor(org.xwiki.rendering.macro.descriptor.MacroDescriptor) Macro(org.xwiki.rendering.macro.Macro) MacroId(org.xwiki.rendering.macro.MacroId) MacroManager(org.xwiki.rendering.macro.MacroManager) Test(org.junit.Test)

Example 2 with MacroManager

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

the class NestedScriptMacroValidatorTest method configure.

@Before
public void configure() throws Exception {
    // Mock macro manager returns a script macro for "script" and null otherwise.
    final MacroManager macroManager = getComponentManager().getInstance(MacroManager.class);
    final ScriptMacro scriptMacro = new DefaultScriptMacro();
    final TestNestedScriptMacroEnabled nestedScriptMacroEnabled = new TestNestedScriptMacroEnabled();
    getMockery().checking(new Expectations() {

        {
            allowing(macroManager).getMacro(with(new MacroId("script")));
            will(returnValue(scriptMacro));
            allowing(macroManager).getMacro(with(new MacroId("nestedscriptmacroenabled")));
            will(returnValue(nestedScriptMacroEnabled));
            allowing(macroManager).getMacro(with(any(MacroId.class)));
            will(returnValue(null));
        }
    });
    this.validator = getComponentManager().getInstance(EventListener.class, "nestedscriptmacrovalidator");
}
Also used : Expectations(org.jmock.Expectations) DefaultScriptMacro(org.xwiki.rendering.internal.macro.script.DefaultScriptMacro) DefaultScriptMacro(org.xwiki.rendering.internal.macro.script.DefaultScriptMacro) MacroId(org.xwiki.rendering.macro.MacroId) MacroManager(org.xwiki.rendering.macro.MacroManager) EventListener(org.xwiki.observation.EventListener) Before(org.junit.Before)

Example 3 with MacroManager

use of org.xwiki.rendering.macro.MacroManager 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

MacroId (org.xwiki.rendering.macro.MacroId)3 MacroManager (org.xwiki.rendering.macro.MacroManager)3 Before (org.junit.Before)2 Macro (org.xwiki.rendering.macro.Macro)2 Expectations (org.jmock.Expectations)1 Test (org.junit.Test)1 EventListener (org.xwiki.observation.EventListener)1 BeanDescriptor (org.xwiki.properties.BeanDescriptor)1 BeanManager (org.xwiki.properties.BeanManager)1 DefaultScriptMacro (org.xwiki.rendering.internal.macro.script.DefaultScriptMacro)1 VelocityMacro (org.xwiki.rendering.internal.macro.velocity.VelocityMacro)1 MacroDescriptor (org.xwiki.rendering.macro.descriptor.MacroDescriptor)1 ContextualAuthorizationManager (org.xwiki.security.authorization.ContextualAuthorizationManager)1