[Hippo-cms7-user] Testing plugins

Jettro Coenradie jettro at jteam.nl
Fri Apr 24 12:10:50 CEST 2009


He all,
for a project we are developing new plugins. Since we like to work test driven we are trying to write a test as well. This is not very easy. The constructor that the plugins have to use do a lot in the super classes. I have come to the following test class for an existing class in de hippo code base. I can create a patch if someone likes to have it.

public class GotolinkDocumentsShortcutPluginTest {
    final PluginManager mockPluginManager = createMock("pluginManager", PluginManager.class);
    final IBrowseService mockBrowseService = createMock("browseService", IBrowseService.class);
    final IBrowseService mockFocusService = createMock("focusService", IBrowseService.class);
    final IModelReference mockModelReference = createMock("modelReference", IModelReference.class);
    final IModel mockModel = createMock("model", IModel.class);

    @Test
    public void checkAvailablePluginPropertyForBrowserId() {
        mockPluginManager.registerService(isA(IClusterable.class), isA(String.class)); //"org.hippoecm.frontend.model.event.IObserver"
        mockPluginManager.registerService(isA(MarkupContainer.class), isA(String.class));// shurtcut
        expect(mockPluginManager.getService("model.browse.folder", IModelReference.class)).andReturn(mockModelReference).times(2);
        expect(mockPluginManager.getService("dummy.browserid", IBrowseService.class)).andReturn(mockBrowseService);
        expect(mockPluginManager.getService("focus.id", IBrowseService.class)).andReturn(mockFocusService);
        expect(mockModelReference.getModel()).andReturn(mockModel);
        mockModel.detach();
        expectLastCall().times(2);

        //noinspection unchecked
        mockBrowseService.browse(isA(JcrNodeModel.class));
        //noinspection unchecked
        mockFocusService.browse(isA(JcrNodeModel.class));

        replay(mockPluginManager, mockBrowseService, mockFocusService, mockModelReference, mockModel);

        WicketTester tester = new WicketTester(new HippoWebApplication());

        TestPanelSource testPanelSource = new TestPanelSource() {
            public Panel getTestPanel(String panelId) {
                IPluginConfig iPluginConfig = new JavaPluginConfig(panelId);
                iPluginConfig.put("browser.id", "dummy.browserid");
                iPluginConfig.put("wicket.model", "model.browse.folder");
                iPluginConfig.put("wicket.id", "shortcut");

                IPluginContext iPluginContext = new PluginContext(mockPluginManager, iPluginConfig);

                GotolinkDocumentsShortcutPlugin documentsShortcutPlugin
                        = new GotolinkDocumentsShortcutPlugin(iPluginContext, iPluginConfig);
                // This is just used to change the id of the plugin
                documentsShortcutPlugin.bind(documentsShortcutPlugin, panelId);

                return documentsShortcutPlugin;
            }
        };
        tester.startPanel(testPanelSource);
        tester.clickLink("panel:link", true); // true = is an ajax link
        verify(mockPluginManager, mockBrowseService, mockFocusService, mockModelReference, mockModel);
    }

    public class HippoWebApplication extends WicketTester.DummyWebApplication {

        public Class getHomePage() {
            return MyHomePage.class;
        }
    }
}

public class MyHomePage extends WebPage {
    public MyHomePage() {
    }
}

and an almost empty MyHomePage.html

Not everything is clear to me. It would be great if someone can have a look at it and come with improvements.

regards Jettro
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.onehippo.org/pipermail/hippo-cms7-user/attachments/20090424/b155775e/attachment.htm>


More information about the Hippo-cms7-user mailing list