@Test public void testRegisterWikiMacroWhenGlobalVisibilityAndAllowed() throws Exception { final DefaultWikiMacro wikiMacro = generateWikiMacro(WikiMacroVisibility.GLOBAL); // Simulate a user with programming rights getMockery() .checking( new Expectations() { { allowing(mockDocumentAccessBridge).getCurrentWiki(); will(returnValue("wiki")); allowing(mockDocumentAccessBridge).getCurrentUser(); will(returnValue("dummy")); allowing(mockDocumentAccessBridge).setCurrentUser("dummy"); allowing(mockWikiMacroFactory) .isAllowed(wikiMacro.getDocumentReference(), WikiMacroVisibility.GLOBAL); will(returnValue(true)); } }); Assert.assertFalse(wikiMacroManager.hasWikiMacro(wikiMacro.getDocumentReference())); wikiMacroManager.registerWikiMacro(wikiMacro.getDocumentReference(), wikiMacro); Assert.assertTrue(wikiMacroManager.hasWikiMacro(wikiMacro.getDocumentReference())); Macro<?> registeredMacro = macroManager.getMacro(new MacroId("testwikimacro")); Assert.assertEquals(0, registeredMacro.compareTo(wikiMacro)); wikiMacroManager.unregisterWikiMacro(wikiMacro.getDocumentReference()); Assert.assertFalse(wikiMacroManager.hasWikiMacro(wikiMacro.getDocumentReference())); Assert.assertFalse(macroManager.exists(new MacroId("testwikimacro"))); }
@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); }