package org.intermine.bio.ontology;

/*
 * Copyright (C) 2002-2014 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.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Set;

import junit.framework.TestCase;

import org.apache.commons.io.IOUtils;
import org.intermine.metadata.Model;

public class SequenceOntologyTest extends TestCase
{
    protected static final String ENDL = System.getProperty("line.separator");


    public SequenceOntologyTest(String arg) throws IOException {
        super(arg);

    }

    public void testGetAllClasses()  throws URISyntaxException, IOException {
        File terms = new File(SequenceOntologyTest.class.getClassLoader().getResource("so_terms-test").toURI());
        File oboFile = new File(SequenceOntologyTest.class.getClassLoader().getResource("SequenceOntology.obo").toURI());
        String targetXML = IOUtils.toString(getClass().getClassLoader().getResourceAsStream("so-target.xml"));
        SequenceOntologyFactory.reset();
        SequenceOntology so = SequenceOntologyFactory.getSequenceOntology(oboFile, terms);

        Model model = so.getModel();
        assertEquals("testing using so-test failed", targetXML, model.toString());
    }

    // test generating SO without providing the data file. use the default
    public void testNoFile() throws IOException {
        SequenceOntologyFactory.reset();
        SequenceOntology so = SequenceOntologyFactory.getSequenceOntology();
        Model model = so.getModel();
        String targetXML = IOUtils.toString(getClass().getClassLoader().getResourceAsStream("so-target-default.xml"));
        assertEquals(model.toAdditionsXML(), targetXML, model.toString());
    }

    public void testParents() {
        SequenceOntology so = SequenceOntologyFactory.getSequenceOntology();
        String className = "exon";
        Set<String> parents = so.getAllPartOfs(className);
        System.out.print(parents);
        assertEquals(2, parents.size());
        assertTrue(parents.contains("transcript"));
    }
}

@@ -448,31 +448,53 @@
 rt j
-unit.framework.TestCase
+avax.xml.parsers.ParserConfigurationException
 ;%0A%0Ai
@@ -545,32 +545,151 @@
 org.
-intermine.metadata.Model
+custommonkey.xmlunit.XMLTestCase;%0Aimport org.custommonkey.xmlunit.XMLUnit;%0Aimport org.intermine.metadata.Model;%0Aimport org.xml.sax.SAXException
 ;%0A%0Ap
@@ -729,16 +729,19 @@
 extends 
+XML
 TestCase
@@ -984,32 +984,76 @@
 ion, IOException
+, SAXException, ParserConfigurationException
  %7B%0A        File 
@@ -1573,47 +1573,17 @@
 sert
+XML
 Equal
-s(%22testing using so-test failed%22, 
+(
 targ
@@ -1729,32 +1729,76 @@
 rows IOException
+, SAXException, ParserConfigurationException
  %7B%0A        Seque
@@ -2076,39 +2076,17 @@
 sert
+XML
 Equal
-s(model.toAdditionsXML(), 
+(
 targ

use better library for comparing XML. Gives better error message for failing test. Refs #828