package org.flymine.web;

/*
 * 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.List;

import servletunit.struts.MockStrutsTestCase;

import org.flymine.objectstore.query.Query;

public class QueryActionTest extends MockStrutsTestCase {

    public QueryActionTest(String testName) {
        super(testName);
    }

    public void setUp() throws Exception {
        super.setUp();
    }

    public void tearDown() throws Exception {
        super.tearDown();
    }

    public void testSubmitSuccessfulQuery() {
        setRequestPathInfo("/query");
        addRequestParameter("querystring","select a1_ from Company as a1_");
        addRequestParameter("action", "Submit");
        actionPerform();
        verifyForward("results");
        assertNotNull((List) getRequest().getAttribute("results"));
        verifyNoActionErrors();
    }

    public void testSubmitEmptyQuery() {
        setRequestPathInfo("/query");
        addRequestParameter("querystring","");
        addRequestParameter("action", "Submit");
        actionPerform();
        verifyForward("error");
        assertNull((String) getRequest().getAttribute("results"));
    }

    public void testSubmitRubbishQuery() {
        setRequestPathInfo("/query");
        addRequestParameter("querystring","some rubbish");
        addRequestParameter("action", "Submit");
        actionPerform();
        verifyForward("error");
        assertNull((String) getRequest().getAttribute("results"));
    }

    public void testViewSuccessfulQuery() {
        setRequestPathInfo("/query");
        addRequestParameter("querystring","select a1_ from Company as a1_");
        addRequestParameter("action", "View");
        actionPerform();
        verifyForward("buildquery");
        assertEquals("SELECT a1_ FROM org.flymine.model.testmodel.Company AS a1_", ((Query) getRequest().getAttribute("query")).toString());
        verifyNoActionErrors();
    }

    public void testViewEmptyQuery() {
        setRequestPathInfo("/query");
        addRequestParameter("querystring","");
        addRequestParameter("action", "View");
        actionPerform();
        verifyForward("error");
        assertNull((String) getRequest().getAttribute("query"));
    }

    public void testViewRubbishQuery() {
        setRequestPathInfo("/query");
        addRequestParameter("querystring","some rubbish");
        addRequestParameter("action", "View");
        actionPerform();
        verifyForward("error");
        assertNull((String) getRequest().getAttribute("query"));
    }
}

@@ -341,16 +341,56 @@
 .List;%0A%0A
+import javax.servlet.http.HttpSession;%0A%0A
 import s
@@ -471,16 +471,95 @@
 y.Query;
+%0Aimport org.flymine.model.testmodel.Company;%0Aimport org.flymine.metadata.Model;
 %0A%0Apublic
@@ -833,32 +833,534 @@
 rDown();%0A    %7D%0A%0A
+    public void testSelectSuccessful() throws Exception %7B%0A        setRequestPathInfo(%22/query%22);%0A        HttpSession session = getSession();%0A        Model model = Model.getInstanceByName(%22testmodel%22);%0A        session.setAttribute(%22model%22, model);%0A        addRequestParameter(%22action%22, %22Select%22);%0A        addRequestParameter(%22cldName%22, %22org.flymine.model.testmodel.Company%22);%0A        actionPerform();%0A        verifyForward(%22buildquery%22);%0A        assertNotNull(session.getAttribute(%22cld%22));%0A%0A    %7D%0A%0A    /*
     public void 
@@ -3406,10 +3406,17 @@
 ;%0A    %7D%0A
+    */%0A
 %7D%0A

test class selection