Where do you get NullPointerExceptions? Could you post a stack trace? How does getHivemindRegistry work?
Achim Am Thu, 07 Sep 2006 17:09:41 +0200 schrieb <[EMAIL PROTECTED]>:
Hi, 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) registry.getService(ApplicationStateManager.class); } 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 defined. 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!