[Hippo-cms7-user] Testing plugins

Frank van Lankvelt f.vanlankvelt at onehippo.com
Fri Apr 24 12:51:33 CEST 2009


cool!  I definitively want this kind of functionality.

Wouldn't it have been easier to mock the IPluginContext instead of the
PluginManager?  The first is certainly part of the plugin development api,
the second is an implementation detail.  I guess ideally, you wouldn't want
to have to mock either of them, but only the services that are used?

What we can do is add this test to the addon with the plugin code and start
moving its generic features into the frontend engine.  (or another package)
Does that sound ok to you?

cheers, Frank

On Fri, Apr 24, 2009 at 12:10 PM, Jettro Coenradie <jettro at jteam.nl> wrote:

>  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
>
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/community.html
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.onehippo.org/pipermail/hippo-cms7-user/attachments/20090424/f39d74b6/attachment.htm>


More information about the Hippo-cms7-user mailing list