This discussion is archived
3 Replies Latest reply: Jul 22, 2013 10:18 AM by ClareR RSS

Using ATGDust to test Formhandlers in MultiSite context

Jagadeesh.P.B Newbie
Currently Being Moderated

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?

  • 1. Re: Using ATGDust to test Formhandlers in MultiSite context
    ClareR Journeyer
    Currently Being Moderated

    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.

  • 2. Re: Using ATGDust to test Formhandlers in MultiSite context
    Jagadeesh.P.B Newbie
    Currently Being Moderated

    Thanks Clare.This works. What's the easier way to get the SiteName?

  • 3. Re: Using ATGDust to test Formhandlers in MultiSite context
    ClareR Journeyer
    Currently Being Moderated

    The easier way to get the site name is the one I mentioned earlier.  It's similar to what you coded, without the call to getCurrentSiteContext.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points