package org.intermine.web.config;

/*
 * Copyright (C) 2002-2005 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 junit.framework.TestCase;

import java.io.InputStream;

public class WebConfigTest extends TestCase
{

    public WebConfigTest(String arg) {
        super(arg);
    }

    public void testParse() throws Exception{
        InputStream is = getClass().getClassLoader().getResourceAsStream("test/WebConfigTest.xml");
        WebConfig wc1 = WebConfig.parse(is);

        Displayer disp1 = new Displayer();
        disp1.setSrc("/model/page2.jsp");
        Type type1 = new Type();
        type1.setClassName("Class1");
        type1.addLongDisplayer(disp1);
        FieldConfig df1 = new FieldConfig();
        df1.setFieldExpr("class1field1");
        type1.addFieldConfig(df1);
        FieldConfig df2 = new FieldConfig();
        df2.setFieldExpr("class1field2.field");
        type1.addFieldConfig(df2);

        Displayer disp2 = new Displayer();
        disp2.setSrc("/model/page4.jsp");
        Displayer disp3 = new Displayer();
        disp3.setSrc("tile2.tile");
        Type type2 = new Type();
        type2.setClassName("Class2");
        type2.addLongDisplayer(disp2);
        type2.addLongDisplayer(disp3);

        Exporter exporter = new Exporter();
        exporter.setId("myExporter");
        exporter.setActionPath("/somePath");
        exporter.setClassName("java.lang.String");

        WebConfig wc2 = new WebConfig();
        wc2.addType(type1);
        wc2.addType(type2);
        wc2.addExporter(exporter);

        assertEquals(wc2, wc1);
    }

    public void testParseNull() throws Exception{
        try {
            WebConfig.parse(null);
            fail("Expected: NullPointerException");
        } catch (NullPointerException e) {
        }

    }

}

@@ -389,16 +389,54 @@
 tream;%0A%0A
+import org.intermine.metadata.Model;%0A%0A
 public c
@@ -728,16 +728,54 @@
 parse(is
+, Model.getInstanceByName(%22testmodel%22)
 );%0A%0A    
@@ -920,14 +920,48 @@
 me(%22
-Class1
+org.intermine.model.testmodel.Employable
 %22);%0A
@@ -1479,14 +1479,43 @@
 me(%22
-Class2
+org.intermine.model.testmodel.Thing
 %22);%0A
@@ -1903,16 +1903,85 @@
 porter);
+%0A        wc2.setSubClassConfig(Model.getInstanceByName(%22testmodel%22));
 %0A%0A      
@@ -2077,16 +2077,16 @@
   try %7B%0A
-
         
@@ -2109,16 +2109,54 @@
 rse(null
+, Model.getInstanceByName(%22testmodel%22)
 );%0A     

Use class names from the test model.