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.Collections;
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.model.testmodel.Department;

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

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

        getRequest().setAttribute("object", new Department());
        actionPerform();
        assertNotNull(context.getAttribute("clds"));
    }

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

        getRequest().setAttribute("object", "test string");
        actionPerform();
        assertNull(context.getAttribute("clds"));
    }

}

@@ -402,16 +402,38 @@
 til.Map;
+%0Aimport java.util.Set;
 %0A%0Aimport
@@ -707,17 +707,16 @@
 esults;%0A
-%0A
 import o
@@ -731,33 +731,108 @@
 ne.m
-odel.testmodel.Department
+etadata.Model;%0A%0Aimport org.flymine.model.FlyMineBusinessObject;%0Aimport org.flymine.model.testmodel.*
 ;%0A%0Ap
@@ -1294,66 +1294,994 @@
 ();%0A
-        assertNotNull(context.getAttribute(%22clds%22));%0A    %7D
+%0A        Model model = Model.getInstanceByName(%22testmodel%22);%0A        assertNotNull(context.getAttribute(%22clds%22));%0A        assertTrue(((Set) context.getAttribute(%22clds%22)).contains(model.getClassDescriptorByName(Department.class.getName())));%0A        assertTrue(((Set) context.getAttribute(%22clds%22)).contains(model.getClassDescriptorByName(RandomInterface.class.getName())));%0A        assertTrue(((Set) context.getAttribute(%22clds%22)).contains(model.getClassDescriptorByName(FlyMineBusinessObject.class.getName())));%0A%0A        assertNotNull(context.getAttribute(%22leafClds%22));%0A        assertTrue(((Set) context.getAttribute(%22leafClds%22)).contains(model.getClassDescriptorByName(Department.class.getName())));%0A        assertFalse(((Set) context.getAttribute(%22leafClds%22)).contains(model.getClassDescriptorByName(RandomInterface.class.getName())));%0A        assertFalse(((Set) context.getAttribute(%22leafClds%22)).contains(model.getClassDescriptorByName(FlyMineBusinessObject.class.getName())));%0A    %7D%0A
 %0A%0A  

Test for leafClds