The complexity of the test setup often reflects how much of the
framework itself you involve in your tests. Usually, I try to avoid
mocking the context and http objects by implementing the *Aware
interfaces and simply injecting simple Map objects, testing the action
in isolation. I realize that this is not always possible though...

Nils-H

On Thu, Nov 6, 2008 at 1:53 PM, Gundersen, Richard
<[EMAIL PROTECTED]> wrote:
> This is what I have so far. It works but I would appreciate a little
> peer review (particularly regarding how I set up my session and the
> logged in user)
>
> Thanks!
>
> ************************************************
>
> @Resource
> private CardPaymentAction cardPaymentAction;
>
>    ActionContext actionContext;
>    ServletActionContext servletActionContext;
>    private HttpServletRequest request;
>    private HttpServletResponse response;
>    private MockServletContext servletContext;
>
>        public CardPaymentActionTest() {}
>
>        @Test
>        public void testPayment() {
>                setupContext();
>
>                // Mastercard payment which requires authentication
>                CustomerPaymentDetails details = new
> CustomerPaymentDetails();
>                details.setAccountNumber("955784322");
>
>                cardPaymentAction.setCustomerPaymentDetails(details);
>                String result = cardPaymentAction.makePayment();
>
> assertTrue(BaseAction.Results.ACS_HANDLER.equals(result));
>        }
>
>        /**
>         * Setup the context (request, session etc) for our action tests
>         * (Move to setUp() when I figure out why it's not being
> executed)
>         */
>        private void setupContext() {
>        Map extraContext = new HashMap();
>
>        request = new MockHttpServletRequest();
>        response = new MockHttpServletResponse();
>        servletContext = new MockServletContext();
>        extraContext.put(HTTP_REQUEST, request);
>        extraContext.put(HTTP_RESPONSE, response);
>        extraContext.put(SERVLET_CONTEXT, servletContext);
>        Map session = new
> org.apache.struts2.dispatcher.SessionMap(request);
>        session.put("profile", createCustomer());  // fake a logged in
> user
>        extraContext.put("session", session);
>
>        actionContext = new ActionContext(extraContext);
>        ServletActionContext.setContext(actionContext);
>        }
>
> As a responsible corporate citizen, London Scottish Bank plc asks you to 
> consider the environment before printing this email.
>
> *** Disclaimer ***
>
> This electronic communication is confidential and for the exclusive use of 
> the addressee. It may contain private and confidential information. The 
> information, attachments and opinions contained in this E-mail are those of 
> its author only and do not necessarily represent those of London Scottish 
> Bank PLC or any other members of the London Scottish Group.
>
> If you are not the intended addressee, you are prohibited from any 
> disclosure, distribution or further copying or use of this communication or 
> the information in it or taking any action in reliance on it. If you have 
> received this communication in error please notify the Information Security 
> Manager at [EMAIL PROTECTED] as soon as possible and delete the message from 
> all places in your computer where it is stored.
>
> We utilise virus scanning software but we cannot guarantee the security of 
> electronic communications and you are advised to check any attachments for 
> viruses. We do not accept liability for any loss resulting from any 
> corruption or alteration of data or importation of any virus as a result of 
> receiving this electronic communication.
>
> Replies to this E-mail may be monitored for operational or business reasons. 
> London Scottish Bank PLC is authorised and regulated by the Financial 
> Services Authority.
>
>
> London Scottish Bank plc, Registered Office: 201 Deansgate, Manchester M3 3NW 
> Registered Number 973008 England.
>
> Subsidiary Companies:-
>
> London Scottish Finance Limited, Registered Office: 201 Deansgate, Manchester 
> M3 3NW Registered Number 233259 England.
>
> London Scottish Broking Limited, Registered Office: 201 Deansgate, Manchester 
> M3 3NW Registered Number 230110 England.
>
> Robinson Way & Company Limited, Registered Office: 201 Deansgate, Manchester 
> M3 3NW Registered Number 885896 England.
>
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to