/*
 *                    BioJava development code
 *
 * 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.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the individual
 * authors.  These should be listed in @author doc comments.
 *
 * For more information on the BioJava project and its aims,
 * or to join the biojava-l mailing list, visit the home page
 * at:
 *
 *      http://www.biojava.org/
 *
 * Created at 08 Aug 2017
 */

package org.biojava.nbio.ontology;

import junit.framework.TestCase;
import org.biojava.nbio.ontology.io.OboParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Set;

import static org.biojava.nbio.ontology.obo.OboFileHandler.NAMESPACE;

public class TestParseOBO extends TestCase {

	private static final Logger logger = LoggerFactory.getLogger(TestParseOBO.class);

	public void testNamespace(){

		String testTermEntry = "\n[Term]\n" +
                "id: SO:0000691\n" +
                "name: cleaved_initiator_methionine \n" +
                "namespace: sequence\n" +
                "alt_id: BS:00067\n" +
                "def: \"The initiator methionine that has been cleaved from a mature polypeptide sequence.\" [EBIBS:GAR]\n" +
                "subset: biosapiens\n" +
                "synonym: \"cleaved initiator methionine\" EXACT []\n" +
                "synonym: \"init_met\" RELATED [uniprot:feature_type]\n" +
                "synonym: \"initiator methionine\" RELATED []\n" +
                "is_a: SO:0100011 ! cleaved_peptide_region\n\n";

        OboParser parser = new OboParser();

		try {


            InputStream inStream = new ByteArrayInputStream(testTermEntry.getBytes());

			assertNotNull(inStream);

			BufferedReader oboFile = new BufferedReader ( new InputStreamReader ( inStream ) );

			Ontology ontology;

			ontology = parser.parseOBO(oboFile, "so-xp/subsets/biosapiens",
                    "snippet from biosapiens protein feature ontology");
			Set<Term> keys = ontology.getTerms();

			assertTrue(keys.size() > 1);
			assertTrue(ontology.getTerm("SO:0000691").getAnnotation().containsProperty(NAMESPACE));
            assertEquals("sequence",ontology.getTerm("SO:0000691").getAnnotation().getProperty(NAMESPACE));

		} catch (Exception e) {
			// TODO Auto-generated catch block
			logger.error("Exception: ", e);
			fail(e.getMessage());
		}
	}
}

@@ -739,194 +739,58 @@
 er;%0A
-import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport java.io.BufferedReader;%0Aimport java.io.ByteArrayInputStream;%0Aimport java.io.InputStream;%0Aimport java.io.InputStreamReader
+%0Aimport java.io.*;%0Aimport java.text.ParseException
 ;%0Aim
@@ -933,118 +933,70 @@
 %0A%0A%09p
-rivate static final Logger logger = LoggerFactory.getLogger(TestParseOBO.class);%0A%0A%09public void testNamespace()
+ublic void testNamespace() throws IOException, ParseException 
 %7B%0A%0A%09
@@ -1705,19 +1705,8 @@
 r();
-%0A%0A%09%09try %7B%0A%0A
 %0A   
@@ -1710,20 +1710,16 @@
         
-    
 InputStr
@@ -1784,25 +1784,24 @@
 ytes());%0A%0A%09%09
-%09
 assertNotNul
@@ -1814,17 +1814,16 @@
 ream);%0A%0A
-%09
 %09%09Buffer
@@ -1900,18 +1900,16 @@
 am ) );%0A
-%0A%09
 %09%09Ontolo
@@ -1915,22 +1915,8 @@
 ogy 
-ontology;%0A%0A%09%09%09
 onto
@@ -2050,17 +2050,16 @@
 gy%22);%0A%09%09
-%09
 Set%3CTerm
@@ -2091,17 +2091,16 @@
 s();%0A%0A%09%09
-%09
 assertTr
@@ -2120,17 +2120,16 @@
 ) %3E 1);%0A
-%09
 %09%09assert
@@ -2218,20 +2218,16 @@
         
-  
-  
 assertEq
@@ -2317,137 +2317,8 @@
 E));
-%0A%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09// TODO Auto-generated catch block%0A%09%09%09logger.error(%22Exception: %22, e);%0A%09%09%09fail(e.getMessage());%0A%09%09%7D
 %0A%09%7D%0A

throw exception instead of fail