package edu.columbia.gemma.controller;

import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.RedirectView;

import edu.columbia.gemma.BaseControllerTestCase;
import edu.columbia.gemma.web.controller.LoaderController;

/**
 * This test makes use of Spring's MockHttpServletRequest and MockHttpServletResponse. I have used TaxonLoaderService as
 * the loader of choice as it is fast (small file to read from).
 * <hr>
 * <p>
 * Copyright (c) 2004 - 2005 Columbia University
 * 
 * @author keshav
 * @version $Id$
 */
public class LoaderControllerTest extends BaseControllerTestCase {

    private LoaderController c;
    private MockHttpServletRequest request;
    private MockHttpServletResponse response;
    private View returnedView;

    public void setUp() throws Exception {
        c = ( LoaderController ) ctx.getBean( "loaderController" );
        request = new MockHttpServletRequest();
        response = new MockHttpServletResponse();
        returnedView = new RedirectView( "home.jsp" );
    }

    public void tearDown() {
        c = null;
    }

    /**
     * hasHeader = true The View returned by the onSubmit method ( a RedirectView(String view) ) will obviously not
     * point to the same place on the heap as returnedView defined in setUp(). Calling toString on both will, however
     * yield the same String value: org.springframework.web.servlet.view.RedirectView: unnamed; URL [home.jsp]
     * 
     * @throws Exception
     */
    public void testOnSubmitHeaderIsTrue() throws Exception {
        request.addParameter( "hasHeader", "true" );
        request.addParameter( "typeOfLoader", "taxonLoaderService" );
        ModelAndView mav = c.onSubmit( request, response, ( Object ) null, ( BindException ) null );
        assertEquals( returnedView.toString(), mav.getView().toString() );

        //
    }

    /**
     * hasHeader = false Calling onSubmit with hasHeader = false will cause a NumberFormatException, as expected. This
     * results in a call to the view numberFormatError.jsp (to display the error), with the view name being
     * numberFormatError. TODO is it possible to test this if LoaderController throws an exception?
     * 
     * @throws Exception
     */
    //    public void testOnSubmitHeaderIsFalse() throws Exception {
    //        request.addParameter( "hasHeader", "false" );
    //        request.addParameter( "typeOfLoader", "taxonLoaderService" );
    //        ModelAndView mav = c.onSubmit( request, response, ( Object ) null, ( BindException ) null );
    //        System.err.println(mav.getView().toString());
    //        assertEquals( null, mav.getView().toString() );
    //    }
}
@@ -1314,32 +1314,34 @@
 ull;%0A    %7D%0A%0A
+//
     /**%0A
      * hasHe
@@ -1320,32 +1320,34 @@
    %7D%0A%0A//    /**%0A
+//
      * hasHeader
@@ -1446,16 +1446,18 @@
 sly not%0A
+//
      * p
@@ -1566,16 +1566,18 @@
 however%0A
+//
      * y
@@ -1679,24 +1679,26 @@
 me.jsp%5D%0A
+//
      * %0A
      * @
@@ -1681,32 +1681,34 @@
 .jsp%5D%0A//     * %0A
+//
      * @throws E
@@ -1712,32 +1712,34 @@
 s Exception%0A
+//
      */%0A
     public v
@@ -1722,24 +1722,26 @@
 n%0A//     */%0A
+//
     public v
@@ -1782,32 +1782,34 @@
 ows Exception %7B%0A
+//
         request.
@@ -1841,24 +1841,26 @@
 , %22true%22 );%0A
+//
         requ
@@ -1913,24 +1913,26 @@
 Service%22 );%0A
+//
         Mode
@@ -2016,24 +2016,26 @@
 n ) null );%0A
+//
         asse
@@ -2097,17 +2097,21 @@
 ng() );%0A
-%0A
+//%0A//
         
@@ -2113,21 +2113,46 @@
      //%0A
+//
     %7D
+ // commented out by pp
 %0A%0A    /*

remove testOnSubmitHeaderIsTrue