Results 1 to 3 of 3

Thread: TDD newbie

  1. #1
    Join Date
    Aug 2004
    Location
    Stockholm
    Posts
    466

    Default TDD newbie

    Hi all

    I'm currently exploring the recommended "test first" approach in Spring development, and I must admit I'm fascinated by all the possibilities theis method has.

    But I'm also a newbie in this way of thinking, and have run into problems

    I wonder why

    Code:
    private MockControl control = null;
        private LogicFacade mockLogic = null;
        private DateSearchFormController datefc = null;
        private MockHttpServletRequest mockreq = null;
        
    
        protected void setUp() throws Exception {
            control = MockControl.createControl(LogicFacade.class);
            mockLogic = (LogicFacade) control.getMock();
            datefc = new DateSearchFormController();
            datefc.setLogic(mockLogic);
            mockreq = new MockHttpServletRequest();
        }
        
        protected void tearDown() throws Exception {
            control = null;
            mockLogic = null;
            datefc = null;
            mockreq = null;
        }
        
        public void testLoginCheck() throws Exception {
        	MockHttpSession mockSession = new MockHttpSession();
        	MockControl sessionControl = MockControl.createControl(UserSession.class);
        	UserSession session = (UserSession) sessionControl.getMock();
        	
        	AvikUser user = new AvikUser();
        	user.setRole(AvikRole.POWERUSER);
        	session.setUser(user);
        	
        	mockSession.setAttribute("usersession", session);
        	mockreq.setAttribute("something", new Object());
        	mockreq.setSession(mockSession);
        	datefc.handleRequest( mockreq , new MockHttpServletResponse() );
        	
        }
    generates the following exception

    Code:
        [junit] Testcase: testLoginCheck(ks.rah.avik2.test.TestSearchController):   Caused an ERROR
        [junit] Request method 'null' not supported
        [junit] org.springframework.web.servlet.support.RequestMethodNotSupportedException: Request method 'null' not suppor
    ted
        [junit]     at org.springframework.web.servlet.support.WebContentGenerator.checkAndPrepare(WebContentGenerator.java:
    199)
        [junit]     at org.springframework.web.servlet.support.WebContentGenerator.checkAndPrepare(WebContentGenerator.java:
    178)
        [junit]     at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:109)
        [junit]     at ks.rah.avik2.test.TestSearchController.testLoginCheck(TestSearchController.java:61)
        [junit]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        [junit]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        [junit]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    testing this code


    Code:
    protected ModelAndView onSubmit(HttpServletRequest request, 
    									HttpServletResponse response,
    									Object command, 
    									BindException errors) throws Exception {
    		DateSearchForm form = (DateSearchForm) command;
    		AvikUser user = AvikController.checkLoggedIn(request, AvikRole.POWERUSER, false);
    .
    .
    .
    Seems like the MockHttpServletRequest/Response is null somehow.....

    Anybody have an idea?
    Sincerely,
    /The Cantor

    "Murphy was an optimist"
    (The O'Toole commentary on Murphy's Law)

  2. #2
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    You are using the constructor for MockHttpServletRequest which does not specify any 'method' string ('GET' or 'POST'), so you need to set this yourself manually as a property.
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

  3. #3
    Join Date
    Aug 2004
    Location
    Stockholm
    Posts
    466

    Default

    That did it.

    Thanks!
    Sincerely,
    /The Cantor

    "Murphy was an optimist"
    (The O'Toole commentary on Murphy's Law)

Similar Threads

  1. Replies: 7
    Last Post: Apr 3rd, 2008, 08:38 AM
  2. Replies: 5
    Last Post: Sep 3rd, 2005, 10:02 AM
  3. Newbie: moving from avalon to spring
    By Leonets in forum Container
    Replies: 5
    Last Post: Sep 2nd, 2005, 08:45 AM
  4. Replies: 1
    Last Post: Jun 12th, 2005, 08:46 AM
  5. Newbie. Hibernate + MySQL
    By abstraction in forum Data
    Replies: 6
    Last Post: Oct 24th, 2004, 10:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •