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;

import org.intermine.metadata.Model;

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, Model.getInstanceByName("testmodel"));

        Displayer disp1 = new Displayer();
        disp1.setSrc("/model/page2.jsp");
        Type type1 = new Type();
        type1.setClassName("org.intermine.model.testmodel.Employable");
        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("org.intermine.model.testmodel.Thing");
        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);
        wc2.setSubClassConfig(Model.getInstanceByName("testmodel"));

        assertEquals(wc2, wc1);
    }

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

    }

}

@@ -788,21 +788,33 @@
 splayer 
-disp1
+employeeDisplayer
  = new D
@@ -833,21 +833,33 @@
         
-disp1
+employeeDisplayer
 .setSrc(
@@ -870,21 +870,24 @@
 del/
-page2
+employee
 .jsp%22);%0A
     
@@ -874,32 +874,33 @@
 employee.jsp%22);%0A
+%0A
         Type typ
@@ -896,21 +896,30 @@
    Type 
-t
+employableT
 ype
-1
  = new T
@@ -933,21 +933,30 @@
         
-t
+employableT
 ype
-1
 .setClas
@@ -1010,29 +1010,38 @@
 %22);%0A        
-t
+employableT
 ype
-1
 .addLongDisp
@@ -1050,13 +1050,25 @@
 yer(
-disp1
+employeeDisplayer
 );%0A 
@@ -1153,37 +1153,46 @@
 eld1%22);%0A        
-t
+employableT
 ype
-1
 .addFieldConfig(
@@ -1302,32 +1302,568 @@
     
-type1.addFieldConfig(df2
+employableType.addFieldConfig(df2);%0A%0A        Displayer managerDisplayer = new Displayer();%0A        managerDisplayer.setSrc(%22/model/manager.jsp%22);%0A%0A        Type managerType = new Type();%0A        managerType.setClassName(%22org.intermine.model.testmodel.Manager%22);%0A        managerType.addLongDisplayer(managerDisplayer);%0A%0A        FieldConfig df3 = new FieldConfig();%0A        df3.setFieldExpr(%22name%22);%0A        managerType.addFieldConfig(df3);%0A        FieldConfig df4 = new FieldConfig();%0A        df4.setFieldExpr(%22seniority%22);%0A        managerType.addFieldConfig(df4
 );%0A%0A
@@ -2022,24 +2022,25 @@
 le2.tile%22);%0A
+%0A
         Type
@@ -2041,20 +2041,24 @@
   Type t
+hingT
 ype
-2
  = new T
@@ -2073,20 +2073,24 @@
        t
+hingT
 ype
-2
 .setClas
@@ -2136,36 +2136,40 @@
 ing%22);%0A        t
+hingT
 ype
-2
 .addLongDisplaye
@@ -2187,20 +2187,24 @@
        t
+hingT
 ype
-2
 .addLong
@@ -2466,13 +2466,56 @@
 ype(
-type1
+employableType);%0A        wc2.addType(managerType
 );%0A 
@@ -2538,12 +2538,16 @@
 pe(t
+hingT
 ype
-2
 );%0A 
@@ -2642,32 +2642,237 @@
 %22testmodel%22));%0A%0A
+        assertEquals(1, managerType.getLongDisplayers().size());%0A        assertEquals(%22/model/manager.jsp%22,%0A                     ((Displayer) managerType.getLongDisplayers().iterator().next()).getSrc());%0A%0A
         assertEq
@@ -2883,24 +2883,25 @@
 (wc2, wc1);%0A
+%0A
     %7D%0A%0A    p

Test inheritance of longdisplayers.