package org.flymine.web.results;

/*
 * Copyright (C) 2002-2003 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import java.util.HashMap;
import java.util.Map;

import servletunit.struts.MockStrutsTestCase;
import org.apache.struts.tiles.ComponentContext;

import org.flymine.objectstore.ObjectStore;
import org.flymine.objectstore.ObjectStoreFactory;
import org.flymine.objectstore.query.Query;
import org.flymine.objectstore.query.Results;
import org.flymine.web.Constants;

public class ResultsViewControllerTest extends MockStrutsTestCase
{
    public ResultsViewControllerTest(String arg1) {
        super(arg1);
    }

    public void testNoExisting() throws Exception {
        ComponentContext context = new ComponentContext();
        ComponentContext.setContext(context, getRequest());
        setRequestPathInfo("/initResultsView");

        Query q = new Query();
        ObjectStore os = ObjectStoreFactory.getObjectStore("os.unittest");

        getSession().setAttribute("results", new Results(q, os, os.getSequence()));
        actionPerform();
        assertNotNull(getRequest().getSession().getAttribute(Constants.RESULTS_TABLE));
        assertNotNull(getRequest().getSession().getAttribute(Constants.SAVED_BAGS));
    }

    public void testExisting() throws Exception {
        ComponentContext context = new ComponentContext();
        ComponentContext.setContext(context, getRequest());
        setRequestPathInfo("/initResultsView");

        Map savedBags = new HashMap();

        getSession().setAttribute(Constants.SAVED_BAGS, savedBags);
        actionPerform();
        assertTrue(savedBags == getRequest().getSession().getAttribute(Constants.SAVED_BAGS));
    }

}

@@ -378,54 +378,8 @@
 p;%0A%0A
-import servletunit.struts.MockStrutsTestCase;%0A
 impo
@@ -644,16 +644,63 @@
 tants;%0A%0A
+import servletunit.struts.MockStrutsTestCase;%0A%0A
 public c
@@ -1063,39 +1063,8 @@
 );%0A%0A
-        Query q = new Query();%0A
     
@@ -1134,25 +1134,24 @@
 test%22);%0A
-%0A
         
 getSessi
@@ -1146,44 +1146,25 @@
     
-getSession().setAttribute(%22
+Results 
 results
-%22,
+ =
  new
@@ -1172,17 +1172,27 @@
 Results(
-q
+new Query()
 , os, os
@@ -1206,16 +1206,70 @@
 uence())
+;%0A        getRequest().setAttribute(%22results%22, results
 );%0A     
@@ -1284,32 +1284,33 @@
 nPerform();%0A
+%0A
         
 assertNotNul
@@ -1301,35 +1301,85 @@
     
-assertNotNull(getRequest().
+verifyNoActionErrors();%0A        DisplayableResults dr = (DisplayableResults) 
 getS
@@ -1424,17 +1424,16 @@
 S_TABLE)
-)
 ;%0A      
@@ -1444,75 +1444,38 @@
 sert
-NotNull(getRequest().getSession().getAttribute(Constants.SAVED_BAGS
+True(results == dr.getResults(
 ));%0A
@@ -1711,39 +1711,292 @@
     
-Map savedBags = new HashMap();%0A
+ObjectStore os = ObjectStoreFactory.getObjectStore(%22os.unittest%22);%0A        Results results = new Results(new Query(), os, os.getSequence());%0A        getRequest().setAttribute(%22results%22, results);%0A        DisplayableResults dr = new DisplayableResults(results);%0A        dr.setStart(3);
 %0A   
@@ -2040,29 +2040,25 @@
 nts.
-SAVED_BAGS, savedBags
+RESULTS_TABLE, dr
 );%0A 
@@ -2081,24 +2081,25 @@
 form();%0A
+%0A
         
 assertTr
@@ -2094,91 +2094,202 @@
     
-assertTrue(savedBags == getRequest().getSession().getAttribute(Constants.SAVED_BAGS
+verifyNoActionErrors();%0A        dr = (DisplayableResults) getSession().getAttribute(Constants.RESULTS_TABLE);%0A        assertTrue(results == dr.getResults());%0A        assertEquals(3, dr.getStart(
 ));%0A
@@ -2294,11 +2294,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

Add more tests