package org.flymine.dataconversion;

/*
 * Copyright (C) 2002-2004 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.util.Map;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Collection;
import java.util.Iterator;
import java.util.HashSet;
import java.util.Set;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileWriter;
import java.io.Reader;
import java.io.FileReader;

import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.ModelFactory;

import org.intermine.xml.full.FullParser;
import org.intermine.dataconversion.DataTranslator;
import org.intermine.dataconversion.DataTranslatorTestCase;
import org.intermine.dataconversion.MockItemReader;
import org.intermine.dataconversion.MockItemWriter;
import org.intermine.dataconversion.XmlConverter;
import org.intermine.metadata.Model;
import org.intermine.xml.full.FullRenderer;

public class PsiDataTranslatorTest extends DataTranslatorTestCase {
    private String tgtNs = "http://www.flymine.org/model/genomic#";

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

    public void testTranslate() throws Exception {
        Collection srcItems = getSrcItems();
        // print out source items XML - result of running XmlConverter on PSI XML
        // FileWriter writer = new FileWriter(new File("src.xml"));
        // writer.write(FullRenderer.render(srcItems));
        // writer.flush(); writer.close();
        DataTranslator translator = new PsiDataTranslator(new MockItemReader(writeItems(srcItems)),
                                                              getOwlModel(), tgtNs);
        MockItemWriter tgtIw = new MockItemWriter(new LinkedHashMap());
        translator.translate(tgtIw);

        assertEquals(new HashSet(getExpectedItems()), tgtIw.getItems());
    }

    protected Collection getSrcItems() throws Exception {
        Model psiModel = Model.getInstanceByName("psi");
        Reader srcReader = (new InputStreamReader(getClass().getClassLoader().getResourceAsStream("test/PsiDataTranslatorTest_src.xml")));
        MockItemWriter mockIw = new MockItemWriter(new HashMap());
        Reader xsdReader = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("psi.xsd"));

        XmlConverter converter = new XmlConverter(psiModel, xsdReader, mockIw);
        converter.process(srcReader);

        return mockIw.getItems();
    }

    protected Collection getExpectedItems() throws Exception {
        return FullParser.parse(getClass().getClassLoader().getResourceAsStream("test/PsiDataTranslatorTest_tgt.xml"));
    }

    protected OntModel getOwlModel() {
        InputStreamReader reader = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("genomic.n3"));

        OntModel ont = ModelFactory.createOntologyModel();
        ont.read(reader, null, "N3");
        return ont;
    }

    protected String getModelName() {
        return "genomic";
    }
}

@@ -1326,81 +1326,8 @@
 %22;%0A%0A
-    public void setUp() throws Exception %7B%0A        super.setUp();%0A    %7D%0A%0A
     
@@ -1365,32 +1365,32 @@
 ows Exception %7B%0A
+
         Collecti
@@ -2034,32 +2034,293 @@
 tems());%0A    %7D%0A%0A
+    protected String getModelName() %7B%0A        return %22genomic%22;%0A    %7D%0A%0A    protected Collection getExpectedItems() throws Exception %7B%0A        return FullParser.parse(getClass().getClassLoader().getResourceAsStream(%22test/PsiDataTranslatorTest_tgt.xml%22));%0A    %7D%0A%0A
     protected Co
@@ -2899,198 +2899,8 @@
  %7D%0A%0A
-    protected Collection getExpectedItems() throws Exception %7B%0A        return FullParser.parse(getClass().getClassLoader().getResourceAsStream(%22test/PsiDataTranslatorTest_tgt.xml%22));%0A    %7D%0A%0A
     
@@ -3149,24 +3149,24 @@
 ull, %22N3%22);%0A
+
         retu
@@ -3182,78 +3182,7 @@
    %7D
-%0A%0A    protected String getModelName() %7B%0A        return %22genomic%22;%0A    %7D
 %0A%7D%0A

Tidy up code