Is it possible to use ATGDust to test multi-site functionalities of ATG?
I have overridden ForgotPasswordHandler to set the message subject based on curent site name, which I get using SiteContextManager.getCurrentSiteContext().getCurrentSite().getItemDisplayName().
From ATG Dust, I can create a Test requests and response objects and directly call FormHandler.forgotPassword(request,response) but when I do this, SiteContextManager will not be initialized by ATG and it will throw a null pointer exception. During normal working this is probably handled by one of the pipelines.
From a ATGDust testcase, how can we make sure current site context is available inside nucleus?
First, there's a slightly easier way to get at the site name: SiteContextManager.getCurrentSite().getItemDisplayName()
Second, yes you can set the site context directly from your unit test code. You'd call SiteContextManager's pushSiteContext method. It's not a static method, so you need a reference to the SiteContextManager component. The method takes a SiteContext as input and returns true if the push was successful. They way you get your hands on a SiteContext object depends on what your test code is trying to do and how much of the normal ATG runtime environment is present.
If your test class contains a number of different cases, you might want to be a good citizen and match every pushSiteContext with a call to popSiteContext. The input to popSiteContext is the SiteContext object you pushed earlier. There's a sanity check to see if the context at the top of the stack is the one the caller passed in.