hivemind-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <>
Subject How do JUnit test programmatic access of the Registry?
Date Thu, 07 Sep 2006 15:09:41 GMT

Here's the situation:

I have a Tapestry 4 application with a hivemodule.xml file inside of
which is a "tmpDir" ASO String.

I've got an HttpSessionListener configured to perform some cleanup
operations when the session expires.  

Inside that listener, I have code like this:

Object getASO(HttpSessionEvent event, String asoName) {
    ApplicationStateManager manager = null;
    Registry registry = getHivemindRegistry(event);
    if(registry.containsService(ApplicationStateManager.class)) {
        manager = (ApplicationStateManager) 
    } else {
	  throw new UsitcApplicationRuntimeException("blah");
    Object aso = null;

    if(manager.exists(asoName)) {
        aso = manager.get(asoName);	
    return aso;

I suspect this code will run fine in production, but I'm having a
helluva time writing a unit test for this.  Basically, I just want to
confirm that if I call 'getAso(event, "tempUploadDir")' it'll return the
String that is the value of the " tempUploadDir " key in my
hivemodule.xml ASO.  Simple, right?

In my unit test, I've got code like this:

public void testGetASO() throws Exception {
    //  ehmtc just extends the HiveMindTestCase to provide access to the

    // protected 'buildFrameworkRegistry' methods
    EdisHiveMindUtil ehmtc = new EdisHiveMindUtil();
    Registry registry = ehmtc.buildFrameworkRegistry();
    HttpSessionEvent event = createMockHttpSessionEvent(registry);
    SessionListener sl = new SessionListener();
    String dir = (String)sl.getASO(event, "tempUploadDir");
    System.out.println("dir = " + dir);

The problem is that even though the registry gets loaded, it
NullPointerExceptions unless the (key, value) pair for tempUploadDir is

Unfortunately, I see no way in the API of force-setting that ASO, nor do
I see a straight forward way of EasyMocking this.

Please help!

View raw message